protected SyncResult DownloadAllDataForSync(DateTime lastSyncDate) { var resultBase = DownloadBaseData(); var standardSyncItems = Task.Run(() => ConnectorLocator.SyncConnector.GetStandardsSyncData(lastSyncDate, 0, int.MaxValue)); var topicSyncItems = Task.Run(() => ConnectorLocator.SyncConnector.GetTopicsSyncData(lastSyncDate, 0, int.MaxValue)); var syncRes = new SyncResult(resultBase) { StandardSyncItems = standardSyncItems.Result, TopicSyncItems = topicSyncItems.Result }; var standardIds = syncRes.StandardSyncItems.Select(x => x.Id); var standardLoader = new LoaderBase <Guid, AcademicBenchmarkConnector.Models.Standard>(standardIds); syncRes.Standards = standardLoader.Load(id => Task.Run(() => ConnectorLocator.StandardsConnector.GetStandardById(id)).Result); var topicIds = syncRes.TopicSyncItems.Select(x => x.Id); var topicLoader = new LoaderBase <Guid, AcademicBenchmarkConnector.Models.Topic>(topicIds); syncRes.Topics = topicLoader.Load(id => Task.Run(() => ConnectorLocator.TopicsConnector.GetTopic(id)).Result); Log.LogInfo("Downloaded Standard, Topic sync data"); return(syncRes); }
//construction and initialization public static ILoad Create(string path) { InstanceChooser myChooser = new InstanceChooser(); LoaderBase myLoader = myChooser.Choose(path); if (myLoader != null) { myLoader.Load(path); //virtual method call moved out of constructor. } return(myLoader); }
private IEnumerator LoadingProcess(LoaderBase loader) { _core.Services.Clear(); loader.Load(_core); var loadingAsyncOperation = SceneManager.LoadSceneAsync(loader.Path); if (loadingAsyncOperation != null) { while (!loadingAsyncOperation.isDone) { yield return(new WaitForEndOfFrame()); } } _isLoading = false; }
protected void FullImport() { Log.LogInfo("Last sync date is empty. Started full import."); var importResult = DownloadAllDataForImport(); var dbService = (ImportDbService)ServiceLocator.DbService; dbService.BeginTransaction(); Log.LogInfo("Started database transaction"); var pingThread = new Thread(PingConnection); pingThread.Start(dbService); try { ServiceLocator.SyncService.BeforeSync(); ProcessImportResult(importResult); } catch (Exception e) { Log.LogInfo($"Error: {e.Message}"); Log.LogInfo("Transaction is going to rollback"); dbService.Rollback(); throw; } finally { try { pingThread.Abort(); } catch (Exception) { // ignored } } ServiceLocator.SyncService.AfterSync(); dbService.CommitAll(); Log.LogInfo("Transaction was commited"); /////////////////////////////////////Proccessing Standardar Relations in another transaction//////////////////////////////////////////////////// var standardIds = importResult.Standards.Select(x => x.Id).ToList(); Log.LogInfo("Loading Standard Relations . . ."); var standardRelLoader = new LoaderBase <Guid, AcademicBenchmarkConnector.Models.StandardRelations>(standardIds); var standardRels = standardRelLoader.Load(id => Task.Run(() => ConnectorLocator.StandardsConnector.GetStandardRelationsById(id)).Result); dbService.BeginTransaction(); Log.LogInfo("Started database transaction"); pingThread = new Thread(PingConnection); pingThread.Start(dbService); try { var standardDerivatives = new List <StandardDerivative>(); foreach (var standardRel in standardRels) { standardDerivatives.AddRange(MapperHelper.Map(standardRel) ?? new List <StandardDerivative>()); } ServiceLocator.StandardDerivativeService.Add(standardDerivatives); } catch (Exception e) { Log.LogError($"Error: {e.Message}"); Log.LogInfo("Transaction is going to rollback"); dbService.Rollback(); throw; } finally { try { pingThread.Abort(); } catch (Exception) { // ignored } } ServiceLocator.SyncService.UpdateLastSyncDate(DateTime.UtcNow.Date); dbService.CommitAll(); Log.LogInfo("Transaction was commited."); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }