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

📄 sscesyncclient.cs

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

namespace Microsoft.Mobile.Data.SqlServerCE
{
    /// <summary>
    /// <see cref="Microsoft.Mobile.Data.SyncClient"/> SyncClient 
    /// implementation for SQL Server Merge Replication.
    /// </summary>
    [SuppressMessage("Microsoft.Naming",
                     "CA1709:IdentifiersShouldBeCasedCorrectly",
                     MessageId = "SSCE",
                     Justification = "Reads better as SSCE since SSCE stands for Sql Server CE.")]
    public class SSCESyncClient : SyncClient
    {
        #region Constructor(s) & Dispose
        /// <summary>
        /// Builds a SyncClient with parameters that are not publication 
        /// specific.
        /// </summary>
        /// <param name="generalParameters">general sync parameters</param>
        public SSCESyncClient(Parameters generalParameters) : base(generalParameters)
        {
        }


        /// <summary>
        /// Dispose of any SqlServer Merge Replication resources
        /// </summary>
        /// <param name="disposing">
        /// set to true when being called by dispose otherwise false.
        /// </param>
        protected override void Dispose(bool disposing)
        {
        }
        #endregion


        #region Methods
        /// <summary>
        /// This method synchronizes a datastore if it is capable of doing so
        /// </summary>
        public override void Synchronize(Parameters publication)
        {
            string tempFile;
            SqlCeReplication repl = new SqlCeReplication();

            try
            {
                //Set Internet Properties
                repl.InternetUrl = GeneralParameters["InternetUrl"].ToString();
                repl.InternetLogin = GeneralParameters["InternetLogin"].ToString();
                repl.InternetPassword = GeneralParameters["InternetPassword"].ToString();

                //Set Publisher Properties
                repl.Publisher = publication["Publisher"].ToString();
                repl.PublisherDatabase = publication["PublisherDatabase"].ToString();
                repl.Publication = publication["Publication"].ToString();

                //Set Security Property
                repl.PublisherSecurityMode = SecurityType.NTAuthentication;

                //Set Subscriber Properties
                repl.SubscriberConnectionString = GeneralParameters["ConnectionString"].ToString();
                repl.Subscriber = GeneralParameters["Subscriber"].ToString();

                //Set Compression Level
                repl.CompressionLevel = (short)GeneralParameters["CompressionLevel"];

                //Check to see if Local Database Exists
                tempFile = publication["Datafile"].ToString();

                if (string.IsNullOrEmpty(tempFile) || string.IsNullOrEmpty(tempFile.Trim()))
                {
                    if (!File.Exists(tempFile))
                    {
                        //If not, have the AddSubscription method create a new database
                        repl.AddSubscription(AddOption.CreateDatabase);
                    }
                }

                //Synchronize with SQL Server 2005
                repl.Synchronize();
            }
            finally
            {
                //Displose of Replication Object
                repl.Dispose();
            }
        }
        #endregion
    }
}

⌨️ 快捷键说明

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