public void Reload(XElement element)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            BrowserSourceSettings   = AbstractSettings.DeepClone(BrowserSettings.Instance.SourceSettings);
            BrowserInstanceSettings = AbstractSettings.DeepClone(BrowserSettings.Instance.InstanceSettings);

            String instanceSettingsString = element.GetString("instanceSettings");
            String sourceSettingsString   = element.GetString("sourceSettings");

            if (sourceSettingsString != null && sourceSettingsString.Count() > 0)
            {
                try
                {
                    BrowserSourceSettings = serializer.Deserialize <BrowserSourceSettings>(sourceSettingsString);
                }
                catch (ArgumentException e)
                {
                    API.Instance.Log("Failed to deserialized source settings and forced to recreate; {0}", e.Message);
                }
            }

            if (instanceSettingsString != null && instanceSettingsString.Count() > 0)
            {
                BrowserInstanceSettings.MergeWith(serializer.Deserialize <BrowserInstanceSettings>(instanceSettingsString));
            }
        }
Exemple #2
0
        public void Reload(XElement element)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            BrowserSourceSettings   = AbstractSettings.DeepClone(BrowserSettings.Instance.SourceSettings);
            BrowserInstanceSettings = AbstractSettings.DeepClone(BrowserSettings.Instance.InstanceSettings);

            try
            {
                byte[] instanceSettingsBytes = Convert.FromBase64String(
                    element.GetString("instanceSettings"));
                byte[] sourceSettingsBytes = Convert.FromBase64String(
                    element.GetString("sourceSettings"));

                string instanceSettingsString = Encoding.UTF8.GetString(
                    instanceSettingsBytes);

                string sourceSettingsString = Encoding.UTF8.GetString(
                    sourceSettingsBytes);

                if (sourceSettingsString != null && sourceSettingsString.Count() > 0)
                {
                    MemoryStream stream = new MemoryStream(
                        Encoding.UTF8.GetBytes(sourceSettingsString));

                    DataContractJsonSerializer ser =
                        new DataContractJsonSerializer(
                            typeof(BrowserSourceSettings));

                    BrowserSourceSettings = ser.ReadObject(stream)
                                            as BrowserSourceSettings;
                }
                //overiding source setting
                BrowserSourceSettings.Width   = Int32.Parse(element.GetString("width"));
                BrowserSourceSettings.Height  = Int32.Parse(element.GetString("height"));
                BrowserSourceSettings.Url     = "about:blank";
                BrowserSourceSettings.LoadUrl = element.GetString("url");

                if (instanceSettingsString != null && instanceSettingsString.Count() > 0)
                {
                    BrowserInstanceSettings.MergeWith(serializer.Deserialize <BrowserInstanceSettings>(instanceSettingsString));

                    try
                    {
                        MemoryStream stream = new MemoryStream(
                            Encoding.UTF8.GetBytes(instanceSettingsString));

                        DataContractJsonSerializer ser =
                            new DataContractJsonSerializer(
                                typeof(BrowserInstanceSettings));
                        BrowserInstanceSettings serializedSettings =
                            ser.ReadObject(stream) as BrowserInstanceSettings;

                        BrowserInstanceSettings.MergeWith(serializedSettings);
                    }
                    catch (Exception e)
                    {
                        API.Instance.Log(
                            "Failed to deserialized source settings and forced to recreate");
                        API.Instance.Log("Exception: {0}", e);
                    }
                }
            }
            catch (Exception e)
            {
                API.Instance.Log(
                    "Failed to deserialized source settings and forced to recreate");
                API.Instance.Log("Exception: {0}", e);
            }
        }