public ImportStatus Add(string url, string userName, string password, bool importClosed, bool disableNotifications, bool importUsersAsCollaborators, IEnumerable <int> projects)
        {
            if (!CoreContext.UserManager.IsUserInGroup(SecurityContext.CurrentAccount.ID, Core.Users.Constants.GroupAdmin.ID))
            {
                throw new SecurityException();
            }

            //Validate all data
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException(ImportResource.EmptyURL);
            }

            if (string.IsNullOrEmpty(userName))
            {
                throw new ArgumentException(ImportResource.EmptyEmail);
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException(ImportResource.EmptyPassword);
            }

            if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                throw new ArgumentException(ImportResource.MalformedUrl);
            }

            ImportQueue.Add(url, userName, password, importClosed, disableNotifications, importUsersAsCollaborators, projects);

            MessageService.Send(Request, MessageAction.ProjectsImportedFromBasecamp, url);

            return(GetStatus());
        }
        public ImportResult ProcessImportQueue(ImportQueue queuedItem, ImportFileSettings fileSettings)
        {
            var result = new ImportResult();

            queuedItem.ImportData = GetImportFileAsDataTable(queuedItem, fileSettings);

            // Validate the import data with some quick sanity checks

            var validator        = new ImportDataValidator();
            var validationResult = validator.Validate(queuedItem);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }

            queuedItem = BulkImportDataTableToDataStore(queuedItem);
            queuedItem = ProcessImportData(queuedItem);

            //File.Delete(queuedItem.FilePath);

            result.Status     = queuedItem.ImportStatus;
            result.TakeRateId = queuedItem.TakeRateId;

            return(result);
        }
Ejemplo n.º 3
0
        public ImportQueue ProcessTakeRateData(ImportQueue importQueue)
        {
            TakeRateSummary takeRateFile = new EmptyTakeRateSummary();

            using (var conn = DbHelper.GetDBConnection())
            {
                using (var tran = conn.BeginTransaction())
                {
                    try
                    {
                        var para = new DynamicParameters();
                        para.Add("@FdpImportId", importQueue.ImportId, DbType.Int32);

                        var results = conn.Query <TakeRateSummary>("dbo.Fdp_ImportData_ProcessTakeRateData", para,
                                                                   commandType: CommandType.StoredProcedure, commandTimeout: 600, transaction: tran);
                        var takeRateSummaries = results as IList <TakeRateSummary> ?? results.ToList();
                        if (results != null && takeRateSummaries.Any())
                        {
                            takeRateFile = takeRateSummaries.First();
                        }

                        tran.Commit();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                        throw;
                    }
                }
            }
            var retVal = ImportQueueGet(importQueue.ImportQueueId.GetValueOrDefault());

            retVal.TakeRateId = takeRateFile.TakeRateId;
            return(retVal);
        }
Ejemplo n.º 4
0
        public static ImportQueue ToImportQueue(ImportQueueDataItem dataItem)
        {
            var queue = new ImportQueue
            {
                ImportQueueId    = dataItem.FdpImportQueueId,
                ImportId         = dataItem.FdpImportId,
                CreatedOn        = dataItem.CreatedOn,
                CreatedBy        = dataItem.CreatedBy,
                UpdatedOn        = dataItem.UpdatedOn,
                OriginalFileName = dataItem.OriginalFileName,
                FilePath         = dataItem.FilePath,
                ImportStatus     = dataItem.ImportStatus,
                ImportType       = dataItem.ImportType,
                Errors           = dataItem.Errors,
                ProgrammeId      = dataItem.ProgrammeId,
                Gateway          = dataItem.Gateway,
                Document         = dataItem.Document,
                VehicleName      = dataItem.VehicleName,
                VehicleAKA       = dataItem.VehicleAKA,
                ModelYear        = dataItem.ModelYear,
                HasErrors        = dataItem.HasErrors,
                ErrorCount       = dataItem.ErrorCount,
                Error            = dataItem.Error,
                DocumentId       = dataItem.DocumentId,
                ErrorType        = dataItem.ErrorType,
                ErrorSubType     = dataItem.ErrorSubType,
                Uploaded         = dataItem.Uploaded
            };

            return(queue);
        }
Ejemplo n.º 5
0
        public ImportQueue ImportQueueBulkImport(ImportQueue importQueue)
        {
            using (var conn = DbHelper.GetDBConnection())
            {
                using (var bulk = new SqlBulkCopy((SqlConnection)conn)
                {
                    BulkCopyTimeout = 600
                })
                {
                    var columnIndex = 0;
                    bulk.DestinationTableName = "dbo.Fdp_ImportData";
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "FdpImportId"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "LineNumber"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Pipeline Code"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Model Year Desc"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "NSC or Importer Description (Vista Market)"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Country Description"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Derivative Code"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Derivative Description"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Trim Pack Description"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Bff Feature Code"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex++, "Feature Description"));
                    bulk.ColumnMappings.Add(new SqlBulkCopyColumnMapping(columnIndex, "Count of Specific Order No"));

                    bulk.WriteToServer(importQueue.ImportData);
                    bulk.Close();
                }
            }
            return(ImportQueueGet(importQueue.ImportQueueId.GetValueOrDefault()));
        }
Ejemplo n.º 6
0
        public ImportStatus StartImportFromBasecamp(string url, string token, bool processClosed, bool disableNotifications)
        {
            ProjectSecurity.DemandAuthentication();

            //Validate all data
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentException(SettingsResource.EmptyURL);
            }
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentException(SettingsResource.EmptyToken);
            }
            if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
            {
                throw new ArgumentException(SettingsResource.MalformedUrl);
            }
            if (!Regex.IsMatch(url.Trim(), @"^http[s]{0,1}://.+\.basecamphq\.com[/]{0,1}$"))
            {
                throw new ArgumentException(SettingsResource.NotBasecampUrl);
            }

            ImportQueue.Add(url, token, processClosed, disableNotifications);
            return(ImportQueue.GetStatus());
        }
Ejemplo n.º 7
0
        public async Task MoveFromProcessedToImport()
        {
            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    var processedQueueItems = _unitOfWork.GetProcessedQueueRepository().GetMultiple(q => q.ProcessStage == EnumProcessStage.PostProcess);
                    foreach (var processedQueueItem in processedQueueItems)
                    {
                        ImportQueue importQueue = new ImportQueue
                        {
                            Guid       = processedQueueItem.Guid,
                            TemplateId = processedQueueItem.TemplateId,
                            FilenameWithoutExtension = processedQueueItem.FilenameWithoutExtension,
                            Extension    = processedQueueItem.Extension,
                            Fullpath     = processedQueueItem.Fullpath,
                            ProcessStage = EnumProcessStage.Preprocess
                        };
                        _unitOfWork.GetImportQueueRepository().Add(importQueue);
                        _unitOfWork.GetProcessedQueueRepository().Delete(pq => pq.Id == processedQueueItem.Id);
                    }
                    await _unitOfWork.Commit();

                    scope.Complete();
                }
                catch (Exception ex)
                {
                    scope.Dispose();
                    throw ex;
                }
            }
        }
        public async Task <IActionResult> UploadSampleDocumentAsync(int templateId, [FromForm] UploadSampleDocumentsForm uploadSampleDocumentsForm)
        {
            List <string> supportedFileExtensions = new List <string>
            {
                "PDF",
                "TIFF",
                "JPEG",
                "PNG"
            };

            if (ModelState.IsValid)
            {
                try
                {
                    List <ImportQueue> newImportDocuments = new List <ImportQueue>();
                    foreach (var file in uploadSampleDocumentsForm.SampleDocuments)
                    {
                        var guid      = Guid.NewGuid();
                        var extension = Path.GetExtension(file.FileName).Substring(1);
                        if (!supportedFileExtensions.Contains(extension.ToUpper()))
                        {
                            return(BadRequest(new { errorMessage = "File format is not supported." }));
                        }
                        var newImportDocument = new ImportQueue
                        {
                            Guid       = guid,
                            TemplateId = templateId,
                            FilenameWithoutExtension = Path.GetFileNameWithoutExtension(file.FileName),
                            Extension    = extension,
                            Fullpath     = DocumentConfiguration.RootPath + guid.ToString() + "." + extension,
                            ProcessStage = EnumProcessStage.Preprocess
                        };
                        newImportDocuments.Add(newImportDocument);
                        _unitOfWork.GetImportQueueRepository().Add(newImportDocument);

                        // Upload File Content
                        using (FileStream fs = System.IO.File.Create(newImportDocument.Fullpath))
                        {
                            await file.CopyToAsync(fs);

                            fs.Flush();
                        }
                    }

                    await _unitOfWork.Commit();

                    return(Ok(newImportDocuments));
                }
                catch (Exception ex)
                {
                    var errorMessage = $"{ex.Message}";
                    _logger.LogError(errorMessage);
                    await _unitOfWork.Rollback();

                    return(BadRequest(new { errorMessage = errorMessage }));
                }
            }
            return(BadRequest());
        }
Ejemplo n.º 9
0
        public override void EnterImportSpec(GoParser.ImportSpecContext context)
        {
            // Remove quotes from package name
            CurrentImportPath = RemoveSurrounding(ToStringLiteral(context.importPath().string_().GetText()));

            // Add package to import queue
            ImportQueue.Add(CurrentImportPath);
        }
        public ImportStatus GetStatus()
        {
            if (!CoreContext.UserManager.IsUserInGroup(SecurityContext.CurrentAccount.ID, Core.Users.Constants.GroupAdmin.ID))
            {
                throw new SecurityException();
            }

            return(ImportQueue.GetStatus());
        }
        public ImportResult ReprocessImportQueue(ImportQueue queuedItem)
        {
            var result = new ImportResult();

            queuedItem    = ProcessImportData(queuedItem);
            result.Status = queuedItem.ImportStatus;

            return(result);
        }
 private void DeleteDumpFiles()
 {
     foreach (ImportQueueItemViewModel importQueueItemViewModel in
              ImportQueue.Where(importQueueItem => importQueueItem.Status == ImportQueueItemStatus.IMPORT_SUCCESSFUL))
     {
         SharedSetupContext.Collection collection = importQueueItemViewModel.Collection;
         if (collection.IsDeleted)
         {
             File.Delete(importQueueItemViewModel.Collection.DownloadFilePath);
             collection.IsDeleted = true;
         }
     }
 }
Ejemplo n.º 13
0
        private async Task <ImportResult> ReProcessException(ImportError exception)
        {
            if (!ConfigurationSettings.GetBoolean("ReprocessImportAfterHandleError"))
            {
                return(null);
            }

            var queuedItem = new ImportQueue()
            {
                ImportId      = exception.FdpImportId,
                ImportQueueId = exception.ImportQueueId,
                LineNumber    = int.Parse(exception.LineNumber)
            };

            return(await Task.FromResult(DataContext.Import.ReprocessImportQueue(queuedItem)));
        }
        public async Task <ImportResult> ProcessTakeRateData(ImportQueue queuedItem)
        {
            var result = new ImportResult();

            // Redo any worktray errors first
            queuedItem = ProcessImportData(queuedItem);
            if (queuedItem.HasErrors)
            {
                return(result);
            }

            queuedItem        = _importDataStore.ProcessTakeRateData(queuedItem);
            result.Status     = queuedItem.ImportStatus;
            result.TakeRateId = queuedItem.TakeRateId;

            return(result);
        }
        private ImportQueue BulkImportDataTableToDataStore(ImportQueue importQueue)
        {
            var importColumn     = importQueue.ImportData.Columns.Add("FdpImportId", typeof(Int32));
            var lineNumberColumn = importQueue.ImportData.Columns.Add("LineNumber", typeof(Int32));

            importColumn.SetOrdinal(0);
            lineNumberColumn.SetOrdinal(1);

            var lineNumber = 0;

            foreach (DataRow row in importQueue.ImportData.Rows)
            {
                row[importColumn]     = importQueue.ImportId;
                row[lineNumberColumn] = ++lineNumber;
            }

            return(_importDataStore.ImportQueueBulkImport(importQueue));;
        }
        private void SelectNextImportQueueItem()
        {
            foreach (ImportQueueItemViewModel importQueueItemViewModel in ImportQueue)
            {
                importQueueItemViewModel.IsNextInQueue = false;
            }
            ImportQueueItemViewModel nextImportQueueItem =
                ImportQueue.FirstOrDefault(importQueueItem => importQueueItem.Status == ImportQueueItemStatus.NOT_IMPORTED ||
                                           importQueueItem.Status == ImportQueueItemStatus.IMPORT_CANCELLED || importQueueItem.Status == ImportQueueItemStatus.IMPORT_ERROR);

            if (nextImportQueueItem != null)
            {
                nextImportQueueItem.IsNextInQueue = true;
                HideNextButton();
            }
            else
            {
                ShowNextButton();
            }
        }
Ejemplo n.º 17
0
        public ImportQueue ImportQueueSave(ImportQueue importQueue)
        {
            ImportQueue retVal;

            using (var conn = DbHelper.GetDBConnection())
            {
                try
                {
                    var para = new DynamicParameters();

                    para.Add("@CDSId", CurrentCDSID, DbType.String, size: 16);
                    para.Add("@OriginalFileName", importQueue.OriginalFileName, DbType.String);
                    para.Add("@FilePath", importQueue.FilePath, DbType.String);
                    para.Add("@FdpImportTypeId", (int)importQueue.ImportType.ImportTypeDefinition, DbType.Int32);
                    para.Add("@FdpImportStatusId", (int)importQueue.ImportStatus.ImportStatusCode, DbType.Int32);
                    para.Add("@ProgrammeId", importQueue.ProgrammeId, DbType.Int32);
                    para.Add("@Gateway", importQueue.Gateway, DbType.String);
                    para.Add("@DocumentId", importQueue.DocumentId, DbType.Int32);

                    var result = conn
                                 .Query <ImportQueueDataItem>("dbo.Fdp_ImportQueue_Save", para, commandType: CommandType.StoredProcedure)
                                 .FirstOrDefault();

                    result.ImportType   = ImportTypeDataItem.ToImportType(result);
                    result.ImportStatus = ImportStatusDataItem.ToImportStatus(result);
                    //HydrateImportErrors(result, conn);

                    retVal = ImportQueueDataItem.ToImportQueue(result);
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    throw;
                }
            }

            return(retVal);
        }
        public ActionResult Upload(HttpPostedFileBase fileToUpload,
                                   string carLine,
                                   string modelYear,
                                   string gateway,
                                   int?documentId)
        {
            Parameters = new ImportParameters
            {
                Action     = ImportAction.Upload,
                UploadFile = fileToUpload,
                CarLine    = carLine,
                ModelYear  = modelYear,
                Gateway    = gateway,
                DocumentId = documentId
            };
            ValidateImportParameters(ImportParametersValidator.Upload);

            SetProgrammeId();
            SetUploadFilePath();
            SaveImportFileToFileSystem();
            QueueItemForProcessing();
            ProcessQueuedItem();
            //ValidateProcessedItem();
            RefreshQueuedItem();

            var retVal = JsonGetSuccess();

            if (CurrentQueuedItem.HasErrors)
            {
                retVal = JsonGetFailure(string.Format("Import Completed with {0} {1} error(s)",
                                                      CurrentQueuedItem.ErrorCount,
                                                      ImportQueue.GetErrorTypeAbbreviation(CurrentQueuedItem.ErrorType)));
            }

            return(retVal);
        }
Ejemplo n.º 19
0
        public ImportStatus GetImportFromBasecampStatus()
        {
            ProjectSecurity.DemandAuthentication();

            return(ImportQueue.GetStatus());
        }
 public int CheckUsersQuota(string url, string userName, string password)
 {
     return(ImportQueue.CheckUsersQuota(url, userName, password));
 }
 public IEnumerable <ObjectWrapperBase> GetProjectsForImport(string url, string userName, string password)
 {
     return(ImportQueue.GetProjects(url, userName, password).Select(x => new ObjectWrapperBase {
         Id = x.ID, Title = x.Title, Status = (int)x.Status, Responsible = new EmployeeWraperFull()
     }).ToSmartList());
 }
 private ImportQueue ProcessImportData(ImportQueue importQueue)
 {
     return(_importDataStore.ImportQueueBulkImportProcess(importQueue));
 }
 public ImportQueue SaveImportQueue(ImportQueue importItem)
 {
     return(_importDataStore.ImportQueueSave(importItem));
 }
        public async Task <ImportQueue> GetProcessStatus(ImportQueue importItem)
        {
            var importQueueId = importItem.ImportQueueId.GetValueOrDefault();

            return(await Task.FromResult(_importDataStore.ImportQueueGet(importQueueId)));
        }
 Task <ImportStatus> IImportDataContext.GetProcessStatus(ImportQueue importItem)
 {
     throw new NotImplementedException();
 }
 private void QueueItemForProcessing()
 {
     CurrentQueuedItem = DataContext.Import.SaveImportQueue(ImportQueue.FromParameters(Parameters));
 }
 private static DataTable GetImportFileAsDataTable(ImportQueue queuedItem, ImportFileSettings settings)
 {
     return(ExcelReader.ReadExcelAsDataTable(queuedItem.FilePath, settings));
 }