/// <summary> Refreshes the specified builder settings object, from the information pulled from the database </summary>
        /// <param name="SettingsObject"> Current builer settings object to refresh </param>
        /// <param name="SobekCM_Settings"> Dataset of all the builder settings, from the instance database </param>
        /// <param name="IncludeModuleDescriptions"> Flag indicates if the module descriptions should be included for human readability </param>
        /// <param name="DataTableOffset"> If some previous tables exist, and should be skipped, set this to a non-zero value</param>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public static bool Refresh(Builder_Settings SettingsObject, DataSet SobekCM_Settings, bool IncludeModuleDescriptions, int DataTableOffset)
        {
            SettingsObject.Clear();
            try
            {
                Dictionary <int, List <Builder_Source_Folder> >  folder_to_set_dictionary = new Dictionary <int, List <Builder_Source_Folder> >();
                Dictionary <int, List <Builder_Module_Setting> > setid_to_modules         = new Dictionary <int, List <Builder_Module_Setting> >();

                Set_Builder_Folders(SettingsObject, SobekCM_Settings.Tables[DataTableOffset], folder_to_set_dictionary);

                Set_NonScheduled_Modules(SettingsObject, SobekCM_Settings.Tables[1 + DataTableOffset], setid_to_modules, IncludeModuleDescriptions);

                // Set_Scheduled_Modules();

                // Link the folders to the builder module sets
                foreach (KeyValuePair <int, List <Builder_Module_Setting> > module in setid_to_modules)
                {
                    if (folder_to_set_dictionary.ContainsKey(module.Key))
                    {
                        List <Builder_Source_Folder> folders = folder_to_set_dictionary[module.Key];
                        foreach (Builder_Source_Folder thisFolder in folders)
                        {
                            thisFolder.Builder_Module_Set.Builder_Modules = module.Value;
                        }
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        /// <summary> Constructor for a new instance of the Builder_Modules class </summary>
        /// <param name="Settings"> Setting information </param>
        public Builder_Modules(Builder_Settings Settings)
        {
            settings = Settings;

            preProcessModules  = new List <iPreProcessModule>();
            processItemModules = new List <iSubmissionPackageModule>();
            deleteItemModules  = new List <iSubmissionPackageModule>();
            postProcessModules = new List <iPostProcessModule>();

            allFolderModules      = new List <iFolderModule>();
            AssemblyClassToModule = new Dictionary <string, iFolderModule>();
        }
        private static void Set_Builder_Folders(Builder_Settings SettingsObject, DataTable BuilderFoldersTable, Dictionary <int, List <Builder_Source_Folder> > FolderToSetDictionary)
        {
            SettingsObject.IncomingFolders.Clear();
            foreach (DataRow thisRow in BuilderFoldersTable.Rows)
            {
                Builder_Source_Folder newFolder = new Builder_Source_Folder
                {
                    IncomingFolderID          = Convert.ToInt32(thisRow["IncomingFolderId"]),
                    Folder_Name               = thisRow["FolderName"].ToString(),
                    Inbound_Folder            = thisRow["NetworkFolder"].ToString(),
                    Failures_Folder           = thisRow["ErrorFolder"].ToString(),
                    Processing_Folder         = thisRow["ProcessingFolder"].ToString(),
                    Perform_Checksum          = Convert.ToBoolean(thisRow["Perform_Checksum_Validation"]),
                    Archive_TIFFs             = Convert.ToBoolean(thisRow["Archive_TIFF"]),
                    Archive_All_Files         = Convert.ToBoolean(thisRow["Archive_All_Files"]),
                    Allow_Deletes             = Convert.ToBoolean(thisRow["Allow_Deletes"]),
                    Allow_Folders_No_Metadata = Convert.ToBoolean(thisRow["Allow_Folders_No_Metadata"]),
                    Allow_Metadata_Updates    = Convert.ToBoolean(thisRow["Allow_Metadata_Updates"]),
                    BibID_Roots_Restrictions  = thisRow["BibID_Roots_Restrictions"].ToString(),
                    Builder_Module_Set        = { SetID = Convert.ToInt32(thisRow["ModuleSetID"]), SetName = thisRow["SetName"].ToString() }
                };


                if ((thisRow["ModuleSetID"] != null) && (thisRow["ModuleSetID"].ToString().Length > 0))
                {
                    int id = Int32.Parse(thisRow["ModuleSetID"].ToString());
                    if (FolderToSetDictionary.ContainsKey(id))
                    {
                        FolderToSetDictionary[id].Add(newFolder);
                    }
                    else
                    {
                        FolderToSetDictionary[id] = new List <Builder_Source_Folder> {
                            newFolder
                        };
                    }
                }

                SettingsObject.IncomingFolders.Add(newFolder);
            }
        }
Example #4
0
        /// <summary> Gets the builder-specific settings, including all the builder modules and incoming folders </summary>
        /// <param name="Response"></param>
        /// <param name="UrlSegments"></param>
        /// <param name="QueryString"></param>
        /// <param name="Protocol"></param>
        /// <param name="IsDebug"></param>
        public void GetBuilderSettings(HttpResponse Response, List <string> UrlSegments, NameValueCollection QueryString, Microservice_Endpoint_Protocol_Enum Protocol, bool IsDebug)
        {
            Custom_Tracer tracer = new Custom_Tracer();

            // Should descriptions be suppressed?
            bool includeDescriptions = !((!String.IsNullOrEmpty(QueryString["IncludeDescs"])) && (QueryString["IncludeDescs"].ToUpper() == "FALSE"));

            try
            {
                tracer.Add_Trace("BuilderServices.GetBuilderSettings", "Pulling dataset from the database");

                // Get the dataset with all the builder settings
                DataSet builderSet = Engine_Database.Get_Builder_Settings(false, tracer);

                // If the returned value from the database was NULL, there was an error
                if ((builderSet == null) || (builderSet.Tables.Count == 0))
                {
                    Response.ContentType = "text/plain";
                    Response.Output.WriteLine("Error completing request");

                    if (IsDebug)
                    {
                        Response.Output.WriteLine("DataSet returned from the database was either NULL or empty");
                        if (Engine_Database.Last_Exception != null)
                        {
                            Response.Output.WriteLine();
                            Response.Output.WriteLine(Engine_Database.Last_Exception.Message);
                            Response.Output.WriteLine();
                            Response.Output.WriteLine(Engine_Database.Last_Exception.StackTrace);
                        }

                        Response.Output.WriteLine();
                        Response.Output.WriteLine(tracer.Text_Trace);
                    }

                    Response.StatusCode = 500;
                    return;
                }

                tracer.Add_Trace("BuilderServices.GetBuilderSettings", "Build the builder-specific settings object");
                Builder_Settings returnValue = new Builder_Settings();
                if (!Builder_Settings_Builder.Refresh(returnValue, builderSet, includeDescriptions, 0))
                {
                    Response.ContentType = "text/plain";
                    Response.Output.WriteLine("Error completing request");

                    if (IsDebug)
                    {
                        Response.Output.WriteLine("Error creating the Builder_Settings object from the database tables");
                        Response.Output.WriteLine();
                        Response.Output.WriteLine(tracer.Text_Trace);
                    }

                    Response.StatusCode = 500;
                    return;
                }

                // 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 = "parseBuilderSettings";
                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;
            }
        }
        private static void Set_NonScheduled_Modules(Builder_Settings SettingsObject, DataTable BuilderFoldersTable, Dictionary <int, List <Builder_Module_Setting> > SetidToModules, bool IncludeModuleDescriptions)
        {
            //DataColumn moduleIdColumn = BuilderFoldersTable.Columns["ModuleID"];
            DataColumn assemblyColumn = BuilderFoldersTable.Columns["Assembly"];
            DataColumn classColumn    = BuilderFoldersTable.Columns["Class"];
            DataColumn descColumn     = BuilderFoldersTable.Columns["ModuleDesc"];
            DataColumn args1Column    = BuilderFoldersTable.Columns["Argument1"];
            DataColumn args2Column    = BuilderFoldersTable.Columns["Argument2"];
            DataColumn args3Column    = BuilderFoldersTable.Columns["Argument3"];
            // DataColumn enabledColumn = BuilderFoldersTable.Columns["Enabled"];
            DataColumn setIdColumn = BuilderFoldersTable.Columns["ModuleSetID"];
            // DataColumn setNameColumn = BuilderFoldersTable.Columns["SetName"];
            // DataColumn setEnabledColumn = BuilderFoldersTable.Columns["SetEnabled"];
            DataColumn typeAbbrevColumn = BuilderFoldersTable.Columns["TypeAbbrev"];
            // DataColumn typeDescColumn = BuilderFoldersTable.Columns["TypeDescription"];


            int prevSetid = -1;
            Dictionary <int, List <Builder_Module_Setting> > folderSettings = new Dictionary <int, List <Builder_Module_Setting> >();

            foreach (DataRow thisRow in BuilderFoldersTable.Rows)
            {
                string type = thisRow[typeAbbrevColumn].ToString().ToUpper();

                Builder_Module_Setting newSetting = new Builder_Module_Setting
                {
                    Class = thisRow[classColumn].ToString()
                };
                if (thisRow[assemblyColumn] != DBNull.Value)
                {
                    newSetting.Assembly = thisRow[assemblyColumn].ToString();
                }
                if (thisRow[args1Column] != DBNull.Value)
                {
                    newSetting.Argument1 = thisRow[args1Column].ToString();
                }
                if (thisRow[args2Column] != DBNull.Value)
                {
                    newSetting.Argument2 = thisRow[args2Column].ToString();
                }
                if (thisRow[args3Column] != DBNull.Value)
                {
                    newSetting.Argument3 = thisRow[args3Column].ToString();
                }

                if (IncludeModuleDescriptions)
                {
                    if (thisRow[descColumn] != DBNull.Value)
                    {
                        newSetting.Description = thisRow[descColumn].ToString();
                    }
                }

                switch (type)
                {
                case "PRE":
                    SettingsObject.PreProcessModulesSettings.Add(newSetting);
                    break;

                case "POST":
                    SettingsObject.PostProcessModulesSettings.Add(newSetting);
                    break;

                case "NEW":
                    SettingsObject.ItemProcessModulesSettings.Add(newSetting);
                    break;

                case "DELT":
                    SettingsObject.ItemDeleteModulesSettings.Add(newSetting);
                    break;

                case "FOLD":
                    int setId = Int32.Parse(thisRow[setIdColumn].ToString());
                    if (SetidToModules.ContainsKey(setId))
                    {
                        SetidToModules[setId].Add(newSetting);
                    }
                    else
                    {
                        SetidToModules[setId] = new List <Builder_Module_Setting> {
                            newSetting
                        };
                    }
                    break;
                }
            }
        }
        /// <summary> Refresh the settings and item list from the database </summary>
        /// <returns> TRUE if successful, otherwise FALSE </returns>
        public bool Refresh_Settings_And_Item_List()
        {
            // Create the tracer for this
            Custom_Tracer tracer = new Custom_Tracer();

            // Disable the cache
            CachedDataManager.Settings.Disabled = true;

            // Set all the database strings appropriately
            Engine_Database.Connection_String       = instanceInfo.DatabaseConnection.Connection_String;
            SobekCM_Item_Database.Connection_String = instanceInfo.DatabaseConnection.Connection_String;

            // Get the settings values directly from the database
            settings = InstanceWide_Settings_Builder.Build_Settings(instanceInfo.DatabaseConnection);
            if (settings == null)
            {
                Add_Error_To_Log("Unable to pull the newest settings from the database", String.Empty, String.Empty, -1);
                return(false);
            }

            // If this was not refreshed yet, ensure [BASEURL] is replaced
            if (!refreshed)
            {
                // Determine the base url
                string baseUrl = String.IsNullOrWhiteSpace(settings.Servers.Base_URL) ? settings.Servers.Application_Server_URL : settings.Servers.Base_URL;
                List <MicroservicesClient_Endpoint> endpoints = instanceInfo.Microservices.Endpoints;
                foreach (MicroservicesClient_Endpoint thisEndpoint in endpoints)
                {
                    if (thisEndpoint.URL.IndexOf("[BASEURL]") > 0)
                    {
                        thisEndpoint.URL = thisEndpoint.URL.Replace("[BASEURL]", baseUrl).Replace("//", "/").Replace("http:/", "http://").Replace("https:/", "https://");
                    }
                    else if ((thisEndpoint.URL.IndexOf("http:/") < 0) && (thisEndpoint.URL.IndexOf("https:/") < 0))
                    {
                        thisEndpoint.URL = (baseUrl + thisEndpoint.URL).Replace("//", "/").Replace("http:/", "http://").Replace("https:/", "https://");
                    }
                }
                refreshed = true;
            }

            // Set the microservice endpoints
            SobekEngineClient.Set_Endpoints(instanceInfo.Microservices);

            // Load the necessary configuration objects into the engine application cache gateway
            try
            {
                Engine_ApplicationCache_Gateway.Configuration.OAI_PMH = SobekEngineClient.Admin.Get_OAI_PMH_Configuration(tracer);
            }
            catch (Exception ee)
            {
                Add_Error_To_Log("Unable to pull the OAI-PMH settings from the engine", String.Empty, String.Empty, -1);
                Add_Error_To_Log(ee.Message, String.Empty, String.Empty, -1);
                return(false);
            }

            try
            {
                Engine_ApplicationCache_Gateway.Configuration.Metadata = SobekEngineClient.Admin.Get_Metadata_Configuration(tracer);
            }
            catch (Exception ee)
            {
                Add_Error_To_Log("Unable to pull the metadata settings from the engine", String.Empty, String.Empty, -1);
                Add_Error_To_Log(ee.Message, String.Empty, String.Empty, -1);
                return(false);
            }

            try
            {
                Engine_ApplicationCache_Gateway.Configuration.Extensions = SobekEngineClient.Admin.Get_Extensions_Configuration(tracer);
            }
            catch (Exception ee)
            {
                Add_Error_To_Log("Unable to pull the extension settings from the engine", String.Empty, String.Empty, -1);
                Add_Error_To_Log(ee.Message, String.Empty, String.Empty, -1);
                return(false);
            }


            // Check for any enabled extensions with assemblies
            ResourceObjectSettings.Clear_Assemblies();
            try
            {
                if ((Engine_ApplicationCache_Gateway.Configuration.Extensions.Extensions != null) && (Engine_ApplicationCache_Gateway.Configuration.Extensions.Extensions.Count > 0))
                {
                    // Step through each extension
                    foreach (ExtensionInfo extensionInfo in Engine_ApplicationCache_Gateway.Configuration.Extensions.Extensions)
                    {
                        // If not enabled, skip it
                        if (!extensionInfo.Enabled)
                        {
                            continue;
                        }

                        // Look for assemblies
                        if ((extensionInfo.Assemblies != null) && (extensionInfo.Assemblies.Count > 0))
                        {
                            // Step through each assembly
                            foreach (ExtensionAssembly assembly in extensionInfo.Assemblies)
                            {
                                // Find the relative file name
                                if (assembly.FilePath.IndexOf("plugins", StringComparison.OrdinalIgnoreCase) > 0)
                                {
                                    // Determine the network way to get there
                                    string from_plugins        = assembly.FilePath.Substring(assembly.FilePath.IndexOf("plugins", StringComparison.OrdinalIgnoreCase));
                                    string network_plugin_file = Path.Combine(settings.Servers.Application_Server_Network, from_plugins);

                                    // Get the plugin filename
                                    string plugin_filename = Path.GetFileName(assembly.FilePath);

                                    // Does this local plugin directory exist for this extension?
                                    string local_path = Path.Combine(pluginRootDirectory, instanceInfo.Name, extensionInfo.Code);
                                    if (!Directory.Exists(local_path))
                                    {
                                        try
                                        {
                                            Directory.CreateDirectory(local_path);
                                        }
                                        catch (Exception ee)
                                        {
                                            Add_Error_To_Log("Error creating the necessary plug-in subdirectory", String.Empty, String.Empty, -1);
                                            Add_Error_To_Log(ee.Message, String.Empty, String.Empty, -1);
                                            return(false);
                                        }
                                    }

                                    // Determine if the assembly is here
                                    string local_file = Path.Combine(local_path, plugin_filename);
                                    if (!File.Exists(local_file))
                                    {
                                        File.Copy(network_plugin_file, local_file);
                                    }
                                    else
                                    {
                                        // Do a date check
                                        DateTime webFileDate   = File.GetLastWriteTime(network_plugin_file);
                                        DateTime localFileDate = File.GetLastWriteTime(local_file);

                                        if (webFileDate.CompareTo(localFileDate) > 0)
                                        {
                                            File.Copy(network_plugin_file, local_file, true);
                                        }
                                    }

                                    // Also, point the assembly to use the local file
                                    assembly.FilePath = local_file;
                                }
                            }
                        }
                    }

                    // Now, also set this all in the metadata portion
                    // Copy over all the extension information
                    foreach (ExtensionInfo thisExtension in Engine_ApplicationCache_Gateway.Configuration.Extensions.Extensions)
                    {
                        if ((thisExtension.Enabled) && (thisExtension.Assemblies != null))
                        {
                            foreach (ExtensionAssembly thisAssembly in thisExtension.Assemblies)
                            {
                                ResourceObjectSettings.Add_Assembly(thisAssembly.ID, thisAssembly.FilePath);
                            }
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                Add_Error_To_Log("Unable to copy the extension files from the web", String.Empty, String.Empty, -1);
                Add_Error_To_Log(ee.Message, String.Empty, String.Empty, -1);
                return(false);
            }

            // Finalize the metadata config
            Engine_ApplicationCache_Gateway.Configuration.Metadata.Finalize_Metadata_Configuration();

            // Set the metadata preferences for writing
            ResourceObjectSettings.MetadataConfig = Engine_ApplicationCache_Gateway.Configuration.Metadata;

            // Also, load the builder configuration this way
            try
            {
                builderSettings = SobekEngineClient.Builder.Get_Builder_Settings(false, tracer);
            }
            catch (Exception ee)
            {
                Add_Error_To_Log("Unable to pull the builder settings from the engine", String.Empty, String.Empty, -1);
                Add_Error_To_Log(ee.Message, String.Empty, String.Empty, -1);
                return(false);
            }


            // Build the modules
            builderModules = new Builder_Modules(builderSettings);
            List <string> errors = builderModules.Builder_Modules_From_Settings(instanceInfo.Name);

            if ((errors != null) && (errors.Count > 0))
            {
                long logId = Add_Error_To_Log("Error(s) builder the modules from the settings", String.Empty, String.Empty, -1);
                foreach (string thisError in errors)
                {
                    Add_Error_To_Log(thisError, String.Empty, String.Empty, logId);
                }
                return(false);
            }

            // Add the event listeners
            foreach (iPreProcessModule thisModule in builderModules.PreProcessModules)
            {
                thisModule.Error   += module_Error;
                thisModule.Process += module_Process;
            }
            foreach (iSubmissionPackageModule thisModule in builderModules.DeleteItemModules)
            {
                thisModule.Error   += module_Error;
                thisModule.Process += module_Process;
            }
            foreach (iSubmissionPackageModule thisModule in builderModules.ItemProcessModules)
            {
                thisModule.Error   += module_Error;
                thisModule.Process += module_Process;
            }
            foreach (iPostProcessModule thisModule in builderModules.PostProcessModules)
            {
                thisModule.Error   += module_Error;
                thisModule.Process += module_Process;
            }
            foreach (iFolderModule thisModule in builderModules.AllFolderModules)
            {
                thisModule.Error   += module_Error;
                thisModule.Process += module_Process;
            }

            return(true);
        }