/// <summary> /// Multiple steps. 1) gets PIPoints fo the Server /// 2) Checks AFSecurity, for admin access and removes ability to import. /// 3) Initializes Database and EventFrameFindCtrl. /// </summary> private void initializeAfServerPicker() { PISystem sys = afServerPicker.PISystem; //PI System != AF Server _curServer = sys.Name; PIServer serv = PIServer.FindPIServer(sys, sys.Name); List <PIPoint> piPoints = control.getPIPoints(sys, serv); avcPIPoints.AFSetObject(piPoints, afDatabasePicker1.AFDatabase, null, null); // Decides if you can import or not. Hides the UI. //TODO: Check AFSecurity security = sys.Security; if (security.HasAdmin) { isAdministrator = true; InformationDirectionPanel.Visible = true; } else { InformationDirectionPanel.Visible = false; } if (_curDatabase == null) { afDatabasePicker1.SetAFDatabase(sys.Databases[1], sys.Databases[1]); afEventFrameFindCtrl.Database = afDatabasePicker1.AFDatabase; } }
/// <summary> /// Get the PIPoint data, uses AFSDK. /// </summary> /// <param name="MatlabName"> The variable name in Matlab workspace.</param> /// <param name="server"> The name of the server. </param> /// <param name="point"> The name of the Point.</param> /// <param name="start"> The start time of data collection.</param> /// <param name="end"> The end time of data collection.</param> /// <param name="addToListView">true: adds to the LogSystem ListView. (generally true)</param> public static void getPIData(string MatlabName, string server, string point, string start, string end, bool addToListView) { PIServer serv = PIServer.FindPIServer(server); PIPoint piPoint = PIPoint.FindPIPoint(serv, point); string server_database = "'" + server + "'-'PI.Point'"; getData(server_database, point, MatlabName, start, end, piPoint, true); }
public JsonResult LoadGraph(string PlantStartDateTime, string PlantEndDateTime, string SubRefinery) { var sessionObj = Session["SessionBO"] as UserModel; if (sessionObj != null) { string PlantStartDateTime1 = PlantStartDateTime; string PlantEndDateTime1 = PlantEndDateTime; BOMDetails objBOMDetails = new BOMDetails(); AFLocaleIndependentFormatProvider myTimeZone = new AFLocaleIndependentFormatProvider(); // DateTime StartDate = Convert.ToDateTime(PlantStartDateTime1); // DateTime EndDate = Convert.ToDateTime(PlantEndDateTime1); DateTime StartDate = Convert.ToDateTime(PlantStartDateTime1, System.Globalization.CultureInfo.CurrentCulture); DateTime EndDate = Convert.ToDateTime(PlantEndDateTime1, System.Globalization.CultureInfo.CurrentCulture); PIPoint feedInTag; PIPoint feedOutTag; AFValues feedInVal; AFValues feedOutVal; AFValues filteredfeedInVal = new AFValues(); AFValues filteredoutInVal = new AFValues(); try { PIServerDetails piServerDetails = new PIServerDetails(); PISystems myPISystems = new PISystems(); PISystem mypiSystem = myPISystems[piServerDetails.PIServerName]; PIServer myPiServer = PIServer.FindPIServer(mypiSystem, piServerDetails.PIServerName); NetworkCredential Credentials = new NetworkCredential(piServerDetails.UserName, piServerDetails.Password); mypiSystem.Connect(Credentials); StartDate = StartDate.AddMinutes(-330); AFTime sAFTime = new AFTime(StartDate); //DateTime endDT = Convert.ToDateTime(szDTend); EndDate = EndDate.AddMinutes(-330); AFTime eAFTime = new AFTime(EndDate); AFTimeRange GraphTimeRange = new AFTimeRange(sAFTime, eAFTime); // mypiSystem.Connect(Credentials); objBOMDetails = objBOMDetails.getFeedInFeedOutTag(SubRefinery); feedInTag = PIPoint.FindPIPoint(myPiServer, objBOMDetails.feedInTag); feedInVal = feedInTag.RecordedValues(GraphTimeRange, 0, null, true, 0); foreach (AFValue val in feedInVal) { if (val.IsGood) { filteredfeedInVal.Add(val); } else { val.Value = 0; filteredfeedInVal.Add(val); } } feedOutTag = PIPoint.FindPIPoint(myPiServer, objBOMDetails.feedOutTag); feedOutVal = feedOutTag.RecordedValues(GraphTimeRange, 0, null, true, 0); foreach (AFValue val in feedOutVal) { if (val.IsGood) { filteredoutInVal.Add(val); } else { val.Value = 0; filteredoutInVal.Add(val); } } int inLenArray = filteredfeedInVal.Count; object[] feedInValArr = new object[inLenArray]; DateTime[] feedInDateArr = new DateTime[inLenArray]; AFValueStatus[] feedInValStatus = new AFValueStatus[inLenArray]; filteredfeedInVal.GetValueArrays(out feedInValArr, out feedInDateArr, out feedInValStatus); int outLenArray = feedOutVal.Count; object[] feedOutValArr = new object[outLenArray]; DateTime[] feedOutDateArr = new DateTime[outLenArray]; AFValueStatus[] feedOutValStatus = new AFValueStatus[outLenArray]; filteredoutInVal.GetValueArrays(out feedOutValArr, out feedOutDateArr, out feedOutValStatus); List <KeyValuePair <string, double> > fInlist = new List <KeyValuePair <string, double> >(); List <KeyValuePair <string, double> > fOutlist = new List <KeyValuePair <string, double> >(); // double[] fInDateValdouble = new double[inLenArray]; double[] fOutDateVal = new double[outLenArray]; double[] fInDateVal = new double[inLenArray]; for (int i = 0; i < feedInValArr.Length; i++) { //string fIn = feedInValArr[i].ToString(); double fint = Convert.ToInt32(feedInValArr[i]); if (fint == 0.0) { fInDateVal[i] = -99999; } else if (fint < 0.0) { fInDateVal[i] = -99999; } else { fInDateVal[i] = Math.Round(Convert.ToDouble(feedInValArr[i]), 2); } } string[] fInDateArr = new string[inLenArray]; for (int i = 0; i < feedInDateArr.Length; i++) { fInDateArr[i] = feedInDateArr[i].ToString("MM-dd-yyyy HH:mm:ss"); var element = new KeyValuePair <string, double>(fInDateArr[i], fInDateVal[i]); fInlist.Add(element); } string[] fOutDateArr = new string[outLenArray]; for (int i = 0; i < feedOutDateArr.Length; i++) //feedOutDateArr { //string fOut = feedOutValArr[i].ToString(); //fOutDateArr double fout = Convert.ToInt32(feedOutValArr[i]); if (fout == 0.0) { fOutDateVal[i] = -99999; } else if (fout < 0.0) { fOutDateVal[i] = -99999; } else { fOutDateVal[i] = Math.Round(Convert.ToDouble(feedOutValArr[i]), 2); } } // string[] fOutDateArr = new string[inLenArray]; for (int i = 0; i < feedOutDateArr.Length; i++) { fOutDateArr[i] = feedOutDateArr[i].ToString("MM-dd-yyyy HH:mm:ss"); var element1 = new KeyValuePair <string, double>(fOutDateArr[i], fOutDateVal[i]); fOutlist.Add(element1); } Dictionary <string, List <KeyValuePair <string, double> > > dec = new Dictionary <string, List <KeyValuePair <string, double> > >(); dec.Add("feedIn", fInlist); dec.Add("feedOut", fOutlist); JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); // string json = javaScriptSerializer.Serialize(feedInDateArr); JsonResult js = Json(new { value = dec }, JsonRequestBehavior.AllowGet); return(js); // return Json(new { value = dec }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return(Json(new { value = "Exception Occured" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { status = false }, JsonRequestBehavior.AllowGet)); } }
public BOMMasterTag CheckIsManualBasedOnValue(string ActualStartDateTime, string ActualEndDateTime, BOMMasterTag objBOMMasterTag1) { DateTime ActualStartDate = Convert.ToDateTime(ActualStartDateTime); DateTime ActualEndDate = Convert.ToDateTime(ActualEndDateTime); BOMMasterTag objBOMMasterTag = new BOMMasterTag(); AFValue strtVal; AFValue endVal; PIPoint strtTag; string exceptionMsg = ""; List <string> lstString = new List <string>(); try { PIServerDetails piServerDetails = new PIServerDetails(); PISystems myPISystems = new PISystems(); PISystem mypiSystem = myPISystems[piServerDetails.PIServerName]; PIServer myPiServer = PIServer.FindPIServer(mypiSystem, piServerDetails.PIServerName); NetworkCredential Credentials = new NetworkCredential(piServerDetails.UserName, piServerDetails.Password); ActualStartDate = ActualStartDate.AddMinutes(-330); AFTime sAFTime = new AFTime(ActualStartDate); ActualEndDate = ActualEndDate.AddMinutes(-330); AFTime eAFTime = new AFTime(ActualEndDate); mypiSystem.Connect(Credentials); IDictionary <AFSummaryTypes, AFValue> sm = null; IDictionary <AFSummaryTypes, AFValue> smin = null; List <string> lstComponent = new List <string>(); double resultValue = 0; strtTag = PIPoint.FindPIPoint(myPiServer, objBOMMasterTag1.PITag); strtVal = strtTag.RecordedValue(sAFTime, AFRetrievalMode.AtOrAfter); endVal = strtTag.RecordedValue(eAFTime, AFRetrievalMode.AtOrAfter); AFTimeRange graphTimeReange = new AFTimeRange(sAFTime, eAFTime); sm = strtTag.Summary(graphTimeReange, AFSummaryTypes.Maximum, 0, 0); smin = strtTag.Summary(graphTimeReange, AFSummaryTypes.Minimum, 0, 0); AFValue mx = sm[AFSummaryTypes.Maximum]; AFValue mn = smin[AFSummaryTypes.Minimum]; string strtValString = strtVal.Value.ToString(); string endValString = endVal.Value.ToString(); if (endValString.Equals("No Data") || mx.IsGood == false || strtValString.Equals("No Data") || mx.IsGood == false) { resultValue = 00000; objBOMMasterTag1.isManual = true; objBOMMasterTag1.isManualWithTag = true; lstString.Add(objBOMMasterTag1.component); } else { if (Convert.ToDouble(endVal.Value) < Convert.ToDouble(mx.Value)) { try { resultValue = Convert.ToDouble(mx.Value) - Convert.ToDouble(strtVal.Value) + Convert.ToDouble(endVal.Value) - Convert.ToDouble(mn.Value); } catch (Exception e) { objBOMMasterTag1.isManual = true; objBOMMasterTag1.isManualWithTag = true; exceptionMsg = "Bad value from PI Tag"; lstString.Add(objBOMMasterTag1.component); } } else if (Convert.ToDouble(endVal.Value) == Convert.ToDouble(strtVal.Value)) { resultValue = 00000; objBOMMasterTag1.isManual = true; objBOMMasterTag1.isManualWithTag = true; lstString.Add(objBOMMasterTag1.component); } else { resultValue = Convert.ToDouble(endVal.Value) - Convert.ToDouble(strtVal.Value); } // objBOMMasterTag1.quantity = (float)resultValue; } return(objBOMMasterTag1); } catch (Exception e) { return(null); } }
public JsonResult CalculateBill(string ActualStartDateTime, string ActualEndDateTime, string SubRefinery, string isSave_status, string PONO, int IDOCNumber) { var sessionObj = Session["SessionBO"] as UserModel; if (sessionObj != null) { BOMMasterTag objBOMMasterTag = new BOMMasterTag(); AFLocaleIndependentFormatProvider myTimeZone = new AFLocaleIndependentFormatProvider(); DateTime ActualStartDate = Convert.ToDateTime(ActualStartDateTime); DateTime ActualEndDate = Convert.ToDateTime(ActualEndDateTime); AFValue strtVal; AFValue endVal; PIPoint strtTag; string exceptionMsg = ""; try { List <BOMMasterTag> lstBOMMasterTag = new List <BOMMasterTag>(); if (isSave_status == "1") { lstBOMMasterTag = objBOMMasterTag.getIsSavedList(PONO, IDOCNumber); List <string> lslComponent = GetIsManualWithTag(ActualStartDateTime, ActualEndDateTime, SubRefinery, isSave_status, PONO, IDOCNumber); foreach (BOMMasterTag objBOMMasterTag1 in lstBOMMasterTag) { foreach (String component in lslComponent) { if (objBOMMasterTag1.component == component) { objBOMMasterTag1.isManual = true; objBOMMasterTag1.isManualWithTag = true; } } } //List<string> lstComponent1 = new List<string>(); //List<string> lstComponent2 = new List<string>(); //lstBOMMasterTag = objBOMMasterTag.getIsSavedList(PONO, IDOCNumber); //List<string> lslComponent = GetIsManualWithTag(ActualStartDateTime, ActualEndDateTime, SubRefinery, isSave_status, PONO, IDOCNumber); //foreach (BOMMasterTag objBOMMasterTag1 in lstBOMMasterTag) //{ // foreach (String component in lslComponent) { // if (objBOMMasterTag1.component == component) // { // objBOMMasterTag1.isManual = true; // objBOMMasterTag1.isManualWithTag = true; // } // } // lstComponent1.Add(objBOMMasterTag1.component); // lstComponent2.Add(objBOMMasterTag1.BOMCategory); //} //string duplicate = ""; //List<string> NonDuplicateList = new List<string>(); //foreach (string s in lstComponent2) //{ // if (!NonDuplicateList.Contains(s)) // NonDuplicateList.Add(s); // else // duplicate = s; //} //foreach (BOMMasterTag objBOMMasterTag1 in lstBOMMasterTag) //{ // if (duplicate != "") // { // if (objBOMMasterTag1.BOMCategory == "Raw-Material" || objBOMMasterTag1.BOMCategory == "Product") // { // if (duplicate == objBOMMasterTag1.BOMCategory) // { // // lstBOMMasterTag.Remove(objBOMMasterTag1); // objBOMMasterTag1.BOMCategory = "Product"; // } // } // } //} } else { PIServerDetails piServerDetails = new PIServerDetails(); PISystems myPISystems = new PISystems(); PISystem mypiSystem = myPISystems[piServerDetails.PIServerName]; PIServer myPiServer = PIServer.FindPIServer(mypiSystem, piServerDetails.PIServerName); NetworkCredential Credentials = new NetworkCredential(piServerDetails.UserName, piServerDetails.Password); ActualStartDate = ActualStartDate.AddMinutes(-330); AFTime sAFTime = new AFTime(ActualStartDate); ActualEndDate = ActualEndDate.AddMinutes(-330); AFTime eAFTime = new AFTime(ActualEndDate); mypiSystem.Connect(Credentials); //Tag Mapping with BOMMaster. List <BOMMasterTag> lstBOMMasterTag1 = objBOMMasterTag.getMasterBOM(SubRefinery, PONO, IDOCNumber); IDictionary <AFSummaryTypes, AFValue> sm = null; IDictionary <AFSummaryTypes, AFValue> smin = null; List <string> lstComponent = new List <string>(); foreach (BOMMasterTag objBOMMasterTag1 in lstBOMMasterTag1) { lstComponent.Add(objBOMMasterTag1.component); } //string duplicate = ""; //List<string> NonDuplicateList = new List<string>(); //foreach (string s in lstComponent) //{ // if (!NonDuplicateList.Contains(s)) // NonDuplicateList.Add(s); // else // duplicate = s; //} foreach (BOMMasterTag objBOMMasterTag1 in lstBOMMasterTag1) { if (objBOMMasterTag1.isManual || objBOMMasterTag1.PITag == "") { //objBOMMasterTag1.quantity = 00; objBOMMasterTag1.isManual = true; if (objBOMMasterTag1.component == "") { } } else { double resultValue = 0; strtTag = PIPoint.FindPIPoint(myPiServer, objBOMMasterTag1.PITag); strtVal = strtTag.RecordedValue(sAFTime, AFRetrievalMode.AtOrAfter); endVal = strtTag.RecordedValue(eAFTime, AFRetrievalMode.AtOrAfter); AFTimeRange graphTimeReange = new AFTimeRange(sAFTime, eAFTime); sm = strtTag.Summary(graphTimeReange, AFSummaryTypes.Maximum, 0, 0); smin = strtTag.Summary(graphTimeReange, AFSummaryTypes.Minimum, 0, 0); AFValue mx = sm[AFSummaryTypes.Maximum]; AFValue mn = smin[AFSummaryTypes.Minimum]; Boolean isWrongValue = false; if (endVal.Value.ToString().Equals("No Data") || mx.IsGood == false || strtVal.Value.ToString().Equals("No Data") || mx.IsGood == false) { resultValue = 0.0; isWrongValue = true; } else { if (Convert.ToDouble(endVal.Value) < Convert.ToDouble(mx.Value)) { resultValue = Convert.ToDouble(mx.Value) - Convert.ToDouble(strtVal.Value) + Convert.ToDouble(endVal.Value) - Convert.ToDouble(mn.Value); } else if (Convert.ToDouble(endVal.Value) == Convert.ToDouble(strtVal.Value)) { resultValue = 0; isWrongValue = true; } else { resultValue = Convert.ToDouble(endVal.Value) - Convert.ToDouble(strtVal.Value); } } //if (objBOMMasterTag1.component == "power") //{ // BOMDetails bomDetails = new BOMDetails(); // List<MasterRefineryModel> lstMasterRefinery = bomDetails.getPlantWiseSubRefineries(SubRefinery); // double upTimeHours = 0; // double totalWeightIntoUptime = 0; // double weightIntoUptime = 0; // double weightIntoUptime1 = 0; // double effectiveWeight = 0; // foreach (MasterRefineryModel RefineryDetails in lstMasterRefinery) // { // Boolean flag = bomDetails.InsertForUpTime(ActualStartDate, ActualEndDate, RefineryDetails.SubRefineryCode, RefineryDetails.SubRefineryName); // if (flag) // { // strtTag = PIPoint.FindPIPoint(myPiServer, RefineryDetails.UpTimeTag); // strtVal = strtTag.RecordedValue(sAFTime, AFRetrievalMode.AtOrAfter); // endVal = strtTag.RecordedValue(eAFTime, AFRetrievalMode.AtOrAfter); // upTimeHours = Convert.ToDouble(endVal.Value); // weightIntoUptime = (upTimeHours * RefineryDetails.UpTimePercentage); // totalWeightIntoUptime = totalWeightIntoUptime + weightIntoUptime; // if (objBOMMasterTag1.SubRefinery == RefineryDetails.SubRefineryCode) // { // weightIntoUptime1 = weightIntoUptime; // } // } // } // effectiveWeight = weightIntoUptime1 / totalWeightIntoUptime; // resultValue = resultValue * effectiveWeight; //} if (resultValue <= 0 || isWrongValue) { objBOMMasterTag1.isManual = true; objBOMMasterTag1.isManualWithTag = true; } objBOMMasterTag1.quantity = (float)resultValue; } lstBOMMasterTag.Add(objBOMMasterTag1); //if (duplicate != "") //{ // if (objBOMMasterTag1.BOMCategory == "Raw-Material" || objBOMMasterTag1.BOMCategory == "Product") // { // if (duplicate == objBOMMasterTag1.component) // { // lstBOMMasterTag.Remove(objBOMMasterTag1); // } // } //} } } JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); string json = javaScriptSerializer.Serialize(lstBOMMasterTag); JsonResult js = Json(new { value = json }, JsonRequestBehavior.AllowGet); return(js); } catch (Exception e) { return(Json(new { value = exceptionMsg }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { status = false }, JsonRequestBehavior.AllowGet)); } }
public static ErrorTypes LoadConfigurationParameters() { //This method loads all of the configuration parameters from the application configuration file PIPointsFile = ConfigurationManager.AppSettings["PIPointsFile"]; if (!Enum.TryParse(ConfigurationManager.AppSettings["DataCollectionMode"], true, out DataCollectionMode)) { return(ErrorTypes.BadMode); } string strSourcePIDataArchive = ConfigurationManager.AppSettings["SourcePIDataArchive"]; SourcePIDataArchive = PIServer.FindPIServer(strSourcePIDataArchive); string strDestinationPIDataArchive = ConfigurationManager.AppSettings["DestinationPIDataArchive"]; try { DestinationPIDataArchive = PIServer.FindPIServer(strDestinationPIDataArchive); } catch { return(ErrorTypes.BadDestinationServer); } if (!Double.TryParse(ConfigurationManager.AppSettings["DestinationSendDataRate"], out DestinationSendDataRate)) { //TODO Throw error } if (DataCollectionMode == DataCollectionModes.Real) { if (!Double.TryParse(ConfigurationManager.AppSettings["SourceReadDataRate"], out SourceReadDataRate)) { //TODO Throw error } }//DataCollectionMode == Real if (DataCollectionMode == DataCollectionModes.Historical) { try { DateTime HistoryRecoveryStart_Local = Convert.ToDateTime(ConfigurationManager.AppSettings["HistoryRecoveryStart"]); HistoryRecoveryStart = HistoryRecoveryStart_Local.ToUniversalTime(); } catch { return(ErrorTypes.BadStartTime); } try { DateTime HistoryRecoveryEnd_Local = Convert.ToDateTime(ConfigurationManager.AppSettings["HistoryRecoveryEnd"]); HistoryRecoveryEnd = HistoryRecoveryEnd_Local.ToUniversalTime(); } catch { return(ErrorTypes.BadEndTime); } }//DataCollectionMode == HR if (!Int32.TryParse(ConfigurationManager.AppSettings["MaxSnapshotEvents"], out MaxSnapshotEvents)) { return(ErrorTypes.BadMaxSnapshotEvents); } if (!Int32.TryParse(ConfigurationManager.AppSettings["SourceArchiveMaxRate"], out SourceArchiveMaxRate)) { SourceArchiveMaxRate = 1000000; } if (!Int32.TryParse(ConfigurationManager.AppSettings["MaxRangeTime"], out MaxRangeTime)) { MaxRangeTime = 600; } if (!Boolean.TryParse(ConfigurationManager.AppSettings["EnablePointCreation"], out EnablePointCreation)) { EnablePointCreation = false; } PIPoints.ErrorTypes PIPointLoadingResult = PIPoints.LoadPIPointsFromFile(); if (PIPointLoadingResult != PIPoints.ErrorTypes.None) { return(ErrorTypes.LoadingPIPoints); } return(ErrorTypes.None); }//LoadConfigurationParameters