public bool CreatePIPoint(PIPointModel piPoint) { string piPointName = piPoint.PointName; /* * List<string> piPointList = this.GetPIPoints(); * bool piPointPresent = false; * foreach (string point in piPointList) * { * if (point == piPointName) * { * piPointPresent = true; * } * } */ bool piPointPresent = PIPointExists(piPointName); if (!piPointPresent) { Dictionary <string, object> pointAttributes = new Dictionary <string, object>(); if (piPoint.PointClassName != null) { pointAttributes.Add( PICommonPointAttributes.PointClassName, piPoint.PointClassName); } else { pointAttributes.Add(PICommonPointAttributes.PointClassName, "classic"); } if (piPoint.PointType != null) { pointAttributes.Add( PICommonPointAttributes.PointType, piPoint.PointType); } else { pointAttributes.Add(PICommonPointAttributes.PointType, "float32"); } if (piPoint.Descriptor != null) { pointAttributes.Add( PICommonPointAttributes.Descriptor, piPoint.Descriptor); } else { pointAttributes.Add(PICommonPointAttributes.Descriptor, "Hello World"); } _pi.CreatePIPoint(piPointName, pointAttributes); Console.WriteLine("PIPointCreated"); return(true); } return(false); }
public AFAttribute AddTimeSeries(string name, PIPointType type) { var settings = new Dictionary <string, object>(1) { [PICommonPointAttributes.PointType] = type }; return(new AFAttribute(server.CreatePIPoint(name, settings))); }
public void PIPointTest() { PIServer piServer = PIFixture.PIServer; string namePIPointTag = "PIPointTest_Point"; string[] myPtAttributes = { PICommonPointAttributes.Step, PICommonPointAttributes.PointType }; try { // If PI Point exists, delete it PIFixture.RemovePIPointIfExists(namePIPointTag, Output); // Create attribute values for the PI Point var attributeValues = new Dictionary <string, object> { { "pointtype", "float32" }, { "step", 0 }, { "compressing", 0 }, { "excmin", 0 }, { "excmax", 0 }, { "excdev", 0 }, { "excdevpercent", 0 }, { "shutdown", 0 }, }; // Create PI Point Output.WriteLine($"Creating PI Point {namePIPointTag} with custom attributes."); var point = piServer.CreatePIPoint(namePIPointTag, attributeValues); // Update Output.WriteLine($"Confirm PI Point [{namePIPointTag}] was created with correct custom attributes."); var returnedPoint = PIPoint.FindPIPoint(piServer, namePIPointTag); Assert.True(returnedPoint != null, $"Could not find PI Point [{namePIPointTag}] on Data Archive [{piServer}]."); var originalAttributes = returnedPoint.GetAttributes(myPtAttributes); Assert.True(originalAttributes.Count > 0, $"Could not find any attributes for PI Point [{namePIPointTag}]."); Assert.False(Convert.ToBoolean(originalAttributes[PICommonPointAttributes.Step], CultureInfo.InvariantCulture), $"Expected the Step PI Point attribute to be originally false for PI Point [{namePIPointTag}]."); var pointType = originalAttributes[PICommonPointAttributes.PointType].ToString(); Assert.True(pointType.Equals("Float32", StringComparison.OrdinalIgnoreCase), $"Expected the Point Type for PI Point [{namePIPointTag}] to be Float32, was actually [{pointType}]."); Output.WriteLine($"Setting Step PI Point attribute to true for {namePIPointTag}."); returnedPoint.SetAttribute(PICommonPointAttributes.Step, true); returnedPoint.SaveAttributes(new string[] { PICommonPointAttributes.Step }); Assert.True(returnedPoint.Step, $"Expected the Step PI Point attribute to be true for PI Point [{namePIPointTag}] after being set."); } finally { PIFixture.DeletePIPoints(namePIPointTag, Output); } }
static void Main(string[] args) { #region Logowanie string today = DateTime.Now.ToString("dd_MM_yyyy"); string fileName = "C:\\Users\\cbuczynm\\Maintanance AF i ARC\\LogiZAktualizacjiPIPoints\\updatePiLog_" + today + ".txt"; FileStream filestream = new FileStream(fileName, FileMode.Create); var streamwriter = new StreamWriter(filestream); streamwriter.AutoFlush = true; Console.SetOut(streamwriter); Console.SetError(streamwriter); #endregion #region PiConnection PIServers piServers = new PIServers(); PIServer piServer = piServers["cp-pisrv1"]; piServer.Connect(); Console.WriteLine("Połączony z {0}", piServer); #endregion #region Ładowanie najnowszego i poprzedniego pliku interfejsu GIS var files = new DirectoryInfo("X:\\GIS_LOD_1\\archiwum\\vector").GetFiles("cieplo_wodo_rds_*.txt"); //var files = new DirectoryInfo("C:\\Users\\cbuczynm\\Desktop").GetFiles("cieplo_wodo_rds_*.txt"); Console.WriteLine("tusięwykładam"); string latestFile = ""; DateTime lastUpdated = DateTime.MinValue; foreach (var file in files) { if (file.LastWriteTime > lastUpdated) { lastUpdated = file.LastWriteTime; latestFile = file.FullName; } } Console.WriteLine("Ostatni plik interfejsu : {0}", latestFile); var logLatestFile = File.ReadAllLines(latestFile); var logLatestList = new List <string>(logLatestFile); logLatestList.Remove(logLatestList.First()); for (int i = 0; i < logLatestList.Capacity - 1; i++) { logLatestList[i] = logLatestList[i].Replace("!Brak wezla Maximo", ""); logLatestList[i] = logLatestList[i].Replace("!Brak odpowiedniego obiegu", ""); } Console.WriteLine("Plik zawiera {0} rekordów", logLatestList.Capacity); string previousFile = ""; lastUpdated = DateTime.MinValue; foreach (var file in files) { if (file.LastWriteTime > lastUpdated && file.FullName != latestFile) { lastUpdated = file.LastWriteTime; previousFile = file.FullName; } } Console.WriteLine("Poprzedni plik interfejsu : {0}", previousFile); var logPreviousFile = File.ReadAllLines(previousFile); var logPreviousList = new List <string>(logPreviousFile); logPreviousList.Remove(logPreviousList.First()); for (int i = 0; i < logPreviousList.Capacity - 1; i++) { logPreviousList[i] = logPreviousList[i].Replace("!Brak wezla Maximo", ""); logPreviousList[i] = logPreviousList[i].Replace("!Brak odpowiedniego obiegu", ""); } Console.WriteLine("Plik zawiera {0} rekordów", logPreviousList.Capacity); #endregion #region Ładowanie listy kodów RDS PP istniejących w CM //Ciepłomierze var filesVectorMeter = new DirectoryInfo("X:\\RDS_PP\\VECTOR").GetFiles("rdspp_cieplomierze*.csv"); string vectorMeterFile = ""; lastUpdated = DateTime.MinValue; foreach (var file in filesVectorMeter) { if (file.LastWriteTime > lastUpdated && file.FullName != latestFile) { lastUpdated = file.LastWriteTime; vectorMeterFile = file.FullName; } } Console.WriteLine("Plik Vector Cieplomierzy : {0}", vectorMeterFile); var logvectorMeterFile = File.ReadAllLines(vectorMeterFile); var logvectorMeterList = new List <string>(logvectorMeterFile); logvectorMeterList.Remove(logvectorMeterList.First()); Console.WriteLine("Plik zawiera {0} rekordów z kodami RDSPP Ciepłomierzy", logvectorMeterList.Capacity); //Wodomierze var filesVectorWodo = new DirectoryInfo("X:\\RDS_PP\\VECTOR").GetFiles("rdspp_wodomierze*.csv"); string vectorWodoFile = ""; lastUpdated = DateTime.MinValue; foreach (var file in filesVectorWodo) { if (file.LastWriteTime > lastUpdated && file.FullName != latestFile) { lastUpdated = file.LastWriteTime; vectorWodoFile = file.FullName; } } Console.WriteLine("Plik Vector Wodomierzy : {0}", vectorWodoFile); var logvectorWodoFile = File.ReadAllLines(vectorWodoFile); var logvectorWodoList = new List <string>(logvectorWodoFile); logvectorWodoList.Remove(logvectorMeterList.First()); Console.WriteLine("Plik zawiera {0} rekordów z kodami RDSPP Wodomierzy", logvectorWodoList.Capacity); #endregion #region Parsowanie plików interfejsu GIS var listOfPreviousPoints = new List <Point>(); foreach (var item in logPreviousList) { string[] parameters = item.Split('|'); Point point = new Point(); point.UPW = Convert.ToInt32(parameters[0]); point.UPW_Kombit = Convert.ToInt32(parameters[1]); point.Typ_przelicznika = parameters[2]; point.WL_id = Convert.ToInt32(parameters[3]); point.Numer_przelicznika = parameters[4]; point.Cieplomierz_RDS_PP = parameters[5]; point.WWU1_numer = parameters[6]; point.WWU1_RDS_PP = parameters[7]; point.WWU2_numer = parameters[8]; point.WWU2_RDS_PP = parameters[9]; point.WCW_numer = parameters[10]; point.WCW_RDS_PP = parameters[11]; point.WCO_Numer = parameters[12]; point.WCO_RDS_PP = parameters[13]; point.adres_wf = parameters[14]; point.wskaznik_kontrolny = parameters[15]; listOfPreviousPoints.Add(point); } var listOfLatestPoints = new List <Point>(); foreach (var item in logLatestList) { string[] parameters = item.Split('|'); Point point = new Point(); point.UPW = Convert.ToInt32(parameters[0]); point.UPW_Kombit = Convert.ToInt32(parameters[1]); point.Typ_przelicznika = parameters[2]; point.WL_id = Convert.ToInt32(parameters[3]); point.Numer_przelicznika = parameters[4]; point.Cieplomierz_RDS_PP = parameters[5]; point.WWU1_numer = parameters[6]; point.WWU1_RDS_PP = parameters[7]; point.WWU2_numer = parameters[8]; point.WWU2_RDS_PP = parameters[9]; point.WCW_numer = parameters[10]; point.WCW_RDS_PP = parameters[11]; point.WCO_Numer = parameters[12]; point.WCO_RDS_PP = parameters[13]; point.adres_wf = parameters[14]; point.wskaznik_kontrolny = parameters[15]; int newCounter = 0; foreach (var prevPoint in listOfPreviousPoints) { if (prevPoint.UPW_Kombit == point.UPW_Kombit) { newCounter++; if (point.Cieplomierz_RDS_PP != prevPoint.Cieplomierz_RDS_PP || point.WWU1_RDS_PP != prevPoint.WWU1_RDS_PP || point.WWU2_RDS_PP != prevPoint.WWU2_RDS_PP || point.WCW_RDS_PP != prevPoint.WCW_RDS_PP || point.WCO_RDS_PP != prevPoint.WCO_RDS_PP ) { point.isChanged = true; } else { } } } if (newCounter == 0) { point.isNew = true; } else { } listOfLatestPoints.Add(point); } int numberOfChangedPoints = 0; foreach (var point in listOfLatestPoints) { if (point.isChanged) { numberOfChangedPoints++; } } Console.WriteLine("Liczba rekodrów w których RDSPP uleglo zmianie : {0}", numberOfChangedPoints); Console.WriteLine("Sa to nastepujace punkty sieci : "); foreach (var point in listOfLatestPoints) { if (point.isChanged) { Console.WriteLine(point.UPW_Kombit + " - " + point.adres_wf); } } int numberOfNewPoints = 0; foreach (var point in listOfLatestPoints) { if (point.isNew) { numberOfNewPoints++; } } Console.WriteLine("Liczba nowych rekodrów : {0}", numberOfNewPoints); Console.WriteLine("Sa to nastepujace punkty sieci : "); foreach (var point in listOfLatestPoints) { if (point.isNew) { Console.WriteLine(point.UPW_Kombit + " - " + point.adres_wf); } } #endregion #region Parsowanie plików z listą RDSPP Vectora //Ciepłomierze var listOfVectorMeters = new List <string>(); foreach (var item in logvectorMeterList) { string[] parameters = item.Split('|'); listOfVectorMeters.Add(parameters[7]); } //Wodomierze var listOfVectorWodo = new List <string>(); foreach (var item in logvectorWodoList) { string[] parameters = item.Split('|'); listOfVectorWodo.Add(parameters[8]); } #endregion #region Kodowanie nowych RDS PP Ciepłomierzy foreach (var point in listOfLatestPoints) { if (!(String.IsNullOrWhiteSpace(point.Cieplomierz_RDS_PP)) && point.isChanged == false && point.isNew == true) { Meter meter = new Meter(point.Cieplomierz_RDS_PP); if (listOfVectorMeters.Contains(meter.LicznikEnergii)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.LicznikEnergii); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.LicznikEnergii); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.LicznikEnergii); piServer.CreatePIPoint(meter.LicznikEnergii); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.LicznikEnergii); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "GJ"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.LicznikEnergii); } if (listOfVectorMeters.Contains(meter.LicznikObjetosciPrzeplywu)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.LicznikObjetosciPrzeplywu); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.LicznikObjetosciPrzeplywu); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.LicznikObjetosciPrzeplywu); piServer.CreatePIPoint(meter.LicznikObjetosciPrzeplywu); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.LicznikObjetosciPrzeplywu); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "m3"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.LicznikObjetosciPrzeplywu); } if (listOfVectorMeters.Contains(meter.MocChwilowa)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.MocChwilowa); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.MocChwilowa); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.MocChwilowa); piServer.CreatePIPoint(meter.MocChwilowa); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.MocChwilowa); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "kW"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.MocChwilowa); } if (listOfVectorMeters.Contains(meter.PrzeplywChwilowy)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.PrzeplywChwilowy); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.PrzeplywChwilowy); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.PrzeplywChwilowy); piServer.CreatePIPoint(meter.PrzeplywChwilowy); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.PrzeplywChwilowy); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "m3/h"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.PrzeplywChwilowy); } if (listOfVectorMeters.Contains(meter.TemperaturaZasilania)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.TemperaturaZasilania); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.TemperaturaZasilania); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.TemperaturaZasilania); piServer.CreatePIPoint(meter.TemperaturaZasilania); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.TemperaturaZasilania); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "°C"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.TemperaturaZasilania); } if (listOfVectorMeters.Contains(meter.TemperaturaPowrotu)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.TemperaturaPowrotu); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.TemperaturaPowrotu); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.TemperaturaPowrotu); piServer.CreatePIPoint(meter.TemperaturaPowrotu); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.TemperaturaPowrotu); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "°C"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.TemperaturaPowrotu); } if (listOfVectorMeters.Contains(meter.NumerFabryczny)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.NumerFabryczny); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.NumerFabryczny); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.NumerFabryczny); piServer.CreatePIPoint(meter.NumerFabryczny); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.NumerFabryczny); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "String"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, ""); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.NumerFabryczny); } if (listOfVectorMeters.Contains(meter.KodBledu)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.KodBledu); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.KodBledu); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.KodBledu); piServer.CreatePIPoint(meter.KodBledu); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.KodBledu); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Int32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, ""); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.KodBledu); } if (listOfVectorMeters.Contains(meter.GodzinyPracy)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.GodzinyPracy); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.GodzinyPracy); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.GodzinyPracy); piServer.CreatePIPoint(meter.GodzinyPracy); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, meter.GodzinyPracy); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Int32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "h"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + meter.GodzinyPracy); } } else { continue; } } #endregion #region Kodowanie nowych RDS PP Wodomierzy //WWU_1 foreach (var point in listOfLatestPoints) { if (!(String.IsNullOrWhiteSpace(point.WWU1_RDS_PP)) && point.isChanged == false && point.isNew == true) { Wodo WWU_1 = new Wodo(point.WWU1_RDS_PP); if (listOfVectorWodo.Contains(WWU_1.StanWodomierza)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WWU_1.StanWodomierza); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WWU_1.StanWodomierza); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WWU_1.StanWodomierza); piServer.CreatePIPoint(WWU_1.StanWodomierza); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WWU_1.StanWodomierza); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "m3"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WWU_1.StanWodomierza); } } else { continue; } } //WWU_2 foreach (var point in listOfLatestPoints) { if (!(String.IsNullOrWhiteSpace(point.WWU2_RDS_PP)) && point.isChanged == false && point.isNew == true) { Wodo WWU_2 = new Wodo(point.WWU2_RDS_PP); if (listOfVectorWodo.Contains(WWU_2.StanWodomierza)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WWU_2.StanWodomierza); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WWU_2.StanWodomierza); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WWU_2.StanWodomierza); piServer.CreatePIPoint(WWU_2.StanWodomierza); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WWU_2.StanWodomierza); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "m3"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WWU_2.StanWodomierza); } } else { continue; } } //WCW foreach (var point in listOfLatestPoints) { if (!(String.IsNullOrWhiteSpace(point.WCW_RDS_PP)) && point.isChanged == false && point.isNew == true) { Wodo WCW = new Wodo(point.WCW_RDS_PP); if (listOfVectorWodo.Contains(WCW.StanWodomierza)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WCW.StanWodomierza); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WCW.StanWodomierza); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WCW.StanWodomierza); piServer.CreatePIPoint(WCW.StanWodomierza); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WCW.StanWodomierza); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "m3"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WCW.StanWodomierza); } } else { continue; } } //WCO foreach (var point in listOfLatestPoints) { if (!(String.IsNullOrWhiteSpace(point.WCO_RDS_PP)) && point.isChanged == false && point.isNew == true) { Wodo WCO = new Wodo(point.WCO_RDS_PP); if (listOfVectorWodo.Contains(WCO.StanWodomierza)) { Console.WriteLine("JEST W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WCO.StanWodomierza); try { PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WCO.StanWodomierza); Console.WriteLine("JEST JUŻ W SYSTEM PI"); } catch (Exception) { Console.WriteLine("NIE znalazlem W SYSTEM PI więc tworzę : " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WCO.StanWodomierza); piServer.CreatePIPoint(WCO.StanWodomierza); PIPoint myPIPoint = PIPoint.FindPIPoint(piServer, WCO.StanWodomierza); myPIPoint.SetAttribute(PICommonPointAttributes.PointType, "Float32"); myPIPoint.SetAttribute(PICommonPointAttributes.Descriptor, ""); myPIPoint.SetAttribute(PICommonPointAttributes.DisplayDigits, "3"); myPIPoint.SetAttribute(PICommonPointAttributes.EngineeringUnits, "m3"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSource, "UFLOD"); myPIPoint.SetAttribute(PICommonPointAttributes.Archiving, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.Compressing, "1"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionDeviation, "0"); myPIPoint.SetAttribute(PICommonPointAttributes.CompressionMaximum, "28800"); myPIPoint.SetAttribute(PICommonPointAttributes.DataSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(w) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(w)"); myPIPoint.SetAttribute(PICommonPointAttributes.PointSecurity, "piadmin: A(r,w) | piadmins: A(r,w) | PIInterfaces: A(r,w) | PICoresightSRV: A(r) | PIAnalysisServices: A(r,w) | PILO_write: A(r) | PILO_read: A(r) | PILO_super: A(r,w) | PI_Buffers: A(r)"); myPIPoint.SaveAttributes(); Console.WriteLine("utworzono {0}", myPIPoint.Name); } } else { Console.WriteLine("NIE MA W VECTORZE! - " + point.UPW_Kombit + " - " + point.adres_wf + " - kod : " + WCO.StanWodomierza); } } else { continue; } } #endregion Console.WriteLine("Zakończono aktualizowanie tagów PI na podstawie referencji z GIS"); }
/// <summary> /// Sends updated metadata to PI. /// </summary> protected override void ExecuteMetadataRefresh() { if (!Initialized || (object)m_connection == null) { return; } if (!m_connection.Connected) { return; } MeasurementKey[] inputMeasurements = InputMeasurementKeys; int previousMeasurementReportingInterval = MeasurementReportingInterval; DateTime latestUpdateTime = DateTime.MinValue; DateTime updateTime; bool refreshMetadata; m_refreshingMetadata = m_runMetadataSync; // For first runs, don't report archived points until PI meta-data has been established MeasurementReportingInterval = 0; // Attempt to load tag-map from existing cache, if any LoadCachedTagMap(); if (m_tagMap.Count > 0) { MeasurementReportingInterval = previousMeasurementReportingInterval; } // Establish initial connection point dictionary (much of the meta-data may already exist) EstablishPIPointDictionary(inputMeasurements); if (!m_runMetadataSync) { MeasurementReportingInterval = previousMeasurementReportingInterval; return; } try { OnStatusMessage("Beginning metadata refresh..."); if ((object)inputMeasurements != null && inputMeasurements.Length > 0) { PIServer server = m_connection.Server; int processed = 0, total = inputMeasurements.Length; AdoDataConnection database = null; DataTable measurements = DataSource.Tables["ActiveMeasurements"]; foreach (MeasurementKey key in inputMeasurements) { // If adapter gets disabled while executing this thread - go ahead and exit if (!Enabled) { return; } Guid signalID = key.SignalID; DataRow[] rows = measurements.Select(string.Format("SignalID='{0}'", signalID)); DataRow measurementRow; PIPoint point; string tagName; refreshMetadata = false; if (rows.Length <= 0) { m_tagMap.TryRemove(signalID, out tagName); continue; } // Get matching measurement row measurementRow = rows[0]; // Get tag-name as defined in meta-data tagName = measurementRow["PointTag"].ToNonNullString().Trim(); // If tag name is not defined in measurements there is no need to continue processing if (string.IsNullOrWhiteSpace(tagName)) { m_tagMap.TryRemove(signalID, out tagName); continue; } // Use alternate tag if one is defined - note that digitals are an exception since they use this field for special labeling if (!string.IsNullOrWhiteSpace(measurementRow["AlternateTag"].ToString()) && !measurementRow["SignalType"].ToString().Equals("DIGI", StringComparison.OrdinalIgnoreCase)) { tagName = measurementRow["AlternateTag"].ToString().Trim(); } // Lookup PI point trying signal ID and tag name point = GetPIPoint(server, signalID, tagName); if ((object)point == null) { try { // Attempt to add point if it doesn't exist Dictionary <string, object> attributes = new Dictionary <string, object>(); attributes[PICommonPointAttributes.PointClassName] = m_pointClass; attributes[PICommonPointAttributes.PointType] = PIPointType.Float32; point = server.CreatePIPoint(tagName, attributes); refreshMetadata = true; } catch (Exception ex) { OnProcessException(new InvalidOperationException(string.Format("Failed to add PI tag '{0}' for measurement '{1}': {2}", tagName, key, ex.Message), ex)); } } if ((object)point != null) { // Update tag-map for faster future loads m_tagMap[signalID] = tagName; try { // Rename tag-name if needed - PI tags are not case sensitive if (string.Compare(point.Name, tagName, StringComparison.InvariantCultureIgnoreCase) != 0) { point.SetAttribute(PICommonPointAttributes.Tag, tagName); point.SaveAttributes(PICommonPointAttributes.Tag); } } catch (Exception ex) { OnProcessException(new InvalidOperationException(string.Format("Failed to rename PI tag '{0}' to '{1}' for measurement '{2}': {3}", point.Name, tagName, key, ex.Message), ex)); } if (!refreshMetadata) { // Validate that PI point has a properly defined Guid in the extended description point.LoadAttributes(PICommonPointAttributes.ExtendedDescriptor); string exdesc = point.GetAttribute(PICommonPointAttributes.ExtendedDescriptor) as string; if (string.IsNullOrWhiteSpace(exdesc)) { refreshMetadata = true; } else { refreshMetadata = string.Compare(exdesc.Trim(), signalID.ToString(), StringComparison.OrdinalIgnoreCase) != 0; } } } // Determine last update time for this meta-data record try { // See if ActiveMeasurements contains updated on column if (measurements.Columns.Contains("UpdatedOn")) { updateTime = Convert.ToDateTime(measurementRow["UpdatedOn"]); } else { // Attempt to lookup last update time for record if ((object)database == null) { database = new AdoDataConnection("systemSettings"); } updateTime = Convert.ToDateTime(database.Connection.ExecuteScalar(string.Format("SELECT UpdatedOn FROM Measurement WHERE SignalID = '{0}'", signalID))); } } catch (Exception) { updateTime = DateTime.UtcNow; } // Tracked latest update time in meta-data, this will become last meta-data refresh time if (updateTime > latestUpdateTime) { latestUpdateTime = updateTime; } if ((refreshMetadata || updateTime > m_lastMetadataRefresh) && (object)point != null) { try { List <string> updatedAttributes = new List <string>(); Action <string, object> updateAttribute = (attribute, newValue) => { string oldValue = point.GetAttribute(attribute).ToString(); if (string.IsNullOrEmpty(oldValue) || string.CompareOrdinal(oldValue, newValue.ToString()) != 0) { point.SetAttribute(attribute, newValue); updatedAttributes.Add(attribute); } }; // Load current attributes point.LoadAttributes( PICommonPointAttributes.PointSource, PICommonPointAttributes.Descriptor, PICommonPointAttributes.ExtendedDescriptor, PICommonPointAttributes.Tag, PICommonPointAttributes.Compressing, PICommonPointAttributes.EngineeringUnits); // Update tag meta-data if it has changed updateAttribute(PICommonPointAttributes.PointSource, m_pointSource); updateAttribute(PICommonPointAttributes.Descriptor, measurementRow["Description"].ToString()); updateAttribute(PICommonPointAttributes.ExtendedDescriptor, measurementRow["SignalID"].ToString()); updateAttribute(PICommonPointAttributes.Tag, tagName); updateAttribute(PICommonPointAttributes.Compressing, UseCompression ? 1 : 0); // Engineering units is a new field for this view -- handle the case that it's not there if (measurements.Columns.Contains("EngineeringUnits")) { updateAttribute(PICommonPointAttributes.EngineeringUnits, measurementRow["EngineeringUnits"].ToString()); } // Save any changes if (updatedAttributes.Count > 0) { point.SaveAttributes(updatedAttributes.ToArray()); } } catch (Exception ex) { OnProcessException(new InvalidOperationException(string.Format("Failed to update PI tag '{0}' metadata from measurement '{1}': {2}", tagName, key, ex.Message), ex)); } } processed++; m_metadataRefreshProgress = processed / (double)total; if (processed % 100 == 0) { OnStatusMessage("Updated {0:N0} PI tags and associated metadata, {1:0.00%} complete...", processed, m_metadataRefreshProgress); } // If mapping for this connection was removed, it may have been because there was no meta-data so // we re-add key to dictionary with null value, actual mapping will happen dynamically as needed if (!m_mappedPIPoints.ContainsKey(key)) { m_mappedPIPoints.TryAdd(key, null); } } if ((object)database != null) { database.Dispose(); } if (m_tagMap.Count > 0 && Enabled) { // Cache tag-map for faster future PI adapter startup try { OnStatusMessage("Caching tag-map for faster future loads..."); using (FileStream tagMapCache = File.Create(m_tagMapCacheFileName)) { Serialization.Serialize(m_tagMap.ToDictionary(kvp => kvp.Key, kvp => kvp.Value), GSF.SerializationFormat.Binary, tagMapCache); } OnStatusMessage("Tag-map cached for faster future loads."); } catch (Exception ex) { OnProcessException(new InvalidOperationException(string.Format("Failed to cache tag-map to file '{0}': {1}", m_tagMapCacheFileName, ex.Message), ex)); } } } else { OnStatusMessage("OSI-PI historian output adapter is not configured to receive any input measurements - metadata refresh canceled."); } } catch (Exception ex) { OnProcessException(ex); } finally { m_refreshingMetadata = false; } if (Enabled) { m_lastMetadataRefresh = latestUpdateTime > DateTime.MinValue ? latestUpdateTime : DateTime.UtcNow; OnStatusMessage("Completed metadata refresh successfully."); // Re-establish connection point dictionary since meta-data and tags may exist in PI server now that didn't before. // This will also start showing warning messages in CreateMappedPIPoint function for un-mappable points // now that meta-data refresh has completed. EstablishPIPointDictionary(inputMeasurements); } // Restore original measurement reporting interval MeasurementReportingInterval = previousMeasurementReportingInterval; }