Esempio n. 1
0
        // ========================================
        // 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);
        }
Esempio n. 2
0
        internal static void SaveIdsToFile(MemoIdCollection ids, string fileName)
        {
            var serializer = new DataContractSerializer(typeof(MemoIdCollection));

            using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                using (var writer = XmlWriter.Create(stream)) {
                    serializer.WriteObject(writer, ids);
                }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        internal static MemoIdCollection LoadIdsFromFile(string fileName)
        {
            var ret = default(MemoIdCollection);

            try {
                if (File.Exists(fileName))
                {
                    var serializer = new DataContractSerializer(typeof(MemoIdCollection));
                    using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                        using (var reader = XmlReader.Create(stream)) {
                            ret = serializer.ReadObject(reader) as MemoIdCollection;
                        }
                }
            } catch (Exception e) {
                Logger.Warn("Recent memoinfos load failed", e);
            }

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

            return(ret);
        }