private void Link_Click(object sender, EventArgs e) { if (IncrementCheck.Checked && String.IsNullOrWhiteSpace(IncrementStepValue.Text)) { MessageBox.Show("IncrementStep Value Required"); } else if (Events.SelectedIndex == -1) { MessageBox.Show("Please select Interval List"); } else { int index = Events.SelectedIndex; IAgCrdnEventIntervalList currentList; List <string> startTimes = new List <string>(); List <string> stopTimes = new List <string>(); string listName; if (cbStkObjects.Text.Contains("Access")) { currentList = accessEventIntervalsCollections[index]; IAgCrdn currentListRe = accessEventIntervalsCollections[index] as IAgCrdn; listName = currentListRe.Name; } else { currentList = eventIntervalsCollections[index]; IAgCrdn currentListRe = eventIntervalsCollections[index] as IAgCrdn; listName = currentListRe.Name; } IAgCrdnIntervalListResult intervals = currentList.FindIntervals(); int numIntervals = intervals.Intervals.Count; for (int i = 0; i < numIntervals; i++) { IAgCrdnInterval interval = intervals.Intervals[i]; string startStr = interval.Start.ToString(); string stopStr = interval.Stop.ToString(); startTimes.Add(startStr); stopTimes.Add(stopStr); } CommonData.sectionList[CommonData.selectedArtic].linkedToList = true; string linkedText; string line1 = "BEGIN SMARTEPOCH \n"; string line2 = "BEGIN EVENT \n"; string line3 = "Type EVENT_LINKTO \n"; string line4 = null; string line5 = null; linkedText = line1 + line2 + line3; if (typeEnum == 0) { if (cbStkObjects.Text.Contains("Access")) { for (int i = 0; i < startTimes.Count; i++) { string name = "ArticCreatorList_" + listName + "_" + "StartTime" + i.ToString(); CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name); IAgCrdnEvent timeEvent = null; if (access.Vgt.Events.Contains(name)) { foreach (IAgCrdnEvent @event in access.Vgt.Events) { // All events implement IAgCrdn interface which provides // information about the event instance and its type. IAgCrdn crdn = @event as IAgCrdn; if (crdn.Name == name) { timeEvent = @event; } } } else { timeEvent = access.Vgt.Events.Factory.CreateEventEpoch(name, "Description"); } IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch; asEpoch.Epoch = startTimes[i]; IAgCrdn currentEvent = (IAgCrdn)timeEvent; string eventName = currentEvent.Name; string pathStr = currentEvent.Path; line4 = "Name " + eventName + " \n"; line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n"; string line6 = "END EVENT" + " \n"; string line7 = "END SMARTEPOCH" + " \n"; string linkedTextFinal = linkedText + line4 + line5 + line6 + line7; CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal); } } else { for (int i = 0; i < startTimes.Count; i++) { string name = "ArticCreatorList_" + listName + "_" + "StartTime" + i.ToString(); CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name); IAgCrdnEvent timeEvent = null; if (obj.Vgt.Events.Contains(name)) { foreach (IAgCrdnEvent @event in obj.Vgt.Events) { // All events implement IAgCrdn interface which provides // information about the event instance and its type. IAgCrdn crdn = @event as IAgCrdn; if (crdn.Name == name) { timeEvent = @event; } } } else { timeEvent = obj.Vgt.Events.Factory.CreateEventEpoch(name, "Description"); } IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch; asEpoch.Epoch = startTimes[i]; IAgCrdn currentEvent = (IAgCrdn)timeEvent; string eventName = currentEvent.Name; string pathStr = currentEvent.Path; line4 = "Name " + eventName + " \n"; line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n"; string line6 = "END EVENT" + " \n"; string line7 = "END SMARTEPOCH" + " \n"; string linkedTextFinal = linkedText + line4 + line5 + line6 + line7; CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal); } } } else if (typeEnum == 1) { if (cbStkObjects.Text.Contains("Access")) { for (int i = 0; i < stopTimes.Count; i++) { string name = "ArticCreatorList_" + listName + "_" + "StopTime" + i.ToString(); CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name); IAgCrdnEvent timeEvent = null; if (access.Vgt.Events.Contains(name)) { foreach (IAgCrdnEvent @event in access.Vgt.Events) { // All events implement IAgCrdn interface which provides // information about the event instance and its type. IAgCrdn crdn = @event as IAgCrdn; if (crdn.Name == name) { timeEvent = @event; } } } else { timeEvent = access.Vgt.Events.Factory.CreateEventEpoch(name, "Description"); } IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch; asEpoch.Epoch = stopTimes[i]; IAgCrdn currentEvent = (IAgCrdn)timeEvent; string eventName = currentEvent.Name; string pathStr = currentEvent.Path; line4 = "Name " + eventName + " \n"; line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n"; string line6 = "END EVENT" + " \n"; string line7 = "END SMARTEPOCH" + " \n"; string linkedTextFinal = linkedText + line4 + line5 + line6 + line7; CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal); } } else { for (int i = 0; i < startTimes.Count; i++) { string name = "ArticCreatorList_" + listName + "_" + "StopTime" + i.ToString(); CommonData.sectionList[CommonData.selectedArtic].linkedToListInstantNames.Add(name); IAgCrdnEvent timeEvent = null; if (obj.Vgt.Events.Contains(name)) { foreach (IAgCrdnEvent @event in obj.Vgt.Events) { // All events implement IAgCrdn interface which provides // information about the event instance and its type. IAgCrdn crdn = @event as IAgCrdn; if (crdn.Name == name) { timeEvent = @event; } } } else { timeEvent = obj.Vgt.Events.Factory.CreateEventEpoch(name, "Description"); } IAgCrdnEventEpoch asEpoch = timeEvent as IAgCrdnEventEpoch; asEpoch.Epoch = stopTimes[i]; IAgCrdn currentEvent = (IAgCrdn)timeEvent; string eventName = currentEvent.Name; string pathStr = currentEvent.Path; line4 = "Name " + eventName + " \n"; line5 = "RelativePath " + pathStr.Substring(0, pathStr.IndexOf(" ")) + " \n"; string line6 = "END EVENT" + " \n"; string line7 = "END SMARTEPOCH" + " \n"; string linkedTextFinal = linkedText + line4 + line5 + line6 + line7; CommonData.sectionList[CommonData.selectedArtic].linkedToListStrings.Add(linkedTextFinal); } } } if (IncrementCheck.Checked) { CommonData.sectionList[CommonData.selectedArtic].isIncremented = true; int numSections = intervals.Intervals.Count; double startValueOG = Convert.ToDouble(CommonData.sectionList[CommonData.selectedArtic].startValue); double stepValueDouble = Convert.ToDouble(IncrementStepValue.Text); for (int i = 0; i < numSections; i++) { LinkedListSection current = new LinkedListSection(); current.startValue = Convert.ToString((startValueOG + i * stepValueDouble)); current.endValue = Convert.ToString((startValueOG + (i + 1) * stepValueDouble)); current.startTimeValue = CommonData.sectionList[CommonData.selectedArtic].startTimeValue; current.durationValue = CommonData.sectionList[CommonData.selectedArtic].durationValue; current.deadbandValue = CommonData.sectionList[CommonData.selectedArtic].deadbandValue; current.accelValue = CommonData.sectionList[CommonData.selectedArtic].accelValue; current.dutyValue = CommonData.sectionList[CommonData.selectedArtic].dutyValue; current.decelValue = CommonData.sectionList[CommonData.selectedArtic].decelValue; current.periodValue = CommonData.sectionList[CommonData.selectedArtic].periodValue; current.sectionName = CommonData.sectionList[CommonData.selectedArtic].sectionName; string section = ArticFunctions.CreateSection(CommonData.sectionList[CommonData.selectedArtic].objectName, CommonData.sectionList[CommonData.selectedArtic].articName, current.startTimeValue, current.durationValue, current.startValue, current.endValue, current.deadbandValue, current.accelValue, current.decelValue, current.dutyValue, current.periodValue, current.sectionName); current.sectionText = section; CommonData.sectionList[CommonData.selectedArtic].linkedListSections.Add(current); } } ArticFunctions.CreateFile(CommonData.fileStr); this.Close(); } }
public static List <Section> ReadFile(string fileStr) { List <Section> fileSections = new List <Section>(); using (StreamReader reader = new StreamReader(@fileStr)) { string line = null; string text = null; int count = 0; Section current = null; LinkedListSection linkedCurrent = null; line = reader.ReadLine(); int ind = 0; int islinked = 0; int linkedToList = 0; int sameLink = 0; string listName = null; string previousLinkArticName = null; int sectionsInList = 0; string linkedText = null; while ((line != null)) { ind = 0; if (line.Contains("BEGIN SMARTEPOCH")) { linkedText = null; islinked = 0; linkedToList = 0; for (int i = 0; i < 7; i++) { linkedText = linkedText + line + "\n"; line = reader.ReadLine(); } if (!linkedText.Contains("ReferenceEpoch") && !linkedText.Contains("ArticCreatorList")) { islinked = 1; } if (linkedText.Contains("ArticCreatorList")) { linkedToList = 1; int start = linkedText.IndexOf("ArticCreatorList_") + "ArticCreatorList_".Length; int stop = start + 5; //Arbitrary value until new one is assigned if (linkedText.Contains("_StartTime")) { stop = linkedText.IndexOf("_StartTime"); } else if (linkedText.Contains("_StopTime")) { stop = linkedText.IndexOf("_StopTime"); } string currentListName = linkedText.Substring(start, stop - start); if (listName == null) { listName = currentListName; sectionsInList = 1; } else if (currentListName == listName) { sectionsInList++; } else if (currentListName != listName) { listName = currentListName; sectionsInList = 1; } } } else if (line.Contains("NEW_ARTICULATION")) { //reads main section of each articulation text = "NEW_ARTICULATION \n"; current = new Section(); linkedCurrent = new LinkedListSection(); current.sectionNumber = count; //CommonData.totalSectionCount = CommonData.totalSectionCount++; line = reader.ReadLine(); current.startTimeValue = line.Split(null).Last(); linkedCurrent.startTimeValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.durationValue = line.Split(null).Last(); linkedCurrent.durationValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.deadbandValue = line.Split(null).Last(); linkedCurrent.deadbandValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.accelValue = line.Split(null).Last(); linkedCurrent.accelValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.decelValue = line.Split(null).Last(); linkedCurrent.decelValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.dutyValue = line.Split(null).Last(); linkedCurrent.dutyValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.periodValue = line.Split(null).Last(); linkedCurrent.periodValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.objectName = line.Split(null).Last(); linkedCurrent.objectName = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.articName = line.Split(null).Last(); linkedCurrent.articName = line.Split(null).Last(); text = text + line + "\n"; //checks for links so they can be added to the list if (linkedToList == 1) { if (previousLinkArticName == null) { previousLinkArticName = current.articName; count++; } else if (previousLinkArticName == current.articName) { sameLink = 1; } else { sameLink = 0; previousLinkArticName = current.articName; count++; } } else { count++; } line = reader.ReadLine(); current.startValue = line.Split(null).Last(); linkedCurrent.startValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); current.endValue = line.Split(null).Last(); linkedCurrent.endValue = line.Split(null).Last(); text = text + line + "\n"; line = reader.ReadLine(); //check for name since the old format does not have a name field if (line.Contains("NAME")) { current.sectionName = line.Substring(line.IndexOf(' ') + 1); text = text + line + "\n"; ind = 1; } current.sectionText = text; if (ind == 1) { line = reader.ReadLine(); } if (islinked == 1) { //Get link name and populate event names in section class current.linkString = linkedText; int startInd = linkedText.IndexOf("Name ") + "Name ".Length; int stopInd = linkedText.IndexOf(" \nRelativePath"); string eventName = linkedText.Substring(startInd, stopInd - startInd); current.linkTimeInstanceName = eventName; current.isLinked = true; } if (linkedToList == 1) { //Get link name and populate event names in section class current.linkString = linkedText; int startInd = linkedText.IndexOf("Name ") + "Name ".Length; int stopInd = linkedText.IndexOf(" \nRelativePath"); string eventName = linkedText.Substring(startInd, stopInd - startInd); current.linkedToListInstantNames.Add(eventName); linkedCurrent.sectionText = text; current.linkedToList = true; current.linkedListSections.Add(linkedCurrent); if (sameLink == 1) { fileSections[count - 1].linkedToListStrings.Add(linkedText); } else { fileSections.Add(current); } } else { fileSections.Add(current); } } else { line = reader.ReadLine(); } } } return(fileSections); }