/// <summary> /// Deserializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> is being deserialized from.</param> /// <returns>The deserialized <see cref="T:System.Object" />.</returns> public Launcher Deserialize(Stream stream) { using (stream) { return((Launcher)DCSerializer.ReadObject(stream)); } }
/// <summary> /// Deserializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> is being deserialized from.</param> /// <returns>The deserialized <see cref="T:System.Object" />.</returns> public ApplicationSettings Deserialize(Stream stream) { using (stream) { return((ApplicationSettings)DCSerializer.ReadObject(stream)); } }
public override bool Load(string versionReuired) { try { string str; TrainsCacheStorage storage = new TrainsCacheStorage(); if (storage.Load(out str, out this.LastError)) { TrainsCache cache = DCSerializer.DeserializeWithDCS(typeof(TrainsCache), str) as TrainsCache; base.CacheTime = cache.CacheTime; this.Trains = cache.Trains; base.Version = cache.Version; if (!cache.IsValid(versionReuired, out this.LastError)) { return(false); } return(true); } } catch (Exception exception) { base.LastError = exception.Message; } return(false); }
/// <summary> /// Deserializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> is being deserialized from.</param> /// <returns>The deserialized <see cref="T:System.Object" />.</returns> public ScriptContainer Deserialize(Stream stream) { using (stream) { return((ScriptContainer)DCSerializer.ReadObject(stream)); } }
private void TISWebService_GetStateCompleted(object sender, GetStateCompletedEventArgs e) { try { //if (e.Error != null) //{ // throw new SLException(e.Error.Message + " DataProvider from server which failed"); //} //if (!e.Result) //{ // throw new SLException(e.strError + " DataProvider from server"); //} //if (this.OnData != null) //{ TISWebServiceGetStateSupportOUT result = DCSerializer.DeserializeWithDCS(typeof(TISWebServiceGetStateSupportOUT), e.strOut) as TISWebServiceGetStateSupportOUT; List <TrainWebData> onlineTrains = DCSerializer.DeserializeWithDCS(typeof(List <TrainWebData>), e.onlineTrainsData) as List <TrainWebData>; List <TrainWebData> offlineTrains = DCSerializer.DeserializeWithDCS(typeof(List <TrainWebData>), e.offlineTrainsData) as List <TrainWebData>; List <TrainWebData> onlineButNotOnTheMap = DCSerializer.DeserializeWithDCS(typeof(List <TrainWebData>), e.onlineButNotOnTheMapTrainsData) as List <TrainWebData>; //this.OnData(result, onlineTrains, offlineTrains, onlineButNotOnTheMap); //this.AddLog("DataProvider GetStateCompleted"); //} } //catch (SLException exception) //{ // this.DataError(exception.Message); // this.AddLog("DataProvider GetState error custom: " + exception.Message); //} catch (Exception exception2) { //this.DataError(exception2.Message); //this.AddLog("DataProvider GetState error: " + exception2.Message); } }
public override bool Load(string versionReuired) { try { byte[] buffer; TrainGraphCacheStorage storage = new TrainGraphCacheStorage(); if (storage.Load(out buffer, out this.LastError)) { TrainGraphCache cache = DCSerializer.DeserializeWithDCSMS(typeof(TrainGraphCache), buffer) as TrainGraphCache; base.CacheTime = cache.CacheTime; base.Curves = cache.Curves; base.Markers = cache.Markers; this.LastTrainGraphTime = cache.LastTrainGraphTime; this.OperationDate = cache.OperationDate; this.ServerTime = cache.ServerTime; base.TimeStart = cache.TimeStart; base.TimeStop = cache.TimeStop; base.Version = cache.Version; if (!cache.IsValid(versionReuired, out this.LastError)) { return(false); } return(true); } } catch (Exception exception) { base.LastError = exception.Message; } return(false); }
/// <summary> /// Deserializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> is being deserialized from.</param> /// <returns>The deserialized <see cref="T:System.Object" />.</returns> public VehicleFamily Deserialize(Stream stream) { using (stream) { return((VehicleFamily)DCSerializer.ReadObject(stream)); } }
public override bool Save() { TrainGraphCacheStorage storage = new TrainGraphCacheStorage(); byte[] data = DCSerializer.SerializeWithDCSMS(this); storage.Clear(); return(storage.Save(data, out this.LastError)); }
/// <summary> /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param> /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param> public void Serialize(Stream stream, ApplicationSettings obj) { var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings()); using (xmlWriter) { DCSerializer.WriteObject(xmlWriter, obj); } }
/// <summary> /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param> /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param> public void Serialize(Stream stream, ScriptContainer obj) { var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings()); using (xmlWriter) { DCSerializer.WriteObject(xmlWriter, obj); } }
/// <summary> /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param> /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param> public void Serialize(Stream stream, LauncherCollection obj) { var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings()); using (xmlWriter) { DCSerializer.WriteObject(xmlWriter, obj); } }
/// <summary> /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param> /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param> public void Serialize(Stream stream, VehicleFamily obj) { var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings()); using (xmlWriter) { DCSerializer.WriteObject(xmlWriter, obj); } }
public override bool Save() { TrainsCacheStorage storage = new TrainsCacheStorage(); string data = DCSerializer.SerializeWithDCS(this); storage.Clear(); bool flag = storage.Save(data, out this.LastError); base.LastError = base.LastError + string.Format(" Len={0}", data.Length); return(flag); }
/// <summary> /// Displays the root View. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> protected override void OnStartup(object sender, System.Windows.StartupEventArgs e) { IExtendedWindowManager windowManager = new ExtendedWindowManager(); ILastFMClientFactory lastFMClientFactory = new LastFMClientFactory(); IScrobblerFactory scrobblerFactory = new ScrobblerFactory(); ILocalFileFactory localFileFactory = new LocalFileFactory(); IFileOperator fileOperator = new FileOperator(); IDirectoryOperator directoryOperator = new DirectoryOperator(); ISerializer <User> userSerializer = new DCSerializer <User>(); MainViewModel mainVM = new MainViewModel(windowManager, lastFMClientFactory, scrobblerFactory, localFileFactory, fileOperator, directoryOperator, userSerializer); windowManager.ShowWindow(new SystemTrayViewModel(windowManager, mainVM)); }
private StateDataViewModel GetStateData(GetStateResponseBody webResponse) { var model = new StateDataViewModel(); model.StateResult = webResponse.GetStateResult; model.strOut = DCSerializer.DeserializeWithDCS <TISWebServiceGetStateSupportOUT>(webResponse.strOut); model.onlineTrains = DCSerializer.DeserializeWithDCS <List <TrainWebData> >(webResponse.onlineTrainsData); model.offlineTrains = DCSerializer.DeserializeWithDCS <List <TrainWebData> >(webResponse.offlineTrainsData); model.onlineButNotOnTheMap = DCSerializer.DeserializeWithDCS <List <TrainWebData> >(webResponse.onlineButNotOnTheMapTrainsData); model.trainGraphData = DCSerializer.DeserializeWithDCS <TrainGraphData>(webResponse.trainGraphData); model.Error = webResponse.strError; return(model); }
/// <summary> /// Displays the root View. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> protected override void OnStartup(object sender, System.Windows.StartupEventArgs e) { IExtendedWindowManager windowManager = new ExtendedWindowManager(); ILastFMClient client = new LastFMClient(APIKEY, APISECRET); IScrobblerFactory scrobblerFactory = new ScrobblerFactory(); ILocalFileFactory localFileFactory = new LocalFileFactory(); IFileOperator fileOperator = new FileOperator(); IDirectoryOperator directoryOperator = new DirectoryOperator(); ISerializer userSerializer = new DCSerializer(); ILogger logger = new Logger("log.txt"); IGitHubClient gitHubClient = new GitHubClient(new ProductHeaderValue("Last.fm-Scrubbler-WPF")); IProcessManager processManager = new ProcessManager(); MainViewModel mainVM = new MainViewModel(windowManager, client, scrobblerFactory, localFileFactory, fileOperator, directoryOperator, userSerializer, logger, gitHubClient, processManager); windowManager.ShowWindow(new SystemTrayViewModel(windowManager, mainVM)); }
/// <summary> /// Displays the root View. /// </summary> /// <param name="sender">Ignored.</param> /// <param name="e">Ignored.</param> protected override void OnStartup(object sender, System.Windows.StartupEventArgs e) { IExtendedWindowManager windowManager = new ExtendedWindowManager(); ILastFMClient client = new LastFMClient(APIKEY, APISECRET); IScrobblerFactory scrobblerFactory = new ScrobblerFactory(); ILocalFileFactory localFileFactory = new LocalFileFactory(); IFileOperator fileOperator = new FileOperator(); IDirectoryOperator directoryOperator = new DirectoryOperator(); ISerializer userSerializer = new DCSerializer(); ILogger logger = new Logger("log.txt"); IGitHubClient gitHubClient = new GitHubClient(new ProductHeaderValue("Last.fm-Scrubbler-WPF")); IProcessManager processManager = new ProcessManager(); IDiscogsDataBaseClient discogsClient = new DiscogsClient.DiscogsClient(new TokenAuthenticationInformation("vcrTuxlCPCANcLDUDcbGSYBxbODkeyywIUtYAMxg")); MainViewModel mainVM = new MainViewModel(windowManager, client, scrobblerFactory, localFileFactory, fileOperator, directoryOperator, userSerializer, logger, gitHubClient, processManager, discogsClient); windowManager.ShowWindow(new SystemTrayViewModel(windowManager, mainVM)); }
private byte[] queryCltSrvInfo(string extInfo, byte[] infoData) { string qryType = Global.Encoding.GetString(infoData); List <StringAndTime> cltIds; if (cltSrvInfo.TryGetValue(qryType, out cltIds)) { DCLogger.LogTrace("{0} has {1} srv in time", qryType, cltIds.Count); //if (cltIds.Count > 0) //{ // return Global.Encoding.GetBytes(cltIds[new Random().Next(0, cltIds.Count)].UniqueString); //} if (cltIds.Count > 0) { return(DCSerializer.ObjToBytes(cltIds)); } } return(new byte[0]); }
public void Post(TISWebServiceGetStateSupportIN model) { TISMonitorWebService.TISWebServiceSoapClient client = this.GetClient(); string strOut, strError, strTrainOnlineData, strTrainOfflineData, strTrainGraphData, strOnlineButNotOnMapData; using (new OperationContextScope(client.InnerChannel)) { HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty(); requestMessage.Headers["Referer"] = "http://blb.csie-data.com/ClientBin/TISMonitor.xap?version22=16010101010000000"; requestMessage.Headers["Content-Type"] = "text/xml; charset=utf-8"; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; client.GetStateCompleted += new EventHandler <GetStateCompletedEventArgs>(this.TISWebService_GetStateCompleted); //var result = client.GetState(DCSerializer.SerializeWithDCS(model), out strOut, out strTrainOnlineData, out strTrainOfflineData, out strOnlineButNotOnMapData, out strTrainOnlineData, out strError); client.GetStateAsync(DCSerializer.SerializeWithDCS(model)); //var result = client.GetStateAsync(DCSerializer.SerializeWithDCS(model);); //result.ContinueWith(x => //{ // var x2 = x.Result.Body; // var xv = x; //}); } //client. += new EventHandler<GetStateCompletedEventArgs>(this.TISWebService_GetStateCompleted); //string strIn = DCSerializer.SerializeWithDCS(model); //var result = new TISWebServiceGetStateSupportOUT(); //var resultAsync = client.GetStateAsync(strIn); //resultAsync.ContinueWith(t => //{ // result = TISWebService_GetStateCompleted(t.Result.Body); //}); //return null; //this.m_stateIn = null; }
public static Message Serialize(object anySerializableObject) { DataContractSerializer DCSerializer = new DataContractSerializer(typeof(Home)); if (anySerializableObject == typeof(Home)) { DCSerializer = new DataContractSerializer(typeof(Home)); } else if (anySerializableObject == typeof(string)) { DCSerializer = new DataContractSerializer(typeof(string)); } using (var memoryStream = new MemoryStream()) { DCSerializer.WriteObject(memoryStream, anySerializableObject); return(new Message { Data = memoryStream.ToArray() }); //return new Message { MemStream = memoryStream }; } }
/// <summary> /// Serializes the <see cref="T:System.Object" /> to a file using the specified <see cref="T:System.IO.Stream" />. /// </summary> /// <param name="stream">The <see cref="T:System.IO.Stream" /> to the specified location and what <see cref="T:System.IO.FileMode" /> it's using.</param> /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param> /// <exception cref="ArgumentNullException">stream - The stream being used can't be null!</exception> /// <exception cref="ArgumentNullException">obj - The object being serialized can't be null!</exception> public override void Serialize(Stream stream, CelestialBody obj) { if (stream == null) { throw new ArgumentNullException(nameof(stream), "The stream being used can't be null!"); } if (obj == null) { throw new ArgumentNullException(nameof(obj), "The object being serialized can't be null!"); } WriterSettings.Indent = true; WriterSettings.NewLineOnAttributes = true; Writer = XmlWriter.Create(stream, WriterSettings); using (Writer) { try { DCSerializer.WriteObject(Writer, obj); } catch (InvalidDataContractException e) { Console.WriteLine(e.Message); throw; } catch (SerializationException e) { Console.WriteLine(e.Message); throw; } catch (Exception e) { Console.WriteLine(e.Message); throw; } } }
private void OnTimerGetState() { if (!this.m_bInsideTimerForTrains) { this.m_bInsideTimerForTrains = true; TISWebServiceSoapClient client = this.GetClient(); client.GetStateCompleted += new EventHandler <GetStateCompletedEventArgs>(this.TISWebService_GetStateCompleted); TISWebServiceGetStateSupportIN tin = new TISWebServiceGetStateSupportIN { clientLastRealTimeTrainGraphTime = this.m_serverInfo.LastTrainGraphTime, getRegularTraingraphData = this.m_needToFillTrainGraph, traingraphStart = (this.m_tgd != null) ? this.m_tgd.TimeStart : DateTime.MinValue, traingraphStop = (this.m_tgd != null) ? this.m_tgd.TimeStop : DateTime.MinValue }; string strIn = DCSerializer.SerializeWithDCS(tin); if (Application.get_Current().get_Host().get_Source().AbsoluteUri.StartsWith("https") && client.Endpoint.Address.Uri.AbsoluteUri.StartsWith("http")) { client.Endpoint.Address = new EndpointAddress(client.Endpoint.Address.Uri.AbsoluteUri.Replace("http", "https")); (client.Endpoint.Binding as BasicHttpBinding).Security.Mode = BasicHttpSecurityMode.Transport; } client.GetStateAsync(strIn); } }
private async Task <StateDataViewModel> GetStateDataAsync(TISWebServiceGetStateSupportIN stateIn) { GetStateResponse result = new GetStateResponse(); using (TISWebService.TISWebServiceSoapClient client = GetClient()) using (var scope = new FlowingOperationContextScope(client.InnerChannel)) { OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = CreateRequestMessageProperty(); string strIn = DCSerializer.SerializeWithDCS(stateIn); try { var webResponse = await client.GetStateAsync(strIn).ContinueOnScope(scope); return(GetStateData(webResponse.Body)); } catch (Exception ex) { return(new StateDataViewModel { Error = ex.Message }); } } }
private byte[] updateCltSrvInfo(string extInfo, byte[] infoData) { List <CltSrvInfo> infos = DCSerializer.BytesToObj <List <CltSrvInfo> >(infoData); foreach (CltSrvInfo info in infos) { StringAndTime tnt = new StringAndTime { UniqueString = info.ClientId, LastRefresh = DateTime.Now.Ticks }; List <StringAndTime> val = new List <StringAndTime>(); val.Add(tnt); cltSrvInfo.AddOrUpdate( info.ClientSrvType, val, (key, oldValue) => { if (oldValue.Contains(tnt)) { oldValue[oldValue.IndexOf(tnt)].LastRefresh = DateTime.Now.Ticks; } else { oldValue.Add(tnt); //Console.WriteLine("List<TypeAndTime>.Count: {0}", oldValue.Count); } //foreach (TypeAndTime t in oldValue) //{ // Console.WriteLine("{0} {1}", t.TypeString, t.LastRefresh); //} //Console.WriteLine("------------------------------------------"); return(oldValue); } ); } return(new byte[0]); }
/// <summary> /// Deserializes a file using the specified <see cref="Stream" />. /// </summary> /// <param name="stream">The <see cref="Stream" /> to the specified file and what <see cref="FileMode" /> it's using.</param> /// <returns>The deserialized object.</returns> /// <exception cref="ArgumentNullException">The stream being used can't be null!</exception> public override CelestialBody Deserialize(Stream stream) { return((CelestialBody)DCSerializer.ReadObject(stream)); }
private void TISWebService_GetStateCompleted(object sender, GetStateCompletedEventArgs e) { try { if (e.Error != null) { throw new SLException(e.Error.Message + " TISMonitor from server which failed"); } if (!e.Result) { throw new SLException(e.strError + " TISMonitor from server"); } TISWebServiceGetStateSupportOUT tout = DCSerializer.DeserializeWithDCS(typeof(TISWebServiceGetStateSupportOUT), e.strOut) as TISWebServiceGetStateSupportOUT; this.m_serverInfo.LastTrainGraphTime = tout.actualRealTimeTrainGraphTime; this.m_serverInfo.ServerTime = tout.ServerTime; List <TrainWebData> onlineTrains = DCSerializer.DeserializeWithDCS(typeof(List <TrainWebData>), e.onlineTrainsData) as List <TrainWebData>; List <TrainWebData> onlineButOnTheMapTrains = DCSerializer.DeserializeWithDCS(typeof(List <TrainWebData>), e.onlineButNotOnTheMapTrainsData) as List <TrainWebData>; List <TrainWebData> offlineTrains = DCSerializer.DeserializeWithDCS(typeof(List <TrainWebData>), e.offlineTrainsData) as List <TrainWebData>; this.DrawTrains(onlineTrains, offlineTrains, onlineButOnTheMapTrains); TrainGraphData data = DCSerializer.DeserializeWithDCS(typeof(TrainGraphData), e.trainGraphData) as TrainGraphData; if (this.m_needToFillTrainGraph) { this.trainGraphControl.ResetData(); } bool needToFillTrainGraph = this.m_needToFillTrainGraph; bool flag2 = false; if (this.m_firstTrainGraphCache != null) { flag2 = true; needToFillTrainGraph = true; data.Curves = this.MergeCachedAndRealTimesCurves(this.m_firstTrainGraphCache.Curves, data.Curves); data.Markers.Clear(); data.Markers.AddRange(this.m_firstTrainGraphCache.Markers); this.m_firstTrainGraphCache = null; } this.m_tgd = data; this.trainGraphControl.TrainGraphData = this.m_tgd; this.trainGraphControl.ActualTime = this.m_serverInfo.ServerTime; this.trainGraphControl.Draw(needToFillTrainGraph); if (this.m_needToFillTrainGraph) { this.m_needToFillTrainGraph = false; } this.UpdateTrainGraphCache(this.m_tgd, this.m_serverInfo); this.UpdateTrainsCache(onlineTrains); this.SetOperationDate(tout.ServerOperationDate, !this.m_isFirstIteration || flag2); this.m_isFirstIteration = false; ErrorDlg.HelperClose(); } catch (SLException exception) { this.AddLog("TISMonitor GetState error custom: " + exception.Message); ErrorDlg.HelperShow("", exception.Message); } catch (Exception exception2) { this.AddLog("TISMonitor GetState error: " + exception2.Message); ErrorDlg.HelperShow("", exception2.Message); this.ResetTrainGraph(); } this.busyIndicator.IsBusy = false; this.m_bInsideTimerForTrains = false; }