Ejemplo n.º 1
0
        private TrendBundle trendBundle;                  // the chart data of many channels


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public ChartDataBuilder(ConfigDataset configDataset, ScadaClient scadaClient, ChartDataBuilderOptions options)
        {
            this.configDataset = configDataset ?? throw new ArgumentNullException(nameof(configDataset));
            this.scadaClient   = scadaClient ?? throw new ArgumentNullException(nameof(scadaClient));
            this.options       = options ?? throw new ArgumentNullException(nameof(options));
            options.Validate();
            formatter = new CnlDataFormatter(configDataset);

            cnls        = Array.Empty <Cnl>();
            singleTrend = null;
            trendBundle = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the data source.
        /// </summary>
        public override void Start()
        {
            scadaClient = new ScadaClient(connOptions);

            if (options.ClientLogEnabled)
            {
                scadaClient.CommLog = CreateClientLog();
            }

            terminated = false;
            thread     = new Thread(Execute);
            thread.Start();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public EventWorkbookBuilder(ConfigDatabase configDatabase, ScadaClient scadaClient, string templateDir)
        {
            this.configDatabase        = configDatabase ?? throw new ArgumentNullException(nameof(configDatabase));
            this.scadaClient           = scadaClient ?? throw new ArgumentNullException(nameof(scadaClient));
            templateFilePath           = Path.Combine(templateDir, TemplateFileName);
            renderer                   = new WorkbookRenderer();
            renderer.BeforeProcessing += Renderer_BeforeProcessing;
            renderer.AfterProcessing  += Renderer_AfterProcessing;
            renderer.DirectiveFound   += Renderer_DirectiveFound;
            dict = Locale.GetDictionary("Scada.Web.Plugins.PlgMain.Code.EventWorkbookBuilder");

            workbookArgs     = null;
            archiveEntity    = null;
            eventRowTemplate = null;
            currentEventF    = null;

            GenerateTime = DateTime.MinValue;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Prepares the logic processing.
        /// </summary>
        private void PrepareProcessing()
        {
            terminated    = false;
            utcStartDT    = DateTime.UtcNow;
            startDT       = utcStartDT.ToLocalTime();
            serviceStatus = ServiceStatus.Starting;
            WriteInfo();

            BaseDataSet = null;
            SharedData  = new ConcurrentDictionary <string, object>();
            scadaClient = Config.GeneralOptions.InteractWithServer ?
                          new ScadaClient(Config.ConnectionOptions)
            {
                CommLog = CreateClientLog()
            } : null;
            commLines = new List <CommLine>(Config.Lines.Count);
            InitDrivers();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reads the configuration database.
        /// </summary>
        public override bool ReadBase(out BaseDataSet baseDataSet)
        {
            // do not read the configuration database from the server that likely contains partial data
            if (deviceFilter != null)
            {
                baseDataSet = null;
                return(false);
            }

            string tableName = Locale.IsRussian ? "неопределена" : "undefined";

            try
            {
                log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                "Приём базы конфигурации" :
                                "Receive the configuration database");

                ScadaClient localClient = new ScadaClient(connOptions);
                baseDataSet = new BaseDataSet();

                foreach (IBaseTable baseTable in baseDataSet.AllTables)
                {
                    tableName = baseTable.Name;
                    localClient.DownloadBaseTable(baseTable);
                }

                localClient.TerminateSession();
                log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                "База конфигурации получена успешно" :
                                "The configuration database has been received successfully");
                return(true);
            }
            catch (Exception ex)
            {
                log.WriteException(ex, CommPhrases.DataSourceMessage, Code, string.Format(Locale.IsRussian ?
                                                                                          "Ошибка при приёме базы конфигурации, таблица {0}" :
                                                                                          "Error receiving the configuration database, the {0} table", tableName));
                baseDataSet = null;
                return(false);
            }
        }
Ejemplo n.º 6
0
        private int eventSkipped;                                        // the number of skipped events


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public ScadaServerDSL(ICommContext commContext, DataSourceConfig dataSourceConfig)
            : base(commContext, dataSourceConfig)
        {
            options       = new ScadaServerDSO(dataSourceConfig.CustomOptions);
            maxCurDataAge = TimeSpan.FromSeconds(options.MaxCurDataAge);
            dataLifetime  = TimeSpan.FromSeconds(options.DataLifetime);
            deviceFilter  = options.DeviceFilter.Count > 0 ? new HashSet <int>(options.DeviceFilter) : null;
            log           = commContext.Log;

            maxQueueSize  = Math.Max(options.MaxQueueSize, MinQueueSize);
            curDataQueue  = new Queue <QueueItem <DeviceSlice> >(maxQueueSize);
            histDataQueue = new Queue <QueueItem <DeviceSlice> >(maxQueueSize);
            eventQueue    = new Queue <QueueItem <DeviceEvent> >(maxQueueSize);

            connOptions     = null;
            scadaClient     = null;
            thread          = null;
            terminated      = false;
            curDataSkipped  = 0;
            histDataSkipped = 0;
            eventSkipped    = 0;
        }
Ejemplo n.º 7
0
        private DriverHolder driverHolder;    // holds drivers


        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        public CoreLogic(CommConfig config, CommDirs appDirs, ILog log)
        {
            Config      = config ?? throw new ArgumentNullException(nameof(config));
            AppDirs     = appDirs ?? throw new ArgumentNullException(nameof(appDirs));
            Log         = log ?? throw new ArgumentNullException(nameof(log));
            BaseDataSet = null;
            SharedData  = null;

            infoFileName = Path.Combine(appDirs.LogDir, CommUtils.InfoFileName);

            thread             = null;
            terminated         = false;
            utcStartDT         = DateTime.MinValue;
            startDT            = DateTime.MinValue;
            serviceStatus      = ServiceStatus.Undefined;
            lastInfoLength     = 0;
            maxLineTitleLength = 0;

            scadaClient  = null;
            commLines    = null;
            driverHolder = null;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the configuration database.
        /// </summary>
        public override bool ReadConfigDatabase(out ConfigDatabase configDatabase)
        {
            // do not read the configuration database from the server that likely contains partial data
            if (deviceFilter != null)
            {
                configDatabase = null;
                return(false);
            }

            log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                            "Приём базы конфигурации" :
                            "Receive the configuration database");

            // check connection
            ScadaClient localClient = new ScadaClient(connOptions);

            try
            {
                localClient.GetStatus(out bool serverIsReady, out bool userIsLoggedIn);

                if (!serverIsReady)
                {
                    localClient.TerminateSession();
                    log.WriteError(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                   "Сервер не готов" :
                                   "Server is not ready");
                    configDatabase = null;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                log.WriteError(ex.BuildErrorMessage(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                                    "Ошибка при проверке соединения с сервером" :
                                                    "Error checking server connection"));
                configDatabase = null;
                return(false);
            }

            // receive tables
            string tableName = CommonPhrases.UndefinedTable;

            try
            {
                configDatabase = new ConfigDatabase();

                foreach (IBaseTable baseTable in configDatabase.AllTables)
                {
                    tableName = baseTable.Name;
                    localClient.DownloadBaseTable(baseTable);
                }

                log.WriteAction(CommPhrases.DataSourceMessage, Code, Locale.IsRussian ?
                                "База конфигурации получена успешно" :
                                "The configuration database has been received successfully");
                return(true);
            }
            catch (Exception ex)
            {
                log.WriteError(ex, CommPhrases.DataSourceMessage, Code, string.Format(Locale.IsRussian ?
                                                                                      "Ошибка при приёме базы конфигурации, таблица {0}" :
                                                                                      "Error receiving the configuration database, the {0} table", tableName));
                configDatabase = null;
                return(false);
            }
            finally
            {
                localClient.TerminateSession();
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public ClientAccessor(IWebContext webContext)
 {
     this.webContext = webContext ?? throw new ArgumentNullException(nameof(webContext));
     scadaClient     = null;
 }