예제 #1
0
        public async Task ExecuteAsync_LoggerNotInitialized_Throws()
        {
            IStep step = new LoadStep()
            {
                MemoryInBytes = 2, TimeInSeconds = 5, CpuPercentage = 2
            };

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(
                () => step.ExecuteAsync());
        }
예제 #2
0
        public void Deserialization_AllData_CreatesValidInstance()
        {
            ulong    expectedBytes = 0;
            LoadStep step          = JsonConvert.DeserializeObject <LoadStep>("{ bytes: 0, time : 10, percent : 20, processors : 2 }");

            Assert.AreEqual(20, step.CpuPercentage);
            Assert.AreEqual(10.0d, step.TimeInSeconds, 0.0001d);
            Assert.AreEqual(expectedBytes, step.MemoryInBytes);
            Assert.AreEqual(2, step.MaxProcessors);
        }
예제 #3
0
 internal static void LoadStaticFields()
 {
     tConfigWrapper.ReportErrors = false;
     tConfigWrapper.ModsPath     = Main.SavePath + "\\tConfigWrapper\\Mods";
     searchDict   = new ConcurrentDictionary <string, object>();
     containsName = typeof(IdDictionary).GetMethod("ContainsName");
     getID        = typeof(IdDictionary).GetMethod("GetId");
     LoadStep.LoadStaticFields();
     //Loaders.AssemblyLoader.LoadStaticFields();
     ModState.LoadStaticFields();
 }
예제 #4
0
 internal static void UnloadStaticFields()
 {
     tConfigWrapper.ReportErrors = false;
     tConfigWrapper.ModsPath     = null;
     searchDict   = null;
     containsName = null;
     getID        = null;
     LoadStep.UnloadStaticFields();
     //Loaders.AssemblyLoader.UnloadStaticFields();
     ModState.UnloadStaticFields();
 }
예제 #5
0
        public async Task ExecuteAsync_InvalidMaxProcessors_Throws()
        {
            IStep step = new LoadStep()
            {
                MemoryInBytes = 5, TimeInSeconds = 2.0d, CpuPercentage = 5, MaxProcessors = -1
            };
            var logger = new Mock <ILogger>(MockBehavior.Loose);

            step = step.AsTypeModel(logger.Object);

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(
                () => step.ExecuteAsync());
        }
예제 #6
0
        public async Task ExecuteAsync_ValidBytesMax_Throws()
        {
            IStep step = new LoadStep()
            {
                MemoryInBytes = ulong.MaxValue, TimeInSeconds = 2, CpuPercentage = 0
            };
            var logger = new Mock <ILogger>(MockBehavior.Loose);

            step = step.AsTypeModel(logger.Object);

            await Assert.ThrowsExceptionAsync <OutOfMemoryException>(
                () => step.ExecuteAsync());
        }
 private void loadAssetAsync(Asset asset = null)
 {
     if (_index < PreLoadAssetPaths.Length)
     {
         Debuger.Log("(" + _index + "/" + _count + ")" + "加载资源====>>>>" + PreLoadAssetPaths[_index]);
         gbb.GetResourcesManager.LoadAsync<UnityEngine.Object>(PreLoadAssetPaths[_index], loadAssetAsync);
         if (AssetLoadProgressHandler != null) AssetLoadProgressHandler(_index, _count);
         _index++;
     }else
     {
         step = LoadStep.LoadSceneStep;
     }
 }
예제 #8
0
        public IEnumerable <Table> Load(LoadStep settings)
        {
            if (_context == null)
            {
                LoadFromDb();
            }

            //bool filterSchemas = (settings.Schemas == null || settings.Schemas.Any(s => !String.IsNullOrWhiteSpace(s)));

            return(_context
                   .Where(e => TypeMatch(e, settings.EntityTypes))
                   .Where(e => !(settings.Schemas != null && settings.Schemas.Any(s => !String.IsNullOrWhiteSpace(s))) || settings.Schemas.Contains(e.Schema.ToLowerInvariant()))
                   .Where(e => !settings.Exclude.IsMatch(e.Schema, e.Name)));
        }
예제 #9
0
        public async Task ExecuteAsync_ValidState_ExecutesCorrectly()
        {
            IStep step = new LoadStep()
            {
                MemoryInBytes = 10, TimeInSeconds = 0.0d, CpuPercentage = 10
            };
            var logger = new Mock <ILogger>(MockBehavior.Loose);

            step = step.AsTypeModel(logger.Object);

            ExecutionStatus status = await step.ExecuteAsync();

            Assert.AreEqual(ExecutionStatus.Success, status);
        }
예제 #10
0
        void Update()
        {
            switch (loadStep)
            {
            case LoadStep.Prepare:
            case LoadStep.Done:
                break;

            // Save loading base scene code
            //case LoadStep.BeginBaseScene:
            //{
            //    StartCoroutine( LoadSceneAsync( "Battle", LoadSceneMode.Single ) );
            //    DebugUtils.Log( DebugUtils.Type.LoadingScene, "begin to load base data!" );
            //    loadStep = LoadStep.LoadingBaseScene;
            //    break;
            //}
            case LoadStep.BeginBattleScene:
            {
                StartCoroutine(LoadSceneAsync(battleSceneName, LoadSceneMode.Single));
                DebugUtils.Log(DebugUtils.Type.LoadingScene, "begin to load real battle scene!");
                loadStep = LoadStep.LoadingBattleScene;
                break;
            }

            case LoadStep.BeginBattleMap:
            {
                StartCoroutine(LoadMapAsync(battleMapName));
                DebugUtils.Log(DebugUtils.Type.LoadingScene, "begin to load battle map!");
                loadStep = LoadStep.LoadingBattleMap;
                break;
            }

            case LoadStep.LoadingBaseScene:
            case LoadStep.LoadingBattleScene:
            case LoadStep.LoadingBattleMap:
            {
                UpdateProgress();
                break;
            }

            default:
            {
                DebugUtils.LogError(DebugUtils.Type.LoadingScene, "There isn't such load step : " + loadStep);
                break;
            }
            }
        }
 private void loadAssetAsync(Asset asset = null)
 {
     if (_index < PreLoadAssetPaths.Length)
     {
         Debuger.Log("(" + _index + "/" + _count + ")" + "加载资源====>>>>" + PreLoadAssetPaths[_index]);
         gbb.GetResourcesManager.LoadAsync <UnityEngine.Object>(PreLoadAssetPaths[_index], loadAssetAsync);
         if (AssetLoadProgressHandler != null)
         {
             AssetLoadProgressHandler(_index, _count);
         }
         _index++;
     }
     else
     {
         step = LoadStep.LoadSceneStep;
     }
 }
예제 #12
0
        public async Task ExecuteAsync_ProcessorOverrideHigherThanProcessorCount_ExecutesCorrectly()
        {
            var   start = DateTime.UtcNow;
            IStep step  = new LoadStep()
            {
                MemoryInBytes = 10, TimeInSeconds = 0.2d, CpuPercentage = 10, MaxProcessors = int.MaxValue
            };
            var logger = new Mock <ILogger>(MockBehavior.Loose);

            step = step.AsTypeModel(logger.Object);

            ExecutionStatus status = await step.ExecuteAsync();

            var timeSpan = DateTime.UtcNow.Subtract(start);

            Assert.IsTrue(timeSpan.TotalSeconds >= 0.2d);
            Assert.AreEqual(ExecutionStatus.Success, status);
        }
예제 #13
0
        public async Task ExecuteAsync_ValidBytesOne_ExecutesCorrectly()
        {
            var   start = DateTime.UtcNow;
            IStep step  = new LoadStep()
            {
                MemoryInBytes = 1, TimeInSeconds = 1.0d, CpuPercentage = 1
            };
            var logger = new Mock <ILogger>(MockBehavior.Loose);

            step = step.AsTypeModel(logger.Object);

            ExecutionStatus status = await step.ExecuteAsync();

            var timeSpan = DateTime.UtcNow.Subtract(start);

            Assert.IsTrue(timeSpan.TotalSeconds >= 1.0d);
            Assert.AreEqual(ExecutionStatus.Success, status);
        }
        //唤醒阶段
        void Awake()
        {
            Debuger.Log("=============开始加载=============");
            Time.timeScale = 1.0f;

            if (EnterLoadHandler != null)
            {
                EnterLoadHandler();
            }

            if (PreLoadAssetPaths == null || PreLoadAssetPaths.Length == 0)
            {
                step = LoadStep.LoadSceneStep;
            }
            else
            {
                step = LoadStep.LoadAssetStep;
            }
        }
예제 #15
0
        public void Create_WithValidSetting_ReturnsStep()
        {
            string setting       = "{ type : 'LoadStep', value : { bytes : 2, time : 10, percent : 20 } }";
            var    logger        = new Mock <ILogger <NestedConfigFactory <IStep, IStep> > >(MockBehavior.Loose);
            var    loggerFactory = new Mock <ILoggerFactory>(MockBehavior.Strict);

            // Mock string implementation, called by extenstion method that takes Type
            loggerFactory.Setup(f => f.CreateLogger(It.IsAny <string>()))
            .Returns(new Mock <ILogger>().Object);

            var factory = new NestedConfigFactory <IStep, IStep>(logger.Object, loggerFactory.Object);

            IStep step = factory.Create(setting);

            Assert.IsNotNull(step, "Step should not be null");
            Assert.IsInstanceOfType(step, typeof(LoadStep), "Step should be a LoadStep instance");
            LoadStep loadStep = step as LoadStep;

            Assert.AreEqual(10, loadStep.TimeInSeconds, "Time should be set correctly");
            Assert.AreEqual(20, loadStep.CpuPercentage, "Percentage should be set correctly");
        }
예제 #16
0
    void Start()
    {
        Ins = this;
        GameData.LoadState();
        //Log.LogInfo("load start");
        if (Application.platform != RuntimePlatform.OSXEditor && Application.platform != RuntimePlatform.WindowsEditor)
        {
            strPlatform = Application.platform.ToString();
        }
        strResource     = Application.persistentDataPath + "/Resource";
        strUpdatePath   = Application.persistentDataPath + "/Update";
        strUpdateConfig = Application.persistentDataPath + "/" + "config.xml";
        //can not use Application.streamingAssetsPath in other thread so save it
        GameObject.DontDestroyOnLoad(this);
        CreateConfig();
        //检查表是否需要全部资源替换.
        //if (CheckTableCompleted())
        //    TableUpdate();

        Global.ShowLoadingStart();
        state = LoadStep.ChcekNeedUpdate;
        StartCoroutine(RestoreUpdate());
    }
예제 #17
0
        //唤醒阶段
        void Awake()
        {
            Debuger.Log("=============开始加载=============");
            Time.timeScale = 1.0f;

            if (EnterLoadHandler != null) EnterLoadHandler();

            if (PreLoadAssetPaths == null || PreLoadAssetPaths.Length == 0)
            {
                step = LoadStep.LoadSceneStep;
            }else
            {
                step = LoadStep.LoadAssetStep;
            }
        }
예제 #18
0
        private bool LoadJobs()
        {
            if (_settingPaths == null || !_settingPaths.Any())
            {
                Log.Warning("No json settings path specified");
                return(false);
            }

            Log.Information(String.Format("Parsing {0} setting files", _settingPaths.Count()));
            foreach (var inputPath in _settingPaths)
            {
                var path = Path.GetFullPath(inputPath);
                Log.Debug(String.Format("Parsing file {0}", path));
                var settings = Newtonsoft.Json.JsonConvert.DeserializeObject <JsonSettings>(File.ReadAllText(path));

                _jobs = new List <Job>();
                int i = 1;
                Log.Debug(String.Format("Parsing job #{0}", i));
                foreach (var jsonJob in settings.Jobs)
                {
                    int  state        = 0;
                    bool preDbContext = false;
                    var  job          = new Job()
                    {
                        SettingsFile     = path,
                        WorkingDirectory = Path.GetDirectoryName(path),
                        Provider         = jsonJob.Provider,
                        ConnectionString = jsonJob.ConnectionString
                    };
                    foreach (var step in jsonJob.Steps)
                    {
                        Log.Debug(String.Format("Parsing step: {0}", step.StepType));
                        if (state == -1)
                        {
                            Log.Warning("Invalid step: no step is allowed after DbContext");
                            return(false);
                        }
                        switch (step.StepType.ToLowerInvariant())
                        {
                        case "load":
                            if (state != 0 && state != 1)
                            {
                                Log.Warning("Invalid Load Step: unallowed position in step flow");
                                return(false);
                            }
                            var loadStep = new LoadStep()
                            {
                                Name        = step.Name,
                                EntityTypes = step.EntityTypes.Select(s => s?.ToLowerInvariant()),
                                Schemas     = step.Schemas?.Select(s => s?.ToLowerInvariant()),
                                Exclude     = step.Exclude.Convert()
                            };
                            if (!ValidateStep(loadStep))
                            {
                                return(false);
                            }
                            job.Steps.Add(loadStep);
                            state = 1;
                            break;

                        case "pocogenerate":
                            if (state != 1)
                            {
                                Log.Warning("Invalid PocoGenerate Step: unallowed position in step flow");
                                return(false);
                            }
                            var pocoGenerateStep = new PocoGenerateStep()
                            {
                                Name                              = step.Name,
                                Namespace                         = step.Namespace,
                                ClassAccessModifier               = step.ClassAccessModifier,
                                ClassPartial                      = step.ClassPartial,
                                VirtualNavigationProperties       = step.VirtualNavigationProperties,
                                Usings                            = step.Usings,
                                Extends                           = step.Extends,
                                ClassNameForcePascalCase          = step.ClassNameForcePascalCase,
                                ClassNameReplace                  = step.ClassNameReplace.Select(c => c.Convert()),
                                PropertyNameForcePascalCase       = step.PropertyNameForcePascalCase,
                                PropertyNameReplace               = step.PropertyNameReplace.Select(c => c.Convert()),
                                PropertyNullableIfDefaultAndNotPk = step.PropertyNullableIfDefaultAndNotPk
                            };
                            if (!ValidateStep(pocoGenerateStep))
                            {
                                return(false);
                            }
                            job.Steps.Add(pocoGenerateStep);
                            state = 2;
                            break;

                        case "pocowrite":
                            if (state != 2)
                            {
                                Log.Warning("Invalid PocoWrite Step: unallowed position in step flow");
                                return(false);
                            }
                            var pocoWriteStep = new PocoWriteStep()
                            {
                                Name         = step.Name,
                                OutputPath   = step.OutputPath,
                                CleanFolder  = step.CleanFolder,
                                PocosExclude = step.Exclude.Convert()
                            };
                            if (!ValidateStep(pocoWriteStep))
                            {
                                return(false);
                            }
                            job.Steps.Add(pocoWriteStep);
                            state        = 0;
                            preDbContext = true;
                            break;

                        case "dbcontext":
                            if (state != 0 || !preDbContext)
                            {
                                Log.Warning("Invalid DbContext Step: unallowed position in step flow");
                                return(false);
                            }
                            var dbContextStep = new DbContextStep()
                            {
                                Name                       = step.Name,
                                OutputPath                 = step.OutputPath,
                                StubOutputPath             = step.StubOutputPath,
                                Namespace                  = step.Namespace,
                                ClassName                  = step.ClassName,
                                ClassAbstract              = step.ClassAbstract,
                                Extends                    = step.Extends,
                                IncludeIndices             = step.IncludeIndices,
                                IncludeOnModelCreatingStub = step.IncludeOnModelCreatingStub,
                                IncludeOptionalStubs       = step.IncludeOptionalStubs,
                                IncludeViews               = step.IncludeViews,
                                IncludeTablesWithoutPK     = step.IncludeTablesWithoutPK
                            };
                            if (!ValidateStep(dbContextStep))
                            {
                                return(false);
                            }
                            job.Steps.Add(dbContextStep);
                            state = -1;
                            break;
                        }
                    }
                    if (!ValidateJob(job))
                    {
                        return(false);
                    }

                    _jobs.Add(job);
                    i++;
                }
            }
            Log.Information(String.Format("Loaded {0} jobs", _settingPaths.Count()));
            return(true);
        }