protected override void LoadData(System.IO.FileInfo xmlFile) { if (xmlFile.Exists) { taskFile = xmlFile; StreamReader projectsXmlFileReader = new StreamReader(xmlFile.ToString()); string projectsInXml = projectsXmlFileReader.ReadToEnd(); projectsXmlFileReader.Close(); List <Project> list = XmlSerializationHelper.Desirialize <List <Project> >(projectsInXml); lock (dataListLock) { foreach (Project obj in list) { dataList.Add(obj.pId, obj); } } Console.WriteLine("{0} File found. {1} Entries", xmlFile.ToString(), dataList.Count); } else { Console.WriteLine("todos.xml File not found."); } }
protected override void ProcessPUT(ConnectorBase Connector, Package package) { switch (package.Event) { case (int)EventMapping.DataItemChanged_13: try { DataItemChanged dataItemChanged = XmlSerializationHelper.Desirialize <DataItemChanged>(package.Data); lock (dataListLock) { Todo.SetPropValue(dataList[dataItemChanged.PK], dataItemChanged.PropertyName, dataItemChanged.Value); } } catch (Exception ex) { RaiseLogEvent(LogType.Error, "TodoNetList.ProcessPUT()" + ex.Message); } break; case (int)EventMapping.CurrentItemChanged_15: CurrentItemChanged putParams = XmlSerializationHelper.Desirialize <CurrentItemChanged>(package.Data); if (putParams.Type == typeof(Todo).ToString()) { RaiseCurrentItemChangedEvent(putParams.PK); } break; default: break; } //src.GetType().GetProperty(propName).SetValue(src, value); //base.ProcessPUT(t14Lab.MessageTree.Connector, package); }
public override bool Receive(out Package result) { bool ok = false; result = new Package(); if (clientStream.DataAvailable) { byte[] buffer = new byte[123]; int numberOfBytesRead = 0; do { numberOfBytesRead = clientStream.Read(buffer, 0, buffer.Length); recivedData = String.Join(string.Empty, new String[] { recivedData, Encoding.UTF8.GetString(buffer, 0, numberOfBytesRead) }); int end = recivedData.IndexOf("</Package>"); if (end > 0) { end += 10; ok = true; string packageString = recivedData.Substring(0, end); recivedData = recivedData.Substring(end, recivedData.Length - end); result = XmlSerializationHelper.Desirialize <Package>(packageString); return(ok); } }while (clientStream.DataAvailable); } return(ok); }
private void HandlePOST(Package package) { if (package.Event == (int)EventMapping.DataItemAdded_18) { DataItemAdded postParams = XmlSerializationHelper.Desirialize <DataItemAdded>(package.Data); DataItemAdded(postParams.PK, postParams.Id, postParams.Type); } }
private void HandleDelete(Package package) { if (package.Event == (int)EventMapping.DataItemDeleted_19) { DataItemDeleted deleteParams = XmlSerializationHelper.Desirialize <DataItemDeleted>(package.Data); DataItemDeleted(deleteParams.PK, deleteParams.Type); } }
public static SortableBindingList <T> GetBindingListFromXmlFile <T>(string fileName) { FileInfo projectListXmlFile = new FileInfo(fileName); List <T> projects = new List <T>(); if (projectListXmlFile.Exists) { StreamReader projectsXmlFileReader = new StreamReader(fileName); string projectsInXml = projectsXmlFileReader.ReadToEnd(); projectsXmlFileReader.Close(); projects = XmlSerializationHelper.Desirialize <List <T> >(projectsInXml); } SortableBindingList <T> result = new SortableBindingList <T>(projects); return(result); }
protected override void ProcessDELETE(ConnectorBase Connector, Package package) { try { DataItemDeleted dataItemDeleted = XmlSerializationHelper.Desirialize <DataItemDeleted>(package.Data); lock (dataListLock) { dataList.Remove(dataItemDeleted.PK); } } catch (Exception ex) { RaiseLogEvent(LogType.Error, "TodoNetList.ProcessDELETE()" + ex.Message); } //base.ProcessDELETE(t14Lab.MessageTree.Connector, package); }
private void HandleResponse(Package package) { if (package.Sender == 10) { if (package.Event == 10) { Todo newTodo = XmlSerializationHelper.Desirialize <Todo>(package.Data); lock (todoLock) TodoList.Add(newTodo); } else if (package.Event == 9) { List <Todo> newTodos = XmlSerializationHelper.Desirialize <List <Todo> >(package.Data); lock (todoLock) foreach (Todo newTodo in newTodos) { TodoList.Add(newTodo); } } else if (package.Event == 2) { //fillMode = false; //sw.Stop();//int packagesCount = 1000;//MessageBox.Show(string.Format("{0} Packages in {1} Milliseconds ~ {2} packages per millisecond and {3} packages per second.", packagesCount, sw.ElapsedMilliseconds, packagesCount / sw.ElapsedMilliseconds, (packagesCount / sw.ElapsedMilliseconds) * 1000)); } } else if (package.Sender == 12) { if (package.Event == 10) { Project newProject = XmlSerializationHelper.Desirialize <Project>(package.Data); lock (todoLock) ProjectList.Add(newProject); } else if (package.Event == 9) { List <Project> newTodos = XmlSerializationHelper.Desirialize <List <Project> >(package.Data); lock (projectLock) foreach (Project newTodo in newTodos) { ProjectList.Add(newTodo); } } else if (package.Event == 2) { //sw.Stop();//int packagesCount = 1000;//MessageBox.Show(string.Format("{0} Packages in {1} Milliseconds ~ {2} packages per millisecond and {3} packages per second.", packagesCount, sw.ElapsedMilliseconds, packagesCount / sw.ElapsedMilliseconds, (packagesCount / sw.ElapsedMilliseconds) * 1000)); } } }
protected override void ProcessPOST(ConnectorBase Connector, Package package) { try { DataItemAdded projectAdded = XmlSerializationHelper.Desirialize <DataItemAdded>(package.Data); Project newProject = new Project() { pId = projectAdded.PK }; lock (dataListLock) { dataList.Add(newProject.pId, newProject); } } catch (Exception ex) { RaiseLogEvent(LogType.Error, "ProjectNetList.ProcessPOST()" + ex.Message); } //base.ProcessPOST(t14Lab.MessageTree.Connector, package); }
protected override void LoadData(System.IO.FileInfo xmlFile) { if (xmlFile.Exists) { StreamReader projectsXmlFileReader = new StreamReader(xmlFile.ToString()); string projectsInXml = projectsXmlFileReader.ReadToEnd(); projectsXmlFileReader.Close(); List <Todo> list = XmlSerializationHelper.Desirialize <List <Todo> >(projectsInXml); lock (dataListLock) { foreach (Todo obj in list) { dataList.Add(obj.pId, obj); } } RaiseLogEvent(LogType.Info, string.Format("{0} File found. {1} Entries", xmlFile.ToString(), dataList.Count)); } else { RaiseLogEvent(LogType.Error, string.Format("{0} File not found.", xmlFile.ToString())); } }
protected override void ProcessPOST(ConnectorBase Connector, Package package) { try { DataItemAdded todoAdded = XmlSerializationHelper.Desirialize <DataItemAdded>(package.Data); Todo newTodo = new Todo() { pId = todoAdded.PK }; if (newTodo.pId == null) { newTodo.pId = Guid.NewGuid(); } lock (dataListLock) { dataList.Add(newTodo.pId, newTodo); } } catch (Exception ex) { RaiseLogEvent(LogType.Error, "TodoNetList.ProcessPOST()" + ex.Message); } //base.ProcessPOST(t14Lab.MessageTree.Connector, package); }
private void HandlePUT(Package package) { if (package.Event == (int)EventMapping.DataItemChanged_13) { DataItemChanged putParams = XmlSerializationHelper.Desirialize <DataItemChanged>(package.Data); if (putParams.Type == typeof(Todo).ToString()) { Todo currentTodo = null; foreach (Todo todo in TodoList) { if (todo.pId == putParams.PK) { currentTodo = todo; break; } } Todo.SetPropValue(currentTodo, putParams.PropertyName, putParams.Value); currentTodo.DidNotReadLoL = true; } else if (putParams.Type == typeof(Project).ToString()) { Project currentProject = null; foreach (Project project in ProjectList) { if (project.pId == putParams.PK) { currentProject = project; break; } } Project.SetPropValue(currentProject, putParams.PropertyName, putParams.Value); currentProject.DidNotReadLoL = true; selectedProject = currentProject; } } else if (package.Event == (int)EventMapping.CurrentItemChanged_15) { CurrentItemChanged putParams = XmlSerializationHelper.Desirialize <CurrentItemChanged>(package.Data); if (putParams.Type == typeof(Todo).ToString()) { object pk = TodoList.Where(todo => todo.pId == putParams.PK).First(); SelectedDataItemChanged(pk, putParams.Type); selectedTodo = (Todo)pk; } else if (putParams.Type == typeof(Project).ToString()) { object pk = ProjectList.Where(project => project.pId == putParams.PK).First(); SelectedDataItemChanged(pk, putParams.Type); selectedProject = (Project)pk; } else { throw new Exception("Unknown Type"); } } else if (package.Event == (int)EventMapping.DataItemBeginChanging_16) { DataItemBeginChanging putParams = XmlSerializationHelper.Desirialize <DataItemBeginChanging>(package.Data); DataItemStartChanging(putParams); } else if (package.Event == (int)EventMapping.DataItemEndChanging_17) { DataItemEndChanging putParams = XmlSerializationHelper.Desirialize <DataItemEndChanging>(package.Data); DataItemEndChanging(putParams); } }