Пример #1
0
        static void Main(string[] args)
        {
            PIServers pIServers = new PIServers();

            foreach (var server in pIServers)
            {
                Console.WriteLine("Server: {0}", server.Name);
            }

            PIServer piServer = pIServers.DefaultPIServer;

            Console.WriteLine("Default connection is: {0}", piServer.Name);

            piServer.Connect();

            // do smth with the pi system
            // get a pi point
            var point      = PIPoint.FindPIPoint(piServer, "PLCW00321500=S20NDD11BU900:XQ001");
            var value      = point.CurrentValue();
            var timevalue  = value.Timestamp;
            var valuevalue = value.Value;

            Console.WriteLine("Tag name: {0} and its Value is: {1}, {2}", point.Name, timevalue, valuevalue);

            var plotValues = point.PlotValues(new AFTimeRange("*-1w", "*"), 10);

            foreach (var pValue in plotValues)
            {
                Console.WriteLine("{0} {1}", pValue.Value, pValue.Timestamp);
            }
            piServer.Disconnect();

            Console.ReadKey();
        }
        public void ConnectToPIDataArchive()
        {
            piServer.Connect();
            IEnumerable <PIPoint> allPIPoints = PIPoint.FindPIPoints(piServer, "CityBikes*");

            allPIPointNames = allPIPoints.Select(p => p.Name).ToList();
        }
Пример #3
0
        public bool Connect()
        {
            try
            {
                if (_memberName == null)
                {
                    _logger.InfoFormat("Trying to connect to PI Data Archive {0}. As {1}", _piServer.Name,
                                       _piServer.CurrentUserName);
                    _piServer.Connect();
                }

                else
                {
                    _logger.InfoFormat("Connecting to member: {0}", _memberName);
                    _piServer = ConnectMember(_piServer.Name, _memberName);
                }

                _logger.InfoFormat("Connected to {0}. As {1}", _piServer.Name, _piServer.CurrentUserName);
                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// Attempts to open <see cref="PIConnection"/>.
        /// </summary>
        public void Open()
        {
            if (m_connected || ((object)m_server != null && m_server.ConnectionInfo.IsConnected))
            {
                throw new InvalidOperationException("OSI-PI server connection is already open.");
            }

            if (string.IsNullOrWhiteSpace(m_serverName))
            {
                throw new InvalidOperationException("Cannot open OSI-PI server connection without a defined server name.");
            }

            m_connected = false;

            try
            {
                // Locate configured PI server
                PIServers servers = new PIServers();
                m_server = servers[m_serverName];

                if ((object)m_server == null)
                {
                    throw new InvalidOperationException("Server not found in the PI servers collection.");
                }

                m_server.ConnectChanged += PIConnection_ConnectChanged;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format("Failed to connect to PI server \"{0}\": {1}", m_serverName, ex.Message));
            }

            if (!m_server.ConnectionInfo.IsConnected)
            {
                // Attempt to open OSI-PI connection
                if (!string.IsNullOrEmpty(m_userName) && !string.IsNullOrEmpty(m_password))
                {
                    m_server.Connect(new NetworkCredential(m_userName, m_password));
                }
                else
                {
                    m_server.Connect(true);
                }
            }

            m_connected = true;
        }
Пример #5
0
        public void ExplicitConnection()
        {
            PIServers piServers = new PIServers();
            PIServer  piServer  = piServers["PIServerName"];

            // At this point, no connection is made.

            piServer.Connect();
            // Now a connection is made by explicit call.

            PIPoint piPoint = PIPoint.FindPIPoint(piServer, "sinusoid");
        }
        public void Connect(string piSystemName, string afDatabaseName, string piDataArchiveName)
        {
            piPointNamesToBeCreated = new List <string>();

            try
            {
                piSystem = new PISystems()[piSystemName];
                piSystem.Connect();
                log.Info("Connected to the AF Server.");
            }
            catch (Exception ex)
            {
                log.Fatal("Could not connect to AF Server: " + ex.Message);
                throw ex;
            }

            try
            {
                afDb = piSystem.Databases[afDatabaseName];
                if (afDb == null)
                {
                    log.Info("AF Database not found. Creating new AF Database.");
                    afDb = piSystem.Databases.Add(afDatabaseName);
                }
                else
                {
                    log.Info("AF Database found.");
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Could not connect to AF Database: " + ex.Message);
                throw ex;
            }


            try
            {
                piServer = new PIServers()[piDataArchiveName];
                piServer.Connect();
                log.Info("Connected to the PI Data Archive.");
            }
            catch (Exception ex)
            {
                log.Fatal("Could not connect to PI Data Archive: " + ex.Message);
                throw ex;
            }
        }
Пример #7
0
        public PIServer Connect(string server)
        {
            PIServers piServers = new PIServers();
            PIServer  piServer  = piServers[server];

            if (piServer == null)
            {
                throw new PIServerNotFoundException();
            }

            // the connect signature:(true, null) will force a password dialog to appear.
            // you should not use this option for a service or an executable that runs outside a user windows session.
            // instead use the empty constructor and make sure that the user that runs the application have an account that allows it to connect.
            piServer.Connect(true, null);
            return(piServer);
        }
Пример #8
0
        public PIPointOperations(string piServerName)
        {
            PIServers piServers = new PIServers();

            _pi = piServers[piServerName];
            try
            {
                _pi.Connect();
                Console.WriteLine("Connected");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            piPointList = this.GetPIPoints();
        }
        public (bool, PIServer) Connect()
        {
            // if _SitePI not initialized before, try get a handle for _SitePI specified in .config file.
            if (_SitePI == null)
            {
                _SitePI = new PIServers()[_PICollectiveName];
                if (_SitePI == null)
                {
                    _logger.Error("Unable to find the PI Collective {0} specified in configuration file", _PICollectiveName);
                    return(false, _SitePI);
                }
                else
                {
                    _logger.Information("Found PI Collective {0} specified in .config file", _PICollectiveName);
                }
            }

            // if _SitePI already initialized, check if it is connected
            if (_SitePI.ConnectionInfo.IsConnected)
            {
                return(true, _SitePI);
            }
            else // else connect
            {
                try
                {
                    _logger.Information("Connecting to PI {0}", _PICollectiveName);
                    _SitePI.Connect();

                    // Connection Info
                    _logger.Information("Connected to {0} at port {1} as user {2}", _SitePI.ConnectionInfo.Host, _SitePI.ConnectionInfo.Port, _SitePI.CurrentUserName);
                    _logger.Information("PI Identities mapped to above user: "******"     {0}", identity.Name);
                    }
                    _logger.Information("Connection to {0} successfully established", _PICollectiveName);
                    // _logger.Information("AllowWriteValues: {0}", _SitePI.Collective.AllowWriteValues);
                }
                catch (Exception e)
                {
                    _logger.Error("Unable to connect to PI Data Collective. Error: {0}", e.Message);
                }

                return(_SitePI.ConnectionInfo.IsConnected, _SitePI);
            }
        }
Пример #10
0
        /// <summary>
        /// Creates an instance of the PIFixture class.
        /// </summary>
        public PIFixture()
        {
            var dataArchiveName = Settings.PIDataArchive;
            var servers         = PIServers.GetPIServers();

            PIServer = servers[dataArchiveName];

            if (PIServer != null)
            {
                PIServer.Connect();
            }
            else
            {
                throw new InvalidOperationException(
                          $"The specific PI Data Archive [{dataArchiveName}] does not exist or is not configured.");
            }
        }
Пример #11
0
        public bool Connect()
        {
            _logger.InfoFormat("Trying to connect to PI Data Archive {0}. As {1}", _piServer.Name, _piServer.CurrentUserName);

            try
            {
                _piServer.Connect(true, null);

                _logger.InfoFormat("Connected to {0}. As {1}", _piServer.Name, _piServer.CurrentUserName);
                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }

            return(false);
        }
Пример #12
0
        private void ConnectPI()
        {
            InitializeHost();

            // Locate configured PI server
            PIServers servers = new PIServers();

            m_server = servers[m_settings.ServerName];

            if (m_server is null)
            {
                throw new InvalidOperationException("Server not found in the PI servers collection.");
            }

            if (!m_server.ConnectionInfo.IsConnected)
            {
                // Attempt to open OSI-PI connection
                m_server.Connect(true);
            }
        }
 public bool Connect(string PIDataArchiveName = null)
 {
     try
     {
         if (PIDataArchiveName == null)
         {
             piServer = pIServers.DefaultPIServer;
         }
         else
         {
             piServer = pIServers[PIDataArchiveName];
         }
         piServer.Connect();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #14
0
    // Connect to PI Data Archive
    public static void Connect(string PIServerName)
    {
        //connections
        PIServers allPIServers = new PIServers();
        PIServer  aPIServer    = allPIServers[PIServerName];

        try
        {
            aPIServer.Connect();
        }
        catch (Exception e)
        {
            Console.WriteLine("{0}\nPIServer '{1}' was not found. List of PI Servers in KST:", e.Message, PIServerName);
            foreach (var it in allPIServers)
            {
                Console.WriteLine("\t" + it.Name);
            }
            Environment.Exit(0);
            return;
        }
    }
Пример #15
0
 public int ConnectToPIServer(string piservername, int def)
 {
     try
     {
         if (def == 0)
         {
             this.PIServerName = piservername;
             MyPiServer        = MyPIServers[piservername];
         }
         else
         {
             this.PIServerName = "Default PI Server";
             MyPiServer        = MyPIServers.DefaultPIServer;
             string test = MyPiServer.Name;
         }
         MyPiServer.Connect();
         this.PIServerName = MyPiServer.Name;
         return(1);
     }
     catch
     {
         return(0);
     }
 }
Пример #16
0
        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");
        }
Пример #17
0
        private void btnPing_Click(object sender, EventArgs e)
        {
            int index = 0;
            List<long> results = new List<long>();

            //Hide all data points
            pingResults.Series["ping"].Points.Clear();
            pingResults.Visible = false;
            lbPingFailure.Text = "";
            lbReturnTime.Visible = false;
            lbAverageReturnTime.Visible = false;
            lbMinReturnTime.Visible = false;
            lbMinTime.Visible = false;
            lbMaxReturnTime.Visible = false;
            lbMaxTime.Visible = false;
            lbConnectionStatus.Visible = false;
            lbConnectionStatusLabel.Visible = false;
            lbAuthenticationStatus.Visible = false;
            lbAuthenticationStatusLabel.Visible = false;

            int timeout = 1000;

            do
            {
               
                try
                {
                    //Ping server selected in drop-down box
                    Ping pinger = new Ping();
                    System.Threading.Thread.Sleep(50);
                    PingReply reply = pinger.Send(piServerPicker2.Text.ToString(), timeout);
                    
                    //if successful, and round trip time to array and chart 
                    if (reply.Status == IPStatus.Success) 
                    {
                        long speed = reply.RoundtripTime;
                        pingResults.Visible = true;
                        pingResults.Series["ping"].Points.AddY(speed);
                        results.Add(speed);
                    }
                    else
                    {
                        //If timeout occurs, display message and exit loop
                        pingResults.Visible = false;
                        lbPingFailure.Text = "Ping Timeout!";
                        break;
                    }
                    pinger.Dispose();
                    index++;

                }
                catch (PingException)//Catch any exceptions and continue with loop
                {
                    continue;
                }
                
            } while (index < 20);

            //Make information items visible
            lbAuthenticationStatus.Visible = true;
            lbAuthenticationStatusLabel.Visible = true;
            lbConnectionStatus.Visible = true;
            lbConnectionStatusLabel.Visible = true;

            //Set information item values depending on ping results
            if (lbPingFailure.Text.Equals("Ping Timeout!"))
            {
                lbAuthenticationStatus.Text = " - ";
                lbConnectionStatus.Text = " - ";
            }
            else
            {
                long pingAverage = (long)results.Average();
                lbAverageReturnTime.Text = pingAverage.ToString() + " ms";
                lbReturnTime.Visible = true;
                lbAverageReturnTime.Visible = true;

                long pingMax = (long)results.Max();
                lbMaxReturnTime.Text = pingMax.ToString() + " ms";
                lbMaxReturnTime.Visible = true;
                lbMaxTime.Visible = true;

                long pingMin = (long)results.Min();
                lbMinReturnTime.Text = pingMin.ToString() + " ms";
                lbMinReturnTime.Visible = true;
                lbMinTime.Visible = true;

                PIServers servers = new PIServers();
                PIServer server = servers[piServerPicker2.PIServer.ToString()];

                //Attempt to connect to server
                try
                {
                    //If sucessful and both 'connection' and 'authentication' information items display this success
                    server.Connect();
                    lbAuthenticationStatus.Text = "Authentication successful";
                    lbConnectionStatus.Text = "Connection successful";
                } catch (OSIsoft.AF.PI.PIAuthenticationException)
                {
                    //If authentication exception occurs, display this
                    lbAuthenticationStatus.Text = "Authentication unsuccessful";
                    lbConnectionStatus.Text = " - ";
                } catch (Exception ex)
                {
                    //If any other exception then unsuccessful connection
                    lbAuthenticationStatus.Text = " - ";
                    lbConnectionStatus.Text = "Connection unsuccessful";

                }
                
                
            }

        }
Пример #18
0
        private void btnGetTagInfo_Click(object sender, EventArgs e)
        {
            //Enable time-range picker
            btnGetTagData.Enabled = true;
            piStartTime.Enabled = true;
            piEndTime.Enabled = true;

            //Prefill time-range
            piStartTime.Text = "*-12h";
            piEndTime.Text = "*";

            //Clear chart
            piDataChart.Series["dataSeries"].Points.Clear();

            //Clear list of data
            lbPIData.Items.Clear();

            //Connect to server
            PIServers servers = new PIServers();
            PIServer server = servers[piServerPicker1.PIServer.ToString()];

            try
            {
                //Connect to server
                server.Connect();

                //Extract tag name
                string tagname = tbEnterTag.Text;

                //Search for tag
                IList<PIPoint> points = PIPoint.FindPIPoints(server, new List<string>() { tagname });

                if (points.Count == 1)
                {
                    lbTagFound.Text = "PI tag found!";

                    //Obtain pi point.
                    PIPoint point = PIPoint.FindPIPoint(server, tagname);

                    //Extract point attributes
                    IDictionary<string, object> pointAttribs = point.GetAttributes();

                    //Extract tag attributes
                    string tag = pointAttribs["tag"].ToString();
                    string descriptor = pointAttribs["descriptor"].ToString();
                    string engunits = pointAttribs["engunits"].ToString();
                    string pointtype = pointAttribs["pointtype"].ToString();
                    string pointsource = pointAttribs["pointsource"].ToString();
                    string creationdate = pointAttribs["creationdate"].ToString();
                    string creator = pointAttribs["creator"].ToString();
                    string location1 = pointAttribs["location1"].ToString();
                    string location2 = pointAttribs["location2"].ToString();
                    string location3 = pointAttribs["location3"].ToString();
                    string location4 = pointAttribs["location4"].ToString();
                    string location5 = pointAttribs["location5"].ToString();
                    string instrumenttag = pointAttribs["instrumenttag"].ToString();

                    //Set tag attributes in relevant text fields
                    piTag.Text = tag;
                    piDescriptor.Text = descriptor;
                    piEngUnits.Text = engunits;
                    piPointType.Text = pointtype;
                    piPointSource.Text = pointsource;
                    piCreationDate.Text = creationdate;
                    piCreator.Text = creator;
                    piLocation1.Text = location1;
                    piLocation2.Text = location2;
                    piLocation3.Text = location3;
                    piLocation4.Text = location4;
                    piLocation5.Text = location5;
                    piInstrumentTag.Text = instrumenttag;

                    piCurrentValue.Text = point.CurrentValue().ToString();
                    piCurrentTimestamp.Text = point.CurrentValue().Timestamp.ToString();

                    //Get data for the tag
                    btnGetTagData.PerformClick();

                } else if (points.Count > 1)
                {
                    //If more than one tag is found matching that name, skip.
                    //Application is designed to handle only one tag at a time.
                    lbTagFound.Text = "Single tag use only.";
                }
                else
                {
                    //If tag cannot be found display message
                    lbTagFound.Text = "PI tag not found.";
                }
            } catch (OSIsoft.AF.PI.PIAuthenticationException)
            {
                //If there is an authentication error trying to connect to the server, display message
                lbTagFound.Text = "Permissions Error!";
            }

            
            
        }
Пример #19
0
        public void PiInsert(string area, DataTable dt)
        {
            //**********************Insert records into pi********************************************
            try
            {
                LabEntities       db          = new LabEntities();
                PIServers         myPIServers = new PIServers();
                PIServer          myPIServer  = myPIServers.DefaultPIServer;
                NetworkCredential credential  = new NetworkCredential("labserver", "labserver1");
                myPIServer.Connect(credential);

                var date = Convert.ToDateTime(Session["sec3_date"].ToString());
                int utc  = DateTime.UtcNow.Hour;
                int dt_  = DateTime.Now.Hour;

                bool dst = DSTcheck();
                if (dst)
                {
                    dt_ = dt_ - 1;
                }
                int diff;
                if (utc > dt_)
                {
                    diff = utc - dt_;
                }
                else
                {
                    diff = utc + 24 - dt_;
                }
                if (area == "caustic_clean")
                {
                    var PiTagList = (from v in db.Lab_TagTable
                                     where v.Tag_Name == area
                                     orderby v.Max, v.Min
                                     select v).ToList();
                    DataTable dt_copy = new DataTable();
                    dt_copy = dt.Copy();
                    dt_copy.Columns.RemoveAt(0);
                    dt_copy.Columns.RemoveAt(3);

                    for (int i = 0; i < dt_copy.Rows.Count; i++)
                    {
                        for (int j = 0; j < dt_copy.Columns.Count; j++)
                        {
                            string TagName      = PiTagList[j].Pi_Tags;
                            string TagName_test = PiTagList[j].Pi_Tags_Test;;
                            {
                                //PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, TagName_test);
                                PIPoint myPIPoint  = PIPoint.FindPIPoint(myPIServer, TagName); //-- use this when go to production
                                AFValue currentTag = myPIPoint.CurrentValue();
                                currentTag.Timestamp = date;
                                currentTag.Value     = Convert.ToString(dt_copy.Rows[i][j]);



                                string   ctv         = currentTag.Value.ToString();
                                DateTime cttimestamp = currentTag.Timestamp;
                                DateTime d           = cttimestamp.Date;

                                if (!string.IsNullOrEmpty(currentTag.Value.ToString()))
                                {
                                    currentTag.Value     = Convert.ToString(dt_copy.Rows[i][j]);
                                    currentTag.Timestamp = date.AddHours(diff + i);
                                    myPIPoint.UpdateValue(currentTag, AFUpdateOption.Insert);
                                }
                            }
                        }
                    }
                }

                else
                {
                    var PiTagList = (from v in db.Lab_TagTable
                                     where v.Tag_Name == area
                                     orderby v.Max, v.Min
                                     select v).ToList();
                    DataTable dt_copy = new DataTable();
                    dt_copy = dt.Copy();
                    dt_copy.Columns.RemoveAt(0);
                    dt_copy.Columns.RemoveAt(0);
                    {
                        for (int i = 0; i < dt_copy.Rows.Count; i++)
                        {
                            for (int j = 0; j < dt_copy.Columns.Count; j++)
                            {
                                //string TagName = item.Pi_Tags_Test.Substring(0, item.Pi_Tags_Test.Length - 5);
                                //string TagName_test = item.Pi_Tags_Test;
                                //int g;
                                //if (i != 0)
                                //{
                                //    g = (8 * i) + j;
                                //}
                                //else
                                //    g = j;

                                if (area == "st_topsamples" || area == "tt_topsamples")
                                {
                                    TagName      = PiTagList[j].Pi_Tags;
                                    TagName_test = PiTagList[j].Pi_Tags_Test;;
                                }
                                else
                                {
                                    int g;
                                    if (i != 0)
                                    {
                                        g            = (8 * i) + j;
                                        TagName      = PiTagList[g].Pi_Tags;
                                        TagName_test = PiTagList[g].Pi_Tags_Test;
                                    }
                                    else
                                    {
                                        TagName      = PiTagList[j].Pi_Tags;
                                        TagName_test = PiTagList[j].Pi_Tags_Test;
                                    }
                                }
                                {
                                    //PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, TagName_test);
                                    PIPoint myPIPoint  = PIPoint.FindPIPoint(myPIServer, TagName); //-- use this when go to production
                                    AFValue currentTag = myPIPoint.CurrentValue();

                                    string s = Convert.ToString(dt_copy.Rows[i][j]);
                                    currentTag.Value     = Convert.ToString(dt_copy.Rows[i][j]);
                                    currentTag.Timestamp = date.AddHours(diff);
                                    if (!string.IsNullOrEmpty(currentTag.Value.ToString()))
                                    {
                                        myPIPoint.UpdateValue(currentTag, AFUpdateOption.Insert);
                                    }
                                }
                            }
                        }
                    }


                    myPIServer.Disconnect();
                }
            }
            catch (Exception exs)
            {
                string filePath = @"C:\Error.txt";

                using (StreamWriter writer = new StreamWriter(filePath, true))
                {
                    writer.WriteLine("Message :" + exs.Message + "<br/>" + Environment.NewLine + "StackTrace :" + exs.StackTrace +
                                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
            }
            //*************************End*******************************
        }
 public Application()
 {
     myPIServers = new PIServers();
     myPIServer = myPIServers["MARC-PI2016"];
     myPIServer.Connect();
 }
Пример #21
0
        public void OMFTest()
        {
            // Use ticks as a unique id mask to avoid naming collisions with other PI Points
            var               idTicks           = $"{DateTime.UtcNow.Ticks}";
            string            typeId            = $"TankMeasurement{idTicks}";
            string            containerId       = $"Tank1Measurements{idTicks}";
            PISystem          omfAFServer       = null;
            AFDatabase        omfDatabase       = null;
            PIServer          omfPIServer       = null;
            List <PIPoint>    omfPIPoints       = null;
            AFElementTemplate omfTypeAsTemplate = null;
            var               jsonType          = @"[
                {
                    ""id"": """ + typeId + @""",
                    ""version"": ""1.0.0.0"",
                    ""type"": ""object"",
                    ""classification"": ""dynamic"",
                    ""properties"": {
                            ""Time"": {
                                ""format"": ""date-time"",
                                    ""type"": ""string"",
                                    ""isindex"": true
                            },
                            ""Pressure"": {
                                ""type"": ""number"",
                                    ""name"": ""Tank Pressure""
                            },
                            ""Temperature"": {
                                ""type"": ""number"",
                                    ""name"": ""Tank Temperature""
                            }
                        }
                    }
                ]";

            var jsonContainer = @"[{
                ""id"": """ + containerId + @""",
                ""typeid"": """ + typeId + @""",
                ""typeVersion"": ""1.0.0.0"",
                ""indexes"": [""Pressure""]
            }]";

            var jsonData = @"[{
                    ""containerid"": """ + containerId + @""",
                    ""values"": [{
                            ""Time"": ""2017-01-11T22:24:23.430Z"",
                            ""Pressure"": 11.5,
                            ""Temperature"": 101
                    }]
            }]";

            var coll = new NameValueCollection
            {
                { "messagetype", "type" },
                { "messageformat", "json" },
                { "omfversion", "1.1" },
                { "action", "create" },
            };

            try
            {
                // Create the type object
                var omfUrl = $"{Fixture.HomePageUrl}/omf";
                Fixture.Client.Headers.Add(coll);
                Output.WriteLine($"Create OMF type through Web API using Url [{omfUrl}] and JSON [{jsonType}].");
                var createTypeResponse = JObject.Parse(Fixture.Client.UploadString(omfUrl, "POST", jsonType));
                Assert.True(createTypeResponse["OperationId"] != null, $"OperationId not returned in OMF response.");

                // Create a container for the created type
                Fixture.Client.Headers["messagetype"] = "container";
                Output.WriteLine($"Create OMF container through Web API using Url [{omfUrl}] and JSON [{jsonContainer}].");
                var createContainerResponse = JObject.Parse(Fixture.Client.UploadString(omfUrl, "POST", jsonContainer));
                Assert.True(createContainerResponse["OperationId"] != null, "OperationId not returned in OMF response.");

                // Add data to the container
                Fixture.Client.Headers["messagetype"] = "data";
                Output.WriteLine($"Add data to the OMF container through Web API using Url [{omfUrl}] and JSON [{jsonData}].");
                var createDataResponse = JObject.Parse(Fixture.Client.UploadString(omfUrl, "POST", jsonData));
                Assert.True(createDataResponse["OperationId"] != null, "OperationId not returned in OMF response.");

                // Verify objects were created correctly in AF and PI
                var instanceConfigUrl = $"{Fixture.HomePageUrl}/system/instanceconfiguration";
                var config            = JObject.Parse(Fixture.Client.DownloadString(instanceConfigUrl));
                Output.WriteLine($"Verify OMF objects were create in AF and PI through Web API using Url [{instanceConfigUrl}].");
                omfAFServer = new PISystems()[(string)config["OmfAssetServerName"]];
                omfDatabase = omfAFServer.Databases[(string)config["OmfAssetDatabaseName"]];
                omfPIServer = PIServers.GetPIServers()[(string)config["OmfDataArchiveName"]];
                if (omfPIServer.ConnectionInfo == null)
                {
                    omfPIServer.Connect();
                }

                var typeInAF = omfDatabase.ElementTemplates[typeId];
                Assert.True(typeInAF != null, $"The OMF Type [{typeId}] should exist as an ElementTemplate in [{omfDatabase}] on [{omfAFServer}].");

                var pointFound = PIPoint.TryFindPIPoint(omfPIServer, $"{containerId}.Pressure", out var piPointPressure);
                Assert.True(pointFound, $"PI Point [{containerId}.Pressure] not found in [{omfPIServer.Name}].");
                Assert.True(piPointPressure.CurrentValue().ValueAsSingle() == 11.5,
                            $"Value for PI Point [{containerId}.Pressure] incorrect. Expected: [11.5], Actual: [{piPointPressure.CurrentValue().ValueAsSingle()}].");
                pointFound = PIPoint.TryFindPIPoint(omfPIServer, $"{containerId}.Temperature", out var piPointTemperature);
                Assert.True(pointFound, $"PI Point [{containerId}.Temperature] not found in [{omfPIServer.Name}].");
                Assert.True(piPointTemperature.CurrentValue().ValueAsInt32() == 101,
                            $"Value for PI Point [{containerId}.Temperature] incorrect. Expected: [101], Actual: [{piPointTemperature.CurrentValue().ValueAsInt32()}].");

                // Delete the data
                Output.WriteLine("Delete OMF data.");
                Fixture.Client.Headers["action"] = "delete";
                var deleteDataResponse = JObject.Parse(Fixture.Client.UploadString(omfUrl, "POST", jsonData));
                Assert.True(deleteDataResponse["OperationId"] != null, "OperationId not returned in OMF response.");

                // Delete the container
                Fixture.Client.Headers["messagetype"] = "container";
                var deleteContainerResponse = JObject.Parse(Fixture.Client.UploadString(omfUrl, "POST", jsonContainer));
                Assert.True(deleteContainerResponse["OperationId"] != null, "OperationId not returned in OMF response.");

                // Delete the type
                Fixture.Client.Headers["messagetype"] = "type";
                var deleteTypeResponse = JObject.Parse(Fixture.Client.UploadString(omfUrl, "POST", jsonType));
                Assert.True(deleteTypeResponse["OperationId"] != null, "OperationId not returned in OMF response.");

                // Verify objects were deleted. Remove objects that were not deleted before Assert to ensure cleanup
                omfPIPoints = PIPoint.FindPIPoints(omfPIServer, $"{containerId}*", null, null).ToList();
                omfDatabase.ElementTemplates.Refresh();
                omfTypeAsTemplate = omfDatabase.ElementTemplates[typeId];

                Assert.True(omfPIPoints.Count == 0, "PIPoints were not deleted by the DELETE CONTAINER request to OMF.");
                Assert.True(omfTypeAsTemplate == null, $"The OMF Type [{typeId}] was not deleted by the DELETE TYPE request to OMF.");
            }
            catch (WebException ex)
            {
                var httpResponse = (HttpWebResponse)ex.Response;
                var statusCode   = string.Empty;
                if (httpResponse.StatusCode != HttpStatusCode.OK &&
                    httpResponse.StatusCode != HttpStatusCode.Accepted &&
                    httpResponse.StatusCode != HttpStatusCode.NoContent)
                {
                    statusCode = $"{httpResponse.StatusCode}: {httpResponse.StatusDescription}";
                }

                // For troubleshooting error response codes returned by PI Web API
                using (var reader = new StreamReader(ex.Response.GetResponseStream()))
                {
                    var response = JObject.Parse(reader.ReadToEnd())["Messages"]?[0]["Events"]?[0]["Message"]?.ToString();
                    if (!string.IsNullOrEmpty(response))
                    {
                        Assert.True(false, $"Error returned from OMF: {response}. {statusCode}.");
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            finally
            {
                // Clean up any existing OMF objects if not deleted by OMF
                if (omfPIServer != null)
                {
                    if (omfPIServer.ConnectionInfo == null)
                    {
                        omfPIServer.Connect();
                    }
                    omfPIPoints = PIPoint.FindPIPoints(omfPIServer, $"{containerId}*", null, null).ToList();
                    bool pointsDeleted = omfPIPoints.Count == 0;
                    if (!pointsDeleted)
                    {
                        omfPIServer.DeletePIPoints(omfPIPoints.Select(p => p.Name).ToList());
                    }
                }

                if (omfAFServer != null && omfDatabase != null)
                {
                    omfTypeAsTemplate = omfDatabase.ElementTemplates[typeId];
                    bool typeDeleted = omfTypeAsTemplate == null;
                    if (!typeDeleted)
                    {
                        AFElementTemplate.DeleteElementTemplates(omfAFServer, new List <Guid> {
                            omfTypeAsTemplate.ID
                        });
                    }
                }
            }
        }
Пример #22
0
        public void PiInsert(string Product, DataTable dt)
        {
            //**********************Insert records into pi********************************************

            try
            {
                LabEntities       db          = new LabEntities();
                PIServers         myPIServers = new PIServers();
                PIServer          myPIServer  = myPIServers.DefaultPIServer;
                NetworkCredential credential  = new NetworkCredential("labserver", "labserver1");
                myPIServer.Connect(credential);

                Dictionary <string, decimal?> piTagValues = new Dictionary <string, decimal?>();
                var PiTaglist = (from v in db.Lab_TagTable
                                 orderby v.Id
                                 select v).Skip(39).Take(44);

                var date = Convert.ToDateTime(Session["alumina_date"].ToString());

                int utc = DateTime.UtcNow.Hour;
                int dt_ = DateTime.Now.Hour;

                bool dst = DSTcheck();
                if (dst)
                {
                    dt_ = dt_ - 1;
                }
                int diff;
                if (utc > dt_)
                {
                    diff = utc - dt_;
                }
                else
                {
                    diff = utc + 24 - dt_;
                }

                //type is not feed moisture
                if (Product == "ALUMINA")
                {
                    //string s = type.Substring(0, type.Length - 4);
                    //string input = type.Substring(type.Length - 4);
                    //int time = Convert.ToInt16(input.TrimEnd('0'));
                    //DateTime datetime;
                    //TimeSpan ts;
                    //if (time == 24)
                    //{
                    //    ts = new TimeSpan(23, 59, 59);
                    //}
                    //else ts = new TimeSpan(time, 0, 0);


                    //datetime = date + ts;

                    //decimal? s = (decimal?)null;
                    //bool nulloremtpy = string.IsNullOrWhiteSpace(dt.Rows[0]["value"].ToString());

                    piTagValues.Add("LABALUMINA_LOI", string.IsNullOrWhiteSpace(dt.Rows[0]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[0]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_P100", string.IsNullOrWhiteSpace(dt.Rows[1]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[1]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_P200", string.IsNullOrWhiteSpace(dt.Rows[2]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[2]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_P325", string.IsNullOrWhiteSpace(dt.Rows[3]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[3]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_BULKDENS", string.IsNullOrWhiteSpace(dt.Rows[4]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[4]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_SI", string.IsNullOrWhiteSpace(dt.Rows[5]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[5]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_FE", string.IsNullOrWhiteSpace(dt.Rows[6]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[6]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_NA", string.IsNullOrWhiteSpace(dt.Rows[7]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[7]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_ZN", string.IsNullOrWhiteSpace(dt.Rows[8]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[8]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_MN", string.IsNullOrWhiteSpace(dt.Rows[9]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[9]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_CA", string.IsNullOrWhiteSpace(dt.Rows[10]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[10]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_TI", string.IsNullOrWhiteSpace(dt.Rows[11]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[11]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_AI", string.IsNullOrWhiteSpace(dt.Rows[12]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[12]["value"].ToString()));
                    piTagValues.Add("LABALUMINA_M20", string.IsNullOrWhiteSpace(dt.Rows[13]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[13]["value"].ToString()));


                    foreach (KeyValuePair <string, decimal?> entry in piTagValues)
                    {
                        foreach (var item in PiTaglist)
                        {
                            string TagName      = item.Pi_Tags_Test.Substring(0, item.Pi_Tags_Test.Length - 5);
                            string TagName_test = item.Pi_Tags_Test;
                            if (TagName == entry.Key)
                            {
                                //PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, TagName_test);
                                PIPoint myPIPoint  = PIPoint.FindPIPoint(myPIServer, TagName); //use this when go to production
                                AFValue currentTag = myPIPoint.CurrentValue();
                                currentTag.Value = Convert.ToString(entry.Value);

                                //string ctv = currentTag.Value.ToString();
                                //DateTime cttimestamp = currentTag.Timestamp;
                                //DateTime d = cttimestamp.Date;
                                currentTag.Timestamp = date.AddHours(diff);



                                if (!string.IsNullOrEmpty(currentTag.Value.ToString()))
                                {
                                    //if (ctv != null && d != date)
                                    //{

                                    myPIPoint.UpdateValue(currentTag, AFUpdateOption.Insert);
                                    //}
                                    //else
                                    //{
                                    //    currentTag.Timestamp = date.AddHours(diff);
                                    //    myPIPoint.UpdateValue(currentTag, AFUpdateOption.Replace);
                                    //}
                                }
                            }
                        }
                    }
                }
                else if (Product == "HYDRATE")
                {
                    piTagValues.Add("LABHYDRATE_P100", string.IsNullOrWhiteSpace(dt.Rows[0]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[0]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_P200", string.IsNullOrWhiteSpace(dt.Rows[1]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[1]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_P325", string.IsNullOrWhiteSpace(dt.Rows[2]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[2]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_SI", string.IsNullOrWhiteSpace(dt.Rows[3]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[3]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_FE", string.IsNullOrWhiteSpace(dt.Rows[4]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[4]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_NA", string.IsNullOrWhiteSpace(dt.Rows[5]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[5]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_ZN", string.IsNullOrWhiteSpace(dt.Rows[6]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[6]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_MN", string.IsNullOrWhiteSpace(dt.Rows[7]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[7]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_CA", string.IsNullOrWhiteSpace(dt.Rows[8]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[8]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_TI", string.IsNullOrWhiteSpace(dt.Rows[9]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[9]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_AI", string.IsNullOrWhiteSpace(dt.Rows[10]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[10]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_FREEMOIST", string.IsNullOrWhiteSpace(dt.Rows[11]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[11]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_CSEDS", string.IsNullOrWhiteSpace(dt.Rows[12]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[12]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_INSOLS", string.IsNullOrWhiteSpace(dt.Rows[13]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[13]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_BULKDENS", string.IsNullOrWhiteSpace(dt.Rows[14]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[14]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_HUNTERL", string.IsNullOrWhiteSpace(dt.Rows[15]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[15]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_HUNTERA", string.IsNullOrWhiteSpace(dt.Rows[16]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[16]["value"].ToString()));
                    piTagValues.Add("LABHYDRATE_HUNTERB", string.IsNullOrWhiteSpace(dt.Rows[17]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[17]["value"].ToString()));

                    foreach (KeyValuePair <string, decimal?> entry in piTagValues)
                    {
                        foreach (var item in PiTaglist)
                        {
                            string TagName      = item.Pi_Tags_Test.Substring(0, item.Pi_Tags_Test.Length - 5);
                            string TagName_test = item.Pi_Tags_Test;
                            if (TagName == entry.Key)
                            {
                                //PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, TagName_test);
                                PIPoint myPIPoint  = PIPoint.FindPIPoint(myPIServer, TagName); // use this when go to production
                                AFValue currentTag = myPIPoint.CurrentValue();
                                currentTag.Value = Convert.ToString(entry.Value);

                                //string ctv = currentTag.Value.ToString();
                                //DateTime cttimestamp = currentTag.Timestamp;
                                //DateTime d = cttimestamp.Date;

                                currentTag.Timestamp = date.AddHours(diff);


                                if (!string.IsNullOrEmpty(currentTag.Value.ToString()))
                                {
                                    //if (ctv != null && d != date)
                                    //{

                                    //    currentTag.Timestamp = date.AddHours(diff);
                                    myPIPoint.UpdateValue(currentTag, AFUpdateOption.Insert);
                                    //    }
                                    //    else
                                    //    {

                                    //        currentTag.Timestamp = date.AddHours(diff);
                                    //        myPIPoint.UpdateValue(currentTag, AFUpdateOption.Replace);
                                    //    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    piTagValues.Add("LABWETHYDRATE_P100", string.IsNullOrWhiteSpace(dt.Rows[0]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[0]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_P200", string.IsNullOrWhiteSpace(dt.Rows[1]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[1]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_P325", string.IsNullOrWhiteSpace(dt.Rows[2]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[2]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_SI", string.IsNullOrWhiteSpace(dt.Rows[3]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[3]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_FE", string.IsNullOrWhiteSpace(dt.Rows[4]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[4]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_NA", string.IsNullOrWhiteSpace(dt.Rows[5]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[5]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_ZN", string.IsNullOrWhiteSpace(dt.Rows[6]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[6]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_MN", string.IsNullOrWhiteSpace(dt.Rows[7]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[7]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_CA", string.IsNullOrWhiteSpace(dt.Rows[8]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[8]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_TI", string.IsNullOrWhiteSpace(dt.Rows[9]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[9]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_CSEDS", string.IsNullOrWhiteSpace(dt.Rows[10]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[10]["value"].ToString()));
                    piTagValues.Add("LABWETHYDRATE_INSOLS", string.IsNullOrWhiteSpace(dt.Rows[11]["value"].ToString()) ? (decimal?)null : Convert.ToDecimal(dt.Rows[11]["value"].ToString()));


                    foreach (KeyValuePair <string, decimal?> entry in piTagValues)
                    {
                        foreach (var item in PiTaglist)
                        {
                            string TagName      = item.Pi_Tags_Test.Substring(0, item.Pi_Tags_Test.Length - 5);
                            string TagName_test = item.Pi_Tags_Test;
                            if (TagName == entry.Key)
                            {
                                // PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, TagName_test);
                                PIPoint myPIPoint  = PIPoint.FindPIPoint(myPIServer, TagName); // use this when go to production
                                AFValue currentTag = myPIPoint.CurrentValue();
                                currentTag.Value = Convert.ToString(entry.Value);

                                //string ctv = currentTag.Value.ToString();
                                //DateTime cttimestamp = currentTag.Timestamp;
                                //DateTime d = cttimestamp.Date;


                                currentTag.Timestamp = date.AddHours(diff);

                                if (!string.IsNullOrEmpty(currentTag.Value.ToString()))
                                {
                                    //if (ctv != null && d != date)
                                    //{

                                    myPIPoint.UpdateValue(currentTag, AFUpdateOption.Insert);
                                    //}
                                    //else
                                    //{
                                    //    currentTag.Timestamp = date.AddHours(diff);
                                    //    myPIPoint.UpdateValue(currentTag, AFUpdateOption.Replace);
                                    //}
                                }
                            }
                        }
                    }
                }

                myPIServer.Disconnect();
            }
            catch (Exception ex)
            {
            }

            //*************************End*******************************
        }
Пример #23
0
 public PIConnection()
 {
     database = new PISystems().DefaultPISystem.Databases.DefaultDatabase;
     server   = PIServers.GetPIServers().DefaultPIServer;
     server.Connect();
 }