// ========================================
        // static method
        // ========================================
        internal static MemoIdCollection LoadIdsFromSdf(string tableName, SqlServerAccessor accessor)
        {
            var ret = default(MemoIdCollection);

            try {
                var xml = accessor.LoadTextDataValue(tableName);
                if (xml != null)
                {
                    var serializer = new DataContractSerializer(typeof(MemoIdCollection));
                    using (var xmlReader = new StringReader(xml))
                        using (var reader = XmlReader.Create(xmlReader)) {
                            ret = serializer.ReadObject(reader) as MemoIdCollection;
                        }
                }
            } catch (Exception e) {
                Logger.Warn("Recent memoinfos load failed", e);
            }

            if (ret == null)
            {
                ret = new MemoIdCollection();
            }

            return(ret);
        }
Exemple #2
0
        public static DbAccessor NewDbAccessor(string connectionString, string providerName)
        {
            DbAccessor dba = null;

            if (string.IsNullOrEmpty(providerName) ||
                providerName == "System.Data.SqlClient" ||
                providerName.ToLower() == DbProviderName.SqlServer.ToString().ToLower())
            {
                dba = new SqlServerAccessor(connectionString);
            }
            else if (providerName.ToLower() == DbProviderName.MySql.ToString().ToLower() ||
                     providerName == "MySql.Data.MySqlClient")
            {
                dba = new MySqlAccessor(connectionString);
            }
            else
            {
                Type tProviderName = Type.GetType(providerName);
                if (tProviderName == null)
                {
                    throw new Exception(string.Format("ConnectionString({0})的ProviderName({1})找不到该类型!", connectionString, providerName));
                }
                //else if (!(tProviderName.IsSubclassOf(typeof(DbAccessor))))
                //{
                //    throw new Exception(string.Format("ConnectionString({0})的ProviderName({1})该类型不是DbAccessor的实现类!", connectionString, providerName));
                //}
                object oProviderName = Activator.CreateInstance(tProviderName, connectionString);
                dba = oProviderName as DbAccessor;
            }

            return(dba);
        }
        private void DoConvert(object sender, DoWorkEventArgs e)
        {
            var worker = (BackgroundWorker)sender;

            var memoConnection   = default(SqlCeConnection);
            var exDataConnection = default(SqlCeConnection);

            try {
                PathUtil.EnsureDirectoryExists(MemopadConstsV2.MemoRoot);
                MakeMemoDataFolderIcon(MemopadConstsV2.MemoRoot);
                worker.ReportProgress(10);

                {
                    var memoConn = string.Format(ConnectionString, MemopadConstsV2.MemoFilePath);
                    var engine   = new SqlCeEngine(memoConn);
                    engine.CreateDatabase();

                    memoConnection = new SqlCeConnection(memoConn);
                    memoConnection.Open();
                }
                {
                    var exDataConn = string.Format(ConnectionString, MemopadConstsV2.ExtendedDataFilePath);
                    var engine     = new SqlCeEngine(exDataConn);
                    engine.CreateDatabase();

                    exDataConnection = new SqlCeConnection(exDataConn);
                    exDataConnection.Open();
                }


                _memoAccessor   = new SqlServerAccessor(memoConnection);
                _exDataAccessor = new SqlServerAccessor(exDataConnection);

                worker.ReportProgress(20);

                ConvertData();
                worker.ReportProgress(40);

                ConvertModel();
                worker.ReportProgress(70);

                CopyData();
                worker.ReportProgress(90);
            } finally {
                if (memoConnection != null)
                {
                    memoConnection.Close();
                }
                if (exDataConnection != null)
                {
                    exDataConnection.Close();
                }
            }

            worker.ReportProgress(100);
        }
Exemple #4
0
        // ========================================
        // constructor
        // ========================================
        public XmlSqlServerEntityStore(SqlCeConnection memoConn, SqlCeConnection exDataConn) : base()
        {
            if (memoConn == null || exDataConn == null)
            {
                throw new ArgumentException("memoConn or exDataConn");
            }

            _memoAccessor   = new SqlServerAccessor(memoConn);
            _exDataAccessor = new SqlServerAccessor(exDataConn);
        }
        internal static void SaveIdsToSdf(MemoIdCollection ids, string tableName, SqlServerAccessor accessor)
        {
            var buf = new StringBuilder();

            using (var writer = XmlWriter.Create(buf)) {
                var serializer = new DataContractSerializer(typeof(MemoIdCollection));
                serializer.WriteObject(writer, ids);
            }

            var xml = buf.ToString();

            if (accessor.IsTextDataExists(tableName))
            {
                accessor.UpdateTextData(tableName, xml);
            }
            else
            {
                accessor.InsertTextData(tableName, xml);
            }
        }
Exemple #6
0
        internal static void SaveMemoInfos(MemoInfoCollection memoInfos, SqlServerAccessor accessor)
        {
            var buf = new StringBuilder();

            using (var writer = XmlWriter.Create(buf)) {
                var serializer = new DataContractSerializer(typeof(MemoInfoCollection));
                serializer.WriteObject(writer, memoInfos);
            }

            var xml = buf.ToString();

            if (accessor.IsTextDataExists("MemoInfo"))
            {
                accessor.UpdateTextData("MemoInfo", xml);
            }
            else
            {
                accessor.InsertTextData("MemoInfo", xml);
            }
        }