⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serviceagent.cs

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 CS
字号:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by the Mobile Client Software Factory.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using Microsoft.Practices.Mobile.DisconnectedAgent;
using System;

namespace MobileDevelopersHandbook.DSAExample.DisconnectedAgents.OrdersWebService
{
    // Generated code for the web service.
    // Use this proxy to make requests to the service when working in an application that is occasionally connected
    public partial class ServiceDisconnectedAgent
    {
        IRequestQueue requestQueue;

        public ServiceDisconnectedAgent(IRequestQueue requestQueue)
        {
            this.requestQueue = requestQueue;
        }

        #region PostOrder

        /// <summary>
        /// Enqueues a request to the <c>PostOrder</c> web service method through the agent.
        /// </summary>
        /// <returns>The unique identifier associated with the request that was enqueued.</returns>
        public Guid PostOrder(String CustomerName, Int32 ProductID, Int32 Quantity)
        {
            return PostOrder(CustomerName, ProductID, Quantity, GetPostOrderDefaultBehavior());
        }

        /// <summary>
        /// Enqueues a request to the <c>PostOrder</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 PostOrder(String CustomerName, Int32 ProductID, Int32 Quantity, OfflineBehavior behavior)
        {
            behavior.ReturnCallback = new CommandCallback(typeof(ServiceDisconnectedAgentCallback), "OnPostOrderReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(ServiceDisconnectedAgentCallback), "OnPostOrderException");

            return EnqueueRequest("PostOrder", behavior, CustomerName, ProductID, Quantity);
        }

        private OfflineBehavior GetPostOrderDefaultBehavior()
        {
            OfflineBehavior behavior = GetAgentDefaultBehavior();
            behavior.ReturnCallback = new CommandCallback(typeof(ServiceDisconnectedAgentCallback), "OnPostOrderReturn");
            behavior.ExceptionCallback = new CommandCallback(typeof(ServiceDisconnectedAgentCallback), "OnPostOrderException");

            return behavior;
        }

        #endregion PostOrder

        #region Common

        private OfflineBehavior GetAgentDefaultBehavior()
        {
            OfflineBehavior behavior = new OfflineBehavior();
            behavior.MaxRetries = 10;
            behavior.Stamps = 1;
            behavior.Expiration = DateTime.Now + new TimeSpan(7, 0, 0, 0);
            return behavior;
        }

        private Guid EnqueueRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = CreateRequest(methodName, behavior, arguments);

            requestQueue.Enqueue(request);

            return request.RequestId;
        }

        private Request CreateRequest(string methodName, OfflineBehavior behavior, params object[] arguments)
        {
            Request request = new Request();
            request.MethodName = methodName;
            request.Behavior = behavior;
            request.CallParameters = arguments;

            request.OnlineProxyType = typeof(MobileDevelopersHandbook.DSAExample.OrdersWebService.OrdersService);
            request.Endpoint = "Orders";

            return request;
        }

        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -