public ImportListResult <ServiceDecomposition> ImportSpreadsheet(string filename)
        {
            if (filename == null)
            {
                throw new ArgumentNullException(nameof(filename));
            }

            if (!File.Exists(filename))
            {
                throw new FileNotFoundException(filename);
            }

            // Set the license for Aspose
            var license = new License();

            license.SetLicense("Aspose.Total.lic");

            var workbook = new Workbook(filename);

            var worksheet = workbook.Worksheets.GetSheetByCodeName("Decomposition");

            if (worksheet == null)
            {
                throw new ArgumentNullException(nameof(worksheet));
            }

            var importer = new WorksheetListImporter();

            var sheet = importer.Import <ServiceDecomposition>(worksheet);

            var result = new ImportListResult <ServiceDecomposition> {
                ValidationResults = sheet.ValidationResults
            };

            var lineNumber = 2;

            foreach (var line in sheet.Results)
            {
                if (!string.IsNullOrWhiteSpace(line.ServiceDomain))
                {
                    line.WorksheetName = worksheet.Name;
                    line.LineNumber    = lineNumber;

                    result.Results.Add(line);
                }

                lineNumber++;
            }

            return(result);
        }
Exemplo n.º 2
0
        public JsonResult Search(ImportSearchCriteria criteria)
        {
            ImportListResult model = new ImportListResult();

            try
            {
                DateTime?criteriaFromDate = null;
                if (!string.IsNullOrEmpty(criteria.StartDate))
                {
                    criteriaFromDate = DateTime.ParseExact(criteria.StartDate,
                                                           CommonConstant.DateFormatDisplay, CultureInfo.InvariantCulture);
                }

                DateTime?criteriaToDate = null;
                if (!string.IsNullOrEmpty(criteria.EndDate))
                {
                    criteriaToDate = DateTime.ParseExact(criteria.EndDate,
                                                         CommonConstant.DateFormatDisplay, CultureInfo.InvariantCulture);
                }

                var listData = this._tubeSampleService.GetImportList(new TubeSampleService.GetImportListParams()
                {
                    ImportId  = criteria.ImportId,
                    StartDate = criteriaFromDate,
                    EndDate   = criteriaToDate
                });
                model.ListData.AddRange(listData);
            }
            catch (BusinessException exception)
            {
                _logger.DebugFormat("BusinessException: {0}-{1}", exception.ErrorCode, exception.Message);
                model.ErrorCode        = exception.ErrorCode;
                model.ErrorDescription = exception.Message;
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("Iternal error {0}", exception));
                model.ErrorCode        = ErrorCode.InternalErrorException;
                model.ErrorDescription = CommonUtils.GetEnumDescription(ErrorCode.InternalErrorException);
            }

            return(Json(model));
        }
        public static List <TemplateRow> AsTemplateRows(this ImportListResult <ServiceDecomposition> importResults)
        {
            var templateRows = (from row in importResults.Results.OrderBy(x => x.ServiceDomain)
                                .ThenBy(x => x.ServiceFunction)
                                .ThenBy(x => x.ServiceComponentLevel1)
                                .ThenBy(x => x.ServiceComponentLevel2)
                                .ThenBy(x => x.ServiceDeliveryOrganisation)
                                .ThenBy(x => x.ServiceDeliveryUnit)
                                .ThenBy(x => x.ResolverGroup)
                                where !string.IsNullOrEmpty(row.ServiceDomain)
                                select new TemplateRow
            {
                ServiceDomain = row.ServiceDomain.SafeTrim(Validation.MaxLength.DomainName),
                ServiceFunction = row.ServiceFunction.SafeTrim(Validation.MaxLength.FunctionName),
                ServiceActivities = row.ServiceActivities.SafeTrim(Validation.MaxLength.ServiceActivities),
                ServiceComponentLevel1 = row.ServiceComponentLevel1.SafeTrim(Validation.MaxLength.ServiceComponentName),
                ServiceComponentLevel2 = row.ServiceComponentLevel2.SafeTrim(Validation.MaxLength.ServiceComponentName),
                ServiceDeliveryOrganisation = row.ServiceDeliveryOrganisation.SafeTrim(Validation.MaxLength.ServiceDeliveryOrganisationName),
                ServiceDeliveryUnit = row.ServiceDeliveryUnit.SafeTrim(Validation.MaxLength.ServiceDeliveryUnitName),
                ResolverGroup = row.ResolverGroup.SafeTrim(Validation.MaxLength.ResolverGroupName)
            }).ToList();

            return(templateRows);
        }