private void openViewFileToolStripMenuItem_Click(object sender, EventArgs args) { if (subViewControl1.myComponents.CommActiveFlg == true) { MessageBox.ShowWarning("Stop communication."); } else { FileChooserDialog fcd = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); fcd.Filter = new FileFilter(); fcd.Filter.AddPattern("*.xml"); if (fcd.Run() == (int)ResponseType.Accept) { string pathName = fcd.Filename; XmlSerializer serializer = new XmlSerializer(typeof(ViewSetting)); ViewSetting deserializedData = new ViewSetting(); try { System.IO.StreamReader reader = new System.IO.StreamReader(pathName); deserializedData = (ViewSetting)serializer.Deserialize(reader); reader.Close(); } catch (Exception ex) { deserializedData = null; MessageBox.ShowWarning(ex.Message); } if (deserializedData != null) { subViewControl1.loadViewSettingFile(deserializedData); subViewControl1.checkTreeViewCells(); string fileName = System.IO.Path.GetFileNameWithoutExtension(pathName); string viewName = subViewControl1.getViewName(fileName); if (viewName != null) { this.Title = viewName + " - " + WINDOW_TITLE; } } } fcd.Destroy(); } }
private void saveViewFileToolStripMenuItem_Click(object sender, EventArgs e) { FileChooserDialog fcd = new FileChooserDialog("Choose the file to save", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept); string text = subViewControl1.getViewSettingFileName(); fcd.CurrentName = text + ".xml"; fcd.Filter = new FileFilter(); fcd.Filter.AddPattern("*.xml"); if (fcd.Run() == (int)ResponseType.Accept) { var tmpVSettingFactor = new ViewSetting(); foreach (var factor in subViewControl1.myComponents.ViewSettingList) { foreach (var item in factor.DataSetting) { tmpVSettingFactor.DataSetting.Add(item); } } try { System.IO.FileStream fs = new System.IO.FileStream(fcd.Filename, System.IO.FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(ViewSetting)); serializer.Serialize(fs, tmpVSettingFactor); fs.Close(); string fileName = System.IO.Path.GetFileNameWithoutExtension(fcd.Filename); string viewName = subViewControl1.getViewName(fileName); if (viewName != null) { this.Title = viewName + " - " + WINDOW_TITLE; } } catch (Exception ex) { MessageBox.ShowWarning(ex.Message); } } fcd.Destroy(); }
private void MainForm_Load(object sender, EventArgs e) { subViewControl1.commonInitialRoutine(); var tmpVSettingFactor = new ViewSetting(); for (int i = 0; i < 32; i++) { tmpVSettingFactor.DataSetting.Add(new DataSetting()); } tmpVSettingFactor.DataSetting[0].Group = SubViewControl.GROUP_TEMPORARY_TAG; subViewControl1.loadViewSettingFile(tmpVSettingFactor); }
private void DefaultViewSettings() { var tmpSetting = new ViewSetting(); for (int i = 0; i < 16; i++) { tmpSetting.Settings.Add(new DataSetting()); } tmpSetting.Settings[0].Group = "x:Test"; subViewCtrl.LoadViewSettingFile(tmpSetting); var tmp = new ViewFileName(); this.Text = makeWindowTitle(tmp); }
public RemoteControl(BusinessLogic tmp) { remote = new TCPListenerResource(); remote.Delimiter = "\r\n"; logic = tmp; requestTask = BusinessLogic.CommunicationTasks.Nothing; viewSettingBuffer = new ViewSetting(); requestTask = BusinessLogic.CommunicationTasks.Nothing; logTextDataBuff = new ConcurrentQueue <string>(); logDataBuffSize = 500; DumpDataBuff = new ConcurrentQueue <byte>(); requestTask = BusinessLogic.CommunicationTasks.Nothing; }
private bool loadViewFile(string path) { if (string.IsNullOrEmpty(path)) { return(false); } bool isSuccess = false; ViewSetting deserializedData = new ViewSetting(); try { using (System.IO.StreamReader reader = new System.IO.StreamReader(path, Encoding.GetEncoding("utf-8"))) { XmlSerializer serializer = new XmlSerializer(typeof(ViewSetting)); deserializedData = (ViewSetting)serializer.Deserialize(reader); } } catch (Exception) { deserializedData = null; } if (deserializedData != null) { subViewCtrl.LoadViewSettingFile(deserializedData); string fileName = System.IO.Path.GetFileNameWithoutExtension(path); ViewFileName tmp = new ViewFileName(); if (!ViewFileName.GetNameFromOldFormat(fileName, out tmp)) { ViewFileName.GetName(fileName, out tmp); } this.Text = makeWindowTitle(tmp); isSuccess = true; } return(isSuccess); }
public ViewSetting(ViewSetting data) { DataSetting = new List <DataSetting>(data.DataSetting); }
public void loadViewSettingFile( ViewSetting tmp ) { myComponents.ViewSettingList = new List<ViewSetting>(); var pageList = new List<string>(); string groupName = null; var tmpVSettingFactor = new ViewSetting(); foreach (var factor in tmp.DataSetting) { if (groupName == null) { groupName = factor.Group; tmpVSettingFactor.DataSetting.Add(factor); if (groupName == null) { groupName = SubViewControl.GROUP_TEMPORARY_TAG; tmpVSettingFactor.DataSetting[0].Group = groupName; } pageList.Add(groupName); } else if ((factor.Group != null) && (factor.Group != groupName)) { groupName = factor.Group; pageList.Add(groupName); myComponents.ViewSettingList.Add(tmpVSettingFactor); tmpVSettingFactor = new ViewSetting(); tmpVSettingFactor.DataSetting.Add(factor); } else { tmpVSettingFactor.DataSetting.Add(factor); } } if (tmpVSettingFactor != null) { myComponents.ViewSettingList.Add(tmpVSettingFactor); } pageValComboBox.SelectedIndexChanged -= new System.EventHandler(pageValComboBox_SelectedIndexChanged); pageValComboBox.Items.Clear(); foreach (var factor in pageList) { pageValComboBox.Items.Add(factor); } pageValComboBox.SelectedIndexChanged += new System.EventHandler(pageValComboBox_SelectedIndexChanged); if ((myComponents.MapList != null) && (myComponents.MapList.Count > 0)) { MessageBox.Show("Purge map file info", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Warning); myComponents.MapList = new List<MapFactor>(); myComponents.ValidMapPath = null; myComponents.ValidMapLastWrittenDate = DateTime.MinValue; AutoCompleteSourceForVariable = new AutoCompleteStringCollection(); } pageValComboBox.SelectedIndex = 0; }
private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripItem item = e.ClickedItem; var name = item.ToString(); Int32 rowValue = dataGridView.Rows.GetFirstRow(DataGridViewElementStates.Selected); if (rowValue < 0) { return; } switch (name) { case "Delete Row": dataGridView.Rows.RemoveAt(rowValue); this.dataGridView.ClearSelection(); break; case "Insert Row": { DataSetting factor = new DataSetting(); factor.Type = numeralSystem.HEX; myComponents.ViewSettingList[pageValComboBox.SelectedIndex].DataSetting.Insert(rowValue, factor); this.dataGridView.ClearSelection(); } break; case "Copy Upper Row": { if (rowValue > 0) { DataSetting factor = new DataSetting(myComponents.ViewSettingList[pageValComboBox.SelectedIndex].DataSetting[rowValue - 1]); factor.Group = null; myComponents.ViewSettingList[pageValComboBox.SelectedIndex].DataSetting.Insert(rowValue, factor); this.dataGridView.ClearSelection(); } } break; case "Delete This Page": { var index = pageValComboBox.SelectedIndex; if (index != 0) { DialogResult result = MessageBox.Show("Do you want to delete this page?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { this.dataGridView.DataSource = null; myComponents.ViewSettingList.RemoveAt(index); pageValComboBox.Items.RemoveAt(index); pageValComboBox.SelectedIndex = index - 1; } } else { MessageBox.Show("Forbidden to delete first page.", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } break; case "Insert Page": { DialogResult result = MessageBox.Show("Do you want to insert a page next to this page?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { var index = pageValComboBox.SelectedIndex; string groupName = GROUP_TEMPORARY_TAG; var tmpVSettingFactor = new ViewSetting(); for (int i = 0; i < COLUMN_NUM; i++) { tmpVSettingFactor.DataSetting.Add(new DataSetting()); } tmpVSettingFactor.DataSetting[0].Group = groupName; myComponents.ViewSettingList.Insert((index + 1), tmpVSettingFactor); pageValComboBox.Items.Insert((index + 1), groupName); pageValComboBox.SelectedIndex = index + 1; } } break; case "Copy This Page": { DialogResult result = MessageBox.Show("Do you want to copy this page to next page?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { var index = pageValComboBox.SelectedIndex; string groupName = GROUP_TEMPORARY_TAG; var tmpVSettingFactor = new ViewSetting(); foreach (var row in myComponents.ViewSettingList[index].DataSetting) { DataSetting factor = new DataSetting(row); tmpVSettingFactor.DataSetting.Add(factor); } tmpVSettingFactor.DataSetting[0].Group = groupName; myComponents.ViewSettingList.Insert((index + 1), tmpVSettingFactor); pageValComboBox.Items.Insert((index + 1), groupName); pageValComboBox.SelectedIndex = index + 1; } } break; default: break; } }
private void saveViewFileToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); string defaultFileName = string.Empty; if (!string.IsNullOrEmpty(pathViewFileName)) { string fileName = System.IO.Path.GetFileNameWithoutExtension(pathViewFileName); ViewFileName tmp = new ViewFileName(); if (!ViewFileName.GetNameFromOldFormat(fileName, out tmp)) { ViewFileName.GetName(fileName, out tmp); } tmp.SoftwareVersion = subViewCtrl.GetTargetVersionName(); defaultFileName = ViewFileName.MakeFileName(tmp); } else { var tmp = new ViewFileName(); tmp.SettingName = "TestSetting001"; tmp.SoftwareVersion = subViewCtrl.GetTargetVersionName(); defaultFileName = ViewFileName.MakeFileName(tmp); } sfd.Title = "Save View File"; //sfd.InitialDirectory = @"D:\"; sfd.FileName = defaultFileName; sfd.Filter = "xml File(*.xml)|*.xml|All Files(*.*)|*.*"; sfd.FilterIndex = 1; if (!string.IsNullOrEmpty(pathViewFileName)) { sfd.InitialDirectory = System.IO.Path.GetDirectoryName(pathViewFileName); } if (sfd.ShowDialog() == DialogResult.OK) { var tmpViewSetting = new ViewSetting(); foreach (var setting in subViewCtrl.ViewSettingList) { foreach (var factor in setting.Settings) { tmpViewSetting.Settings.Add(factor); } } try { using (System.IO.FileStream fs = new System.IO.FileStream(sfd.FileName, System.IO.FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(ViewSetting)); serializer.Serialize(fs, tmpViewSetting); } string fileName = System.IO.Path.GetFileNameWithoutExtension(sfd.FileName); ViewFileName tmp = new ViewFileName(); ViewFileName.GetName(fileName, out tmp); this.Text = makeWindowTitle(tmp); pathViewFileName = sfd.FileName; } catch (Exception ex) { MessageBox.Show(ex.Message); } } sfd.Dispose(); }
private void openViewFileToolStripMenuItem_Click(object sender, EventArgs e) { if (subViewControl1.myComponents.CommActiveFlg == true) { MessageBox.Show("Stop communication.", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { OpenFileDialog ofd = new OpenFileDialog(); ofd.FileName = "test.xml"; // ofd.InitialDirectory = @"D:\"; ofd.Filter = "ViewSetting File(*.xml)|*.xml|All Files(*.*)|*.*"; ofd.FilterIndex = 1; ofd.Title = "Open View File"; ofd.RestoreDirectory = true; ofd.CheckFileExists = true; ofd.CheckPathExists = true; if (ofd.ShowDialog() == DialogResult.OK) { string path = ofd.FileName; XmlSerializer serializer = new XmlSerializer(typeof(ViewSetting)); ViewSetting deserializedData = new ViewSetting(); try { StreamReader reader = new StreamReader(path); deserializedData = (ViewSetting)serializer.Deserialize(reader); reader.Close(); } catch (Exception ex) { deserializedData = null; MessageBox.Show(ex.Message); } if (deserializedData != null) { subViewControl1.loadViewSettingFile(deserializedData); string name = subViewControl1.getViewName(path); if (name != null) { this.Text = name + " - " + this.Text; } } } ofd.Dispose(); } }
private void saveViewFileToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); string defaultFileName = subViewControl1.getViewSettingFileName(); sfd.Title = "Save View File"; //sfd.InitialDirectory = @"D:\"; sfd.FileName = defaultFileName; sfd.Filter = "ViewSetting File(*.xml)|*.xml|All Files(*.*)|*.*"; sfd.FilterIndex = 1; sfd.RestoreDirectory = true; sfd.ShowHelp = true; sfd.CreatePrompt = true; if (sfd.ShowDialog() == DialogResult.OK) { var tmpVSettingFactor = new ViewSetting(); foreach (var factor in subViewControl1.myComponents.ViewSettingList) { foreach (var item in factor.DataSetting) { tmpVSettingFactor.DataSetting.Add(item); } } try { FileStream fs = new FileStream(sfd.FileName, FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(ViewSetting)); serializer.Serialize(fs, tmpVSettingFactor); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { } sfd.Dispose(); }
private string AnalyzeCommand(string message) { string failedText = "Failed"; string okText = "OK"; string busyText = "Busy"; string emptyText = "Empty"; string command = string.Empty; string parameters = string.Empty; string answer = failedText; var splitIndex = message.IndexOf(' '); if (splitIndex != -1) { command = message.Substring(0, splitIndex); parameters = message.Substring(splitIndex + 1, (message.Length - command.Length - 1)); } else { command = message; } switch (command) { case CommandResource: var config = new Configuration(); if (ValidateCommunicationResource(parameters, out config)) { if (logic.UpdateResource(config)) { answer = okText; } } break; case CommandOpen: answer = busyText; if (requestTask != BusinessLogic.CommunicationTasks.Open) { requestTask = BusinessLogic.CommunicationTasks.Open; if (!logic.IsCommAvailable) { logic.ClearWaitingTasks(); logic.EnqueueTask(BusinessLogic.CommunicationTasks.Open); logic.CancelCurrentTask(); } } else { if (logic.TaskState != BusinessLogic.CommunicationTasks.Open) { requestTask = BusinessLogic.CommunicationTasks.Nothing; if (logic.IsCommAvailable) { answer = okText; } else { answer = failedText; } } } break; case CommandClose: if (requestTask == BusinessLogic.CommunicationTasks.Open) { requestTask = BusinessLogic.CommunicationTasks.Nothing; } logic.ClearWaitingTasks(); logic.EnqueueTask(BusinessLogic.CommunicationTasks.Close); logic.CancelCurrentTask(); answer = okText; break; case CommandInitialize: logic.EnqueueTask(BusinessLogic.CommunicationTasks.Initialize); DeviceVersion = string.Empty; answer = okText; break; case CommandGetVersion: if (string.IsNullOrEmpty(DeviceVersion)) { answer = busyText; } else { answer = okText + " " + DeviceVersion; } break; case CommandRegister: if (AddDataSetting(parameters)) { answer = okText; } break; case CommandAdapt: RegisterLogConfigCallBack?.Invoke(viewSettingBuffer); viewSettingBuffer = new ViewSetting(); answer = okText; break; case CommandPage: if (logic.TaskState == BusinessLogic.CommunicationTasks.Logging) { answer = busyText; } else { int pageValue; if (!int.TryParse(parameters, out pageValue)) { answer = failedText; } else { if (ChangePageCallBack != null) { if (!ChangePageCallBack(pageValue)) { answer = failedText; } else { ClearLogTextDataBuff(); answer = okText; } } } } break; case CommandTimeStep: int timeStep; if (int.TryParse(parameters, out timeStep)) { if (timeStep < BusinessLogic.TimeStepMin) { timeStep = BusinessLogic.TimeStepMin; } else if (timeStep > BusinessLogic.TimeStepMax) { timeStep = BusinessLogic.TimeStepMax; } ChangeTimeStepCallBack?.Invoke(timeStep); logic.LogTimeStep = (uint)timeStep; answer = okText; } break; case CommandLogStart: logic.EnqueueTask(BusinessLogic.CommunicationTasks.Config); logic.EnqueueTask(BusinessLogic.CommunicationTasks.Logging); ClearLogTextDataBuff(); answer = okText; break; case CommandLogStop: if (logic.TaskState == BusinessLogic.CommunicationTasks.Logging) { logic.ClearWaitingTasks(); logic.CancelCurrentTask(); } answer = okText; break; case CommandLogGet: string data; if (!logTextDataBuff.TryDequeue(out data)) { if (logic.TaskState == BusinessLogic.CommunicationTasks.Logging) { answer = busyText; } else { answer = emptyText; } } else { answer = okText + " " + data; } break; case CommandLogWrite: if (logic.TaskState == BusinessLogic.CommunicationTasks.Logging) { var wrParam = new BusinessLogic.DataParameter(); if (IsValidWriteSetting(parameters, out wrParam)) { logic.EditValue(wrParam); answer = okText; } } break; case CommandLogSize: if (logic.TaskState == BusinessLogic.CommunicationTasks.Logging) { answer = busyText; } else { int size; if (int.TryParse(parameters, out size)) { if (size > 0) { ClearLogTextDataBuff(); logDataBuffSize = size; answer = okText; } } } break; case CommandDumpSet: if (requestTask == BusinessLogic.CommunicationTasks.Dump) { answer = busyText; } else { var param = new BusinessLogic.DataParameter(); if (ValidateDumpConfigrations(parameters, out param)) { requestTask = BusinessLogic.CommunicationTasks.Dump; logic.DumpConfigParameter = param; logic.ClearWaitingTasks(); logic.EnqueueTask(BusinessLogic.CommunicationTasks.Dump); logic.CancelCurrentTask(); answer = okText; } } break; case CommandDumpGet: if (logic.TaskState == BusinessLogic.CommunicationTasks.Dump) { answer = busyText; } else { requestTask = BusinessLogic.CommunicationTasks.Nothing; if (DumpDataBuff.Count <= 0) { answer = emptyText; } else { answer = okText + " "; int count = 0; while (count < 16) { byte abyte; if (DumpDataBuff.TryDequeue(out abyte)) { answer += abyte.ToString("X2"); count++; } else { break; } } } } break; case CommandBypassRequest: if (requestTask == BusinessLogic.CommunicationTasks.Bypass) { answer = busyText; } else { if (System.Text.RegularExpressions.Regex.IsMatch(parameters, @"\A\b[0-9a-fA-F]+\b\Z") && (parameters.Length % 2) == 0) { requestTask = BusinessLogic.CommunicationTasks.Bypass; logic.BypassRequest.Enqueue(parameters); logic.ClearWaitingTasks(); logic.EnqueueTask(BusinessLogic.CommunicationTasks.Bypass); logic.CancelCurrentTask(); answer = okText; } } break; case CommandBypassResponse: if (logic.TaskState == BusinessLogic.CommunicationTasks.Bypass) { answer = busyText; } else { requestTask = BusinessLogic.CommunicationTasks.Nothing; string outputText; if (logic.BypassResponse.TryDequeue(out outputText)) { answer = okText + " " + outputText; } else { answer = emptyText; } } break; default: break; } return(answer); }
public ViewSetting(ViewSetting vs) { Settings = new BindingList <DataSetting>(vs.Settings); }
public ViewSetting( ViewSetting data) { DataSetting = new BindingList<DataSetting>(data.DataSetting); }