Esempio n. 1
0
        /// <summary> Constructor for a new instance of the Static_Browse_Info_AggregationViewer class </summary>
        /// <param name="Browse_Object"> Browse or information object to be displayed </param>
        /// <param name="Static_Web_Content"> HTML content-based browse, info, or imple CMS-style web content objects.  These are objects which are read from a static HTML file and much of the head information must be maintained </param>
        /// <param name="Current_Collection"> Current collection being displayed</param>
        /// <param name="Current_Mode"> Mode / navigation information for the current request</param>
        /// <param name="Current_User"> Current user/session information </param>
        public Static_Browse_Info_AggregationViewer(Item_Aggregation_Child_Page Browse_Object, HTML_Based_Content Static_Web_Content, Item_Aggregation Current_Collection, SobekCM_Navigation_Object Current_Mode, User_Object Current_User) : base(Current_Collection, Current_Mode)
        {
            browseObject     = Browse_Object;
            staticWebContent = Static_Web_Content;
            currentUser      = Current_User;

            bool isAdmin = (currentUser != null) && (currentUser.Is_Aggregation_Admin(currentCollection.Code));

            if ((currentMode.Aggregation_Type == Aggregation_Type_Enum.Child_Page_Edit) && (!isAdmin))
            {
                currentMode.Aggregation_Type = Aggregation_Type_Enum.Browse_Info;
            }

            NameValueCollection form = HttpContext.Current.Request.Form;

            if ((currentMode.Aggregation_Type == Aggregation_Type_Enum.Child_Page_Edit) && (form["sbkSbia_ChildTextEdit"] != null) && (currentUser != null))
            {
                string aggregation_folder = SobekCM_Library_Settings.Base_Design_Location + "aggregations\\" + currentCollection.Code + "\\";
                string file = aggregation_folder + browseObject.Get_Static_HTML_Source(currentMode.Language);

                // Get the header information as well
                if (!String.IsNullOrEmpty(form["admin_childpage_title"]))
                {
                    staticWebContent.Title = form["admin_childpage_title"];
                }
                if (form["admin_childpage_author"] != null)
                {
                    staticWebContent.Author = form["admin_childpage_author"];
                }
                if (form["admin_childpage_date"] != null)
                {
                    staticWebContent.Date = form["admin_childpage_date"];
                }
                if (form["admin_childpage_description"] != null)
                {
                    staticWebContent.Description = form["admin_childpage_description"];
                }
                if (form["admin_childpage_keywords"] != null)
                {
                    staticWebContent.Keywords = form["admin_childpage_keywords"];
                }
                if (form["admin_childpage_extrahead"] != null)
                {
                    staticWebContent.Extra_Head_Info = form["admin_childpage_extrahead"];
                }


                // Make a backup from today, if none made yet
                if (File.Exists(file))
                {
                    DateTime lastWrite = (new FileInfo(file)).LastWriteTime;
                    string   new_file  = file.ToLower().Replace(".txt", "").Replace(".html", "").Replace(".htm", "") + lastWrite.Year + lastWrite.Month.ToString().PadLeft(2, '0') + lastWrite.Day.ToString().PadLeft(2, '0') + ".bak";
                    if (File.Exists(new_file))
                    {
                        File.Delete(new_file);
                    }
                    File.Move(file, new_file);
                }


                // Assign the new text
                Static_Web_Content.Static_Text = form["sbkSbia_ChildTextEdit"];
                Static_Web_Content.Date        = DateTime.Now.ToLongDateString();
                Static_Web_Content.Save_To_File(file);

                // Also save this change
                SobekCM_Database.Save_Item_Aggregation_Milestone(currentCollection.Code, "Child page '" + browseObject.Code + "' edited (" + Web_Language_Enum_Converter.Enum_To_Name(currentMode.Language) + ")", currentUser.Full_Name);

                // Forward along
                currentMode.Aggregation_Type = Aggregation_Type_Enum.Browse_Info;
                if (Browse_Object.Browse_Type == Item_Aggregation_Child_Page.Visibility_Type.METADATA_BROWSE_BY)
                {
                    currentMode.Aggregation_Type = Aggregation_Type_Enum.Browse_By;
                }

                string redirect_url = currentMode.Redirect_URL();
                if (redirect_url.IndexOf("?") > 0)
                {
                    redirect_url = redirect_url + "&refresh=always";
                }
                else
                {
                    redirect_url = redirect_url + "?refresh=always";
                }
                currentMode.Request_Completed = true;
                HttpContext.Current.Response.Redirect(redirect_url, false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
        }
        /// <summary> Builds a language-specific <see cref="Web_Skin_Object"/> when needed by a user's request </summary>
        /// <param name="CompleteSkin"> Complete web skin object </param>
        /// <param name="Language_Code"> Code for the language, which determines which HTML to use </param>
        /// <param name="Tracer"></param>
        /// <returns> Completely built HTML interface object </returns>
        /// <remarks> The datarow for this method is retrieved from the database by calling the <see cref="Database.Engine_Database.Get_All_Web_Skins"/> method during
        /// application startup and is then stored in the <see cref="Web_Skin_Collection"/> class until needed. </remarks>
        public static Web_Skin_Object Build_Skin(Complete_Web_Skin_Object CompleteSkin, string Language_Code, Custom_Tracer Tracer)
        {
            // Look for the language
            Web_Language_Enum language          = Web_Language_Enum_Converter.Code_To_Enum(Language_Code);
            Web_Language_Enum original_language = language;

            if (!CompleteSkin.SourceFiles.ContainsKey(language))
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Language requested ( " + Web_Language_Enum_Converter.Enum_To_Name(language) + " ) not in language list");
                }

                language = Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language;
                if ((original_language == language) || (!CompleteSkin.SourceFiles.ContainsKey(language)))
                {
                    if ((Tracer != null) && (original_language != language))
                    {
                        Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Default UI language ( " + Web_Language_Enum_Converter.Enum_To_Name(language) + " ) not in language list");
                    }

                    language = Web_Language_Enum.DEFAULT;
                    if (!CompleteSkin.SourceFiles.ContainsKey(language))
                    {
                        if (Tracer != null)
                        {
                            Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "DEFAULT language not in language list");
                        }

                        language = Web_Language_Enum.English;

                        if (!CompleteSkin.SourceFiles.ContainsKey(language))
                        {
                            if (Tracer != null)
                            {
                                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "English language also not in language list");
                            }

                            if (CompleteSkin.SourceFiles.Count > 0)
                            {
                                language = CompleteSkin.SourceFiles.Keys.First();
                            }
                            else
                            {
                                if (Tracer != null)
                                {
                                    Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Apparently there are NO source files.. returning NULL");
                                }
                                language = Web_Language_Enum.UNDEFINED;
                            }
                        }
                    }
                }
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Will build language-specific web skin for '" + Web_Language_Enum_Converter.Enum_To_Name(language) + "'");
            }

            // Now, look in the cache for this
            if (language != Web_Language_Enum.UNDEFINED)
            {
                Web_Skin_Object cacheObject = CachedDataManager.WebSkins.Retrieve_Skin(CompleteSkin.Skin_Code, Web_Language_Enum_Converter.Enum_To_Code(language), null);
                if (cacheObject != null)
                {
                    if (Tracer != null)
                    {
                        Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Web skin found in the memory cache");
                    }

                    return(cacheObject);
                }
            }

            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Web skin not found in the memory cache, so building it now");
            }

            // Build this then
            Web_Skin_Object returnValue = new Web_Skin_Object(CompleteSkin.Skin_Code, CompleteSkin.Base_Skin_Code);

            if (!String.IsNullOrEmpty(CompleteSkin.CSS_Style))
            {
                returnValue.CSS_Style = "design/skins/" + CompleteSkin.Skin_Code + "/" + CompleteSkin.CSS_Style;
            }
            if (!String.IsNullOrEmpty(CompleteSkin.Javascript_File))
            {
                returnValue.Javascript = "design/skins/" + CompleteSkin.Skin_Code + "/" + CompleteSkin.Javascript_File;
            }

            // Set the language code
            if (language == Web_Language_Enum.DEFAULT)
            {
                returnValue.Language_Code = Web_Language_Enum_Converter.Enum_To_Code(Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language);
            }
            else if (language == Web_Language_Enum.UNDEFINED)
            {
                returnValue.Language_Code = Web_Language_Enum_Converter.Enum_To_Code(language);
            }

            // Set some optional (nullable) flags
            if (CompleteSkin.Override_Banner)
            {
                returnValue.Override_Banner = true;
            }
            if (CompleteSkin.Suppress_Top_Navigation)
            {
                returnValue.Suppress_Top_Navigation = true;
            }

            // If no suitable language was found, probably an error (no source files at all)
            if (language == Web_Language_Enum.UNDEFINED)
            {
                if (!String.IsNullOrEmpty(CompleteSkin.Exception))
                {
                    returnValue.Exception = CompleteSkin.Exception;
                }
                else
                {
                    returnValue.Exception = "No valid source files found";
                }

                // Also set the headers and footers to the exception
                returnValue.Header_HTML      = returnValue.Exception;
                returnValue.Footer_HTML      = returnValue.Exception;
                returnValue.Header_Item_HTML = returnValue.Exception;
                returnValue.Footer_Item_HTML = returnValue.Exception;

                return(returnValue);
            }

            // Get the source file
            Complete_Web_Skin_Source_Files sourceFiles = CompleteSkin.SourceFiles[language];

            // Build the banner
            if ((returnValue.Override_Banner.HasValue) && (returnValue.Override_Banner.Value))
            {
                if (Tracer != null)
                {
                    Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Skin overrides the banner, so build the banner HTML");
                }

                // Find the LANGUAGE-SPECIFIC high-bandwidth banner image
                if (!String.IsNullOrEmpty(sourceFiles.Banner))
                {
                    if (!String.IsNullOrEmpty(CompleteSkin.Banner_Link))
                    {
                        returnValue.Banner_HTML = "<a href=\"" + CompleteSkin.Banner_Link + "\"><img border=\"0\" src=\"<%BASEURL%>skins/" + CompleteSkin.Skin_Code + "/" + sourceFiles.Banner + "\" alt=\"MISSING BANNER\" /></a>";
                    }
                    else
                    {
                        returnValue.Banner_HTML = "<img border=\"0\" src=\"<%BASEURL%>skins/" + CompleteSkin.Skin_Code + "/" + sourceFiles.Banner + "\" alt=\"MISSING BANNER\" />";
                    }
                }
            }

            // Now, set the header and footer html
            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Determine the header footer source HTML files");
            }
            string this_header      = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Header_Source_File);
            string this_footer      = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Footer_Source_File);
            string this_item_header = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Header_Item_Source_File);
            string this_item_footer = Path.Combine(Engine_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location, "skins", CompleteSkin.Skin_Code, sourceFiles.Footer_Item_Source_File);

            // If the item specific stuff doesn't exist, use the regular
            if (!File.Exists(this_item_header))
            {
                this_item_header = this_header;
            }
            if (!File.Exists(this_item_footer))
            {
                this_item_footer = this_footer;
            }

            // Now, assign all of these
            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Get the HTML source for all the headers and footers");
            }
            returnValue.Set_Header_Footer_Source(this_header, this_footer, this_item_header, this_item_footer);

            if (Tracer != null)
            {
                Tracer.Add_Trace("Web_Skin_Utilities.Build_Skin", "Returning the fully built web skin");
            }
            return(returnValue);
        }
Esempio n. 3
0
        /// <summary> Gets the language-specific web skin, by web skin code and language code </summary>
        /// <param name="Response"></param>
        /// <param name="UrlSegments"></param>
        /// <param name="QueryString"></param>
        /// <param name="Protocol"></param>
        /// <param name="IsDebug"></param>
        public void GetWebSkin(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug)
        {
            if (UrlSegments.Count > 1)
            {
                Custom_Tracer   tracer = new Custom_Tracer();
                Web_Skin_Object returnValue;
                try
                {
                    // Get the code and language from the URL
                    string skinCode = UrlSegments[0];
                    tracer.Add_Trace("WebSkinServices.GetWebSkin", "Getting skin for '" + skinCode + "'");

                    string            language     = UrlSegments[1];
                    Web_Language_Enum languageEnum = Web_Language_Enum_Converter.Code_To_Enum(language);
                    tracer.Add_Trace("WebSkinServices.GetWebSkin", "Getting skin for language '" + Web_Language_Enum_Converter.Enum_To_Name(languageEnum) + "'");

                    returnValue = get_web_skin(skinCode, languageEnum, Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language, tracer);

                    // If this was debug mode, then just write the tracer
                    if (IsDebug)
                    {
                        Response.ContentType = "text/plain";
                        Response.Output.WriteLine("DEBUG MODE DETECTED");
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(tracer.Text_Trace);

                        return;
                    }
                }
                catch (Exception ee)
                {
                    if (IsDebug)
                    {
                        Response.ContentType = "text/plain";
                        Response.Output.WriteLine("EXCEPTION CAUGHT!");
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(ee.Message);
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(ee.StackTrace);
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(tracer.Text_Trace);

                        return;
                    }

                    Response.ContentType = "text/plain";
                    Response.Output.WriteLine("Error completing request");
                    Response.StatusCode = 500;
                    return;
                }

                // Get the JSON-P callback function
                string json_callback = "parseWebSkin";
                if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"])))
                {
                    json_callback = QueryString["callback"];
                }

                // Use the base class to serialize the object according to request protocol
                Serialize(returnValue, Response, Protocol, json_callback);
            }
        }
        /// <summary> Compares the two aggregation objects and returns a list of differences for saving as milestones
        /// during aggregation curatorial or administrative work </summary>
        /// <param name="Base"> Base item aggregation </param>
        /// <param name="Compared"> New item aggregation object to compare to the base </param>
        /// <returns> List of changes between the two aggregation objects </returns>
        public static List <string> Compare(Complete_Item_Aggregation Base, Complete_Item_Aggregation Compared)
        {
            // TODO: Facet comparison below needs to look up the name of the facet,
            // TODO: rather than just showing the primary key to the facet

            List <string> changes = new List <string>();

            // code
            if (!Base.Code.Equals(Compared.Code))
            {
                changes.Add("Changed code ( '" + Base.Code + "' --> '" + Compared.Code + "' )");
            }

            // parents
            List <string> base_parents     = new List <string>();
            List <string> compared_parents = new List <string>();

            if (Base.Parents != null)
            {
                foreach (Item_Aggregation_Related_Aggregations parentAggr in Base.Parents)
                {
                    // Look in compared for a match
                    if ((Compared.Parents == null) || (Compared.Parents.All(CompareAggr => String.Compare(parentAggr.Code, CompareAggr.Code, StringComparison.InvariantCultureIgnoreCase) != 0)))
                    {
                        base_parents.Add(parentAggr.Code);
                    }
                }
            }
            if (Compared.Parents != null)
            {
                foreach (Item_Aggregation_Related_Aggregations parentAggr in Compared.Parents)
                {
                    // Look in base for a match
                    if ((Base.Parents == null) || (Base.Parents.All(CompareAggr => String.Compare(parentAggr.Code, CompareAggr.Code, StringComparison.InvariantCultureIgnoreCase) != 0)))
                    {
                        compared_parents.Add(parentAggr.Code);
                    }
                }
            }
            if (base_parents.Count > 0)
            {
                if (base_parents.Count == 1)
                {
                    changes.Add("Removed parent " + base_parents[0]);
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Removed parents " + base_parents[0]);
                    for (int i = 1; i < base_parents.Count; i++)
                    {
                        builder.Append(", " + base_parents[i]);
                    }
                    changes.Add(builder.ToString());
                }
            }
            if (compared_parents.Count > 0)
            {
                if (compared_parents.Count == 1)
                {
                    changes.Add("Added parent " + compared_parents[0]);
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Added parents " + compared_parents[0]);
                    for (int i = 1; i < compared_parents.Count; i++)
                    {
                        builder.Append(", " + compared_parents[i]);
                    }
                    changes.Add(builder.ToString());
                }
            }

            // name
            if (!Base.Name.Equals(Compared.Name))
            {
                changes.Add("Changed name ( '" + Base.Name + "' --> '" + Compared.Name + "' )");
            }

            // short name
            if (!Base.ShortName.Equals(Compared.ShortName))
            {
                changes.Add("Changed short name ( '" + Base.ShortName + "' --> '" + Compared.ShortName + "' )");
            }

            // description
            if (!Base.Description.Equals(Compared.Description))
            {
                changes.Add("Changed description");
            }

            // type
            if (!Base.Type.Equals(Compared.Type))
            {
                changes.Add("Changed type ( '" + Base.Type + "' --> '" + Compared.Type + "' )");
            }

            // email address
            compare_nullable_strings(Base.Contact_Email, Compared.Contact_Email, "contact email", changes);

            // external link
            compare_nullable_strings(Base.External_Link, Compared.External_Link, "external link", changes);

            // Hidden flag
            if (Base.Hidden != Compared.Hidden)
            {
                if (Compared.Hidden)
                {
                    changes.Add("Removed from parent home page");
                }
                else
                {
                    changes.Add("Added to parent home page");
                }
            }

            // active flag
            if (Base.Active != Compared.Active)
            {
                if (Compared.Active)
                {
                    changes.Add("Aggregation activated");
                }
                else
                {
                    changes.Add("Aggregation deactivated");
                }
            }

            // thematic headings
            if (Base.Thematic_Heading == null)
            {
                if (Compared.Thematic_Heading != null)
                {
                    changes.Add("Added to thematic heading '" + Compared.Thematic_Heading.Text + "'");
                }
            }
            else
            {
                if (Compared.Thematic_Heading == null)
                {
                    changes.Add("Removed from thematic heading '" + Base.Thematic_Heading.Text + "'");
                }
                else
                {
                    if (Base.Thematic_Heading.ID != Compared.Thematic_Heading.ID)
                    {
                        changes.Add("Changed thematic heading ( '" + Base.Thematic_Heading.Text + "' --> '" + Compared.Thematic_Heading.Text + "' )");
                    }
                }
            }

            // web skin
            List <string> base_skins     = new List <string>();
            List <string> compared_skins = new List <string>();

            if (Base.Web_Skins != null)
            {
                foreach (string thisSkin in Base.Web_Skins)
                {
                    // Look in compared for a match
                    if ((Compared.Web_Skins == null) || (Compared.Web_Skins.All(CompareSkin => String.Compare(thisSkin, CompareSkin, StringComparison.InvariantCultureIgnoreCase) != 0)))
                    {
                        base_skins.Add(thisSkin);
                    }
                }
            }
            if (Compared.Web_Skins != null)
            {
                foreach (string thisSkin in Compared.Web_Skins)
                {
                    // Look in base for a match
                    if ((Base.Web_Skins == null) || (Base.Web_Skins.All(CompareSkin => String.Compare(thisSkin, CompareSkin, StringComparison.InvariantCultureIgnoreCase) != 0)))
                    {
                        compared_skins.Add(thisSkin);
                    }
                }
            }
            if (base_skins.Count > 0)
            {
                if (base_skins.Count == 1)
                {
                    changes.Add("Removed web skin " + base_skins[0]);
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Removed web skins " + base_skins[0]);
                    for (int i = 1; i < base_skins.Count; i++)
                    {
                        builder.Append(", " + base_skins[i]);
                    }
                    changes.Add(builder.ToString());
                }
            }
            if (compared_skins.Count > 0)
            {
                if (compared_skins.Count == 1)
                {
                    changes.Add("Added web skin " + compared_skins[0]);
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Added web skins " + compared_skins[0]);
                    for (int i = 1; i < compared_skins.Count; i++)
                    {
                        builder.Append(", " + compared_skins[i]);
                    }
                    changes.Add(builder.ToString());
                }
            }

            // default web skin
            compare_nullable_strings(Base.Default_Skin, Compared.Default_Skin, "default web skin", changes);

            // custom css
            if (String.IsNullOrEmpty(Base.CSS_File))
            {
                if (!String.IsNullOrEmpty(Compared.CSS_File))
                {
                    changes.Add("Enabled the aggregation-level stylesheet");
                }
            }
            else
            {
                if (String.IsNullOrEmpty(Compared.CSS_File))
                {
                    changes.Add("Disabled the aggregation-level stylesheet");
                }
            }

            // home pages (multilingual)
            List <Web_Language_Enum> removedLanguages = new List <Web_Language_Enum>();
            List <Web_Language_Enum> addedLanguages   = new List <Web_Language_Enum>();

            if (Base.Home_Page_File_Dictionary != null)
            {
                foreach (KeyValuePair <Web_Language_Enum, Complete_Item_Aggregation_Home_Page> thisHomePage in Base.Home_Page_File_Dictionary)
                {
                    // Look in compared for a match
                    if ((Compared.Home_Page_File_Dictionary == null) || (Compared.Home_Page_File_Dictionary.All(CompareHomePage => thisHomePage.Key != CompareHomePage.Key)))
                    {
                        removedLanguages.Add(thisHomePage.Key);
                    }
                }
            }
            if (Compared.Home_Page_File_Dictionary != null)
            {
                foreach (KeyValuePair <Web_Language_Enum, Complete_Item_Aggregation_Home_Page> thisHomePage in Compared.Home_Page_File_Dictionary)
                {
                    // Look in base for a match
                    if ((Base.Home_Page_File_Dictionary == null) || (Base.Home_Page_File_Dictionary.All(CompareHomePage => thisHomePage.Key != CompareHomePage.Key)))
                    {
                        addedLanguages.Add(thisHomePage.Key);
                    }
                }
            }
            if (removedLanguages.Count > 0)
            {
                if (removedLanguages.Count == 1)
                {
                    changes.Add("Removed " + Web_Language_Enum_Converter.Enum_To_Name(removedLanguages[0]) + " home page");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Removed " + Web_Language_Enum_Converter.Enum_To_Name(removedLanguages[0]));
                    for (int i = 1; i < removedLanguages.Count; i++)
                    {
                        builder.Append(", " + removedLanguages[i]);
                    }
                    changes.Add(builder + " home pages");
                }
            }
            if (addedLanguages.Count > 0)
            {
                if (addedLanguages.Count == 1)
                {
                    changes.Add("Added " + Web_Language_Enum_Converter.Enum_To_Name(addedLanguages[0]) + " home page");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Added " + Web_Language_Enum_Converter.Enum_To_Name(removedLanguages[0]));
                    for (int i = 1; i < addedLanguages.Count; i++)
                    {
                        builder.Append(", " + addedLanguages[i]);
                    }
                    changes.Add(builder + " home pages");
                }
            }


            // banners (multilingual)
            removedLanguages.Clear();
            addedLanguages.Clear();
            if (Base.Banner_Dictionary != null)
            {
                foreach (KeyValuePair <Web_Language_Enum, string> thisBanner in Base.Banner_Dictionary)
                {
                    // Look in compared for a match
                    bool match = false;
                    if (Compared.Banner_Dictionary != null)
                    {
                        foreach (KeyValuePair <Web_Language_Enum, string> compareBanner in Compared.Banner_Dictionary)
                        {
                            if (thisBanner.Key == compareBanner.Key)
                            {
                                match = true;

                                // Now, compare the source file as well
                                if (String.Compare(thisBanner.Value, compareBanner.Value, StringComparison.InvariantCultureIgnoreCase) != 0)
                                {
                                    changes.Add("Changed " + Web_Language_Enum_Converter.Enum_To_Name(thisBanner.Key) + " banner source file (" + thisBanner.Value + " --> " + compareBanner.Value + ")");
                                }

                                break;
                            }
                        }
                    }
                    if (!match)
                    {
                        removedLanguages.Add(thisBanner.Key);
                    }
                }
            }
            if (Compared.Banner_Dictionary != null)
            {
                foreach (KeyValuePair <Web_Language_Enum, string> thisBanner in Compared.Banner_Dictionary)
                {
                    // Look in base for a match
                    if ((Base.Banner_Dictionary == null) || (Base.Banner_Dictionary.All(CompareBanner => thisBanner.Key != CompareBanner.Key)))
                    {
                        addedLanguages.Add(thisBanner.Key);
                    }
                }
            }
            if (removedLanguages.Count > 0)
            {
                if (removedLanguages.Count == 1)
                {
                    changes.Add("Removed " + Web_Language_Enum_Converter.Enum_To_Name(removedLanguages[0]) + " banner");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Removed " + Web_Language_Enum_Converter.Enum_To_Name(removedLanguages[0]));
                    for (int i = 1; i < removedLanguages.Count; i++)
                    {
                        builder.Append(", " + removedLanguages[i]);
                    }
                    changes.Add(builder + " banners");
                }
            }
            if (addedLanguages.Count > 0)
            {
                if (addedLanguages.Count == 1)
                {
                    changes.Add("Added " + Web_Language_Enum_Converter.Enum_To_Name(addedLanguages[0]) + " banner");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Added " + Web_Language_Enum_Converter.Enum_To_Name(addedLanguages[0]));
                    for (int i = 1; i < addedLanguages.Count; i++)
                    {
                        builder.Append(", " + addedLanguages[i]);
                    }
                    changes.Add(builder + " banners");
                }
            }

            // search types
            List <Search_Type_Enum> removedSearches = new List <Search_Type_Enum>();
            List <Search_Type_Enum> addedSearches   = new List <Search_Type_Enum>();

            if (Base.Search_Types != null)
            {
                foreach (Search_Type_Enum thisSearch in Base.Search_Types)
                {
                    // Look in compared for a match
                    if ((Compared.Search_Types == null) || (Compared.Search_Types.All(CompareSearch => thisSearch != CompareSearch)))
                    {
                        removedSearches.Add(thisSearch);
                    }
                }
            }
            if (Compared.Search_Types != null)
            {
                foreach (Search_Type_Enum thisSearch in Compared.Search_Types)
                {
                    // Look in base for a match
                    if ((Base.Search_Types == null) || (Base.Search_Types.All(CompareSearch => thisSearch != CompareSearch)))
                    {
                        addedSearches.Add(thisSearch);
                    }
                }
            }
            if (removedSearches.Count > 0)
            {
                if (removedSearches.Count == 1)
                {
                    changes.Add("Removed " + removedSearches[0].ToString() + " search");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Removed " + removedSearches[0].ToString());
                    for (int i = 1; i < removedSearches.Count; i++)
                    {
                        builder.Append(", " + removedSearches[i].ToString());
                    }
                    changes.Add(builder + " searches");
                }
            }
            if (addedSearches.Count > 0)
            {
                if (addedSearches.Count == 1)
                {
                    changes.Add("Added " + addedSearches[0] + " search");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Added " + addedSearches[0]);
                    for (int i = 1; i < addedSearches.Count; i++)
                    {
                        builder.Append(", " + addedSearches[i]);
                    }
                    changes.Add(builder + " searches");
                }
            }

            // other display types? ( all/new item browse, map browse )

            // map search default area
            if ((Base.Map_Search_Display != null) || (Compared.Map_Search_Display != null))
            {
                if (Base.Map_Search_Display == null)
                {
                    changes.Add("Added default area for map search display");
                }
                else if (Compared.Map_Search_Display == null)
                {
                    changes.Add("Removed default area information for map search display");
                }
                else
                {
                    // Are these different?
                    bool different = false;
                    if (Base.Map_Search_Display.Type != Compared.Map_Search_Display.Type)
                    {
                        different = true;
                    }
                    else
                    {
                        if ((Base.Map_Search_Display.ZoomLevel.HasValue != Compared.Map_Search_Display.ZoomLevel.HasValue) ||
                            ((Base.Map_Search_Display.ZoomLevel.HasValue) && (Base.Map_Search_Display.ZoomLevel.Value != Compared.Map_Search_Display.ZoomLevel.Value)))
                        {
                            different = true;
                        }
                        if ((Base.Map_Search_Display.Latitude.HasValue != Compared.Map_Search_Display.Latitude.HasValue) ||
                            ((Base.Map_Search_Display.Latitude.HasValue) && (Base.Map_Search_Display.Latitude.Value != Compared.Map_Search_Display.Latitude.Value)))
                        {
                            different = true;
                        }
                        if ((Base.Map_Search_Display.Longitude.HasValue != Compared.Map_Search_Display.Longitude.HasValue) ||
                            ((Base.Map_Search_Display.Longitude.HasValue) && (Base.Map_Search_Display.Longitude.Value != Compared.Map_Search_Display.Longitude.Value)))
                        {
                            different = true;
                        }
                    }

                    if (different)
                    {
                        changes.Add("Changed default area for map search display");
                    }
                }
            }

            // map browse default area
            if ((Base.Map_Browse_Display != null) || (Compared.Map_Browse_Display != null))
            {
                if (Base.Map_Browse_Display == null)
                {
                    changes.Add("Added default area for map browse display");
                }
                else if (Compared.Map_Browse_Display == null)
                {
                    changes.Add("Removed default area information for map browse display");
                }
                else
                {
                    // Are these different?
                    bool different = false;
                    if (Base.Map_Browse_Display.Type != Compared.Map_Browse_Display.Type)
                    {
                        different = true;
                    }
                    else
                    {
                        if ((Base.Map_Browse_Display.ZoomLevel.HasValue != Compared.Map_Browse_Display.ZoomLevel.HasValue) ||
                            ((Base.Map_Browse_Display.ZoomLevel.HasValue) && (Base.Map_Browse_Display.ZoomLevel.Value != Compared.Map_Browse_Display.ZoomLevel.Value)))
                        {
                            different = true;
                        }
                        if ((Base.Map_Browse_Display.Latitude.HasValue != Compared.Map_Browse_Display.Latitude.HasValue) ||
                            ((Base.Map_Browse_Display.Latitude.HasValue) && (Base.Map_Browse_Display.Latitude.Value != Compared.Map_Browse_Display.Latitude.Value)))
                        {
                            different = true;
                        }
                        if ((Base.Map_Browse_Display.Longitude.HasValue != Compared.Map_Browse_Display.Longitude.HasValue) ||
                            ((Base.Map_Browse_Display.Longitude.HasValue) && (Base.Map_Browse_Display.Longitude.Value != Compared.Map_Browse_Display.Longitude.Value)))
                        {
                            different = true;
                        }
                    }

                    if (different)
                    {
                        changes.Add("Changed default area for map browse display");
                    }
                }
            }

            // facets
            List <Complete_Item_Aggregation_Metadata_Type> addedFacets   = new List <Complete_Item_Aggregation_Metadata_Type>();
            List <Complete_Item_Aggregation_Metadata_Type> removedFacets = new List <Complete_Item_Aggregation_Metadata_Type>();

            if (Base.Facets != null)
            {
                foreach (Complete_Item_Aggregation_Metadata_Type thisFacet in Base.Facets)
                {
                    // Look in compared for a match
                    if ((Compared.Facets == null) || (Compared.Facets.All(CompareFacet => thisFacet.ID != CompareFacet.ID)))
                    {
                        removedFacets.Add(thisFacet);
                    }
                }
            }
            if (Compared.Facets != null)
            {
                foreach (Complete_Item_Aggregation_Metadata_Type thisFacet in Compared.Facets)
                {
                    // Look in base for a match
                    if ((Base.Facets == null) || (Base.Facets.All(CompareFacet => thisFacet.ID != CompareFacet.ID)))
                    {
                        addedFacets.Add(thisFacet);
                    }
                }
            }
            if (removedFacets.Count > 0)
            {
                if (removedFacets.Count == 1)
                {
                    changes.Add("Removed facet " + removedFacets[0]);
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Removed facets " + removedFacets[0]);
                    for (int i = 1; i < removedFacets.Count; i++)
                    {
                        builder.Append(", " + removedFacets[i]);
                    }
                    changes.Add(builder.ToString());
                }
            }
            if (addedFacets.Count > 0)
            {
                if (addedFacets.Count == 1)
                {
                    changes.Add("Added facet " + addedFacets[0]);
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Added facets " + addedFacets[0]);
                    for (int i = 1; i < addedFacets.Count; i++)
                    {
                        builder.Append(", " + addedFacets[i]);
                    }
                    changes.Add(builder.ToString());
                }
            }

            // result views
            List <string> removedResultsDisplay = new List <string>();
            List <string> addedResultsDisplays  = new List <string>();

            if (Base.Result_Views != null)
            {
                foreach (string thisSearch in Base.Result_Views)
                {
                    // Look in compared for a match
                    if ((Compared.Result_Views == null) || (Compared.Result_Views.All(CompareSearch => thisSearch != CompareSearch)))
                    {
                        removedResultsDisplay.Add(thisSearch);
                    }
                }
            }
            if (Compared.Search_Types != null)
            {
                foreach (string thisSearch in Compared.Result_Views)
                {
                    // Look in base for a match
                    if ((Base.Result_Views == null) || (Base.Result_Views.All(CompareSearch => thisSearch != CompareSearch)))
                    {
                        addedResultsDisplays.Add(thisSearch);
                    }
                }
            }
            if (removedResultsDisplay.Count > 0)
            {
                if (removedResultsDisplay.Count == 1)
                {
                    changes.Add("Removed " + removedResultsDisplay[0].ToString() + " result display type");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Removed " + removedResultsDisplay[0]);
                    for (int i = 1; i < removedResultsDisplay.Count; i++)
                    {
                        builder.Append(", " + removedResultsDisplay[i]);
                    }
                    changes.Add(builder + " result display types");
                }
            }
            if (addedResultsDisplays.Count > 0)
            {
                if (addedResultsDisplays.Count == 1)
                {
                    changes.Add("Added " + addedResultsDisplays[0] + " result display type");
                }
                else
                {
                    StringBuilder builder = new StringBuilder("Added " + addedResultsDisplays[0]);
                    for (int i = 1; i < addedResultsDisplays.Count; i++)
                    {
                        builder.Append(", " + addedResultsDisplays[i]);
                    }
                    changes.Add(builder + " result display types");
                }
            }

            // default browse
            compare_nullable_strings(Base.Default_BrowseBy, Compared.Default_BrowseBy, "default browse", changes);

            // metadata browse


            // oai-pmh flag
            if (Base.OAI_Enabled != Compared.OAI_Enabled)
            {
                if (Compared.OAI_Enabled)
                {
                    changes.Add("OAI-PMH enabled");
                }
                else
                {
                    changes.Add("OAI-PMH disabled");
                }
            }

            // oai-pmh description
            compare_nullable_strings(Base.OAI_Metadata, Compared.OAI_Metadata, "additional OAI-PMH metadata", changes);

            // child pages


            return(changes);
        }
        /// <summary> Gets the all information, including the HTML, for an item aggregation child page </summary>
        /// <param name="Response"></param>
        /// <param name="UrlSegments"></param>
        /// <param name="QueryString"></param>
        /// <param name="Protocol"></param>
        /// <param name="IsDebug"></param>
        public void GetCollectionStaticPage(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug)
        {
            if (UrlSegments.Count > 2)
            {
                Custom_Tracer tracer = new Custom_Tracer();

                try
                {
                    // Get the code and language from the URL
                    string            aggrCode  = UrlSegments[0];
                    string            language  = UrlSegments[1];
                    string            childCode = UrlSegments[2];
                    Web_Language_Enum langEnum  = Web_Language_Enum_Converter.Code_To_Enum(language);

                    if (langEnum == Web_Language_Enum.UNDEFINED)
                    {
                        tracer.Add_Trace("AggregationServices.GetCollectionStaticPage", "Language code '" + language + "' not recognized");
                    }

                    // Build the language-specific item aggregation
                    tracer.Add_Trace("AggregationServices.GetCollectionStaticPage", "Build and return child page '" + childCode + "' in aggregation '" + aggrCode + "' for '" + Web_Language_Enum_Converter.Enum_To_Name(langEnum) + "'");

                    // Get the aggregation code manager
                    HTML_Based_Content returnValue = get_item_aggregation_html_child_page(aggrCode, langEnum, Engine_ApplicationCache_Gateway.Settings.System.Default_UI_Language, childCode, tracer);

                    // If this was debug mode, then just write the tracer
                    if (IsDebug)
                    {
                        Response.ContentType = "text/plain";
                        Response.Output.WriteLine("DEBUG MODE DETECTED");
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(tracer.Text_Trace);

                        return;
                    }

                    // Get the JSON-P callback function
                    string json_callback = "parseCollectionStaticPage";
                    if ((Protocol == Microservice_Endpoint_Protocol_Enum.JSON_P) && (!String.IsNullOrEmpty(QueryString["callback"])))
                    {
                        json_callback = QueryString["callback"];
                    }

                    // Use the base class to serialize the object according to request protocol
                    Serialize(returnValue, Response, Protocol, json_callback);
                }
                catch (Exception ee)
                {
                    if (IsDebug)
                    {
                        Response.ContentType = "text/plain";
                        Response.Output.WriteLine("EXCEPTION CAUGHT!");
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(ee.Message);
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(ee.StackTrace);
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(tracer.Text_Trace);
                        return;
                    }

                    Response.ContentType = "text/plain";
                    Response.Output.WriteLine("Error completing request");
                    Response.StatusCode = 500;
                }
            }
        }
Esempio n. 6
0
        /// <summary> Constructor for a new instance of the Static_Browse_Info_AggregationViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        /// <param name="ViewBag"> Aggregation-specific request information, such as aggregation object and any browse object requested </param>
        public Static_Browse_Info_AggregationViewer(RequestCache RequestSpecificValues, AggregationViewBag ViewBag)
            : base(RequestSpecificValues, ViewBag)
        {
            bool isAdmin = (RequestSpecificValues.Current_User != null) && (RequestSpecificValues.Current_User.Is_Aggregation_Admin(ViewBag.Hierarchy_Object.Code));

            if ((RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Child_Page_Edit) && (!isAdmin))
            {
                RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Browse_Info;
            }

            NameValueCollection form = HttpContext.Current.Request.Form;

            if ((RequestSpecificValues.Current_Mode.Aggregation_Type == Aggregation_Type_Enum.Child_Page_Edit) && (form["sbkSbia_ChildTextEdit"] != null) && (RequestSpecificValues.Current_User != null))
            {
                string aggregation_folder = UI_ApplicationCache_Gateway.Settings.Servers.Base_Design_Location + "aggregations\\" + ViewBag.Hierarchy_Object.Code + "\\";

                string file = aggregation_folder + ViewBag.Browse_Object.Source;

                // Get the header information as well
                if (!String.IsNullOrEmpty(form["admin_childpage_title"]))
                {
                    ViewBag.Static_Web_Content.Title = form["admin_childpage_title"];
                }
                if (form["admin_childpage_author"] != null)
                {
                    ViewBag.Static_Web_Content.Author = form["admin_childpage_author"];
                }
                if (form["admin_childpage_date"] != null)
                {
                    ViewBag.Static_Web_Content.Date = form["admin_childpage_date"];
                }
                if (form["admin_childpage_description"] != null)
                {
                    ViewBag.Static_Web_Content.Description = form["admin_childpage_description"];
                }
                if (form["admin_childpage_keywords"] != null)
                {
                    ViewBag.Static_Web_Content.Keywords = form["admin_childpage_keywords"];
                }
                if (form["admin_childpage_extrahead"] != null)
                {
                    ViewBag.Static_Web_Content.Extra_Head_Info = form["admin_childpage_extrahead"];
                }


                // Make a backup from today, if none made yet
                if (File.Exists(file))
                {
                    DateTime lastWrite = (new FileInfo(file)).LastWriteTime;
                    string   new_file  = file.ToLower().Replace(".txt", "").Replace(".html", "").Replace(".htm", "") + lastWrite.Year + lastWrite.Month.ToString().PadLeft(2, '0') + lastWrite.Day.ToString().PadLeft(2, '0') + ".bak";
                    if (File.Exists(new_file))
                    {
                        File.Delete(new_file);
                    }
                    File.Move(file, new_file);
                }


                // Assign the new text
                ViewBag.Static_Web_Content.Content = form["sbkSbia_ChildTextEdit"].Replace("%]", "%>").Replace("[%", "<%");
                ViewBag.Static_Web_Content.Date    = DateTime.Now.ToLongDateString();
                ViewBag.Static_Web_Content.Save_To_File(file);

                // Also save this change
                SobekCM_Database.Save_Item_Aggregation_Milestone(ViewBag.Hierarchy_Object.Code, "Child page '" + ViewBag.Browse_Object.Code + "' edited (" + Web_Language_Enum_Converter.Enum_To_Name(RequestSpecificValues.Current_Mode.Language) + ")", RequestSpecificValues.Current_User.Full_Name);

                // Forward along
                RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Browse_Info;
                if (ViewBag.Browse_Object.Browse_Type == Item_Aggregation_Child_Visibility_Enum.Metadata_Browse_By)
                {
                    RequestSpecificValues.Current_Mode.Aggregation_Type = Aggregation_Type_Enum.Browse_By;
                }

                string redirect_url = UrlWriterHelper.Redirect_URL(RequestSpecificValues.Current_Mode);
                if (redirect_url.IndexOf("?") > 0)
                {
                    redirect_url = redirect_url + "&refresh=always";
                }
                else
                {
                    redirect_url = redirect_url + "?refresh=always";
                }
                RequestSpecificValues.Current_Mode.Request_Completed = true;
                HttpContext.Current.Response.Redirect(redirect_url, false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
        }