private string _curServer, _curDatabase, _curPath; //Track current states #endregion Fields #region Constructors // Initialization public MainForm(MainControl main) { InitializeComponent(); this.control = main; control.setMainForm(this); importing = false; isAdministrator = false; currentTreeSearch = ""; currentSearchResults = new AFNamedCollectionList<AFElement>(); }
static void PrintElementTemplates(AFDatabase database) { Console.WriteLine("Print Element Templates"); AFNamedCollectionList <AFElementTemplate> elemTemplates = database.ElementTemplates.FilterBy(typeof(AFElement)); foreach (AFElementTemplate elemTemp in elemTemplates) { string[] categories = new string[elemTemp.Categories.Count]; int i = 0; foreach (AFCategory category in elemTemp.Categories) { categories[i++] = category.Name; } // Note: An alternative approach is to use CategoriesString string categoriesString = string.Join(",", categories); Console.WriteLine("Name: {0}, Categories: {1}", elemTemp.Name, elemTemp.CategoriesString); } Console.WriteLine(); }
private List <string> FindChildElementTemplates() { List <string> _templateNames = new List <string>(); try { if (dataReference.Attribute != null) { AFElement element = (AFElement)dataReference.Attribute.Element; AFNamedCollectionList <AFElement> childElements = AFElement.FindElements(element.Database, element, "*", AFSearchField.Name, false, AFSortField.Name, AFSortOrder.Ascending, 1000000); if (childElements != null && childElements.Count > 0) { foreach (AFElement childElement in childElements) { if (!(_templateNames.Contains(childElement.Template.Name))) { _templateNames.Add(childElement.Template.Name); } } } } if (dataReference.Template != null) { foreach (AFElementTemplate template in dataReference.Database.ElementTemplates) { _templateNames.Add(template.Name); } } _templateNames.Sort(); return(_templateNames); } catch { return(null); } }
public void Run() { PISystems piSystems = new PISystems(); PISystem piSystem = piSystems["<AFSERVER>"]; AFDatabase afDatabase = piSystem.Databases["Basic-AFSDK-Sample"]; const int pageSize = 1000; int startIndex = 0; int returnLimit = 100000; do { AFElementTemplate efTemplate = afDatabase.ElementTemplates["BasicEventFrameTemplate"]; // Get event frames that started the past two days. AFNamedCollectionList <AFEventFrame> eventFrames = AFEventFrame.FindEventFrames( database: afDatabase, searchRoot: null, startTime: "t-2d", startIndex: startIndex, maxCount: pageSize, searchMode: AFEventFrameSearchMode.ForwardFromStartTime, nameFilter: "*", referencedElementNameFilter: "BoilerA", elemCategory: null, elemTemplate: efTemplate, searchFullHierarchy: true); foreach (AFEventFrame ef in eventFrames) { //Note: We should make a bulk call on the attribute values via AFAttributeList if we had many event frames. Console.WriteLine("Name: {0}, Start: {1}, End: {2}, Max temp: {3}", ef.Name, ef.StartTime, ef.EndTime, ef.Attributes["Maximum temperature"].GetValue()); } startIndex += pageSize; } while (startIndex < returnLimit); }
/// <summary> /// Removes the analysis from the AF Database if it exists. /// </summary> /// <param name="name">The name of the analysis to remove.</param> /// <param name="output">The output logger used for writing messages.</param> public void RemoveAnalysisIfExists(string name, ITestOutputHelper output) { Contract.Requires(output != null); AFAnalysis preCheckAnalysis; using (var search = new AFAnalysisSearch(AFDatabase, string.Empty, $"Name:'{name}'")) { var coll = new AFNamedCollectionList <AFAnalysis>(search.FindObjects()); preCheckAnalysis = coll[name]; } if (preCheckAnalysis != null) { output.WriteLine($"Analysis [{preCheckAnalysis}] exists, delete it."); preCheckAnalysis.Delete(); preCheckAnalysis.CheckIn(); } else { output.WriteLine($"Analysis [{name}] does not exist, can not be deleted."); } }
// Load and Closing private void PItoMatlabForm_Load(object sender, EventArgs e) { startDTP.Text = "*-2h"; endDTP.Text = "*"; // Log System Initialization logForm = new LogDialog(control, this); // Initialize AFViewControllers AFNamedCollectionList <AFAttribute> atts = new AFNamedCollectionList <AFAttribute>(); AFNamedCollectionList <AFEventFrame> frames = new AFNamedCollectionList <AFEventFrame>(); avcAttributes.AFSetObject(atts, null, null, null); avcAttributes.ContextMenuStrip = null; avcEventAttributes.AFSetObject(atts, null, null, null); avcEventFrames.AFSetObject(frames, null, null, null); //Initialize Data Preference Dialog dataPrefDialog = new DataPreferences(this); //Control AfTreeView1.ContextMenuSTrip afmenu = afTreeViewElements.ContextMenuStrip as AFMenu; if (afmenu != null) { // Event raised when the menu control is opening. afmenu.Opening += new CancelEventHandler(afmenu_Opening); } //Connect the Database Picker to the System Picker afDatabasePicker1.SystemPicker = afServerPicker; //Initialize Connection initializeAfServerPicker(); Status("Loaded from the AF System " + _curServer); }
// Load and Closing private void PItoMatlabForm_Load(object sender, EventArgs e) { startDTP.Text = "*-2h"; endDTP.Text = "*"; // Log System Initialization logForm = new LogDialog(control,this); // Initialize AFViewControllers AFNamedCollectionList<AFAttribute> atts = new AFNamedCollectionList<AFAttribute>(); AFNamedCollectionList<AFEventFrame> frames = new AFNamedCollectionList<AFEventFrame>(); avcAttributes.AFSetObject(atts, null, null, null); avcAttributes.ContextMenuStrip = null; avcEventAttributes.AFSetObject(atts, null, null, null); avcEventFrames.AFSetObject(frames, null, null, null); //Initialize Data Preference Dialog dataPrefDialog = new DataPreferences(this); //Control AfTreeView1.ContextMenuSTrip afmenu = afTreeViewElements.ContextMenuStrip as AFMenu; if (afmenu != null) { // Event raised when the menu control is opening. afmenu.Opening += new CancelEventHandler(afmenu_Opening); } //Connect the Database Picker to the System Picker afDatabasePicker1.SystemPicker = afServerPicker; //Initialize Connection initializeAfServerPicker(); Status("Loaded from the AF System " + _curServer); }
/// <summary> /// If it is a new search, the elements that fit the criteria are collected and the first is selected. /// Else it iterates through the collection of elements and expands to the node. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bSearchElements_Click(object sender, EventArgs e) { currentTreeSearchTimes++; if (currentTreeSearch == tbElementSearchName.Text) { if (currentSearchResults.Count == 0) //No search results { Status("Couldn't find Element Name"); return; } else if (currentTreeSearchTimes < currentSearchResults.Count) // iterate through. { findTreeNode(afTreeViewElements.Nodes[0], currentSearchResults[currentTreeSearchTimes]); } else //restart iteration through. { currentTreeSearchTimes = 0; findTreeNode(afTreeViewElements.Nodes[0], currentSearchResults[currentTreeSearchTimes]); } } else //Load Search Results { currentTreeSearchTimes = 0; currentTreeSearch = tbElementSearchName.Text; AFDatabase afdb = control.getAFDatabase(); currentSearchResults = AFElement.FindElements(afdb, null, "*" + tbElementSearchName.Text + "*", AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, Int32.MaxValue); if (currentSearchResults.Count > 0) findTreeNode(afTreeViewElements.Nodes[0], currentSearchResults[currentTreeSearchTimes]); } }
/// <summary> /// Handles the afTreeView Menu Item calls, brings up the FindElements Dialog and EventFrame Dialog /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void afTreeViewElements_MenuItemClicked(object sender, MenuItemClickedEventArgs e) { try { e.Handled = true; bool persistUserData = true; bool multiSelect = true; string myPersistID = "MyPersistID"; if ((AFMenu.MenuCommand)e.ClickedItem.MergeIndex == AFMenu.MenuCommand.FindChildren) { AFNamedCollectionList<AFElement> elements = null; DialogResult dr = AFOperations.FindElements(this, afDatabasePicker1.AFDatabase, out elements, multiSelect, persistUserData, myPersistID); //Clear Search and Load new search if (dr == DialogResult.OK) { currentSearchResults = elements; currentTreeSearchTimes = 0; currentTreeSearch = ""; tbElementSearchName.Text = ""; if (currentSearchResults.Count > 0) findTreeNode(afTreeViewElements.Nodes[0], currentSearchResults[currentTreeSearchTimes]); } } else if ((AFMenu.MenuCommand)e.ClickedItem.MergeIndex == AFMenu.MenuCommand.FindEventFrames) { AFNamedCollectionList<AFEventFrame> frames = null; AFOperations.FindEventFrames(this, afDatabasePicker1.AFDatabase, out frames, true, true, "PersistID"); if (frames.Count > 0) { avcEventFrames.AFSetObject(frames, afDatabasePicker1.AFDatabase, null, null); avcEventFrames.AFSelection = frames[0]; object selected = avcEventFrames.AFSelection; avcEventFrames_ItemSelected(this, null); } } } catch { } }
/// <summary> /// The FindEventFrameCriteria Dialog updates the event frame to one EventFrame, which is shown in the AFViewController /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void afEventFrameFindCtrl_AFEventFrameUpdated(object sender, CancelEventArgs e) { //GET Results from FindDialog AFEventFrame frame = afEventFrameFindCtrl.AFEventFrame; avcEventFrames.AFSelection = frame; if (avcEventFrames.AFSelection == null) { AFNamedCollectionList<AFEventFrame> frames = new AFNamedCollectionList<AFEventFrame>() { frame }; avcEventFrames.AFSetObject(frames, afDatabasePicker1.AFDatabase, null, null); avcEventFrames.AFSelection = frames[0]; object selected = avcEventFrames.AFSelection; avcEventFrames_ItemSelected(this, null); } }
public static void GetACIOutput(Service unit, string ViewerFilePath) { PISystems piSystems = new PISystems(); PISystem piSystem; AFDatabase database; string error = ""; string error1 = ""; Outputs objOutputUnit = null; CurrentOutputAtGivenLoadStep resCurrentOutputs = null; IdealOutputAtGivenTorque resIdealOtpsAt90T = null, resIdealOtpsAt95T = null, resIdealOtpsAt100T = null; IList <PIPoint> lstPiPointForUnit = null; AFNamedCollectionList <AFElement> AllElements = new AFNamedCollectionList <AFElement>(); AFValue floatingValue = null; AFElement Model = new AFElement(); AFAttribute ErrorArrayCode = null; try { piSystem = piSystems["WINOSIT3D01"]; database = piSystem.Databases["DCPDev"]; if (File.Exists(ViewerFilePath)) { // Trace.Write(unit.UnitName + " :"); Trace.WriteLine(ViewerFilePath); var objERCM = objERCMKernal; objERCM.Reset(); objERCM.eRCMViewerFilename = ViewerFilePath; AciModelInputs objAciInput = new AciModelInputs(unit); if (objERCM.SuccessfulFileLoad) { if (!string.IsNullOrEmpty(objAciInput.ErrorMsg)) { Trace.TraceError("Valid Input data not available for " + unit.UnitName + " at" + DateTime.Now); return; } objOutputUnit = GetACIOutputObjectForUnit(unit.UnitName, unit.ServiceName); if (objAciInput.Rpm < 100) { error1 = " RPM is less than 100. Model wouold not run for " + unit.ServiceName + " " + unit.UnitName; Console.WriteLine(error1); AllElements = AFElement.FindElements(database, null, null, AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, 1000000000); foreach (AFElement ele in AllElements) { if (ele.Name.Equals(unit.UnitName) && ((ele.Parent != null && ele.Parent.Name.Equals(unit.ServiceName)) || (ele.Parent.Parent != null && ele.Parent.Parent.Name.Equals(unit.ServiceName)))) { Model = ele.Elements["Model"]; ErrorArrayCode = Model.Attributes["ACI Error Array Code"]; floatingValue = new AFValue(error1); ErrorArrayCode.Data.UpdateValue(floatingValue, AFUpdateOption.NoReplace, AFBufferOption.DoNotBuffer); } } return; } objERCM.CurrentLoadStep = unit.LoadStep; resCurrentOutputs = GetCurrentOutputAtGivenLoadStep(unit.LoadStep, objAciInput, objERCM); resIdealOtpsAt90T = GetIdealOutputAtGivenTorque(unit.LoadStep, 90, objAciInput, objERCM); resIdealOtpsAt95T = GetIdealOutputAtGivenTorque(unit.LoadStep, 95, objAciInput, objERCM); resIdealOtpsAt100T = GetIdealOutputAtGivenTorque(unit.LoadStep, 100, objAciInput, objERCM); objERCM.TorqueLimit = 100; objERCM.CurrentLoadStep = unit.LoadStep; objERCM.ChangeOpCondition(objAciInput.PsG, objAciInput.PdG, objAciInput.Rpm, objAciInput.Ts1, objAciInput.Ts2, objAciInput.Ts3, objAciInput.Ts4, objAciInput.Ts5, objAciInput.Ts6); string ACIInputValues = "PsG:" + objAciInput.PsG + " PdG:" + objAciInput.PdG + " Rpm:" + objAciInput.Rpm + " Ts1:" + objAciInput.Ts1 + " Ts2:" + objAciInput.Ts2 + " Ts3:" + objAciInput.Ts3 + " Ts4:" + objAciInput.Ts4 + " Ts5:" + objAciInput.Ts5 + " Ts6:" + objAciInput.Ts6; Trace.TraceInformation(ACIInputValues); //Max Allowed Dischage Pressure var MaxAllowedPd = objERCM.CalcMaxAllowedPd(objAciInput.PsG, objAciInput.Rpm, objAciInput.Ts1, objAciInput.Ts2, objAciInput.Ts3, objAciInput.Ts4, objAciInput.Ts5, objAciInput.Ts6, unit.LoadStep); objERCM.ErrorArray(objERCM.CurrentLoadStep); error = objERCM.FullEnglishErrors(objERCM.ErrorArray(objERCM.CurrentLoadStep), 0); if (error != string.Empty) { Trace.TraceInformation(ACIInputValues); Trace.TraceError(error); } error = error + error1; string CurrentTorq = objERCM.CurrentTorque.ToString(); //Output Result //objOutputUnit = GetACIOutputObjectForUnit(unit.UnitName, unit.ServiceName);//at here Error Occurs!!! //Assign Value to tags lstPiPointForUnit = GetOutputTagList(objOutputUnit); //Update in PI Server // var result = SaveOutputDataInPi(objUnit, lstPiPointForUnit, objERCM); objOutputUnit.MaxAllowedDischargePressure.Value = MaxAllowedPd; //Current Operating Outputs objOutputUnit.LoadStep.Current.Value = resCurrentOutputs.CurrentLoadStep; objOutputUnit.LoadStep.CurrentDetails.Value = resCurrentOutputs.CurrentLoadStepDetail; objOutputUnit.LoadPrediction.Current.Value = resCurrentOutputs.CurrentLoad; objOutputUnit.FlowPrediction.Current.Value = resCurrentOutputs.CurrentFlow; objOutputUnit.FuelRate.Current.Value = resCurrentOutputs.CurrentFuelRate; //Ideal Outputs at 90% Torque objOutputUnit.IdealFlow90T.Value = resIdealOtpsAt90T.IdealFlowAtGivenTorque; objOutputUnit.IdealFuelRate90T.Value = resIdealOtpsAt90T.IdealFuelRateAtGivenTorque; objOutputUnit.IdealLoad90T.Value = resIdealOtpsAt90T.IdealLoadAtGivenTorque; objOutputUnit.IdealLoadStep90T.Value = resIdealOtpsAt90T.IdealLoadStepAtGivenTorque; objOutputUnit.IdealLoadStepDetail90T.Value = resIdealOtpsAt90T.IdealLoadStepDetailAtGivenTorque; //Ideal Outputs at 95% Torque objOutputUnit.IdealFlow95T.Value = resIdealOtpsAt95T.IdealFlowAtGivenTorque; objOutputUnit.IdealFuelRate95T.Value = resIdealOtpsAt95T.IdealFuelRateAtGivenTorque; objOutputUnit.IdealLoad95T.Value = resIdealOtpsAt95T.IdealLoadAtGivenTorque; objOutputUnit.IdealLoadStep95T.Value = resIdealOtpsAt95T.IdealLoadStepAtGivenTorque; objOutputUnit.IdealLoadStepDetail95T.Value = resIdealOtpsAt95T.IdealLoadStepDetailAtGivenTorque; //Ideal Outputs at 100% Torque objOutputUnit.LoadStep.Ideal.Value = resIdealOtpsAt100T.IdealLoadStepAtGivenTorque; objOutputUnit.LoadStep.IdealDetails.Value = resIdealOtpsAt100T.IdealLoadStepDetailAtGivenTorque; objOutputUnit.LoadPrediction.Ideal.Value = resIdealOtpsAt100T.IdealLoadAtGivenTorque; objOutputUnit.FlowPrediction.Ideal.Value = resIdealOtpsAt100T.IdealFlowAtGivenTorque; objOutputUnit.FuelRate.Ideal.Value = resIdealOtpsAt100T.IdealFuelRateAtGivenTorque; if (resCurrentOutputs.CurrentFlow < resIdealOtpsAt100T.IdealFlowAtGivenTorque || resCurrentOutputs.CurrentLoad < resIdealOtpsAt100T.IdealLoadAtGivenTorque) { Console.WriteLine("Current load & Flow lower than ideal."); string message = string.Format("Service Name:{0}, Unit Name:{1},Current Load:{2},Ideal Load:{3}, Current Flow:{4}, Ideal Flow: {5}", unit.ServiceName, unit.UnitName, resCurrentOutputs.CurrentLoad, resIdealOtpsAt100T.IdealLoadAtGivenTorque, resCurrentOutputs.CurrentFlow, resIdealOtpsAt100T.IdealFlowAtGivenTorque); Trace.WriteLine(message); //Ideal Outputs at 90% Torque objOutputUnit.IdealFlow90T.Value = "No Data"; objOutputUnit.IdealFuelRate90T.Value = "No Data"; objOutputUnit.IdealLoad90T.Value = "No Data"; objOutputUnit.IdealLoadStep90T.Value = "No Data"; objOutputUnit.IdealLoadStepDetail90T.Value = "No Data"; //Ideal Outputs at 95% Torque objOutputUnit.IdealFlow95T.Value = "No Data"; objOutputUnit.IdealFuelRate95T.Value = "No Data"; objOutputUnit.IdealLoad95T.Value = "No Data"; objOutputUnit.IdealLoadStep95T.Value = "No Data"; objOutputUnit.IdealLoadStepDetail95T.Value = "No Data"; objOutputUnit.LoadStep.Ideal.Value = "No Data"; objOutputUnit.LoadStep.IdealDetails.Value = "No Data"; objOutputUnit.LoadPrediction.Ideal.Value = "No Data"; objOutputUnit.FlowPrediction.Ideal.Value = "No Data"; objOutputUnit.FuelRate.Ideal.Value = "No Data"; } objOutputUnit.ErrorCode.Value = error; SaveOutputDataInPi(objOutputUnit, lstPiPointForUnit, objERCM, unit); } else { Trace.WriteLine("Failed to load in Viewer file!"); } } else { Trace.WriteLine("File doesn't exist at " + ViewerFilePath); return; } } catch (Exception ex) { Console.WriteLine(ex.Message); Trace.WriteLine(ex.StackTrace); } }