コード例 #1
0
        public void TestReadOnlyCopyConstruct()
        {
            Guid id = new Guid("{53BC19DB-1D34-4995-82FE-8041C9E71EC5}");
            IPolicyLanguageItem name = new NonTranslateableLanguageItem("Test routing");
            RoutingTable httpRoutingTable = new RoutingTable(id, name, ChannelType.HTTP);
            Assert.AreEqual(id, httpRoutingTable.Identifier);
            Assert.IsFalse(httpRoutingTable.ReadOnly);
            Assert.AreEqual(name.Value, httpRoutingTable.Name.Value);
            Assert.IsNotNull(httpRoutingTable.DefaultDestination);
            Assert.IsNotNull(httpRoutingTable.DefaultSource);
            Assert.IsNotNull(httpRoutingTable[httpRoutingTable.DefaultSource, httpRoutingTable.DefaultDestination]);

            RoutingTable copy = new RoutingTable(httpRoutingTable, true, false);
            Assert.AreEqual(id, copy.Identifier);
            Assert.IsTrue(copy.ReadOnly);
            Assert.AreEqual(name.Value, copy.Name.Value);
            Assert.IsNotNull(copy.DefaultSource);
            Assert.IsNotNull(copy.DefaultDestination);
            Assert.IsNotNull(copy[copy.DefaultSource, copy.DefaultDestination]);
            Assert.IsNotNull(copy[copy.DefaultSource, copy.DefaultDestination].Name);
            Assert.IsNotInstanceOf(typeof(NonTranslateableLanguageItem), copy[copy.DefaultSource, copy.DefaultDestination].Name.GetType());
            Assert.AreEqual(httpRoutingTable[httpRoutingTable.DefaultSource, httpRoutingTable.DefaultDestination].Identifier, copy[copy.DefaultSource, copy.DefaultDestination].Identifier);
            Assert.AreEqual(httpRoutingTable[httpRoutingTable.DefaultSource, httpRoutingTable.DefaultDestination].Name.Identifier, copy[copy.DefaultSource, copy.DefaultDestination].Name.Identifier);
            Assert.AreEqual(httpRoutingTable[httpRoutingTable.DefaultSource, httpRoutingTable.DefaultDestination].Name.Value, copy[copy.DefaultSource, copy.DefaultDestination].Name.Value);
        }
コード例 #2
0
        private void ReadRoutings(XmlNode parentNode, PolicyChannel policyChannel)
        {
            if (parentNode == null)
                return;

            IPolicyObjectCollection<IRoutingTable> routingTables = m_reader.CataloguesCache.RoutingTables;
            XmlNode routingTableNode = parentNode.SelectSingleNode("RoutingTable");
            if (routingTableNode == null)
                return;

            bool routingsReadOnly = PolicyUtilities.IsReadOnly(routingTableNode);

            IAddressGroup entireAddressGroup = m_reader.CataloguesCache.AddressGroup;

            string guid = routingTableNode.Attributes.GetNamedItem("id").InnerText;
            Guid identifier = new Guid(guid);
            bool routingTableReadOnly = PolicyUtilities.IsReadOnly(routingTableNode);

            RoutingTable routingTable = new RoutingTable(routingTables[identifier] as RoutingTable, routingTableReadOnly);

            XmlNodeList senderGroupNode = routingTableNode.SelectNodes("./SenderGroup/*");
            if (senderGroupNode != null)
                routingTable.Senders = ReadAddressGroup(senderGroupNode, entireAddressGroup, routingTableReadOnly);

            XmlNodeList recipientGroupNode = routingTableNode.SelectNodes("./RecipientGroup/*");
            if (recipientGroupNode != null)
                routingTable.Recipients = ReadAddressGroup(recipientGroupNode, entireAddressGroup, routingTableReadOnly);

            // Now build the matrix relationships... i.e. The Cells...
            XmlNodeList matrixCellNodes = routingTableNode.SelectNodes("./RoutingMatrixCells/*");
            if (matrixCellNodes != null)
                AddMatrixCells(matrixCellNodes, routingTable);

            policyChannel.Routing = routingTable;
        }
コード例 #3
0
        public void TestReadOnlyCopyConstruct()
        {
            RoutingTable routingTable = new RoutingTable(Guid.Empty, new TranslateableLanguageItem("RoutingName"), ChannelType.SMTP);

            RoutingItemCollection collection1 = new RoutingItemCollection(Guid.NewGuid(), "Collection1");
            RoutingItemCollection collection2 = new RoutingItemCollection(Guid.NewGuid(), "Collection2");
            RoutingItemCollection collection3 = new RoutingItemCollection(Guid.NewGuid(), "Collection3");
            routingTable.Sources.Add(collection1);
            routingTable.Sources.Add(collection2);
            routingTable.Sources.Add(collection3);

            RoutingItemCollection collection4 = new RoutingItemCollection(Guid.NewGuid(), "Collection4");
            RoutingItemCollection collection5 = new RoutingItemCollection(Guid.NewGuid(), "Collection5");
            RoutingItemCollection collection6 = new RoutingItemCollection(Guid.NewGuid(), "Collection6");
            routingTable.Destinations.Add(collection4);
            routingTable.Destinations.Add(collection5);
            routingTable.Destinations.Add(collection6);

            RoutingTable routingTable2 = new RoutingTable(routingTable, true, false);

            Assert.AreEqual(routingTable.Name.Value, routingTable2.Name.Value);
            Assert.AreEqual(routingTable.Sources.Count, routingTable2.Sources.Count);
            Assert.AreEqual(routingTable.Destinations.Count, routingTable2.Destinations.Count);
            Assert.AreEqual(routingTable.CellCount, routingTable2.CellCount);
            Assert.IsTrue(routingTable2.ReadOnly);
        }
コード例 #4
0
        public void TestConstruct()
        {
            Guid id = new Guid("{53BC19DB-1D34-4995-82FE-8041C9E71EC5}");
            IPolicyLanguageItem name = new NonTranslateableLanguageItem("Test routing");
            RoutingTable routingTable = new RoutingTable(id, name, ChannelType.Mta);
            Assert.AreEqual(id, routingTable.Identifier);
            Assert.IsFalse(routingTable.ReadOnly);
            Assert.AreEqual(name.Value, routingTable.Name.Value);
            Assert.IsNotNull(routingTable.DefaultDestination);
            Assert.AreEqual(1, routingTable.Destinations.Count);
            Assert.IsNotNull(routingTable.DefaultSource);
            Assert.IsNotNull(routingTable[routingTable.DefaultSource, routingTable.DefaultDestination]);

            Assert.AreEqual(2, routingTable.Sources.Count);

            Assert.AreEqual("Mail server", routingTable.Sources[0].Name.Value);
            Assert.IsTrue(System.Convert.ToBoolean(routingTable.Sources[0][RoutingTable.DefaultGroupName].Value,
                System.Globalization.CultureInfo.CurrentCulture));

            Assert.AreEqual("Blackberry", routingTable.Sources[1].Name.Value);
            Assert.IsTrue(string.IsNullOrEmpty(routingTable.Sources[1][RoutingTable.DefaultGroupName].Value));

            Assert.IsNotNull(routingTable[routingTable.Sources[0], routingTable.DefaultDestination]);
            Assert.IsNotNull(routingTable[routingTable.Sources[1], routingTable.DefaultDestination]);
        }
コード例 #5
0
 private IRoutingTable BuildSmtpRouting()
 {
     RoutingTable routingTable = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.SMTP);
     routingTable.Sources = TestHelpers.BuildSenderGroup();
     routingTable.Destinations = TestHelpers.BuildRecipientGroup();
     TestHelpers.BuildMatrixCells(routingTable);
     return routingTable;
 }
コード例 #6
0
 public void MatchesDynamicUrlWithTrailingValues()
 {
     var target = new RoutingTable();
     var expected = typeof (RoutingTableTests);
     target.Add("/tests/{Id}/bar", expected);
     IDictionary<string, string[]> variables;
     var actual = target.Get("/tests/1/bar", out variables);
     Assert.Equal(expected, actual);
 }
コード例 #7
0
 public void MatchesStaticUrl()
 {
     var target = new RoutingTable();
     var expected = typeof(RoutingTableTests);
     target.Add("/", expected);
     IDictionary<string, string> _;
     var actual = target.Get("/", out _);
     Assert.Equal(expected, actual);
 }
コード例 #8
0
        /// <summary>
        /// Update routing table by the files that will found be requested directory.
        /// Also auto loking for core routing  table by "resources\routing\".
        ///
        /// In case if tables not found then create new one to provide example.
        /// </summary>
        /// <param name="directories"></param>
        public static void LoadRoutingTables(params string[] directories)
        {
            #region Load routing tables
            // Load routing tables
            routingTable = null;
            // From system folders.
            routingTable += RoutingTable.LoadRoutingTables(AppDomain.CurrentDomain.BaseDirectory + "resources\\routing\\", SearchOption.AllDirectories);
            // From custrom directories.
            foreach (string dir in directories)
            {
                routingTable += RoutingTable.LoadRoutingTables(dir, SearchOption.AllDirectories);
            }
            #endregion

            /* TODO Deprecated unnessesary code with requesting keys and tokens.
             #region Request public keys
             * foreach (Instruction instruction in routingTable.intructions)
             * {
             *  if (instruction is PartialAuthorizedInstruction pai)
             *  {
             *      Task.Run(async delegate()
             *      {
             *          // Waiting for guest token.
             *          await pai.TryToGetGuestTokenAsync(TerminationTokenSource.Token);
             *
             *          // If encryption requested.
             *          if (instruction.encryption)
             *          {
             *              // Request public key reciving.
             *              _ = GetValidSecretKeysViaPPAsync(instruction);
             *          }
             *      }
             *  }
             * }
             #endregion*/

            #region Validate
            // If routing table not found.
            if (routingTable.intructions.Count == 0)
            {
                //// Log error.
                //Console.WriteLine("ROUTING TABLE NOT FOUND: Create default table by directory \\resources\\routing\\ROUTING.xml");

                //// Set default intruction.
                //routingTable.intructions.Add(Instruction.Default);

                //// Save sample routing table to application files.
                //RoutingTable.SaveRoutingTable(routingTable, AppDomain.CurrentDomain.BaseDirectory + "resources\\routing\\", "ROUTING");
            }
            else
            {
                // Log error.
                Console.WriteLine("ROUTING TABLE: Detected {0} instructions.", routingTable.intructions.Count);
            }
            #endregion
        }
コード例 #9
0
 public void MatchesVanityUrlWithTrailingSlash()
 {
     var target = new RoutingTable();
     var expected = typeof(RoutingTableTests);
     target.Add("/{Name}", expected);
     IDictionary<string, string> variables;
     var actual = target.Get("/test/", out variables);
     Assert.Equal(expected, actual);
     Assert.Equal("test", variables["Name"]);
 }
コード例 #10
0
        private HttpServer(string ipAddress, int port, IRoutingTable routingTable)
        {
            this.ipAddress = IPAddress.Parse(ipAddress);
            this.port      = port;

            this.listener     = new TcpListener(this.ipAddress, port);
            this.routingTable = (RoutingTable)routingTable;

            this.serviceCollection = new ServiceCollection();
        }
コード例 #11
0
ファイル: Ipv4.cs プロジェクト: xsjames/Network.Sim
        /// <summary>
        /// Initializes a new instance of the Network class.
        /// </summary>
        /// <param name="interfaces">An enumerable collection of interfaces
        /// installed on the host.</param>
        /// <param name="routingTable">The routing table to use.</param>
        /// <param name="nodalProcessingDelay">The nodal processing delay, in
        /// nanoseconds.</param>
        /// <exception cref="ArgumentNullException">Thrown if the interfaces
        /// parameter is null.</exception>
        public Ipv4(IEnumerable <Interface> interfaces, RoutingTable routingTable,
                    ulong nodalProcessingDelay)
        {
            interfaces.ThrowIfNull("interfaces");
            this.interfaces           = interfaces;
            this.routingTable         = routingTable;
            this.nodalProcessingDelay = nodalProcessingDelay;

            arp = new Arp.Arp(Output);
        }
コード例 #12
0
ファイル: HttpServer.cs プロジェクト: vlatcata/SoftUni
        public HttpServer(string ipAddress, int port, Action <IRoutingTable> routingTableConfiguration)
        {
            this.ipAddress = IPAddress.Parse(ipAddress);
            this.port      = port;

            this.serverListener = new TcpListener(this.ipAddress, port);

            routingTableConfiguration(this.routingTable = new RoutingTable());
            ServiceCollection = new ServiceCollection();
        }
コード例 #13
0
ファイル: HttpServer.cs プロジェクト: VenziVi/SoftUni
        public HttpServer(string _ipAddress, int _port,
                          Action <RoutingTable> _routingTableConfiguration)
        {
            ipAddress = IPAddress.Parse(_ipAddress);
            port      = _port;

            serverListener = new TcpListener(ipAddress, port);

            _routingTableConfiguration(routingTable = new RoutingTable());
        }
コード例 #14
0
 private void AddToTable(IProtocolNode node, int count)
 {
     node?.Connections.ForEach(c =>
     {
         if (!RoutingTable.Any(t => t.Item1.Contains(c)))
         {
             RoutingTable.Add(new Tuple <string, string, int>(c, node.Id, count));
         }
     });
 }
コード例 #15
0
 public void MatchesDynamicUrlWithOneVariable()
 {
     var target = new RoutingTable();
     var expected = typeof(RoutingTableTests);
     target.Add("/tests/{Id}", expected);
     IDictionary<string, string> variables;
     var actual = target.Get("/tests/1", out variables);
     Assert.Equal(expected, actual);
     Assert.Equal("1", variables["Id"]);
 }
コード例 #16
0
 public void Setup()
 {
     _id               = new byte[20];
     _id[1]            = 128;
     _node             = new Node(new NodeId(_id), new IPEndPoint(IPAddress.Any, 0));
     _table            = new RoutingTable(_node);
     _table.NodeAdded += delegate { _addedCount++; };
     _table.Add(_node); //the local node is no more in routing table so add it to show test is still ok
     _addedCount = 0;
 }
コード例 #17
0
 public TcpTransport(TcpTransportConfiguration configuration, Identity identity, RoutingTable routingTable, PeerTable peerTable, InboundMessageDispatcher inboundMessageDispatcher, TcpRoutingContextContainer tcpRoutingContextContainer, PayloadUtils payloadUtils)
 {
     this.configuration              = configuration;
     this.identity                   = identity;
     this.routingTable               = routingTable;
     this.peerTable                  = peerTable;
     this.inboundMessageDispatcher   = inboundMessageDispatcher;
     this.tcpRoutingContextContainer = tcpRoutingContextContainer;
     this.payloadUtils               = payloadUtils;
 }
コード例 #18
0
 public void Copy(RoutingTable other)
 {
     if (other != null)
     {
         for (int i = 0; i < other.Entries.Length; ++i)
         {
             Entries[i] = other.Entries[i];
         }
     }
 }
コード例 #19
0
        public ClientCollection(IServer <TPeer> server, uint sessionId)
        {
            _server    = server;
            _sessionId = sessionId;

            _playerIds             = new RoutingTable();
            _clientsByConnection   = new Dictionary <TPeer, ClientInfo>();
            _connectionsByRoom     = new Dictionary <ushort, List <TPeer> >();
            _connectionsByPlayerId = new Dictionary <ushort, TPeer>();
        }
コード例 #20
0
        public IntKadNode CreateNode(int nodeId)
        {
            RoutingTable <int> routingTable = Mother.CreateIntRoutingTable();
            var settings = new KademeliaSettings(TimeSpan.FromMilliseconds(100), 2, 5);

            return
                (new IntKadNode(
                     new MockKadCore(routingTable, settings, CreateClientFromNodeId,
                                     new NodeIdentifier <int>("", nodeId)), this));
        }
コード例 #21
0
        public static HttpServer WithRoutes(Action <IRoutingTable> routingTableConfiguration)
        {
            var routingTable = new RoutingTable();

            routingTableConfiguration(routingTable);

            var httpServer = new HttpServer(routingTable);

            return(httpServer);
        }
コード例 #22
0
            [InlineData(1, 2, 1, -1, true)]      // expire immediately
            public void ShouldBeStaleInWriteModeIfOnlyHaveOneRouter(int routerCount, int readerCount, int writerCount, long expireAfterSeconds, bool isStale)
            {
                var table = new RoutingTable(
                    CreateUriArray(routerCount),
                    CreateUriArray(readerCount),
                    CreateUriArray(writerCount),
                    expireAfterSeconds);

                table.IsStale(AccessMode.Write).Should().Be(isStale);
            }
コード例 #23
0
        public void MatchesDynamicUrlWithTrailingValues()
        {
            var target   = new RoutingTable();
            var expected = typeof(RoutingTableTests);

            target.Add("/tests/{Id}/bar", expected);
            IDictionary <string, string[]> variables;
            var actual = target.Get("/tests/1/bar", out variables);

            Assert.Equal(expected, actual);
        }
コード例 #24
0
        public void MatchesStaticUrl()
        {
            var target   = new RoutingTable();
            var expected = typeof(RoutingTableTests);

            target.Add("/", expected);
            IDictionary <string, string[]> _;
            var actual = target.Get("/", out _);

            Assert.Equal(expected, actual);
        }
コード例 #25
0
 public void MatchesDynamicUrlWithTwoVariables()
 {
     var target = new RoutingTable();
     var expected = typeof(RoutingTableTests);
     target.Add("/tests/{Year}/{Month}", expected);
     IDictionary<string, string> variables;
     var actual = target.Get("/tests/2012/2", out variables);
     Assert.Equal(expected, actual);
     Assert.Equal("2012", variables["Year"]);
     Assert.Equal("2", variables["Month"]);
 }
コード例 #26
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="communicationLayer">Reference to the Communication Layer</param>
 /// <param name="storageManager">Reference to the Storage Manager</param>
 /// <param name="routingTable">Reference to the routing table</param>
 /// <param name="serverGraph">Reference to server graph</param>
 /// <param name="clientApplicationList">Reference to application list</param>
 /// <param name="ngridManager">Reference to NGRID Manager object</param>
 public OrganizationLayer(CommunicationLayer communicationLayer, IStorageManager storageManager, RoutingTable routingTable, NGRIDServerGraph serverGraph, NGRIDClientApplicationList clientApplicationList, NGRIDController ngridManager)
 {
     _settings              = NGRIDSettings.Instance;
     _communicationLayer    = communicationLayer;
     _storageManager        = storageManager;
     _routingTable          = routingTable;
     _serverGraph           = serverGraph;
     _clientApplicationList = clientApplicationList;
     _ngridManager          = ngridManager;
     _waitingMessages       = new SortedList <string, WaitingMessage>();
     PrepareCommunicationLayer();
 }
コード例 #27
0
            public void ShouldReturnExpectedValue(long elapsedMs, long expiresAfterMs, long expiredForCheckMs,
                                                  bool expected)
            {
                var timer = new Mock <ITimer>();

                timer.Setup(x => x.ElapsedMilliseconds).Returns(elapsedMs);

                var routingTable = new RoutingTable(null, new[] { new Uri("neo4j://my-router") },
                                                    new[] { new Uri("neo4j://my-reader") }, Enumerable.Empty <Uri>(), expiresAfterMs / 1000, timer.Object);

                routingTable.IsExpiredFor(TimeSpan.FromMilliseconds(expiredForCheckMs)).Should().Be(expected);
            }
コード例 #28
0
        public HttpServer(string ipAddres, int port, Action <IRoutingTable> routingTableConfiguration)
        {
            // local host IP address
            this.ipAddress = IPAddress.Parse(ipAddres);
            // port
            this.port = port;

            this.listener = new TcpListener(ipAddress, port);

            this.routingTable = new RoutingTable();
            routingTableConfiguration(this.routingTable);
        }
コード例 #29
0
ファイル: TestUtils.cs プロジェクト: Chaleeshadow/libplanet
        public static PrivateKey GeneratePrivateKeyOfBucketIndex(Address tableAddress, int target)
        {
            var        table = new RoutingTable(tableAddress);
            PrivateKey privateKey;

            do
            {
                privateKey = new PrivateKey();
            }while (table.GetBucketIndexOf(privateKey.ToAddress()) != target);

            return(privateKey);
        }
コード例 #30
0
ファイル: UDPListener.cs プロジェクト: ollandos/SharedDesk
        private static RoutingTable byteArrayToRoutingTable(byte[] arrBytes)
        {
            MemoryStream    memStream = new MemoryStream();
            BinaryFormatter binForm   = new BinaryFormatter();

            memStream.Write(arrBytes, 0, arrBytes.Length);
            memStream.Seek(0, SeekOrigin.Begin);

            RoutingTable routingTable = (RoutingTable)binForm.Deserialize(memStream);

            return(routingTable);
        }
コード例 #31
0
ファイル: NGRIDServer.cs プロジェクト: erisonliang/NGRID
 /// <summary>
 /// Constructor.
 /// </summary>
 public NGRIDServer()
 {
     _settings                       = NGRIDSettings.Instance;
     _serverGraph                    = new NGRIDServerGraph();
     _clientApplicationList          = new NGRIDClientApplicationList();
     _ngridManager                   = new NGRIDController("NGRIDController");
     _storageManager                 = StorageManagerFactory.CreateStorageManager();
     _routingTable                   = new RoutingTable();
     _communicationLayer             = new CommunicationLayer();
     _organizationLayer              = new OrganizationLayer(_communicationLayer, _storageManager, _routingTable, _serverGraph, _clientApplicationList, _ngridManager);
     _ngridManager.OrganizationLayer = _organizationLayer;
 }
コード例 #32
0
 public void TestConstruct()
 {
     Guid id = new Guid("{53BC19DB-1D34-4995-82FE-8041C9E71EC5}");
     IPolicyLanguageItem name = new NonTranslateableLanguageItem("Test routing");
     RoutingTable httpRoutingTable = new RoutingTable(id, name, ChannelType.HTTP);
     Assert.AreEqual(id, httpRoutingTable.Identifier);
     Assert.IsFalse(httpRoutingTable.ReadOnly);
     Assert.AreEqual(name.Value, httpRoutingTable.Name.Value);
     Assert.IsNotNull(httpRoutingTable.DefaultDestination);
     Assert.IsNotNull(httpRoutingTable.DefaultSource);
     Assert.IsNotNull(httpRoutingTable[httpRoutingTable.DefaultSource, httpRoutingTable.DefaultDestination]);
 }
コード例 #33
0
        public void MatchesDynamicUrlWithOneVariable()
        {
            var target   = new RoutingTable();
            var expected = typeof(RoutingTableTests);

            target.Add("/tests/{Id}", expected);
            IDictionary <string, string[]> variables;
            var actual = target.Get("/tests/1", out variables);

            Assert.Equal(expected, actual);
            Assert.Equal("1", variables["Id"][0]);
        }
コード例 #34
0
        public void MatchesVanityUrlWithTrailingSlash()
        {
            var target   = new RoutingTable();
            var expected = typeof(RoutingTableTests);

            target.Add("/{Name}", expected);
            IDictionary <string, string[]> variables;
            var actual = target.Get("/test/", out variables);

            Assert.Equal(expected, actual);
            Assert.Equal("test", variables["Name"][0]);
        }
        public void returns_k_nearest_ordered()
        {
            RoutingTable <int> table = Mother.CreateIntRoutingTable();

            table.Add(new NodeIdentifier <int>("", 1));
            table.Add(new NodeIdentifier <int>("", 2));
            table.Add(new NodeIdentifier <int>("", 4));
            table.Add(new NodeIdentifier <int>("", 5));

            CollectionAssert.IsOrdered(table.NearTo(1).Select(n => n.NodeId),
                                       new LamdaComparer <int>((a, b) => a.CompareTo(b)));
        }
コード例 #36
0
        public void MatchesDynamicUrlWithTwoVariables()
        {
            var target   = new RoutingTable();
            var expected = typeof(RoutingTableTests);

            target.Add("/tests/{Year}/{Month}", expected);
            IDictionary <string, string[]> variables;
            var actual = target.Get("/tests/2012/2", out variables);

            Assert.Equal(expected, actual);
            Assert.Equal("2012", variables["Year"][0]);
            Assert.Equal("2", variables["Month"][0]);
        }
コード例 #37
0
        public void MatchesUrlWhenTwoRegexesHaveSameNumberOfGroups()
        {
            var target      = new RoutingTable();
            var expectedFoo = typeof(int);
            var expectedBar = typeof(string);

            target.Add("/tests/{Id}/foo", expectedFoo);
            target.Add("/tests/{Id}/bar", expectedBar);
            IDictionary <string, string[]> variables;

            Assert.Equal(expectedFoo, target.Get("/tests/1/foo", out variables));
            Assert.Equal(expectedBar, target.Get("/tests/1/bar", out variables));
        }
コード例 #38
0
            public async Task ShouldAllowMultipleRoutingTables(AccessMode mode)
            {
                var defaultRoutingTable =
                    new RoutingTable(null, new[] { server01 }, new[] { server02 }, new[] { server03 }, 60);
                var fooRoutingTable =
                    new RoutingTable("foo", new[] { server04 }, new[] { server05 }, new[] { server06 }, 80);
                var barRoutingTable =
                    new RoutingTable("bar", new[] { server07 }, new[] { server08 }, new[] { server09 }, 100);

                var discovery = new Mock <IDiscovery>();

                discovery.Setup(x => x.DiscoverAsync(It.IsAny <IConnection>(), "", null, Bookmark.Empty))
                .ReturnsAsync(defaultRoutingTable);
                discovery.Setup(x => x.DiscoverAsync(It.IsAny <IConnection>(), "foo", null, Bookmark.Empty))
                .ReturnsAsync(fooRoutingTable);
                discovery.Setup(x => x.DiscoverAsync(It.IsAny <IConnection>(), "bar", null, Bookmark.Empty))
                .ReturnsAsync(barRoutingTable);

                var poolManager = new Mock <IClusterConnectionPoolManager>();

                poolManager.Setup(x => x.CreateClusterConnectionAsync(It.IsAny <Uri>()))
                .ReturnsAsync(Mock.Of <IConnection>);

                var initialAddressProvider = new Mock <IInitialServerAddressProvider>();

                initialAddressProvider.Setup(x => x.Get()).Returns(new HashSet <Uri> {
                    server01, server04, server07
                });

                var manager = new RoutingTableManager(initialAddressProvider.Object, discovery.Object,
                                                      poolManager.Object, Mock.Of <ILogger>(), TimeSpan.MaxValue);

                // When
                var routingTable1 = await manager.EnsureRoutingTableForModeAsync(mode, null, null, Bookmark.Empty);

                var routingTable2 =
                    await manager.EnsureRoutingTableForModeAsync(mode, "foo", null, Bookmark.Empty);

                var routingTable3 =
                    await manager.EnsureRoutingTableForModeAsync(mode, "bar", null, Bookmark.Empty);

                routingTable1.Should().Be(defaultRoutingTable);
                routingTable2.Should().Be(fooRoutingTable);
                routingTable3.Should().Be(barRoutingTable);

                manager.RoutingTableFor(null).Should().Be(defaultRoutingTable);
                manager.RoutingTableFor("").Should().Be(defaultRoutingTable);
                manager.RoutingTableFor("foo").Should().Be(fooRoutingTable);
                manager.RoutingTableFor("bar").Should().Be(barRoutingTable);
            }
コード例 #39
0
        public void TestRoutingTableReturnsEmptyForAbsentTopic()
        {
            var node   = new NodeMock();
            var routes = new Dictionary <string, Partition[]>
            {
                { "test1p", new[] { new Partition {
                                        Id = 0, Leader = node
                                    } } },
            };
            var routingTable = new RoutingTable(routes);

            Assert.Less(0, routingTable.GetPartitions("test1p").Length);
            Assert.AreEqual(0, routingTable.GetPartitions("tortemoque").Length);
        }
コード例 #40
0
 private static void OnRoleInstanceNumberChanged(int number)
 {
     if (number < 0)
     {
         List <WorkSessionServerInfo> affectedServers = new List <WorkSessionServerInfo>();
         RoutingTable.ForEachWorkSessionServer((roleInstanceId, serverInfo) => {
             if (serverInfo.IsProbablyShuttingDown())
             {
                 affectedServers.Add(serverInfo);
             }
         });
         WorkSessionMessenger.SendMessage(MessageOperation.ServerNumberDecreased, affectedServers);
     }
 }
コード例 #41
0
            public void ShouldEnsureInitialRouter()
            {
                var initUri = new Uri("bolt://123:456");
                var routers = new HashSet <Uri> {
                    initUri
                };
                var table = new RoutingTable(null, routers);

                Uri uri = table.Routers.Single();

                uri.Should().Be(initUri);

                table.All().Single().Should().Be(initUri);
            }
コード例 #42
0
        private IRoutingTable BuildInternalExternalSmtpRouting()
        {
            RoutingTable routingTable = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.SMTP);
            routingTable["resolve"] = new NonTranslateableLanguageItem("emailclient");

            RoutingItemCollection interalGroup = new RoutingItemCollection(Guid.NewGuid(), "Recipients:Internal");
            interalGroup.Add(new RoutingItem("Recipients:Internal", "Recipients:Internal"));
            interalGroup["InternalGroup"] = new NonTranslateableLanguageItem("true");
            interalGroup["assembly"] = new NonTranslateableLanguageItem("Workshare.InternalExternalResolver.dll");
            interalGroup["class"] = new NonTranslateableLanguageItem("Workshare.InternalExternalResolver");
            routingTable.Destinations.Add(interalGroup);

            routingTable.Sources = TestHelpers.BuildSenderGroup();
            routingTable.Destinations = TestHelpers.BuildRecipientGroup();
            TestHelpers.BuildMatrixCells(routingTable);
            return routingTable;
        }
コード例 #43
0
        public void TestReadOnlyCopyConstruct()
        {
            Guid id = new Guid("{53BC19DB-1D34-4995-82FE-8041C9E71EC5}");
            IPolicyLanguageItem name = new NonTranslateableLanguageItem("Test routing");
            RoutingTable activeContentRoutingTable = new RoutingTable(id, name, ChannelType.ActiveContent);
            Assert.AreEqual(id, activeContentRoutingTable.Identifier);
            Assert.IsFalse(activeContentRoutingTable.ReadOnly);
            Assert.AreEqual(name.Value, activeContentRoutingTable.Name.Value);
            Assert.IsNotNull(activeContentRoutingTable.DefaultDestination);
            Assert.IsNotNull(activeContentRoutingTable.DefaultSource);
            Assert.IsNotNull(activeContentRoutingTable[activeContentRoutingTable.DefaultSource, activeContentRoutingTable.DefaultDestination]);

            RoutingTable copy = new RoutingTable(activeContentRoutingTable, true, false);
            Assert.AreEqual(id, copy.Identifier);
            Assert.IsTrue(copy.ReadOnly);
            Assert.AreEqual(name.Value, copy.Name.Value);
            Assert.IsNotNull(copy.DefaultDestination);
            Assert.IsNotNull(copy.DefaultSource);
            Assert.IsNotNull(copy[copy.DefaultSource, copy.DefaultDestination]);
        }
コード例 #44
0
        /// <summary>
        /// Returns the 'neighbours' of an RoutingItem Collection.
        /// </summary>
        /// <param name="locationCollection">The location collection whose neighbours we're looking for</param>
        /// <param name="routingTable">The routing table we're looking in</param>
        /// <returns>If <paramref name="locationCollection"/> is on the 'row' axis of <paramref name="routingTable"/>, returns the Sources property of <paramref name="routingTable"/>.  Otherwise, returns the Destinations property, or null if <paramref name="locationCollection"/> does not belong in the routing table</returns>
        /// <remarks>Return value will always contain <paramref name="locationCollection"/>.
        /// This method assumes that all Identifiers within the matrix are unique.</remarks>
        internal static IRoutingItemCollections GetNeighbours(IRoutingItemCollection addressCollection, RoutingTable routingTable)
        {
            if ((null != addressCollection) && (null != routingTable))
            {
                foreach (IRoutingItemCollection ac in routingTable.Destinations)
                {
                    if (0 == ac.Identifier.CompareTo(addressCollection.Identifier))
                    {
                        return routingTable.Destinations;
                    }
                }

                foreach (IRoutingItemCollection ac in routingTable.Sources)
                {
                    if (0 == ac.Identifier.CompareTo(addressCollection.Identifier))
                    {
                        return routingTable.Sources;
                    }
                }
            }
            return null;
        }
コード例 #45
0
        public void TestGetNeighbours()
        {
            RoutingTable table = new RoutingTable(Guid.NewGuid(), new NonTranslateableLanguageItem("TestRoutingTable"), Workshare.Policy.ChannelType.SMTP);

            table.Sources = new RoutingItemCollections();
            table.Destinations = new RoutingItemCollections();

            IRoutingItemCollection senderA = new RoutingItemCollection(Guid.NewGuid(), "senderA");
            IRoutingItemCollection senderB = new RoutingItemCollection(Guid.NewGuid(), "senderB");
            IRoutingItemCollection senderC = new RoutingItemCollection(Guid.NewGuid(), "senderC");

            IRoutingItemCollection recipA = new RoutingItemCollection(Guid.NewGuid(), "recipA");
            IRoutingItemCollection recipB = new RoutingItemCollection(Guid.NewGuid(), "recipB");
            IRoutingItemCollection recipC = new RoutingItemCollection(Guid.NewGuid(), "recipC");

            //add into the routing table
            table.Sources.Add(senderA);
            table.Sources.Add(senderB);
            table.Sources.Add(senderC);

            table.Destinations.Add(recipA);
            table.Destinations.Add(recipB);
            table.Destinations.Add(recipC);

            IRoutingItemCollection notInMyRoutingTable = new RoutingItemCollection(Guid.NewGuid(), "notInMyRoutingTable");

            Assert.IsNull(EditRoutingDetailState.GetNeighbours(null, table), "Should return null when either param is null.");
            Assert.IsNull(EditRoutingDetailState.GetNeighbours(notInMyRoutingTable, null), "Should return null when either param is null.");
            Assert.IsNull(EditRoutingDetailState.GetNeighbours(notInMyRoutingTable, table), "Should return null when 1st param does not exist in the table");

            Assert.AreSame(table.Sources, EditRoutingDetailState.GetNeighbours(senderA, table), "Expected to return the table.Sources object for this param");
            Assert.AreSame(table.Sources, EditRoutingDetailState.GetNeighbours(senderB, table), "Expected to return the table.Sources object for this param");
            Assert.AreSame(table.Sources, EditRoutingDetailState.GetNeighbours(senderC, table), "Expected to return the table.Sources object for this param");

            Assert.AreSame(table.Destinations, EditRoutingDetailState.GetNeighbours(recipA, table), "Expected to return the table.Destinations object for this param");
            Assert.AreSame(table.Destinations, EditRoutingDetailState.GetNeighbours(recipB, table), "Expected to return the table.Destinations object for this param");
            Assert.AreSame(table.Destinations, EditRoutingDetailState.GetNeighbours(recipC, table), "Expected to return the table.Destinations object for this param");
        }
コード例 #46
0
        public void TestConstruct()
        {
            RoutingTable routingTable = new RoutingTable(Guid.Empty, new TranslateableLanguageItem("RoutingName"), ChannelType.SMTP);
            routingTable["resolve"] = new NonTranslateableLanguageItem("emailclient");

            RoutingItemCollection interalGroup = new RoutingItemCollection(Guid.NewGuid(), "Recipients:Internal");
            interalGroup.Add(new RoutingItem("Recipients:Internal", "Recipients:Internal"));
            interalGroup["InternalGroup"] = new NonTranslateableLanguageItem("true");
            interalGroup["assembly"] = new NonTranslateableLanguageItem("Workshare.InternalExternalResolver.dll");
            interalGroup["class"] = new NonTranslateableLanguageItem("Workshare.InternalExternalResolver");
            routingTable.Destinations.Add(interalGroup);

            Assert.AreEqual("RoutingName", routingTable.Name.Value);
            Assert.AreEqual("Sources:Everyone", routingTable.DefaultSource.Name.Value);
            Assert.AreEqual(1, routingTable.Sources.Count);
            Assert.AreEqual("Sources:Everyone", routingTable.Sources[0].Name.Value);

            Assert.AreEqual("Destinations:Everyone", routingTable.DefaultDestination.Name.Value);
            Assert.AreEqual(2, routingTable.Destinations.Count);
            Assert.AreEqual("Recipients:Internal", routingTable.Destinations[0].Name.Value);
            Assert.AreEqual("Destinations:Everyone", routingTable.Destinations[1].Name.Value);
            Assert.AreEqual(2, routingTable.CellCount);
        }
コード例 #47
0
        public void TestCopyConstruct()
        {
            RoutingTable routingTable = new RoutingTable(Guid.Empty, new TranslateableLanguageItem("RoutingName"), ChannelType.SMTP);
            routingTable["resolve"] = new NonTranslateableLanguageItem("emailclient");

            RoutingItemCollection interalGroup = new RoutingItemCollection(Guid.NewGuid(), "Recipients:Internal");
            interalGroup.Add(new RoutingItem("Recipients:Internal", "Recipients:Internal"));
            interalGroup["InternalGroup"] = new NonTranslateableLanguageItem("true");
            interalGroup["assembly"] = new NonTranslateableLanguageItem("Workshare.InternalExternalResolver.dll");
            interalGroup["class"] = new NonTranslateableLanguageItem("Workshare.InternalExternalResolver");
            routingTable.Destinations.Add(interalGroup);

            RoutingItemCollection collection1 = new RoutingItemCollection(Guid.NewGuid(), "Collection1");
            RoutingItemCollection collection2 = new RoutingItemCollection(Guid.NewGuid(), "Collection2");
            RoutingItemCollection collection3 = new RoutingItemCollection(Guid.NewGuid(), "Collection3");
            routingTable.Sources.Add(collection1);
            routingTable.Sources.Add(collection2);
            routingTable.Sources.Add(collection3);

            RoutingItemCollection collection4 = new RoutingItemCollection(Guid.NewGuid(), "Collection4");
            RoutingItemCollection collection5 = new RoutingItemCollection(Guid.NewGuid(), "Collection5");
            RoutingItemCollection collection6 = new RoutingItemCollection(Guid.NewGuid(), "Collection6");
            routingTable.Destinations.Add(collection4);
            routingTable.Destinations.Add(collection5);
            routingTable.Destinations.Add(collection6);

            RoutingTable routingTable2 = new RoutingTable(routingTable);
            routingTable["resolve"] = new NonTranslateableLanguageItem("emailclient");

            routingTable2.Destinations.Add(interalGroup);

            Assert.AreEqual(routingTable.Name.Value, routingTable2.Name.Value);
            Assert.AreEqual(routingTable.Sources.Count, routingTable2.Sources.Count);
            Assert.AreEqual(routingTable.Destinations.Count, routingTable2.Destinations.Count);
            Assert.AreEqual(routingTable.CellCount, routingTable2.CellCount);
            Assert.AreEqual(routingTable.ReadOnly, routingTable2.ReadOnly);
        }
コード例 #48
0
ファイル: TestHelpers.cs プロジェクト: killbug2004/WSProf
        public static void BuildMatrixCells(RoutingTable routingTable)
        {
            PolicyCataloguesCache policyCataloguesCache = PolicyCataloguesCache.Instance();
            IRoutingItemCollection senders1 = policyCataloguesCache.LocationsCollections[new Guid("{A81631A6-6AA3-45F7-AADD-4853447E5BD6}")];
            Assert.IsNotNull(senders1, "Expected the sources 1 to be valid");
            IRoutingItemCollection recipients1 = policyCataloguesCache.LocationsCollections[new Guid("{FA13BE82-9EB1-407E-9DD5-8005F3E840E4}")];
            Assert.IsNotNull(recipients1, "Expected the destinations 1 to be valid");
            IRoutingItemCollection senders2 = policyCataloguesCache.LocationsCollections[new Guid("{0DAACC5C-6167-42C7-AED0-55D1D9CC5096}")];
            Assert.IsNotNull(senders2, "Expected the sources 2 to be valid");
            IRoutingItemCollection recipients2 = policyCataloguesCache.LocationsCollections[new Guid("{13A8EBE5-8B1E-4919-82E2-8A860DE4043E}")];
            Assert.IsNotNull(recipients2, "Expected the destinations 2 to be valid");
            
            IRoutingMatrixCell cell = new RoutingMatrixCell(new TranslateableLanguageItem("Important"), new TranslateableLanguageItem("High Priority Scanning"), new TranslateableLanguageItem("Red"), 1, senders1, recipients1);
            routingTable["{A81631A6-6AA3-45F7-AADD-4853447E5BD6}", "{FA13BE82-9EB1-407E-9DD5-8005F3E840E4}"] = cell;

            IRoutingMatrixCell cell2 = new RoutingMatrixCell(new TranslateableLanguageItem("Sort of important"), new TranslateableLanguageItem("Sort of High Priority Scanning"), new TranslateableLanguageItem("Yellow"), 2, senders1, recipients2);
            routingTable["{A81631A6-6AA3-45F7-AADD-4853447E5BD6}", "{13A8EBE5-8B1E-4919-82E2-8A860DE4043E}"] = cell2;

            IRoutingMatrixCell cell3 = new RoutingMatrixCell(new TranslateableLanguageItem("Who cares"), new TranslateableLanguageItem("Very Low Priority Scanning"), new TranslateableLanguageItem("Brown"), 3, senders2, recipients1);
            routingTable["{0DAACC5C-6167-42C7-AED0-55D1D9CC5096}", "{13A8EBE5-8B1E-4919-82E2-8A860DE4043E}"] = cell3;

            IRoutingMatrixCell cell4 = new RoutingMatrixCell(new TranslateableLanguageItem("Not important at all"), new TranslateableLanguageItem("Very, very, very Low Priority Scanning"), new TranslateableLanguageItem("Black"), 4, senders2, recipients2);
            routingTable["{0DAACC5C-6167-42C7-AED0-55D1D9CC5096}", "{FA13BE82-9EB1-407E-9DD5-8005F3E840E4}"] = cell4;
        }
コード例 #49
0
 public void TestReadOnlyCopyConstructNull()
 {
     RoutingTable copy = new RoutingTable(null, true, false);
 }
コード例 #50
0
 public void TestCopyConstructNull()
 {
     RoutingTable copy = new RoutingTable(null);
 }
コード例 #51
0
        public void TestOfflineHttpRoutingCopyNullOffline()
        {
            RoutingTable routingTable = new RoutingTable(Guid.Empty, new TranslateableLanguageItem("RoutingName"), ChannelType.HTTP);
            IRoutingMatrixCell offlineCell = routingTable.Offline;
            Assert.IsNotNull(offlineCell, "Expected a valid offline routing cell");
            offlineCell.Name.Value = "This is an offline cell";

            RoutingTable copy = new RoutingTable(null, false, false);
        }
コード例 #52
0
        public void TestOfflineHttpRoutingCopyCreateNew()
        {
            RoutingTable routingTable = new RoutingTable(Guid.Empty, new TranslateableLanguageItem("RoutingName"), ChannelType.HTTP);
            IRoutingMatrixCell offlineCell = routingTable.Offline;
            Assert.IsNotNull(offlineCell, "Expected a valid offline routing cell");
            offlineCell.Name.Value = "This is an offline cell";
            offlineCell.Description.Value = "This is a cell that will be used in offline mode";
            Assert.IsNotNull(offlineCell, "Expected a valid offline routing cell");

            RoutingTable copy = routingTable.DeepCopy(false, true) as RoutingTable;
            Assert.AreEqual(offlineCell.Name.Value, copy.Offline.Name.Value);
            Assert.AreNotEqual(offlineCell.Description.Identifier, copy.Offline.Description.Identifier);
            Assert.AreEqual(offlineCell.Description.Value, copy.Offline.Description.Value);
            copy.Offline.Description.Value = "A change was made";
            Assert.AreNotEqual(offlineCell.Description.Value, copy.Offline.Description.Value);

            RoutingTable copy2 = new RoutingTable(routingTable, false, true);
            Assert.AreEqual(offlineCell.Name.Value, copy2.Offline.Name.Value);
            Assert.AreNotEqual(offlineCell.Description.Identifier, copy2.Offline.Description.Identifier);
            Assert.AreEqual(offlineCell.Description.Value, copy2.Offline.Description.Value);
            copy2.Offline.Description.Value = "A change was made";
            Assert.AreNotEqual(offlineCell.Description.Value, copy2.Offline.Description.Value);
        }
コード例 #53
0
 public void TestOfflineHttpRouting()
 {
     RoutingTable routingTable = new RoutingTable(Guid.Empty, new TranslateableLanguageItem("RoutingName"), ChannelType.HTTP);
     Assert.IsNotNull(routingTable.Offline, "Expected a valid offline routing cell");
 }
コード例 #54
0
ファイル: RoutingHelper.cs プロジェクト: killbug2004/WSProf
        private static IRoutingTable SmtpInternalExternalRoutingTableFactory(string name)
        {
            IRoutingTable routingTable = new RoutingTable(Guid.NewGuid(), new TranslateableLanguageItem(name), ChannelType.SMTP);
            routingTable["resolve"] = new NonTranslateableLanguageItem("emailclient");

            RoutingItemCollection interalGroup = new RoutingItemCollection(Guid.NewGuid(), "Recipients:Internal");
            interalGroup.Add(new Workshare.Policy.ObjectModel.RoutingItem("Recipients:Internal", "Recipients:Internal"));
            interalGroup["InternalGroup"] = new NonTranslateableLanguageItem("true");
            interalGroup["assembly"] = new NonTranslateableLanguageItem("Workshare.InternalExternalResolver.dll");
            interalGroup["class"] = new NonTranslateableLanguageItem("Workshare.Policy.Routing.InternalExternalRouter");
            routingTable.Destinations.Add(interalGroup);

            // creating default sources group
            IRoutingItemCollection defaultSenders = routingTable.DefaultSource;
            defaultSenders.Name.Value = Properties.Resources.ROUTING_EVERYONE;

            // creating external destinations group
            IRoutingItemCollection recipients = routingTable.DefaultDestination;
            recipients.Name.Value = Properties.Resources.ROUTING_EXTERNALRECIPIENTS;
            IRoutingMatrixCell cell = routingTable[defaultSenders, recipients];
            cell.Name = new TranslateableLanguageItem(Properties.Resources.ROUTING_TO + recipients.Name.Value);

            // creating internal destinations group
            recipients = routingTable.Destinations[0];
            recipients.Name.Value = Properties.Resources.ROUTING_INTERNALRECIPIENTS;
            cell = routingTable[defaultSenders, recipients];
            cell.Name = new TranslateableLanguageItem(Properties.Resources.ROUTING_TO + recipients.Name.Value);

            RefreshRoutingMatrixTablePrecedences(routingTable);


            return routingTable;
        }
コード例 #55
0
 public void MatchesUrlWhenTwoRegexesHaveSameNumberOfGroups()
 {
     var target = new RoutingTable();
     var expectedFoo = typeof(int);
     var expectedBar = typeof(string);
     target.Add("/tests/{Id}/foo", expectedFoo);
     target.Add("/tests/{Id}/bar", expectedBar);
     IDictionary<string, string> variables;
     Assert.Equal(expectedFoo, target.Get("/tests/1/foo", out variables));
     Assert.Equal(expectedBar, target.Get("/tests/1/bar", out variables));
 }
コード例 #56
0
        public void TestCreatePolicySetChannelsMasterCataloguePrepopulateRouting()
        {
            string testCatalogue = m_testPath + "TestCreatePolicySetChannelsMasterCatalogue.xml";
            string languageFilename = m_testPath + "TestCreatePolicySetChannelsMasterCatalogueLanguage.xml";
            string policySetFilename = m_testPath + "TestCreatePolicySetChannelsMasterCataloguePolicySet.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.Reset();

            Guid languageId = new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}");
            PolicyLanguageCache.Instance.ActiveLanguageId = languageId;
            IPolicyLanguage language = new PolicyLanguage(languageId, "en");
            language.DefaultLanguage = true;
            languageStore.AddLanguage(language);

            PolicyLanguageCache policyLanguageCache = PolicyLanguageCache.Instance;
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), "New catalogue");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), "New policy set");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), "New policy");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), "Test channel");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{03005F4E-04FC-4287-B2A6-25F877D9C31B}"), "Test sources");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}"), "Test destinations");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), "Test routing table");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), "Test condition group");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), "Test action group");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), "Test data element");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{6197CDBE-9F42-4A61-9369-238355BAB404}"), "Test data element display");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), "Test data item");
            policyLanguageCache.SetLanguageItemText(languageId, new Guid("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "Test action");

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();
            PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore);
            catalogueStore.AddPolicyCatalogue(policyCatalogue);

            IPolicyStore policyStore = new XmlStore();
            IPolicySet policySet = new PolicySet(new Guid("{29EC30A5-1271-4306-89C8-5811172D901A}"), new TranslateableLanguageItem("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), policyStore, policyCatalogue, false);
            IPolicy newPolicy = new P5Policy(policySet, new Guid("{D257D4DC-4A12-438F-A32A-CF1CE4474441}"), new TranslateableLanguageItem("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), PolicyStatus.Active);
            policySet.Policies.Add(newPolicy);

            // Create policy set channel
            PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), ChannelType.SMTP);           

            // Create routing table
            RoutingTable routingTable = new RoutingTable(new Guid("{CDF0252C-3D5D-4AFB-98C2-89CF00FE2175}"), new TranslateableLanguageItem("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), ChannelType.SMTP);
            
            IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "{03005F4E-04FC-4287-B2A6-25F877D9C31B}");
            senders.Add(new RoutingItem(new Guid("{D41A47E2-CC13-46FF-BE83-829625792576}"), "James Brown", "*****@*****.**"));
            senders.Add(new RoutingItem(new Guid("{B031DFE9-54E7-482B-8955-18CFB8F06A40}"), "Nat King Cole", "*****@*****.**"));
            IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}");
            recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**"));
            
            routingTable.Sources.Add(senders);
            routingTable.Destinations.Add(recipients);

            // Assign routing table to channel
            channel.Routing = routingTable;

            // Create action matrix
            ActionMatrix actionMatrix = new ObjectModel.ActionMatrix(false);

            // Create an action matrix cell
            ActionMatrixCell actionMatrixCell = new ObjectModel.ActionMatrixCell(senders, recipients);

            // Populate the action matrix cell
            ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), ConditionLogic.AND, false);
            ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{32D97853-2680-4B02-A391-22CAEE87B017}"), new TranslateableLanguageItem("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), 1);
            IActionConditionGroup actionConditionGroup = new ObjectModel.ActionConditionGroup(conditionGroup, actionGroup, false);

            ObjectModel.Action action = new ObjectModel.Action(new Guid("{5153B00E-7D30-4D37-90F9-75E55AA1B32B}"), new TranslateableLanguageItem("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "TestAction.dll", "Test.Action", RunAt.Client, false, 1); //TODO JE

            DataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), DataType.String, "Not again, when will it ever end!");
            DataElement dataElement = new DataElement(new Guid("{39500989-0B41-4C4E-85DF-CCB4FBD5BEB8}"), new TranslateableLanguageItem("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), new TranslateableLanguageItem("{6197CDBE-9F42-4A61-9369-238355BAB404}"), DataType.String, dataItem);
            action.DataElements.Add(dataElement);
            actionConditionGroup.ActionGroup.Actions.Add(action);

            // Assign the action condition group to the matrix cell
            actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup);

            // Assign the action matrix cell to the action matrix
            actionMatrix[senders, recipients] = actionMatrixCell;

            // Assign action matrix to channel
            channel.Actions = actionMatrix;

            // Assign channel to policy
            newPolicy.Channels.Add(channel);

            // Save everything
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, language.Identifier);
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            policySet.Save();

            TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation);

            IRoutingMatrixCell routingMatrixCell = routingTable[senders, recipients];

            string expectedCatalogueXml = System.IO.File.ReadAllText(testCatalogue);
            expectedCatalogueXml = expectedCatalogueXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogueXml = expectedCatalogueXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper());
            testCatalogue += ".tmp";

            System.IO.File.WriteAllText(testCatalogue, expectedCatalogueXml);

            TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policySet.MasterCatalogue.Identifier));

            string expectedLanguageXml = System.IO.File.ReadAllText(languageFilename);
            expectedLanguageXml = expectedLanguageXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper());
            expectedLanguageXml = expectedLanguageXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper());
            languageFilename += ".tmp";
            System.IO.File.WriteAllText(languageFilename, expectedLanguageXml);

            TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value));
        }
コード例 #57
0
        public void TestAddRoutingPostAddToChannel()
        {
            IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en");

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();
            PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore);
            catalogueStore.AddPolicyCatalogue(policyCatalogue);

            PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue);

            Assert.AreEqual(0, policyCatalogue.Channels.Count);
            Assert.AreEqual(0, policyCatalogue.RoutingTables.Count);
            Assert.AreEqual(0, policyCatalogue.LocationsCollection.Count);
            Assert.AreEqual(0, policyCatalogue.Locations.Count);

            PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP);
            policySetObserver.AddObject(channel);

            IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "Test sources");
            senders.Add(new RoutingItem(new Guid("{D41A47E2-CC13-46FF-BE83-829625792576}"), "James Brown", "*****@*****.**"));
            senders.Add(new RoutingItem(new Guid("{B031DFE9-54E7-482B-8955-18CFB8F06A40}"), "Nat King Cole", "*****@*****.**"));
            IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "Test destinations");
            recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**"));

            RoutingTable routingTable = new RoutingTable(new Guid("{CDF0252C-3D5D-4AFB-98C2-89CF00FE2175}"), new TranslateableLanguageItem("Test routing table"), ChannelType.SMTP);

            routingTable.Sources.Add(senders);
            routingTable.Destinations.Add(recipients);

            channel.Routing = routingTable;

            IRoutingItemCollection recipients2 = new RoutingItemCollection(new Guid("{4E17A792-0CBC-4362-8A82-A1A7FF3C71B0}"), "More test destinations");
            recipients2.Add(new RoutingItem(new Guid("{98CE8CF9-6CF1-4F32-BE4F-C2D381E6C972}"), "why you", "*****@*****.**"));

            routingTable.Destinations.Add(recipients2);

            Assert.AreEqual(1, policyCatalogue.Channels.Count, "Expected one channel");
            Assert.AreEqual(1, policyCatalogue.RoutingTables.Count, "Expected one routing table");
            Assert.AreEqual(3, policyCatalogue.LocationsCollection.Count, "Expected two location groups");
            Assert.AreEqual(4, policyCatalogue.Locations.Count, "Expected three locations");
        }
コード例 #58
0
        public void TestWriteSmtpOfflineRouting()
        {
            string testCatalogue = m_testPath + "TestSmtpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestSmtpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP);
            IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.SMTP);
            IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called
            channel.Routing = routings;
            channels.Add(channel);
            policy.Channels = channels;

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestSmtpOfflineRouting.Catalogue.Modified.xml";
            string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile);
            expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogueFile = expectedCatalogueFile + ".tmp";
            System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue);

            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }
コード例 #59
0
ファイル: RoutingHelper.cs プロジェクト: killbug2004/WSProf
        public static IRoutingTable RoutingTableFactory(string name, Workshare.Policy.ChannelType channelType)
        {
            RoutingTable routingTable = new RoutingTable(Guid.NewGuid(), new TranslateableLanguageItem(name), channelType);

            IRoutingItemCollection defaultSenders = routingTable.DefaultSource;
            defaultSenders.Name.Value = (channelType == ChannelType.Mta) ?
                Properties.Resources.ROUTING_MAILSERVER : Properties.Resources.ROUTING_EVERYONE;

            IRoutingItemCollection defaultRecipients = routingTable.DefaultDestination;
            defaultRecipients.Name.Value = Properties.Resources.ROUTING_EVERYONE;

            IRoutingMatrixCell cell = routingTable[routingTable.DefaultSource, routingTable.DefaultDestination];
            cell.Name = new TranslateableLanguageItem(Properties.Resources.ROUTING_TO + defaultRecipients.Name.Value);

            RefreshRoutingMatrixTablePrecedences(routingTable);

            return routingTable;
        }
コード例 #60
0
        public void TestWriteHttpOfflineRouting()
        {
            string testCatalogue = m_testPath + "TestHttpOfflineRouting.Catalogue.xml";
            string testLanguage = m_testPath + "TestHttpOfflineRouting.Language.xml";

            Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue));

            XmlStore store = new XmlStore();

            Store.IPolicyStoreWriter writer = store.Writer;
            Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer");

            ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false);
            P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active);

            IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>();
            PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP);
            IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.HTTP);
            IRoutingItemCollection defaultSender = routings.DefaultSource;
            IRoutingItemCollection defaultRecipient = routings.DefaultDestination;
            IRoutingMatrixCell routingCell = routings[defaultSender, defaultRecipient];
            IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called
            channel.Routing = routings;
            channels.Add(channel);
            policy.Channels = channels;

            // Persist the changes to the catalogue.
            IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId);
            catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper());
            catalogueWriter.WriteCatalogue(policyCatalogue);
            catalogueWriter.Close();

            string expectedCatalogueFile = m_testPath + "TestHttpOfflineRouting.Catalogue.Modified.xml";
            string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile);
            expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogue = expectedCatalogue.Replace("{73B623E3-7D1A-470B-9C3A-BCE2B4D2B3CD}", defaultSender.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{0FC0FBD3-FC51-4D19-B7CE-04C6A5447E8C}", defaultSender.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{E811E002-16F5-41B6-877E-6C7741529965}", defaultRecipient.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{3D594866-8C44-4896-91FD-A549B6481722}", defaultRecipient.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{6ACC2C34-071A-445E-88A2-4C5B94452E5B}", routingCell.Name.Identifier.ToString("B").ToUpper());
            expectedCatalogue = expectedCatalogue.Replace("{1BE90656-9FF3-4747-960D-176E6183C673}", routingCell.Description.Identifier.ToString("B").ToUpper());

            expectedCatalogueFile = expectedCatalogueFile + ".tmp";
            System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue);

            TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier));
        }