/// <summary>
        /// Asynchronously loads data from the persistence layer and populates managed systems with it
        /// </summary>
        /// <param name="dataPersistence">The persistence layer used to execute the process</param>
        /// <param name="onLoadCompleted">Called when the loading process is completed with success</param>
        /// <param name="onLoadFailed">Called when the loading process failed</param>
        public static void LoadAppSettings(
            IDataPersistence dataPersistence,
            Action onLoadCompleted = null,
            Action onLoadFailed    = null)
        {
            if (dataPersistence == null)
            {
                onLoadFailed?.Invoke();
                Debug.LogWarning("DataPersistence cannot be null on persistence process.");
                return;
            }

            LoadAppSettingsData(dataPersistence,
                                (data) =>
            {
                try
                {
                    FillAppSettings(data);
                    onLoadCompleted?.Invoke();
                }
                catch
                {
                    onLoadFailed?.Invoke();
                }
            }, onLoadFailed);
        }
        /// <summary>
        /// Initialize the GameFoundation . It need a persistence object to be passed as argument to set the default persistence layer
        /// If the initialization fails, onInitializeFailed will be called with an exception.
        /// </summary>
        /// <param name="dataPersistence">The persistence layer of the Game Foundation. Required and cached for future execution</param>
        /// <param name="onInitializeCompleted">Called when the initialization process is completed with success</param>
        /// <param name="onInitializeFailed">Called when the initialization process failed</param>
        public static void InitializeAppSettings(
            IDataPersistence dataPersistence        = null,
            IDataSerializationAdapter dataFormatter = null,
            Action onInitializeCompleted            = null,
            Action onInitializeFailed = null)
        {
            if (m_AppSettingsInitializationStatus == InitializationStatus.Initializing ||
                m_AppSettingsInitializationStatus == InitializationStatus.Initialized)
            {
                Debug.LogWarning("AppSettings is already initialized and cannot be initialized again.");
                onInitializeFailed?.Invoke();

                return;
            }

            m_AppSettingsInitializationStatus = InitializationStatus.Initializing;

            if (dataPersistence != null && dataFormatter != null)
            {
                LoadAppSettingsData(dataPersistence,
                                    (data) =>
                {
                    InitializeAppSettings(data, dataFormatter, onInitializeCompleted, onInitializeFailed);
                },
                                    () =>
                {
                    InitializeAppSettings(null as ISerializableData, dataFormatter, onInitializeCompleted, onInitializeFailed);
                });
            }
            else
            {
                InitializeAppSettings(null as ISerializableData, dataFormatter, onInitializeCompleted, onInitializeFailed);
            }
        }
        private static void LoadAppSettingsData
        (
            IDataPersistence dataPersistence,
            Action <ISerializableData> onLoadCompleted = null,
            Action onLoadFailed = null)
        {
            if (dataPersistence == null)
            {
                onLoadFailed?.Invoke();
                Debug.LogWarning("DataPersistence cannot be null on persistence process.");
            }

            dataPersistence.Load <T>(m_AppSettingsDataPath,
                                     (data) =>
            {
                try
                {
                    onLoadCompleted?.Invoke(data);
                }
                catch
                {
                    onLoadFailed?.Invoke();
                }
            },
                                     () => { onLoadFailed?.Invoke(); });
        }
Beispiel #4
0
        protected override IDataPersistence CreateDataPersistenceForRemote(IDataSerializer serializer, IStorageHelper storageHelper)
        {
            IDataPersistence dataPersistence = null;

            if (m_persistenceTarget == DataPersistenceTarget.GameFoundation)
            {
#if PLAYFAB
                var dp = new PlayFabPersistenceWithIdentifier(
                    serializer, m_encrypted,
                    m_authenticator.AuthenticationId, storageHelper);
                dp.SetIdentifier(Identifier);
                dataPersistence = dp;
#endif
            }
            else
            {
#if PLAYFAB
                dataPersistence = new DefaultPlayFabPersistence(
                    serializer, m_encrypted,
                    m_authenticator.AuthenticationId, storageHelper
                    );
#endif
            }

            return(dataPersistence);
        }
Beispiel #5
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="baseAddress">Base Address,Default value is "http://localhost:8500"</param>
 public ConsulConfig(string baseAddress = "http://localhost:8500", IDataPersistence dataPersistence = null, bool isLoadConfigs = true)
 {
     _dataPersistence    = dataPersistence;
     _client             = new HttpClient();
     _client.BaseAddress = new Uri($"{baseAddress}");
     if (isLoadConfigs)
     {
         LoadConfig().GetAwaiter().GetResult();
     }
 }
Beispiel #6
0
        /// <summary>
        /// Synchronizes the confg.
        /// </summary>
        static async Task SynchronizeConfg(IDataPersistence dataPersistence, IConfig config)
        {
            var key = new Key {
                NameSpace = "ns", Environment = "pro", Version = "1.0", Tag = "His"
            };
            var value = new MyEntity {
                Name = "Gui Suwei", Sex = false
            };

            await config.Write(key, value);
        }
Beispiel #7
0
        /// <summary>
        /// Removes the config.
        /// </summary>
        static async Task RemoveConfig(IDataPersistence dataPersistence, IConfig config)
        {
            var key = new Key {
                NameSpace = "ns", Environment = "pro", Version = "1.0", Tag = "His"
            };
            var result = dataPersistence.DeleteConfig(key.ToString());

            if (result)
            {
                await config.Remove(key);
            }
        }
Beispiel #8
0
        private void LinkedToDomainObject(IBaseNode Node, IBaseNode linkedTo, List <IBaseNode> list)
        {
            IDataPersistence dataPersistence = GetIDataPersistence(Node);

            if (dataPersistence != null && dataPersistence.DataConnections.Contains(linkedTo.Reference))
            {
                list.Add(Node);
            }

            foreach (IBaseNode n in Node.Nodes)
            {
                LinkedToDomainObject(n, linkedTo, list);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Loads the config.
        /// </summary>
        static async Task <bool> LoadConfig(IDataPersistence dataPersistence, IConfig config)
        {
            var configs = dataPersistence.ReadConfigs();

            foreach (var item in configs)
            {
                var result = await config.Write(Newtonsoft.Json.JsonConvert.DeserializeObject <Key>(item.Key), Newtonsoft.Json.JsonConvert.DeserializeObject <MyEntity>(item.Value));

                if (!result)
                {
                    throw new Exception("write consul config fault");
                }
            }
            return(true);
        }
Beispiel #10
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (svc != null)
            {
                IBaseNode baseNode = context.Instance as IBaseNode;
                if (baseNode != null)
                {
                    using (DataConnectionForm frm = new DataConnectionForm(baseNode))
                    {
                        IDataPersistence dp = getDataPersistence(baseNode);
                        if (dp != null)
                        {
                            IDecisionTree tree     = baseNode.Tree;
                            List <string> Elements = new List <string>();
                            foreach (string reference in dp.DataConnections)
                            {
                                IBaseNode node = tree.GetNodeByReference(reference);
                                if (node != null)
                                {
                                    Elements.Add(node.Name);
                                }
                            }
                            frm.Elements = Elements;

                            if (svc.ShowDialog(frm) == DialogResult.OK)
                            {
                                List <string> result    = new List <string>();
                                IBaseNode     dataNodes = tree.RootNode.GetNode(eNodeType.DataObjects);
                                foreach (string name in frm.Elements)
                                {
                                    IBaseNode dc = dataNodes.GetNode(name);
                                    if (dc != null)
                                    {
                                        result.Add(dc.Reference);
                                    }
                                }

                                value = result.ToArray();
                            }
                        }
                    }
                }
            }

            return(value);
        }
Beispiel #11
0
        public static IDataPersistence GetIDataPersistence(IBaseNode node)
        {
            IDataPersistence result = null;

            if (node is IDomainObject)
            {
                result = (node as IDomainObject).DataPersistence;
            }

            if (node is IVariableDef)
            {
                result = (node as IVariableDef).DataPersistence;
            }

            return(result);
        }
Beispiel #12
0
        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (svc != null)
            {
                IBaseNode baseNode = context.Instance as IBaseNode;
                if (baseNode != null)
                {
                    using (LinkDataDefinitionsForm frm = new LinkDataDefinitionsForm(baseNode))
                    {
                        IDataPersistence dp = getDataPersistence(baseNode);
                        if (dp != null)
                        {
                            IDecisionTree tree = baseNode.Tree;
                            List <LinkDataDefinitionsForm.ListBoxItem> Elements = new List <LinkDataDefinitionsForm.ListBoxItem>();
                            foreach (string reference in dp.DataConnections)
                            {
                                IBaseNode node = tree.GetNodeByReference(reference);
                                if (node != null)
                                {
                                    Elements.Add(new LinkDataDefinitionsForm.ListBoxItem(node, 0));
                                }
                            }
                            frm.Elements = Elements;

                            if (svc.ShowDialog(frm) == DialogResult.OK)
                            {
                                dp.DataConnections.Clear();
                                foreach (LinkDataDefinitionsForm.ListBoxItem lbi in frm.Elements)
                                {
                                    dp.DataConnections.Add(lbi.Node.Reference);
                                }
                            }
                        }
                    }
                }
            }

            return(value);
        }
        /// <summary>
        /// Asynchronously saves data through the persistence layer.
        /// </summary>
        /// <param name="dataPersistence">The persistence layer used to execute the process</param>
        /// <param name="onSaveCompleted">Called when the saving process is completed with success</param>
        /// <param name="onSaveFailed">Called when the saving process failed</param>
        public static void SaveAppSettings(
            IDataPersistence dataPersistence,
            Action onSaveCompleted = null,
            Action onSaveFailed    = null)
        {
            if (dataPersistence == null)
            {
                onSaveFailed?.Invoke();
                Debug.LogWarning("DataPersistence cannot be null on persistence process.");
                return;
            }

            if (!AppSettings.Database.IsInitialized)
            {
                onSaveFailed?.Invoke();
                Debug.LogWarning("Cannot save AppSettings. AppSettings is not initialized.");
                return;
            }

            var appSettingsData = AppSettings.Database.GetSerializableData();

            dataPersistence.Save(m_AppSettingsDataPath, appSettingsData, onSaveCompleted, onSaveFailed);
        }
        public void TestInitializer()
        {
            // initialize fake context
            FakeContext = InitializeFakeContext<ILocationRepository>();

            // explicitly create fake dependencies that need to be intercepted
            //  (all other fake dependencies will be implicitly created by FakeContext.Resolve<>)
            _fakeDataPersistence = A.Fake<IDataPersistence>();
            _fakeDataAccessService = A.Fake<IDataAccessService>();
            _fakeLocationProxies = A.Fake<IIndex<DataSource, ILocationProxy>>();
            _fakeLoadedSubscriber = A.Fake<ILoadedSubscriber>();

            // provide fake dependencies to context
            FakeContext.Provide(_fakeDataPersistence);
            FakeContext.Provide(_fakeDataAccessService);
            FakeContext.Provide(_fakeLocationProxies);
            FakeContext.Provide(_fakeLoadedSubscriber);

            // create system-under-test instance
            _locationRepositoryForTest = FakeContext.Resolve<ILocationRepository>();
        }
Beispiel #15
0
 public CovidController(IDataPersistence provider)
 {
     _dataProvider = provider;
 }
Beispiel #16
0
        private void Client_OPCClientDataChangeEvent(object source, OPCClientDataChangeEventArgs e)
        {
            if (GlobalConfig.Global.PersistenceType == PersistenceType.Xml)
            {
                OnServiceLog("OPC读取数据不支持XML方式持久化");
                return;
            }

            if (_config == null)
            {
                OnServiceLog("配置信息为空");
                return;
            }

            List <ITag> tags = ConvertTagData(e);

            //CrossServerCache.TagCache.AddOrUpdateRange(tags);

            if (_config.OPCClientPersistence)
            {
                PersistenceType pt = GlobalConfig.Global.PersistenceType;
                if (pt == PersistenceType.CoreRT
                    //|| pt == PersistenceType.Golden
                    || pt == PersistenceType.eDNA)
                {
                    #region 写入实时数据库
                    IDbContext rdb = null;
                    try
                    {
                        rdb = DbContextPool.Pop();
                        if (rdb != null)
                        {
                            string tableName = "SSIOOpc";
                            rdb.WriteTags(tableName, e.TimeStamps, e.ItemNames, e.ItemValues);
                        }
                    }
                    catch (Exception ex)
                    {
                        OnServiceLog(ex.Message);
                    }
                    finally
                    {
                        if (rdb != null)
                        {
                            DbContextPool.Push(rdb);
                        }
                    }

                    OnServiceLog("OPC Client>>写入实时数据库操作完成。共:" + e.NumItems.ToString() + " 数据点。");
                    #endregion
                }
                else if (pt == PersistenceType.MySql ||
                         pt == PersistenceType.Oracle ||
                         pt == PersistenceType.SqlServer ||
                         pt == PersistenceType.Sqlite)
                {
                    #region 写到关系数据库
                    if (_persistence == null)
                    {
                        _persistence = DataPersistenceFactory.CreateDataPersistence(pt);
                    }

                    ((BaseSqlPersistence)_persistence).PersistenceData("", tags);

                    OnServiceLog("OPC Client>>写入关系数据库操作完成。共:" + e.NumItems.ToString() + " 数据点。");
                    #endregion
                }
            }
            else
            {
                string context = "OPC Client>>";
                for (int i = 0; i < e.NumItems; i++)
                {
                    context += String.Format("序号:{0},时间:{1},标签:{2},值:{3};", i.ToString(), e.TimeStamps[i].ToString("yyyy-MM-dd HH:mm:ss"), e.ItemNames[i], e.ItemValues[i].ToString());
                }

                OnServiceLog(context);
            }
        }