SobekCM.Core.Aggregations.Complete_Item_Aggregation.Write_Configuration_File C# (CSharp) Method

Write_Configuration_File() public method

Write the XML configuration file for this item aggregation
public Write_Configuration_File ( string Directory ) : bool
Directory string Directory within which to write this XML configuration file
return bool
        public bool Write_Configuration_File(string Directory)
        {
            try
            {
                string filename = Code.ToLower() + ".xml";

                // If the directory does not exist, creat it
                if (!System.IO.Directory.Exists(Directory))
                {
                    System.IO.Directory.CreateDirectory(Directory);
                }

                // Create the writer object
                StreamWriter writer = new StreamWriter(Directory + "\\" + filename, false);

                // Write the header for the XML file
                writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
                writer.WriteLine();
                writer.WriteLine("<!-- ITEM AGGREGATION CONFIGURATION FILE FOR '" + Code.ToUpper() + "'   -->");
                writer.WriteLine("<hi:aggregationInfo xmlns:hi=\"http://sobekrepository.org/schemas/sobekcm_aggregation/\" ");
                writer.WriteLine("				  xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
                writer.WriteLine("				  xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
                writer.WriteLine("				  xsi:schemaLocation=\"http://sobekrepository.org/schemas/sobekcm_aggregation/ ");
                writer.WriteLine("									 http://sobekrepository.org/schemas/sobekcm_aggregation.xsd\" >");
                writer.WriteLine();

                // Write the settings portion
                writer.WriteLine("<!-- Simple aggregation-wide settings, including a specified web skin, facets, etc.. -->");
                writer.WriteLine("<hi:settings>");
                if ((Web_Skins != null) && (Web_Skins.Count > 0))
                {
                    if (Web_Skins.Count == 1)
                        writer.WriteLine("    <hi:webskins>" + Web_Skins[0] + "</hi:webskins>");
                    else
                    {
                        writer.Write("    <hi:webskins>" + Web_Skins[0]);
                        for (int i = 1; i < Web_Skins.Count; i++)
                            writer.Write("," + Web_Skins[i]);
                        writer.WriteLine("</hi:webskins>");
                    }
                }
                else
                {
                    writer.WriteLine("    <hi:webskins></hi:webskins>");
                }
                writer.WriteLine();

                // Add the aggregation-level CSS file
                if (!String.IsNullOrEmpty(CSS_File))
                {
                    writer.WriteLine("    <!-- Aggregation-level CSS file  -->");
                    writer.WriteLine("    <hi:css>" + CSS_File + "</hi:css>");
                    writer.WriteLine();
                }

                if ((Facets != null) && (Facets.Count > 0))
                {
                    if (Facets.Count == 1)
                        writer.WriteLine("    <hi:facets>" + Facets[0] + "</hi:facets>");
                    else
                    {
                        writer.Write("    <hi:facets>" + Facets[0]);
                        for (int i = 1; i < Facets.Count; i++)
                            writer.Write("," + Facets[i]);
                        writer.WriteLine("</hi:facets>");
                    }
                }
                else
                {
                    writer.WriteLine("    <hi:facets></hi:facets>");
                }

                // Include settings for map SEARCH
                if (Map_Search_Display != null)
                {
                    if (Map_Search_Display.Type == Item_Aggregation_Map_Coverage_Type_Enum.EXTENT)
                    {
                        writer.WriteLine("    <hi:mapsearch type=\"EXTENT\" />");
                    }
                    else if (Map_Search_Display.Type == Item_Aggregation_Map_Coverage_Type_Enum.COMPUTED)
                    {
                        writer.WriteLine("    <hi:mapsearch type=\"COMPUTED\" />");
                    }
                    else
                    {
                        if ((Map_Search_Display.ZoomLevel.HasValue) && (Map_Search_Display.Longitude.HasValue) && (Map_Search_Display.Latitude.HasValue))
                        {
                            writer.WriteLine("    <hi:mapsearch type=\"FIXED\" zoom=\"" + Map_Search_Display.ZoomLevel + "\" latitude=\"" + Map_Search_Display.Latitude + "\" longitude=\"" + Map_Search_Display.Longitude + "\" />");
                        }
                    }
                }

                // Inlude settings for map BROWSE
                if (Map_Browse_Display != null)
                {
                    if (Map_Browse_Display.Type == Item_Aggregation_Map_Coverage_Type_Enum.EXTENT)
                    {
                        writer.WriteLine("    <hi:mapbrowse type=\"EXTENT\" />");
                    }
                    else if (Map_Browse_Display.Type == Item_Aggregation_Map_Coverage_Type_Enum.COMPUTED)
                    {
                        writer.WriteLine("    <hi:mapbrowse type=\"COMPUTED\" />");
                    }
                    else
                    {
                        if ((Map_Browse_Display.ZoomLevel.HasValue) && (Map_Browse_Display.Longitude.HasValue) && (Map_Browse_Display.Latitude.HasValue))
                        {
                            writer.WriteLine("    <hi:mapbrowse type=\"FIXED\" zoom=\"" + Map_Browse_Display.ZoomLevel + "\" latitude=\"" + Map_Browse_Display.Latitude + "\" longitude=\"" + Map_Browse_Display.Longitude + "\" />");
                        }
                    }
                }

                writer.WriteLine("</hi:settings>");
                writer.WriteLine();

                // Add the home page information
                writer.WriteLine("<hi:home>");
                if (Home_Page_File_Dictionary != null)
                {
                    foreach (KeyValuePair<Web_Language_Enum, Complete_Item_Aggregation_Home_Page> homePair in Home_Page_File_Dictionary)
                    {
                        writer.WriteLine("    <hi:body lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(homePair.Key) + "\" isCustom=\"" + homePair.Value.isCustomHome.ToString().ToLower() + "\">" + homePair.Value.Source.Replace("/", "\\") + "</hi:body>");
                    }
                }
                writer.WriteLine("</hi:home>");
                writer.WriteLine();

                // Add the banner information
                writer.WriteLine("<hi:banner>");
                if (Banner_Dictionary != null)
                {
                    foreach (KeyValuePair<Web_Language_Enum, string> homePair in Banner_Dictionary)
                    {
                        writer.WriteLine("    <hi:source lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(homePair.Key) + "\">" + homePair.Value.Replace("/", "\\") + "</hi:source>");
                    }
                }
                if (Front_Banner_Dictionary != null)
                {
                    foreach (KeyValuePair<Web_Language_Enum, Item_Aggregation_Front_Banner> homePair in Front_Banner_Dictionary)
                    {
                        writer.Write("    <hi:source type=\"HIGHLIGHT\" lang=\"" + Web_Language_Enum_Converter.Enum_To_Code(homePair.Key) + "\"");
                        writer.Write(" height=\"" + homePair.Value.Height + "\" width=\"" + homePair.Value.Width + "\"");
                        switch (homePair.Value.Type)
                        {
                            case Item_Aggregation_Front_Banner_Type_Enum.Full:
                                writer.Write(" side=\"FULL\"");
                                break;

                            case Item_Aggregation_Front_Banner_Type_Enum.Left:
                                writer.Write(" side=\"LEFT\"");
                                break;

                            case Item_Aggregation_Front_Banner_Type_Enum.Right:
                                writer.Write(" side=\"RIGHT\"");
                                break;
                        }

                        writer.WriteLine(">" + homePair.Value.File + "</hi:source>");
                    }
                }
                writer.WriteLine("</hi:banner>");
                writer.WriteLine();

                // Add any changes to the standard views during browses or search results
                List<string> adds = new List<string>();
                List<string> deletes = new List<string>
                {
                    "<hi:remove type=\"BRIEF\" />",
                    "<hi:remove type=\"FULL\" />",
                    "<hi:remove type=\"TABLE\" />",
                    "<hi:remove type=\"THUMBNAIL\" />"
                };
                if (Result_Views != null)
                {
                    foreach (Result_Display_Type_Enum thisType in Result_Views)
                    {
                        switch (thisType)
                        {
                            case Result_Display_Type_Enum.Brief:
                                deletes.Remove("<hi:remove type=\"BRIEF\" />");
                                break;

                            case Result_Display_Type_Enum.Full_Citation:
                            case Result_Display_Type_Enum.Full_Image:
                                deletes.Remove("<hi:remove type=\"FULL\" />");
                                break;

                            case Result_Display_Type_Enum.Map:
                                adds.Add("<hi:remove type=\"MAP\" />");
                                break;

                            case Result_Display_Type_Enum.Map_Beta:
                                adds.Add("<hi:remove type=\"MAP_BETA\" />");
                                break;

                            case Result_Display_Type_Enum.Table:
                                deletes.Remove("<hi:remove type=\"TABLE\" />");
                                break;

                            case Result_Display_Type_Enum.Thumbnails:
                                deletes.Remove("<hi:remove type=\"THUMBNAIL\" />");
                                break;
                        }
                    }
                }

                switch (Default_Result_View)
                {
                    case Result_Display_Type_Enum.Brief:
                        adds.Add("<hi:add type=\"BRIEF\" default=\"DEFAULT\" />");
                        break;

                    case Result_Display_Type_Enum.Full_Citation:
                    case Result_Display_Type_Enum.Full_Image:
                        adds.Add("<hi:add type=\"FULL\" default=\"DEFAULT\" />");
                        break;

                    case Result_Display_Type_Enum.Map:
                        adds.Remove("<hi:add type=\"MAP\" />");
                        adds.Add("<hi:add type=\"MAP\" default=\"DEFAULT\" />");
                        break;

                    case Result_Display_Type_Enum.Map_Beta:
                        adds.Remove("<hi:add type=\"MAP_BETA\" />");
                        adds.Add("<hi:add type=\"MAP_BETA\" default=\"DEFAULT\" />");
                        break;

                    case Result_Display_Type_Enum.Table:
                        adds.Add("<hi:add type=\"TABLE\" default=\"DEFAULT\" />");
                        break;

                    case Result_Display_Type_Enum.Thumbnails:
                        adds.Add("<hi:add type=\"THUMBNAIL\" default=\"DEFAULT\" />");
                        break;
                }

                if ((adds.Count > 0) || (deletes.Count > 0))
                {
                    writer.WriteLine("  <hi:results>");
                    writer.WriteLine("    <hi:views>");
                    foreach (string thisDelete in deletes)
                        writer.WriteLine("      " + thisDelete);
                    foreach (string thisAdd in adds)
                        writer.WriteLine("      " + thisAdd);
                    writer.WriteLine("    </hi:views>");
                    writer.WriteLine("  </hi:results>");
                }
                else
                {
                    writer.WriteLine("  <hi:results></hi:results>");
                }
                writer.WriteLine();

                // Add the custom derivative information here, if there are some
                if ((Custom_Directives != null) && (Custom_Directives.Count > 0))
                {
                    writer.WriteLine("  <hi:directives>");
                    foreach (KeyValuePair<string, Item_Aggregation_Custom_Directive> thisDirective in Custom_Directives)
                    {
                        writer.WriteLine("    <hi:directive>");
                        writer.WriteLine("      <hi:code>" + thisDirective.Value.Code + "</hi:code>");
                        writer.WriteLine("      <hi:source>" + thisDirective.Value.Source_File + "</hi:source>");
                        writer.WriteLine("    </hi:directive>");
                    }
                    writer.WriteLine("  </hi:directives>");
                    writer.WriteLine();
                }

                // Add the highlights, if there are some
                if ((Highlights != null) && (Highlights.Count > 0))
                {
                    // Is there a special front banner with highlighted item within it?
                    if ((Front_Banner_Dictionary != null) && (Front_Banner_Dictionary.Count > 0))
                    {
                        writer.Write("  <hi:highlights ");
                        if ((Rotating_Highlights.HasValue) && (Rotating_Highlights.Value))
                            writer.WriteLine("type=\"ROTATING\">");
                        else
                            writer.WriteLine("type=\"STANDARD\">");
                    }
                    else
                    {
                        writer.WriteLine("  <hi:highlights>");
                    }

                    // Step through each highlight
                    foreach (Complete_Item_Aggregation_Highlights thisHighlight in Highlights)
                    {
                        thisHighlight.Write_In_Configuration_XML_File(writer);
                    }
                    writer.WriteLine("  </hi:highlights>");
                    writer.WriteLine();
                }

                // Add all the child pages
                if ((childPagesHash != null) && (childPagesHash.Count > 0))
                {
                    foreach (Complete_Item_Aggregation_Child_Page browseObject in Child_Pages)
                    {
                        // Don't add ALL or NEW here
                        if ((String.Compare(browseObject.Code, "all", StringComparison.InvariantCultureIgnoreCase) != 0) && (String.Compare(browseObject.Code, "new", StringComparison.InvariantCultureIgnoreCase) != 0))
                        {
                            browseObject.Write_In_Configuration_XML_File(writer, Default_BrowseBy);
                        }
                    }
                    writer.WriteLine();
                }

                // Close the main tag
                writer.WriteLine("</hi:aggregationInfo>");

                // Flush and close the writer
                writer.Flush();
                writer.Close();

                return true;
            }
            catch
            {
                return false;
            }
        }