protected void XMPPReader(XmlStream xml, CancellationToken canceltoken) { try { while (!canceltoken.IsCancellationRequested) { if (xml.ReadStartElement(true)) { XElement el = xml.ReadElement(true); if (!canceltoken.IsCancellationRequested) { if (el.Name == (NamespaceClient + "iq")) { EnqueueInfoQueryResponse(el); } else if (el.Name == (NamespaceClient + "message")) { EnqueueMessage(el); } } } } } catch (Exception ex) { Logger.Log(LogLevel.Warning, "XMPP Reader task caught exception {0}\n{1}", ex.Message, ex.ToString()); ReaderException = ex; ReaderFaulted.Set(); } }
async public Task SaveConfig(ServerMapDocument mapDocument) { try { if (MapDocument == null) { return; } var map = mapDocument?.Maps.First() as Map; if (map == null) { throw new MapServerException("Mapdocument don't contain a map"); } XmlStream stream = new XmlStream("MapServer"); stream.Save("MapDocument", mapDocument); stream.WriteStream(_mapServerService.Options.ServicesPath + "/" + map.Name + ".mxl"); if (map is Map) { await ApplyMetadata(map); } } catch (Exception ex) { _logger.LogError($"Map { mapDocument?.Maps?.First()?.Name }: LoadConfig - { ex.Message }"); } }
protected void ProcessQueuedMessages(XmlStream xml, CancellationToken canceltoken) { Message msg; while (!canceltoken.IsCancellationRequested && QueuedMessages.TryDequeue(out msg)) { foreach (XElement el in msg.Content) { if (el.Name.ToString() == "{google:push}push") { string channel = el.Attribute("channel").Value; if (Subscriptions.ContainsKey(channel)) { Logger.Log(LogLevel.Debug, "Handling message for channel {0}", channel); Subscriptions[channel](el, this); } else { Logger.Log(LogLevel.Debug, "Message for unknown channel {0}", channel); } } } } canceltoken.ThrowIfCancellationRequested(); }
public string ToXmlString() { XmlStream xmlStream = new XmlStream("SpatialReference"); this.Save(xmlStream); return(xmlStream.ToString()); }
async public override Task <bool> Refresh() { try { await base.Refresh(); _mapDocument = new MapDocument(); XmlStream stream = new XmlStream(""); stream.ReadStream(_filename); //_mapDocument.LoadMapDocument(_filename); await stream.LoadAsync("MapDocument", _mapDocument); foreach (IMap map in _mapDocument.Maps) { base.AddChildObject(new MapExplorerObject(this, _filename, map)); } return(true); } catch (Exception ex) { string errMsg = ex.Message; return(false); } }
static public void SaveConfig(IMap map) { try { if (mapDocument == null) { return; } ServerMapDocument doc = new ServerMapDocument(); if (!doc.AddMap(map)) { return; } XmlStream stream = new XmlStream("MapServer"); stream.Save("MapDocument", doc); stream.WriteStream(ServicesPath + @"\" + map.Name + ".mxl"); } catch (Exception ex) { if (Functions.log_errors) { Logger.Log(loggingMethod.error, "LoadConfig: " + ex.Message); } } }
public bool LoadMapDocument(string path) { XmlStream stream = new XmlStream(""); if (stream.ReadStream(path)) { while (_maps.Count > 0) { this.RemoveMap((IMap)_maps[0]); } stream.Load("MapDocument", null, this); if (_maps.Count > 0) { FocusMap = _maps[0]; } else { FocusMap = null; } return(true); } return(false); }
public bool RemoveFavorite(string name, string path) { try { FileInfo fi = new FileInfo(ConfigPath); if (!fi.Exists) { return(false); } XmlStream stream = new XmlStream("Favorites"); stream.ReadStream(fi.FullName); FavoriteList favList = (FavoriteList)stream.Load("favlist", null, new FavoriteList()); if (favList == null) { return(false); } favList.Remove(name, path); stream = new XmlStream("Favorites"); stream.Save("favlist", favList); stream.WriteStream(fi.FullName); return(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error - Remove Favorite"); } return(false); }
static public void SaveServiceableDataset(IServiceableDataset sds, string name) { try { if (sds != null) { XmlStream stream = new XmlStream("MapServer"); stream.Save("IServiceableDataset", sds); stream.WriteStream(ServicesPath + @"\" + name + ".svc"); if (sds is IMetadata) { stream = new XmlStream("Metadata"); ((IMetadata)sds).WriteMetadata(stream); stream.WriteStream(ServicesPath + @"\" + name + ".svc.meta"); } } } catch (Exception ex) { if (Functions.log_errors) { Logger.Log(loggingMethod.error, "LoadConfig: " + ex.Message); } } }
static private void Load() { try { _loaded = true; XmlStream stream = new XmlStream("localcaching"); if (!stream.ReadStream(SystemVariables.CommonApplicationData + @"\options_tilecache_local_caching.xml")) { stream = new XmlStream("localcaching"); stream.Save("use", (bool)true); stream.Save("folder", SystemVariables.CommonApplicationData + @"\temp\tilecache"); stream.WriteStream(SystemVariables.CommonApplicationData + @"\options_tilecache_local_caching.xml"); stream = new XmlStream("webproxy"); stream.ReadStream(SystemVariables.CommonApplicationData + @"\options_tilecache_local_caching.xml"); } _use = (bool)stream.Load("use", (bool)true); _folder = (string)stream.Load("folder", SystemVariables.CommonApplicationData + @"\temp\tilecache"); } catch (Exception ex) { _loaded = false; } }
public bool AddFavorite(string name, string path, Image image) { try { RemoveFavorite(name, path); FileInfo fi = new FileInfo(ConfigPath); XmlStream stream = new XmlStream("Favorites"); FavoriteList favList = new FavoriteList(); if (fi.Exists) { stream.ReadStream(fi.FullName); favList = (FavoriteList)stream.Load("favlist", null, favList); if (favList == null) { favList = new FavoriteList(); } } favList.Add(new Favorite(name, path, image)); stream = new XmlStream("Favorites"); stream.Save("favlist", favList); stream.WriteStream(fi.FullName); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error - Add Favorite"); } return(false); }
protected void StartPlaintextStream(CancellationToken canceltoken) { using (var stream = Connect(EndpointHost, EndpointPort, ProxyHost, ProxyPort)) { using (var xml = new XmlStream(stream)) { using (var xmppstream = xml.WriteStart(new XElement(NamespaceStream + "stream", new XAttribute("to", Domain), new XAttribute(XNamespace.Xml + "lang", "en"), new XAttribute("version", "1.0")))) { xml.ReadStartElement(NamespaceStream + "stream"); xml.Expect((rdr) => rdr.GetAttribute("from") == Domain, (rdr) => String.Format("Expected domain {0}; got domain {1}", Domain, rdr.GetAttribute("from"))); var features = xml.ReadElement(NamespaceStream + "features"); xml.Write(new XElement(NamespaceStartTLS + "starttls")); xml.ReadStartElement(NamespaceStartTLS + "proceed"); xml.Stream.Logged = false; using (var ssl = new SslStream(xml.Stream, true, (sender, cert, chain, errs) => true)) { ssl.AuthenticateAsClient(EndpointHost); using (var sslxml = new XmlStream(ssl)) { StartTLSStream(sslxml, canceltoken); } } } } } }
protected override void SaveChanges() { XmlStream.Position = 0; XmlStream.SetLength(0); base.SaveChanges(); XmlStream.Flush(); }
public string ToXmlString() { XmlStream xmlStream = new XmlStream("EventTableConnection"); this.Save(xmlStream); return(xmlStream.ToString()); }
public override string ToString() { XmlStream stream = new XmlStream("DbConnectionString"); Save(stream); return(stream.ToString()); }
public void FromXmlString(string xml) { XmlStream stream = new XmlStream("EventTableConnection"); StringReader sr = new StringReader(xml); stream.ReadStream(sr); Load(stream); }
public void FromXmlString(string xml) { XmlStream stream = new XmlStream("SpatialReference"); StringReader sr = new StringReader(xml); stream.ReadStream(sr); this.Load(stream); }
public FormMetadata(XmlStream xmlStream, object metadataObject) { InitializeComponent(); _metadata = new Metadata(); _metadata.ReadMetadata(xmlStream); _metadataObject = metadataObject; }
private void WmtsMetadata100(IServiceRequestContext context, TileServiceMetadata metadata) { XmlStream stream = new XmlStream("WmtsMetadata"); stream.Save("TileServiceMetadata", metadata); context.ServiceRequest.Response = stream.ToString(); context.ServiceRequest.ResponseContentType = "text/xml"; }
public void FromString(string connection) { XmlStream stream = new XmlStream("DbConnectionString"); StringReader sr = new StringReader(connection); stream.ReadStream(sr); Load(stream); }
public void SaveMapDocument(string filename, bool performEncryption) { if (filename == "") { return; } if (filename.ToLower() == SystemVariables.ApplicationDirectory.ToLower() + @"\normal.mxl" || filename == "normal.mxl") { switch (MessageBox.Show("Override normal.mxl?", "gView.Carto", MessageBoxButtons.YesNo)) { case DialogResult.No: return; } } XmlStream stream = new XmlStream("MapApplication", performEncryption); stream.Save("MapDocument", _doc); foreach (DataView dv in _dataViews) { stream.Save("DataView", dv); } System.IO.FileInfo fi = new System.IO.FileInfo(filename); if (fi.Extension.ToLower() == ".rdm") { StringBuilder sb = new StringBuilder(); StringWriter strwr = new StringWriter(sb); stream.WriteStream(strwr, Formatting.None); strwr.Close(); byte[] bytes = Encoding.Unicode.GetBytes(sb.ToString()); bytes = Crypto.Encrypt(bytes, _cryptoKey); StreamWriter sw = new StreamWriter(fi.FullName); BinaryWriter bw = new BinaryWriter(sw.BaseStream); bw.Write(bytes); sw.Close(); } else if (fi.Extension.ToLower() == ".axl") { MessageBox.Show("Can't save AXL Documents...", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { stream.WriteStream(filename); } IsDirty = false; _docFilename = filename; _appWindow.Title = "gView.Carto " + fi.Name; }
public void ShouldStreamTwoObjects() { const string xml = @"<root><item id=""1""/><item id=""2""/></root>"; using (TextReader source = new StringReader(xml)) using (XmlStream stream = new XmlStream(source)) { Assert.That(stream.Open("item").Count(), Is.EqualTo(2)); } }
async public Task <XmlStream> GetStream() { XmlStream stream = new XmlStream("Metadata"); if (_metadata != null) { await _metadata.WriteMetadata(stream); } return(stream); }
protected void ProcessQueuedResponses(XmlStream xml, CancellationToken canceltoken) { InfoQueryResponse iq; while (!canceltoken.IsCancellationRequested && QueuedResponses.TryDequeue(out iq)) { iq.Query.Callback(iq, canceltoken); } canceltoken.ThrowIfCancellationRequested(); }
public void Dispose() { if (RootWriter != null) { RootWriter.Dispose(); } if (XmlStream != null) { XmlStream.Dispose(); } }
public void ShouldStreamAllProperties() { const string xml = @"<root><item id=""1""/><item id=""2""/></root>"; using (TextReader source = new StringReader(xml)) using (XmlStream stream = new XmlStream(source)) { foreach (dynamic element in stream.Open("item")) { Assert.That(element.id.ToString(), Is.EqualTo("1").Or.EqualTo("2")); } } }
protected virtual void SaveChanges() { DataSet.AcceptChanges(); if (CanWriteStream) { XmlStream.Flush(); DataSet.WriteXml(XmlStream, XmlWriteMode.IgnoreSchema); } else { throw new ApplicationException("Can't write to XML stream."); } }
public static byte[] SerializeWeight(IGraphWeight weight) { if (weight != null) { XmlStream stream = new XmlStream("weight"); weight.Save(stream); MemoryStream ms = new MemoryStream(); stream.WriteStream(ms); return(ms.GetBuffer()); } return(null); }
async private void btnMapServiceMetadata_Click(object sender, EventArgs e) { XmlStream xmlStream = new XmlStream(String.Empty); this._map.ReadMetadata(xmlStream); FormMetadata dlg = new FormMetadata(xmlStream, this._map); if (dlg.ShowDialog() == DialogResult.OK) { await(this._map).WriteMetadata(await dlg.GetStream()); } }
public static IGraphWeight DeserializeWeight(byte[] bytes) { if (bytes != null) { XmlStream stream = new XmlStream("weight"); MemoryStream ms = new MemoryStream(bytes); stream.ReadStream(ms); GraphWeight weight = new GraphWeight(); weight.Load(stream); return(weight); } return(null); }
public DisposableXElement(XmlStream stream, XElement element) { Stream = stream; Stream.Writer.WriteStartElement(element.Name.LocalName, element.Name.NamespaceName); var rdr = element.CreateReader(); rdr.Read(); Stream.Writer.WriteAttributes(rdr, false); foreach (XNode node in element.Nodes()) { Stream.Write(node); } Stream.Writer.WriteWhitespace(""); Stream.Writer.Flush(); }
protected void ProcessQueuedQueries(XmlStream xml, CancellationToken canceltoken) { InfoQuery iq; if (IsReadyForSubscriptions) { Func<InfoQuery> iqfactory; while (!canceltoken.IsCancellationRequested && QueuedSubscriptions.TryDequeue(out iqfactory)) { ProcessInfoQuery(xml, iqfactory()); } } while (!canceltoken.IsCancellationRequested && QueuedQueries.TryDequeue(out iq)) { ProcessInfoQuery(xml, iq); } canceltoken.ThrowIfCancellationRequested(); }
protected void StartTLSStream(XmlStream xml, CancellationToken canceltoken) { using (var xmppstream = xml.WriteStart(new XElement(NamespaceStream + "stream", new XAttribute("to", Domain), new XAttribute(XNamespace.Xml + "lang", "en"), new XAttribute("version", "1.0")))) { xml.ReadStartElement(NamespaceStream + "stream"); xml.Expect((rdr) => rdr.GetAttribute("from") == Domain, (rdr) => String.Format("Expected domain {0}; got domain {1}", Domain, rdr.GetAttribute("from"))); var features = xml.ReadElement(NamespaceStream + "features"); xml.Write( new XElement(NamespaceSASL + "auth", new XAttribute("mechanism", AuthMechanism), new XAttribute(NamespaceAuth + "service", "chromiumsync"), new XAttribute(NamespaceAuth + "allow-generated-jid", "true"), new XAttribute(NamespaceAuth + "client-uses-full-bind-result", "true"), new XText(Convert.ToBase64String(Encoding.ASCII.GetBytes("\0" + LoginJID + "\0" + AuthCookie))) ) ); xml.ReadStartElement(NamespaceSASL + "success"); xml.Stream.Logged = false; StartXMPPStream(new XmlStream(xml.Stream), canceltoken); } }
protected void StartXMPPStream(XmlStream xml, CancellationToken canceltoken) { using (var xmppstream = xml.WriteStart(new XElement(NamespaceStream + "stream", new XAttribute("to", Domain), new XAttribute(XNamespace.Xml + "lang", "en"), new XAttribute("version", "1.0")))) { xml.ReadStartElement(NamespaceStream + "stream"); xml.Expect((rdr) => rdr.GetAttribute("from") == Domain, (rdr) => String.Format("Expected domain {0}; got domain {1}", Domain, rdr.GetAttribute("from"))); var features = xml.ReadElement(NamespaceStream + "features"); ReaderThread = new Thread(new ThreadStart(() => XMPPReader(xml, canceltoken))); ReaderThread.Start(); BeginBind(); while (!canceltoken.IsCancellationRequested) { switch (WaitHandle.WaitAny(new WaitHandle[] { canceltoken.WaitHandle, ReaderFaulted, QueriesQueued, IsReadyForSubscriptions ? SubscriptionsQueued : QueriesQueued, ResponsesQueued, MessagesQueued }, 15000)) { case 0: break; case 1: throw new AggregateException(ReaderException); case 2: ProcessQueuedQueries(xml, canceltoken); break; case 3: goto case 2; case 4: ProcessQueuedResponses(xml, canceltoken); break; case 5: ProcessQueuedMessages(xml, canceltoken); break; case WaitHandle.WaitTimeout: xml.Write(new XText(" ")); break; } } throw new OperationCanceledException(); } }
public IAsyncOperation<string> Connect() { var window = CoreWindow.GetForCurrentThread(); return Task.Run<string>(async () => { try { var socket = this.socket = new Windows.Networking.Sockets.StreamSocket(); await socket.ConnectAsync(new HostName("talk.google.com"), "5222", SocketProtectionLevel.PlainSocket); await log(window, "connected!"); reader = new DataReader(socket.InputStream); writer = new DataWriter(socket.OutputStream); reader.InputStreamOptions = InputStreamOptions.Partial; Write("<?xml version='1.0'?>\n<stream:stream to='" + server + "' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"); xmlStream = new XmlStream(); bool shouldRead = true; xmlStream.SetCallback(async (promptRead, data) => { await log(window, "data " + data); if (promptRead) { if (shouldRead) { await log(window, "prompt read"); await reader.LoadAsync(4096); var buffer = new byte[reader.UnconsumedBufferLength]; reader.ReadBytes(buffer); await log(window, "in " + Encoding.UTF8.GetString(buffer, 0, buffer.Length)); xmlStream.Update(buffer, 0, buffer.Length); } else { await log(window, "read blocked"); } } else if (data.IndexOf("stream:features") != -1) { Write("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />"); } else if (data.IndexOf("proceed") != -1) { await log(window, "SSL Strength: " + socket.Information.ProtectionLevel); writer.DetachStream(); reader.DetachStream(); shouldRead = false; if (server == "gmail.com") { await socket.UpgradeToSslAsync(SocketProtectionLevel.Ssl, new Windows.Networking.HostName("gmail.com")); } else { await socket.UpgradeToSslAsync(SocketProtectionLevel.Ssl, new Windows.Networking.HostName("talk.google.com")); } writer = new DataWriter(socket.OutputStream); reader = new DataReader(socket.InputStream); reader.InputStreamOptions = InputStreamOptions.Partial; await log(window, "upgraded!"); await log(window, "SSL Strength: " + socket.Information.ProtectionLevel); Write("<?xml version='1.0'?>\n<stream:stream to='" + server + "' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"); xmlStream.SetCallback(async (shouldRead2, data2) => { await log(window, "data " + data2); if (shouldRead2) { await reader.LoadAsync(4096); var buffer = new byte[reader.UnconsumedBufferLength]; reader.ReadBytes(buffer); await log(window, "in " + Encoding.UTF8.GetString(buffer, 0, buffer.Length)); xmlStream.Update(buffer, 0, buffer.Length); } else if (data2.Contains("X-GOOGLE-TOKEN")) { var token = Convert.ToBase64String(Encoding.UTF8.GetBytes('\x00' + this.username + '\x00' + this.auth)); Write("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='X-GOOGLE-TOKEN'>" + token + "</auth>"); } else if (data2.Contains("failure")) { if (Disconnect != null) Disconnect(this, "auth failure"); } else if (data2.Contains("success")) { var messageEvent = Message; xmlStream.SetCallback(async (shouldRead3, data3) => { if (shouldRead3) { await reader.LoadAsync(4096); var buffer = new byte[reader.UnconsumedBufferLength]; reader.ReadBytes(buffer); await log(window, "in " + Encoding.UTF8.GetString(buffer, 0, buffer.Length)); xmlStream.Update(buffer, 0, buffer.Length); } else if (data3 == "</stream:stream>") { await disconnect(window, "end of stream"); } else if (!data3.StartsWith("<stream:stream")) { await message(window, data3); } }); Write("<?xml version='1.0'?>\n<stream:stream to='" + server + "' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"); } else if (!data2.StartsWith("<stream:stream")) { await log(window, "Ummm not sure what to do with '" + data2 + "'. flee."); if (Disconnect != null) Disconnect(this, "protocol error"); } }); } else if (!data.StartsWith("<stream:stream")) { await log(window, "Ummm not sure what to do with '" + data + "'. flee."); if (Disconnect != null) Disconnect(this, "protocol error"); } }); return "ok"; } catch (Exception e) { return e.ToString(); } }).AsAsyncOperation<string>(); }
protected void ProcessInfoQuery(XmlStream xml, InfoQuery iq) { int id = InfoQueryID.NewId(); xml.Write( new XElement(NamespaceClient + "iq", new XAttribute("type", iq.Type), iq.To == null ? null : new XAttribute("to", iq.To), new XAttribute("id", id), iq.Content ) ); RunningQueries[id.ToString()] = iq; }