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

📄 syncclient.cs

📁 微软的行业应用解决方案示例
💻 CS
字号:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace Microsoft.Mobile.Data
{
    /// <summary>
    /// Generic synchronization client
    /// </summary>
    public abstract class SyncClient : IDisposable
    {
        #region Constants
        /// <summary>
        /// Name of the Sql Server CE Provider
        /// </summary>
        [SuppressMessage("Microsoft.Naming",
                         "CA1709:IdentifiersShouldBeCasedCorrectly",
                         MessageId = "SSCE",
                         Justification = "SSCE is the abbreviated product name.")]
        public const string SSCEProvider = "Microsoft.Mobile.Data.SqlServerCE.SSCESyncClient";
        #endregion


        #region Fields
        private static string _defaultProvider = SSCEProvider;
        private Parameters _generalSync;
        #endregion


        #region Constructor(s) & Dispose
        /// <summary>
        /// Builds a SyncClient with parameters that are not publication 
        /// specific.
        /// </summary>
        /// <param name="generalParameters">general sync parameters</param>
        protected SyncClient(Parameters generalParameters)
        {
            _generalSync = generalParameters;
        }


        /// <summary>
        /// Destructor for SyncClient to only be used by Finalizer
        /// </summary>
        ~SyncClient()
        {
            Dispose(false);
        }


        /// <summary>
        /// Dispose of any resources associated with the SyncClient 
        /// implementation.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);

            // This object will be cleaned up by the Dispose method. Therefore, 
            // you should call GC.SupressFinalize to take this object off the 
            // finalization queue and prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }


        /// <summary>
        /// Actual dispose implementation. Used to prevent dispose executing 
        /// twice.
        /// </summary>
        /// <remarks>
        /// Dispose(bool disposing) executes in two distinct scenarios. If 
        /// disposing equals true, the method has been called directly or 
        /// indirectly by a user's code. Managed and unmanaged resources can be 
        /// disposed.
        /// 
        /// If disposing equals false, the method has been called by the 
        /// runtime from inside the finalizer and you should not reference 
        /// other objects. Only unmanaged resources can be disposed.
        /// </remarks>
        /// <param name="disposing">
        /// set to true when being called by dispose otherwise false.
        /// </param>
        protected abstract void Dispose(bool disposing);
        #endregion


        #region Properties
        /// <summary>
        /// General synchronization parameters
        /// </summary>
        public Parameters GeneralParameters
        {
            get
            {
                if (_generalSync == null)
                {
                    _generalSync = new Parameters();
                }

                return _generalSync;
            }
        }
        #endregion


        #region Methods
        public static SyncClient CreateClient(Parameters generalParameters)
        {
            return CreateClient(_defaultProvider, generalParameters);
        }


        public static SyncClient CreateClient(string providerType, Parameters generalParameters)
        {
            Type syncClientType = null;
            ConstructorInfo constructor = null;
            SyncClient result = null;

            syncClientType = Type.GetType(providerType, true, false);
            constructor = syncClientType.GetConstructor(new Type[] { typeof(Parameters) });
            result = (SyncClient)constructor.Invoke(new object[] { generalParameters });

            return result;
        }



        /// <summary>
        /// This method synchronizes a datastore if it is capable of doing so
        /// </summary>
        public abstract void Synchronize(Parameters publication);
        #endregion
    }
}

⌨️ 快捷键说明

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