Beispiel #1
0
        public void ImportWorkflow(FileInfo importFile, XmlImportInfo importInfo)
        {
            var accountModel = System.Web.HttpContext.Current.Session["allClientsAccountModel"] as AllClientsAccountModel;

            if (accountModel != null)
            {
                var results = WorkflowInvoker.Invoke(new ClientFileImportActivity(),
                                       new Dictionary<string, object> { { "clientId", accountModel.ClientId }, { "importFile", importFile } });
                int importCount = 0;
                int failureCount = 0;
                int.TryParse(results["importCountArg"].ToString(), out importCount);
                int.TryParse(results["ImportFailureArg"].ToString(), out failureCount);
                importInfo.SuccessCount = importCount;
                importInfo.FailureCount = failureCount;
            }
        }
Beispiel #2
0
        public XmlImportInfo TransformToXml(CsvFileInfo csvFileInfo, List<FieldMap> fieldMaps)
        {

            string csvFilePath = csvFileInfo.Path;
            var rawRows = GetRawRows(csvFilePath).Skip(csvFileInfo.FirstRowContainsColumnHeadings ? 1 : 0);
            var category = _xmlRepository.GetCategory(csvFileInfo.Category);
            var flag = _xmlRepository.GetFlag(csvFileInfo.Flag);

            var rowsToContacts = ConvertRowsToContacts(rawRows, fieldMaps, category, flag);

            var xmlFilePath = csvFilePath.Replace(Path.GetExtension(csvFilePath), ".xml");
            XmlImportInfo importResult = null;
            try
            {
                GenerateXml(rowsToContacts.Contacts, xmlFilePath);
                using (DomainContext ctx = new DomainContext())
                {
                    var account = System.Web.HttpContext.Current.Session["allClientsAccountModel"] as AllClientsAccountModel;
                    var importRecord = new ClientFileImport();
                    importRecord.Id = Guid.NewGuid();
                    importRecord.ImportedFilePath = xmlFilePath;
                    importRecord.UploadFilePath = csvFileInfo.Path;
                    importRecord.RecordsImported = rowsToContacts.SuccessCount;
                    importRecord.RecordsFailed = rowsToContacts.FailureCount;
                    importRecord.ClientId = account.ClientId;
                    importRecord.LastUpdated = System.DateTime.Now;
                    ctx.ClientFileImport.InsertOnSubmit(importRecord);
                    ctx.SubmitChanges();
                }
                var importFile = new FileInfo(xmlFilePath);
                importResult = new XmlImportInfo { SuccessCount = rowsToContacts.SuccessCount, FailureCount = rowsToContacts.FailureCount, DuplicateCount = rowsToContacts.DuplicateCount, FileName = Path.GetFileName(xmlFilePath) };
                ImportWorkflow(importFile, importResult);
            }
            catch (Exception e)
            {
                throw e;
            }
            return importResult;
        }