コード例 #1
0
        private void ServiceQueue_1_Writer_n_Readers(ServiceQueueRotationAlgorithm algorithm, int readers)
        {
            using (var serviceQueue = new ServiceQueue(algorithm))
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = GetEndpoint();
                serviceQueue.Bind(endpoint);

                var counterSignal = new CounterSignal(NumberOfMessages, 0);

                for (var i = 0; i < readers; i++)
                {
                    var reader = new ServiceQueueReader();
                    reader.MessageReceived += (s, m) => counterSignal.Increment();

                    reader.Connect(endpoint);
                }

                writer.Connect(endpoint);

                var messageSent = new TestMessage();

                var sw = Stopwatch.StartNew();
                for (var i = 0; i < NumberOfMessages; i++)
                {
                    writer.SendMessage(messageSent);
                }
                Assert.IsTrue(counterSignal.Wait(TimeOut), "Timeout waiting for message");
                sw.Stop();

                Assert.Inconclusive("{0} elapsed reading {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfMessages, NumberOfMessages / sw.Elapsed.TotalSeconds);

            }
        }
コード例 #2
0
        private void ServiceQueue_1_Writer_n_Readers(ServiceQueueRotationAlgorithm algorithm, int readers)
        {
            using (var serviceQueue = new ServiceQueue(algorithm))
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = GetEndpoint();
                    serviceQueue.Bind(endpoint);

                    var counterSignal = new CounterSignal(NumberOfMessages, 0);

                    for (var i = 0; i < readers; i++)
                    {
                        var reader = new ServiceQueueReader();
                        reader.MessageReceived += (s, m) => counterSignal.Increment();

                        reader.Connect(endpoint);
                    }

                    writer.Connect(endpoint);

                    var messageSent = new TestMessage();

                    var sw = Stopwatch.StartNew();
                    for (var i = 0; i < NumberOfMessages; i++)
                    {
                        writer.SendMessage(messageSent);
                    }
                    Assert.IsTrue(counterSignal.Wait(TimeOut), "Timeout waiting for message");
                    sw.Stop();

                    Assert.Inconclusive("{0} elapsed reading {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfMessages, NumberOfMessages / sw.Elapsed.TotalSeconds);
                }
        }
コード例 #3
0
        public void ServiceQueue_connect_Writer_send_multiple_message_received()
        {
            const int count = 1000;

            using (var serviceQueue = new ServiceQueue())
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = new RedFoxEndpoint("/path");

                    var messageFrames = new List <MessageFrame>();
                    var counterSignal = new CounterSignal(count, 0);
                    serviceQueue.MessageFrameReceived += m =>
                    {
                        messageFrames.Add(m);
                        counterSignal.Increment();
                    };

                    serviceQueue.Bind(endpoint);
                    writer.Connect(endpoint);

                    for (var i = 0; i < count; i++)
                    {
                        writer.SendMessage(new TestMessage());
                    }

                    Assert.IsTrue(counterSignal.Wait(TimeSpan.FromSeconds(30)));
                    Assert.AreEqual(count, messageFrames.Count);
                }
        }
コード例 #4
0
        public void ServiceQueue_connect_AddMessageFrame_single_message_received(ServiceQueueRotationAlgorithm rotationAlgorithm)
        {
            var endpoint = new RedFoxEndpoint("/path");

            using (var serviceQueue = new ServiceQueue(rotationAlgorithm))
            using (var serviceQueueReader = new ServiceQueueReader())
            {
                IMessage messageReceived = null;
                var received = new ManualResetEventSlim();
                serviceQueueReader.MessageReceived += (s, m) =>
                {
                    messageReceived = m;
                    received.Set();
                };

                serviceQueue.Bind(endpoint);
                serviceQueueReader.Connect(endpoint);

                var testMessage = new TestMessage();
                var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                serviceQueue.AddMessageFrame(testMessageFrame);

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.AreEqual(testMessage, messageReceived);
            }
        }
コード例 #5
0
        public void ServiceQueue_AddMessageFrame_connect_single_message_received(ServiceQueueRotationAlgorithm rotationAlgorithm)
        {
            var endpoint = new RedFoxEndpoint("/path");

            using (var serviceQueue = new ServiceQueue(rotationAlgorithm))
                using (var serviceQueueReader = new ServiceQueueReader())
                {
                    IMessage messageReceived = null;
                    var      received        = new ManualResetEventSlim();
                    serviceQueueReader.MessageReceived += (s, m) =>
                    {
                        messageReceived = m;
                        received.Set();
                    };

                    var testMessage      = new TestMessage();
                    var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                    serviceQueue.AddMessageFrame(testMessageFrame);

                    serviceQueue.Bind(endpoint);
                    serviceQueueReader.Connect(endpoint);

                    Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                    Assert.AreEqual(testMessage, messageReceived);
                }
        }
コード例 #6
0
        private void FillQueueObject(ServiceQueue queue)
        {
            if (this.IsActivationEnabled != "NotSet")
            {
                if (!String.IsNullOrEmpty(this.ProcedureName))
                {
                    queue.ProcedureName = this.ProcedureName;
                }

                queue.IsActivationEnabled       = Convert.ToBoolean(this.IsActivationEnabled);
                queue.ExecutionContextPrincipal = this.ExecutionContextPrincipal;
                if (queue.IsActivationEnabled)
                {
                    CreateProcedure(m_ProcedureName);
                }
            }

            queue.IsRetentionEnabled = this.IsRetentionEnabled;
            queue.IsEnqueueEnabled   = this.IsEnqueueEnabled;

            if (this.ExecutionContextPrincipal != null)
            {
                queue.ExecutionContextPrincipal = this.ExecutionContextPrincipal;
            }
            if (this.MaxReaders > 0)
            {
                queue.MaxReaders = this.MaxReaders;
            }

            queue.ActivationExecutionContext = this.ActivationExecutionContext;
        }
コード例 #7
0
        public ServiceQueueStatistic(ServiceQueue serviceQueue, IDictionary <DateTime, int> dateIndexer)
        {
            _dateIndexer = dateIndexer;
            AbadonRate   = serviceQueue.AbandonRate / 100.0;

            (_dateIndexer.Count * 96).Self(c =>
            {
                Capacity             = c;
                _ahts                = new double[c];
                _cvs                 = new double[c];
                _weightedSL          = new double[c];
                AssignedStaffing     = new double[c];
                AssignedServiceLevel = new double[c];
                AssignedMaxStaffing  = new double[c];
                //StaffingRequirement = new double[c];
            });

            (_dateIndexer.Count * 24).Self(c =>
            {
                _goals = new double[c];
            });
            _dailyCVs = new double[dateIndexer.Count];
            DailyAssignedServiceLevel = new double[dateIndexer.Count];
            DailyForecastStaffing     = new double[dateIndexer.Count];
            DailyAssignedStaffing     = new double[dateIndexer.Count];


            _hashCode                = serviceQueue.GetHashCode();
            _serviceQueue            = serviceQueue;
            _dailyCalculationActions = new Dictionary <int, Action>();
        }
コード例 #8
0
 public void ServiceQueue_can_bind_multiple_different_endpoints()
 {
     using (var serviceQueue = new ServiceQueue())
     {
         serviceQueue.Bind(new RedFoxEndpoint("/path1"));
         serviceQueue.Bind(new RedFoxEndpoint("/path2"));
     }
 }
コード例 #9
0
 public void ServiceQueue_can_bind_multiple_different_endpoints()
 {
     using (var serviceQueue = new ServiceQueue())
     {
         serviceQueue.Bind(new RedFoxEndpoint("/path1"));
         serviceQueue.Bind(new RedFoxEndpoint("/path2"));
     }
 }
コード例 #10
0
 public void ServiceQueues_bind_same_endpoint_twice_fails()
 {
     using (var serviceQueue = new ServiceQueue())
     {
         var endpoint = new RedFoxEndpoint("/path");
         serviceQueue.Bind(endpoint);
         Assert.Throws <InvalidOperationException>(() => serviceQueue.Bind(endpoint));
     }
 }
コード例 #11
0
        public void AddMessageFrame_single_message_frame_MessageFramesCount_is_one()
        {
            using (var serviceQueue = new ServiceQueue())
            {
                serviceQueue.AddMessageFrame(new MessageFrame());

                Assert.AreEqual(1, serviceQueue.MessageFramesCount);
            }
        }
コード例 #12
0
 public void ServiceQueues_bind_same_endpoint_twice_fails()
 {
     using (var serviceQueue = new ServiceQueue())
     {
         var endpoint = new RedFoxEndpoint("/path");
         serviceQueue.Bind(endpoint);
         Assert.Throws<InvalidOperationException>(() => serviceQueue.Bind(endpoint));
     }
 }
コード例 #13
0
        public void AddMessageFrame_single_message_frame_MessageFramesCount_is_one()
        {
            using (var serviceQueue = new ServiceQueue())
            {
                serviceQueue.AddMessageFrame(new MessageFrame());

                Assert.AreEqual(1, serviceQueue.MessageFramesCount);
            }
        }
コード例 #14
0
 public void two_ServiceQueues_same_endpoint_fails()
 {
     using (var serviceQueue1 = new ServiceQueue())
     using (var serviceQueue2 = new ServiceQueue())
     {
         var endpoint = new RedFoxEndpoint("/path");
         serviceQueue1.Bind(endpoint);
         Assert.Throws<InvalidOperationException>(() => serviceQueue2.Bind(endpoint));
     }
 }
コード例 #15
0
 public void two_ServiceQueues_same_endpoint_fails()
 {
     using (var serviceQueue1 = new ServiceQueue())
         using (var serviceQueue2 = new ServiceQueue())
         {
             var endpoint = new RedFoxEndpoint("/path");
             serviceQueue1.Bind(endpoint);
             Assert.Throws <InvalidOperationException>(() => serviceQueue2.Bind(endpoint));
         }
 }
コード例 #16
0
        public void Create()
        {
            if (!this.ServiceBroker.Queues.Contains(this.FullName))
            {
                // Create queue
                ServiceQueue queue = new ServiceQueue(
                    this.ServiceBroker, this.FullName, "dbo");

                this.FillQueueObject(queue);

                queue.Create();
            }
        }
コード例 #17
0
        public void ServiceQueue_AddMessageFrame_connect_multiple_readers_LoadBalance()
        {
            var endpoint1 = new RedFoxEndpoint("/path1");
            var endpoint2 = new RedFoxEndpoint("/path2");

            using (var serviceQueue = new ServiceQueue(ServiceQueueRotationAlgorithm.LoadBalance))
                using (var serviceQueueReader1 = new ServiceQueueReader())
                    using (var serviceQueueReader2 = new ServiceQueueReader())
                    {
                        const int count   = 1000;
                        var       counter = new CounterSignal(count, 0);

                        var messagesReceived1 = new List <IMessage>();
                        serviceQueueReader1.MessageReceived += (s, m) =>
                        {
                            messagesReceived1.Add(m);
                            counter.Increment();
                        };

                        var messagesReceived2 = new List <IMessage>();
                        serviceQueueReader2.MessageReceived += (s, m) =>
                        {
                            messagesReceived2.Add(m);
                            counter.Increment();
                        };

                        var testMessage      = new TestMessage();
                        var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                        serviceQueue.Bind(endpoint1);
                        serviceQueue.Bind(endpoint2);

                        serviceQueueReader1.Connect(endpoint1);
                        serviceQueueReader2.Connect(endpoint2);

                        for (var i = 0; i < count; i++)
                        {
                            serviceQueue.AddMessageFrame(testMessageFrame);
                        }

                        Assert.IsTrue(counter.Wait());
                        Assert.AreEqual(count, messagesReceived1.Count + messagesReceived2.Count);

                        Assert.AreNotEqual(0, messagesReceived1.Count);
                        Assert.AreNotEqual(0, messagesReceived2.Count);

                        var ratio = (decimal)messagesReceived1.Count / messagesReceived2.Count;
                        Assert.Greater(ratio, 0.9);
                        Assert.Less(ratio, 1.1);
                    }
        }
コード例 #18
0
        public void ServiceQueue_dispose_unbinds_endpoints()
        {
            using (var serviceQueue = new ServiceQueue())
            {
                serviceQueue.Bind(new RedFoxEndpoint("/path1"));
                serviceQueue.Bind(new RedFoxEndpoint("/path2"));
            }

            using (var serviceQueue = new ServiceQueue())
            {
                serviceQueue.Bind(new RedFoxEndpoint("/path1"));
                serviceQueue.Bind(new RedFoxEndpoint("/path2"));
            }
        }
コード例 #19
0
        public void Alter()
        {
            ServiceQueue queue = null;

            if (this.ServiceBroker.Queues.Contains(this.FullName))
            {
                // Create queue
                queue = this.ServiceBroker.Queues[this.FullName];

                this.FillQueueObject(queue);

                queue.Alter();
            }
        }
コード例 #20
0
        public void ServiceQueue_dispose_unbinds_endpoints()
        {
            using (var serviceQueue = new ServiceQueue())
            {
                serviceQueue.Bind(new RedFoxEndpoint("/path1"));
                serviceQueue.Bind(new RedFoxEndpoint("/path2"));
            }

            using (var serviceQueue = new ServiceQueue())
            {
                serviceQueue.Bind(new RedFoxEndpoint("/path1"));
                serviceQueue.Bind(new RedFoxEndpoint("/path2"));
            }
        }
コード例 #21
0
        public void ServiceQueueReader_should_obey_ReceiveTimeout_in_socket_configuration_and_disconnects_on_timeout()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var serviceQueueReader = new ServiceQueueReader())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
                var socketConfiguration = new SocketConfiguration { ReceiveTimeout = TimeSpan.FromMilliseconds(100) };

                serviceQueue.Bind(endpoint);
                serviceQueueReader.Connect(endpoint, socketConfiguration);

                var disconnected = new ManualResetEventSlim();
                serviceQueueReader.Disconnected += disconnected.Set;

                Assert.IsTrue(disconnected.Wait(TimeSpan.FromSeconds(1)));
            }
        }
コード例 #22
0
        public void ServiceQueueReader_should_obey_ReceiveTimeout_in_socket_configuration_and_disconnects_on_timeout()
        {
            using (var serviceQueue = new ServiceQueue())
                using (var serviceQueueReader = new ServiceQueueReader())
                {
                    var endpoint            = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
                    var socketConfiguration = new SocketConfiguration {
                        ReceiveTimeout = TimeSpan.FromMilliseconds(100)
                    };

                    serviceQueue.Bind(endpoint);
                    serviceQueueReader.Connect(endpoint, socketConfiguration);

                    var disconnected = new ManualResetEventSlim();
                    serviceQueueReader.Disconnected += disconnected.Set;

                    Assert.IsTrue(disconnected.Wait(TimeSpan.FromSeconds(1)));
                }
        }
コード例 #23
0
        public void ServiceQueue_AddMessageFrame_connect_multiple_readers_multiple_message_received(ServiceQueueRotationAlgorithm rotationAlgorithm)
        {
            var endpoint = new RedFoxEndpoint("/path");

            using (var serviceQueue = new ServiceQueue(rotationAlgorithm))
                using (var serviceQueueReader1 = new ServiceQueueReader())
                    using (var serviceQueueReader2 = new ServiceQueueReader())
                    {
                        const int count   = 1000;
                        var       counter = new CounterSignal(count, 0);

                        var messagesReceived1 = new List <IMessage>();
                        serviceQueueReader1.MessageReceived += (s, m) =>
                        {
                            messagesReceived1.Add(m);
                            counter.Increment();
                        };

                        var messagesReceived2 = new List <IMessage>();
                        serviceQueueReader2.MessageReceived += (s, m) =>
                        {
                            messagesReceived2.Add(m);
                            counter.Increment();
                        };

                        var testMessage      = new TestMessage();
                        var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                        for (var i = 0; i < count; i++)
                        {
                            serviceQueue.AddMessageFrame(testMessageFrame);
                        }

                        serviceQueue.Bind(endpoint);

                        serviceQueueReader1.Connect(endpoint);
                        serviceQueueReader2.Connect(endpoint);

                        Assert.IsTrue(counter.Wait(TimeSpan.FromSeconds(10)));
                        Assert.AreEqual(count, messagesReceived1.Count + messagesReceived2.Count);
                    }
        }
コード例 #24
0
        public void ServiceQueue_connect_Writer_send_single_message_MessageFramesCount_is_one()
        {
            using (var serviceQueue = new ServiceQueue())
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = new RedFoxEndpoint("/path");

                    var received = new ManualResetEventSlim();
                    serviceQueue.MessageFrameReceived += m => received.Set();

                    serviceQueue.Bind(endpoint);
                    writer.Connect(endpoint);

                    Assert.AreEqual(0, serviceQueue.MessageFramesCount);
                    writer.SendMessage(new TestMessage());

                    Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                    Assert.AreEqual(1, serviceQueue.MessageFramesCount);
                }
        }
コード例 #25
0
        public void ServiceQueue_connect_Writer_send_single_message_MessageFramesCount_is_one()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                var received = new ManualResetEventSlim();
                serviceQueue.MessageFrameReceived += m => received.Set();

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                Assert.AreEqual(0, serviceQueue.MessageFramesCount);
                writer.SendMessage(new TestMessage());

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.AreEqual(1, serviceQueue.MessageFramesCount);
            }
        }
コード例 #26
0
        public ServiceQueueConfiguration(string fullName, ServiceBroker serviceBroker)
            : base(serviceBroker)
        {
            if (this.ServiceBroker.Queues.Contains(fullName))
            {
                ServiceQueue item = this.ServiceBroker.Queues[fullName];


                base.Urn = new Uri(base.Urn.ToString() + "queue/");

                m_Name = item.Name.Substring
                             (base.Urn.ToString().Length, item.Name.Length - base.Urn.ToString().Length);

                m_IsActivationEnabled        = item.IsActivationEnabled.ToString();
                m_IsRetentionEnabled         = item.IsRetentionEnabled;
                m_IsEnqueueEnabled           = item.IsEnqueueEnabled;
                m_ProcedureName              = item.ProcedureName;
                m_MaxReaders                 = item.MaxReaders;
                m_ActivationExecutionContext = item.ActivationExecutionContext;
            }
        }
コード例 #27
0
        static void RetrieveAndLoadObjects(SSBIServer s, Database db, TreeNode tnode, SsbEnum ssbType)
        {
            ICollection coll = smo.GetSSBObjects2(s, db, ssbType);
            IEnumerator en   = coll.GetEnumerator();

            while (en.MoveNext())
            {
                TreeNode tn = new TreeNode();
                tn.Text = en.Current.ToString();
                tn.Tag  = en.Current;
                tnode.Nodes.Add(tn);
            }
            if (ssbType == SsbEnum.Queu)
            {
                TreeNode     tn  = new TreeNode();
                ServiceQueue txQ = new ServiceQueue();
                //txQ.Parent.Parent = GetDatabaseFromTag(tn.Parent);
                txQ.Name = "sys.transmission_queue";
                tn.Text  = txQ.Name;
                tn.Tag   = txQ;
                tnode.Nodes.Add(tn);
            }
        }
コード例 #28
0
        public void ServiceQueue_connect_Writer_send_single_message_received_fires_MessageFrameReceived_event()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                MessageFrame messageFrame = null;
                var received = new ManualResetEventSlim();
                serviceQueue.MessageFrameReceived += m =>
                {
                    messageFrame = m;
                    received.Set();
                };

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                writer.SendMessage(new TestMessage());

                Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                Assert.IsNotNull(messageFrame);
            }
        }
コード例 #29
0
        public void ServiceQueue_connect_Writer_send_single_message_received_fires_MessageFrameReceived_event()
        {
            using (var serviceQueue = new ServiceQueue())
                using (var writer = new ServiceQueueWriter())
                {
                    var endpoint = new RedFoxEndpoint("/path");

                    MessageFrame messageFrame = null;
                    var          received     = new ManualResetEventSlim();
                    serviceQueue.MessageFrameReceived += m =>
                    {
                        messageFrame = m;
                        received.Set();
                    };

                    serviceQueue.Bind(endpoint);
                    writer.Connect(endpoint);

                    writer.SendMessage(new TestMessage());

                    Assert.IsTrue(received.Wait(TimeSpan.FromSeconds(1)));
                    Assert.IsNotNull(messageFrame);
                }
        }
コード例 #30
0
        public void ServiceQueue_AddMessageFrame_connect_multiple_readers_multiple_message_received(ServiceQueueRotationAlgorithm rotationAlgorithm)
        {
            var endpoint = new RedFoxEndpoint("/path");

            using (var serviceQueue = new ServiceQueue(rotationAlgorithm))
            using (var serviceQueueReader1 = new ServiceQueueReader())
            using (var serviceQueueReader2 = new ServiceQueueReader())
            {
                const int count = 1000;
                var counter = new CounterSignal(count, 0);

                var messagesReceived1 = new List<IMessage>();
                serviceQueueReader1.MessageReceived += (s, m) =>
                {
                    messagesReceived1.Add(m);
                    counter.Increment();
                };

                var messagesReceived2 = new List<IMessage>();
                serviceQueueReader2.MessageReceived += (s, m) =>
                {
                    messagesReceived2.Add(m);
                    counter.Increment();
                };

                var testMessage = new TestMessage();
                var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                for (var i = 0; i < count; i++)
                    serviceQueue.AddMessageFrame(testMessageFrame);

                serviceQueue.Bind(endpoint);

                serviceQueueReader1.Connect(endpoint);
                serviceQueueReader2.Connect(endpoint);

                Assert.IsTrue(counter.Wait(TimeSpan.FromSeconds(10)));
                Assert.AreEqual(count, messagesReceived1.Count + messagesReceived2.Count);
            }
        }
コード例 #31
0
        public void ServiceQueue_connect_Writer_send_multiple_message_received()
        {
            const int count = 1000;

            using (var serviceQueue = new ServiceQueue())
            using (var writer = new ServiceQueueWriter())
            {
                var endpoint = new RedFoxEndpoint("/path");

                var messageFrames = new List<MessageFrame>();
                var counterSignal = new CounterSignal(count, 0);
                serviceQueue.MessageFrameReceived += m =>
                {
                    messageFrames.Add(m);
                    counterSignal.Increment();
                };

                serviceQueue.Bind(endpoint);
                writer.Connect(endpoint);

                for (var i = 0; i < count; i++)
                    writer.SendMessage(new TestMessage());

                Assert.IsTrue(counterSignal.Wait(TimeSpan.FromSeconds(30)));
                Assert.AreEqual(count, messageFrames.Count);
            }
        }
コード例 #32
0
        private void FillQueueObject(ServiceQueue queue)
        {
            if (this.IsActivationEnabled != "NotSet")
            {
                if (!String.IsNullOrEmpty(this.ProcedureName))
                {
                    queue.ProcedureName = this.ProcedureName;
                }

                queue.IsActivationEnabled = Convert.ToBoolean(this.IsActivationEnabled);
                queue.ExecutionContextPrincipal = this.ExecutionContextPrincipal;
                if (queue.IsActivationEnabled)
                {
                    CreateProcedure(m_ProcedureName);
                }
            }

            queue.IsRetentionEnabled = this.IsRetentionEnabled;
            queue.IsEnqueueEnabled = this.IsEnqueueEnabled;

            if (this.ExecutionContextPrincipal != null)
                queue.ExecutionContextPrincipal = this.ExecutionContextPrincipal;
            if (this.MaxReaders > 0)
                queue.MaxReaders = this.MaxReaders;

            queue.ActivationExecutionContext = this.ActivationExecutionContext;
        }
コード例 #33
0
        public void Create()
        {
            if (!this.ServiceBroker.Queues.Contains(this.FullName))
            {
                // Create queue
                ServiceQueue queue = new ServiceQueue(
                    this.ServiceBroker, this.FullName, "dbo");

                this.FillQueueObject(queue);

                queue.Create();
            }
        }
コード例 #34
0
ファイル: TreeViewStuff.cs プロジェクト: nberglund/ssbadmin
 static void RetrieveAndLoadObjects(SSBIServer s, Database db, TreeNode tnode, SsbEnum ssbType)
 {
     ICollection coll = smo.GetSSBObjects2(s, db, ssbType);
       IEnumerator en = coll.GetEnumerator();
       while (en.MoveNext()) {
     TreeNode tn = new TreeNode();
     tn.Text = en.Current.ToString();
     tn.Tag = en.Current;
     tnode.Nodes.Add(tn);
       }
       if (ssbType == SsbEnum.Queu) {
     TreeNode tn = new TreeNode();
     ServiceQueue txQ = new ServiceQueue();
     //txQ.Parent.Parent = GetDatabaseFromTag(tn.Parent);
     txQ.Name = "sys.transmission_queue";
     tn.Text = txQ.Name;
     tn.Tag = txQ;
     tnode.Nodes.Add(tn);
       }
 }
コード例 #35
0
ファイル: smo.cs プロジェクト: nberglund/ssbadmin
        internal static object GetObject2(SSBIServer s, Database db, string objName, SsbEnum index)
        {
            object smob = null;
              Server serv = null;
              Database db2 = null;
              ServiceBroker sb = null;
              try {

            serv = CreateServer2(s);
            s.SMOServer = serv;
            if (db != null) {
              db2 = serv.Databases[db.Name];
              sb = serv.Databases[db2.Name].ServiceBroker;
            }

            switch (index) {

              case SsbEnum.Server:
            smob = s;
            break;

              case SsbEnum.Database:
            db2 = serv.Databases[objName];
            smob = new SSBIDatabase(db2);
            //serv.ConnectionContext.Disconnect();
            break;

              case SsbEnum.MessageType:
            smob = sb.MessageTypes[objName];
            break;

              case SsbEnum.Contract:
            smob = sb.ServiceContracts[objName];
            break;

              case SsbEnum.Service:
            smob = sb.Services[objName];
            break;

              case SsbEnum.Queu:
            if(objName == "sys.transmission_queue") {
              ServiceQueue txQ = new ServiceQueue();
              txQ.Name = "sys.transmission_queue";
              txQ.Parent = sb;
              txQ.Schema = "sys";
              smob = txQ;
            }
            else
              smob = sb.Queues[objName];
            break;

              case SsbEnum.Route:
            smob = sb.Routes[objName];
            break;

              case SsbEnum.RemoteBinding:
            smob = sb.RemoteServiceBindings[objName];
            break;

              case SsbEnum.Conversation:
            smob = smo.GetConversationCollection(db, null, new Guid(objName)).Item(0);
            break;

            }

            if (smob == null) {
              string errMsg = string.Format("Can not retrieve {0}: {1}.\nIt may have been dropped/deleted.", index.ToString(), objName);
              throw new ApplicationException(errMsg);
            }

            return smob;
              }

              catch (NullReferenceException) {
            if (serv != null && db2 == null) {
              throw new ApplicationException(string.Format("Can not connect to database: {0}.\nIt may have been dropped/deleted.", db.Name));

            }

            return null;

              }

              catch (ConnectionFailureException e) {
            throw e;
            return null;
              }
              finally {
            serv.ConnectionContext.Disconnect();

              }
        }
コード例 #36
0
ファイル: Form2.cs プロジェクト: nberglund/ssbadmin
        int UpDateSsb()
        {
            updatedobj = null;
              //if (!isDirty)
            //return 0;
              if (!ValidateData()) {
            Cursor crs = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            try {
              Database db = null;

              ServiceBroker sb = null;
              if (ssbType != SsbEnum.Database && ssbType != SsbEnum.Login && ssbType != SsbEnum.EndPoint) {
             sb = dBase.ServiceBroker;
              }
              switch (ssbType) {
            case SsbEnum.Database:
              MasterKey mk = null;
              SSBIDatabase sbd = null;
              if (isEdit) {
                sbd = (SSBIDatabase)objToUpdate;
                db = sbd.DataBase;
              }
              else {
                db = new Database();
                db.Name = txtName.Text;
                db.Parent = dbServ.SMOServer;
              }

              if (isEdit) {
               if(db.MasterKey != null && db_chkMasterKey.Checked == false) {
                 mk = db.MasterKey;
                 mk.Drop();

               }
               else if (db.MasterKey == null && db_chkMasterKey.Checked) {
                 mk = new MasterKey();
                 mk.Parent = db;
                 mk.Create(db_txtMkPwd.Text);
               }

               db.Alter();
               if (sbd.IsTrustworthy != db_chkTrustWorthy.Checked)
                 sbd.IsTrustworthy = db_chkTrustWorthy.Checked;

              }
              else {
                db.Create();
                sbd = new SSBIDatabase(db);

                if (db_chkMasterKey.Checked) {
                  mk = new MasterKey();
                  mk.Parent = db;
                  mk.Create(db_txtMkPwd.Text);

                }

                if (db_chkTrustWorthy.Checked) {
                  sbd.IsTrustworthy = true;
                }

              }
              if (dBase == null)
                dBase = db;

              //Server serv = db.Parent;

              updatedobj = db;
              break;
            case SsbEnum.MessageType:
              MessageType mt = null;
              if (isEdit)
                mt = (MessageType)objToUpdate;
              else {
                mt = new MessageType();
                mt.Parent = sb;
                mt.Name = txtName.Text;
              }
              if (cboUser.Text != string.Empty)
                mt.Owner = cboUser.Text;
              mt.MessageTypeValidation = (MessageTypeValidation)Enum.Parse(typeof(MessageTypeValidation), cboVal.Text);
              if (cboValSchema.Enabled)
                mt.ValidationXmlSchemaCollection = cboValSchema.Text;

              if (isEdit)
                mt.Alter();
              else
                mt.Create();
              updatedobj = mt;
              break;

            case SsbEnum.Contract:
              ServiceContract sc = new ServiceContract();
              sc.Parent = sb;
              sc.Name = txtName.Text;
              if (cboUser.Text != string.Empty)
                sc.Owner = cboUser.Text;
              //get the message types
              foreach (DataGridViewRow row in dvMsgTypes.Rows) {
                sc.MessageTypeMappings.Add(new MessageTypeMapping(sc, row.Cells[0].Value.ToString(), (MessageSource)Enum.Parse(typeof(MessageSource), row.Cells[1].Value.ToString())));
              }

              if (isEdit)
                sc.Alter();
              else
                sc.Create();

              updatedobj = sc;
              break;

            case SsbEnum.Queu:
              ServiceQueue q = null;
              if (isEdit)
                q = (ServiceQueue)objToUpdate;
              else {
                q = new ServiceQueue();
                q.Parent = sb;
                q.Name = txtName.Text;
              }
              q.IsEnqueueEnabled = chkStatus.Checked;
              if (chkRetention.Checked)
                q.IsRetentionEnabled = true;

              //if (chkActivation.Checked) {
              //if(isEdit)
              //  q.IsActivationEnabled = chkActivation.Checked;
              //
              if (chkActivation.Checked) {
                q.IsActivationEnabled = chkActivation.Checked;
                if (dBase.Name != cboQDb.Text)
                  q.ProcedureDatabase = cboQDb.Text;
                StoredProcedure sp = (StoredProcedure)cboProc.SelectedItem;
                q.ProcedureSchema = sp.Schema;
                q.ProcedureName = cboProc.Text;
                q.MaxReaders = short.Parse(txtReaders.Text);
                if (rdOwner.Checked)
                  q.ActivationExecutionContext = ActivationExecutionContext.Owner;
                else if (rdSelf.Checked)
                  q.ActivationExecutionContext = ActivationExecutionContext.Self;
                else if (rdUser.Checked) {
                  q.ActivationExecutionContext = ActivationExecutionContext.ExecuteAsUser;
                  q.ExecutionContextPrincipal = txtExecuteAs.Text;
                }

              }

              if (isEdit)
                q.Alter();
              else
                q.Create();

              updatedobj = q;

              break;

            case SsbEnum.Service:
              BrokerService bserv = null;
              if (isEdit)
                bserv = (BrokerService)objToUpdate;
              else {
                bserv = new BrokerService();
                bserv.Parent = sb;
                bserv.Name = txtName.Text;
              }
              if (cboUser.Text != string.Empty)
                bserv.Owner = cboUser.Text;

              ServiceQueue servq = (ServiceQueue)cboQueue.SelectedItem;
              bserv.QueueName = servq.Name;
              bserv.QueueSchema = servq.Schema;

              if (lbChosenCtr.Items.Count > 0) {
                foreach (object o in lbChosenCtr.Items) {
                  ServiceContract servctr = o as ServiceContract;
                  ServiceContractMapping scm = new ServiceContractMapping(bserv, servctr.Name);
                  bserv.ServiceContractMappings.Add(scm);
                }
              }

              if (isEdit)
                bserv.Alter();
              else
                bserv.Create();

              updatedobj = bserv;

              break;

            case SsbEnum.Route:
              ServiceRoute srt = null;
              if (isEdit)
                srt = (ServiceRoute)objToUpdate;
              else {
                srt = new ServiceRoute();
                srt.Name = txtName.Text;
                srt.Parent = sb;
              }

              if (cboUser.Text != string.Empty)
                srt.Owner = cboUser.Text;

              if (textBroker.Text != string.Empty)
                srt.BrokerInstance = textBroker.Text;

              if (textRemote.Text != string.Empty)
                srt.RemoteService = textRemote.Text;

              if (textLifeTime.Text != string.Empty)
                srt.ExpirationDate = DateTime.Parse(textLifeTime.Text);

              if (rdLocal.Checked)
                srt.Address = "LOCAL";

              if (rdTransport.Checked)
                srt.Address = "TRANSPORT";

              if (rdTCP.Checked)
                srt.Address = "TCP://" + txtAddress.Text;

              if (txtMirror.Text != string.Empty)
                srt.MirrorAddress = "TCP://" + txtMirror.Text;

              //StringCollection sColl = srt.Script();
              //foreach (string s in sColl)
              //  MessageBox.Show(s);

              if (isEdit)
                srt.Alter();
              else
                srt.Create();

              updatedobj = srt;

              break;

            case SsbEnum.RemoteBinding:
              RemoteServiceBinding remBind = null;
              if (isEdit)
                remBind = (RemoteServiceBinding)objToUpdate;
              else {
                remBind = new RemoteServiceBinding();
                remBind.Name = txtName.Text;
                remBind.Parent = sb;
              }

              if (cboUser.Text != string.Empty)
                remBind.Owner = cboUser.Text;

              remBind.RemoteService = textRemServ.Text;

              remBind.CertificateUser = cboRemUser.Text;
              remBind.IsAnonymous = chkAnon.Checked;

              StringCollection sColl = remBind.Script();
              foreach (string s in sColl)
                MessageBox.Show(s);

              if (isEdit)
                remBind.Alter();
              else
                remBind.Create();

              updatedobj = remBind;

              break;

            case SsbEnum.Conversation:
              TimeSpan ts = TimeSpan.Zero;
              Guid grpHandle = Guid.Empty;
              string convContract = "DEFAULT";
              BrokerService bServ = (BrokerService)cnv_cboFrmServ.SelectedItem;

              string toService = cnv_txtToSrv.Text;

              if (cnv_txtLifetime.Text != string.Empty && cnv_txtLifetime.Text != "0")
                ts = TimeSpan.FromSeconds(double.Parse(cnv_txtLifetime.Text));

              if (cnv_cboContract.Text != string.Empty)
                convContract = cnv_cboContract.Text;

              if (cnv_txtRelGrpHndl.Text != string.Empty)
                grpHandle = new Guid(cnv_txtRelGrpHndl.Text);

              //get a service object
              Service smoserv = smo.GetSSBIService(bServ.Parent.Parent, bServ.Name);
              if (smoserv.Connection.State == ConnectionState.Closed)
                smoserv.Connection.Open();

              smoserv.Connection.ChangeDatabase(bServ.Parent.Parent.Name);
              updatedobj = smoserv.BeginDialog(toService, convContract, ts, cnv_chkEncryption.Checked, grpHandle);
              break;

            case SsbEnum.Message:
              SSBIConversation msgConv = (SSBIConversation)msg_cboConv.SelectedItem;
              string servName = msg_txtFrom.Text;
              //we need a service object
              Service msgSsbiServ = smo.GetSSBIService(dBase, msgConv.FromService);
              if (msgSsbiServ.Connection.State== ConnectionState.Closed)
                 msgSsbiServ.Connection.Open();

               msgSsbiServ.Connection.ChangeDatabase(dBase.Name);
              Conversation msgCnv = new Conversation(msgSsbiServ, msgConv.Handle);
              string msgType = msg_cboMsgType.SelectedText;
              string msgString = msg_rchMsg.Text;
              msgType = msg_cboMsgType.Text;
              MemoryStream msgBody = new MemoryStream(Encoding.ASCII.GetBytes(msgString));

              Microsoft.Samples.SqlServer.Message msg = new Microsoft.Samples.SqlServer.Message(msgType, msgBody);
              msgCnv.Send(msg);

              break;

            case SsbEnum.Login :
              string pwd = "";
              Login lg = new Login();
              lg.Parent = dbServ.SMOServer;
              lg.Name = lgn_txtLoginName.Text;
              if (lgn_rdSql.Checked) {
                pwd = lgn_txtPwd.Text;
                lg.PasswordPolicyEnforced = lgn_chkEnforcePolicy.Checked;
                lg.LoginType = LoginType.SqlLogin;
                lg.Create(pwd);
              }
              else {
                lg.Create();
              }

              updatedobj = lg;
              break;

            case SsbEnum.Certificate:
              string certOwner  = "dbo";
              int certSource = cert_cboSource.SelectedIndex;
              Certificate cert = new Certificate();
              if(!isEdit) {
                cert.Name = txtName.Text;
                if(cboUser.Text != "")
                  certOwner = cboUser.Text;
                cert.Parent = dBase;
                cert.Owner = certOwner;

              }

              cert.ActiveForServiceBrokerDialog = cert_chkBeginDlg.Checked;

              if (certSource == 0) {
                if (!isEdit) {
                  if (cert_chkMasterKey.Checked)
                    cert.Create(cert_txtCertPath.Text, CertificateSourceType.File, cert_txtPrivPath.Text, cert_txtDecrypt.Text);
                  else
                    cert.Create(cert_txtCertPath.Text, CertificateSourceType.File, cert_txtPrivPath.Text, cert_txtDecrypt.Text, cert_txtEncrypt.Text);

                }
              }
              else if (certSource == 1) {
                if (!isEdit) {
                  cert.StartDate = cert_dtValidFrom.Value;
                  cert.ExpirationDate = cert_dtExpiry.Value;
                  cert.Subject = cert_txtCertPath.Text;

                  if (cert_chkMasterKey.Checked) {
                    cert.Create();
                  }
                  else {
                    cert.Create(cert_txtEncrypt.Text);
                  }
                }

              }
              else if (certSource == 2) {
                if (!isEdit) {
                  cert.Create(cert_txtCertPath.Text, CertificateSourceType.File);
                }

              }

              if (isEdit)
                cert.Alter();

              updatedobj = cert;
              break;

            case SsbEnum.User :
              User usr;
              if (!isEdit) {
                usr = new User();
                usr.Name = txtName.Text;
                usr.Parent = dBase;
                if(usr_chkLogin.Checked)
                  usr.Login = usr_cboLogin.Text;

              }
              else
                usr = (User)objToUpdate;

              if (usr_cboCerts.SelectedIndex != -1)
                usr.Certificate = usr_cboCerts.Text;

              if (!isEdit)
                if (usr_chkLogin.Checked)
                  usr.Create();
                else
                  smo.CreateUserWithNoLogin(usr);

              else
                usr.Alter();
              updatedobj = usr;
              break;

            case SsbEnum.EndPoint :
              Endpoint ep = null;
              if (!isEdit) {
                ep = new Endpoint();
                ep.Name = txtName.Text;
                ep.Parent = dbServ.SMOServer;
                ep.ProtocolType = ProtocolType.Tcp;
                ep.EndpointType = EndpointType.ServiceBroker;
              }
              else
                ep = ((SSBIEndpoint)objToUpdate).EndPoint;

              ep.Protocol.Tcp.ListenerPort = int.Parse(ep_txtPort.Text);
              if (ep_txtIp.Text == "ALL")
                ep.Protocol.Tcp.ListenerIPAddress = System.Net.IPAddress.Any;
              else {
                ep.Protocol.Tcp.ListenerIPAddress = System.Net.IPAddress.Parse(ep_txtIp.Text);
              }
              ep.Payload.ServiceBroker.EndpointAuthenticationOrder = (EndpointAuthenticationOrder)ep_cboAuth.SelectedItem;
              if (ep_cboCert.SelectedIndex != -1)
                ep.Payload.ServiceBroker.Certificate = ep_cboCert.Text;

              ep.Payload.ServiceBroker.EndpointEncryption = (EndpointEncryption)ep_cboEncrypt.SelectedItem;
              if (ep_cboAlgorithm.SelectedIndex != -1)
                ep.Payload.ServiceBroker.EndpointEncryptionAlgorithm = (EndpointEncryptionAlgorithm)ep_cboAlgorithm.SelectedItem;

              ep.Payload.ServiceBroker.IsMessageForwardingEnabled = ep_chkFwd.Checked;

              if (ep_txtSize.Text != string.Empty)
                ep.Payload.ServiceBroker.MessageForwardingSize = int.Parse(ep_txtSize.Text);

              if(!isEdit)
                ep.Create();

              switch ((EndpointState)ep_cboState.SelectedIndex) {
                case EndpointState.Disabled :
                  ep.Disable();
                  break;

                case EndpointState.Started :
                  ep.Start();
                  break;
                case EndpointState.Stopped :
                  if (isEdit)
                    ep.Stop();
                  break;
              }

              if (isEdit)
                ep.Alter();

              break;

            case SsbEnum.CreateListing :
              CreateListing(true);

              break;

              }

              if (isEdit)
            _state = SsbState.Edited;
              else
            _state = SsbState.New;

              Cursor.Current = crs;

              this.DialogResult = DialogResult.OK;

              ExitAndClose();

            }
            catch (FailedOperationException e) {
              smo.ShowException(e);
            }
            catch (Exception ex) {
              smo.ShowException(ex);
            }

            finally {
              if(dbServ !=null)
            dbServ.SMOServer.ConnectionContext.Disconnect();

            }

              }

              return 0;
        }
コード例 #37
0
        public void ServiceQueue_AddMessageFrame_connect_multiple_readers_LoadBalance()
        {
            var endpoint1 = new RedFoxEndpoint("/path1");
            var endpoint2 = new RedFoxEndpoint("/path2");

            using (var serviceQueue = new ServiceQueue(ServiceQueueRotationAlgorithm.LoadBalance))
            using (var serviceQueueReader1 = new ServiceQueueReader())
            using (var serviceQueueReader2 = new ServiceQueueReader())
            {
                const int count = 1000;
                var counter = new CounterSignal(count, 0);

                var messagesReceived1 = new List<IMessage>();
                serviceQueueReader1.MessageReceived += (s, m) =>
                {
                    messagesReceived1.Add(m);
                    counter.Increment();
                };

                var messagesReceived2 = new List<IMessage>();
                serviceQueueReader2.MessageReceived += (s, m) =>
                {
                    messagesReceived2.Add(m);
                    counter.Increment();
                };

                var testMessage = new TestMessage();
                var testMessageFrame = new MessageFrameCreator(DefaultMessageSerialization.Instance).CreateFromMessage(testMessage);

                serviceQueue.Bind(endpoint1);
                serviceQueue.Bind(endpoint2);

                serviceQueueReader1.Connect(endpoint1);
                serviceQueueReader2.Connect(endpoint2);

                for (var i = 0; i < count; i++)
                    serviceQueue.AddMessageFrame(testMessageFrame);

                Assert.IsTrue(counter.Wait());
                Assert.AreEqual(count, messagesReceived1.Count + messagesReceived2.Count);

                Assert.AreNotEqual(0, messagesReceived1.Count);
                Assert.AreNotEqual(0, messagesReceived2.Count);

                var ratio = (decimal)messagesReceived1.Count / messagesReceived2.Count;
                Assert.Greater(ratio, 0.9);
                Assert.Less(ratio, 1.1);
            }
        }
コード例 #38
0
ファイル: smo.cs プロジェクト: nberglund/ssbadmin
        internal static SSBIMessageCollection GetMessageCollection(BrokerService bServ, Database db, Guid handle, ServiceQueue q)
        {
            string sqlConn = string.Format("server={0};database={1};Integrated Security='SSPI';", db.Parent.Name, db.Name);
              string schema;
              string qName;

              string sqlExec = @"select q.conversation_group_id,
                                       q.conversation_handle,
                                               q.message_sequence_number,
                                       q.service_name,
                                       se.far_service,
                                       q.service_contract_name,
                                               q.message_type_name,
                                       q.validation, message_body
                                       from {0}.{1} q
                                       join sys.conversation_endpoints se
                                       on q.conversation_handle = se.conversation_handle";
                                       //where se.state in ('SO','SI','CO')";

              SqlConnection conn = CreateNewConnection(db);
              SqlCommand cmd = conn.CreateCommand();

              if (bServ == null && q != null) {
            schema = q.Schema;
            qName = q.Name;
              }
              else {
            schema = bServ.QueueSchema;
            qName = bServ.QueueName;
            sqlExec += " and q.service_id = @id";
            int id = bServ.ID;
            cmd.Parameters.Add("@id", SqlDbType.Int, 4);
            cmd.Parameters["@id"].Value = id;
              }

              if (handle != Guid.Empty) {
            sqlExec += " and q.conversation_handle = @h";
            cmd.Parameters.Add("@h", SqlDbType.UniqueIdentifier);
            cmd.Parameters["@h"].Value = handle;
              }

              sqlExec = string.Format(sqlExec, schema, qName);

             cmd.CommandText = sqlExec;

              if (conn.Database != db.Name)
            conn.ChangeDatabase(db.Name);

              SqlDataReader reader = cmd.ExecuteReader();
              SSBIMessageCollection scColl = new SSBIMessageCollection();
              while (reader.Read()) {
            Guid cnvHandle;
            SSBIMessage msg = new SSBIMessage();
            msg.ConversationGroupId = reader.GetGuid(0);
            cnvHandle = reader.GetGuid(1);
            msg.ConversationHandle = cnvHandle;
            //msg.Conversation = new Conversation(srv, cnvHandle);
            msg.SequenceNumber = reader.GetInt64(2);
            msg.RemoteServiceName = reader.GetString(4);
            msg.ServiceName = reader.GetString(3);
            msg.ContractName = reader.GetString(5);
            msg.Type = reader.GetString(6);
            msg.Validation = reader.GetString(7);
            if (!reader.IsDBNull(8)) {
              SqlBytes sb = reader.GetSqlBytes(8);
              msg.Body = sb.Stream;

            }
            else
              msg.Body = null;

            scColl.Add(msg);
              }

              conn.Close();

              return scColl;
        }