Ejemplo n.º 1
0
        /// <summary>
        /// Creates a URL that gives access to the provided key.
        /// </summary>
        /// <param name="bucketName">The name of the bucket</param>
        /// <param name="key">The key to share</param>
        /// <param name="raw">No landing page, directly access the file</param>
        /// <param name="is_public">Wether objects can be read using only the access_key_id</param>
        /// <returns></returns>
        public string CreateShareURL(string bucketName, string key, bool raw, bool is_public)
        {
            using (EdgeConfig edgeConfig = new EdgeConfig {
                auth_service_address = "auth.storjshare.io:7777"
            })
                using (EdgeRegisterAccessOptions edgeRegisterAccessOptions = new EdgeRegisterAccessOptions {
                    is_public = is_public
                })
                    using (EdgeShareURLOptions edgeShareURLOptions = new EdgeShareURLOptions {
                        raw = raw
                    })
                    {
                        using (var registeredAccess = SWIG.storj_uplink.edge_register_access(edgeConfig, _access, edgeRegisterAccessOptions))
                        {
                            if (registeredAccess.error != null && !string.IsNullOrEmpty(registeredAccess.error.message))
                            {
                                throw new AccessShareException(registeredAccess.error.message);
                            }

                            using (var shareUrl = SWIG.storj_uplink.edge_join_share_url(registeredAccess.credentials.endpoint, registeredAccess.credentials.access_key_id, bucketName, key, edgeShareURLOptions))
                            {
                                if (shareUrl.error != null && !string.IsNullOrEmpty(shareUrl.error.message))
                                {
                                    throw new AccessShareException(shareUrl.error.message);
                                }

                                return(shareUrl.string_.Replace("gateway.eu1", "link").Replace("gateway.us1", "link").Replace("gateway.ap1", "link"));
                            }
                        }
                    }
        }
Ejemplo n.º 2
0
        protected void EdgeVersionListTest()
        {
            var browserConfig = new EdgeConfig();
            var version       = browserConfig.GetDriverVersion("16");

            Assert.NotEmpty(version);
            Assert.Equal("D/4/1/D417998A-58EE-4EFE-A7CC-39EF9E020768", version);
        }
Ejemplo n.º 3
0
 private static ExcuteInfo GetExcuteInfoV2_1(EdgeConfig config)
 {
     return(new ExcuteInfo()
     {
         FileName = $"{AppDomain.CurrentDomain.BaseDirectory}/EdgeFile/edge21.exe",
         Args = BuilArgs(config)
     });
 }
Ejemplo n.º 4
0
 public Edge(Relation Relation, Node NodeOne, Node NodeTwo, EdgeConfig edgeConfig)
 {
     this.Relation = Relation;
     this.NodeOne  = NodeOne;
     this.NodeTwo  = NodeTwo;
     EdgeConfig    = edgeConfig;
     EdgeConfig.SetDefaultValues(NodeOne, NodeTwo);
 }
Ejemplo n.º 5
0
        /**
         * {@inheritdoc}
         */
        public void AddEdge(IActivity a1, IActivity a2)
        {
            EdgeConfig config = new EdgeConfig(a2, 0.5);

            a1.AddEdge(config);

            // Adds the node to the dictionary.
            AddToDictionary(a2);
        }
Ejemplo n.º 6
0
        public static EdgeCredentialsResult edge_register_access(EdgeConfig config, UplinkAccess access, EdgeRegisterAccessOptions options)
        {
            EdgeCredentialsResult ret = new EdgeCredentialsResult(storj_uplinkPINVOKE.edge_register_access(EdgeConfig.getCPtr(config), UplinkAccess.getCPtr(access), EdgeRegisterAccessOptions.getCPtr(options)), true);

            if (storj_uplinkPINVOKE.SWIGPendingException.Pending)
            {
                throw storj_uplinkPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Ejemplo n.º 7
0
        public void EdgeVersionResultNotEmptyAndMatch()
        {
            var edgeConfig = new EdgeConfig();
            var version    = edgeConfig.GetLatestVersion();
            var regex      = new Regex(@"^\d+\.\d+$");
            var match      = regex.Match(version);

            Assert.NotEmpty(version);
            Assert.True(match.Success);
        }
Ejemplo n.º 8
0
        public ConfigEditWindow(string edgeConfigName) : this()
        {
            _edgeConfigName = edgeConfigName;

            if (!string.IsNullOrEmpty(_edgeConfigName))
            {
                this.Title  = _edgeConfigName;
                _edgeConfig = ConfigManager.GetEdgeConfig(_edgeConfigName);
                SetToForms(_edgeConfig);
            }
        }
Ejemplo n.º 9
0
        public void TestHashCode(int source, int destination, int code)
        {
            var edge = new EdgeConfig(source, EdgeDirection.South, destination, null);

            Assert.AreEqual(code, edge.GetHashCode());

            var edges = new HashSet <EdgeConfig> {
                edge
            };

            Assert.False(edges.Add(edge));
        }
Ejemplo n.º 10
0
        public static void SaveEdgeConfig(string name, EdgeConfig config)
        {
            string path       = $"{EDGE_CONFIG_DIR}/{name}.json";
            string configText = JsonConvert.SerializeObject(config, Formatting.Indented);

            if (!Directory.Exists(EDGE_CONFIG_DIR))
            {
                Directory.CreateDirectory(EDGE_CONFIG_DIR);
            }

            File.WriteAllText(path, configText);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 组装参数
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private static string BuilArgs(EdgeConfig config)
        {
            List <string> args = new List <string>();

            args.Add($"-d n2n{_random.Next()}");
            args.Add($"-a {config.EdgeIP}");
            args.Add($"-c {config.EdgeGroup}");
            args.Add($"-k {config.EdgePassword}");
            args.Add($"-l {config.SuperNodeIP}:{config.SuperNodePort}");

            if (!string.IsNullOrEmpty(config.EdgeNetmask))
            {
                args.Add($"-s {config.EdgeNetmask}");
            }

            if (config.ResolveSuperNode)
            {
                args.Add($"-b");
            }

            if (config.PacketForwarding)
            {
                args.Add($"-r");
            }

            if (config.Multicast)
            {
                args.Add($"-E");
            }

            if (config.Verbose)
            {
                args.Add($"-v");
            }

            if (config.LocalPort > 0)
            {
                args.Add($"-p {config.LocalPort}");
            }

            if (!string.IsNullOrEmpty(config.MacAddress))
            {
                args.Add($"-m {config.MacAddress}");
            }

            if (config.MTU > 0)
            {
                args.Add($"-M {config.MTU}");
            }

            return(string.Join(" ", args.ToArray()));
        }
Ejemplo n.º 12
0
        private void DrawPanel_MouseClick(object sender, MouseEventArgs e)
        {
            DrawPanel.Focus();
            Drawing.Editing(e.Location, SemanticNetwork);
            if (e.Button == MouseButtons.Left)
            {
                SemanticNetwork.Deselect();
            }

            if (AddingNewEdgeFlag)
            {
                for (int i = 0; i < SemanticNetwork.Nodes.Count; i++)
                {
                    Node node = Drawing.CheckNode(e.X, e.Y, SemanticNetwork);
                    if (node == null)
                    {
                        return;
                    }

                    if (selected1 == null)
                    {
                        selected1 = node;
                        break;
                    }
                    if (selected2 == null)
                    {
                        selected2 = node;
                        if (selected1 == null)
                        {
                            return;
                        }

                        EdgeForm addNewEdgeForm = new EdgeForm();
                        addNewEdgeForm.SetRelations = SemanticNetwork.Relations;
                        addNewEdgeForm.Converter    = converter;
                        if (addNewEdgeForm.ShowDialog() == DialogResult.OK)
                        {
                            Relation   relation = addNewEdgeForm.Relation;
                            EdgeConfig ec       = addNewEdgeForm.EdgeConfig;
                            Edge       edge     = new Edge(relation, selected1, selected2, ec);
                            //edge.EdgeConfig.SetDefaultValues(edge.NodeOne, edge.NodeTwo);
                            SemanticNetwork.AddEdge(edge);
                            AddingNewEdgeFlag = false;
                        }
                        DrawPanel.Invalidate();
                        selected1 = null;
                        selected2 = null;
                        break;
                    }
                }
            }
        }
        private void btnDeleteAllConfig_Click(object sender, EventArgs e)
        {
            if (_edgeAgent == null)
            {
                return;
            }

            EdgeConfig config = new EdgeConfig();

            config.Node = new EdgeConfig.NodeConfig();

            bool result = _edgeAgent.UploadConfig(ActionType.Delete, config).Result;
        }
Ejemplo n.º 14
0
        public static bool ConvertDeleteConfig(EdgeConfig config, ref string payload)
        {
            // add by kelly start

            try
            {
                if (config == null)
                {
                    return(false);
                }

                ConfigMessage msg = new ConfigMessage();

                msg.ScadaList = new Dictionary <string, ConfigMessage.ScadaObject>();

                ConfigMessage.ScadaObject scadaObj = new ConfigMessage.ScadaObject()
                {
                    //Id = config.Scada.Id,
                    //DeviceType = config.Scada.DeviceType,

                    DeviceType = SCADAConfigType.SCADA,

                    Description = config.Scada.Description,

                    PortNumber = config.Scada.PortNumber,

                    HeartBeat = config.Scada.HeartBeat,

                    BackupDeviceId = config.Scada.BackupDeviceId,

                    DeleteAllTags = 1
                };

                //scadaObj.UpdateTagList = new Dictionary<string, ConfigMessage.TagObject>();

                msg.ScadaList.Add(config.Scada.Id, scadaObj);


                payload = JsonConvert.SerializeObject(msg, Formatting.None, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }
            // add by kelly end
            return(true);
        }
Ejemplo n.º 15
0
        private bool _uploadConfig(ActionType action, EdgeConfig edgeConfig)
        {
            try
            {
                if (_mqttClient.IsConnected == false)
                {
                    return(false);
                }

                if (edgeConfig == null)
                {
                    return(false);
                }

                string payload = string.Empty;
                bool   result  = false;
                switch (action)
                {
                case ActionType.Create:
                    result = Converter.ConvertCreateOrUpdateConfig(edgeConfig, ref payload, _options.Heartbeat);
                    break;

                case ActionType.Update:
                    result = Converter.ConvertCreateOrUpdateConfig(edgeConfig, ref payload, _options.Heartbeat);
                    break;

                case ActionType.Delete:
                    result = Converter.ConvertDeleteConfig(edgeConfig, ref payload);
                    break;
                }

                if (result)
                {
                    var message = new MqttApplicationMessageBuilder()
                                  .WithTopic(_configTopic)
                                  .WithPayload(payload)
                                  .WithAtLeastOnceQoS()
                                  .WithRetainFlag(false)
                                  .Build();

                    _mqttClient.PublishAsync(message);
                }
                return(result);
            }
            catch (Exception ex)
            {
                //_logger.Error( ex.ToString() );
                return(false);
            }
        }
Ejemplo n.º 16
0
 private void SetToForms(EdgeConfig edgeConfig)
 {
     this.cbbVersion.Text               = edgeConfig.Version;
     this.txtSuperNodeIP.Text           = edgeConfig.SuperNodeIP;
     this.txtSuperNodePort.Text         = edgeConfig.SuperNodePort.ToString();
     this.txtEdgeIP.Text                = edgeConfig.EdgeIP;
     this.txtEdgeNetmask.Text           = edgeConfig.EdgeNetmask;
     this.txtEdgeGroup.Text             = edgeConfig.EdgeGroup;
     this.txtEdgePassword.Text          = edgeConfig.EdgePassword;
     this.txtMacAddress.Text            = edgeConfig.MacAddress;
     this.txtMTU.Text                   = edgeConfig.MTU.ToString();
     this.txtExtensionArgs.Text         = edgeConfig.ExtensionArgs;
     this.chkMulticast.IsChecked        = edgeConfig.Multicast;
     this.chkPacketForwarding.IsChecked = edgeConfig.PacketForwarding;
     this.chkResolveSuperNode.IsChecked = edgeConfig.ResolveSuperNode;
     this.chkVerbose.IsChecked          = edgeConfig.Verbose;
 }
        private void btnDeleteTags_Click(object sender, EventArgs e)
        {
            if (_edgeAgent == null)
            {
                return;
            }

            EdgeConfig config = new EdgeConfig();

            for (int i = 1; i <= numDeviceCount.Value; i++)
            {
                EdgeConfig.DeviceConfig device = new EdgeConfig.DeviceConfig()
                {
                    Id = "Device" + i
                };
                for (int j = 1; j <= numATagCount.Value; j++)
                {
                    EdgeConfig.AnalogTagConfig analogTag = new EdgeConfig.AnalogTagConfig()
                    {
                        Name = "ATag" + j
                    };
                    device.AnalogTagList.Add(analogTag);
                }
                for (int j = 1; j <= numDTagCount.Value; j++)
                {
                    EdgeConfig.DiscreteTagConfig discreteTag = new EdgeConfig.DiscreteTagConfig()
                    {
                        Name = "DTag" + j
                    };
                    device.DiscreteTagList.Add(discreteTag);
                }
                for (int j = 1; j <= numTTagCount.Value; j++)
                {
                    EdgeConfig.TextTagConfig textTag = new EdgeConfig.TextTagConfig()
                    {
                        Name = "TTag" + j
                    };
                    device.TextTagList.Add(textTag);
                }

                config.Node.DeviceList.Add(device);
            }

            bool result = _edgeAgent.UploadConfig(ActionType.Delete, config).Result;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 连接
        /// </summary>
        /// <param name="configName"></param>
        private void Connect(string configName)
        {
            _edgeConfig = ConfigManager.GetEdgeConfig(configName);
            if (_edgeConfig != null)
            {
                var excuteInfo = EdgeHelper.GetExcuteInfo(_edgeConfig);

                Trace.WriteLine($"正在执行:{excuteInfo.FileName} {excuteInfo.Args}");

                _edgeProcess = ProcessHelper.StartProcess(excuteInfo, (a, b) =>
                {
                    Trace.WriteLine(b.Data);
                });

                _isStarted = true;

                RefreshStatus();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 获取对应的运行参数信息
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static ExcuteInfo GetExcuteInfo(EdgeConfig config)
        {
            var version = config.Version;

            switch (version)
            {
            case "v1":
                return(GetExcuteInfoV1(config));

            case "v2":
                return(GetExcuteInfoV2(config));

            case "v2.1":
                return(GetExcuteInfoV2_1(config));

            default:
                throw new Exception("不支持的版本");
            }
        }
Ejemplo n.º 20
0
        private void DrawTimer_Tick(object sender, EventArgs e)
        {
            if (ShapeComboBox.SelectedItem == null || ArrowHeadComboBox.SelectedItem == null ||
                ArrowTailComboBox.SelectedItem == null)
            {
                return;
            }
            Converter  c;
            NodeConfig nc;
            Edge       testEdge;

            if (RelationsListBox.SelectedItem != null)
            {
                using (Graphics g = Graphics.FromImage(exampleBitmap))
                {
                    c  = new Converter(DrawPictureBox.Width, DrawPictureBox.Height, -1, 1, -5, 5);
                    nc = new NodeConfig(new Rectangle(), c, Pens.Black, Pens.Black, Color.White, Color.White, c.ToRealFont(DefaultFont), Color.Black);
                    EdgeConfig ec = new EdgeConfig(
                        (IEdgeShape)ShapeComboBox.SelectedItem,
                        (IArrowShape)ArrowHeadComboBox.SelectedItem,
                        (IArrowShape)ArrowTailComboBox.SelectedItem,
                        c.ToRealSize(ArrowSize),
                        c.ToRealSize(MarkerSize),
                        edgePen,
                        selectedEdgePen,
                        Converter.ToRealFont(font),
                        FontColorBTN.BackColor,
                        c);
                    testEdge = new Edge(
                        new Relation(RelationsListBox.SelectedItem.ToString()),
                        new Node("One", c.IJtoXY(new Point(40, 40)), nc),
                        new Node("Two", c.IJtoXY(new Point(DrawPictureBox.Width - 40, DrawPictureBox.Height - 40)), nc),
                        ec
                        );

                    testEdge.EdgeConfig.Edit = selected;
                    g.Clear(Color.White);
                    Drawing.DrawEdge(g, testEdge);
                    DrawPictureBox.Image = exampleBitmap;
                }
            }
        }
        private void btnDeleteDevices_Click(object sender, EventArgs e)
        {
            if (_edgeAgent == null)
            {
                return;
            }

            EdgeConfig config = new EdgeConfig();

            for (int i = 1; i <= numDeviceCount.Value; i++)
            {
                EdgeConfig.DeviceConfig device = new EdgeConfig.DeviceConfig()
                {
                    Id = "Device" + i
                };

                config.Node.DeviceList.Add(device);
            }

            bool result = _edgeAgent.UploadConfig(ActionType.Delete, config).Result;
        }
Ejemplo n.º 22
0
        private EdgeConfig GetFromFroms()
        {
            _edgeConfig = _edgeConfig ?? new EdgeConfig();

            _edgeConfig.Version          = this.cbbVersion.Text;
            _edgeConfig.SuperNodeIP      = this.txtSuperNodeIP.Text;
            _edgeConfig.SuperNodePort    = ParseInt(this.txtSuperNodePort.Text);
            _edgeConfig.EdgeIP           = this.txtEdgeIP.Text;
            _edgeConfig.EdgeNetmask      = this.txtEdgeNetmask.Text;
            _edgeConfig.EdgeGroup        = this.txtEdgeGroup.Text;
            _edgeConfig.EdgePassword     = this.txtEdgePassword.Text;
            _edgeConfig.MacAddress       = this.txtMacAddress.Text;
            _edgeConfig.MTU              = ParseInt(this.txtMTU.Text);
            _edgeConfig.ExtensionArgs    = this.txtExtensionArgs.Text;
            _edgeConfig.Multicast        = this.chkMulticast.IsChecked ?? false;
            _edgeConfig.PacketForwarding = this.chkPacketForwarding.IsChecked ?? false;
            _edgeConfig.ResolveSuperNode = this.chkResolveSuperNode.IsChecked ?? false;
            _edgeConfig.Verbose          = this.chkVerbose.IsChecked ?? false;

            return(_edgeConfig);
        }
Ejemplo n.º 23
0
        public Entity CreateConnection(Dictionary <int, Entity> subsystems, EdgeConfig edgeConfig)
        {
            if (_entityFactoryProvider.TryCreateEntityFromArchetype(edgeConfig.Archetype, out var connection))
            {
                var head = subsystems[edgeConfig.Source];
                var tail = subsystems[edgeConfig.Destination];

                connection.GetComponent <MovementCost>().Value = edgeConfig.Weight;

                connection.GetComponent <GraphNode>().EntrancePositions.Add(head.Id, 0);
                connection.GetComponent <GraphNode>().ExitPositions.Add(tail.Id, SimulationConstants.ConnectionPositions * edgeConfig.Length);

                head.GetComponent <GraphNode>().ExitPositions.Add(connection.Id, edgeConfig.SourcePosition.ToPosition(SimulationConstants.SubsystemPositions));
                tail.GetComponent <GraphNode>().EntrancePositions.Add(connection.Id, edgeConfig.SourcePosition.OppositePosition().ToPosition(SimulationConstants.SubsystemPositions));

                edgeConfig.EntityId = connection.Id;
                return(connection);
            }
            connection?.Dispose();
            throw new SimulationException($"Could not create connection from archetype '{edgeConfig.Archetype}'");
        }
Ejemplo n.º 24
0
        private void Test()
        {
            EdgeConfig ec = new EdgeConfig(
                new CurvedLine(),
                new CustomArrow(), new CustomArrow(),
                converter.ToRealSize(new SizeF(15, 25)),
                converter.ToRealSize(new SizeF(30, 30)),
                new Pen(Color.Black, 5),
                new Pen(Color.Red, 5),
                converter.ToRealFont(new Font(FontFamily.GenericMonospace, 24)),
                Color.Black, converter);

            Node n1 = new Node("qwe", new PointF(-2.14f, -0.88f), new NodeConfig(
                                   new RoundedRectangle(),
                                   converter,
                                   new Pen(Color.Black, 5),
                                   new Pen(Color.Red, 5),
                                   Color.White,
                                   Color.White,
                                   converter.ToRealFont(new Font(FontFamily.GenericMonospace, 24)),
                                   Color.Black));

            Node n2 = new Node("qwe", new PointF(2.31f, 3.4f), new NodeConfig(
                                   new RoundedRectangle(),
                                   converter,
                                   new Pen(Color.Black, 5),
                                   new Pen(Color.Red, 5),
                                   Color.White,
                                   Color.White,
                                   converter.ToRealFont(new Font(FontFamily.GenericMonospace, 24)),
                                   Color.Black));

            SemanticNetwork.AddNode(n1);
            SemanticNetwork.AddNode(n2);
            Edge e = new Edge(new Relation("test"), SemanticNetwork.Nodes[0], SemanticNetwork.Nodes[1], ec);

            SemanticNetwork.AddEdge(e);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Using the Web Driver Manager
        /// </summary>
        private static void UsingDriverManager(DriverOption driverOption)
        {
            IWebDriver    webDriver    = null;
            IDriverConfig driverConfig = null;

            switch (driverOption)
            {
            case DriverOption.Chrome:
                driverConfig = new ChromeConfig();
                webDriver    = new ChromeDriver();
                break;

            case DriverOption.Edge:
                driverConfig = new EdgeConfig();
                webDriver    = new EdgeDriver();
                break;

            case DriverOption.Firefox:
                driverConfig = new FirefoxConfig();
                webDriver    = new FirefoxDriver("./");
                break;

            case DriverOption.IE:
                driverConfig = new InternetExplorerConfig();
                webDriver    = new InternetExplorerDriver();
                break;

            case DriverOption.Opera:
                driverConfig = new OperaConfig();
                webDriver    = new OperaDriver();
                break;
            }

            new DriverManager().SetUpDriver(driverConfig);
            webDriver.Navigate().GoToUrl("https://www.google.com");
            System.Console.WriteLine($"Title : {webDriver.Title}");
            webDriver.Quit();
        }
Ejemplo n.º 26
0
        public MainWindow()
        {
            InitializeComponent();

            //加载配置
            _config     = ConfigManager.GetConfig();
            _edgeConfig = ConfigManager.GetEdgeConfig(_config.CurrentEdgeConfigName);

            //自动连接
            if (_config.AutoConnect && !string.IsNullOrEmpty(_config.CurrentEdgeConfigName))
            {
                Connect(_config.CurrentEdgeConfigName);
            }

            //系统唤醒
            SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

            //刷新状态栏和菜单
            RefreshStatus();

            //设置系统托盘图标
            SetNotifyIcon();
        }
        private void buttonUploadConfig_Click(object sender, EventArgs e)
        {
            if (_edgeAgent == null)
            {
                return;
            }

            EdgeConfig config = new EdgeConfig();

            config.Scada = new EdgeConfig.ScadaConfig()
            {
                Id             = textBoxGroupId.Text.Trim(),
                Description    = "descrp",
                PortNumber     = (int)numericUpDownPort.Value,
                HeartBeat      = 60,
                BackupDeviceId = 0
            };

            config.Scada.AnalogTagList   = new List <EdgeConfig.AnalogTagConfig> ();
            config.Scada.DiscreteTagList = new List <EdgeConfig.DiscreteTagConfig>();
            config.Scada.TextTagList     = new List <EdgeConfig.TextTagConfig>();

            for (int j = 1; j <= numATagCount.Value; j++)
            {
                EdgeConfig.AnalogTagConfig analogTag = new EdgeConfig.AnalogTagConfig()
                {
                    Name        = "ATag" + j,
                    Description = "ATag " + j,
                    ReadOnly    = false,
                    ArraySize   = 2,

                    NeedLog        = true,
                    SpanHigh       = 1000,
                    SpanLow        = 0,
                    EngineerUnit   = string.Empty,
                    DisplayFormat  = "4.2",
                    AlarmEnable    = false,
                    HHPriority     = 0,
                    HHAlarmLimit   = 0,
                    HighPriority   = 0,
                    HighAlarmLimit = 0,
                    LowPriority    = 0,
                    LowAlarmLimit  = 0,
                    LLPriority     = 0,
                    LLAlarmLimit   = 0
                };
                config.Scada.AnalogTagList.Add(analogTag);
            }
            for (int j = 1; j <= numDTagCount.Value; j++)
            {
                EdgeConfig.DiscreteTagConfig discreteTag = new EdgeConfig.DiscreteTagConfig()
                {
                    Name        = "DTag" + j,
                    Description = "DTag " + j,
                    ReadOnly    = false,
                    ArraySize   = 0,

                    AlarmEnable         = false,
                    State0              = "0",
                    State1              = "1",
                    State2              = string.Empty,
                    State3              = string.Empty,
                    State4              = string.Empty,
                    State5              = string.Empty,
                    State6              = string.Empty,
                    State7              = string.Empty,
                    State0AlarmPriority = 0,
                    State1AlarmPriority = 0,
                    State2AlarmPriority = 0,
                    State3AlarmPriority = 0,
                    State4AlarmPriority = 0,
                    State5AlarmPriority = 0,
                    State6AlarmPriority = 0,
                    State7AlarmPriority = 0
                };
                config.Scada.DiscreteTagList.Add(discreteTag);
            }
            for (int j = 1; j <= numTTagCount.Value; j++)
            {
                EdgeConfig.TextTagConfig textTag = new EdgeConfig.TextTagConfig()
                {
                    Name        = "TTag" + j,
                    Description = "TTag " + j,
                    ReadOnly    = false,
                    ArraySize   = 2,
                };
                config.Scada.TextTagList.Add(textTag);
            }

            bool result = _edgeAgent.UploadConfig(ActionType.Create, config).Result;
        }
        private void btnUpdateConfig_Click(object sender, EventArgs e)
        {
            if (_edgeAgent == null)
            {
                return;
            }

            EdgeConfig config = new EdgeConfig();

            for (int i = 1; i <= numDeviceCount.Value; i++)
            {
                EdgeConfig.DeviceConfig device = new EdgeConfig.DeviceConfig()
                {
                    Id          = "Device" + i,
                    Description = "Device " + i,
                };

                for (int j = 1; j <= numATagCount.Value; j++)
                {
                    EdgeConfig.AnalogTagConfig analogTag = new EdgeConfig.AnalogTagConfig()
                    {
                        Name                  = "ATag" + j,
                        Description           = "ATag " + j,
                        ReadOnly              = false,
                        ArraySize             = 0,
                        SpanHigh              = 1000,
                        SpanLow               = 0,
                        EngineerUnit          = string.Empty,
                        IntegerDisplayFormat  = 4,
                        FractionDisplayFormat = 2
                    };
                    device.AnalogTagList.Add(analogTag);
                }
                for (int j = 1; j <= numDTagCount.Value; j++)
                {
                    EdgeConfig.DiscreteTagConfig discreteTag = new EdgeConfig.DiscreteTagConfig()
                    {
                        Name        = "DTag" + j,
                        Description = "DTag " + j,
                        ReadOnly    = false,
                        ArraySize   = 0,
                        State0      = "0",
                        State1      = "1",
                        State2      = string.Empty,
                        State3      = string.Empty,
                        State4      = string.Empty,
                        State5      = string.Empty,
                        State6      = string.Empty,
                        State7      = string.Empty
                    };
                    device.DiscreteTagList.Add(discreteTag);
                }
                for (int j = 1; j <= numTTagCount.Value; j++)
                {
                    EdgeConfig.TextTagConfig textTag = new EdgeConfig.TextTagConfig()
                    {
                        Name        = "TTag" + j,
                        Description = "TTag " + j,
                        ReadOnly    = false,
                        ArraySize   = 0
                    };
                    device.TextTagList.Add(textTag);
                }

                config.Node.DeviceList.Add(device);
            }

            bool result = _edgeAgent.UploadConfig(ActionType.Update, config).Result;
        }
Ejemplo n.º 29
0
        // TODO: this should be parameterized further and read from config
        public override SimulationScenario GenerateScenario()
        {
            #region configuration

            #region graph

            var node00      = new NodeConfig(0, 0, AntivirusWorkstation.Archetype, "Antivirus");
            var node10      = new NodeConfig(1, 0, SubsystemNode.Archetype);
            var node20      = new NodeConfig(2, 0, SubsystemNode.Archetype);
            var node01      = new NodeConfig(0, 1, SubsystemNode.Archetype);
            var node11      = new NodeConfig(1, 1, SubsystemNode.Archetype);
            var node21      = new NodeConfig(2, 1, SubsystemNode.Archetype);
            var nodeConfigs = new NodeConfig[]
            {
                node00,
                node10,
                node20,
                node01,
                node11,
                node21,
            };
            ConfigurationHelper.ProcessNodeConfigs(nodeConfigs);

            var connection0010 = new EdgeConfig(node00.Id, EdgeDirection.East, node10.Id, ConnectionNode.Archetype);
            var connection1000 = connection0010.Reciprocate();

            var connection1020 = new EdgeConfig(node10.Id, EdgeDirection.East, node20.Id, ConnectionNode.Archetype);
            var connection2010 = connection1020.Reciprocate();

            var connection0001 = new EdgeConfig(node00.Id, EdgeDirection.South, node01.Id, ConnectionNode.Archetype);
            var connection0100 = connection0001.Reciprocate();

            var connection0111 = new EdgeConfig(node01.Id, EdgeDirection.East, node11.Id, ConnectionNode.Archetype);
            var connection1101 = connection0111.Reciprocate();

            var connection1121 = new EdgeConfig(node11.Id, EdgeDirection.East, node21.Id, ConnectionNode.Archetype);
            var connection2111 = connection1121.Reciprocate();

            var connection2021 = new EdgeConfig(node20.Id, EdgeDirection.South, node21.Id, ConnectionNode.Archetype);
            var connection2120 = connection2021.Reciprocate();

            var edgeConfigs = new EdgeConfig[]
            {
                connection0010,
                connection1000,
                connection1020,
                connection2010,
                connection0001,
                connection0100,
                connection0111,
                connection1101,
                connection1121,
                connection2111,
                connection2021,
                connection2120,
            };

            #endregion

            var archetypes = new List <Archetype>
            {
                SubsystemNode.Archetype,
                ConnectionNode.Archetype,
                Player.Archetype,
                ScannerTool.Archetype,
                AntivirusWorkstation.Archetype,
                AnalyserActivator.Archetype,
                CaptureTool.Archetype,
                AntivirusTool.Archetype,
                RedVirus80,
            };

            var configuration = ConfigurationHelper.GenerateConfiguration(nodeConfigs, edgeConfigs, null, archetypes);
            configuration.RNGSeed = 561122999;

            #endregion

            var scenario = new SimulationScenario(ScenarioInfo)
            {
                Configuration = configuration,

                PlayerConfigFactory = new StartingLocationSequencePlayerConfigFactory(Player.Archetype, new[] { node00.Id, node20.Id, node01.Id, node21.Id }),
                Sequence            = new List <SequenceFrame <Simulation, SimulationConfiguration> >(),

                Scoring = SimulationScenario.ScoringMode.Full,
            };

            var spawnSequence = new NodeSequence(new[]
            {
                // offset by one vs config
                node00,
                node20,
                node10,
                node00,
                node20,
                node01,
                node10,
                node01,
            });

            #region frames

            // 1
            scenario.Sequence.Add(
                new SimulationFrame()
            {
                OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >()
                {
                    new SetTimer <Simulation, SimulationConfiguration>(scenario.TimeLimitSeconds.Value),
                    new CreateItem(ScannerTool.Archetype, node10),
                    new CreateItem(ScannerTool.Archetype, node20),
                    new CreateItem(CaptureTool.Archetype, node10),
                    new CreateItem(CaptureTool.Archetype, node10),
                },
                ExitCondition = new WaitForTicks(1),
                OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >()
                {
                    new CreateMalware(RedVirus80, node01)
                },
            }
                );

            // 2
            scenario.Sequence.Add(
                new SimulationFrame()
            {
                OnEnterActions = new List <ECSAction <Simulation, SimulationConfiguration> >()
                {
                },
                OnTickActions = new List <ECSAction <Simulation, SimulationConfiguration> >()
                {
                    new ConditionalAction <Simulation, SimulationConfiguration>(new NodeSequenceAction(spawnSequence, ec => new CreateMalware(RedVirus80, ec)),
                                                                                new OnEvent <AntivirusActivationEvent>(aae => aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.SoloExtermination ||
                                                                                                                       aae.ActivationResult == AntivirusActivationEvent.AntivirusActivationResult.CoopExtermination)),
                },
                ExitCondition = new WaitForTimer(),
                OnExitActions = new List <ECSAction <Simulation, SimulationConfiguration> >()
                {
                    new EndGame(EndGameState.Neutral),
                },
            }
                );

            #endregion

            return(scenario);
        }
Ejemplo n.º 30
0
 public Task <bool> UploadConfig(ActionType action, EdgeConfig edgeConfig)
 {
     return(Task.Run(() => _uploadConfig(action, edgeConfig)));
 }