예제 #1
0
        public override void CommitLogEvent(LogEvent logEvent)
        {
            SourceName   source    = GetSource(logEvent, Database);
            CategoryName category  = GetCategory(logEvent, Database);
            UserName     user      = GetUser(logEvent, Database);
            ComputerName computer  = GetComputer(logEvent, Database);
            Signature    signature = GetSignature(logEvent, Database);

            Event instance = new Event();

            instance.SignatureId    = signature.Id;
            instance.ComputerNameId = computer.Id;
            instance.CategoryNameId = category.Id;
            instance.SourceNameId   = source.Id;
            instance.UserNameId     = user.Id;
            instance.EventId        = logEvent.EventID;
            instance.Time           = logEvent.Time;
            instance.Severity       = (int)logEvent.Severity;
            instance.Save(Database);
            logEvent.MessageVariableValues.Each((val, pos) =>
            {
                Param p    = instance.Params.AddNew();
                p.Position = pos;
                p.Value    = val;
            });
            instance.Save(Database);
        }
예제 #2
0
        public override int GetHashCode()
        {
            int hash = 13;

            hash = (hash * 7) + ComputerName.GetHashCode();
            return(hash);
        }
예제 #3
0
        internal static PerformanceCounterLib GetPerformanceCounterLib(string machineName, CultureInfo culture)
        {
            string lcidString = culture.Name.ToLowerInvariant();

            if (machineName.CompareTo(".") == 0)
            {
                machineName = ComputerName.ToLowerInvariant();
            }
            else
            {
                machineName = machineName.ToLowerInvariant();
            }

            LazyInitializer.EnsureInitialized(ref s_libraryTable, ref s_internalSyncObject, () => new Dictionary <string, PerformanceCounterLib>());

            string libraryKey = machineName + ":" + lcidString;
            PerformanceCounterLib library;

            if (!PerformanceCounterLib.s_libraryTable.TryGetValue(libraryKey, out library))
            {
                library = new PerformanceCounterLib(machineName, lcidString);
                PerformanceCounterLib.s_libraryTable[libraryKey] = library;
            }
            return(library);
        }
        internal static PerformanceCounterLib GetPerformanceCounterLib(string machineName, CultureInfo culture)
        {
            SharedUtils.CheckEnvironment();
            string lcid = culture.LCID.ToString("X3", CultureInfo.InvariantCulture);

            if (machineName.CompareTo(".") == 0)
            {
                machineName = ComputerName.ToLower(CultureInfo.InvariantCulture);
            }
            else
            {
                machineName = machineName.ToLower(CultureInfo.InvariantCulture);
            }
            if (libraryTable == null)
            {
                lock (InternalSyncObject)
                {
                    if (libraryTable == null)
                    {
                        libraryTable = new Hashtable();
                    }
                }
            }
            string key = machineName + ":" + lcid;

            if (libraryTable.Contains(key))
            {
                return((PerformanceCounterLib)libraryTable[key]);
            }
            PerformanceCounterLib lib = new PerformanceCounterLib(machineName, lcid);

            libraryTable[key] = lib;
            return(lib);
        }
예제 #5
0
        private string GetExeFileCommandLineArguments(CodeActivityContext context)
        {
            string doNotDeleteArgument    = "-enableRule:DoNotDeleteRule";
            string computerNameArgument   = string.Format("computerName='{0}',", ComputerName.Get(context));
            string userNameArgument       = string.Format("userName='******',", Username.Get(context));
            string passwordArgument       = string.Format("password='******',", Password.Get(context));
            string webApplicationArgument = string.Format("-setParam:'IIS Web Application Name'='{0}'", IISWebApplication.Get(context));

            string msdeployArguments = (Test.Get(context) ? "-whatif" : "");

            msdeployArguments += " -source:package='{0}' -dest:auto,{1}{2}{3}authtype='Basic',includeAcls='False' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:\"{4}\" {5} {6} {7} {8}";

            msdeployArguments = string.Format(msdeployArguments,
                                              Path.GetFullPath(ZipPackageFilename.Get(context)),
                                              (string.IsNullOrEmpty(ComputerName.Get(context)) ? "" : computerNameArgument),
                                              (string.IsNullOrEmpty(Username.Get(context)) ? "" : userNameArgument),
                                              (string.IsNullOrEmpty(Password.Get(context)) ? "" : passwordArgument),
                                              Path.GetFullPath(ParamFilename.Get(context)),
                                              (string.IsNullOrEmpty(IISWebApplication.Get(context)) ? "" : webApplicationArgument),
                                              (DoNotDeleteFiles.Get(context) ? doNotDeleteArgument : ""),
                                              (AllowUntrustedSSLConnection.Get(context) ? "-allowUntrusted" : ""),
                                              (!string.IsNullOrEmpty(CommandLineParams.Get(context)) ? CommandLineParams.Get(context) : "")).Trim();

            return(msdeployArguments);
        }
예제 #6
0
        internal static PerformanceCounterLib GetPerformanceCounterLib(string machineName, CultureInfo culture)
        {
            string lcidString = culture.Name.ToLowerInvariant();

            if (machineName.CompareTo(".") == 0)
            {
                machineName = ComputerName.ToLowerInvariant();
            }
            else
            {
                machineName = machineName.ToLowerInvariant();
            }

            if (PerformanceCounterLib.s_libraryTable == null)
            {
                lock (InternalSyncObject)
                {
                    if (PerformanceCounterLib.s_libraryTable == null)
                    {
                        PerformanceCounterLib.s_libraryTable = new Dictionary <string, PerformanceCounterLib>();
                    }
                }
            }

            string libraryKey = machineName + ":" + lcidString;
            PerformanceCounterLib library;

            if (!PerformanceCounterLib.s_libraryTable.TryGetValue(libraryKey, out library))
            {
                library = new PerformanceCounterLib(machineName, lcidString);
                PerformanceCounterLib.s_libraryTable[libraryKey] = library;
            }
            return(library);
        }
예제 #7
0
 private bool Encrypt()
 {
     if (IsAutoMode)
     {
         if (ComputerName.IsNullOrEmpty())
         {
             var protector = new PasswordProtector();
             EncryptedValue = protector.Protect(OriginalValue, PasswordProtectionScope.LocalMachine);
             return(true);
         }
         else
         {
             //var factory = new ImpersonatorFactory()
             //{
             //    IsEnabled = true,
             //    Username = "******",
             //    Password = "******",
             //    Domain = "LILI"
             //};
             //using (factory.Create())
             {
                 var powershell = new PowerShellExecutor(ComputerName);
                 if (powershell.Execute())
                 {
                     EncryptedValue = powershell.Result;
                     return(true);
                 }
             }
         }
         return(false);
     }
     return(true);
 }
예제 #8
0
 internal object ToParam()
 {
     return(new
     {
         account = UserName.ToUpper(),
         computer = ComputerName.ToUpper(),
         weight = Weight
     });
 }
예제 #9
0
 public override object ToParam()
 {
     return(new
     {
         a = UserName.ToUpper(),
         b = ComputerName.ToUpper(),
         weight = Weight
     });
 }
예제 #10
0
        internal void CaptureAssetInfo(List <string> output)
        {
            ManufacturerName = output[2];
            Model            = output[0];
            ComputerName     = output[1];
            SerialNumber     = output[3];
            var startIndex = ComputerName.Length - 8;

            Barcode = Convert.ToInt32(ComputerName.Substring(startIndex, 7));
        }
예제 #11
0
        public void ParameterNamesDefinedCorrect()
        {
            // Fixture setup

            // Exercise system and verify outcome
            ComputerName.Name.Should().Be("ComputerName");
            ComputerName.ConvertFromString("string").As <string>().Should().Be("string");

            Command.Name.Should().Be("Command");
            Command.ConvertFromString("string").As <string>().Should().Be("string");
        }
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Authentication.Expression != null)
            {
                targetCommand.AddParameter("Authentication", Authentication.Get(context));
            }

            if ((ComputerName.Expression != null) && (PSRemotingBehavior.Get(context) != RemotingBehavior.Custom))
            {
                targetCommand.AddParameter("ComputerName", ComputerName.Get(context));
            }

            if (Port.Expression != null)
            {
                targetCommand.AddParameter("Port", Port.Get(context));
            }

            if (UseSSL.Expression != null)
            {
                targetCommand.AddParameter("UseSSL", UseSSL.Get(context));
            }

            if (ApplicationName.Expression != null)
            {
                targetCommand.AddParameter("ApplicationName", ApplicationName.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (CertificateThumbprint.Expression != null)
            {
                targetCommand.AddParameter("CertificateThumbprint", CertificateThumbprint.Get(context));
            }

            if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom))
            {
                targetCommand.AddParameter("ComputerName", PSComputerName.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
예제 #13
0
        private static ComputerName GetComputer(LogEvent logEvent, Database db)
        {
            ComputerName computer = ComputerName.OneWhere(cc => cc.Value == logEvent.Computer, db);

            if (computer == null)
            {
                computer       = new ComputerName();
                computer.Value = logEvent.Computer;
                computer.Save(db);
            }
            return(computer);
        }
예제 #14
0
        public void ComputerName_ToString_SetProperty_Expect_SetName()
        {
            //--------------------Arrange--------------------
            var testName = "TestComputerName";

            var computerNames = new ComputerName();

            //--------------------Act------------------------
            computerNames.Name = testName;
            //--------------------Assert---------------------
            Assert.AreEqual(testName, computerNames.Name);
            Assert.AreEqual(testName, computerNames.ToString());
        }
        public static void AssertComputerNames( string[] expected, ComputerName[] actual )
        {
            if ( expected.Length % 2 > 0 )
                throw new ArgumentException( "Number of expected strings should be divisable by two.  Expecting name,alias pairs." );

            ComputerName[] names = new ComputerName[expected.Length / 2];
            for ( int i = 0; i < expected.Length; ++i )
            {
                names[i / 2] = new ComputerName( expected[i], expected[++i] );
            }

            Assert.AreEqual( names, actual );
        }
예제 #16
0
        /// <summary>
        /// Performs execution of the command
        /// </summary>
        protected override void DoProcessRecord()
        {
            const string cmd           = "_GetConnectionString -Version $args[0]";
            const string localTemplate = "{0}";
            // const string remoteTemplate = "Invoke-Command -ScriptBlock {{ {0} }} -ArgumentList $args[0] ";
            // const string remoteComputerTemplate = remoteTemplate + " -Computer $args[1] -Credential $args[2]";
            // const string remoteSessionTemplate = remoteTemplate + " -Session $args[1]";

            var funcCode = File.ReadAllText(Path.Combine(
                                                MyInvocation.MyCommand.Module.ModuleBase,
                                                "Private/Admin.ps1"
                                                ));

            object session    = null;
            object credential = null;
            string invokeCmd;

            if (Session != null)
            {
                throw new NotImplementedException("Remote sessions are currently not supported");
                // invokeCmd = string.Format(remoteSessionTemplate, cmd);
                // session = Session;
            }
            else if (!ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase))
            {
                throw new NotImplementedException("Remote computers are currently not supported");
                // invokeCmd = string.Format(remoteComputerTemplate, cmd);
                // session = ComputerName;
                // credential = Credential;
            }
            else
            {
                invokeCmd = string.Format(localTemplate, cmd);
            }

            string version;

            if (Version == 0)
            {
                version = null;
            }
            else
            {
                version = $"{TfsVersionTable.GetMajorVersion(Version)}.0";
            }

            var result = this.InvokeCommand.InvokeScript(funcCode + invokeCmd, true, PipelineResultTypes.None, null,
                                                         version, session, credential);

            WriteObject(result);
        }
예제 #17
0
        internal String GetConfigEntry(String entry)
        {
            switch (entry)
            {
            case "CAServerName": return(ComputerName);

            case "ServerShortName": return(ComputerName.Split('.')[0]);

            case "CommonName": return(Name);

            case "CATruncatedName": return(DsUtils.GetSanitizedName(Name));

            case "ConfigurationContainer": return((String)CryptoRegistry.GetRReg("DSConfigDN", Name, ComputerName));

            default: return(String.Empty);
            }
        }
        public void TestFromModel()
        {
            //arrange
            var dbSourceMock               = new Mock <IDbSource>();
            var expectedResourceName       = "expectedResourceName";
            var expectedAuthenticationType = AuthenticationType.Windows;
            var expectedUserName           = "******";
            var dbSourceServerName         = "dbSoureServerName";
            var dbSourceType               = enSourceType.DynamicService;
            var expectedPassword           = "******";
            var expectedPath               = "expectedPath";
            var expectedServerName         = new ComputerName()
            {
                Name = dbSourceServerName
            };

            _targetAsyncWorker.ComputerNames = new List <ComputerName> {
                expectedServerName
            };
            var expectedDatabaseName = "expectedDatabaseName";

            dbSourceMock.SetupGet(it => it.Name).Returns(expectedResourceName);
            dbSourceMock.SetupGet(it => it.AuthenticationType).Returns(expectedAuthenticationType);
            dbSourceMock.SetupGet(it => it.UserName).Returns(expectedUserName);
            dbSourceMock.SetupGet(it => it.ServerName).Returns(dbSourceServerName);
            dbSourceMock.SetupGet(it => it.Password).Returns(expectedPassword);
            dbSourceMock.SetupGet(it => it.Path).Returns(expectedPath);
            dbSourceMock.SetupGet(it => it.Type).Returns(dbSourceType);
            dbSourceMock.SetupGet(it => it.DbName).Returns(expectedDatabaseName);
            _changedPropertiesAsyncWorker.Clear();

            //act
            _targetAsyncWorker.FromModel(dbSourceMock.Object);

            //assert
            Assert.AreEqual(expectedResourceName, _targetAsyncWorker.ResourceName);
            Assert.AreEqual(expectedAuthenticationType, _targetAsyncWorker.AuthenticationType);
            Assert.AreEqual(expectedUserName, _targetAsyncWorker.UserName);
            Assert.AreSame(expectedServerName, _targetAsyncWorker.ServerName);
            Assert.AreEqual(dbSourceServerName, _targetAsyncWorker.EmptyServerName);
            Assert.AreEqual(expectedPassword, _targetAsyncWorker.Password);
            Assert.AreEqual(expectedPath, _targetAsyncWorker.Path);
            Assert.AreEqual(expectedDatabaseName, _targetAsyncWorker.DatabaseName);
            Assert.IsTrue(_changedPropertiesAsyncWorker.Contains("DatabaseNames"));
        }
예제 #19
0
        public VerifyComputer AddComputer(string name, string introduced, string discontinued, string company)
        {
            //open page
            AddNewComputer.Click();
            //Thread.Sleep(1000);

            //provide data
            ComputerName.SendKeys(name);
            IntrodecedDate.SendKeys(introduced);
            DiscontinuedDate.SendKeys(discontinued);
            Company.SendKeys(company);
            Company.SendKeys(Keys.Enter);
            Console.WriteLine("Company details provided");

            //submit form
            CreateComputer.Submit();
            return(new VerifyComputer(webDriver));
        }
예제 #20
0
        // Module defining this command
        

        // Optional custom code for this activity
        

        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments
            
            if((ComputerName.Expression != null) && (PSRemotingBehavior.Get(context) != RemotingBehavior.Custom))
            {
                targetCommand.AddParameter("ComputerName", ComputerName.Get(context));
            }
            
            if(GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom))
            {
                targetCommand.AddParameter("ComputerName", PSComputerName.Get(context));
            }

            return new ActivityImplementationContext() { PowerShellInstance = invoker };
        }
        public ComputerName BuildComputerName( string computerName, string aliasName )
        {
            ComputerName computer = m_RecentComputerList.Find( computerName );
            if (computer == null)
            {
                computer = new ComputerName( computerName, aliasName );
            }
            else if (computer.EqualsAlias( computerName ))
            {
                // There is some ambiguity in the UI.  If you have an alias in the Computer Name drop-down
                // and a name in the Alias textbox then don't do anything with the Alias textbox.
            }
            else if (aliasName != "")
            {
                // We still set the alias in-case we are trying to change the computer name the alias is associated with.
                computer.Alias = aliasName;
            }

            return computer;
        }
        public void TestServerName()
        {
            //arrange
            var expectedValue = new ComputerName();

            _changedPropertiesAsyncWorker.Clear();

            //act
            _targetAsyncWorker.ServerName = expectedValue;
            var actualValue = _targetAsyncWorker.ServerName;

            //assert
            Assert.AreSame(expectedValue, actualValue);
            Assert.IsTrue(_changedPropertiesAsyncWorker.Contains("ServerName"));
            Assert.IsTrue(_changedPropertiesAsyncWorker.Contains("Header"));
            Assert.IsFalse(_targetAsyncWorker.TestPassed);
            Assert.IsTrue(string.IsNullOrEmpty(_targetAsyncWorker.TestMessage));
            Assert.IsFalse(_targetAsyncWorker.TestFailed);
            Assert.IsFalse(_targetAsyncWorker.Testing);
        }
예제 #23
0
        private string GetCmdFileCommandLineArguments(CodeActivityContext context)
        {
            string doNotDeleteArgument    = "-enableRule:DoNotDeleteRule";
            string computerNameArgument   = string.Format("/M:{0}", ComputerName.Get(context));
            string userNameArgument       = string.Format("/U:{0}", Username.Get(context));
            string passwordArgument       = string.Format("/P:{0}", Password.Get(context));
            string webApplicationArgument = string.Format("\"-setParam:'IIS Web Application Name'='{0}'\"", IISWebApplication.Get(context));

            string msdeployArguments = (Test.Get(context) ? "/t" : "/y");

            msdeployArguments += " {0} {1} {2} {3} {4} {5} {6}";

            msdeployArguments = string.Format(msdeployArguments,
                                              (!string.IsNullOrEmpty(IISWebApplication.Get(context)) ? webApplicationArgument : ""),
                                              (DoNotDeleteFiles.Get(context) ? doNotDeleteArgument : ""),
                                              (!string.IsNullOrEmpty(ComputerName.Get(context)) ? computerNameArgument : ""),
                                              (!string.IsNullOrEmpty(Username.Get(context)) ? userNameArgument : ""),
                                              (!string.IsNullOrEmpty(Password.Get(context)) ? passwordArgument : ""),
                                              (AllowUntrustedSSLConnection.Get(context) ? "-allowUntrusted" : ""),
                                              (!string.IsNullOrEmpty(CommandLineParams.Get(context)) ? CommandLineParams.Get(context) : "")).Trim();

            return(msdeployArguments);
        }
예제 #24
0
        internal String GetConfigEntry(String entry)
        {
            switch (entry)
            {
            case "CAServerName":
                return(ComputerName);

            case "ServerShortName":
                return(ComputerName.Split('.')[0]);

            case "CommonName":
                return(Name);

            case "CATruncatedName":
                return(DsUtils.GetSanitizedName(Name));

            case "ConfigurationContainer":
                _regReader.SetRootNode(true);
                return(_regReader.GetStringEntry("DSConfigDN"));

            default: return(String.Empty);
            }
        }
        public void ReadFile( )
        {
            StringReader reader = new StringReader(
                "1.1.1.1\talias\tTrue\r\n" +
                "work\t\tFalse\r\n" +
                // The "classic" style, computer \t alias
                "2.2.2.2\tclassic\r\n" +
                "3.3.3.3\t\r\n" +
                "\r\n" +
                "4.4.4.4" );

            ComputerListFile serializer = new ComputerListFile();
            RecentComputerList computers = serializer.Read( reader );

            ComputerName[] cnames = new ComputerName[]
            {
                new ComputerName( "1.1.1.1", "alias", true ),
                new ComputerName( "work", null, false ),
                new ComputerName( "2.2.2.2", "classic", false ),
                new ComputerName( "3.3.3.3", null, false ),
                new ComputerName( "4.4.4.4", null, false )
            };
            Assert.AreEqual( cnames, computers.ToArray() );
        }
예제 #26
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (AsJob.Expression != null)
            {
                targetCommand.AddParameter("AsJob", AsJob.Get(context));
            }

            if (DcomAuthentication.Expression != null)
            {
                targetCommand.AddParameter("DcomAuthentication", DcomAuthentication.Get(context));
            }

            if (WsmanAuthentication.Expression != null)
            {
                targetCommand.AddParameter("WsmanAuthentication", WsmanAuthentication.Get(context));
            }

            if (Protocol.Expression != null)
            {
                targetCommand.AddParameter("Protocol", Protocol.Get(context));
            }

            if (BufferSize.Expression != null)
            {
                targetCommand.AddParameter("BufferSize", BufferSize.Get(context));
            }

            if (ComputerName.Expression != null)
            {
                targetCommand.AddParameter("ComputerName", ComputerName.Get(context));
            }

            if (Count.Expression != null)
            {
                targetCommand.AddParameter("Count", Count.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (Source.Expression != null)
            {
                targetCommand.AddParameter("Source", Source.Get(context));
            }

            if (Impersonation.Expression != null)
            {
                targetCommand.AddParameter("Impersonation", Impersonation.Get(context));
            }

            if (ThrottleLimit.Expression != null)
            {
                targetCommand.AddParameter("ThrottleLimit", ThrottleLimit.Get(context));
            }

            if (TimeToLive.Expression != null)
            {
                targetCommand.AddParameter("TimeToLive", TimeToLive.Get(context));
            }

            if (Delay.Expression != null)
            {
                targetCommand.AddParameter("Delay", Delay.Get(context));
            }

            if (Quiet.Expression != null)
            {
                targetCommand.AddParameter("Quiet", Quiet.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
예제 #27
0
 public static void LogAddComputer( ComputerName computer )
 {
     LogString( string.Format( "Adding computer: {0} ({1})",
         computer.Computer, computer.Alias ) );
 }
 protected void OnComputerChanged( ComputerName computer )
 {
     if ( ComputerChanged != null )
         ComputerChanged( this, new DataEventArgs( computer ) );
 }
 private Brush GetComboBoxItemBrush( ComputerName computer, DrawItemState state )
 {
     if ( (state & DrawItemState.Selected) != 0 )
         return SystemBrushes.HighlightText;
     else if ( computer.Alias != null )
         return UIItems.AliasBrush;
     else
         return SystemBrushes.ControlText;
 }
예제 #30
0
 public string GetComputerName()
 {
     return(ComputerName.GetAttribute("value"));
 }
예제 #31
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (Path.Expression != null)
            {
                targetCommand.AddParameter("Path", Path.Get(context));
            }

            if (Class.Expression != null)
            {
                targetCommand.AddParameter("Class", Class.Get(context));
            }

            if (Arguments.Expression != null)
            {
                targetCommand.AddParameter("Arguments", Arguments.Get(context));
            }

            if (PutType.Expression != null)
            {
                targetCommand.AddParameter("PutType", PutType.Get(context));
            }

            if (AsJob.Expression != null)
            {
                targetCommand.AddParameter("AsJob", AsJob.Get(context));
            }

            if (Impersonation.Expression != null)
            {
                targetCommand.AddParameter("Impersonation", Impersonation.Get(context));
            }

            if (Authentication.Expression != null)
            {
                targetCommand.AddParameter("Authentication", Authentication.Get(context));
            }

            if (Locale.Expression != null)
            {
                targetCommand.AddParameter("Locale", Locale.Get(context));
            }

            if (EnableAllPrivileges.Expression != null)
            {
                targetCommand.AddParameter("EnableAllPrivileges", EnableAllPrivileges.Get(context));
            }

            if (Authority.Expression != null)
            {
                targetCommand.AddParameter("Authority", Authority.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (ThrottleLimit.Expression != null)
            {
                targetCommand.AddParameter("ThrottleLimit", ThrottleLimit.Get(context));
            }

            if (ComputerName.Expression != null)
            {
                targetCommand.AddParameter("ComputerName", ComputerName.Get(context));
            }

            if (Namespace.Expression != null)
            {
                targetCommand.AddParameter("Namespace", Namespace.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
예제 #32
0
        public void GatherSystemData()
        {
            IniFile RegisterIniFile = new IniFile(RegisterIni);

            IsMaster = Convert.ToBoolean(RegisterIniFile.IniReadValue("Terminal", "IsMaster"));
            string  StoreIni     = RegisterIniFile.IniReadValue("INI", "Store").ToString().Replace(@"\", @"\\");
            IniFile StoreIniFile = new IniFile(StoreIni);

            RegisterCount = Convert.ToInt32(StoreIniFile.IniReadValue("System", "NumRegisters"));

            //Set variables available using Environment.
            OSVersion        = Environment.OSVersion.ToString();
            NumOfLogicalProc = Convert.ToInt32(Environment.ProcessorCount);
            ComputerName     = Environment.MachineName.ToString();

            //Read Build Date and Build Version from Registry
            BuildDate = Registry.GetValue(GameStopRegKey, "CREATED", null).ToString();
            BuildVer  = Registry.GetValue(GameStopRegKey, "BuildVersion", null).ToString();

            // Set POS related variables
            if (File.Exists(RetechEXE))
            {
                POSArch = "ReTech";
                FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(RetechEXE);
                POSVer         = myFileVersionInfo.FileVersion.ToString();
                Terminal       = RegisterIniFile.IniReadValue("Terminal", "Num");
                PinPad         = "Verifone MX";
                ReceiptPrinter = "Epson Thermal";
            }
            else
            {
                POSArch = "IPOS";
                FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(IPOSExe);
                POSVer   = myFileVersionInfo.ProductName.ToString();
                Terminal = RegisterIniFile.IniReadValue("Terminal", "Num");

                string PinPadType = RegisterIniFile.IniReadValue("DeviceType", "PinPad");
                switch (PinPadType)
                {
                case "0": { PinPad = "None"; break; }

                case "1": { PinPad = "Verifone"; break; }

                case "5": { PinPad = "Ingenico eN1000"; break; }

                case "6": { PinPad = "Ingenico i6550"; break; }

                case "8": { PinPad = "Verifone MX"; break; }

                default: { break; }
                }
                string ReceiptPrinterType = RegisterIniFile.IniReadValue("DeviceType", "ReceiptPrinter");
                switch (ReceiptPrinterType)
                {
                case "0": { ReceiptPrinter = "None"; break; }

                case "1": { ReceiptPrinter = "Epson Impact"; break; }

                case "2": { ReceiptPrinter = "Star Thermal"; break; }

                case "3": { ReceiptPrinter = "Epson Thermal"; break; }

                default: { break; }
                }
            }

            if (File.Exists(StoreServerExe))
            {
                FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(StoreServerExe);
                StoreServerVer = myFileVersionInfo.FileVersion.ToString();

                Process [] pname = Process.GetProcessesByName("GameStop.Store.Server.Service.exe");
                if (pname.Length == 0)
                {
                    StoreServerStatus = false;
                }
                else
                {
                    StoreServerStatus = true;
                }
            }

            if (File.Exists(KioskExe))
            {
                FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(KioskExe);
                KioskVer = myFileVersionInfo.FileVersion.ToString();
                Terminal = ComputerName.Substring(ComputerName.Length - 3);
            }

            //Set variables using WIM query
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
                                                                                 "SELECT * FROM Win32_ComputerSystem");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    BootupState = queryObj["BootupState"].ToString();
                    //Manufacturer = queryObj["Manufacturer"].ToString();
                    Model               = queryObj["Model"].ToString();
                    Workgroup           = queryObj["Domain"].ToString();
                    TotalPhysicalMemory = Convert.ToInt32(queryObj["TotalPhysicalMemory"].ToString().Remove((queryObj["TotalPhysicalMemory"].ToString().Length) - 3, 3));
                    PhysicalMemory      = (Double)TotalPhysicalMemory / 1073741;
                    TotalPhysicalMemory = Convert.ToInt32(Math.Round(PhysicalMemory));
                }
            }
            catch { }

            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
                                                                                 "Select IPAddress from Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (queryObj["IPAddress"] != null)
                    {
                        String[] arrIPAddress = (String[])(queryObj["IPAddress"]);
                        Array.Sort(arrIPAddress);
                        foreach (String arrValue in arrIPAddress)
                        {
                            if (!arrValue.Contains(":"))
                            {
                                if (IPAddress == null)
                                {
                                    IPAddress = arrValue.ToString();
                                }
                                else
                                {
                                    IPAddress = IPAddress + ";" + arrValue.ToString();
                                }
                            }
                        }
                    }
                }
            }
            catch { }

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_BIOS");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    SerialNum = queryObj["SerialNumber"].ToString();
                    BIOSver   = queryObj["Name"].ToString();
                }
            }
            catch  { }

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_OperatingSystem");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    InstalledDate = ManagementDateTimeConverter.ToDateTime(queryObj["InstallDate"].ToString());
                }
            }
            catch { }

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_DiskDrive WHERE MediaType = 'Fixed hard disk media'");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    if (HDDModel == null)
                    {
                        HDDModel = queryObj["Model"].ToString();
                    }
                    else
                    {
                        HDDModel = HDDModel + ";" + queryObj["Model"].ToString();
                    }
                }
            }
            catch { }

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_Processor");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    ProcName = queryObj["Name"].ToString();
                }
            }
            catch { }

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                                                 "SELECT * FROM Win32_PhysicalMemory");

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    MemoryModuleCount = MemoryModuleCount + 1;
                    if (MemoryPart == null)
                    {
                        MemoryPart = queryObj["PartNumber"].ToString();
                    }

                    if (MemoryPart != queryObj["PartNumber"].ToString())
                    {
                        MemoryPart = MemoryPart + ";" + queryObj["PartNumber"].ToString();
                    }

                    if (MemorySpeed == null)
                    {
                        MemorySpeed = queryObj["Speed"].ToString();
                    }
                    if (MemorySpeed != queryObj["Speed"].ToString())
                    {
                        MemorySpeed = MemorySpeed + ";" + queryObj["Speed"].ToString();
                    }
                }
            }
            catch { }
        }
예제 #33
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ApplicationName.Expression != null)
            {
                targetCommand.AddParameter("ApplicationName", ApplicationName.Get(context));
            }

            if (BasePropertiesOnly.Expression != null)
            {
                targetCommand.AddParameter("BasePropertiesOnly", BasePropertiesOnly.Get(context));
            }

            if ((ComputerName.Expression != null) && (PSRemotingBehavior.Get(context) != RemotingBehavior.Custom))
            {
                targetCommand.AddParameter("ComputerName", ComputerName.Get(context));
            }

            if (ConnectionURI.Expression != null)
            {
                targetCommand.AddParameter("ConnectionURI", ConnectionURI.Get(context));
            }

            if (Dialect.Expression != null)
            {
                targetCommand.AddParameter("Dialect", Dialect.Get(context));
            }

            if (Enumerate.Expression != null)
            {
                targetCommand.AddParameter("Enumerate", Enumerate.Get(context));
            }

            if (Filter.Expression != null)
            {
                targetCommand.AddParameter("Filter", Filter.Get(context));
            }

            if (Fragment.Expression != null)
            {
                targetCommand.AddParameter("Fragment", Fragment.Get(context));
            }

            if (OptionSet.Expression != null)
            {
                targetCommand.AddParameter("OptionSet", OptionSet.Get(context));
            }

            if (Port.Expression != null)
            {
                targetCommand.AddParameter("Port", Port.Get(context));
            }

            if (Associations.Expression != null)
            {
                targetCommand.AddParameter("Associations", Associations.Get(context));
            }

            if (ResourceURI.Expression != null)
            {
                targetCommand.AddParameter("ResourceURI", ResourceURI.Get(context));
            }

            if (ReturnType.Expression != null)
            {
                targetCommand.AddParameter("ReturnType", ReturnType.Get(context));
            }

            if (SelectorSet.Expression != null)
            {
                targetCommand.AddParameter("SelectorSet", SelectorSet.Get(context));
            }

            if (SessionOption.Expression != null)
            {
                targetCommand.AddParameter("SessionOption", SessionOption.Get(context));
            }

            if (Shallow.Expression != null)
            {
                targetCommand.AddParameter("Shallow", Shallow.Get(context));
            }

            if (UseSSL.Expression != null)
            {
                targetCommand.AddParameter("UseSSL", UseSSL.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (Authentication.Expression != null)
            {
                targetCommand.AddParameter("Authentication", Authentication.Get(context));
            }

            if (CertificateThumbprint.Expression != null)
            {
                targetCommand.AddParameter("CertificateThumbprint", CertificateThumbprint.Get(context));
            }

            if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom))
            {
                targetCommand.AddParameter("ComputerName", PSComputerName.Get(context));
            }

            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
예제 #34
0
 /// <summary>
 /// Sets information about username and computer name
 /// </summary>
 private void SetBaseInfoValues()
 {
     UserName.SetText(Environment.UserName);
     ComputerName.SetText(Environment.MachineName);
 }
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ComputerName.Expression != null)
            {
                targetCommand.AddParameter("ComputerName", ComputerName.Get(context));
            }

            if (ApplicationName.Expression != null)
            {
                targetCommand.AddParameter("ApplicationName", ApplicationName.Get(context));
            }

            if (ConnectionUri.Expression != null)
            {
                targetCommand.AddParameter("ConnectionUri", ConnectionUri.Get(context));
            }

            if (ConfigurationName.Expression != null)
            {
                targetCommand.AddParameter("ConfigurationName", ConfigurationName.Get(context));
            }

            if (AllowRedirection.Expression != null)
            {
                targetCommand.AddParameter("AllowRedirection", AllowRedirection.Get(context));
            }

            if (Name.Expression != null)
            {
                targetCommand.AddParameter("Name", Name.Get(context));
            }

            if (InstanceId.Expression != null)
            {
                targetCommand.AddParameter("InstanceId", InstanceId.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (Authentication.Expression != null)
            {
                targetCommand.AddParameter("Authentication", Authentication.Get(context));
            }

            if (CertificateThumbprint.Expression != null)
            {
                targetCommand.AddParameter("CertificateThumbprint", CertificateThumbprint.Get(context));
            }

            if (Port.Expression != null)
            {
                targetCommand.AddParameter("Port", Port.Get(context));
            }

            if (UseSSL.Expression != null)
            {
                targetCommand.AddParameter("UseSSL", UseSSL.Get(context));
            }

            if (ThrottleLimit.Expression != null)
            {
                targetCommand.AddParameter("ThrottleLimit", ThrottleLimit.Get(context));
            }

            if (State.Expression != null)
            {
                targetCommand.AddParameter("State", State.Get(context));
            }

            if (SessionOption.Expression != null)
            {
                targetCommand.AddParameter("SessionOption", SessionOption.Get(context));
            }

            if (PSSessionId.Expression != null)
            {
                targetCommand.AddParameter("Id", PSSessionId.Get(context));
            }

            if (ContainerId.Expression != null)
            {
                targetCommand.AddParameter("ContainerId", ContainerId.Get(context));
            }

            if (VMId.Expression != null)
            {
                targetCommand.AddParameter("VMId", VMId.Get(context));
            }

            if (VMName.Expression != null)
            {
                targetCommand.AddParameter("VMName", VMName.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
        public void CopyTo( )
        {
            ICollection<ComputerName> collection = new RecentComputerList();
            collection.Add( new ComputerName( "cpu1", "alias1" ) );
            collection.Add( new ComputerName( "cpu2", "alias2" ) );

            ComputerName[] array = new ComputerName[3];
            array[0] = new ComputerName( "0.0.0.0", "zero" );
            collection.CopyTo( array, 1 );

            Assert2.AssertComputerNames( new string[]
            {
                "0.0.0.0", "zero",
                "cpu1", "alias1",
                "cpu2", "alias2",
            }, array );
        }
        public void Find( )
        {
            RecentComputerList computers = new RecentComputerList();
            ComputerName withAlias = new ComputerName( "1.1.1.1", "alias" );
            ComputerName justComputer = new ComputerName( "work", null );
            computers.Add( withAlias );
            computers.Add( justComputer );

            // Find by alias
            Assert.AreEqual( withAlias, computers.Find( "alias" ) );
            // Find by computer
            Assert.AreEqual( withAlias, computers.Find( "1.1.1.1" ) );
            // Find with no alias
            Assert.AreEqual( justComputer, computers.Find( "work" ) );
            // Find by alias, case insensitive
            Assert.AreEqual( withAlias, computers.Find( "ALIAS" ) );
            // Find by computer, case insensitive
            Assert.AreEqual( justComputer, computers.Find( "WORK" ) );
            // Not found
            Assert.IsNull( computers.Find( "foobar" ) );
        }
        public void ToStringTest( )
        {
            ComputerName withAlias = new ComputerName( "1.1.1.1", "alias" );
            Assert.AreEqual( "alias", withAlias.ToString() );

            ComputerName withoutAlias = new ComputerName( "work", null );
            Assert.AreEqual( "work", withoutAlias.ToString() );

            // Do we treat empty string as null?
            ComputerName emptyAlias = new ComputerName( "afar", "" );
            Assert.AreEqual( "afar", emptyAlias.ToString() );
        }
예제 #39
0
        protected override void ProcessRecord() //Add this Process function method
        {
            if (MinHostGroup < 1)
            {
                MinHostGroup = 1;
            }

            MaxThreads = Math.Min(ComputerName.Length, MaxThreads);

            if (MaxThreads == 1) // if only 1 host or 1 thread max call pinscanasync on main thread
            {
                for (int i = 0; i < ComputerName.Length; i += MinHostGroup)
                {
                    WriteVerbose("Starting Ping Scan...");
                    List <PingScanner.PingResponse> plist = PingScanner.PingScan.PingScanAsync(ComputerName.Skip(i).Take(MinHostGroup).ToArray(), Timeout, NoDNSLookup).Result;
                    WriteVerbose("Writing objects now...");
                    foreach (var item in plist)
                    {
                        WriteObject(item);
                    }
                }
                return;
            }

            WriteVerbose(string.Format("MaxThreads:    {0}", MaxThreads));
            WriteVerbose(string.Format("MinHostGroup:  {0}", MinHostGroup));

            Thread[] ta  = new Thread[MaxThreads];
            object[] pra = new object[MaxThreads];
            int[]    d   = new int[MaxThreads];

            for (int i = 0; i < MaxThreads; i++)
            {
                pra[i] = null;
            }

            for (int i = 0; i < MaxThreads; i++)
            {
                // Console.WriteLine("I:{0}",i);
                int j = i;
                ta[j] = new Thread(delegate()
                {
                    // Console.WriteLine("ComputerName[ComputerSegment*j]: {0}", ComputerName[ComputerSegment * j]);
                    // Console.WriteLine("ComputerSgment: {0}    j: {1}", ComputerSegment, j);
                    // Console.WriteLine(j);
                    pra[j] = PingScan.PingScanAsync(ComputerName.Skip(MinHostGroup * j).Take(MinHostGroup).ToArray(), Timeout, NoDNSLookup).Result;
                });
                ta[i].Start();
            }

            for (int i = 0; i < MaxThreads; i++)
            {
                // ta[i].Start();
            }
            for (int i = 0; i < MaxThreads; i++)
            {
                ta[i].Join();
            }

            for (int i = 0; i < MaxThreads; i++)
            {
                List <PingResponse> pr = (List <PingResponse>)pra[i];
                // Console.WriteLine(pr.ElementAt(0).Destination);
                for (int j = 0; j < pr.Count(); j++)
                {
                    WriteObject(pr.ElementAt(j));
                }
            }
        }