/// <summary>
 /// This object is passed to NodeInitializer if you want to create a node inside the virtual network. Communications in the virtual network do not take place via the internet, but through a pipeline, simulating the Internet protocol.
 /// </summary>
 public VirtualDevice()
 {
     Id          = _lastId + 1;
     _lastId     = Id;
     MachineName = Environment.MachineName;
     Domain      = Id + "." + MachineName.ToLower();
     Address     = "vd://" + Domain;
     Ip          = (uint)Domain.GetHashCode();
 }
        /// <summary>
        /// Continue method implementation
        /// PowerShell Resume-Service
        /// </summary>
        public void Continue()
        {
            Runspace   SPRunSpace   = null;
            PowerShell SPPowerShell = null;

            try
            {
                bool islocal = (Dns.GetHostEntry("LocalHost").HostName.ToLower().Equals(MachineName.ToLower()));
                if (!islocal)
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, MachineName, 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", null, 30000);
                    SPRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);
                    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.NegotiateWithImplicitCredential;
                }
                else
                {
                    SPRunSpace = RunspaceFactory.CreateRunspace();
                }

                SPPowerShell          = PowerShell.Create();
                SPPowerShell.Runspace = SPRunSpace;
                SPRunSpace.Open();

                Pipeline pipeline = SPRunSpace.CreatePipeline();
                Command  cmd      = new Command("Resume-Service " + this.ServiceName, true);
                pipeline.Commands.Add(cmd);
                Collection <PSObject> PSOutput = pipeline.Invoke();
            }
            finally
            {
                if (SPRunSpace != null)
                {
                    SPRunSpace.Close();
                }
                if (SPPowerShell != null)
                {
                    SPPowerShell.Dispose();
                }
            }
        }
        private void Open()
        {
            Runspace   SPRunSpace   = null;
            PowerShell SPPowerShell = null;

            try
            {
                bool islocal = (Dns.GetHostEntry("LocalHost").HostName.ToLower().Equals(MachineName.ToLower()));
                if (!islocal)
                {
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, MachineName, 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", null, 30000);
                    SPRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);
                    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.NegotiateWithImplicitCredential;
                }
                else
                {
                    SPRunSpace = RunspaceFactory.CreateRunspace();
                }

                SPPowerShell          = PowerShell.Create();
                SPPowerShell.Runspace = SPRunSpace;
                SPRunSpace.Open();

                Pipeline pipeline = SPRunSpace.CreatePipeline();
                Command  cmd      = new Command("Get-Service " + this.ServiceName, true);
                pipeline.Commands.Add(cmd);
                Collection <PSObject> PSOutput = pipeline.Invoke();
                foreach (var result in PSOutput)
                {
                    ServiceName = result.Members["Name"].Value.ToString();
                    DisplayName = result.Members["DisplayName"].Value.ToString();
                    string _status = result.Members["Status"].Value.ToString();
                    Status = StringToStatus(_status);
                    CanPauseAndContinue = Convert.ToBoolean(result.Members["CanPauseAndContinue"].Value);
                    CanShutdown         = Convert.ToBoolean(result.Members["CanShutdown"].Value);
                    CanStop             = Convert.ToBoolean(result.Members["CanStop"].Value);
                }
            }
            finally
            {
                if (SPRunSpace != null)
                {
                    SPRunSpace.Close();
                }
                if (SPPowerShell != null)
                {
                    SPPowerShell.Dispose();
                }
            }
        }
        private void DetectDenialOfService(string port, string protocol, string machineName)
        {
            _canResetCnt = true;

            if (!string.IsNullOrEmpty(Port) && !string.IsNullOrEmpty(Protocol))
            {
                if (!port.ToLower().Equals(Port.ToLower()) && !protocol.ToLower().Equals(Protocol.ToLower()) && !machineName.ToLower().Equals(MachineName.ToLower()))
                {
                    Counter = 0;
                }
            }
            else if (!string.IsNullOrEmpty(Port))
            {
                if (!port.ToLower().Equals(Port.ToLower()) || !machineName.ToLower().Equals(MachineName.ToLower()))
                {
                    Counter = 0;
                }
            }
            else if (!string.IsNullOrEmpty(Protocol))
            {
                if (!protocol.ToLower().Equals(Protocol.ToLower()) || !machineName.ToLower().Equals(MachineName.ToLower()))
                {
                    Counter = 0;
                }
            }

            Counter += 1;

            if (Counter == 3)
            {
                DenialOfService();
            }
        }