Ejemplo n.º 1
0
        /// <summary>
        /// Loads the DataManager configuration
        /// </summary>
        /// <param name="file">The file to load from</param>
        /// <param name="loadDefaults">Load the default parameters rather than loading from file</param>
        /// <returns></returns>
        public bool Load(string file, bool loadDefaults = false)
        {
            Info("Loading DataManager configuration...");
            if (!loadDefaults)
            {
                try
                {
                    Datasets = Util.DeserializeNewtonsoft <Dictionary <string, DataSource> >(file);
                }
                catch (Exception ex)
                {
                    Fatal($"Failed to deserialize DataManager from file [{file}].  {ex.Message}");
                    return(false);
                }
            }
            //TODO: remove all of this
            else
            {
                DataSource source = new CsvDataSource()
                {
                    Name                  = "T1Disconnectors",
                    FileName              = "T1Disconnectors.csv",
                    IndexColumn           = "Asset Number",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(T1Disconnector), source);

                source = new CsvDataSource()
                {
                    Name                  = "T1Fuses",
                    FileName              = "T1Fuses.csv",
                    IndexColumn           = "Asset Number",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(T1Fuse), source);

                source = new CsvDataSource()
                {
                    Name                  = "T1HvCircuitBreakers",
                    IndexColumn           = "Asset Number",
                    FileName              = "T1HvCircuitBreakers.csv",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(T1HvCircuitBreaker), source);

                source = new CsvDataSource()
                {
                    Name                  = "T1RingMainUnits",
                    FileName              = "T1RingMainUnits.csv",
                    IndexColumn           = "Asset Number",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(T1RingMainUnit), source);

                source = new CsvDataSource()
                {
                    Name                  = "T1Transformers",
                    FileName              = "T1Transformers.csv",
                    IndexColumn           = "Asset Number",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(T1Transformer), source);

                source = new CsvDataSource()
                {
                    Name                  = "TranspowerTransformers",
                    FileName              = "TranspowerTransformers.csv",
                    IndexColumn           = "id",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(TranspowerTransformer), source);

                source = new CsvDataSource()
                {
                    Name                  = "ScadaStatus",
                    FileName              = "SCADA_STATUS.csv",
                    IndexColumn           = "Key",
                    InitializeFailIsFatal = true,
                    IsOsiFormat           = true
                };
                Datasets.Add(nameof(OsiScadaStatus), source);

                source = new CsvDataSource()
                {
                    Name                  = "ScadaAnalog",
                    FileName              = "SCADA_ANALOG.csv",
                    IndexColumn           = "Key",
                    InitializeFailIsFatal = true,
                    IsOsiFormat           = true
                };
                Datasets.Add(nameof(OsiScadaAnalog), source);

                source = new CsvDataSource()
                {
                    Name                  = "ScadaAccumulator",
                    IndexColumn           = "Key",
                    FileName              = "SCADA_ACCUM.csv",
                    InitializeFailIsFatal = true,
                    IsOsiFormat           = true
                };
                Datasets.Add(nameof(OsiScadaAccumulator), source);

                source = new CsvDataSource()
                {
                    Name                  = "ScadaSetpoint",
                    IndexColumn           = "Key",
                    FileName              = "SCADA_SETPOINT.csv",
                    InitializeFailIsFatal = true,
                    IsOsiFormat           = true
                };
                Datasets.Add(nameof(OsiScadaSetpoint), source);
                source = new SqliteSource()
                {
                    Database              = "adms.db",
                    Table                 = "Switch",
                    Name                  = "AdmsSwitch",
                    IndexColumn           = "SwitchNumber",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(AdmsSwitch), source);
                source = new SqliteSource()
                {
                    Database              = "adms.db",
                    Table                 = "Transformer",
                    Name                  = "AdmsTransformer",
                    IndexColumn           = "AssetNumber",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(AdmsTransformer), source);
                source = new SqliteSource()
                {
                    Database              = "adms.db",
                    Table                 = "Regulator",
                    Name                  = "AdmsRegulator",
                    IndexColumn           = "Name",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(AdmsRegulator), source);
                source = new SqliteSource()
                {
                    Database              = "adms.db",
                    Table                 = "Source",
                    Name                  = "AdmsSource",
                    IndexColumn           = "Name",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(AdmsSource), source);

                source = new CsvDataSource()
                {
                    Name                  = "ICPs",
                    FileName              = "ICPs.csv",
                    IndexColumn           = "Name",
                    InitializeFailIsFatal = true
                };
                Datasets.Add(nameof(Icp), source);
            }
            foreach (var d in Datasets.Values)
            {
                if (!d.Initialize() && d.InitializeFailIsFatal)
                {
                    return(false);
                }
            }
            return(true);
        }