Ejemplo n.º 1
0
        public static void Script_CreateOrUpdate(string name, string scriptOrUrl, string location, int order, string description)
        {
            if (name.IsNullOrEmpty())
            {
                throw new Exception("The script name cannot be empty");
            }
            if (order < 0)
            {
                throw new Exception("'{0}' is not a valid script order (must be greater or equal to 0)".F(order));
            }
            if (ScriptLocations.IndexOf(location) == -1)
            {
                throw new Exception("'{0}' is not a valid script location".F(location));
            }


            bool isUrl = Uri.IsWellFormedUriString(scriptOrUrl, UriKind.RelativeOrAbsolute);

            AppInfo info = AppInfo.GetAppInfo();

            if (info != null)
            {
                info.CheckPlatformExtensibilityAPIs();

                using (Transaction tran = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) {
                    DBRuntimePlatform.Instance.Script_CreateOrUpdate(tran, name, isUrl ? scriptOrUrl : "", isUrl ? "" : scriptOrUrl, location, order, description);
                    info.InvalidateInjectionCache();
                }
            }
        }
Ejemplo n.º 2
0
        public static void Script_DisableScriptInScreen(string scriptName)
        {
            AppInfo info = AppInfo.GetAppInfo();

            if (info != null)
            {
                info.CheckPlatformExtensibilityAPIs();
                info.OsContext.AddDisabledScript(scriptName ?? "");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Set the Connection String for a specific Database Connection to be applied in the current Session.
 ///
 /// - This method will not affect queries in the current request if the connection was already used.
 /// - The target database must have the same type as configured in Service Center (e.g. Oracle, SQL Server, MySQL).
 /// - Requires the Platform Extensibility APIs Feature.
 /// </summary>
 /// <param name="connectionName">Name of the Database Connection</param>
 /// <param name="connectionString">Connection String to use</param>
 /// <param name="databaseIdentifier">The initial database to use (effective only for Oracle databases, indicating the schema to be initialy used)</param>
 public static void SetConnectionStringForSession(string connectionName, string connectionString, string databaseIdentifier)
 {
     if (HttpContext.Current != null)
     {
         AppInfo info = AppInfo.GetAppInfo();
         if (info != null)
         {
             info.CheckPlatformExtensibilityAPIs();
             info.OsContext.Session.SetDatabaseConnectionOverride(connectionName, connectionString, databaseIdentifier.IsEmpty() ? null : databaseIdentifier);
         }
     }
 }
Ejemplo n.º 4
0
        public static void Script_Activate(string scriptName)
        {
            AppInfo info = AppInfo.GetAppInfo();

            if (info != null)
            {
                info.CheckPlatformExtensibilityAPIs();

                using (Transaction tran = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) {
                    DBRuntimePlatform.Script_Activate(tran, scriptName);
                    info.InvalidateInjectionCache();
                }
            }
        }
Ejemplo n.º 5
0
        public static void Script_List(bool showInactive, out List <JavaScript> scripts)
        {
            AppInfo info = AppInfo.GetAppInfo();

            scripts = null;
            if (info != null)
            {
                info.CheckPlatformExtensibilityAPIs();

                using (Transaction tran = DatabaseAccess.ForSystemDatabase.GetReadOnlyTransaction()) {
                    scripts = new List <JavaScript>();
                    List <string> excludedAppKeys = new List <string>(); // to ignore duplicated applications (due to different espaces)

                    //temp variables for the "Reader" iteration
                    int        currentReadingScript = -1;
                    JavaScript currentScript        = null;

                    using (IDataReader reader = DBRuntimePlatform.Instance.Script_List(tran, showInactive)) {
                        while (reader.Read())
                        {
                            int tempScriptId = reader.SafeGet <int>("ID");

                            //checks if we are in a new script
                            if (currentReadingScript != tempScriptId)     //we are in a new application

                            {
                                currentReadingScript = tempScriptId; //updates the current script ID
                                currentScript        = JavaScript.CreateFromReader(reader);
                                scripts.Add(currentScript);
                                excludedAppKeys = new List <string>();
                            }
                            string applicationKey = reader.SafeGet <string>("APPLICATIONKEY");
                            string appName        = reader.SafeGet <string>("APPNAME");
                            string eSpaceKey      = reader.SafeGet <string>("ESPACEKEY");
                            string eSpaceName     = reader.SafeGet <string>("ESPACENAME");
                            if (currentScript != null && applicationKey != null && appName != null && !excludedAppKeys.Contains(applicationKey))   //there are excluded applications
                            {
                                excludedAppKeys.Add(applicationKey);
                                currentScript.AddAppExclusion(applicationKey, appName);
                            }

                            if (currentScript != null && eSpaceKey != null && eSpaceName != null)
                            {
                                currentScript.AddEspaceExclusion(eSpaceKey, eSpaceName);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void Script_Get(string scriptName, out JavaScript script)
        {
            AppInfo info = AppInfo.GetAppInfo();

            script = null;
            if (info != null)
            {
                info.CheckPlatformExtensibilityAPIs();

                using (Transaction tran = DatabaseAccess.ForSystemDatabase.GetReadOnlyTransaction()) {
                    List <string> excludedAppKeys = new List <string>(); // to ignore duplicated applications (due to different espaces)

                    using (IDataReader reader = DBRuntimePlatform.Instance.Script_Get(tran, scriptName)) {
                        while (reader.Read())
                        {
                            if (script == null)
                            {
                                script = JavaScript.CreateFromReader(reader);
                            }
                            string applicationKey = reader.SafeGet <string>("APPLICATIONKEY");
                            string appName        = reader.SafeGet <string>("APPNAME");
                            string eSpaceKey      = reader.SafeGet <string>("ESPACEKEY");
                            string eSpaceName     = reader.SafeGet <string>("ESPACENAME");

                            if (applicationKey != null && appName != null && !excludedAppKeys.Contains(applicationKey))   //there are excluded applications
                            {
                                excludedAppKeys.Add(applicationKey);
                                script.AddAppExclusion(applicationKey, appName);
                            }

                            if (eSpaceKey != null && eSpaceName != null)
                            {
                                script.AddEspaceExclusion(eSpaceKey, eSpaceName);
                            }
                        }

                        if (script == null)   //could not find given script
                        {
                            script = new JavaScript();
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static void Script_AddEspaceExclusion(string scriptName, string eSpaceKey)
        {
            AppInfo info = AppInfo.GetAppInfo();

            if (info != null)
            {
                info.CheckPlatformExtensibilityAPIs();

                using (Transaction tran = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) {
                    int scriptId = DBRuntimePlatform.Script_GetId(tran, scriptName);
                    if (scriptId == 0)
                    {
                        return;
                    }
                    DBRuntimePlatform.Instance.Script_AddEspaceExclusion(tran, scriptId, eSpaceKey);
                    info.InvalidateInjectionCache();
                }
            }
        }