Ejemplo n.º 1
0
 // TODO remove this
 public void Configure(DatabaseTemplate template)
 {
     foreach (var record in template.binaries)
     {
         record.staticVariation = (StaticBinaryVariation)this.ComboBoxBinary.SelectedItem;
     }
     foreach (var record in template.binaryOutputStatii)
     {
         record.staticVariation = (StaticBinaryOutputStatusVariation)this.ComboBoxBinaryOutputStatus.SelectedItem;
     }
     foreach (var record in template.doubleBinaries)
     {
         record.staticVariation = (StaticDoubleBinaryVariation)this.ComboBoxDoubleBinary.SelectedItem;
     }
     foreach (var record in template.counters)
     {
         record.staticVariation = (StaticCounterVariation)ComboBoxCounter.SelectedItem;
     }
     foreach (var record in template.frozenCounters)
     {
         record.staticVariation = (StaticFrozenCounterVariation)ComboBoxCounter.SelectedItem;
     }
     foreach (var record in template.analogs)
     {
         record.staticVariation = (StaticAnalogVariation)ComboBoxAnalog.SelectedItem;
     }
     foreach (var record in template.analogOutputStatii)
     {
         record.staticVariation = (StaticAnalogOutputStatusVariation)ComboBoxAnalogOutputStatus.SelectedItem;
     }
 }
Ejemplo n.º 2
0
        public TemplateDialog(string alias, DatabaseTemplate template)
        {
            InitializeComponent();

            this.textBoxAlias.Text = alias;

            Configure(template);
        }
Ejemplo n.º 3
0
        public TemplateDialog(string alias, DatabaseTemplate template)
        {
            InitializeComponent();

            this.textBoxAlias.Text = alias;

            Configure(template);
        }
Ejemplo n.º 4
0
 private void Configure(DatabaseTemplate template)
 {
     this.templateControlAnalog.SetRecords(template.analogs);
     this.templateControlAOStatus.SetRecords(template.analogOutputStatii);
     this.templateControlBinary.SetRecords(template.binaries);
     this.templateControlBOStatus.SetRecords(template.binaryOutputStatii);
     this.templateControlCounter.SetRecords(template.counters);
     this.templateControlDoubleBinary.SetRecords(template.doubleBinaries);
     this.templateControlFrozenCounter.SetRecords(template.frozenCounters);
 }
Ejemplo n.º 5
0
 private void Configure(DatabaseTemplate template)
 {
     this.templateControlAnalog.SetRecords(template.analogs);
     this.templateControlAOStatus.SetRecords(template.analogOutputStatii);
     this.templateControlBinary.SetRecords(template.binaries);
     this.templateControlBOStatus.SetRecords(template.binaryOutputStatii);
     this.templateControlCounter.SetRecords(template.counters);
     this.templateControlDoubleBinary.SetRecords(template.doubleBinaries);
     this.templateControlFrozenCounter.SetRecords(template.frozenCounters);
 }
 // TODO remove this
 public void Configure(DatabaseTemplate template)
 {
     foreach (var record in template.binaries) record.staticVariation = (StaticBinaryVariation)this.ComboBoxBinary.SelectedItem;
     foreach (var record in template.binaryOutputStatii) record.staticVariation = (StaticBinaryOutputStatusVariation)this.ComboBoxBinaryOutputStatus.SelectedItem;
     foreach (var record in template.doubleBinaries) record.staticVariation = (StaticDoubleBinaryVariation)this.ComboBoxDoubleBinary.SelectedItem;
     foreach (var record in template.counters) record.staticVariation = (StaticCounterVariation)ComboBoxCounter.SelectedItem;
     foreach (var record in template.frozenCounters) record.staticVariation = (StaticFrozenCounterVariation)ComboBoxCounter.SelectedItem;
     foreach (var record in template.analogs) record.staticVariation = (StaticAnalogVariation)ComboBoxAnalog.SelectedItem;
     foreach (var record in template.analogOutputStatii) record.staticVariation = (StaticAnalogOutputStatusVariation)ComboBoxAnalogOutputStatus.SelectedItem;
 }
Ejemplo n.º 7
0
        public void TestCreate()
        {
            var template = new DatabaseTemplate(_dataSourceConfig);
            var gateway  = new UserDataGateway(template);

            gateway.Create("aUser");

            var names = template.Query("select name from users", reader => reader.GetString(0),
                                       new List <DbParameter>());

            Assert.Equal("aUser", names.First());
        }
Ejemplo n.º 8
0
        public MeasurementCache(DatabaseTemplate template)
        {
            var values = new ChangeSet();
            template.binaries.EachIndex((m, i) => values.Update(new Binary(Flags.RESTART), Convert.ToUInt16(i)));
            template.doubleBinaries.EachIndex((m, i) => values.Update(new DoubleBitBinary(Flags.RESTART), Convert.ToUInt16(i)));
            template.counters.EachIndex((m, i) => values.Update(new Counter(Flags.RESTART), Convert.ToUInt16(i)));
            template.frozenCounters.EachIndex((m, i) => values.Update(new FrozenCounter(Flags.RESTART), Convert.ToUInt16(i)));
            template.analogs.EachIndex((m, i) => values.Update(new Analog(Flags.RESTART), Convert.ToUInt16(i)));
            template.binaryOutputStatii.EachIndex((m, i) => values.Update(new BinaryOutputStatus(Flags.RESTART), Convert.ToUInt16(i)));
            template.analogOutputStatii.EachIndex((m, i) => values.Update(new AnalogOutputStatus(Flags.RESTART), Convert.ToUInt16(i)));
            template.timeAndIntervals.EachIndex((m, i) => values.Update(new TimeAndInterval(0, 0, IntervalUnits.Undefined), Convert.ToUInt16(i)));

            this.Load(values);
        }
Ejemplo n.º 9
0
        public MeasurementCache(DatabaseTemplate template)
        {
            var info = new HeaderInfo(GroupVariation.UNKNOWN, QualifierCode.UNDEFINED, TimestampMode.SYNCHRONIZED);

            ISOEHandler handler = this;

            handler.OnReceiveHeader(info, template.binaries.SelectWithIndex((m, i) => new IndexedValue <Binary>(new Binary(m.quality), i)));
            handler.OnReceiveHeader(info, template.doubleBinaries.SelectWithIndex((m, i) => new IndexedValue <DoubleBitBinary>(new DoubleBitBinary(m.quality), i)));
            handler.OnReceiveHeader(info, template.counters.SelectWithIndex((m, i) => new IndexedValue <Counter>(new Counter(m.quality), i)));
            handler.OnReceiveHeader(info, template.frozenCounters.SelectWithIndex((m, i) => new IndexedValue <FrozenCounter>(new FrozenCounter(m.quality), i)));
            handler.OnReceiveHeader(info, template.analogs.SelectWithIndex((m, i) => new IndexedValue <Analog>(new Analog(m.quality), i)));
            handler.OnReceiveHeader(info, template.binaryOutputStatii.SelectWithIndex((m, i) => new IndexedValue <BinaryOutputStatus>(new BinaryOutputStatus(m.quality), i)));
            handler.OnReceiveHeader(info, template.analogOutputStatii.SelectWithIndex((m, i) => new IndexedValue <AnalogOutputStatus>(new AnalogOutputStatus(m.quality), i)));
        }
Ejemplo n.º 10
0
        public MeasurementCache(DatabaseTemplate template)
        {
            var values = new ChangeSet();

            template.binaries.EachIndex((m, i) => values.Update(new Binary(Flags.RESTART), Convert.ToUInt16(i)));
            template.doubleBinaries.EachIndex((m, i) => values.Update(new DoubleBitBinary(Flags.RESTART), Convert.ToUInt16(i)));
            template.counters.EachIndex((m, i) => values.Update(new Counter(Flags.RESTART), Convert.ToUInt16(i)));
            template.frozenCounters.EachIndex((m, i) => values.Update(new FrozenCounter(Flags.RESTART), Convert.ToUInt16(i)));
            template.analogs.EachIndex((m, i) => values.Update(new Analog(Flags.RESTART), Convert.ToUInt16(i)));
            template.binaryOutputStatii.EachIndex((m, i) => values.Update(new BinaryOutputStatus(Flags.RESTART), Convert.ToUInt16(i)));
            template.analogOutputStatii.EachIndex((m, i) => values.Update(new AnalogOutputStatus(Flags.RESTART), Convert.ToUInt16(i)));
            template.timeAndIntervals.EachIndex((m, i) => values.Update(new TimeAndInterval(0, 0, IntervalUnits.Undefined), Convert.ToUInt16(i)));

            this.Load(values);
        }
Ejemplo n.º 11
0
        public void TestCreate()
        {
            var support = new TestDatabaseSupport(_dataSourceConfig);

            support.ExecSql(@"
insert into users (id, name) values (12, 'Jack');
");

            var template = new DatabaseTemplate(_dataSourceConfig);
            var gateway  = new AccountDataGateway(template);

            gateway.Create(12, "anAccount");

            var names = template.Query("select name from accounts", reader => reader.GetString(0),
                                       new List <DbParameter>());

            Assert.Equal("anAccount", names.First());
        }
Ejemplo n.º 12
0
        public void TestCreate()
        {
            var support = new TestDatabaseSupport(_dataSourceConfig);

            support.ExecSql(@"
insert into users (id, name) values (12, 'Jack');
insert into accounts (id, owner_id, name) values (1, 12, 'anAccount');
");

            var gateway = new ProjectDataGateway(new DatabaseTemplate(_dataSourceConfig));

            gateway.Create(1, "aProject");

            // todo...
            var template = new DatabaseTemplate(_dataSourceConfig);
            var projects = template.Query("select name from projects where account_id = 1",
                                          reader => reader.GetString(0),
                                          new List <DbParameter>());

            Assert.Equal("aProject", projects.First());
        }
Ejemplo n.º 13
0
        public void TestCreate()
        {
            var support = new TestDatabaseSupport(_dataSourceConfig);

            support.ExecSql(@"
insert into users (id, name) values (12, 'Jack');
insert into accounts (id, owner_id, name) values (1, 12, 'anAccount');
insert into projects (id, account_id, name) values (22, 1, 'aProject');
");

            var gateway = new AllocationDataGateway(new DatabaseTemplate(_dataSourceConfig));

            gateway.Create(22, 12, DateTime.Now, DateTime.Now);

            // todo...
            var template   = new DatabaseTemplate(_dataSourceConfig);
            var projectIds = template.Query("select project_id from allocations", reader => reader.GetInt64(0),
                                            new List <DbParameter>());

            Assert.Equal(22, projectIds.First());
        }
Ejemplo n.º 14
0
 void IDNP3Config.AddTemplate(string alias, DatabaseTemplate template)
 {
     templates[alias] = template;
 }
Ejemplo n.º 15
0
        void LoadRtu(DataRow equipmentRow)
        {
            Rtu    rtu = null;
            int    id, snmpPort, type, dnp3port, rtuDnp3Addres, scadaDnp3Address;
            string name, clientAddress;
            ushort maxBin = 0, maxAnalog = 0, maxCounter = 0;

            DatabaseTemplate      databaseTemplate;
            GeminiMap             GMap = new GeminiMap();
            DataTable             DNP3Map = null, Bin = null, Analog = null, Counter = null;
            Dictionary <int, int> bins = new Dictionary <int, int>();
            Dictionary <int, int> analogs = new Dictionary <int, int>();
            Dictionary <int, int> counters = new Dictionary <int, int>();

            id               = Convert.ToInt32(equipmentRow["id"]);
            snmpPort         = Convert.ToInt32(equipmentRow["snmp_port"]);
            type             = Convert.ToInt32(equipmentRow["type"]);
            dnp3port         = Convert.ToInt32(equipmentRow["dnp3_port"]);
            name             = Convert.ToString(equipmentRow["nome"]);
            clientAddress    = Convert.ToString(equipmentRow["ip"]);
            rtuDnp3Addres    = Convert.ToInt32(equipmentRow["dnp3_address"]);
            scadaDnp3Address = Convert.ToInt32(equipmentRow["dnp3_master_address"]);

            using (IQueryAdapter adapter = Core.DatabaseManager.GetQueryReactor())
            {
                adapter.SetQuery("SELECT * FROM dnp3_map WHERE equipment_type_id = @tid;");
                adapter.AddParameter("tid", type);
                DNP3Map = adapter.getTable();
            }

            try
            {
                foreach (DataRow dr in DNP3Map.Rows)
                {
                    GMap.Add(new GeminiPoint
                    {
                        Id            = Convert.ToInt32(dr["id"]),
                        EquipmentType = Convert.ToInt32(dr["equipment_type_id"]),
                        PointType     = Convert.ToChar(dr["point_type"]),
                        Class         = Convert.ToInt32(dr["class"]),
                        SnmpObjectId  = Convert.ToInt32(dr["snmp_object_id"]),
                        Dnp3Addr      = ushort.Parse(dr["dnp3_addr"].ToString())
                    });
                }

                Bin     = DNP3Map.AsEnumerable().Where(r => r.Field <String>("point_type") == "D").CopyToDataTable();
                Analog  = DNP3Map.AsEnumerable().Where(r => r.Field <String>("point_type") == "A").CopyToDataTable();
                Counter = DNP3Map.AsEnumerable().Where(r => r.Field <String>("point_type") == "C").CopyToDataTable();
            }
            catch (Exception) { }

            foreach (DataRow dr in Bin.Rows)
            {
                maxBin = (ushort)Math.Max(maxBin, Convert.ToInt32(dr["dnp3_addr"]));
            }
            foreach (DataRow dr in Analog.Rows)
            {
                maxAnalog = (ushort)Math.Max(maxAnalog, Convert.ToInt32(dr["dnp3_addr"]));
            }
            foreach (DataRow dr in Bin.Rows)
            {
                maxCounter = (ushort)Math.Max(maxCounter, Convert.ToInt32(dr["dnp3_addr"]));
            }

            maxBin++;
            maxAnalog++;
            maxCounter++;

            databaseTemplate = new DatabaseTemplate(maxBin, 0, maxAnalog, maxCounter, 0, 0, 0, 0, 0);

            if (Bin != null)
            {
                foreach (DataRow dr in Bin.Rows)
                {
                    int        cls      = Convert.ToInt32(dr["class"]);
                    int        dnp3Addr = Convert.ToInt32(dr["dnp3_addr"]);
                    PointClass ptCls;
                    switch (cls)
                    {
                    case 0:
                        ptCls = PointClass.Class0;
                        break;

                    case 1:
                        ptCls = PointClass.Class1;
                        break;

                    case 2:
                        ptCls = PointClass.Class2;
                        break;

                    case 3:
                        ptCls = PointClass.Class3;
                        break;

                    default:
                        ptCls = PointClass.Class0;
                        break;
                    }
                    databaseTemplate.binaries[dnp3Addr].clazz = ptCls;
                    bins.Add(dnp3Addr, Convert.ToInt32(dr["snmp_object_id"]));
                }
            }

            if (Analog != null)
            {
                foreach (DataRow dr in Analog.Rows)
                {
                    int        cls      = Convert.ToInt32(dr["class"]);
                    int        dnp3Addr = Convert.ToInt32(dr["dnp3_addr"]);
                    PointClass ptCls;
                    switch (cls)
                    {
                    case 0:
                        ptCls = PointClass.Class0;
                        break;

                    case 1:
                        ptCls = PointClass.Class1;
                        break;

                    case 2:
                        ptCls = PointClass.Class2;
                        break;

                    case 3:
                        ptCls = PointClass.Class3;
                        break;

                    default:
                        ptCls = PointClass.Class0;
                        break;
                    }
                    databaseTemplate.analogs[dnp3Addr].clazz = ptCls;
                    analogs.Add(dnp3Addr, Convert.ToInt32(dr["snmp_object_id"]));
                }
            }

            if (Counter != null)
            {
                foreach (DataRow dr in Counter.Rows)
                {
                    int        cls      = Convert.ToInt32(dr["class"]);
                    int        dnp3Addr = Convert.ToInt32(dr["dnp3_addr"]);
                    PointClass ptCls;
                    switch (cls)
                    {
                    case 0:
                        ptCls = PointClass.Class0;
                        break;

                    case 1:
                        ptCls = PointClass.Class1;
                        break;

                    case 2:
                        ptCls = PointClass.Class2;
                        break;

                    case 3:
                        ptCls = PointClass.Class3;
                        break;

                    default:
                        ptCls = PointClass.Class0;
                        break;
                    }
                    databaseTemplate.counters[dnp3Addr].clazz = ptCls;
                    counters.Add(dnp3Addr, Convert.ToInt32(dr["snmp_object_id"]));
                }
            }

            rtu = new Rtu(id, name, new IPEndpoint(clientAddress, (ushort)snmpPort), new IPEndpoint("0.0.0.0", (ushort)dnp3port), (ushort)rtuDnp3Addres, (ushort)scadaDnp3Address, bins, analogs, counters, databaseTemplate, GMap);
        }
Ejemplo n.º 16
0
Archivo: Rtu.cs Proyecto: AKllX/Gemini
        public Rtu(int id, string name, IPEndpoint clientAddress, IPEndpoint hostAddres, ushort localDNP3Addres, ushort remoteDNP3Address,
            Dictionary<int, int> bins, Dictionary<int, int> analogs, Dictionary<int, int> counters, DatabaseTemplate dt, GeminiMap gmap)
        {
            Id = id;
            Name = name;
            //Considerando uma RTU por Canal
            if (Core.LoggingEnabled)
            {
                Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.ALL, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print());
            }
            else
            {
                Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.NONE, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print());
            }

            //Configuração Padrão de RTU é Outstation
            Config = new OutstationStackConfig
            {
                databaseTemplate = dt
            };
            Config.link.remoteAddr = remoteDNP3Address;
            Config.link.localAddr = localDNP3Addres;
            DNP3ToSNMPBinaries = bins;
            DNP3ToSNMPAnalogs = analogs;
            DNP3ToSNMPCounters = counters;
            Outstation = Channel.AddOutstation(name, RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, Config);
            Outstation.Enable();
            geminiMap = gmap;

            Target = new SnmpTarget(clientAddress.address, clientAddress.port, Core.Settings.SNMPTimeout, Core.Settings.SNMPRetry);

            foreach (KeyValuePair<int, int> map in DNP3ToSNMPBinaries)
            {
                Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value));
            }

            foreach (KeyValuePair<int, int> map in DNP3ToSNMPAnalogs)
            {
                Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value));
            }

            foreach (KeyValuePair<int, int> map in DNP3ToSNMPCounters)
            {
                Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value));
            }

            MonitorThread = new Timer(new TimerCallback(Update), null, TimeSpan.FromMilliseconds(10), TimeSpan.FromSeconds(Core.Settings.GatewayPoolingTime));
        }
Ejemplo n.º 17
0
 void IDNP3Config.AddTemplate(string alias, DatabaseTemplate template)
 {
     templates[alias] = template;
 }