コード例 #1
0
        private static bool ReadAccessInfo(string accessInfoPath, out AccessInfo accessInfo)
        {
            accessInfo = AccessInfo.Empty;
            if (File.Exists(accessInfoPath) == false)
            {
                return(false);
            }

            accessInfo = (AccessInfo)JsonSerializerUtility.Read <AccessSerializationInfo>(accessInfoPath);
            return(true);
        }
コード例 #2
0
ファイル: DataServiceItemBase.cs プロジェクト: teize001/Crema
        private void ReadInfo()
        {
            var infoPath = Path.Combine(this.BasePath, "info.json");

            if (FileUtility.Exists(infoPath) == true)
            {
                try
                {
                    this.info = JsonSerializerUtility.Read <DataServiceItemInfo>(infoPath);
                }
                catch (Exception e)
                {
                    this.logService.Error(e);
                }
            }
        }
コード例 #3
0
        private Dictionary <string, DataBaseState> ReadStateCaches()
        {
            var caches = new Dictionary <string, DataBaseState>();
            var files  = Directory.GetFiles(cachePath, $"*{stateExtension}");

            foreach (var item in files)
            {
                try
                {
                    var dataBaseState = JsonSerializerUtility.Read <DataBaseState>(item);
                    caches.Add(Path.GetFileNameWithoutExtension(item), dataBaseState);
                }
                catch (Exception e)
                {
                    this.cremaHost.Error(e);
                }
            }

            return(caches);
        }
コード例 #4
0
        private Dictionary <string, DataBaseSerializationInfo> ReadCaches()
        {
            var caches = new Dictionary <string, DataBaseSerializationInfo>();
            var files  = Directory.GetFiles(cachePath, $"*{databaseExtension}");

            foreach (var item in files)
            {
                try
                {
                    var dataBaseInfo = JsonSerializerUtility.Read <DataBaseSerializationInfo>(item);
                    caches.Add(dataBaseInfo.Name, dataBaseInfo);
                }
                catch (Exception e)
                {
                    this.cremaHost.Error(e);
                }
            }

            return(caches);
        }
コード例 #5
0
ファイル: DataServiceItemBase.cs プロジェクト: teize001/Crema
        private void Initialize()
        {
            this.Dispatcher.CheckAccess();
            var error = false;

            try
            {
                if (this.info.Revision != 0)
                {
                    foreach (var item in this.info.ItemList)
                    {
                        if (item.StartsWith(CremaSchema.TableDirectory) == true)
                        {
                            var tableName = Path.GetFileName(item);
                            using (var stream = FileUtility.OpenRead(this.BasePath, CremaSchema.TableDirectory, infoDirectory, tableName + jsonExtension))
                            {
                                this.tableInfos.Add(tableName, JsonSerializerUtility.Read <TableInfo>(stream));
                            }
                            using (var stream = FileUtility.OpenRead(this.BasePath, CremaSchema.TableDirectory, dataDirectory, tableName))
                            {
                                this.tableDatas.Add(tableName, this.OnDeserializeTable(stream));
                            }
                        }
                        else if (item.StartsWith(CremaSchema.TypeDirectory) == true)
                        {
                            var typeName = Path.GetFileName(item);
                            using (var stream = FileUtility.OpenRead(this.BasePath, CremaSchema.TypeDirectory, infoDirectory, typeName + jsonExtension))
                            {
                                this.typeInfos.Add(typeName, JsonSerializerUtility.Read <TypeInfo>(stream));
                            }
                            using (var stream = FileUtility.OpenRead(this.BasePath, CremaSchema.TypeDirectory, dataDirectory, typeName))
                            {
                                this.typeDatas.Add(typeName, this.OnDeserializeType(stream));
                            }
                        }
                    }
                }
                else
                {
                    error = true;
                }
            }
            catch
            {
                error = true;
            }

            if (error == true)
            {
                var result = this.dataBase.Dispatcher.Invoke(() =>
                {
                    var revision = this.dataBase.DataBaseInfo.Revision;
                    var contains = this.dataBase.Contains(this.Authentication);
                    if (contains == false)
                    {
                        this.dataBase.Enter(this.Authentication);
                    }
                    var dataSet = this.dataBase.GetDataSet(this.Authentication, -1);
                    if (contains == false)
                    {
                        this.dataBase.Leave(this.Authentication);
                    }
                    return(new Tuple <long, CremaDataSet>(revision, dataSet));
                });
                this.Serialize(result.Item2, result.Item1);
            }
            this.initialized = true;
        }