Пример #1
0
 //
 //====================================================================================================
 //
 public static void processAfterSave_AddonCollection(CoreController core, bool isDelete, string contentName, int recordID, string recordName, int recordParentID, bool useContentWatchLink)
 {
     //
     // -- if this is an add or delete, manage the collection folders
     if (isDelete)
     {
         //
         // todo - if a collection is deleted, consider deleting the collection folder (or saving as archive)
     }
     else
     {
         //
         // -- add or modify collection, verify collection /addon folder
         var addonCollection = AddonCollectionModel.create <AddonCollectionModel>(core.cpParent, recordID);
         if (addonCollection != null)
         {
             string CollectionVersionFolderName = CollectionFolderController.verifyCollectionVersionFolderName(core, addonCollection.ccguid, addonCollection.name);
             if (string.IsNullOrEmpty(CollectionVersionFolderName))
             {
                 //
                 // -- new collection
                 string CollectionVersionFolder = AddonController.getPrivateFilesAddonPath() + CollectionVersionFolderName;
                 core.privateFiles.createPath(CollectionVersionFolder);
                 CollectionFolderController.updateCollectionFolderConfig(core, addonCollection.name, addonCollection.ccguid, core.dateTimeNowMockable, CollectionVersionFolderName);
             }
         }
     }
 }
Пример #2
0
        //
        // ====================================================================================================
        /// <summary>
        /// create the colleciton zip file and return the pathFilename in the Cdn
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="collectionId"></param>
        /// <returns></returns>
        public static string createCollectionZip_returnCdnPathFilename(CPBaseClass cp, AddonCollectionModel collection)
        {
            string cdnExportZip_Filename = "";

            try {
                if ((collection == null))
                {
                    //
                    // -- exit with error
                    cp.UserError.Add("The collection you selected could not be found");
                    return(string.Empty);
                }
                using (CPCSBaseClass CS = cp.CSNew()) {
                    CS.OpenRecord("Add-on Collections", collection.id);
                    if (!CS.OK())
                    {
                        //
                        // -- exit with error
                        cp.UserError.Add("The collection you selected could not be found");
                        return(string.Empty);
                    }
                    string collectionXml  = "<?xml version=\"1.0\" encoding=\"windows-1252\"?>";
                    string CollectionGuid = CS.GetText("ccGuid");
                    if (CollectionGuid == "")
                    {
                        CollectionGuid = cp.Utils.CreateGuid();
                        CS.SetField("ccGuid", CollectionGuid);
                    }
                    string onInstallAddonGuid = "";
                    if ((CS.FieldOK("onInstallAddonId")))
                    {
                        int onInstallAddonId = CS.GetInteger("onInstallAddonId");
                        if ((onInstallAddonId > 0))
                        {
                            AddonModel addon = AddonModel.create <AddonModel>(cp, onInstallAddonId);
                            if ((addon != null))
                            {
                                onInstallAddonGuid = addon.ccguid;
                            }
                        }
                    }
                    string CollectionName = CS.GetText("name");
                    collectionXml        += System.Environment.NewLine + "<Collection";
                    collectionXml        += " name=\"" + CollectionName + "\"";
                    collectionXml        += " guid=\"" + CollectionGuid + "\"";
                    collectionXml        += " system=\"" + GenericController.getYesNo(CS.GetBoolean("system")) + "\"";
                    collectionXml        += " updatable=\"" + GenericController.getYesNo(CS.GetBoolean("updatable")) + "\"";
                    collectionXml        += " blockNavigatorNode=\"" + GenericController.getYesNo(CS.GetBoolean("blockNavigatorNode")) + "\"";
                    collectionXml        += " onInstallAddonGuid=\"" + onInstallAddonGuid + "\"";
                    collectionXml        += ">";
                    cdnExportZip_Filename = encodeFilename(cp, CollectionName + ".zip");
                    List <string> tempPathFileList = new List <string>();
                    string        tempExportPath   = "CollectionExport" + Guid.NewGuid().ToString() + @"\";
                    //
                    // --resource executable files
                    string        wwwFileList          = CS.GetText("wwwFileList");
                    string        ContentFileList      = CS.GetText("ContentFileList");
                    List <string> execFileList         = ExportResourceListController.getResourceFileList(cp, CS.GetText("execFileList"), CollectionGuid);
                    string        execResourceNodeList = ExportResourceListController.getResourceNodeList(cp, execFileList, CollectionGuid, tempPathFileList, tempExportPath);
                    //
                    // helpLink
                    //
                    if (CS.FieldOK("HelpLink"))
                    {
                        collectionXml += System.Environment.NewLine + "\t" + "<HelpLink>" + System.Net.WebUtility.HtmlEncode(CS.GetText("HelpLink")) + "</HelpLink>";
                    }
                    //
                    // Help
                    //
                    collectionXml += System.Environment.NewLine + "\t" + "<Help>" + System.Net.WebUtility.HtmlEncode(CS.GetText("Help")) + "</Help>";
                    //
                    // Addons
                    //
                    string IncludeSharedStyleGuidList = "";
                    string IncludeModuleGuidList      = "";
                    foreach (var addon in DbBaseModel.createList <AddonModel>(cp, "collectionid=" + collection.id))
                    {
                        //
                        // -- style sheet is in the wwwroot
                        if (!string.IsNullOrEmpty(addon.stylesLinkHref))
                        {
                            string filename = addon.stylesLinkHref.Replace("/", "\\");
                            if (filename.Substring(0, 1).Equals(@"\"))
                            {
                                filename = filename.Substring(1);
                            }
                            if (!cp.WwwFiles.FileExists(filename))
                            {
                                cp.WwwFiles.Save(filename, @"/* css file created as exported for addon [" + addon.name + "], collection [" + collection.name + "] in site [" + cp.Site.Name + "] */");
                            }
                            wwwFileList += System.Environment.NewLine + addon.stylesLinkHref;
                        }
                        //
                        // -- js is in the wwwroot
                        if (!string.IsNullOrEmpty(addon.jsHeadScriptSrc))
                        {
                            string filename = addon.jsHeadScriptSrc.Replace("/", "\\");
                            if (filename.Substring(0, 1).Equals(@"\"))
                            {
                                filename = filename.Substring(1);
                            }
                            if (!cp.WwwFiles.FileExists(filename))
                            {
                                cp.WwwFiles.Save(filename, @"// javascript file created as exported for addon [" + addon.name + "], collection [" + collection.name + "] in site [" + cp.Site.Name + "]");
                            }
                            wwwFileList += System.Environment.NewLine + addon.jsHeadScriptSrc;
                        }
                        collectionXml += ExportAddonController.getAddonNode(cp, addon.id, ref IncludeModuleGuidList, ref IncludeSharedStyleGuidList);
                    }
                    //
                    // Layouts
                    foreach (var layout in DbBaseModel.createList <LayoutModel>(cp, "(installedByCollectionId=" + collection.id + ")"))
                    {
                        collectionXml += ExportLayoutController.get(cp, layout);
                    }
                    //
                    // Templates
                    foreach (var template in DbBaseModel.createList <PageTemplateModel>(cp, "(collectionId=" + collection.id + ")"))
                    {
                        collectionXml += ExportTemplateController.get(cp, template);
                    }
                    //
                    // Data Records
                    string DataRecordList = CS.GetText("DataRecordList");
                    collectionXml += ExportDataRecordController.getNodeList(cp, DataRecordList, tempPathFileList, tempExportPath);
                    //
                    // CDef
                    foreach (Contensive.Models.Db.ContentModel content in createListFromCollection(cp, collection.id))
                    {
                        if ((string.IsNullOrEmpty(content.ccguid)))
                        {
                            content.ccguid = cp.Utils.CreateGuid();
                            content.save(cp);
                        }
                        XmlController xmlTool = new XmlController(cp);
                        string        Node    = xmlTool.GetXMLContentDefinition3(content.name);
                        //
                        // remove the <collection> top node
                        //
                        int Pos = Strings.InStr(1, Node, "<cdef", CompareMethod.Text);
                        if (Pos > 0)
                        {
                            Node = Strings.Mid(Node, Pos);
                            Pos  = Strings.InStr(1, Node, "</cdef>", CompareMethod.Text);
                            if (Pos > 0)
                            {
                                Node           = Strings.Mid(Node, 1, Pos + 6);
                                collectionXml += System.Environment.NewLine + "\t" + Node;
                            }
                        }
                    }
                    //
                    // Scripting Modules
                    if (IncludeModuleGuidList != "")
                    {
                        string[] Modules = Strings.Split(IncludeModuleGuidList, System.Environment.NewLine);
                        for (var Ptr = 0; Ptr <= Information.UBound(Modules); Ptr++)
                        {
                            string ModuleGuid = Modules[Ptr];
                            if (ModuleGuid != "")
                            {
                                using (CPCSBaseClass CS2 = cp.CSNew()) {
                                    CS2.Open("Scripting Modules", "ccguid=" + cp.Db.EncodeSQLText(ModuleGuid));
                                    if (CS2.OK())
                                    {
                                        string Code = CS2.GetText("code").Trim();
                                        Code           = EncodeCData(Code);
                                        collectionXml += System.Environment.NewLine + "\t" + "<ScriptingModule Name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\" guid=\"" + ModuleGuid + "\">" + Code + "</ScriptingModule>";
                                    }
                                    CS2.Close();
                                }
                            }
                        }
                    }
                    //
                    // shared styles
                    string[] recordGuids;
                    string   recordGuid;
                    if ((IncludeSharedStyleGuidList != ""))
                    {
                        recordGuids = Strings.Split(IncludeSharedStyleGuidList, System.Environment.NewLine);
                        for (var Ptr = 0; Ptr <= Information.UBound(recordGuids); Ptr++)
                        {
                            recordGuid = recordGuids[Ptr];
                            if (recordGuid != "")
                            {
                                using (CPCSBaseClass CS2 = cp.CSNew()) {
                                    CS2.Open("Shared Styles", "ccguid=" + cp.Db.EncodeSQLText(recordGuid));
                                    if (CS2.OK())
                                    {
                                        collectionXml += System.Environment.NewLine + "\t" + "<SharedStyle"
                                                         + " Name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\""
                                                         + " guid=\"" + recordGuid + "\""
                                                         + " alwaysInclude=\"" + CS2.GetBoolean("alwaysInclude") + "\""
                                                         + " prefix=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("prefix")) + "\""
                                                         + " suffix=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("suffix")) + "\""
                                                         + " sortOrder=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("sortOrder")) + "\""
                                                         + ">"
                                                         + EncodeCData(CS2.GetText("styleFilename").Trim())
                                                         + "</SharedStyle>";
                                    }
                                    CS2.Close();
                                }
                            }
                        }
                    }
                    //
                    // Import Collections
                    {
                        string Node = "";
                        using (CPCSBaseClass CS3 = cp.CSNew()) {
                            if (CS3.Open("Add-on Collection Parent Rules", "parentid=" + collection.id))
                            {
                                do
                                {
                                    using (CPCSBaseClass CS2 = cp.CSNew()) {
                                        if (CS2.OpenRecord("Add-on Collections", CS3.GetInteger("childid")))
                                        {
                                            string Guid = CS2.GetText("ccGuid");
                                            if (Guid == "")
                                            {
                                                Guid = cp.Utils.CreateGuid();
                                                CS2.SetField("ccGuid", Guid);
                                            }

                                            Node = Node + System.Environment.NewLine + "\t" + "<ImportCollection name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\">" + Guid + "</ImportCollection>";
                                        }

                                        CS2.Close();
                                    }

                                    CS3.GoNext();
                                }while (CS3.OK());
                            }
                            CS3.Close();
                        }
                        collectionXml += Node;
                    }
                    //
                    // wwwFileList
                    if (wwwFileList != "")
                    {
                        string[] Files = Strings.Split(wwwFileList, System.Environment.NewLine);
                        for (int Ptr = 0; Ptr <= Information.UBound(Files); Ptr++)
                        {
                            string pathFilename = Files[Ptr];
                            if (pathFilename != "")
                            {
                                pathFilename = Strings.Replace(pathFilename, @"\", "/");
                                string path     = "";
                                string filename = pathFilename;
                                int    Pos      = Strings.InStrRev(pathFilename, "/");
                                if (Pos > 0)
                                {
                                    filename = Strings.Mid(pathFilename, Pos + 1);
                                    path     = Strings.Mid(pathFilename, 1, Pos - 1);
                                }
                                string fileExtension = System.IO.Path.GetExtension(filename);
                                pathFilename = Strings.Replace(pathFilename, "/", @"\");
                                if (tempPathFileList.Contains(tempExportPath + filename))
                                {
                                    //
                                    // -- the path already has a file with this name
                                    cp.UserError.Add("There was an error exporting this collection because there were multiple files with the same filename [" + filename + "]");
                                }
                                else if (fileExtension.ToUpperInvariant().Equals(".ZIP"))
                                {
                                    //
                                    // -- zip files come from the collection folder
                                    CoreController core           = ((CPClass)cp).core;
                                    string         addonPath      = AddonController.getPrivateFilesAddonPath();
                                    string         collectionPath = CollectionFolderController.getCollectionConfigFolderPath(core, collection.ccguid);
                                    if (!cp.PrivateFiles.FileExists(addonPath + collectionPath + filename))
                                    {
                                        //
                                        // - not there
                                        cp.UserError.Add("There was an error exporting this collection because the zip file [" + pathFilename + "] was not found in the collection path [" + collectionPath + "].");
                                    }
                                    else
                                    {
                                        //
                                        // -- copy file from here
                                        cp.PrivateFiles.Copy(addonPath + collectionPath + filename, tempExportPath + filename, cp.TempFiles);
                                        tempPathFileList.Add(tempExportPath + filename);
                                        collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(filename) + "\" type=\"www\" path=\"" + System.Net.WebUtility.HtmlEncode(path) + "\" />";
                                    }
                                }
                                else if ((!cp.WwwFiles.FileExists(pathFilename)))
                                {
                                    cp.UserError.Add("There was an error exporting this collection because the www file [" + pathFilename + "] was not found.");
                                }
                                else
                                {
                                    cp.WwwFiles.Copy(pathFilename, tempExportPath + filename, cp.TempFiles);
                                    tempPathFileList.Add(tempExportPath + filename);
                                    collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(filename) + "\" type=\"www\" path=\"" + System.Net.WebUtility.HtmlEncode(path) + "\" />";
                                }
                            }
                        }
                    }
                    //
                    // ContentFileList
                    //
                    if (true)
                    {
                        if (ContentFileList != "")
                        {
                            string[] Files = Strings.Split(ContentFileList, System.Environment.NewLine);
                            for (var Ptr = 0; Ptr <= Information.UBound(Files); Ptr++)
                            {
                                string PathFilename = Files[Ptr];
                                if (PathFilename != "")
                                {
                                    PathFilename = Strings.Replace(PathFilename, @"\", "/");
                                    string Path     = "";
                                    string Filename = PathFilename;
                                    int    Pos      = Strings.InStrRev(PathFilename, "/");
                                    if (Pos > 0)
                                    {
                                        Filename = Strings.Mid(PathFilename, Pos + 1);
                                        Path     = Strings.Mid(PathFilename, 1, Pos - 1);
                                    }
                                    if (tempPathFileList.Contains(tempExportPath + Filename))
                                    {
                                        cp.UserError.Add("There was an error exporting this collection because there were multiple files with the same filename [" + Filename + "]");
                                    }
                                    else if ((!cp.CdnFiles.FileExists(PathFilename)))
                                    {
                                        cp.UserError.Add("There was an error exporting this collection because the cdn file [" + PathFilename + "] was not found.");
                                    }
                                    else
                                    {
                                        cp.CdnFiles.Copy(PathFilename, tempExportPath + Filename, cp.TempFiles);
                                        tempPathFileList.Add(tempExportPath + Filename);
                                        collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(Filename) + "\" type=\"content\" path=\"" + System.Net.WebUtility.HtmlEncode(Path) + "\" />";
                                    }
                                }
                            }
                        }
                    }
                    //
                    // ExecFileListNode
                    //
                    collectionXml += execResourceNodeList;
                    //
                    // Other XML
                    //
                    string OtherXML;
                    OtherXML = CS.GetText("otherxml");
                    if (Strings.Trim(OtherXML) != "")
                    {
                        collectionXml += System.Environment.NewLine + OtherXML;
                    }
                    collectionXml += System.Environment.NewLine + "</Collection>";
                    CS.Close();
                    string tempExportXml_Filename = encodeFilename(cp, CollectionName + ".xml");
                    //
                    // Save the installation file and add it to the archive
                    //
                    cp.TempFiles.Save(tempExportPath + tempExportXml_Filename, collectionXml);
                    if (!tempPathFileList.Contains(tempExportPath + tempExportXml_Filename))
                    {
                        tempPathFileList.Add(tempExportPath + tempExportXml_Filename);
                    }
                    string tempExportZip_Filename = encodeFilename(cp, CollectionName + ".zip");
                    //
                    // -- zip up the folder to make the collection zip file in temp filesystem
                    zipTempCdnFile(cp, tempExportPath + tempExportZip_Filename, tempPathFileList);
                    //
                    // -- copy the collection zip file to the cdn filesystem as the download link
                    cp.TempFiles.Copy(tempExportPath + tempExportZip_Filename, cdnExportZip_Filename, cp.CdnFiles);
                    //
                    // -- delete the temp folder
                    cp.TempFiles.DeleteFolder(tempExportPath);
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
            }
            return(cdnExportZip_Filename);
        }