예제 #1
0
        private static void DownloadProjects()
        {
            try
            {
                Log.Logger.Information("Download projects started");

                var projectImporter   = ImporterFactory.GetProjectImporter();
                var projectRepository = new ProjectRepository();

                var projects = new List <RedmineProject>
                {
                    projectImporter.GetById(13),
                    projectImporter.GetById(331),
                    projectImporter.GetById(300),
                    projectImporter.GetById(365),
                    projectImporter.GetById(352)
                };

                projectRepository.Save(projects);

                Log.Logger.Information("Download projects finished");
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
            }
        }
예제 #2
0
    public static async Task Load(GameObject gameObjectLoader, string url, Action callback, Action <GameObject> onInitializeGltfObject)
    {
        ImporterFactory Factory       = null;
        bool            UseStream     = true;
        string          GLTFUri       = url;
        bool            Multithreaded = true;
        int             MaximumLod    = 300;
        int             Timeout       = 8;

        var importOptions = new ImportOptions
        {
            AsyncCoroutineHelper = gameObjectLoader.GetComponent <AsyncCoroutineHelper>() ?? gameObjectLoader.AddComponent <AsyncCoroutineHelper>()
        };

        GLTFSceneImporter sceneImporter = null;
        var cancelToken = new CancellationTokenSource();

        try
        {
            Factory = Factory ?? ScriptableObject.CreateInstance <DefaultImporterFactory>();
            if (UseStream)
            {
                var    fullPath      = GLTFUri;
                string directoryPath = URIHelper.GetDirectoryName(fullPath);
                importOptions.DataLoader = new FileLoader(directoryPath);
                sceneImporter            = Factory.CreateSceneImporter(Path.GetFileName(GLTFUri), importOptions);
            }
            else
            {
                string directoryPath = URIHelper.GetDirectoryName(GLTFUri);
                importOptions.DataLoader = new WebRequestLoader(directoryPath);
                sceneImporter            = Factory.CreateSceneImporter(URIHelper.GetFileFromUri(new Uri(GLTFUri)), importOptions);
            }
            sceneImporter.SceneParent            = gameObjectLoader.transform;
            sceneImporter.MaximumLod             = MaximumLod;
            sceneImporter.Timeout                = Timeout;
            sceneImporter.IsMultithreaded        = Multithreaded;
            sceneImporter.OnInitializeGltfObject = onInitializeGltfObject;
            mTasks.Add(cancelToken);
            await sceneImporter.LoadSceneAsync(-1, true, null, cancelToken.Token);
        }
        finally
        {
            if (importOptions.DataLoader != null)
            {
                if (sceneImporter != null)
                {
                    mCreatedScenes.Add(sceneImporter.CreatedObject);
                    if (cancelToken.IsCancellationRequested)
                    {
                        sceneImporter.CreatedObject.DestroySelf();
                    }
                    sceneImporter.Dispose();
                    sceneImporter = null;
                }
                importOptions.DataLoader = null;
            }
            callback.InvokeGracefully();
        }
    }
예제 #3
0
        public void ImportOldRepository(string fromImportPath, string toRepoName, string toRepoPath = null)
        {
            Repository  repository  = _repoManager.GetOrCreateRepository(toRepoName, toRepoPath);
            TaskManager taskManager = TaskStore.LoadTaskManager(repository);

            var       importerFactory = new ImporterFactory();
            IImporter importer        = importerFactory.CreateOldInfraImporter();

            importer.ImportFromFileToTaskManager(fromImportPath, taskManager);

            TaskStore.SaveTaskManager(repository, taskManager);
        }
예제 #4
0
 public MethodContext(Type type, Property method, PropertyDefinition methodDefinition)
 {
     Type               = type;
     Property           = method;
     PropertyDefinition = methodDefinition;
     Marker             = new MethodMarker();
     NameAlias          = new NameAliasFactory();
     Importer           = new ImporterFactory(this);
     Cloning            = new MethodCloneFactory(this);
     Mixin              = new MethodMixinExtension(this);
     Scope              = new MethodScopingExtension(this);
     Assemblies         = new AssemblyFactory();
 }
예제 #5
0
        public static int Main(string[] args)
        {
            if (args.Length < 3)
            {
                WriteHelp();
                return(-1);
            }

            var sportText = args[0];          // NBA (for now)
            var config    = args[1];          // Last10, Last15, All, or Playoffs
            var season    = args[2];          // 2014-15, 2015-16, 2016-17, etc..

            AllowedSports sport;

            if (!Enum.TryParse(sportText, true, out sport))
            {
                Console.WriteLine($"Invalid sport name '{sportText}'");
                WriteHelp();
                return(-1);
            }

            var import = ImporterFactory.GetImporterForSport(sport);

            if (!import.SetConfiguration(config, season))
            {
                Console.WriteLine($"Invalid configuration '{config}'");
                WriteHelp();
                return(-1);
            }

            var dirPath = GetOutputDirPath();

            Directory.CreateDirectory(dirPath);
            var filePath = Path.Combine(dirPath, "data.tsv");

            try
            {
                var data = import.Import() ?? GetErrorMessage("Data returned from website in unexpected format");
                var text = TsvEncoder.Encode(data);
                File.WriteAllText(filePath, text);
            }
            catch (Exception e)
            {
                File.WriteAllText(filePath, e.ToString());
                return(1);
            }

            return(0);
        }
예제 #6
0
        public void ConvertVer1Repository(string repoName)
        {
            Repository  repository  = _repoManager.GetRepository(repoName);
            TaskManager taskManager = _taskManager.RepositoryName == repoName
                                          ? _taskManager
                                          : new TaskManager(Enumerable.Empty <TaskItem>(), repository.Name);

            var       importerFactory = new ImporterFactory();
            IImporter importer        = importerFactory.CreateVer1Importer();

            importer.ImportFromFileToTaskManager(repository.Path, taskManager);

            TaskStore.SaveTaskManager(repository, taskManager);

            _output.WriteLine("Repository '{0}' converted", repository.Name);
        }
예제 #7
0
        public async Task <ActionResult> ManualImport(HttpPostedFileBase file, int accountId, ImporterType importer)
        {
            var watch       = new Stopwatch();
            var currentUser = await GetCurrentUser();

            var currentClient = await GetCurrentClient();

            var account = await Db.Accounts.FirstOrDefaultAsync(x => x.Id == accountId && x.ClientId == currentClient.Id);

            var viewModel = (await new ManualImportViewModel().Fill(Db, currentClient)).PreSelect(accountId, importer);

            watch.Start();
            try
            {
                if (account != null && file != null)
                {
                    using (var reader = new StreamReader(file.InputStream, Encoding.Default))
                    {
                        var concreteImporter = new ImporterFactory().GetImporter(reader, importer);
                        viewModel.ImportResult = await concreteImporter.LoadFileAndImport(Db, currentClient.Id, account.Id, new RulesApplier());

                        watch.Stop();

                        // save to import log
                        Db.ImportLog.Add(new ImportLog
                        {
                            AccountId            = account.Id,
                            UserId               = currentUser.Id,
                            Date                 = DateTime.UtcNow,
                            LinesDuplicatesCount = viewModel.ImportResult.DuplicateLinesCount,
                            LinesFoundCount      = viewModel.ImportResult.DuplicateLinesCount,
                            LinesImportedCount   = viewModel.ImportResult.NewLinesCount,
                            Type                 = ImportLogType.Manual,
                            Milliseconds         = (int)watch.ElapsedMilliseconds,
                            Log = null
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                viewModel.ErrorMessage = ex.Message;
            }

            return(View(viewModel));
        }
예제 #8
0
        static void Main(string[] args)
        {
            var columns = "Id,ApplicationNumber,OverdueDays,AveOverdueDays,OverdueLevel,OverdueMoney,OverduePeriods,HavePayPeriods,FinancingMaturity,TheHightOverduePeriods,TotalOverduePeriods,RemitDays,OverdueStatus,RiskLevel,FiveLevelClass,IsOverdueNow,CarAge,RedBookOfSecondHand,SaleActualSurplusMoney,SaleCurrentSurplusMoney,DQSYZJ,FinancialActualSurplusMoney,FinancialCurrentSurplusMoney,DisposalAssessmentAmount,DisposalAmount,CLSFSH,VehicleRecyclingNotice,ElectricityStatus,ElectricityOperate,LitigationStatus,LitigationOperators,LitigationDate,FamilyVisitState,HomeVisitsOperator,FamilyVisitApplicationDate,CollectState,CollectOperator,CollectApplicationDate,VehicleDisposalStatus,VehicleDisposalOperator,VehicleDisposalApplicationDate,ChargeOffStatus,ChargeOffApplicationDate,ChargeOffMoney,ChargeOffOperate,YQRQ".Split(',').ToList();
            var keys    = new List <string>()
            {
                "ApplicationNumber"
            };
            var connectionString = "data source=.;initial catalog=sa;persist security info=True;user id=dht_test;password=123456;MultipleActiveResultSets=True;";

            var singleFileImportOption = new SingleFileImportOption()
                                         .BuildDatabaseConnect(DatabaseType.SQLServer, connectionString)
                                         .BuildImportTarget(true, "OverdueInfo", columns, keys)
                                         .BuildLocalFileSource(@"E:\OverdueInfo.csv");
            var importer = ImporterFactory.CreateInstance(singleFileImportOption);

            importer.Import();
        }
예제 #9
0
        private static void DownloadIssueStatuses()
        {
            try
            {
                Log.Logger.Information("Download issue statuses started");

                var issueStatusesImporter   = ImporterFactory.GetIssueStatusesImporter();
                var issueStatusesRepository = new IssueStatusRepository();

                var statuses = issueStatusesImporter.GetAll();
                issueStatusesRepository.Save(statuses);

                Log.Logger.Information("Download issue statuses finished");
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
            }
        }
예제 #10
0
        private static async Task <ImporterBase.ImportResult> ParseAndSaveToDatabase(Db db, int clientId, int accountId, string tempFilePath, ConfigurationContainer config, ILogger logger)
        {
            logger?.Trace("Parsing file and saving to database ...");
            logger?.Trace("File size: " + new FileInfo(tempFilePath).Length + " bytes.");

            ImporterBase.ImportResult importResult;

            var importerType = (ImporterType)Enum.Parse(typeof(ImporterType), config.Erbsenzaehler.Importer);

            using (var reader = new StreamReader(tempFilePath, Encoding.UTF8))
            {
                var concreteImporter = new ImporterFactory().GetImporter(reader, importerType);
                importResult = await concreteImporter.LoadFileAndImport(db, clientId, accountId, new RulesApplier());

                logger?.Info(importResult.NewLinesCount + " line(s) created, " + importResult.DuplicateLinesCount + " duplicate line(s).");
            }

            return(importResult);
        }
예제 #11
0
        private static void DownloadEmployees()
        {
            try
            {
                Log.Logger.Information("Download users started");

                var employeeImporter   = ImporterFactory.GetEmployeeImporter();
                var employeeRepository = new EmployeeRepository();

                var employees = employeeImporter.GetAll().ToList();

                employeeRepository.Save(employees);

                Log.Logger.Information("Download users finished");
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
            }
        }
예제 #12
0
        private static void DownloadTimeRecords()
        {
            try
            {
                Log.Logger.Information("Download timeRecords started");

                var timeRecordImporter   = ImporterFactory.GetTimeRecordImporter();
                var timeRecordRepository = new TimeRecordRepository();

                foreach (var issueId in _dbContext.Issues.Where(i => i.ExternalId.HasValue).Select(i => i.ExternalId.Value).ToArray())
                {
                    var timeRecords = timeRecordImporter.GetMany(issueId: issueId).ToArray();
                    timeRecordRepository.Save(timeRecords);
                }

                Log.Logger.Information("Download timeRecords finished");
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.InnerException.Message);
            }
        }
예제 #13
0
        private static void DownloadProejectVersions()
        {
            try
            {
                Log.Logger.Information("Download project versions started");

                var projectImporter   = ImporterFactory.GetProjectImporter();
                var versionRepository = new VersionRepository();

                var projectIds = _dbContext.Projects.Where(i => i.ExternalId.HasValue).Select(i => i.ExternalId.Value).ToArray();

                foreach (var versions in projectIds.Select(projectId => projectImporter.GetAllProjectVersions(projectId).ToList()))
                {
                    versionRepository.Save(versions);
                }

                Log.Logger.Information("Download project versions finished");
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
            }
        }
예제 #14
0
        private static void DownloadIssues()
        {
            try
            {
                Log.Logger.Information("Download issues started");

                var issueImporter   = ImporterFactory.GetIssueImporter();
                var issueRepository = new IssueRepository();

                var projectIds = _dbContext.Projects.Where(i => i.ExternalId.HasValue).Select(i => i.ExternalId.Value).ToArray();

                foreach (var issues in projectIds.Select(projectId => issueImporter.GetMany(projectId).ToArray()))
                {
                    issueRepository.Save(issues);
                }

                Log.Logger.Information("Download issues finished");
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex.Message);
            }
        }
예제 #15
0
 private void menuFileOpen_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         string    fileName = openFileDialog1.FileName;
         IImporter importer = ImporterFactory.CreateImporter(model, fileName);
         try
         {
             importer.Import(fileName);
             toolStripStatusLabel1.Text = $"Количество треугольников: {model.Facets.Count}";
             SetupInitialScaleAndPosition();
         }
         catch (Exception ex)
         {
             MessageBox.Show($"Не могу прочитать файл '{fileName}'!\n{ex.Message}",
                             Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
             model.Clear();
             scale    = Vector3.One;
             position = Vector3.Zero;
             toolStripStatusLabel1.Text = string.Empty;
         }
         glControl1.Invalidate();
     }
 }
 public IssueStatusImporterTests()
 {
     _issueStatusImporter = ImporterFactory.GetIssueStatusesImporter();
 }
 public TimeRecordImporterTests()
 {
     _timeRecordImporter = ImporterFactory.GetTimeRecordImporter();
 }
        public GetNotificationsToCopyForUserHandlerTests()
        {
            userContext = new TestUserContext(UserWithNotificationsId);

            context = new TestIwsContext(userContext);

            var notification1 = NotificationApplicationFactory.Create(UserWithNotificationsId, NotificationType.Recovery,
                                                                      UKCompetentAuthority.England, 1);

            EntityHelper.SetEntityId(notification1, Notification1Id);
            var importer1 = ImporterFactory.Create(Notification1Id, new Guid("DA0C2B9A-3370-4265-BA0D-2F7030241E7C"));

            ObjectInstantiator <NotificationApplication> .SetProperty(x => x.WasteType, WasteType.CreateOtherWasteType("wood"), notification1);

            var notification2 = NotificationApplicationFactory.Create(UserWithNotificationsId, NotificationType.Recovery,
                                                                      UKCompetentAuthority.England, 2);

            EntityHelper.SetEntityId(notification2, Notification2Id);
            var importer2 = ImporterFactory.Create(Notification2Id, new Guid("CD8FE7F5-B0EF-47E4-A198-D1E531A6CCDF"));

            ObjectInstantiator <NotificationApplication> .SetProperty(x => x.WasteType, WasteType.CreateRdfWasteType(new List <WasteAdditionalInformation>
            {
                WasteAdditionalInformation.CreateWasteAdditionalInformation("toffee", 1, 10, WasteInformationType.AshContent)
            }), notification2);

            var notification3 = NotificationApplicationFactory.Create(UserWithNotificationsId, NotificationType.Disposal,
                                                                      UKCompetentAuthority.England, 1);

            EntityHelper.SetEntityId(notification3, Notification3Id);
            var importer3 = ImporterFactory.Create(Notification3Id, new Guid("AF7ADA0A-E81B-4A7F-9837-52591B219DD3"));

            ObjectInstantiator <NotificationApplication> .SetProperty(x => x.WasteType, WasteType.CreateOtherWasteType("wood"), notification3);

            var destinationNotification = NotificationApplicationFactory.Create(UserWithNotificationsId, NotificationType.Recovery,
                                                                                UKCompetentAuthority.England, 1);

            EntityHelper.SetEntityId(destinationNotification, DestinationNotificationId);

            var destinationNotification2 = NotificationApplicationFactory.Create(UserWithoutNotificationsId, NotificationType.Recovery,
                                                                                 UKCompetentAuthority.England, 1);

            EntityHelper.SetEntityId(destinationNotification2, DestinationNotificationId2);

            context.NotificationApplications.AddRange(new[]
            {
                notification1,
                notification2,
                notification3,
                destinationNotification,
                destinationNotification2
            });

            context.Exporters.AddRange(new[]
            {
                CreateExporter(Notification1Id),
                CreateExporter(Notification2Id),
                CreateExporter(Notification3Id)
            });

            context.Importers.AddRange(new[]
            {
                importer1,
                importer2,
                importer3
            });

            handler = new GetNotificationsToCopyForUserHandler(context, userContext);
        }
예제 #19
0
 public EmployeeImporterTests()
 {
     _employeeImporter = ImporterFactory.GetEmployeeImporter();
 }
예제 #20
0
 public ProjectImporterTests()
 {
     _projectImproter = ImporterFactory.GetProjectImporter();
 }
예제 #21
0
        public async Task <ActionResult> Import(ImportViewModel model)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "Username or password empty."));
                }

                var signInStatus = await SignInManager.PasswordSignInAsync(model.Username, model.Password, false, false);

                switch (signInStatus)
                {
                case SignInStatus.Success:
                    break;

                case SignInStatus.LockedOut:
                    return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "User locked."));

                default:
                    return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized, "Username or password invalid."));
                }

                var currentUser = await Db.Users.FirstAsync(x => x.UserName == model.Username);

                var currentClient = currentUser.Client;
                var account       = await Db.Accounts.FirstOrDefaultAsync(x => x.ClientId == currentClient.Id && x.Name == model.Account);

                if (account == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid account."));
                }

                ImporterType importer;
                if (!Enum.TryParse(model.Importer, true, out importer))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid importer."));
                }

                if (model.File == null || model.File.Length <= 0)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Empty file."));
                }

                var result    = new ImportResultViewModel();
                var importLog = new ImportLog
                {
                    AccountId = account.Id,
                    UserId    = currentUser.Id,
                    Date      = DateTime.UtcNow,
                    Type      = ImportLogType.AutomaticOnClient
                };
                try
                {
                    using (var stream = new MemoryStream(model.File))
                    {
                        using (var reader = new StreamReader(stream, Encoding.UTF8))
                        {
                            var concreteImporter = new ImporterFactory().GetImporter(reader, importer);
                            var importResult     = await concreteImporter.LoadFileAndImport(Db, currentClient.Id, account.Id, new RulesApplier());

                            result.IgnoredCount  = importResult.DuplicateLinesCount;
                            result.ImportedCount = importResult.NewLinesCount;

                            importLog.LinesDuplicatesCount = importResult.DuplicateLinesCount;
                            importLog.LinesFoundCount      = importResult.DuplicateLinesCount + importResult.NewLinesCount;
                            importLog.LinesImportedCount   = importResult.NewLinesCount;
                        }
                    }
                }
                catch (Exception ex)
                {
                    importLog.Log = ex.Message;
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Import failed: " + ex.Message));
                }
                finally
                {
                    // save to import log
                    stopwatch.Stop();
                    importLog.Milliseconds = (int)stopwatch.ElapsedMilliseconds;
                    Db.ImportLog.Add(importLog);
                    await Db.SaveChangesAsync();
                }

                return(Json(result));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public IssueImporterTests()
 {
     _issueImporter = ImporterFactory.GetIssueImporter();
 }