Ejemplo n.º 1
0
        private static void CreateTMFRelationship(Asset masterLocale, Asset childLocale, IhSiteBuilderLog siteLog = null)
        {
            string szSiteName = IhSiteBuilderTMFHelper.GetSitePath(masterLocale).Parent.Label;

            Asset aSourceLanguageContent = masterLocale;
            Asset aDestinationLanguageContent = childLocale;

            Asset aFolderSource = Asset.Load(aSourceLanguageContent["folder_root"]);
            Asset aFolderDest = Asset.Load(aDestinationLanguageContent["folder_root"]);
            Asset aTemplConfig = Asset.Load(IhSiteBuilderTMFHelper.GetSitePath(masterLocale) + "/TMF Config/Templates configuration");

            FilterParams fpFilter = new FilterParams();
            fpFilter.Add(Comparison.Equals, AssetType.File);
            fpFilter.SortOrder = SortOrder.OrderBy(AssetPropertyNames.Label);
            fpFilter.Add(AssetPropertyNames.Label, Comparison.NotInSet, Util.MakeList(".jpeg", ".jpg", ".gif", ".png", ".js", ".css", ".pdf", ".doc", ".docx"));

            List<Asset> laPackageList = Asset.Load(aFolderSource.Id).GetFilterList(fpFilter);
            foreach (Asset aPackage in laPackageList)
            {
                int nSourceId = aPackage.Id;
                Asset aContentSource = Asset.Load(nSourceId);

                if (!string.Equals(aContentSource.TemplateId.ToString(), "0") && string.IsNullOrWhiteSpace(aTemplConfig["tmftemplate_" + aContentSource.TemplateId.ToString()]))
                {
                    string szSourcePath = aContentSource.AssetPath.ToString();
                    string szDestinationPath = szSourcePath.Replace(aSourceLanguageContent["folder_root"], aDestinationLanguageContent["folder_root"]);
                    int nDestinationId = Asset.Load(szDestinationPath).Id;

                    int nRelationshipId = 0;
                    string szDestStatus = "";
                    if (nDestinationId <= 0)
                    {
                        szDestStatus = "DESTINATION LABEL NOT FOUND, ";
                        List<Asset> laConfigList = IhSiteBuilderTMFHelper.GetRelList(nSourceId, "source", szSiteName);
                        nDestinationId = 0;
                        foreach (Asset aConfigList in laConfigList)
                        {
                            if (Asset.Load(aConfigList["destination_id"]).AssetPath.ToString().ToLower().Contains(aDestinationLanguageContent["folder_root"].ToLower()))
                            {
                                nDestinationId = Convert.ToInt32(aConfigList["destination_id"]);
                                nRelationshipId = aConfigList.Id;
                                break;
                            }
                        }
                    }
                    else
                        nRelationshipId = Asset.Load(IhSiteBuilderTMFHelper.GetSitePath(masterLocale) + "/Relationship config/" + nSourceId.ToString() + "-" + nDestinationId.ToString()).Id;

                    string szStatus = "";
                    Asset aContentDest = Asset.Load(nDestinationId);
                    if (nRelationshipId <= 0)
                    {
                        if (aContentSource.Id > 0 && aContentDest.Id > 0)
                        {
                            siteLog.Add("aContentSource: " + aContentSource.AssetPath);
                            siteLog.Add("aContentDest: " + aContentDest.AssetPath);
                            siteLog.Add("Master Locale: " + IhSiteBuilderTMFHelper.GetSitePath(masterLocale).AssetPath);
                            IhSiteBuilderTMFHelper.AutoLinkLocales(aContentSource, aContentDest, IhSiteBuilderTMFHelper.GetSitePath(masterLocale).AssetPath.ToString());
                            IhSiteBuilderTMFHelper.FixRelativeLinks(aContentDest, masterLocale, childLocale, IhSiteBuilderTMFHelper.GetSitePath(masterLocale).AssetPath.ToString());

                            szStatus = "RELATIONSHIP CREATED, SourceID= " + nSourceId.ToString() + " DestID= " + nDestinationId.ToString();
                        }
                        else
                            szStatus = "SKIPPED, SourceID= " + nSourceId.ToString() + " DestID= " + nDestinationId.ToString();
                    }
                    else
                        szStatus = "RELATIONSHIP ALREADY EXISTS, SourceID= " + nSourceId.ToString() + " DestID= " + nDestinationId.ToString() + " Relationship ID= " + nRelationshipId.ToString();

                    szStatus = szDestStatus + szStatus;
                    siteLog.Add(szStatus);
                }
            }
        }
Ejemplo n.º 2
0
        public static void RenderOutput(Asset asset, OutputContext context, string xmFilePath, bool allowOverwrite)
        {
            IhSiteBuilderLog siteLog = new IhSiteBuilderLog();
            try
            {
                switch (asset.Raw["sitebuilder_type"])
                {
                    case "site_build":
                        //--------------------------------------------
                        // Build Site
                        //--------------------------------------------
                        siteLog.Add("Building new site");

                        string szFileSource = string.Empty;
                        switch (asset.Raw["technology_list_option"])
                        {
                            case "public":
                                szFileSource = GetPageSource(asset.Raw["cp_language_type"]);
                                break;
                            case "training":
                                szFileSource = GetPageSource(asset.Raw["training_language_type"]);
                                break;
                            case "private":
                                szFileSource = GetPageSource(asset.Raw["private_language_type"]);
                                break;
                            case "local":
                                siteLog.Add("Building local site from file: " + xmFilePath);
                                Asset aLocalFile = Asset.Load(xmFilePath);
                                siteLog.Add("Have local file: " + aLocalFile.IsLoaded.ToString());
                                if (aLocalFile.IsLoaded)
                                    szFileSource = CTLHelper.GetBinaryAsText(aLocalFile);
                                else
                                    siteLog.Add("Error - Unable to load file");
                                break;
                        }

                        if (!string.IsNullOrWhiteSpace(szFileSource))
                        {
                            string szCollectionPath, szSiteRootName, szProjectName = string.Empty;

                            if (asset["collection_folder_type"].Equals("new"))
                                szCollectionPath = "/" + asset["collection_new"];
                            else
                                szCollectionPath = Asset.Load(asset["collection_select"]).AssetPath.ToString();

                            szSiteRootName = asset.Raw["site_root_name"];

                            szProjectName = asset.Raw["project_name"];

                            bool bChildProject = false;
                            if (asset["project_level"].Equals("nested"))
                                bChildProject = true;

                            IhSiteBuilderImport.ReplicateSite(asset, szFileSource, szCollectionPath, szSiteRootName, szProjectName, workflowName: asset.Raw["workflow_name"], clientName: context.ClientName, childProject: bChildProject, siteLog: siteLog, allowOverwrite: allowOverwrite);

                            string szRootName = string.Empty;

                            siteLog.Add("Builder finished");
                        }
                        break;
                    case "site_extension":
                        //--------------------------------------------
                        // Add Extension
                        //--------------------------------------------
                        switch (asset.Raw["extension_types"])
                        {
                            case "ext_tmf":
                                //Add TMF
                                CreateTMF(asset, siteLog);
                            break;
                            case "ext_blog":
                            break;
                        }

                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                siteLog.Add(e.Message);
            }

            //Create Log
            CreateLogFile(asset, siteLog);
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
0
        private static void CreateTMF(Asset asset, IhSiteBuilderLog siteLog = null)
        {
            //First loop only creates the sites
            Asset aMaster = Asset.Load(asset.Raw["tmf_master_main_site"]);
            if (aMaster.IsLoaded)
            {
                siteLog.Add("Cloning Master Site");
                //Create Locales
                //foreach (PanelEntry peTMF in asset.GetPanels("tmf_locale_panel"))
                //{
                //    if (!string.IsNullOrWhiteSpace(peTMF.Raw["locale_name"]))
                //    {
                //        Asset aLocale = Asset.Load(aMaster.Parent.AssetPath + "/" + peTMF.Raw["locale_name"]);
                //        if (!aLocale.IsLoaded)
                //            Asset.CopyAsset(peTMF.Raw["locale_name"], aMaster.Parent, aMaster);
                //    }
                //}

                //Second loop will create TMF and their relationships
                //response = Util.GetHttp("http://stagepsdev.cp-access.com/site-builder-tool/site-tmf.xml");

                Asset aCollectionFolder = Asset.Load(asset.Raw["tmf_project_folder"]);
                if (!aCollectionFolder.IsLoaded)
                    aCollectionFolder = aMaster.Parent;

                if (aCollectionFolder.IsLoaded)
                {
                    siteLog.Add("Creating Locale Folders");
                    //Create locale folders
                    List<Asset> laLocales = new List<Asset>();
                    Asset aMasterLocale = Asset.Load("");

                    foreach (PanelEntry peLocale in asset.GetPanels("tmf_locale_panel"))
                    {
                        Asset aCountryFile = Asset.Load("");
                        Asset aLangFile = Asset.Load("");

                        Asset aLocaleFolder = Asset.Load(aMaster.Parent.AssetPath + "/" + peLocale.Raw["locale_name"]);

                        if (!string.IsNullOrWhiteSpace(peLocale.Raw["locale_name"]))
                        {
                            if (!aLocaleFolder.IsLoaded)
                                aLocaleFolder = Asset.CopyAsset(peLocale.Raw["locale_name"], aMaster.Parent, aMaster);
                        }

                        //Create Country
                        string szCountry = string.Empty;
                        if (peLocale.Raw["tmf_country_option"].Equals("dropdown"))
                        {
                            szCountry = peLocale.Raw["tmf_country_select"];
                        }
                        else
                        {
                            szCountry = peLocale.Raw["new_country_name"];
                        }

                        if (!string.IsNullOrWhiteSpace(szCountry))
                        {
                            aCountryFile = CreateCountry(szCountry, aCollectionFolder);
                        }

                        //Create Language
                        string szLanguage = string.Empty;
                        if (peLocale.Raw["tmf_language_option"].Equals("dropdown"))
                        {
                            szLanguage = peLocale.Raw["tmf_lang_select"];
                        }
                        else
                        {
                            szLanguage = peLocale.Raw["new_language_name"];
                        }

                        if (!string.IsNullOrWhiteSpace(szLanguage))
                        {
                            aLangFile = CreateLanguage(szLanguage, aCollectionFolder);
                        }

                        //Create Locale
                        if (!string.IsNullOrWhiteSpace(peLocale.Raw["locale_name"]))
                        {

                            laLocales.Add(CreateLocale(peLocale.Raw["locale_name"], aLocaleFolder, aCountryFile, aLangFile, aCollectionFolder, false));
                        }
                    }

                    //Create Master
                    if (aMaster.IsLoaded)
                    {
                        Asset aLocaleFolder = aMaster;
                        Asset aCountryFile = Asset.Load("");
                        Asset aLangFile = Asset.Load("");

                        string szLocaleName = asset.Raw["tmf_master_main_site_rename"];
                        if (!string.IsNullOrWhiteSpace(szLocaleName))
                            aMaster.Rename(szLocaleName);
                        else
                            szLocaleName = aMaster.Label;

                        //Create Country
                        string szCountry = string.Empty;
                        if (asset.Raw["tmf_master_country_option"].Equals("dropdown"))
                        {
                            szCountry = asset.Raw["tmf_master_country_select"];
                        }
                        else
                        {
                            szCountry = asset.Raw["new_master_country_name"];
                        }

                        if (!string.IsNullOrWhiteSpace(szCountry))
                        {
                            aCountryFile = CreateCountry(szCountry, aCollectionFolder);
                        }

                        //Create Language
                        string szLanguage = string.Empty;
                        if (asset.Raw["tmf_master_language_option"].Equals("dropdown"))
                        {
                            szLanguage = asset.Raw["tmf_master_lang_select"];
                        }
                        else
                        {
                            szLanguage = asset.Raw["new_master_language_name"];
                        }

                        if (!string.IsNullOrWhiteSpace(szLanguage))
                        {
                            aLangFile = CreateLanguage(szLanguage, aCollectionFolder);
                        }

                        //Create Locale
                        if (!string.IsNullOrWhiteSpace(szLocaleName))
                        {
                            aMasterLocale = CreateLocale(szLocaleName, aLocaleFolder, aCountryFile, aLangFile, aCollectionFolder, true);
                        }

                        //Create Relationships Config Folder
                        IhSiteBuilderHelper.CreateFolder(aCollectionFolder.AssetPath + "/_TMF/Relationships Config", IhSiteBuilderHelper.BaseFolderModel);

                        //Create Auto Link Locales File
                        CreateTMFConfig(aCollectionFolder, "Auto Link Locales", "/System/Translation Model Framework/_Templates/Auto Link Locales/");

                        //Create Templates configuration
                        CreateTMFConfig(aCollectionFolder, "Templates configuration", "/System/Translation Model Framework/_Templates/Templates Config/");

                        //Autolink TMF
                        foreach (Asset aLocale in laLocales)
                        {
                            if (aLocale.IsLoaded)
                            {
                                CreateTMFRelationship(aMasterLocale, aLocale, siteLog);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static void CreateLogFile(Asset asset, IhSiteBuilderLog siteLog)
        {
            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.ToString() + "/" + asset.Label + "_log");
            if (!aLog.IsLoaded)
            {
                Asset.CreateNewAsset(asset.Label + "_log", asset.Parent, asModel, siteLog.ReturnLog()).SetTemplate(nTempId);
            }
            else
            {
                aLog.DeleteContentFields(aLog.GetContent().Keys.ToList());
                aLog.SaveContent(siteLog.ReturnLog());
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates the site structure based on the options provided
        /// </summary>
        public static void ReplicateSite(
			Asset asset,
			string siteXML,
			string collectionPath,
			string siteName = "",
			string projectName = "",
			string workflowName = "",
			string clientName = "",
			bool childProject = false,
			bool mobileOutput = false,
			bool createTemplate = true,
			bool createModel = true,
			bool createSite = true,
			bool createBinary = true,
			bool createWrapper = true,
			bool renewInternalLinks = true,
			bool allowOverwrite = false,
			IhSiteBuilderLog siteLog = null
			)
        {
            siteLog.Add("Replicate site started");

            // Gather site creation/update parameters
            IhSiteBuilderInfo siteInfoNew = new IhSiteBuilderInfo();

            string[] arrCollectionPath = collectionPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
            siteInfoNew.CollectionName = arrCollectionPath.Last();

            if (arrCollectionPath.Count() > 1)
            {
                siteInfoNew.CollectionPath = collectionPath;
            }
            else
            {
                siteInfoNew.CollectionPath = "/" + siteInfoNew.CollectionName;
            }

            siteLog.Add("New info collection name: " + siteInfoNew.CollectionName);
            siteLog.Add("New info collection path: " + siteInfoNew.CollectionPath);

            siteInfoNew.SiteRootName = siteName;
            siteInfoNew.ClientName = clientName;
            siteInfoNew.SiteRootParent = siteInfoNew.CollectionPath;
            siteInfoNew.SiteRootPath = siteInfoNew.CollectionPath + "/" + siteName;

            if (!string.IsNullOrWhiteSpace(projectName))
            {
                siteInfoNew.ProjectName = projectName;

                if (childProject)
                {
                    siteInfoNew.ProjectParent = siteInfoNew.SiteRootPath;
                    siteInfoNew.ProjectPath = siteInfoNew.SiteRootPath + "/" + projectName;
                    siteInfoNew.ProjectNested = true;
                }
                else
                {
                    siteInfoNew.ProjectParent = siteInfoNew.CollectionPath;
                    siteInfoNew.ProjectPath = siteInfoNew.CollectionPath + "/" + projectName;
                    siteInfoNew.ProjectNested = false;
                }
            }
            else
            {
                siteInfoNew.TemplatePath = string.Format("/System/Templates/{0}/{1}", siteInfoNew.CollectionName, siteInfoNew.SiteRootName);
                siteInfoNew.ModelPath = string.Format("/System/Models/{0}/{1}", siteInfoNew.CollectionName, siteInfoNew.SiteRootName);
            }
            siteInfoNew.WorkflowName = workflowName;

            // Begin creation/update of site
            IhSiteBuilderModel siteModels = new IhSiteBuilderModel();

            if (!string.IsNullOrWhiteSpace(siteXML))
            {
                siteLog.Add("Site XML found and running");
                IhSiteBuilderImportSiteRoot siteImport = new IhSiteBuilderImportSiteRoot(siteXML, siteInfoNew, siteModels, allowOverwrite, siteLog);

                siteImport.CreateSiteRoot();

                if (!string.IsNullOrWhiteSpace(projectName))
                    siteImport.CreateProject();

                if (createTemplate)
                {
                    siteImport.CreateTemplate();
                }

                if (createModel)
                {
                    siteImport.CreateModel();
                }

                if (createSite)
                {
                    siteImport.CreateSite();
                }

                if (createBinary)
                {
                    siteImport.CreateBinaryFile(siteXML);
                }

                if (createWrapper)
                {
                    siteImport.CreateBinaryWrapper(siteXML);
                }

                if (!string.IsNullOrWhiteSpace(projectName))
                {
                    siteImport.CreateLibrary();

                    #region *** IH Custom Code ***
                    siteImport.CreateLibraryReferences();
                    #endregion
                }

                if (renewInternalLinks)
                {
                    siteImport.RenewAllContentAsset();
                }

                siteLog.Add("Import DONE");

                //Util.Email("Import Script Finished", DateTime.Now.ToString(), "*****@*****.**");
            }
            else
                siteLog.Add("Site XML Empty or not loaded correctly");
        }
Ejemplo n.º 7
0
        public IhSiteBuilderImportSiteRoot(string siteXML, IhSiteBuilderInfo newSiteInfo, IhSiteBuilderModel siteModels = null, bool allowOverwrite = false, IhSiteBuilderLog siteLog = null)
        {
            this.siteLog = siteLog;
            siteLog.Add("SiteBuilder Import class inizialized");

            this.szSiteXML = siteXML;
            this.allowOverwrite = allowOverwrite;
            this.siteInfoNew = newSiteInfo;

            if (siteModels.Equals(null))
                this.siteModels = new IhSiteBuilderModel();
            else
                this.siteModels = siteModels;

            if (!string.IsNullOrWhiteSpace(siteInfoNew.ProjectName))
            {
                if (siteInfoNew.ProjectNested)
                {
                    siteInfoNew.Namespace = IhSiteBuilderHelper.ReformatName(siteInfoNew.SiteRootName) + "." + IhSiteBuilderHelper.ReformatName(siteInfoNew.ProjectName) + ".Library";
                }
                else
                {
                    siteInfoNew.Namespace = IhSiteBuilderHelper.ReformatName(siteInfoNew.ProjectName) + ".Library";
                }
            }
            else
            {
                siteInfoNew.Namespace = "CrownPeak.CMSAPI.CustomLibrary";
            }
            siteLog.Add("New Namespace: " + siteInfoNew.Namespace);

            PrepareSiteNames();
        }
Ejemplo n.º 8
0
 private static List<Asset> ExcludeFolderList(List<Asset> assetList, List<string> folderList, IhSiteBuilderLog siteLog = null)
 {
     List<Asset> laFiltered = new List<Asset>();
     foreach (Asset aAsset in assetList)
     {
         foreach (string folder in folderList)
         {
             if (!aAsset.AssetPath.ToString().Contains(folder))
                 laFiltered.Add(aAsset);
         }
     }
     return laFiltered;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Filters everything even subfolders from the selected folder. Key = AssetID, Value = Asset.
        /// <para>If AssetType.Unspecified is selected, it will return all folders and files.</para>
        /// </summary>
        public static List<Asset> GetFilterList(Asset _assetFolder, AssetType _assetType = AssetType.Unspecified, string _path = "", bool excludeProjectTypes = false, List<string> excludeFolders = null, IhSiteBuilderLog siteLog = null)
        {
            FilterParams fpFilter = new FilterParams();
            fpFilter.ExcludeProjectTypes = excludeProjectTypes;

            if (!_assetType.Equals(AssetType.Unspecified))
                fpFilter.Add(Comparison.Equals, _assetType);

            Dictionary<string, Asset> dtAssets = new Dictionary<string, Asset>();
            if (!string.IsNullOrWhiteSpace(_path))
            {
                if (Asset.Load(_path).IsLoaded)
                    _assetFolder = Asset.Load(_path);
            }

            List<Asset> laAssets = _assetFolder.GetFilterList(fpFilter);

            if (excludeFolders != null)
            {
                laAssets = ExcludeFolderList(laAssets, excludeFolders);
            }
            foreach (Asset asAsset in laAssets)
            {
                if (!dtAssets.Keys.Contains(asAsset.BranchId.ToString()))
                {
                    if (asAsset.Type.Equals(AssetType.Folder))
                    {
                        dtAssets.Add(asAsset.BranchId.ToString(), asAsset);
                    }
                    else if (asAsset.Type.Equals(AssetType.File))
                    {
                        if (asAsset.WorkflowStatus.Name.Equals("Live") || asAsset.WorkflowStatus.Name.Equals("Stage") || asAsset.WorkflowStatus.Name.Equals("Draft") || asAsset.WorkflowStatus.Name.Equals(""))
                        {
                            dtAssets.Add(asAsset.BranchId.ToString(), asAsset);
                        }
                    }
                }
                else
                {
                    if (asAsset.WorkflowStatus.Name.Equals("Live"))
                    {
                        dtAssets[asAsset.BranchId.ToString()] = asAsset;
                    }
                    else if (asAsset.WorkflowStatus.Name.Equals("Stage"))
                    {
                        if (!dtAssets[asAsset.BranchId.ToString()].WorkflowStatus.Name.Equals("Live") && !dtAssets[asAsset.BranchId.ToString()].WorkflowStatus.Name.Equals("Stage"))
                        {
                            dtAssets[asAsset.BranchId.ToString()] = asAsset;
                        }
                    }
                    else if (asAsset.WorkflowStatus.Name.Equals("Draft"))
                    {
                        if (!dtAssets[asAsset.BranchId.ToString()].WorkflowStatus.Name.Equals("Live") && !dtAssets[asAsset.BranchId.ToString()].WorkflowStatus.Name.Equals("Stage") && !dtAssets[asAsset.BranchId.ToString()].WorkflowStatus.Name.Equals("Draft"))
                        {
                            dtAssets[asAsset.BranchId.ToString()] = asAsset;
                        }
                    }
                }
            }
            return dtAssets.Values.ToList<Asset>();
        }