Example #1
0
 /// <summary>
 /// Update a Package.
 /// </summary>
 public void Update(Model.Package package)
 {
     //
     // todo: add other logic here.
     //
     accessor.Update(package);
 }
Example #2
0
 /// <summary>
 /// Insert a Package.
 /// </summary>
 public void Insert(Model.Package package)
 {
     //
     // todo:add other logic here
     //
     accessor.Insert(package);
 }
Example #3
0
        public void Create(Config config, int packageId)
        {
            int            logId          = 0;
            PackageService packageService = new PackageService
            {
                Config    = config,
                PackageId = packageId
            };

            try
            {
                string convertedFolderPath = config.DocumentsConvertedFolder;

                logId = packageService.ProcessStartedLog("Package generation started", config.UserId);

                Model.Package package = packageService
                                        .Load()
                                        .WithSections()
                                        .WithDocumentItems()
                                        .WithReportItems()
                                        .Package;

                package.LogId       = logId;
                package.LogProgress = packageService.UpdateProcessLog;

                new AuxDocumentManager().Process(config, package, convertedFolderPath);
                new ReportsManager().Process(config, package);
                new PackageManager().Process(config, package, convertedFolderPath);

                string packagedFile;

                if (package.IncludeToc)
                {
                    package.LogProgress(package.LogId, "Started creating table of contents");
                    string tocFilePath = new TocManager().Create(package, config);
                    package.LogProgress(package.LogId, "Completed creating table of contents");
                    packagedFile = new Files().MergeDocs(config, package, tocFilePath);
                }
                else
                {
                    packagedFile = new Files().MergeDocs(config, package);
                }

                DocumentService documentService = new DocumentService();
                string          description     = string.Format("Package output for {0} generated by {1} {2} on {3}", package.Name, config.UserFirstName, config.UserLastName, DateTime.Now.ToString("dd MMM yyyy HH:mm:ss"));

                FileInfo fileInfo = new FileInfo(config.DocumentsConvertedFolder + packagedFile);
                double   fileSize = fileInfo.Length / 1000000.0;

                documentService.AddPackgeToDocuments(config, package.Name, description, packagedFile, fileSize.ToString("N2"), logId, package.Id);

                SendSuccessEmail(config);
            }
            catch (Exception e)
            {
                packageService.ProcessFailedLog(logId, "Package generation failed", e.ToString());
                SendFailureMail(config, packageId, logId, e);
            }
        }
Example #4
0
        /// <summary>
        /// Retrieves <see cref="Stream"/> from connector. If the file name contains special characters (e.g. "%20") and cannot be retrieved, a workaround will be performed
        /// </summary>
        private static Stream GetPackageStream(ProvisioningTemplate template, Model.Package package)
        {
            var fileName  = package.Src;
            var container = String.Empty;

            if (fileName.Contains(@"\") || fileName.Contains(@"/"))
            {
                var tempFileName = fileName.Replace(@"/", @"\");
                container = fileName.Substring(0, tempFileName.LastIndexOf(@"\"));
                fileName  = fileName.Substring(tempFileName.LastIndexOf(@"\") + 1);
            }

            // add the default provided container (if any)
            if (!String.IsNullOrEmpty(container))
            {
                if (!String.IsNullOrEmpty(template.Connector.GetContainer()))
                {
                    if (container.StartsWith("/"))
                    {
                        container = container.TrimStart("/".ToCharArray());
                    }

#if !NETSTANDARD2_0
                    if (template.Connector.GetType() == typeof(Connectors.AzureStorageConnector))
                    {
                        if (template.Connector.GetContainer().EndsWith("/"))
                        {
                            container = $@"{template.Connector.GetContainer()}{container}";
                        }
                        else
                        {
                            container = $@"{template.Connector.GetContainer()}/{container}";
                        }
                    }
                    else
                    {
                        container = $@"{template.Connector.GetContainer()}\{container}";
                    }
#else
                    container = $@"{template.Connector.GetContainer()}\{container}";
#endif
                }
            }
            else
            {
                container = template.Connector.GetContainer();
            }

            var stream = template.Connector.GetFileStream(fileName, container);
            if (stream == null)
            {
                //Decode the URL and try again
                fileName = WebUtility.UrlDecode(fileName);
                stream   = template.Connector.GetFileStream(fileName, container);
            }

            return(stream);
        }
Example #5
0
        public Model.Package Delete(Model.Package packageDataModel, string userName, bool updateHistorical)
        {
            var currentCollection    = _database.GetCollection <Model.Package>(DataStoreConfiguration.CurrentPackagesCollection);
            var deletedCollection    = _database.GetCollection <Model.Package>(DataStoreConfiguration.DeletedPackagesCollection);
            var historicalCollection = _database.GetCollection <HistoricalRecord>(DataStoreConfiguration.HistoricalPackagesCollection);

            if (updateHistorical)
            {
                historicalCollection.Save(new HistoricalRecord(packageDataModel, "DELETE", userName));
            }

            var         qc       = new List <IMongoQuery>();
            IMongoQuery idClause = Query.EQ("TitleIds", BsonValue.Create(new List <int>()));

            if (packageDataModel.TitleIds != null && packageDataModel.TitleIds.Count > 0)
            {
                idClause = Query.EQ("TitleIds", BsonValue.Create(packageDataModel.TitleIds));
            }
            else if (packageDataModel.ContentIds != null && packageDataModel.ContentIds.Count > 0)
            {
                idClause = Query.EQ("ContentIds", BsonValue.Create(packageDataModel.ContentIds));
            }

            //Either AiringId or TitleId or ContentId  would be provided
            if (!string.IsNullOrEmpty(packageDataModel.AiringId))
            {
                qc.Add(Query.EQ("AiringId", packageDataModel.AiringId));
            }
            else
            {
                qc.Add(idClause);
            }

            qc.Add(Query.EQ("Type", packageDataModel.Type));
            if (!string.IsNullOrEmpty(packageDataModel.DestinationCode))
            {
                qc.Add(Query.EQ("DestinationCode", packageDataModel.DestinationCode));
            }
            else //we need to explicitly add a query to exclude
            {
                qc.Add(Query.NotExists("DestinationCode"));
            }

            currentCollection.Remove(Query.And(qc));

            deletedCollection.Update(Query.And(qc),
                                     Update.Replace(packageDataModel),
                                     UpdateFlags.Upsert);

            return(packageDataModel);
        }
        public void Process(Config config, Model.Package package, string convertedFolderPath)
        {
            int startPageNumber = 1;

            foreach (Section section in package.Sections.OrderBy(s => s.Order))
            {
                if (package.Pagination == Pagination.BySection)
                {
                    startPageNumber = 1;
                }

                foreach (Item item in section.Items.OrderBy(i => i.Order))
                {
                    if (item.ItemType == ItemType.AuxiliaryDocument)
                    {
                        if (item.AuxiliaryDocument.ConvertedFile != null)
                        {
                            item.AuxiliaryDocument.PageCount = TotalPages.GetCount(convertedFolderPath + item.AuxiliaryDocument.ConvertedFile);
                        }

                        if (item.AuxiliaryDocument.PageCount <= 0)
                        {
                            continue;
                        }

                        item.StartPageNumber = startPageNumber;
                        item.EndPageNumber   = startPageNumber + item.AuxiliaryDocument.PageCount - 1;
                        startPageNumber      = item.EndPageNumber + 1;
                    }
                    else
                    {
                        item.ReportFilter.PageCount =
                            TotalPages.GetCount(config.ReportOutputPath + item.ReportFilter.ReportPath);
                        if (item.ReportFilter.PageCount <= 0)
                        {
                            item.ReportFilter.ReportPageNumberXml = null;
                            continue;
                        }

                        item.StartPageNumber = startPageNumber;
                        item.EndPageNumber   = startPageNumber + item.ReportFilter.PageCount - 1;
                        startPageNumber      = item.EndPageNumber + 1;
                        item.ReportFilter.ReportPageNumbers =
                            GetReportPageNumbersCollection(item.ReportFilter.ReportPageNumberXml);
                    }
                }
            }
        }
        public void Process(Config config, Model.Package package, string documentsFolderPath)
        {
            ICollection <AuxDocument> convertedDocuments = new Collection <AuxDocument>();

            package.LogProgress(package.LogId, "Processing documents");
            foreach (Section section in package.Sections)
            {
                package.LogProgress(package.LogId, "Processing documents in section \"" + section.Name + "\"");
                foreach (Item item in section.Items.Where(i => i.ItemType == ItemType.AuxiliaryDocument))
                {
                    if (!item.AuxiliaryDocument.ConversionRequired)
                    {
                        continue;
                    }

                    if (!File.Exists(documentsFolderPath + item.AuxiliaryDocument.SourceFile))
                    {
                        continue;
                    }

                    package.LogProgress(package.LogId, "Converting document for \"" + item.Name + "\"");
                    switch (item.AuxiliaryDocument.DocumentType)
                    {
                    case DocumentType.Word:
                        new WordConvert().ToPdf(item.AuxiliaryDocument, documentsFolderPath, convertedDocuments, config);

                        break;

                    case DocumentType.Excel:
                        new ExcelConvert().ToPdf(item.AuxiliaryDocument, documentsFolderPath, convertedDocuments, config);
                        break;

                    case DocumentType.Pdf:
                        new PdfConvert().ToPdf(item.AuxiliaryDocument, documentsFolderPath, convertedDocuments);

                        break;

                    default:
                        continue;
                    }
                }
                package.LogProgress(package.LogId, "Completed processing documents in section \"" + section.Name + "\"");
            }
            package.LogProgress(package.LogId, "Completed documents conversion");
            PackageItemService packageItemService = new PackageItemService();

            packageItemService.UpdateConverted(convertedDocuments, config);
        }
 public void Process(Config config, Model.Package package)
 {
     package.LogProgress(package.LogId, "Processing reports");
     foreach (Section section in package.Sections)
     {
         package.LogProgress(package.LogId, "Processing reports in section \"" + section.Name + "\"");
         foreach (Item item in section.Items.Where(i => i.ItemType == ItemType.Report))
         {
             package.LogProgress(package.LogId, "Generating report \"" + item.Name + "\"");
             StarchefReportingEngine engine = new StarchefReportingEngine();
             engine.Run(config, item.ReportFilter, package.PageSetting.Paper);
         }
         package.LogProgress(package.LogId, "Completed processing reports in section \"" + section.Name + "\"");
     }
     package.LogProgress(package.LogId, "Completed generating reports");
 }
Example #9
0
        public PackageDialog(Model.Package package, ModelController controller)
        {
            InitializeComponent();

            this.controller = controller;
            this.package    = package;
            this.Title      = string.Format("Package: {0}", package.QualifiedName);

            oldName     = package.Name;
            tbName.Text = package.Name;

            SubpackagesGetter    subpackagesGetter = new SubpackagesGetter(controller.Model);
            Collection <Package> packages          = subpackagesGetter.GetSubpackages(package);

            cbPackages.ItemsSource  = packages;
            cbPackages.SelectedItem = package.NestingPackage;
        }
        public object Resolve(object source, Dictionary <String, IResolver> resolvers = null, Boolean recursive = false)
        {
            var result = new AppCatalog();

            var appCatalogPackages = source.GetPublicInstancePropertyValue("AppCatalog");

            if (null != appCatalogPackages)
            {
                foreach (var p in ((IEnumerable)appCatalogPackages))
                {
                    var targetItem = new Model.Package();
                    PnPObjectsMapper.MapProperties(p, targetItem, resolvers, recursive);
                    result.Packages.Add(targetItem);
                }
            }

            return(result);
        }
Example #11
0
 internal override void CommandOperation()
 {
     nestingPackage = DeletedPackage.NestingPackage;
     nestingPackage.NestedPackages.Remove(DeletedPackage);
 }
Example #12
0
 public Model.Package GetNext(Model.Package e)
 {
     return(accessor.GetNext(e));
 }
Example #13
0
 public Model.Package GetPrev(Model.Package e)
 {
     return(accessor.GetPrev(e));
 }
Example #14
0
 public bool HasRowsAfter(Model.Package e)
 {
     return(accessor.HasRowsAfter(e));
 }
Example #15
0
 public bool HasRowsBefore(Model.Package e)
 {
     return(accessor.HasRowsBefore(e));
 }
Example #16
0
        public Model.Package Save(Model.Package packageDataModel, string userName, bool updateHistorical)
        {
            var collection           = _database.GetCollection <Model.Package>(DataStoreConfiguration.CurrentPackagesCollection);
            var deletedCollection    = _database.GetCollection <Model.Package>(DataStoreConfiguration.DeletedPackagesCollection);
            var historicalCollection = _database.GetCollection <Model.Package>(DataStoreConfiguration.HistoricalPackagesCollection);

            var         qc       = new List <IMongoQuery>();
            IMongoQuery idClause = Query.EQ("TitleIds", BsonValue.Create(new List <int>()));

            if (packageDataModel.TitleIds != null && packageDataModel.TitleIds.Count > 0)
            {
                idClause = Query.EQ("TitleIds", BsonValue.Create(packageDataModel.TitleIds));
            }
            else if (packageDataModel.ContentIds != null && packageDataModel.ContentIds.Count > 0)
            {
                idClause = Query.EQ("ContentIds", BsonValue.Create(packageDataModel.ContentIds));
            }

            //Either AiringId or TitleId or ContentId  would be provided
            if (!string.IsNullOrEmpty(packageDataModel.AiringId))
            {
                qc.Add(Query.EQ("AiringId", packageDataModel.AiringId));
            }
            else
            {
                qc.Add(idClause);
            }

            qc.Add(Query.EQ("Type", packageDataModel.Type));
            if (!string.IsNullOrEmpty(packageDataModel.DestinationCode))
            {
                qc.Add(Query.EQ("DestinationCode", packageDataModel.DestinationCode));
            }
            else //we need to explicitly add a query to exclude
            {
                qc.Add(Query.NotExists("DestinationCode"));
            }


            Model.Package matchingPkg = collection
                                        .Find(Query.And(qc))
                                        .AsQueryable().FirstOrDefault();

            Model.Package deletedPkg = deletedCollection
                                       .Find(Query.And(qc))
                                       .AsQueryable().FirstOrDefault();

            //match for a previously "deleted" package
            if (deletedPkg != null)
            {
                deletedCollection.Remove(Query.And(qc)); //remove it
            }
            if (matchingPkg != null)                     //if there is already a package with same TitleIds or ContentIds or AiringId , DestinationCode and Type in Package -- then overwrite the package.
            {
                matchingPkg.PackageData = packageDataModel.PackageData;
                collection.Update(Query.EQ("_id", matchingPkg.Id), Update.Replace(matchingPkg));
                if (updateHistorical)
                {
                    historicalCollection.Save(new HistoricalRecord(packageDataModel, "MODIFY", userName));
                }
                return(matchingPkg);
            }
            else //otherwise simply store it
            {
                collection.Save(packageDataModel);
                if (updateHistorical)
                {
                    historicalCollection.Save(new HistoricalRecord(packageDataModel, "CREATE", userName));
                }
                return(packageDataModel);
            }
        }
Example #17
0
        public List<Model.Package> GetList(Int64 _PackageID, String _PackageName, int _Start, int _Limit)
        {
            try
            {
                List<Model.Package> lModel = new List<Model.Package>();

                SqlParameter[] p =  {
                                        new SqlParameter("@PackageID", SqlDbType.BigInt, 8),
                                        new SqlParameter("@PackageName", SqlDbType.NVarChar, 500),
                                        new SqlParameter("@Start", SqlDbType.Int, 4),
                                        new SqlParameter("@Limit", SqlDbType.Int, 4)
                                    };
                p[0].Value = _PackageID;
                p[1].Value = _PackageName;
                p[2].Value = _Start;
                p[3].Value = _Limit;

                DataTable dt = db.ExcuteSelectReturnDataTable("dbo.Package_Select", CommandType.StoredProcedure, p);

                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        Model.Package model = new Model.Package();

                        model.Ind = Convert.ToInt32(dr["Ind"].ToString());
                        model.PackageID = Convert.ToInt32(dr["PackageID"].ToString());
                        model.PackageName = dr["PackageName"].ToString();
                        model.Intro = dr["Intro"].ToString();
                        model.CreateBy = dr["CreateBy"].ToString();
                        model.CreateTime = dr["CreateTime"].ToString();
                        model.UpdateBy = dr["UpdateBy"].ToString();
                        model.UpdateTime = dr["UpdateTime"].ToString();
                        model.TotalRow = Convert.ToInt32(dr["TotalRow"].ToString());
                        lModel.Add(model);
                    }

                    return lModel;
                }
                else
                {
                    return null;
                }

            }
            catch (Exception ex)
            {
                PTSLog.Error(ex.Message);
                return null;
            }
        }