Esempio n. 1
0
 /// <summary>
 ///     Broadcast an shape against an other new shape.
 /// </summary>
 /// <param name="from">The shape that is to be broadcasted</param>
 /// <param name="against">The shape that'll be used to broadcast <paramref name="from"/> shape</param>
 /// <returns>A readonly view on the original array with the given shape. It is typically not contiguous. Furthermore, more than one element of a broadcasted array may refer to a single memory location.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_to.html</remarks>
 public static Shape broadcast_to(Shape from, NDArray against)
 {
     return(DefaultEngine.Broadcast(from, against.Shape).LeftShape);
 }
Esempio n. 2
0
        private void DoNewGame(string fen, GameMode gameMode, GameType gameType, OptionsBlitzClock blitzClock, OptionsLongClock longClock)
        {
            NewGameEventArgs args = new NewGameEventArgs();

            if (BeforeNewGame != null)
            {
                BeforeNewGame(this, args);
            }

            if (args.Cancel)
            {
                return;
            }

            if (SaveDocking != null)
            {
                SaveDocking(this, EventArgs.Empty);
            }

            GameStartTimeLocal = DateTime.Now;

            Ap.Options.CurrentGameGuid = string.Empty;
            Stop();

            InitialBoardFen = fen;

            PreviousGameMode   = GameMode;
            PreviousPonderMove = string.Empty;
            GameMode           = gameMode;
            GameType           = gameType;

            #region Init
            //GameValidator = new GameW(this.InitialBoardFen);
            GameValidator.SetFen(this.InitialBoardFen);

            SpaceBarCounter = 0;

            CloseEngines();

            if (GameType == GameType.Long)
            {
                GameTime.Init(longClock, true);
            }
            else
            {
                GameTime.Init(blitzClock, true);
            }

            if (Flags.IsBookLoadRequired)
            {
                Book.Load(null);
            }

            GameResult = GameResultE.InProgress;
            Reset();

            if (DbGame != null && DbGame.IsFinished)
            {
                this.GameResult = DbGame.GameResultIDE;
                this.Flags.SetFlags(DbGame.GameFlags);
            }

            CurrentMove = RootMove.Clone();
            Moves.Clear();
            CurrentLine = null;
            #endregion

            #region Switch GameMode
            switch (GameMode)
            {
            case GameMode.None:
                break;

            case GameMode.HumanVsHuman:
                #region HumanVsHuman
                GameTime.TimeMin     = 0;
                GameTime.GainPerMove = 0;

                Player1.Engine = null;
                Player2.Engine = null;

                Player2.Book = Book;

                Player1.PlayerTitle = Ap.UserProfile.LastName;
                Player2.PlayerTitle = "InfinityChess";

                GameData.SetPlayers(Player1.PlayerTitle, Ap.UserProfile.FirstName, Player2.PlayerTitle, "");
                gameTypeTitle = Ap.GetGameTypeTitle(GameType);
                #endregion
                break;

            case GameMode.HumanVsEngine:
                #region HumanVsEngine
                Player2EngineFileName = InfinitySettings.Settings.DefaultEngineXml.FilePath;
                Player1.Engine        = null;
                if (DefaultEngine == null)
                {
                    Player2.Engine = UCIEngine.Load(Player2EngineFileName, Options.DefaultHashTableSize, this);
                    Player2.Engine.UseTablebases = Ap.EngineOptions.UseTablebases;

                    DefaultEngine = Player2.Engine;
                }
                else
                {
                    Player2.Engine = DefaultEngine;
                }

                Player2.Book = Book;

                DefaultBook = Player2.Book;

                Player1.PlayerTitle = Ap.UserProfile.LastName;
                Player2.PlayerTitle = Player2.Engine.EngineName;

                GameData.SetPlayers(Player1.PlayerTitle, Ap.UserProfile.FirstName, Player2.PlayerTitle, "");
                gameTypeTitle = Ap.GetGameTypeTitle(GameType);
                #endregion
                break;

            case GameMode.EngineVsEngine:
                #region EngineVsEngine
                Player1.Engine = UCIEngine.Load(Player1EngineFileName, Player1EngineHashTableSize, this);
                Player1.Engine.UseTablebases = Ap.EngineOptions.UseTablebases;

                Player2.Engine = UCIEngine.Load(Player2EngineFileName, Player2EngineHashTableSize, this);
                Player2.Engine.UseTablebases = Ap.EngineOptions.UseTablebases;

                Player1.PlayerTitle = Player1.Engine.EngineName;
                Player2.PlayerTitle = Player2.Engine.EngineName;

                if (Player1.Book != null)
                {
                    Player1.Book.NewGame();
                }
                if (Player2.Book != null)
                {
                    Player2.Book.NewGame();
                }

                GameData.SetPlayers(Player1.PlayerTitle, "", Player2.PlayerTitle, "");
                gameTypeTitle = Ap.GetGameTypeTitle(GameType);

                InitE2eResult();
                #endregion
                break;

            case GameMode.OnlineHumanVsHuman:
                #region OnlineHumanVsHuman
                StartOnlineH2HGame();
                #endregion
                break;

            case GameMode.OnlineHumanVsEngine:
                #region OnlineHumanVsEngine
                gameTypeTitle = Ap.GetGameTypeTitle(GameType);
                #endregion
                break;

            case GameMode.OnlineEngineVsEngine:
                #region OnlineEngineVsEngine
                if (Ap.PlayingMode.SelectedEngine == null)
                {
                    StartOnlineH2HGame();
                }
                else
                {
                    StartOnlineE2EGame();
                }
                #endregion
                break;

            case GameMode.Kibitzer:
                #region Kibitzer
                GameTime.Set(DbGame);
                GameResult = DbGame.GameResultIDE;

                Player1.PlayerTitle = DbGame.WhiteUser.UserName + " " + DbGame.WhiteUser.Engine.Name;
                Player2.PlayerTitle = DbGame.BlackUser.UserName + " " + DbGame.BlackUser.Engine.Name;

                if (DbGame.IsRated)
                {
                    gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "' + " + DbGame.GainPerMoveMin.ToString() + "'', " + "Rated";

                    if (DbGame.EloBlackBefore != 0 && !DbGame.BlackUser.IsGuest)
                    {
                        Player2.PlayerTitle += " " + DbGame.EloBlackBefore.ToString();
                    }

                    if (DbGame.EloWhiteBefore != 0 && !DbGame.WhiteUser.IsGuest)
                    {
                        Player1.PlayerTitle += " " + DbGame.EloWhiteBefore.ToString();
                    }
                }
                else
                {
                    gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "' + " + DbGame.GainPerMoveMin.ToString() + "'', " + "Unrated";
                }

                GameData.SetPlayers(Player1.PlayerTitle, "", Player2.PlayerTitle, "");

                #endregion
                break;

            default:
                break;
            }
            #endregion

            if (DefaultEngine != null)
            {
                if (DefaultEngine.IsClosed)
                {
                    DefaultEngine.Load();
                }
            }

            Flags.IsEngineBlack = true;

            #region Start

            Clock.NewGame();
            Notations.NewGame();

            if (Flags.IsBookLoadRequired)
            {
                Book.NewGame();
            }

            CapturedPieces.NewGame();
            GameData.NewGame();

            Clipboard.Reset();

            GameData.Tournament = GameTypeTitle;

            Ap.Options.GameType = gameType;
            Ap.Options.Save();

            #endregion

            if (CreateDocking != null)
            {
                CreateDocking(this, EventArgs.Empty);
            }

            Flags.IsInfiniteAnalysisOn = false;
            MediaPlayer.PlaySound(SoundFileNameE.SetPieces);
            SetFen(fen);

            Flags.IsBoardSetByFen = fen != ChessLibrary.FenParser.InitialBoardFen;

            if (Flags.IsOnline && DbGame != null)
            {
                Flags.IsChallengerSendsGame = DbGame.IsChallengerSendsGame;
            }

            SetSuddenDeathMatchTime();

            if (AfterNewGame != null)
            {
                AfterNewGame(this, EventArgs.Empty);
            }
        }
Esempio n. 3
0
        private static void StartDefault()
        {
            if (CertificateUtil.FindRootCertificate() == default)
            {
                CertificateUtil.InstallNewRootCertificate();
            }
            //CertificateUtil.UninstallRootCertificates();
            //CertificateUtil.UninstallAllServerCertificatesByIssuer();
            //var ca = CertificateUtil.FindRootCertificate();
            //CertificateUtil.UninstallFromRootStore(ca);

            var engine = DefaultEngine.Create(new ListeningConfig(8080));

            engine.DecryptConfig.IsDecrypt = true;
            //engine.DecryptConfig.HostFilterHandler = host
            //    => host.EndsWith("cat-ears.net");
            // engine.DecryptConfig.RootCertificateResolver = store => store.FindRootCertificate("Titanium Root Certificate Authority");
            engine.DecryptConfig.CacheLocations
                = new[] {   // 定義順が読み取り優先順
                CertificateCacheLocation.Memory,
                CertificateCacheLocation.Custom,
                CertificateCacheLocation.Store,
                };
            engine.DecryptConfig.ServerCertificateCacheResolver = host =>
            {
                Console.WriteLine($"### ServerCertificateCacheResolver: {host}");
                return(null);
                //var path = host.Replace("*", "$x$") + ".pfx";
                //if (!File.Exists(path)) return null;
                //var bytes = File.ReadAllBytes(path);
                //return new X509Certificate2(bytes);
            };
            engine.ServerCertificateCreated += (_, c) =>
            {
                Console.WriteLine($"### ServerCertificateCreated: {c.Certificate.Subject}");
                //var path = c.Certificate.Subject.Replace("CN=", "").Replace("*", "$x$") + ".pfx";
                //if (!File.Exists(path))
                //    File.WriteAllBytes(path, c.Certificate.RawData);
            };

            engine.UpstreamProxyConfig = null;
            engine.ConnectionAdded    += (_, c) => Console.WriteLine($"### Connection Added. Connections Count: {c.Count}");
            engine.ConnectionRemoved  += (_, c) => Console.WriteLine($"### Connection Removed. Connections Count: {c.Count}");


            var proxy = HttpProxyFactory.Create(engine);

            proxy.FatalException   += (_, e) => Console.WriteLine(e.Exception);
            proxy.HttpResponseSent += (_, s) =>
            {
                if (IsOutputHeaders(s.Session))
                {
                    Console.WriteLine($"{s.Session.GetHost()}: {s.Session.Request}\r\n" +
                                      $"{s.Session.Response.StatusLine }{s.Session.Response.Headers}");
                }
                else if (s.Session.Request.RequestLine.Method.Method != "CONNECT")
                {
                    Console.WriteLine($"{s.Session.GetHost()}: {s.Session.Request.RequestLine}" +
                                      $"{s.Session.Response.StatusLine}");
                }
            };
            proxy.ClientWebSocketMessageSent += (_, m) =>
            {
                var host = m.Message.HandshakeSession.GetHost();
                if (m.Message.Opcode == WebSocketOpcode.Text)
                {
                    Console.WriteLine(
                        $@"ClientWebSocketMessage: {host}
Text: {Encoding.UTF8.GetString(m.Message.PayloadData.ToArray())}");
                }
                else
                {
                    //                    Console.WriteLine(
                    //$@"ClientWebSocketMessage: {host}
                    //{m.Message.Opcode}: {m.Message.PayloadData.Count} bytes.");
                }
            };
            proxy.ServerWebSocketMessageSent += (_, m) =>
            {
                var host = m.Message.HandshakeSession.GetHost();
                if (m.Message.Opcode == WebSocketOpcode.Text)
                {
                    Console.WriteLine(
                        $@"ServerWebSocketMessage: {host}
Text: {Encoding.UTF8.GetString(m.Message.PayloadData.ToArray())}");
                }
                else
                {
                    //                    Console.WriteLine(
                    //$@"ServerWebSocketMessage: {host}
                    //{m.Message.Opcode}: {m.Message.PayloadData.Count} bytes.");
                }
            };

            try
            {
                proxy.Start();
                while (true)
                {
                    Task.Delay(1000).Wait();
                }
            }
            finally
            {
                proxy.Stop();
            }
        }
 public SiteBuilderTests(DefaultEngine engine)
 {
     Fixture = new DefaultFixture(engine);
 }
Esempio n. 5
0
 /// <summary>
 ///     Produce an object that mimics broadcasting.
 /// </summary>
 /// <returns>Broadcast the input parameters against one another, and return an object that encapsulates the result. Amongst others, it has shape and nd properties, and may be used as an iterator.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast.html</remarks>
 public static Broadcast broadcast(NDArray nd1, NDArray nd2)
 {
     return(new Broadcast {
         shape = DefaultEngine.ResolveReturnShape(nd1.Shape, nd2.Shape)
     });
 }
 public ContentBuilderTests(DefaultEngine engine)
 {
     Fixture   = new DefaultFixture(engine);
     Resources = new DefaultResources();
 }
Esempio n. 7
0
 /// <summary>
 ///     Produce an object that mimics broadcasting.
 /// </summary>
 /// <returns>Broadcast the input parameters against one another, and return an object that encapsulates the result. Amongst others, it has shape and nd properties, and may be used as an iterator.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast.html</remarks>
 public static Broadcast broadcast(NDArray nd1, NDArray nd2)
 {
     return(new Broadcast {
         shape = DefaultEngine.ResolveReturnShape(nd1.Shape, nd2.Shape), iters = new[] { nd1.AsIterator(), nd2.AsIterator() }
     });
 }
Esempio n. 8
0
        public void NewGame(string fen, GameMode gameMode, GameType gameType, OptionsBlitzClock blitzClock, OptionsLongClock longClock)
        {
            Stop();

            InitialBoardFen = fen;
            GameMode        = gameMode;
            GameType        = gameType;

            if (BeforeNewGame != null)
            {
                BeforeNewGame(this, EventArgs.Empty);
            }

            #region Init
            GameValidator = new GameW(this.InitialBoardFen);

            SpaceBarCounter = 0;

            CloseEngines();

            if (GameType == GameType.LongGame)
            {
                GameTime.Init(longClock, true);
            }
            else
            {
                GameTime.Init(blitzClock, true);
            }

            GameResult  = GameResultE.InProgress;
            CurrentMove = null;

            Flags.Reset();
            #endregion

            #region Switch gameMode
            switch (GameMode)
            {
            case GameMode.None:
                break;

            case GameMode.HumanVsHuman:
                Player1.PlayerType = PlayerType.Human;
                Player2.PlayerType = PlayerType.Human;

                Player1.Engine = null;
                Player2.Engine = null;

                Player1.PlayerTitle = GameData.WhiteTitle;
                Player2.PlayerTitle = GameData.BlackTitle;
                break;

            case GameMode.HumanVsEngine:
                Player1.PlayerType    = PlayerType.Human;
                Player2.PlayerType    = PlayerType.Engine;
                Player2EngineFileName = InfinitySettings.Settings.DefaultEngineXml.FilePath;
                Player1.Engine        = null;
                if (DefaultEngine == null)
                {
                    Player2.Engine = UCIEngine.Load(Player2EngineFileName, Options.DefaultHashTableSize);
                    Player2.Engine.UseTablebases = EngineParameters.UseTablebases;

                    DefaultEngine = Player2.Engine;
                }
                else
                {
                    Player2.Engine = DefaultEngine;
                }

                Player2.Book = Book;
                DefaultBook  = Player2.Book;

                Player1.PlayerTitle = Ap.UserProfile.LastName;
                Player2.PlayerTitle = Player2.Engine.EngineName;

                break;

            case GameMode.EngineVsEngine:
                Player1.PlayerType = PlayerType.Engine;
                Player2.PlayerType = PlayerType.Engine;

                Player1.Engine = UCIEngine.Load(Player1EngineFileName, Player1EngineHashTableSize);
                Player1.Engine.UseTablebases = EngineParameters.UseTablebases;

                Player2.Engine = UCIEngine.Load(Player2EngineFileName, Player2EngineHashTableSize);
                Player2.Engine.UseTablebases = EngineParameters.UseTablebases;

                Player1.PlayerTitle = Player1.Engine.EngineName;
                Player2.PlayerTitle = Player2.Engine.EngineName;

                break;

            case GameMode.OnlineHumanVsHuman:
                #region OnlineHumanVsHuman
                StartOnlineH2HGame();
                #endregion
                break;

            case GameMode.OnlineHumanVsEngine:
                break;

            case GameMode.OnlineEngineVsEngine:

                if (PlayingMode.SelectedEngine == null)
                {
                    StartOnlineH2HGame();
                }
                else
                {
                    StartOnlineE2EGame();
                }

                break;

            case GameMode.Kibitzer:
                #region Kibitzer
                GameTime.Set(DbGame);
                GameResult = DbGame.GameResultIDE;     //GameResultE.InProgress;

                Player1.PlayerType  = PlayerType.Human;
                Player1.PlayerTitle = DbGame.WhiteUser.UserName;
                Player2.PlayerType  = PlayerType.Human;
                Player2.PlayerTitle = DbGame.BlackUser.UserName;

                if (DbGame.IsRated)
                {
                    gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "m + " + DbGame.GainPerMoveMin.ToString() + "s, " + "Rated";

                    if (DbGame.EloBlackBefore != 0 && !DbGame.BlackUser.IsGuest)
                    {
                        Player2.PlayerTitle += " " + DbGame.EloBlackBefore.ToString();
                    }

                    if (DbGame.EloWhiteBefore != 0 && !DbGame.WhiteUser.IsGuest)
                    {
                        Player1.PlayerTitle += " " + DbGame.EloWhiteBefore.ToString();
                    }
                }
                else
                {
                    gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "m + " + DbGame.GainPerMoveMin.ToString() + "s, " + "Unrated";
                }
                #endregion
                break;

            default:
                break;
            }
            #endregion

            if (DefaultEngine != null)
            {
                if (DefaultEngine.IsClosed)
                {
                    DefaultEngine.Load();
                }
            }

            Flags.IsEngineBlack = true;

            #region Start

            gameTypeTitle = Ap.GetGameTypeTitle(GameType);

            Player1.Active = true;
            Player2.Active = false;

            Notations.SetupNewGame();
            CapturedPieces.SetupNewGame();
            Clock.SetupNewGame();
            Book.SetupNewGame();

            Clipboard.Reset();

            CurrentPlayer = Player1;

            GameData.SetupNewGame();


            if (Flags.IsChangeNamesAllowed)
            {
                GameData.White1 = Player1.PlayerTitle;
                GameData.White2 = Ap.UserProfile.FirstName;
                GameData.Black1 = Player2.PlayerTitle;
            }
            GameData.Tournament = GameTypeTitle;

            InitTablebases();

            Ap.Options.GameType = gameType;
            Ap.Options.Save();


            #endregion

            if (CreateDocking != null)
            {
                CreateDocking(this, EventArgs.Empty);
            }

            Flags.IsInfiniteAnalysisOn = false;
            SetFen(fen);

            if (Flags.IsOnline)
            {
                // Flags.IsChallengerSendsGame = Flags.IsPositionSetupAllowed;
            }

            if (AfterNewGame != null)
            {
                AfterNewGame(this, EventArgs.Empty);
            }
        }
        public void basics_broadcasting()
        {
            (Shape LeftShape, Shape RightShape)ret;

            ret = DefaultEngine.Broadcast(new Shape(5, 5), Shape.Scalar);
            ret.LeftShape.dimensions.Should().ContainInOrder(5, 5);
            ret.RightShape.dimensions.Should().ContainInOrder(5, 5);
            ret.RightShape.strides.Should().AllBeEquivalentTo(0);
            indexes2(5, 5).Select(i => ret.RightShape.GetOffset(i.i1, i.i2)).Should().AllBeEquivalentTo(0);
            indexes2(5, 5).Select(i => ret.LeftShape.GetOffset(i.i1, i.i2))
            .Should().BeInAscendingOrder().And.Subject.First().Should().Be(0);

            ret = DefaultEngine.Broadcast(Shape.Scalar, new Shape(5, 5));
            ret.LeftShape.dimensions.Should().ContainInOrder(5, 5);
            ret.RightShape.dimensions.Should().ContainInOrder(5, 5);
            ret.LeftShape.strides.Should().AllBeEquivalentTo(0);
            indexes2(5, 5).Select(i => ret.LeftShape.GetOffset(i.i1, i.i2)).Should().AllBeEquivalentTo(0);
            indexes2(5, 5).Select(i => ret.RightShape.GetOffset(i.i1, i.i2))
            .Should().BeInAscendingOrder().And.Subject.First().Should().Be(0);

            ret = DefaultEngine.Broadcast(new Shape(5, 5), new Shape(5, 5));
            ret.LeftShape.dimensions.Should().ContainInOrder(5, 5);
            ret.RightShape.dimensions.Should().ContainInOrder(5, 5);
            ret.LeftShape.strides.Should().ContainInOrder(5, 1);
            ret.RightShape.strides.Should().ContainInOrder(5, 1);

            ret = DefaultEngine.Broadcast(new Shape(5, 5, 3), new Shape(5, 3));
            ret.LeftShape.dimensions.Should().ContainInOrder(5, 5, 3);
            ret.RightShape.dimensions.Should().ContainInOrder(5, 5, 3);

            ret = DefaultEngine.Broadcast(new Shape(256, 256, 3), new Shape(3));
            ret.LeftShape.dimensions.Should().ContainInOrder(256, 256, 3);
            ret.RightShape.dimensions.Should().ContainInOrder(256, 256, 3);

            ret = DefaultEngine.Broadcast(new Shape(8, 1, 6, 1), new Shape(7, 1, 5));
            ret.LeftShape.dimensions.Should().ContainInOrder(8, 7, 6, 5);
            ret.RightShape.dimensions.Should().ContainInOrder(8, 7, 6, 5);

            ret = DefaultEngine.Broadcast(new Shape(5, 4), new Shape(1));
            ret.LeftShape.dimensions.Should().ContainInOrder(5, 4);
            ret.RightShape.dimensions.Should().ContainInOrder(5, 4);
            indexes2(5, 4).Select(i => ret.LeftShape.GetOffset(i.i1, i.i2))
            .Should().BeInAscendingOrder().And.Subject.First().Should().Be(0);
            indexes2(5, 4).Select(i => ret.RightShape.GetOffset(i.i1, i.i2)).Should().AllBeEquivalentTo(0);


            ret = DefaultEngine.Broadcast(new Shape(5, 4), new Shape(4));
            ret.LeftShape.dimensions.Should().ContainInOrder(5, 4);
            ret.RightShape.dimensions.Should().ContainInOrder(5, 4);

            ret = DefaultEngine.Broadcast(new Shape(15, 3, 5), new Shape(15, 1, 5));
            ret.LeftShape.dimensions.Should().ContainInOrder(15, 3, 5);
            ret.RightShape.dimensions.Should().ContainInOrder(15, 3, 5);

            ret = DefaultEngine.Broadcast(new Shape(15, 3, 5), new Shape(3, 1));
            ret.LeftShape.dimensions.Should().ContainInOrder(15, 3, 5);
            ret.RightShape.dimensions.Should().ContainInOrder(15, 3, 5);

            new Action(() => DefaultEngine.ResolveReturnShape(new Shape(3), new Shape(4))).Should().Throw <Exception>();
            new Action(() => DefaultEngine.ResolveReturnShape(new Shape(2, 1), new Shape(8, 4, 3))).Should().Throw <Exception>();
        }
Esempio n. 10
0
 public FixtureNestedContextTests(DefaultEngine engine)
 {
     Fixture = new DefaultFixture(engine);
 }
Esempio n. 11
0
        public void ChangeUpstreamProxyTest()
        {
            var server     = new TestTcpServer();
            var engine     = new DefaultEngine(server);
            var clientTcp1 = new TestTcpClient();

            server.AcceptTcp(clientTcp1);
            var connection1 = engine.connections.Last();

            connection1.CreateTcpClientForServer = (host, port) => new TestTcpClient(host, port);

            engine.UpstreamProxyConfig = new UpstreamProxyConfig("first.example.com", 1);

            var tcsRequest1_1 = new TaskCompletionSource <IReadOnlyHttpRequest>();

            connection1.HttpRequestSent += r => tcsRequest1_1.TrySetResult(r);

            var request =
                @"GET / HTTP/1.1
Host: hoge.example.com

";

            clientTcp1.WriteToInput(request);

            var request1_1 = tcsRequest1_1.GetResult();

            var serverTcp1 = connection1.serverConnection.client.AsTest();

            serverTcp1.Host.Is("first.example.com");
            serverTcp1.Port.Is(1);

            // UpstreamProxyConfig 変更
            engine.UpstreamProxyConfig = new UpstreamProxyConfig("second.example.com", 2);

            var tcsRequest1_2 = new TaskCompletionSource <IReadOnlyHttpRequest>();

            connection1.HttpRequestSent += r => tcsRequest1_2.TrySetResult(r);
            clientTcp1.WriteToInput(request);
            // 接続中のコネクションには反映されない
            var request1_2 = tcsRequest1_2.GetResult();

            serverTcp1.Host.Is("first.example.com");
            serverTcp1.Port.Is(1);

            // 次の接続から反映される
            var clientTcp2 = new TestTcpClient();

            server.AcceptTcp(clientTcp2);
            var connection2 = engine.connections.Last();

            connection2.CreateTcpClientForServer = (host, port) => new TestTcpClient(host, port);

            connection2.HttpRequestSent += r => tcsRequest1_1.TrySetResult(r);

            var tcsRequest2 = new TaskCompletionSource <IReadOnlyHttpRequest>();

            connection2.HttpRequestSent += r => tcsRequest2.TrySetResult(r);
            clientTcp2.WriteToInput(request);
            var request2   = tcsRequest2.GetResult();
            var serverTcp2 = connection2.serverConnection.client.AsTest();

            serverTcp2.Host.Is("second.example.com");
            serverTcp2.Port.Is(2);

            (engine as IReadOnlyHttpProxyEngine).Stop();
        }
Esempio n. 12
0
 /// <summary>
 ///     Tests if these two two arrays are broadcastable against each other.
 /// </summary>
 /// <param name="lhs">An array to test for broadcasting.</param>
 /// <param name="rhs">An array to test for broadcasting.</param>
 /// <returns>True if these can be broadcasted against each other.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_arrays.html</remarks>
 public static bool are_broadcastable(NDArray lhs, NDArray rhs)
 {
     return(DefaultEngine.AreBroadcastable(lhs, rhs));
 }
Esempio n. 13
0
 /// <summary>
 ///     Tests if these two two arrays are broadcastable against each other.
 /// </summary>
 /// <param name="shapes">The shapes to test for broadcasting.</param>
 /// <returns>True if these can be broadcasted against each other.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_arrays.html</remarks>
 public static bool are_broadcastable(params int[][] shapes)
 {
     return(DefaultEngine.AreBroadcastable(shapes));
 }
Esempio n. 14
0
 /// <summary>
 ///     Tests if these two two arrays are broadcastable against each other.
 /// </summary>
 /// <param name="ndArrays">The arrays to test for broadcasting.</param>
 /// <returns>True if these can be broadcasted against each other.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_arrays.html</remarks>
 public static bool are_broadcastable(params NDArray[] ndArrays)
 {
     return(DefaultEngine.AreBroadcastable(ndArrays));
 }
Esempio n. 15
0
 /// <summary>
 ///     Broadcast an shape against an other new shape.
 /// </summary>
 /// <param name="from">The shape that is to be broadcasted</param>
 /// <param name="against">The shape that'll be used to broadcast <paramref name="from"/> shape</param>
 /// <returns>A readonly view on the original array with the given shape. It is typically not contiguous. Furthermore, more than one element of a broadcasted array may refer to a single memory location.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_to.html</remarks>
 public static Shape broadcast_to(Shape from, UnmanagedStorage against)
 {
     return(DefaultEngine.Broadcast(from, against.Shape).LeftShape);
 }
 public ExploratoryTests(DefaultEngine engine)
 {
     Fixture   = new ExploratoryFixture(engine);
     Resources = new DefaultResources();
 }
Esempio n. 17
0
 /// <summary>
 ///     Broadcast an array to a new shape.
 /// </summary>
 /// <param name="from">The UnmanagedStorage to broadcast.</param>
 /// <param name="against">The shape to broadcast against.</param>
 /// <returns>These arrays are views on the original arrays. They are typically not contiguous. Furthermore, more than one element of a broadcasted array may refer to a single memory location. If you need to write to the arrays, make copies first.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_to.html</remarks>
 public static NDArray broadcast_to(UnmanagedStorage from, UnmanagedStorage against)
 {
     return(new NDArray(UnmanagedStorage.CreateBroadcastedUnsafe(from, DefaultEngine.Broadcast(from.Shape, against.Shape).LeftShape)));
 }
Esempio n. 18
0
 public SearchAndNavigationConfigurationTests(DefaultEngine engine)
 {
     Fixture = new DefaultFixture(engine);
 }
Esempio n. 19
0
 /// <summary>
 ///     Broadcast two arrays against each other.
 /// </summary>
 /// <param name="lhs">An array to broadcast.</param>
 /// <param name="rhs">An array to broadcast.</param>
 /// <returns>These arrays are views on the original arrays. They are typically not contiguous. Furthermore, more than one element of a broadcasted array may refer to a single memory location. If you need to write to the arrays, make copies first.</returns>
 /// <remarks>https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast_arrays.html</remarks>
 public static (NDArray Lhs, NDArray Rhs) broadcast_arrays(NDArray lhs, NDArray rhs)
 {
     var(leftShape, rightShape) = DefaultEngine.Broadcast(lhs.Shape, rhs.Shape);
     return(new NDArray(UnmanagedStorage.CreateBroadcastedUnsafe(lhs.Storage, leftShape)),
            new NDArray(UnmanagedStorage.CreateBroadcastedUnsafe(rhs.Storage, rightShape)));
 }
Esempio n. 20
0
 public EpiserverFixtureTests(DefaultEngine engine)
 {
     Fixture = new DefaultFixture(engine);
 }