Beispiel #1
0
        public static IWebElement SearchInSorted(String name, IList <IWebElement> list)
        {
            int j = list.Count;
            int i = 0;

            if (StrComparer.Compare(name, list[i].Text) == -1 || StrComparer.Compare(name, list[j - 1].Text) == 1)
            {
                throw new Exception("Element not found!");
            }
            while (!list[i].Text.Equals(name))
            {
                if (StrComparer.Compare(name, list[(j + i) / 2].Text) <= 0)
                {
                    j = i + (j - i) / 2;
                }
                else
                {
                    i = i + (j - i) / 2 + 1;
                }
                if (i == j && !list[i].Text.Equals(name))
                {
                    throw new Exception("Element not found!");
                }
            }
            return(list[i]);
        }
Beispiel #2
0
        public void CompareIgnoreSpaceTest1()
        {
            // arraange
            var str1 = "  a ";
            var str2 = "   a";
            IComparer<string> c = new StrComparer();

            // act
            var res = c.Compare(str1, str2);

            //assert
            Assert.AreEqual(1, res, "Сравнение строк");
        }
Beispiel #3
0
        public void Setup()
        {
            var source = new Node
            {
                Name  = "Start",
                Edges = new List <Edge>()
            };

            var cityA = new Node
            {
                Name  = "A",
                Edges = new List <Edge>()
            };

            var cityB = new Node
            {
                Name  = "B",
                Edges = new List <Edge>()
            };

            var end = new Node
            {
                Name  = "End",
                Edges = new List <Edge>()
            };

            var sourceToA = new Edge
            {
                To       = cityA,
                Capacity = 5
            };

            var aToSource = new Edge
            {
                To       = source,
                Capacity = 5
            };

            sourceToA.BackEdge = aToSource;

            aToSource.BackEdge = sourceToA;

            var sourceToB = new Edge
            {
                To       = cityB,
                Capacity = 6
            };

            var bTosource = new Edge
            {
                To       = source,
                Capacity = 6
            };

            sourceToB.BackEdge = bTosource;

            bTosource.BackEdge = sourceToB;

            var AToB = new Edge
            {
                To       = cityB,
                Capacity = 3
            };

            var bToA = new Edge
            {
                To       = cityA,
                Capacity = 3
            };

            AToB.BackEdge = bToA;

            bToA.BackEdge = AToB;

            var AToEnd = new Edge
            {
                To       = end,
                Capacity = 4
            };

            var endToA = new Edge
            {
                To       = cityA,
                Capacity = 4
            };

            AToEnd.BackEdge = endToA;

            endToA.BackEdge = AToEnd;

            var BToEnd = new Edge
            {
                To       = end,
                Capacity = 5
            };

            var endToB = new Edge
            {
                To       = cityB,
                Capacity = 5
            };

            BToEnd.BackEdge = endToB;

            endToB.BackEdge = BToEnd;

            source.Edges.Add(sourceToA);

            source.Edges.Add(sourceToB);

            cityA.Edges.Add(AToB);

            cityA.Edges.Add(AToEnd);

            cityA.Edges.Add(aToSource);

            cityB.Edges.Add(BToEnd);

            cityB.Edges.Add(bToA);

            cityB.Edges.Add(bTosource);

            end.Edges.Add(endToA);

            end.Edges.Add(endToB);

            var comparer = new StrComparer();

            tree = new AVLTree <string, Node>(comparer);

            tree.Insert(source.Name, source);

            tree.Insert(cityA.Name, cityA);

            tree.Insert(cityB.Name, cityB);

            tree.Insert(end.Name, end);
        }
Beispiel #4
0
 public int Compare(IWebElement x, IWebElement y)
 {
     return(StrComparer.Compare(x.Text, y.Text));
 }
Beispiel #5
0
        public void Setup()
        {
            var cityS = new GraphNode
            {
                Name  = "S",
                Edges = new List <Edge>()
            };

            var cityB = new GraphNode
            {
                Name  = "B",
                Edges = new List <Edge>()
            };

            var cityA = new GraphNode
            {
                Name  = "A",
                Edges = new List <Edge>()
            };

            var T = new GraphNode
            {
                Name  = "T",
                Edges = new List <Edge>()
            };

            var sToA = new Edge
            {
                To       = cityA,
                Capacity = 5
            };

            var aToS = new Edge
            {
                To       = cityS,
                Capacity = 5
            };

            sToA.BackEdge = aToS;

            aToS.BackEdge = sToA;

            var sToB = new Edge
            {
                To       = cityB,
                Capacity = 6
            };

            var bToS = new Edge
            {
                To       = cityS,
                Capacity = 6
            };

            sToB.BackEdge = bToS;

            bToS.BackEdge = sToB;

            var AToB = new Edge
            {
                To       = cityB,
                Capacity = 3
            };

            var bToA = new Edge
            {
                To       = cityA,
                Capacity = 3
            };

            AToB.BackEdge = bToA;

            bToA.BackEdge = AToB;

            var ATot = new Edge
            {
                To       = T,
                Capacity = 4
            };

            var tToA = new Edge
            {
                To       = cityA,
                Capacity = 4
            };

            ATot.BackEdge = tToA;

            tToA.BackEdge = ATot;

            var BTot = new Edge
            {
                To       = T,
                Capacity = 5
            };

            var tToB = new Edge
            {
                To       = cityB,
                Capacity = 5
            };

            BTot.BackEdge = tToB;

            tToB.BackEdge = BTot;

            cityS.Edges.Add(sToA);

            cityS.Edges.Add(sToB);

            cityA.Edges.Add(AToB);

            cityA.Edges.Add(ATot);

            cityA.Edges.Add(aToS);

            cityB.Edges.Add(BTot);

            cityB.Edges.Add(bToA);

            cityB.Edges.Add(bToS);

            T.Edges.Add(tToA);

            T.Edges.Add(tToB);

            var comparer = new StrComparer();

            avlTree = new AVLTree <string, GraphNode>(comparer);

            avlTree.Insert(cityS.Name, cityS);

            avlTree.Insert(cityA.Name, cityA);

            avlTree.Insert(cityB.Name, cityB);

            avlTree.Insert(T.Name, T);
        }
Beispiel #6
0
        // 初期化
        static Env()
        {
            BootTime = DateTimeOffset.Now;

            NumCpus = Math.Max(Environment.ProcessorCount, 1);

            int debugChecker = 0;

            Debug.Assert((++debugChecker) >= 1);
            Env.IsCoresLibraryDebugBuild = (debugChecker >= 1);

            ExeAssembly = Assembly.GetExecutingAssembly();
            var asmName = ExeAssembly.GetName();

            ExeAssemblySimpleName = asmName.Name ?? throw new ArgumentNullException();
            ExeAssemblyFullName   = asmName.FullName;

            FrameworkVersion = Environment.Version;
            if (FrameworkInfoString.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase))
            {
                IsDotNetCore = true;
            }
            OsInfo    = Environment.OSVersion;
            IsWindows = (OsInfo.Platform == PlatformID.Win32NT);
            if (IsUnix)
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    IsLinux = true;
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    IsMac = true;
                }
            }

            PathSeparator = "" + Path.DirectorySeparatorChar;
            if (Str.IsEmptyStr(PathSeparator))
            {
                PathSeparator = "/";
                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    PathSeparator = "\\";
                }
            }
            PathSeparatorChar             = PathSeparator[0];
            AppRealProcessExeFileName     = IO.RemoveLastEnMark(GetAppRealProcessExeFileNameInternal());
            AppExecutableExeOrDllFileName = IO.RemoveLastEnMark(GetAppExeOrDllImageFilePathInternal());
            BuildConfigurationName        = GetBuildConfigurationNameInternal();

            // dotnet プロセスによって起動されたプロセスであるか否かを判別

            // .NET Core 2.2 以前は以下の方法で判別できる
            Env.IsHostedByDotNetProcess = Path.GetFileNameWithoutExtension(Env.AppRealProcessExeFileName).Equals("dotnet", StringComparison.OrdinalIgnoreCase);

            if (Env.IsHostedByDotNetProcess)
            {
                Env.DotNetHostProcessExeName = Process.GetCurrentProcess().MainModule.FileName;
            }
            else
            {
                // .NET Core 3.0 以降はスタンドアロンプロセスモードでも起動できるようになった
                // この場合は、
                // 1. DOTNET_ROOT 環境変数にディレクトリ名が入っていること
                // 2. DOTNET_ROOT 環境変数 + "\dotnet" というファイル (dotnet の実行可能ファイルである) が存在すること
                // で判定を行なう
                // (TODO: Windows ではこの方法で判別ができない)

                if (IsUnix)
                {
                    string?dotNetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT");

                    if (dotNetRoot._IsFilled())
                    {
                        if (Directory.Exists(dotNetRoot))
                        {
                            string dotnetExeName = Path.Combine(dotNetRoot, "dotnet");

                            if (File.Exists(dotnetExeName))
                            {
                                // 判定成功
                                Env.IsHostedByDotNetProcess  = true;
                                Env.DotNetHostProcessExeName = dotnetExeName;
                            }
                        }
                    }
                }
            }

            // DNS ホスト名とドメイン名の取得
            PalHostNetInfo.GetHostNameAndDomainNameInfo(out string dnsHostName, out string dnsDomainName);

            DnsHostName     = dnsHostName;
            DnsDomainName   = dnsDomainName;
            DnsFqdnHostName = DnsHostName + (string.IsNullOrEmpty(DnsDomainName) ? "" : "." + DnsDomainName);

            if (Str.IsEmptyStr(AppExecutableExeOrDllFileName) == false)
            {
                AppRootDir = AppExecutableExeOrDllFileDir = IO.RemoveLastEnMark(System.AppContext.BaseDirectory);
                // プログラムのあるディレクトリから 1 つずつ遡ってアプリケーションの root ディレクトリを取得する
                string tmp = AppExecutableExeOrDllFileDir;

                string tmp2 = AppExecutableExeOrDllFileDir._ReplaceStr("\\", "/");
                if (tmp2._InStr("/tmp/.net/", true) || tmp2._InStr("/temp/.net/", true))
                {
                    // dotnet publish で -p:PublishSingleFile=true で生成されたファイルである。
                    // この場合、AppExecutableExeOrDllFileDir は一時ディレクトリを指しているので、
                    // AppRootDir は代わりに EXE ファイルのある本物のディレクトリを指すようにする。
                    AppRootDir = tmp = Path.GetDirectoryName(AppRealProcessExeFileName) ?? AppRootDir;
                }

                IEnumerable <string> markerFiles = Env.IsHostedByDotNetProcess ? Consts.FileNames.AppRootMarkerFileNames : Consts.FileNames.AppRootMarkerFileNamesForBinary;

                while (true)
                {
                    try
                    {
                        bool found = false;

                        var filenames = Directory.GetFiles(tmp).Select(x => Path.GetFileName(x));

                        foreach (string fn in Consts.FileNames.AppRootMarkerFileNames)
                        {
                            if (filenames.Where(x => (IgnoreCaseTrim)x == fn).Any())
                            {
                                found = true;
                                break;
                            }

                            if (fn.StartsWith("."))
                            {
                                if (filenames.Where(x => x.EndsWith(fn, StringComparison.OrdinalIgnoreCase)).Any())
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }

                        if (found)
                        {
                            AppRootDir = tmp;
                            break;
                        }
                        tmp = Path.GetDirectoryName(tmp) !;
                    }
                    catch
                    {
                        break;
                    }
                }
            }
            else
            {
                AppExecutableExeOrDllFileName = "/tmp/dummyexe";
                AppExecutableExeOrDllFileDir  = "/tmp";
                AppRootDir = IO.RemoveLastEnMark(Environment.CurrentDirectory);
            }

            HomeDir = IO.RemoveLastEnMark(Kernel.GetEnvStr("HOME"));
            if (Str.IsEmptyStr(HomeDir))
            {
                HomeDir = IO.RemoveLastEnMark(Kernel.GetEnvStr("HOMEDRIVE") + Kernel.GetEnvStr("HOMEPATH"));
            }
            if (Str.IsEmptyStr(HomeDir) == false)
            {
                UnixMutantDir = Path.Combine(HomeDir, ".dotnet_temp/.Cores.NET.Mutex");
            }
            else
            {
                HomeDir = AppRootDir;
                if (IsUnix)
                {
                    UnixMutantDir = Path.Combine("/tmp", ".dotnet_temp/.Cores.NET.Mutex");
                }
            }
            if (IsWindows)
            {
                UnixMutantDir = "";
            }
            if (Str.IsEmptyStr(UnixMutantDir) == false)
            {
                IO.MakeDirIfNotExists(UnixMutantDir);
            }
            if (IsWindows)
            {
                // Windows
                Win32_SystemDir  = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.System));
                Win32_WindowsDir = IO.RemoveLastEnMark(Path.GetDirectoryName(Win32_SystemDir) !);
                TempDir          = IO.RemoveLastEnMark(Path.GetTempPath());
                Win32_WinTempDir = IO.RemoveLastEnMark(Path.Combine(Win32_WindowsDir, "Temp"));
                IO.MakeDir(Win32_WinTempDir);
                if (Win32_WindowsDir.Length >= 2 && Win32_WindowsDir[1] == ':')
                {
                    Win32_WindowsDir = Win32_WindowsDir.Substring(0, 2).ToUpper();
                }
                else
                {
                    Win32_WindowsDrive = "C:";
                }
            }
            else
            {
                // UNIX
                Win32_SystemDir    = "/bin";
                Win32_WindowsDir   = "/bin";
                Win32_WindowsDrive = "/";
                if (Str.IsEmptyStr(HomeDir) == false)
                {
                    TempDir = Path.Combine(HomeDir, ".dotnet_temp/.Cores.NET.PerProcess.Temp");
                }
                else
                {
                    TempDir = "/tmp";
                }
                Win32_WinTempDir = TempDir;
            }
            FilePathStringComparer     = StrComparer.Get(!Env.IgnoreCaseInFileSystem);
            Win32_ProgramFilesDir      = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
            Win32_PersonalStartMenuDir = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu));
            Win32_PersonalProgramsDir  = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
            Win32_PersonalStartupDir   = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.Startup));
            Win32_PersonalAppDataDir   = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
            Win32_PersonalDesktopDir   = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
            Win32_MyDocumentsDir       = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            Win32_LocalAppDataDir      = IO.RemoveLastEnMark(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
            if (IsUnix)
            {
                // ダミーディレクトリ
                Win32_SystemDir            = "/bin";
                Win32_WindowsDir           = "/bin";
                Win32_WindowsDrive         = "/";
                Win32_ProgramFilesDir      = "/bin";
                Win32_PersonalStartMenuDir = Path.Combine(HomeDir, "dummy/starmenu");
                Win32_PersonalProgramsDir  = Path.Combine(HomeDir, "dummy/starmenu/programs");
                Win32_PersonalStartupDir   = Path.Combine(HomeDir, "dummy/starmenu/startup");
                Win32_LocalAppDataDir      = Win32_PersonalAppDataDir = Path.Combine(HomeDir, ".dnappdata");
                Win32_PersonalDesktopDir   = Path.Combine(HomeDir, "dummy/desktop");
                Win32_MyDocumentsDir       = HomeDir;
            }
            StartupCurrentDir = CurrentDir;
            UserName          = Environment.UserName;
            try
            {
                UserNameEx = Environment.UserDomainName + "\\" + UserName;
            }
            catch
            {
                UserNameEx = UserName;
            }
            MachineName = Environment.MachineName;

            CommandLine = initCommandLine(Environment.CommandLine);

            IsLittleEndian = BitConverter.IsLittleEndian;
            ProcessId      = System.Diagnostics.Process.GetCurrentProcess().Id;
            IsAdmin        = CheckIsAdmin();

            if (IsUnix)
            {
                MutantUnixImpl.DeleteUnusedMutantFiles();
            }
        }