Example #1
0
        static void DisconnectHistorian(HistorianAccess historian)
        {
            Console.WriteLine("Closing connection, please wait...");
            HistorianAccessError error;

            if (historian != null)
            {
                if (!historian.CloseConnection(out error))
                {
                    Console.WriteLine("Failed to close historian connection: {0} {1} {2}",
                                      error.ErrorType, error.ErrorCode, error.ErrorDescription);
                }
            }
        }
Example #2
0
        static void ConnectHistorian(HistorianAccess historian)
        {
            HistorianConnectionArgs connectionArgs = JsonConvert.DeserializeObject <HistorianConnectionArgs>(System.IO.File.ReadAllText("historianconnectionsettings.json"));

            Console.WriteLine("Initiating asynchronous historian connection, please wait...");
            HistorianAccessError error;

            if (!historian.OpenConnection(connectionArgs, out error))
            {
                Console.WriteLine("Failed to initiate historian connection: {0} {1} {2}",
                                  error.ErrorType, error.ErrorCode, error.ErrorDescription);
            }

            log.Info("Checking connection status...");
            HistorianConnectionStatus connectionStatus = new HistorianConnectionStatus();

            for (; ;)
            {
                historian.GetConnectionStatus(ref connectionStatus);
                if (connectionStatus.Pending)
                {
                    Console.WriteLine("Connection is pending");
                    Thread.Sleep(1000);
                    continue;
                }
                if (connectionStatus.ErrorOccurred)
                {
                    Console.WriteLine("Connection error: {0}",
                                      connectionStatus.Error.ErrorDescription);
                }

                Console.WriteLine("Server = {0}, ServerStorage = {1}, StoreForward = {2}",
                                  connectionStatus.ConnectedToServer,
                                  connectionStatus.ConnectedToServerStorage,
                                  connectionStatus.ConnectedToStoreForward);

                //Console.WriteLine("Press 'x' to continue or any other key to recheck the status");
                //if (Console.ReadKey(true).KeyChar == 'x')
                break;
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            try
            {
                log.Info("Starting " + System.AppDomain.CurrentDomain.FriendlyName);

                _HistorianTags = new SubscriptionList();
                _HistorianTags = JsonConvert.DeserializeObject <SubscriptionList>(System.IO.File.ReadAllText("subscriptions.json"));

                _historian    = new HistorianAccess();
                _messageQueue = new Queue <TimestampedMqttMsgPublishEventArgs>();

                //_historianQueueTimer = new Timer(HistorianQueueTimerTick, null,0,1000);

                sw = new System.Diagnostics.Stopwatch();
                //_timeCount = 0;
                //timings = new List<float>();

                ConnectHistorian(_historian);
                AddHistorianTags();
                ConnectMQTT();

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                log.Error(ex);
                Console.ReadLine();
            }
            finally
            {
                // Always disconnect on shutdown
                DisconnectMQTT();
                DisconnectHistorian(_historian);
            }
        }