Inheritance: IBrowserDecorator
示例#1
0
        /*
         *   browserDecorators are a collection of plugin-like classes (IBrowserDecorator) that add some bit of functionality to the browser.
         *   These are somewhat different than plugins in that they are usually not async and patch a browser feature that we would
         *   already expect to have.  Essentially these are browser polyfills that are patched from the outside in.
         * */
        void CreateDecorators()
        {
            XHRHelper xhrProxy = new XHRHelper();

            xhrProxy.Browser = CordovaBrowser;
            browserDecorators.Add("XHRLOCAL", xhrProxy);

            OrientationHelper orientHelper = new OrientationHelper();

            orientHelper.Browser = CordovaBrowser;
            browserDecorators.Add("Orientation", orientHelper);

            DOMStorageHelper storageHelper = new DOMStorageHelper();

            storageHelper.Browser = CordovaBrowser;
            browserDecorators.Add("DOMStorage", storageHelper);

            ConsoleHelper console = new ConsoleHelper();

            console.Browser = CordovaBrowser;
            browserDecorators.Add("ConsoleLog", console);
        }
示例#2
0
        void GapBrowser_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            // prevents refreshing web control to initial state during pages transitions
            if (this.IsBrowserInitialized) return;

            this.domStorageHelper = new DOMStorageHelper(this.CordovaBrowser);

            try
            {

                // Before we possibly clean the ISO-Store, we need to grab our generated UUID, so we can rewrite it after.
                string deviceUUID = "";

                using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    try
                    {
                        IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage);

                        using (StreamReader reader = new StreamReader(fileStream))
                        {
                            deviceUUID = reader.ReadLine();
                        }
                    }
                    catch (Exception /*ex*/)
                    {
                        deviceUUID = Guid.NewGuid().ToString();
                    }

                    Debug.WriteLine("Updating IsolatedStorage for APP:DeviceID :: " + deviceUUID);
                    IsolatedStorageFileStream file = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Create, FileAccess.Write, appStorage);
                    using (StreamWriter writeFile = new StreamWriter(file))
                    {
                        writeFile.WriteLine(deviceUUID);
                        writeFile.Close();
                    }

                }

                StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("CordovaSourceDictionary.xml", UriKind.Relative));

                if (streamInfo != null)
                {
                    StreamReader sr = new StreamReader(streamInfo.Stream);
                    //This will Read Keys Collection for the xml file

                    XDocument document = XDocument.Parse(sr.ReadToEnd());

                    var files = from results in document.Descendants("FilePath")
                                select new
                                {
                                    path = (string)results.Attribute("Value")
                                };
                    StreamResourceInfo fileResourceStreamInfo;

                    using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
                    {

                        foreach (var file in files)
                        {
                            fileResourceStreamInfo = Application.GetResourceStream(new Uri(file.path, UriKind.Relative));

                            if (fileResourceStreamInfo != null)
                            {
                                using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
                                {
                                    byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);

                                    string strBaseDir = AppRoot + file.path.Substring(0, file.path.LastIndexOf(System.IO.Path.DirectorySeparatorChar));

                                    if (!appStorage.DirectoryExists(strBaseDir))
                                    {
                                        Debug.WriteLine("INFO: Creating Directory :: " + strBaseDir);
                                        appStorage.CreateDirectory(strBaseDir);
                                    }

                                    // This will truncate/overwrite an existing file, or
                                    using (IsolatedStorageFileStream outFile = appStorage.OpenFile(AppRoot + file.path, FileMode.Create))
                                    {
                                        Debug.WriteLine("INFO: Writing data for " + AppRoot + file.path + " and length = " + data.Length);
                                        using (var writer = new BinaryWriter(outFile))
                                        {
                                            writer.Write(data);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Debug.WriteLine("ERROR: Failed to write file :: " + file.path + " did you forget to add it to the project?");
                            }
                        }
                    }
                }

                CordovaBrowser.Navigate(StartPageUri);
                IsBrowserInitialized = true;
                AttachHardwareButtonHandlers();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ERROR: Exception in GapBrowser_Loaded :: {0}", ex.Message);
            }
        }
示例#3
0
        /*
         *   browserDecorators are a collection of plugin-like classes (IBrowserDecorator) that add some bit of functionality to the browser.
         *   These are somewhat different than plugins in that they are usually not async and patch a browser feature that we would
         *   already expect to have.  Essentially these are browser polyfills that are patched from the outside in.
         * */
        void CreateDecorators()
        {
            XHRHelper xhrProxy = new XHRHelper();
            xhrProxy.Browser = CordovaBrowser;
            browserDecorators.Add("XHRLOCAL", xhrProxy);

            OrientationHelper orientHelper = new OrientationHelper();
            orientHelper.Browser = CordovaBrowser;
            browserDecorators.Add("Orientation", orientHelper);

            DOMStorageHelper storageHelper = new DOMStorageHelper();
            storageHelper.Browser = CordovaBrowser;
            browserDecorators.Add("DOMStorage", storageHelper);

            ConsoleHelper console = new ConsoleHelper();
            console.Browser = CordovaBrowser;
            browserDecorators.Add("ConsoleLog", console);
        }
示例#4
0
        void GapBrowser_Loaded(object sender, RoutedEventArgs e)
        {
            this.bmHelper.ScrollDisabled = this.DisableBouncyScrolling;

            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            // prevents refreshing web control to initial state during pages transitions
            if (this.IsBrowserInitialized)
            {
                return;
            }



            this.domStorageHelper = new DOMStorageHelper(this.CordovaBrowser);

            try
            {
                // Before we possibly clean the ISO-Store, we need to grab our generated UUID, so we can rewrite it after.
                string deviceUUID = "";

                using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    try
                    {
                        IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage);

                        using (StreamReader reader = new StreamReader(fileStream))
                        {
                            deviceUUID = reader.ReadLine();
                        }
                    }
                    catch (Exception /*ex*/)
                    {
                        deviceUUID = Guid.NewGuid().ToString();
                    }

                    Debug.WriteLine("Updating IsolatedStorage for APP:DeviceID :: " + deviceUUID);
                    IsolatedStorageFileStream file = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Create, FileAccess.Write, appStorage);
                    using (StreamWriter writeFile = new StreamWriter(file))
                    {
                        writeFile.WriteLine(deviceUUID);
                        writeFile.Close();
                    }
                }

                /*
                 * 11/08/12 Ruslan Kokorev
                 * Copying files to isolated storage is no more required in WP8. WebBrowser control now works with files located in XAP.
                 */
                //StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("CordovaSourceDictionary.xml", UriKind.Relative));

                //if (streamInfo != null)
                //{
                //    StreamReader sr = new StreamReader(streamInfo.Stream);
                //    //This will Read Keys Collection for the xml file

                //    XDocument document = XDocument.Parse(sr.ReadToEnd());

                //    var files = from results in document.Descendants("FilePath")
                //                select new
                //                {
                //                    path = (string)results.Attribute("Value")
                //                };
                //    StreamResourceInfo fileResourceStreamInfo;

                //    using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
                //    {

                //        foreach (var file in files)
                //        {
                //            fileResourceStreamInfo = Application.GetResourceStream(new Uri(file.path, UriKind.Relative));

                //            if (fileResourceStreamInfo != null)
                //            {
                //                using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
                //                {
                //                    byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);

                //                    string strBaseDir = AppRoot + file.path.Substring(0, file.path.LastIndexOf(System.IO.Path.DirectorySeparatorChar));

                //                    if (!appStorage.DirectoryExists(strBaseDir))
                //                    {
                //                        Debug.WriteLine("INFO: Creating Directory :: " + strBaseDir);
                //                        appStorage.CreateDirectory(strBaseDir);
                //                    }

                //                    // This will truncate/overwrite an existing file, or
                //                    using (IsolatedStorageFileStream outFile = appStorage.OpenFile(AppRoot + file.path, FileMode.Create))
                //                    {
                //                        Debug.WriteLine("INFO: Writing data for " + AppRoot + file.path + " and length = " + data.Length);
                //                        using (var writer = new BinaryWriter(outFile))
                //                        {
                //                            writer.Write(data);
                //                        }
                //                    }
                //                }
                //            }
                //            else
                //            {
                //                Debug.WriteLine("ERROR: Failed to write file :: " + file.path + " did you forget to add it to the project?");
                //            }
                //        }
                //    }
                //}

                CordovaBrowser.Navigate(StartPageUri);
                IsBrowserInitialized = true;
                AttachHardwareButtonHandlers();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ERROR: Exception in GapBrowser_Loaded :: {0}", ex.Message);
            }
        }