Exemple #1
0
 public static void RenderPostSave(Asset asset, PostSaveContext context)
 {
     asset.DeleteContentField("log_message");
 }
Exemple #2
0
        public static void ExportPostSave(Asset asset, Context context)
        {
            IhSiteBuilderLog siteLog = new IhSiteBuilderLog();
            if (asset.Raw["export_site_option"].Equals("yes"))
            {
                Dictionary<string, string> dicLog = new Dictionary<string, string>();

                try
                {
                    Asset aSiteRootFolder;
                    Asset aProjectFolder;
                    Asset aTemplateFolder;
                    Asset aModelFolder;
                    Asset aNavTemplate;
                    Asset aLibraryFolder;
                    string szNavPath = string.Empty;
                    string szNamespace = string.Empty;

                    bool bContent = asset.Raw["include_contents"].Equals("true") ? true : false;
                    bool bBinary = asset.Raw["include_Binaries"].Equals("true") ? true : false;
                    bool bWrapper = asset.Raw["include_Wrappers"].Equals("true") ? true : false;

                    switch (asset.Raw["extract_type"])
                    {
                        case "system":
                            //Required values
                            aSiteRootFolder = Asset.Load(asset.Raw["sys_site_root_folder"]);

                            //Optional values
                            aTemplateFolder = Asset.Load(asset.Raw["sys_template_folder"]);
                            aModelFolder = Asset.Load(asset.Raw["sys_model_folder"]);

                            aNavTemplate = Asset.Load(asset.Raw["sys_nav_wrap_location"]);
                            if (aNavTemplate.IsLoaded)
                                szNavPath = aNavTemplate.AssetPath.ToString();

                            aLibraryFolder = Asset.Load(asset.Raw["sys_library_folder"]);

                            if (aSiteRootFolder.IsLoaded)
                            {
                                IhSiteBuilderExport.ExportSiteRoot(
                                    asset, aSiteRootFolder,
                                    template: aTemplateFolder,
                                    model: aModelFolder,
                                    library: aLibraryFolder,
                                    clientName: context.ClientName,
                                    navWrapPath: szNavPath,
                                    includeContent: bContent,
                                    includeBinary: bBinary,
                                    includeWrapper: bWrapper,
                                    dicLog: dicLog
                                    );
                            }
                            else
                            {
                                siteLog.Add("SiteRoot not loaded");
                            }
                            break;
                        case "project":
                            //Required values
                            aSiteRootFolder = Asset.Load(asset.Raw["pro_site_root_folder"]);
                            aProjectFolder = Asset.Load(asset.Raw["pro_project_folder"]);

                            aNavTemplate = Asset.Load(asset.Raw["pro_nav_wrap_location"]);
                            if (aNavTemplate.IsLoaded)
                                szNavPath = aNavTemplate.AssetPath.ToString();

                            if (aSiteRootFolder.IsLoaded && aProjectFolder.IsLoaded)
                            {
                                //Optional values
                                aTemplateFolder = Asset.Load(asset.Raw["pro_template_folder"]);
                                if (!aTemplateFolder.IsLoaded)
                                    aTemplateFolder = Asset.Load(aProjectFolder.AssetPath + "/Templates");

                                aModelFolder = Asset.Load(asset.Raw["pro_model_folder"]);
                                if (!aModelFolder.IsLoaded)
                                    aModelFolder = Asset.Load(aProjectFolder.AssetPath + "/Models");

                                aLibraryFolder = Asset.Load(asset.Raw["pro_library_folder"]);
                                if (!aLibraryFolder.IsLoaded)
                                    aLibraryFolder = Asset.Load(aProjectFolder.AssetPath + "/Library");

                                //Generate namespace based on siteroot and project
                                if (aProjectFolder.Parent.AssetPath.ToString().Equals(aSiteRootFolder.AssetPath.ToString()))
                                    szNamespace = IhSiteBuilderHelper.ReformatName(aSiteRootFolder.Label) + "." + IhSiteBuilderHelper.ReformatName(aProjectFolder.Label) + ".Library";
                                else
                                    szNamespace = IhSiteBuilderHelper.ReformatName(aProjectFolder.Label) + ".Library";

                                IhSiteBuilderExport.ExportSiteRoot(
                                    asset, aSiteRootFolder,
                                    project: aProjectFolder,
                                    template: aTemplateFolder,
                                    model: aModelFolder,
                                    library: aLibraryFolder,
                                    clientName: context.ClientName,
                                    navWrapPath: szNavPath,
                                    customNamespace: szNamespace,
                                    includeContent: bContent,
                                    includeBinary: bBinary,
                                    includeWrapper: bWrapper,
                                    dicLog: dicLog
                                    );
                            }
                            else
                            {
                                siteLog.Add("SiteRoot or project not loaded");
                            }
                            break;
                    }
                }
                catch (Exception e)
                {
                    IhSiteBuilderHelper.SaveLog(dicLog, "Failed: " + e.Message);
                }

                //Create Log
                int nTempId = Asset.LoadDirect("/System/Templates/Basis/ComponentsCS/output.aspx").TemplateId;
                Asset asModel = Asset.LoadDirect("/System/Models/Basis/Asset/Asset");
                Asset aLog = Asset.LoadDirect(asset.Parent.AssetPath + "/" + asset.Label + " - Export Log");

                if (aLog.IsLoaded)
                {
                    aLog.DeleteContentFields(aLog.GetContent().Keys.ToList());
                    aLog.SaveContent(dicLog);
                }
                else
                {
                    Asset.CreateNewAsset(asset.Label + " - Export Log", asset.Parent, asModel, dicLog).SetTemplate(nTempId);
                }

                asset.SaveContentField("export_site_option", "no");
            }
            asset.DeleteContentField("log_message");
        }