JSON Serialization and Deserialization Assistant Class
示例#1
0
        public static void OverwriteSystemProxySettings(Dictionary <string, object> currentSettings)
        {
            if ((int)currentSettings["proxySettingsPolicy"] == 1)
            {
                return;
            }
            IWebProxy systemWebProxy = WebRequest.GetSystemWebProxy();
            string    remoteAddress1 = "http://www.janison.com.au";
            string    keyEnable1     = "HTTPEnable";
            string    keyHost1       = "HTTPProxy";
            string    keyPort1       = "HTTPPort";
            bool      flag1          = SEBXulRunnerSettings.UpdateProxySettings(systemWebProxy, remoteAddress1, keyEnable1, keyHost1, keyPort1);
            string    remoteAddress2 = "https://www.janison.com.au";
            string    keyEnable2     = "HTTPSEnable";
            string    keyHost2       = "HTTPSProxy";
            string    keyPort2       = "HTTPSPort";
            bool      flag2          = SEBXulRunnerSettings.UpdateProxySettings(systemWebProxy, remoteAddress2, keyEnable2, keyHost2, keyPort2);

            if (flag1 | flag2)
            {
                currentSettings["proxySettingsPolicy"] = (object)1;
            }
            else
            {
                currentSettings["proxySettingsPolicy"] = (object)0;
            }
        }
示例#2
0
        /// <summary>
        /// Sets properties in config.json XULRunner configuration file.
        /// </summary>
        /// <returns></returns>
        public static bool SetXulRunnerConfiguration()
        {
            bool setXulRunnerConfiguration = false;

            try
            {
                // Get the path of the "Program Data" directory.
                string localAppDataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                //string programDataDirectory = Environment.GetEnvironmentVariable("PROGRAMMDATA");

                // Set the location of the XULRunnerConfigFileDirectory
                StringBuilder xulRunnerConfigFileDirectoryBuilder = new StringBuilder(localAppDataDirectory).Append("\\").Append(MANUFACTURER_LOCAL).Append("\\");  //.Append(PRODUCT_NAME).Append("\\");
                XulRunnerConfigFileDirectory = xulRunnerConfigFileDirectoryBuilder.ToString();

                // Set the location of the config.json file
                StringBuilder xulRunnerConfigFileBuilder = new StringBuilder(XulRunnerConfigFileDirectory).Append(XUL_RUNNER_CONFIG);
                XulRunnerConfigFile = xulRunnerConfigFileBuilder.ToString();

                XULRunnerConfig xulRunnerConfig = SEBXulRunnerSettings.XULRunnerConfigDeserialize(XulRunnerConfigFile);
                xulRunnerConfig.seb_openwin_width  = Int32.Parse(SEBClientInfo.getSebSetting(SEBSettings.KeyNewBrowserWindowByLinkWidth)[SEBSettings.KeyNewBrowserWindowByLinkWidth].ToString());
                xulRunnerConfig.seb_openwin_height = Int32.Parse(SEBClientInfo.getSebSetting(SEBSettings.KeyNewBrowserWindowByLinkHeight)[SEBSettings.KeyNewBrowserWindowByLinkHeight].ToString());
                if ((Int32)SEBClientInfo.getSebSetting(SEBSettings.KeyBrowserViewMode)[SEBSettings.KeyBrowserViewMode] == (int)browserViewModes.browserViewModeWindow)
                {
                    xulRunnerConfig.seb_mainWindow_titlebar_enabled = true;
                }
                else
                {
                    xulRunnerConfig.seb_mainWindow_titlebar_enabled = false;
                }
                xulRunnerConfig.seb_url   = SEBClientInfo.getSebSetting(SEBSettings.KeyStartURL)[SEBSettings.KeyStartURL].ToString();
                setXulRunnerConfiguration = true;
                SEBXulRunnerSettings.XULRunnerConfigSerialize(xulRunnerConfig, XulRunnerConfigFile);
            }
            catch (Exception ex)
            {
                Logger.AddError("Error ocurred by setting XulRunner configuration.", null, ex, ex.Message);
            }

            return(setXulRunnerConfiguration);
        }
        public static bool SetXulRunnerConfiguration()
        {
            bool flag = false;

            try
            {
                SEBClientInfo.XulRunnerConfigFileDirectory = new StringBuilder(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)).Append("\\").Append("SafeExamBrowser").Append("\\").ToString();
                SEBClientInfo.XulRunnerConfigFile          = new StringBuilder(SEBClientInfo.XulRunnerConfigFileDirectory).Append("config.json").ToString();
                XULRunnerConfig objXULRunnerConfig = SEBXulRunnerSettings.XULRunnerConfigDeserialize(SEBClientInfo.XulRunnerConfigFile);
                objXULRunnerConfig.seb_openwin_width  = int.Parse(SEBClientInfo.getSebSetting("newBrowserWindowByLinkWidth")["newBrowserWindowByLinkWidth"].ToString());
                objXULRunnerConfig.seb_openwin_height = int.Parse(SEBClientInfo.getSebSetting("newBrowserWindowByLinkHeight")["newBrowserWindowByLinkHeight"].ToString());
                objXULRunnerConfig.seb_mainWindow_titlebar_enabled = (int)SEBClientInfo.getSebSetting("browserViewMode")["browserViewMode"] == 0;
                objXULRunnerConfig.seb_url = SEBClientInfo.getSebSetting("startURL")["startURL"].ToString();
                flag = true;
                SEBXulRunnerSettings.XULRunnerConfigSerialize(objXULRunnerConfig, SEBClientInfo.XulRunnerConfigFile);
            }
            catch (Exception ex)
            {
                Logger.AddError("Error ocurred by setting XulRunner configuration.", (object)null, ex, ex.Message);
            }
            return(flag);
        }
示例#4
0
        public static string XULRunnerConfigDictionarySerialize(Dictionary <string, object> xulRunnerSettings)
        {
            if ((bool)xulRunnerSettings["sendBrowserExamKey"])
            {
                string browserExamKey = SEBProtectionController.ComputeBrowserExamKey();
                xulRunnerSettings["browserExamKey"] = (object)browserExamKey;
                xulRunnerSettings["browserURLSalt"] = (object)true;
            }
            xulRunnerSettings["startURL"] = (object)SEBXulRunnerSettings.ResolveResourceUrl((string)xulRunnerSettings["startURL"]);
            SEBXulRunnerSettings.OverwriteSystemProxySettings(xulRunnerSettings);
            if ((bool)SEBSettings.settingsCurrent["restartExamUseStartURL"])
            {
                xulRunnerSettings["restartExamURL"] = xulRunnerSettings["startURL"];
            }
            if (!(bool)xulRunnerSettings["URLFilterEnable"])
            {
                xulRunnerSettings["blacklistURLFilter"] = (object)"";
                xulRunnerSettings["whitelistURLFilter"] = (object)"";
            }
            else
            {
                xulRunnerSettings["urlFilterTrustedContent"] = (object)(bool)xulRunnerSettings["URLFilterEnableContentFilter"];
                if (!xulRunnerSettings["whitelistURLFilter"].ToString().Contains(xulRunnerSettings["startURL"].ToString()) && !string.IsNullOrWhiteSpace(xulRunnerSettings["whitelistURLFilter"].ToString()))
                {
                    Dictionary <string, object> dictionary = xulRunnerSettings;
                    dictionary["whitelistURLFilter"] = (object)(dictionary["whitelistURLFilter"].ToString() + ";");
                }
                Dictionary <string, object> dictionary1 = xulRunnerSettings;
                dictionary1["whitelistURLFilter"] = (object)(dictionary1["whitelistURLFilter"].ToString() + xulRunnerSettings["startURL"].ToString());
                if ((bool)xulRunnerSettings["URLFilterEnableContentFilter"])
                {
                    if (!string.IsNullOrWhiteSpace(xulRunnerSettings["whitelistURLFilter"].ToString()))
                    {
                        Dictionary <string, object> dictionary2 = xulRunnerSettings;
                        dictionary2["whitelistURLFilter"] = (object)(dictionary2["whitelistURLFilter"].ToString() + ";");
                    }
                    Dictionary <string, object> dictionary3 = xulRunnerSettings;
                    dictionary3["whitelistURLFilter"] = (object)(dictionary3["whitelistURLFilter"].ToString() + string.Format("http://{0}", (object)SEBXULRunnerWebSocketServer.ServerAddress.Substring(5)));
                }
            }
            xulRunnerSettings["browserMessagingSocket"] = (object)SEBXULRunnerWebSocketServer.ServerAddress;
            Logger.AddInformation("Socket: " + xulRunnerSettings["browserMessagingSocket"].ToString(), (object)null, (Exception)null, (string)null);
            string str = Environment.ExpandEnvironmentVariables((string)xulRunnerSettings["downloadDirectoryWin"]);

            xulRunnerSettings["downloadDirectoryWin"] = (object)str;
            if ((bool)xulRunnerSettings["touchOptimized"])
            {
                xulRunnerSettings["showReloadWarning"] = (object)false;
                xulRunnerSettings["taskBarHeight"]     = (object)(int)Math.Round((double)(int)xulRunnerSettings["taskBarHeight"] * 1.7);
                if ((int)xulRunnerSettings["browserUserAgentWinTouchMode"] == 0)
                {
                    xulRunnerSettings["browserUserAgent"] = (object)"Mozilla/5.0 (Windows NT 6.3; rv:41.0; Touch) Gecko/20100101 Firefox/41";
                }
                else if ((int)xulRunnerSettings["browserUserAgentWinTouchMode"] == 1)
                {
                    xulRunnerSettings["browserUserAgent"] = (object)"Mozilla/5.0 (iPad; CPU OS 9_0_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13A452 Safari/601.1";
                }
                else if ((int)xulRunnerSettings["browserUserAgentWinTouchMode"] == 2)
                {
                    xulRunnerSettings["browserUserAgent"] = xulRunnerSettings["browserUserAgentWinTouchModeCustom"];
                }
            }
            else if ((int)xulRunnerSettings["browserUserAgentWinDesktopMode"] == 0)
            {
                OperatingSystem osVersion = Environment.OSVersion;
                xulRunnerSettings["browserUserAgent"] = (object)string.Format("Mozilla/5.0 (Windows NT {0}.{1}; rv:41.0) Gecko/20100101 Firefox/41", (object)osVersion.Version.Major, (object)osVersion.Version.Minor);
            }
            else
            {
                xulRunnerSettings["browserUserAgent"] = xulRunnerSettings["browserUserAgentWinDesktopModeCustom"];
            }
            Dictionary <string, object> dictionary4 = xulRunnerSettings;

            dictionary4["browserUserAgent"]            = (object)(dictionary4["browserUserAgent"].ToString() + " SEB " + Application.ProductVersion);
            xulRunnerSettings["browserScreenKeyboard"] = (object)(bool)xulRunnerSettings["touchOptimized"];
            return(Convert.ToBase64String(Encoding.UTF8.GetBytes(new JavaScriptSerializer().Serialize((object)xulRunnerSettings))));
        }
示例#5
0
 public static string ResolveResourceUrl(string path)
 {
     return(string.Format("file:///{0}", (object)SEBXulRunnerSettings.ResolveResourcePath(path)));
 }