Esempio n. 1
0
        /// <summary> Resets all the application-level data  </summary>
        public static void ResetAll()
        {
            Engine_ApplicationCache_Gateway.RefreshAll();

            WebContent_Hierarchy_Clear();

            ItemViewer_Factory.Clear();

            HtmlLayoutManager.Clear();
        }
Esempio n. 2
0
 /// <summary> Clears the lists of globally defined default metadata sets and metadata input templates, so they
 /// will be refreshed next time they are requested </summary>
 public static void ResetDefaultMetadataTemplates()
 {
     Engine_ApplicationCache_Gateway.RefreshDefaultMetadataTemplates();
 }
Esempio n. 3
0
 /// <summary> Refresh the settings object by pulling the data back from the database </summary>
 public static void ResetSettings()
 {
     Engine_ApplicationCache_Gateway.RefreshSettings();
 }
Esempio n. 4
0
        /// <summary> Constructor for a new instance of the Default_Metadata_AdminViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        /// <remarks> Postback from handling a new project is handled here in the constructor </remarks>
        public Default_Metadata_AdminViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Default_Metadata_AdminViewer.Constructor", String.Empty);

            // Set action message and entered values to nothing to start
            actionMessage = String.Empty;
            entered_code  = String.Empty;
            entered_base  = String.Empty;
            entered_name  = String.Empty;
            entered_desc  = String.Empty;

            // If the RequestSpecificValues.Current_User cannot edit this, go back
            if ((!RequestSpecificValues.Current_User.Is_System_Admin) && (!RequestSpecificValues.Current_User.Is_Portal_Admin))
            {
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.My_Sobek;
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // If this is a postback, handle any events first
            if (RequestSpecificValues.Current_Mode.isPostBack)
            {
                try
                {
                    // Pull the standard values
                    NameValueCollection form = HttpContext.Current.Request.Form;

                    string save_value   = form["admin_project_tosave"].ToUpper().Trim();
                    string delete_value = form["admin_project_delete"].ToUpper().Trim();
                    string code_value   = form["admin_project_code"].ToUpper().Trim();

                    // Was this a delete request?
                    if ((RequestSpecificValues.Current_User.Is_System_Admin) && (delete_value.Length > 0))
                    {
                        RequestSpecificValues.Tracer.Add_Trace("Default_Metadata_AdminViewer.Constructor", "Delete default metadata '" + delete_value + "'");

                        // Try to delete in the database
                        if (SobekCM_Database.Delete_Default_Metadata(delete_value, RequestSpecificValues.Tracer))
                        {
                            // Set the message
                            actionMessage = "Deleted default metadata '" + delete_value + "'";

                            // Look for the file to delete as well
                            string pmets_file = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "projects\\" + delete_value + ".pmets";
                            if (File.Exists(pmets_file))
                            {
                                try
                                {
                                    File.Delete(pmets_file);
                                }
                                catch
                                {
                                    actionMessage = "Deleted default metadata '" + delete_value + "' but failed to delete associated pmets file";
                                }
                            }
                        }
                        else
                        {
                            actionMessage = "Error encountered deleting default metadata '" + delete_value + "' from the database";
                        }



                        Engine_ApplicationCache_Gateway.RefreshCollectionAliases();
                    }
                    else if (save_value.Length > 0) // Or.. was this a save request
                    {
                        RequestSpecificValues.Tracer.Add_Trace("Default_Metadata_AdminViewer.Constructor", "Save default metadata '" + save_value + "'");

                        // Was this to save a new project (from the main page) or rename an existing (from the popup form)?
                        if (save_value == code_value)
                        {
                            entered_code = code_value;
                            entered_base = form["admin_project_base"].ToUpper().Trim();
                            entered_name = form["admin_project_name"].Trim().Replace("\"", "'");
                            entered_desc = form["admin_project_desc"].Trim().Replace("\"", "'");

                            if (entered_name.Length == 0)
                            {
                                entered_name = entered_code;
                            }
                            if (entered_desc.Length == 0)
                            {
                                entered_desc = entered_name;
                            }

                            // Ensure the code is valid first
                            bool result = entered_code.All(C => Char.IsLetterOrDigit(C) || C == '_');
                            if (!result)
                            {
                                actionMessage = "ERROR: Default metadata CODE must contain only letters and numbers";
                                entered_code  = entered_code.Replace("\"", "");
                            }
                            else if (entered_code.Length == 0)
                            {
                                actionMessage = "ERROR: Default metadata CODE is required";
                            }
                            else if (entered_code.Length > 20)
                            {
                                actionMessage = "ERROR: Default metadata CODE cannot be more than twenty characters long";
                                entered_code  = entered_code.Substring(0, 20);
                            }
                            else if (entered_name.Length > 50)
                            {
                                actionMessage = "ERROR: Default metadata NAME cannot be more than fifty characters long";
                                entered_name  = entered_name.Substring(0, 50);
                            }
                            else
                            {
                                // Save this new interface
                                if (SobekCM_Database.Save_Default_Metadata(entered_code.ToUpper(), entered_name, entered_desc, -1, RequestSpecificValues.Tracer))
                                {
                                    actionMessage = "Saved new default metadata <i>" + save_value + "</i>";

                                    entered_code = String.Empty;
                                    entered_base = String.Empty;
                                    entered_name = String.Empty;
                                    entered_desc = String.Empty;
                                }
                                else
                                {
                                    actionMessage = "Unable to save new default metadata <i>" + save_value + "</i>";
                                }

                                Engine_ApplicationCache_Gateway.RefreshCollectionAliases();

                                // Try to creating the PMETS file if there was a base PMETS code provided
                                try
                                {
                                    if (entered_base.Length > 0)
                                    {
                                        string pmets_file      = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "projects\\" + code_value + ".pmets";
                                        string base_pmets_file = UI_ApplicationCache_Gateway.Settings.Servers.Base_MySobek_Directory + "projects\\" + entered_base + ".pmets";

                                        if (File.Exists(base_pmets_file))
                                        {
                                            File.Copy(base_pmets_file, pmets_file, true);
                                        }
                                    }
                                }
                                catch (Exception)
                                {
                                    actionMessage = "Error copying new default metadata METS to the project folder";
                                }
                            }
                        }
                        else
                        {
                            string edit_name        = form["form_project_name"].Trim().Replace("\"", "'");
                            string edit_description = form["form_project_desc"].Trim().Replace("\"", "'");

                            // Save this existing interface
                            if (SobekCM_Database.Save_Default_Metadata(save_value.ToUpper(), edit_name, edit_description, -1, RequestSpecificValues.Tracer))
                            {
                                actionMessage = "Renamed existing default metadata <i>" + save_value + "</i>";
                            }
                            else
                            {
                                actionMessage = "Unable to rename existing default metadata <i>" + save_value + "</i>";
                            }

                            Engine_ApplicationCache_Gateway.RefreshCollectionAliases();
                        }
                    }
                }
                catch (Exception)
                {
                    actionMessage = "Unknown exception occurred while processing your request";
                }
            }

            UI_ApplicationCache_Gateway.ResetDefaultMetadataTemplates();
        }
Esempio n. 5
0
        /// <summary> Constructor for a new instance of the Thematic_Headings_AdminViewer class </summary>
        /// <param name="RequestSpecificValues"> All the necessary, non-global data specific to the current request </param>
        /// <remarks> Postback from handling an edit or new thematic heading is handled here in the constructor </remarks>
        public Thematic_Headings_AdminViewer(RequestCache RequestSpecificValues) : base(RequestSpecificValues)
        {
            RequestSpecificValues.Tracer.Add_Trace("Thematic_Headings_AdminViewer.Constructor", String.Empty);

            // Set action message to nothing to start
            actionMessage = String.Empty;

            // If the RequestSpecificValues.Current_User cannot edit this, go back
            if ((!RequestSpecificValues.Current_User.Is_System_Admin) && (!RequestSpecificValues.Current_User.Is_Portal_Admin))
            {
                RequestSpecificValues.Current_Mode.Mode          = Display_Mode_Enum.My_Sobek;
                RequestSpecificValues.Current_Mode.My_Sobek_Type = My_Sobek_Type_Enum.Home;
                UrlWriterHelper.Redirect(RequestSpecificValues.Current_Mode);
                return;
            }

            // Handle any post backs
            if (RequestSpecificValues.Current_Mode.isPostBack)
            {
                try
                {
                    // Pull the standard values from the form
                    NameValueCollection form = HttpContext.Current.Request.Form;
                    string save_value        = form["admin_heading_tosave"];
                    string action_value      = form["admin_heading_action"];

                    // Switch, depending on the request
                    if (action_value != null)
                    {
                        switch (action_value.Trim().ToLower())
                        {
                        case "edit":
                            string new_name = form["form_heading_name"];
                            if (new_name != null)
                            {
                                int id    = Convert.ToInt32(save_value);
                                int order = 1 + UI_ApplicationCache_Gateway.Thematic_Headings.TakeWhile(ThisHeading => ThisHeading.ID != id).Count();
                                if (Engine_Database.Edit_Thematic_Heading(id, order, new_name, RequestSpecificValues.Tracer) < 1)
                                {
                                    actionMessage = "Unable to edit existing thematic heading";
                                }
                                else
                                {
                                    // For thread safety, lock the thematic headings list
                                    Engine_ApplicationCache_Gateway.RefreshThematicHeadings();

                                    actionMessage = "Thematic heading edits saved";
                                }
                            }
                            break;

                        case "delete":
                            int thematicDeleteId = Convert.ToInt32(save_value);
                            if (!Engine_Database.Delete_Thematic_Heading(thematicDeleteId, RequestSpecificValues.Tracer))
                            {
                                // Set action message
                                actionMessage = "Unable to delete existing thematic heading";
                            }
                            else
                            {
                                // For thread safety, lock the thematic headings list
                                lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                {
                                    // Remove this thematic heading from the list
                                    int i = 0;
                                    while (i < UI_ApplicationCache_Gateway.Thematic_Headings.Count)
                                    {
                                        if (UI_ApplicationCache_Gateway.Thematic_Headings[i].ID == thematicDeleteId)
                                        {
                                            UI_ApplicationCache_Gateway.Thematic_Headings.RemoveAt(i);
                                        }
                                        else
                                        {
                                            i++;
                                        }
                                    }
                                }

                                // Set action message
                                actionMessage = "Thematic heading deleted";
                            }
                            break;


                        case "new":
                            int new_order = UI_ApplicationCache_Gateway.Thematic_Headings.Count + 1;
                            int newid     = Engine_Database.Edit_Thematic_Heading(-1, new_order, save_value, RequestSpecificValues.Tracer);
                            if (newid < 1)
                            {
                                actionMessage = "Unable to save new thematic heading";
                            }
                            else
                            {
                                // For thread safety, lock the thematic headings list
                                lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                {
                                    // Repopulate the thematic headings list
                                    Engine_Database.Populate_Thematic_Headings(UI_ApplicationCache_Gateway.Thematic_Headings, RequestSpecificValues.Tracer);
                                }

                                // Add this blank thematic heading to the code manager
                                UI_ApplicationCache_Gateway.Aggregations.Add_Blank_Thematic_Heading(newid);

                                actionMessage = "New thematic heading saved";
                            }
                            break;

                        case "moveup":
                            string[] moveup_split = save_value.Split(",".ToCharArray());
                            int      moveup_id    = Convert.ToInt32(moveup_split[0]);
                            int      moveup_order = Convert.ToInt32(moveup_split[1]);
                            if (moveup_order > 1)
                            {
                                Thematic_Heading themeHeading = UI_ApplicationCache_Gateway.Thematic_Headings[moveup_order - 1];
                                if (themeHeading.ID == moveup_id)
                                {
                                    // For thread safety, lock the thematic headings list
                                    lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                    {
                                        // Move this thematic heading up
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Remove(themeHeading);
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Insert(moveup_order - 2, themeHeading);
                                        int current_order = 1;
                                        foreach (Thematic_Heading thisTheme in UI_ApplicationCache_Gateway.Thematic_Headings)
                                        {
                                            Engine_Database.Edit_Thematic_Heading(thisTheme.ID, current_order, thisTheme.Text, RequestSpecificValues.Tracer);
                                            current_order++;
                                        }

                                        // Repopulate the thematic headings list
                                        Engine_Database.Populate_Thematic_Headings(UI_ApplicationCache_Gateway.Thematic_Headings, RequestSpecificValues.Tracer);
                                    }
                                }
                            }
                            break;

                        case "movedown":
                            string[] movedown_split = save_value.Split(",".ToCharArray());
                            int      movedown_id    = Convert.ToInt32(movedown_split[0]);
                            int      movedown_order = Convert.ToInt32(movedown_split[1]);
                            if (movedown_order < UI_ApplicationCache_Gateway.Thematic_Headings.Count)
                            {
                                Thematic_Heading themeHeading = UI_ApplicationCache_Gateway.Thematic_Headings[movedown_order - 1];
                                if (themeHeading.ID == movedown_id)
                                {
                                    // For thread safety, lock the thematic headings list
                                    lock (UI_ApplicationCache_Gateway.Thematic_Headings)
                                    {
                                        // Move this thematic heading down
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Remove(themeHeading);
                                        UI_ApplicationCache_Gateway.Thematic_Headings.Insert(movedown_order, themeHeading);
                                        int current_order = 1;
                                        foreach (Thematic_Heading thisTheme in UI_ApplicationCache_Gateway.Thematic_Headings)
                                        {
                                            Engine_Database.Edit_Thematic_Heading(thisTheme.ID, current_order, thisTheme.Text, RequestSpecificValues.Tracer);
                                            current_order++;
                                        }

                                        // Repopulate the thematic headings list
                                        Engine_Database.Populate_Thematic_Headings(UI_ApplicationCache_Gateway.Thematic_Headings, RequestSpecificValues.Tracer);
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                catch (Exception)
                {
                    actionMessage = "Unknown error caught while handling your reqeust";
                }
            }
        }
        /// <summary> Disable an existing plug-in </summary>
        /// <param name="Response"></param>
        /// <param name="UrlSegments"></param>
        /// <param name="QueryString"></param>
        /// <param name="Protocol"></param>
        /// <param name="IsDebug"></param>
        public void DisablePlugin(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug)
        {
            // Must at least have one URL segment for the Plugin ID
            if (UrlSegments.Count > 0)
            {
                Custom_Tracer tracer = new Custom_Tracer();

                // Get the plugin to enable/disable
                string plugin_code = UrlSegments[0];

                // Create the message to return
                EnableExtensionMessage responder = new EnableExtensionMessage
                {
                    Success = true,
                    Message = "Disable request received by the engine"
                };

                // Get this extension from the list of installed plugins
                ExtensionInfo thisExtension = Engine_ApplicationCache_Gateway.Configuration.Extensions.Get_Extension(plugin_code);

                // If this was NULL, do nothing else
                if (thisExtension == null)
                {
                    responder.Message = "Unable to find the extension indicated.";
                    responder.Success = false;
                }
                else
                {
                    // Set the new flag in the database and get the return message
                    responder.Message = Engine_Database.Plugin_Set_Enabled_Flag(plugin_code, false, tracer);
                    if (responder.Message.IndexOf("error", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        responder.Success = false;
                    }
                    else
                    {
                        // Repull all the configuration information
                        Engine_ApplicationCache_Gateway.RefreshAll();
                    }
                }

                // 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 = "parsePluginEnable";
                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(responder, Response, Protocol, json_callback);
            }
            else
            {
                Response.ContentType = "text/plain";
                Response.Output.WriteLine("The unique plug-in code to enable must be provided");
            }
        }