Exemplo n.º 1
0
        /// <summary>
        /// Initializes this <see cref="LocalOutputAdapter"/>.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            //const string errorMessage = "{0} is missing from Settings - Example: instanceName=default; ArchiveDirectories={{c:\\Archive1\\;d:\\Backups2\\}}; dataChannel={{port=9591; interface=0.0.0.0}}";
            Dictionary <string, string> settings = Settings;
            string setting;

            // Validate settings.
            if (!settings.TryGetValue("instanceName", out m_instanceName) || string.IsNullOrWhiteSpace(m_instanceName))
            {
                m_instanceName = Name;
            }

            // Track instance in static dictionary
            Instances[InstanceName] = this;

            if (!settings.TryGetValue("WorkingDirectory", out setting) || string.IsNullOrEmpty(setting))
            {
                setting = "Archive";
            }

            WorkingDirectory = setting;

            if (settings.TryGetValue("ArchiveDirectories", out setting))
            {
                ArchiveDirectories = setting;
            }

            if (settings.TryGetValue("AttachedPaths", out setting))
            {
                AttachedPaths = setting;
            }

            if (!settings.TryGetValue("DataChannel", out m_dataChannel))
            {
                m_dataChannel = DefaultDataChannel;
            }

            double targetFileSize;

            if (!settings.TryGetValue("TargetFileSize", out setting) || !double.TryParse(setting, out targetFileSize))
            {
                targetFileSize = DefaultTargetFileSize;
            }

            if (targetFileSize < 0.1D || targetFileSize > SI2.Tera)
            {
                targetFileSize = DefaultTargetFileSize;
            }

            if (!settings.TryGetValue("MaximumArchiveDays", out setting) || !int.TryParse(setting, out m_maximumArchiveDays))
            {
                m_maximumArchiveDays = DefaultMaximumArchiveDays;
            }

            if (!settings.TryGetValue("DirectoryNamingMode", out setting) || !Enum.TryParse(setting, true, out m_directoryNamingMode))
            {
                DirectoryNamingMode = DefaultDirectoryNamingMode;
            }

            // Handle advanced settings - there are hidden but available from manual entry into connection string
            int stagingCount, diskFlushInterval, cacheFlushInterval;

            if (!settings.TryGetValue("StagingCount", out setting) || !int.TryParse(setting, out stagingCount))
            {
                stagingCount = 3;
            }

            if (!settings.TryGetValue("DiskFlushInterval", out setting) || !int.TryParse(setting, out diskFlushInterval))
            {
                diskFlushInterval = 10000;
            }

            if (!settings.TryGetValue("CacheFlushInterval", out setting) || !int.TryParse(setting, out cacheFlushInterval))
            {
                cacheFlushInterval = 100;
            }

            // Establish archive information for this historian instance
            m_archiveInfo = new HistorianServerDatabaseConfig(InstanceName, WorkingDirectory, true);

            if ((object)m_archiveDirectories != null)
            {
                m_archiveInfo.FinalWritePaths.AddRange(m_archiveDirectories);
            }

            if ((object)m_attachedPaths != null)
            {
                m_archiveInfo.ImportPaths.AddRange(m_attachedPaths);
            }

            m_archiveInfo.TargetFileSize     = (long)(targetFileSize * SI.Giga);
            m_archiveInfo.DirectoryMethod    = DirectoryNamingMode;
            m_archiveInfo.StagingCount       = stagingCount;
            m_archiveInfo.DiskFlushInterval  = diskFlushInterval;
            m_archiveInfo.CacheFlushInterval = cacheFlushInterval;

            // Provide web service support
            m_dataServices = new DataServices();
            m_dataServices.AdapterCreated       += DataServices_AdapterCreated;
            m_dataServices.AdapterLoaded        += DataServices_AdapterLoaded;
            m_dataServices.AdapterUnloaded      += DataServices_AdapterUnloaded;
            m_dataServices.AdapterLoadException += AdapterLoader_AdapterLoadException;

            // Provide archive replication support
            m_replicationProviders = new ReplicationProviders();
            m_replicationProviders.AdapterCreated       += ReplicationProviders_AdapterCreated;
            m_replicationProviders.AdapterLoaded        += ReplicationProviders_AdapterLoaded;
            m_replicationProviders.AdapterUnloaded      += ReplicationProviders_AdapterUnloaded;
            m_replicationProviders.AdapterLoadException += AdapterLoader_AdapterLoadException;

            if (MaximumArchiveDays > 0)
            {
                m_dailyTimer           = new Timer(Time.SecondsPerDay * 1000.0D);
                m_dailyTimer.AutoReset = true;
                m_dailyTimer.Elapsed  += m_dailyTimer_Elapsed;
                m_dailyTimer.Enabled   = true;
            }
        }
        /// <summary>
        /// Initializes this <see cref="LocalOutputAdapter"/>.
        /// </summary>
        /// <exception cref="ArgumentException"><b>InstanceName</b> is missing from the <see cref="AdapterBase.Settings"/>.</exception>
        public override void Initialize()
        {
            base.Initialize();

            Dictionary<string, string> settings = Settings;
            string setting;
            ulong badDataMessageInterval;

            // Validate settings.
            if (!settings.TryGetValue("instanceName", out m_instanceName) || string.IsNullOrWhiteSpace(m_instanceName))
                m_instanceName = Name.ToLower();

            // Track instance in static dictionary
            Instances[InstanceName] = this;

            if (!settings.TryGetValue("archivePath", out m_archivePath))
                m_archivePath = FilePath.GetAbsolutePath(FilePath.AddPathSuffix("Archive"));

            if (settings.TryGetValue("refreshMetadata", out setting) || settings.TryGetValue("autoRefreshMetadata", out setting))
                m_autoRefreshMetadata = setting.ParseBoolean();

            if (settings.TryGetValue("badDataMessageInterval", out setting) && ulong.TryParse(setting, out badDataMessageInterval))
                m_badDataMessageInterval = badDataMessageInterval;

            //if (settings.TryGetValue("useNamespaceReservation", out setting))
            //    m_useNamespaceReservation = setting.ParseBoolean();
            //else
            //    m_useNamespaceReservation = false;

            // Initialize metadata file.
            m_instanceName = m_instanceName.ToLower();
            m_archive.MetadataFile.FileName = Path.Combine(m_archivePath, m_instanceName + "_dbase.dat");
            m_archive.MetadataFile.PersistSettings = true;
            m_archive.MetadataFile.SettingsCategory = m_instanceName + m_archive.MetadataFile.SettingsCategory;
            m_archive.MetadataFile.FileAccessMode = FileAccess.ReadWrite;
            m_archive.MetadataFile.Initialize();

            // Initialize state file.
            m_archive.StateFile.FileName = Path.Combine(m_archivePath, m_instanceName + "_startup.dat");
            m_archive.StateFile.PersistSettings = true;
            m_archive.StateFile.SettingsCategory = m_instanceName + m_archive.StateFile.SettingsCategory;
            m_archive.StateFile.FileAccessMode = FileAccess.ReadWrite;
            m_archive.StateFile.Initialize();

            // Initialize intercom file.
            m_archive.IntercomFile.FileName = Path.Combine(m_archivePath, "scratch.dat");
            m_archive.IntercomFile.PersistSettings = true;
            m_archive.IntercomFile.SettingsCategory = m_instanceName + m_archive.IntercomFile.SettingsCategory;
            m_archive.IntercomFile.FileAccessMode = FileAccess.ReadWrite;
            m_archive.IntercomFile.Initialize();

            // Initialize data archive file.           
            m_archive.FileName = Path.Combine(m_archivePath, m_instanceName + "_archive.d");
            m_archive.FileSize = 100;
            m_archive.CompressData = false;
            m_archive.PersistSettings = true;
            m_archive.SettingsCategory = m_instanceName + m_archive.SettingsCategory;

            m_archive.RolloverStart += m_archive_RolloverStart;
            m_archive.RolloverComplete += m_archive_RolloverComplete;
            m_archive.RolloverException += m_archive_RolloverException;

            m_archive.DataReadException += m_archive_DataReadException;
            m_archive.DataWriteException += m_archive_DataWriteException;

            m_archive.OffloadStart += m_archive_OffloadStart;
            m_archive.OffloadComplete += m_archive_OffloadComplete;
            m_archive.OffloadException += m_archive_OffloadException;

            m_archive.OrphanDataReceived += m_archive_OrphanDataReceived;
            m_archive.FutureDataReceived += m_archive_FutureDataReceived;
            m_archive.OutOfSequenceDataReceived += m_archive_OutOfSequenceDataReceived;

            m_archive.Initialize();

            // Provide web service support.
            m_dataServices = new DataServices();
            m_dataServices.AdapterCreated += DataServices_AdapterCreated;
            m_dataServices.AdapterLoaded += DataServices_AdapterLoaded;
            m_dataServices.AdapterUnloaded += DataServices_AdapterUnloaded;
            m_dataServices.AdapterLoadException += AdapterLoader_AdapterLoadException;

            // Provide metadata sync support.
            m_metadataProviders = new MetadataProviders();
            m_metadataProviders.AdapterCreated += MetadataProviders_AdapterCreated;
            m_metadataProviders.AdapterLoaded += MetadataProviders_AdapterLoaded;
            m_metadataProviders.AdapterUnloaded += MetadataProviders_AdapterUnloaded;
            m_metadataProviders.AdapterLoadException += AdapterLoader_AdapterLoadException;

            // Provide archive replication support.
            m_replicationProviders = new ReplicationProviders();
            m_replicationProviders.AdapterCreated += ReplicationProviders_AdapterCreated;
            m_replicationProviders.AdapterLoaded += ReplicationProviders_AdapterLoaded;
            m_replicationProviders.AdapterUnloaded += ReplicationProviders_AdapterUnloaded;
            m_replicationProviders.AdapterLoadException += AdapterLoader_AdapterLoadException;
        }
        /// <summary>
        /// Initializes this <see cref="LocalOutputAdapter"/>.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            //const string errorMessage = "{0} is missing from Settings - Example: instanceName=default; ArchiveDirectories={{c:\\Archive1\\;d:\\Backups2\\}}; dataChannel={{port=9591; interface=0.0.0.0}}";
            Dictionary<string, string> settings = Settings;
            string setting;

            // Validate settings.
            if (!settings.TryGetValue("instanceName", out m_instanceName) || string.IsNullOrWhiteSpace(m_instanceName))
                m_instanceName = Name;

            // Track instance in static dictionary
            Instances[InstanceName] = this;

            if (!settings.TryGetValue("WorkingDirectory", out setting) || string.IsNullOrEmpty(setting))
                setting = "Archive";

            WorkingDirectory = setting;

            if (settings.TryGetValue("ArchiveDirectories", out setting))
                ArchiveDirectories = setting;

            if (settings.TryGetValue("AttachedPaths", out setting))
                AttachedPaths = setting;

            if (!settings.TryGetValue("DataChannel", out m_dataChannel))
                m_dataChannel = DefaultDataChannel;

            double targetFileSize;

            if (!settings.TryGetValue("TargetFileSize", out setting) || !double.TryParse(setting, out targetFileSize))
                targetFileSize = DefaultTargetFileSize;

            if (targetFileSize < 0.1D || targetFileSize > SI2.Tera)
                targetFileSize = DefaultTargetFileSize;

            if (!settings.TryGetValue("MaximumArchiveDays", out setting) || !int.TryParse(setting, out m_maximumArchiveDays))
                m_maximumArchiveDays = DefaultMaximumArchiveDays;

            if (!settings.TryGetValue("DirectoryNamingMode", out setting) || !Enum.TryParse(setting, true, out m_directoryNamingMode))
                DirectoryNamingMode = DefaultDirectoryNamingMode;

            // Handle advanced settings - there are hidden but available from manual entry into connection string
            int stagingCount, diskFlushInterval, cacheFlushInterval;

            if (!settings.TryGetValue("StagingCount", out setting) || !int.TryParse(setting, out stagingCount))
                stagingCount = 3;

            if (!settings.TryGetValue("DiskFlushInterval", out setting) || !int.TryParse(setting, out diskFlushInterval))
                diskFlushInterval = 10000;

            if (!settings.TryGetValue("CacheFlushInterval", out setting) || !int.TryParse(setting, out cacheFlushInterval))
                cacheFlushInterval = 100;

            // Establish archive information for this historian instance
            m_archiveInfo = new HistorianServerDatabaseConfig(InstanceName, WorkingDirectory, true);

            if ((object)m_archiveDirectories != null)
                m_archiveInfo.FinalWritePaths.AddRange(m_archiveDirectories);

            if ((object)m_attachedPaths != null)
                m_archiveInfo.ImportPaths.AddRange(m_attachedPaths);

            m_archiveInfo.TargetFileSize = (long)(targetFileSize * SI.Giga);
            m_archiveInfo.DirectoryMethod = DirectoryNamingMode;
            m_archiveInfo.StagingCount = stagingCount;
            m_archiveInfo.DiskFlushInterval = diskFlushInterval;
            m_archiveInfo.CacheFlushInterval = cacheFlushInterval;

            // Provide web service support
            m_dataServices = new DataServices();
            m_dataServices.AdapterCreated += DataServices_AdapterCreated;
            m_dataServices.AdapterLoaded += DataServices_AdapterLoaded;
            m_dataServices.AdapterUnloaded += DataServices_AdapterUnloaded;
            m_dataServices.AdapterLoadException += AdapterLoader_AdapterLoadException;

            // Provide archive replication support
            m_replicationProviders = new ReplicationProviders();
            m_replicationProviders.AdapterCreated += ReplicationProviders_AdapterCreated;
            m_replicationProviders.AdapterLoaded += ReplicationProviders_AdapterLoaded;
            m_replicationProviders.AdapterUnloaded += ReplicationProviders_AdapterUnloaded;
            m_replicationProviders.AdapterLoadException += AdapterLoader_AdapterLoadException;

            if (MaximumArchiveDays > 0)
            {
                m_dailyTimer = new Timer(Time.SecondsPerDay * 1000.0D);
                m_dailyTimer.AutoReset = true;
                m_dailyTimer.Elapsed += m_dailyTimer_Elapsed;
                m_dailyTimer.Enabled = true;
            }
        }