예제 #1
0
        public static OfflineBehavior TranslateToOfflineBehavior(object offlineBehavior)
        {
            OfflineBehavior properBehavior      = new OfflineBehavior();
            Type            offlineBehaviorType = offlineBehavior.GetType();

            PropertyInfo expirationProperty = offlineBehaviorType.GetProperty("Expiration");

            if (expirationProperty != null)
            {
                properBehavior.Expiration = (DateTime?)expirationProperty.GetValue(offlineBehavior, null);
            }
            PropertyInfo stampsProperty = offlineBehaviorType.GetProperty("Stamps");

            if (stampsProperty != null)
            {
                properBehavior.Stamps = (int)stampsProperty.GetValue(offlineBehavior, null);
            }
            PropertyInfo maxRetriesProperty = offlineBehaviorType.GetProperty("MaxRetries");

            if (maxRetriesProperty != null)
            {
                properBehavior.MaxRetries = (int)maxRetriesProperty.GetValue(offlineBehavior, null);
            }
            PropertyInfo tagProperty = offlineBehaviorType.GetProperty("Tag");

            if (tagProperty != null)
            {
                properBehavior.Tag = (string)tagProperty.GetValue(offlineBehavior, null);
            }

            return(properBehavior);
        }
        /// <summary>
        /// Enqueues a request to the <c>GetMenuItems</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetMenuItems(String restaurantId, OfflineBehavior behavior)
        {
            behavior.ReturnCallback    = new CommandCallback(typeof(Callback), "OnGetMenuItemsReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetMenuItemsException");

            return(EnqueueRequest("GetMenuItems", behavior, restaurantId));
        }
예제 #3
0
        /// <summary>
        /// Enqueues a request to the <c>Add</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid Add(Int32 a, Int32 b, OfflineBehavior behavior)
        {
            behavior.ReturnCallback    = new CommandCallback(typeof(IntegerCalculatorServiceDisconnectedAgentCallback), "OnAddReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(IntegerCalculatorServiceDisconnectedAgentCallback), "OnAddException");

            return(EnqueueRequest("Add", behavior, a, b));
        }
예제 #4
0
        public void CreateOnlineProxyAndInvokeResultsInRequestInQueue()
        {
            MockRequestQueue queue = new MockRequestQueue();

            OfflineMockService proxy = new OfflineMockService(queue);

            proxy.DoWithNoParams();

            Request r = queue.GetNextRequest();

            Assert.AreEqual("DoWithNoParams", r.MethodName);
            Assert.AreEqual("MockService", r.Endpoint);
            Assert.AreSame(typeof(MockService), r.OnlineProxyType);

            OfflineBehavior defaultBehavior = new OfflineBehavior();

            defaultBehavior.Expiration        = null;
            defaultBehavior.MaxRetries        = 1;
            defaultBehavior.ReturnCallback    = new CommandCallback(typeof(OfflineMockServiceCallbacks), "DoWithNoParamsCallback");
            defaultBehavior.ExceptionCallback = new CommandCallback(typeof(OfflineMockServiceCallbacks), "OfflineCallFailed");
            defaultBehavior.Stamps            = 3;
            defaultBehavior.Tag = "";

            Assert.AreEqual(defaultBehavior.Expiration, r.Behavior.Expiration);
            Assert.AreEqual(defaultBehavior.MaxRetries, r.Behavior.MaxRetries);
            Assert.AreEqual(defaultBehavior.ReturnCallback.TargetMethodName, r.Behavior.ReturnCallback.TargetMethodName);
            Assert.AreEqual(defaultBehavior.ReturnCallback.TargetType, r.Behavior.ReturnCallback.TargetType);
            Assert.AreEqual(defaultBehavior.Stamps, r.Behavior.Stamps);
            Assert.AreEqual(defaultBehavior.Tag, r.Behavior.Tag);
        }
        /// <summary>
        /// Enqueues a request to the <c>GetRestaurants</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetRestaurants(OfflineBehavior behavior)
        {
            behavior.ReturnCallback    = new CommandCallback(typeof(Callback), "OnGetRestaurantsReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetRestaurantsException");

            return(EnqueueRequest("GetRestaurants", behavior));
        }
예제 #6
0
        public void CanSpecifyBehaviorsForTheRequest()
        {
            MockRequestQueue queue = new MockRequestQueue();

            OfflineMockService proxy = new OfflineMockService(queue);

            OfflineBehavior beh = new OfflineBehavior();

            beh.Tag            = "tag";
            beh.Stamps         = 3;
            beh.MaxRetries     = 5;
            beh.ReturnCallback = new CommandCallback(typeof(OfflineMockServiceCallbacks), "SomeOtherMethod");
            beh.Expiration     = DateTime.MinValue;

            proxy.DoWithNoParams(beh);

            Request r = queue.GetNextRequest();

            Assert.AreEqual(beh, r.Behavior);
            Assert.AreEqual(DateTime.MinValue, r.Behavior.Expiration);
            Assert.AreEqual(5, r.Behavior.MaxRetries);
            Assert.AreEqual("SomeOtherMethod", r.Behavior.ReturnCallback.TargetMethodName);
            Assert.AreEqual(typeof(OfflineMockServiceCallbacks), r.Behavior.ReturnCallback.TargetType);
            Assert.AreEqual(3, r.Behavior.Stamps);
            Assert.AreEqual("tag", r.Behavior.Tag);
        }
        public void DoWithNoParams()
        {
            OfflineBehavior behavior = GetDefaultOfflineBehavior();

            behavior.ReturnCallback = new CommandCallback(typeof(OfflineMockServiceCallbacks), "DoWithNoParamsCallback");

            DoWithNoParams(behavior);
        }
예제 #8
0
        public static OfflineBehavior GetAddDefaultBehavior()
        {
            OfflineBehavior behavior = GetAgentDefaultBehavior();

            behavior.ReturnCallback    = new CommandCallback(typeof(IntegerCalculatorServiceDisconnectedAgentCallback), "OnAddReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(IntegerCalculatorServiceDisconnectedAgentCallback), "OnAddException");
            return(behavior);
        }
예제 #9
0
        private Guid EnqueueRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = CreateRequest(methodName, behavior, arguments);

            requestQueue.Enqueue(request);

            return(request.RequestId);
        }
        public void DoWithParamsAndReturn(int p, MockServiceDataContract obj)
        {
            OfflineBehavior behavior = GetDefaultOfflineBehavior();

            behavior.ReturnCallback = new CommandCallback(typeof(OfflineMockServiceCallbacks), "OnDoWithParamsAndReturnReturn");

            DoWithParamsAndReturn(p, obj, behavior);
        }
예제 #11
0
        public void CanSpecifyTheProxyFactoryType()
        {
            OfflineBehavior behavior = new OfflineBehavior();

            behavior.ProxyFactoryType = typeof(MockProxyFactory);


            Assert.AreEqual(typeof(MockProxyFactory), behavior.ProxyFactoryType);
        }
        public static OfflineBehavior GetGetRestaurantsDefaultBehavior()
        {
            OfflineBehavior behavior = GetAgentDefaultBehavior();

            behavior.ReturnCallback    = new CommandCallback(typeof(Callback), "OnGetRestaurantsReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetRestaurantsException");

            return(behavior);
        }
예제 #13
0
        public static OfflineBehavior GetAgentDefaultBehavior()
        {
            OfflineBehavior behavior = new OfflineBehavior();
            behavior.MaxRetries = 3;
            behavior.Stamps = 1;
            behavior.Expiration = DateTime.Now + new TimeSpan(24, 0, 0, 0);
            behavior.ProxyFactoryType = typeof(WCFProxyFactory<IMenuService>);

            return behavior;
        }
예제 #14
0
        public static OfflineBehavior GetAgentDefaultBehavior()
        {
            OfflineBehavior behavior = new OfflineBehavior();

            behavior.ProxyFactoryType = typeof(WebServiceProxyFactory);
            behavior.MaxRetries       = 1;
            behavior.Stamps           = 1;
            behavior.Expiration       = DateTime.Now + new TimeSpan(0, 0, 30);
            return(behavior);
        }
        public static OfflineBehavior GetAgentDefaultBehavior()
        {
            OfflineBehavior behavior = new OfflineBehavior();

            behavior.MaxRetries       = 3;
            behavior.Stamps           = 1;
            behavior.Expiration       = DateTime.Now + new TimeSpan(24, 0, 0, 0);
            behavior.ProxyFactoryType = typeof(Microsoft.Practices.SmartClient.DisconnectedAgent.WCFProxyFactory <QuickStart.RestaurantModule.RestaurantService.IMenuService>);

            return(behavior);
        }
        private OfflineBehavior GetDefaultOfflineBehavior()
        {
            OfflineBehavior behavior = new OfflineBehavior();

            //Set default offlineBehavior values
            behavior.ExceptionCallback = new CommandCallback(typeof(OfflineMockServiceCallbacks), "OnMockServiceException");
            behavior.Expiration        = null;
            behavior.MaxRetries        = 1;
            behavior.Stamps            = 3;
            behavior.Tag = string.Empty;
            return(behavior);
        }
        public void DoWithNoParams(OfflineBehavior behavior)
        {
            Request r = new Request();

            r.MethodName      = "DoWithNoParams";
            r.Endpoint        = "MockService";
            r.OnlineProxyType = typeof(MockService);

            r.Behavior = behavior;

            requestQueue.Enqueue(r);
        }
        public void DoWithParamsAndReturn(int p, MockServiceDataContract obj, OfflineBehavior behavior)
        {
            Request r = new Request();

            r.MethodName      = "DoWithParamsAndReturn";
            r.Endpoint        = "MockService";
            r.OnlineProxyType = typeof(MockService);
            r.CallParameters  = CallParameters.ToArray(p, obj);

            r.Behavior = behavior;

            requestQueue.Enqueue(r);
        }
예제 #19
0
        public static Request CreateRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = new Request();

            request.MethodName     = methodName;
            request.Behavior       = behavior;
            request.CallParameters = arguments;

            request.OnlineProxyType = OnlineProxyType;
            request.Endpoint        = Endpoint;

            return(request);
        }
        private bool AreEqual(OfflineBehavior a, OfflineBehavior b)
        {
            if (ReferenceEquals(a, b))
            {
                return(true);
            }

            return(AreEqual(a.ExceptionCallback, b.ExceptionCallback) &&
                   a.Expiration == b.Expiration &&
                   a.MaxRetries == b.MaxRetries &&
                   a.MessageId == b.MessageId &&
                   AreEqual(a.ReturnCallback, b.ReturnCallback) &&
                   a.Stamps == b.Stamps &&
                   a.Tag == b.Tag);
        }
예제 #21
0
        public static MethodBehaviors GetMethodsBehavior(Type dsaType, Type proxyType)
        {
            MethodBehaviors   behaviors       = new MethodBehaviors();
            List <MethodInfo> methods         = GetAgentMethods(dsaType, proxyType);
            OfflineBehavior   defaultBehavior = GetDefaultBehavior(dsaType);

            foreach (MethodInfo method in methods)
            {
                OfflineBehavior methodOfflineBehavior = GetMethodBehavior(dsaType, method.Name);
                MethodBehavior  behavior = GenerateMethodBehavior(method, methodOfflineBehavior, defaultBehavior);

                behaviors.Add(behavior);
            }

            return(behaviors);
        }
예제 #22
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            int number1 = 0;
            int number2 = 0;

            int.TryParse(textBoxFirstNumber.Text, out number1);
            int.TryParse(textBoxSecondNumber.Text, out number2);

            OfflineBehavior behavior = IntegerCalculatorServiceDisconnectedAgent.GetAddDefaultBehavior();

            if (!tagComboBox.SelectedItem.ToString().Equals("(none)"))
            {
                behavior.Tag = tagComboBox.SelectedItem.ToString();
            }

            calculator.Add(number1, number2, behavior);
        }
        public void DispatchAllRequestByTagBypassingCost()
        {
            MockRequestQueue    queue           = new MockRequestQueue();
            MockRequestQueue    deadletterQueue = new MockRequestQueue();
            MockEndpointCatalog endCatalog      = CreateEndpointCatalog();

            MockConnectionMonitor connectionMonitor = CreateConnectionManager();

            connectionMonitor.MockChangeConnectionStatus(true);

            RequestManager mgr = RequestManager.Instance;

            mgr.Initialize <MockRequestDispatcher>(queue, deadletterQueue, connectionMonitor, endCatalog);
            MockRequestDispatcher disp     = MockRequestDispatcher.Instance;
            OfflineBehavior       behavior = new OfflineBehavior();

            behavior.Tag = "A";

            Request r1 = new Request();

            r1.Endpoint = "Endpoint";
            Request r2 = new Request();

            r2.Endpoint = "Endpoint";
            Request r3 = new Request();

            r3.Endpoint = "Endpoint";

            r1.Behavior = behavior;
            r3.Behavior = behavior;

            queue.Enqueue(r1);
            queue.Enqueue(r2);
            queue.Enqueue(r3);

            mgr.DispatchPendingRequestsByTag("A");
            mgr.Join(1000);

            Assert.IsTrue(disp.RequestsReceived.Contains(r1));
            Assert.IsTrue(disp.RequestsReceived.Contains(r3));
            Assert.IsFalse(disp.RequestsReceived.Contains(r2));

            Assert.AreEqual(2, disp.RequestsReceived.Count);
            Assert.AreEqual(1, queue.GetCount());
        }
예제 #24
0
        public void CreatingRequestWithReturnValueAndSpecificBehavior()
        {
            MockRequestQueue        queue = new MockRequestQueue();
            OfflineMockService      proxy = new OfflineMockService(queue);
            MockServiceDataContract obj   = new MockServiceDataContract("Jose", 31);

            OfflineBehavior behavior = new OfflineBehavior();

            behavior.MaxRetries     = 7;
            behavior.Stamps         = 5;
            behavior.Tag            = "Test";
            behavior.ReturnCallback =
                new CommandCallback(typeof(OfflineMockServiceCallbacks), "OnDoWithParamsAndReturnAlternativeReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(OfflineMockServiceCallbacks), "OnMockServiceOtherException");
            DateTime expDate = DateTime.Now + TimeSpan.FromHours(2);

            behavior.Expiration = expDate;
            Guid behId = Guid.NewGuid();

            behavior.MessageId = behId;

            proxy.DoWithParamsAndReturn(1, obj, behavior);

            Request r = queue.GetNextRequest();

            Assert.AreEqual(behId, r.Behavior.MessageId);
            Assert.AreSame(obj, r.CallParameters[1]);
            Assert.AreEqual("MockService", r.Endpoint);
            Assert.AreEqual("DoWithParamsAndReturn", r.MethodName);
            Assert.AreEqual(typeof(MockService), r.OnlineProxyType);

            Assert.AreEqual("OnDoWithParamsAndReturnAlternativeReturn", r.Behavior.ReturnCallback.TargetMethodName);
            Assert.AreEqual(typeof(OfflineMockServiceCallbacks), r.Behavior.ReturnCallback.TargetType);
            Assert.AreEqual("OnMockServiceOtherException", r.Behavior.ExceptionCallback.TargetMethodName);
            Assert.AreEqual(typeof(OfflineMockServiceCallbacks), r.Behavior.ExceptionCallback.TargetType);

            //these test the default behavior; which should have been set by the recipe when creating the OfflineSvcAgent
            Assert.AreEqual(expDate, r.Behavior.Expiration);
            Assert.AreEqual(7, r.Behavior.MaxRetries);
            Assert.AreEqual(5, r.Behavior.Stamps);
            Assert.AreEqual("Test", r.Behavior.Tag);
        }
예제 #25
0
 /// <summary>
 /// Enqueues a request to the <c>Foo</c> web service method through the agent.
 /// </summary>
 /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
 /// <returns>The unique identifier associated with the request that was enqueued.</returns>
 public Guid Foo(OfflineBehavior behavior)
 {
     return(EnqueueRequest("Foo", behavior));
 }
예제 #26
0
        private static MethodBehavior GenerateMethodBehavior(MethodInfo method, OfflineBehavior methodOffBehavior, OfflineBehavior defaultOffBehavior)
        {
            MethodBehavior behavior = new MethodBehavior(method, false);

            behavior.Expiration = null;
            behavior.MaxRetries = null;
            behavior.Stamps     = null;
            behavior.Tag        = null;

            if (methodOffBehavior != null)
            {
                if (defaultOffBehavior == null)
                {
                    behavior.Expiration = methodOffBehavior.Expiration - DateTime.Now;
                    behavior.MaxRetries = methodOffBehavior.MaxRetries;
                    behavior.Stamps     = methodOffBehavior.Stamps;
                    behavior.Tag        = methodOffBehavior.Tag;
                }
                else
                {
                    TimeSpan methoBehaviorExpiration   = new TimeSpan();
                    TimeSpan defaultBehaviorExpiration = new TimeSpan();

                    if (methodOffBehavior.Expiration.HasValue)
                    {
                        methoBehaviorExpiration = methodOffBehavior.Expiration.Value - DateTime.Now;
                        methoBehaviorExpiration = new TimeSpan(methoBehaviorExpiration.Days,
                                                               methoBehaviorExpiration.Hours,
                                                               methoBehaviorExpiration.Minutes,
                                                               methoBehaviorExpiration.Seconds);
                    }
                    if (defaultOffBehavior.Expiration.HasValue)
                    {
                        defaultBehaviorExpiration = defaultOffBehavior.Expiration.Value - DateTime.Now;
                        defaultBehaviorExpiration = new TimeSpan(defaultBehaviorExpiration.Days,
                                                                 defaultBehaviorExpiration.Hours,
                                                                 defaultBehaviorExpiration.Minutes,
                                                                 defaultBehaviorExpiration.Seconds);
                    }

                    if (methoBehaviorExpiration != null && defaultBehaviorExpiration != null &&
                        !(methoBehaviorExpiration.Equals(defaultBehaviorExpiration)))
                    {
                        behavior.Expiration = methoBehaviorExpiration;
                        behavior.IsOverride = true;
                    }
                    if (!(methodOffBehavior.MaxRetries.Equals(defaultOffBehavior.MaxRetries)))
                    {
                        behavior.MaxRetries = methodOffBehavior.MaxRetries;
                        behavior.IsOverride = true;
                    }
                    if (!(methodOffBehavior.Stamps.Equals(defaultOffBehavior.Stamps)))
                    {
                        behavior.Stamps     = methodOffBehavior.Stamps;
                        behavior.IsOverride = true;
                    }
                    if (methodOffBehavior.Tag != null &&
                        !(methodOffBehavior.Tag.Equals(defaultOffBehavior.Tag)))
                    {
                        behavior.Tag        = methodOffBehavior.Tag;
                        behavior.IsOverride = true;
                    }
                }
            }
            return(behavior);
        }
예제 #27
0
 /// <summary>
 /// Enqueues a request to the <c>HelloWorld</c> web service method through the agent.
 /// </summary>
 /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
 /// <returns>The unique identifier associated with the request that was enqueued.</returns>
 public Guid HelloWorld(OfflineBehavior behavior)
 {
     return(EnqueueRequest("HelloWorld", behavior));
 }
예제 #28
0
 /// <summary>
 /// Enqueues a request to the <c>HelloWorld</c> web service method through the agent.
 /// </summary>
 /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
 /// <returns>The unique identifier associated with the request that was enqueued.</returns>
 public Guid HelloWorld(String message, OfflineBehavior behavior)
 {
     return(EnqueueRequest("HelloWorld", behavior, message));
 }
예제 #29
0
        /// <summary>
        /// Enqueues a request to the <c>GetMenuItems</c> web service method through the agent.
        /// </summary>
        /// <param name="restaurantId"></param>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetMenuItems(String restaurantId, OfflineBehavior behavior)
        {
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetMenuItemsReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetMenuItemsException");

            return EnqueueRequest("GetMenuItems", behavior, restaurantId);
        }
예제 #30
0
            public static OfflineBehavior GetHelloWorld2DefaultBehavior()
            {
                OfflineBehavior behavior = GetAgentDefaultBehavior();

                return(behavior);
            }
예제 #31
0
        private Guid EnqueueRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = CreateRequest(methodName, behavior, arguments);

            requestQueue.Enqueue(request);

            return request.RequestId;
        }
예제 #32
0
        private static Request CreateRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = new Request();
            request.MethodName = methodName;
            request.Behavior = behavior;
            request.CallParameters = arguments;

            request.OnlineProxyType = OnlineProxyType;
            request.Endpoint = Endpoint;

            return request;
        }
예제 #33
0
        /// <summary>
        /// Enqueues a request to the <c>GetRestaurants</c> web service method through the agent.
        /// </summary>
        /// <param name="behavior">The behavior associated with the offline request being enqueued.</param>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid GetRestaurants(OfflineBehavior behavior)
        {
            behavior.ReturnCallback = new CommandCallback(typeof(Callback), "OnGetRestaurantsReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(Callback), "OnGetRestaurantsException");

            return EnqueueRequest("GetRestaurants", behavior);
        }
예제 #34
0
            public static OfflineBehavior GetFooDefaultBehavior()
            {
                OfflineBehavior behavior = GetAgentDefaultBehavior();

                return(behavior);
            }
예제 #35
0
            private static Request CreateRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
            {
                Request request = new Request();

                return(request);
            }