示例#1
0
        protected override IList<City> GetCities()
        {
            var result = new List<City>();
            string dataJson = "";

            var csr = App.GetResourceStream(new Uri("Assets/PubliBike-services.zip", UriKind.Relative)).Stream;
            var uz = new UnZipper(csr);
            using (var fs = uz.GetFileStream(uz.FileNamesInZip.FirstOrDefault()))
            {
                var sr = new StreamReader(fs);
                dataJson = sr.ReadToEnd();
            }

            var allServices = dataJson.FromJson<List<AboProvider>>();
            foreach (var abo in allServices)
            {
                if (abo.Abo == null || abo.Abo.Terminals == null) continue;
                var serviceName = abo.Abo.Name;
                var grouppedTerminals = from term in abo.Abo.Terminals where !string.IsNullOrEmpty(term.City) group term by term.City into byCity select new { City = byCity.Key, Country = DomainNameToCountry(byCity.First().Country), Terminals = byCity.ToList() };
                foreach (var xcity in grouppedTerminals)
                {
                    // todo: find an existing city and append the service name; eg: "SwissPass, Bulle"
                    var city = (from c in result where string.Equals(c.CityName, xcity.City, StringComparison.InvariantCultureIgnoreCase) select c).FirstOrDefault();
                    if (city == null)
                    {
                        city = new City()
                        {
                            CityName = xcity.City,
                            Country = DomainNameToCountry(xcity.Country),
                            ServiceName = serviceName,
                            UrlCityName = xcity.City,
                            Latitude = abo.Abo.Lat,
                            Longitude = abo.Abo.Lng,
                            //UID = (string)xcity.Attribute("uid"),
                            Provider = Instance
                        };
                        if (string.IsNullOrEmpty(city.UrlCityName))
                            city.UrlCityName = city.CityName;
                        result.Add(city);
                    }
                    else if (city.ServiceName.IndexOf(serviceName, StringComparison.InvariantCultureIgnoreCase) < 0)
                    {
                        city.ServiceName += ", " + serviceName;
                        if (!string.Equals(serviceName, "SwissPass", StringComparison.InvariantCultureIgnoreCase))
                        {
                            city.Latitude = abo.Abo.Lat;
                            city.Longitude = abo.Abo.Lng;
                        }
                    }
                }
            }
            return result;
        }
示例#2
0
        /// <summary>
        /// Create a new PebbleBundle from a .pwb file and parse its metadata.
        /// </summary>
        /// <param name="path">The relative or full path to the file.</param>
        public P3bbleBundle(String path)
        {
            Stream jsonstream;
            Stream binstream;
            _privateName = path;

            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
            if (!file.FileExists(path))
                throw new FileNotFoundException("the file could not be found in the isolated storage");

            FullPath = Path.GetFullPath(path);
            Bundle = new UnZipper(file.OpenFile(path, FileMode.Open));

            if (Bundle.FileNamesInZip.Contains("manifest.json"))
            {
                jsonstream = Bundle.GetFileStream("manifest.json");
            }
            else
            {
                throw new ArgumentException("manifest.json not found in archive - not a Pebble bundle.");
            }

            var serializer = new DataContractJsonSerializer(typeof(P3bbleBundleManifest));

            Manifest = serializer.ReadObject(jsonstream) as P3bbleBundleManifest;
            jsonstream.Close();

            HasResources = (Manifest.Resources.Size != 0);

            if (Manifest.Type == "firmware")
            {
                BundleType = BundleTypes.Firmware;
            }
            else
            {
                BundleType = BundleTypes.Application;
                if (Bundle.FileNamesInZip.Contains(Manifest.Application.Filename))
                {
                    binstream = Bundle.GetFileStream(Manifest.Application.Filename);
                }
                else
                {
                    String format = "App file {0} not found in archive";
                    throw new ArgumentException(String.Format(format, Manifest.Application.Filename));
                }

                Application = Util.ReadStruct<P3bbleApplicationMetadata>(binstream);
                binstream.Close();
            }
        }
示例#3
0
        public void unzip(string jsonArgs)
        {
            Console.WriteLine("unzip");
            var options = JsonHelper.Deserialize<string[]>(jsonArgs);
            string zipPath = options[0];
            string extractPath = options[1];

            // open isolated storage
            using (IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // open filestream for the zip-file
                using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(zipPath, FileMode.Open, FileAccess.ReadWrite, isoStorage))
                {
                    // let's creat unzipper
                    using (UnZipper zipStream = new UnZipper(fileStream))
                    {
                        foreach (string dir in zipStream.DirectoriesInZip)
                        {
                            isoStorage.CreateDirectory(dir);
                        }

                        // let's run through all files within the zip-file
                        foreach (string file in zipStream.FileNamesInZip) {
                            using (var streamWriter = new BinaryWriter(new IsolatedStorageFileStream(file, FileMode.Create, FileAccess.Write, FileShare.Write, isoStorage)))
                            {
                                Stream zipFileStream = zipStream.GetFileStream(file);

                                var buffer = new byte[2048];
                                int size;
                                while ((size = zipFileStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    streamWriter.Write(buffer, 0, size);
                                }
                            }
                        }

                        DispatchCommandResult(new PluginResult(PluginResult.Status.OK, true));
                    }
                }
            }
        }
示例#4
0
        public void addMenuItem(String text, int ordinal, int priority, int wrapper_callback, int callback, int push_at_start)
        {
            for (int i = 0; i < m_menuItems.Count; i++)
            {
                WazeMenuItem m = (WazeMenuItem)m_menuItems[i];
                if (text.CompareTo(m.ToString()) == 0)
                {
                    return; // item already exists, don't add.
                }
            }

            /*            if (text.Equals("Accept"))
                        {
                            int c_on_menuItem = CibylCallTable.getAddressByName("rim_on_menuItem");
                            if (c_on_menuItem != 0)
                            {
                                UIWorker.addUIEvent(c_on_menuItem, wrapper_callback, callback, 0, 0, true);
                            }
                        }*/

            WazeMenuItem new_item = new WazeMenuItem(text, ordinal, priority, wrapper_callback, callback);
            if (push_at_start == 1)
            {
                m_menuItems.Insert(0, new_item);
            }
            else
            {
                m_menuItems.Add(new_item);
            }

            System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {

                // Create a new menu item with the localized string from AppResources
                ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(text);
                if (text.ToLower().Equals("About") || text.Equals("אודות"))
                {
                    appBarMenuItem.Click += delegate
                    {
                        string name = System.Reflection.Assembly.GetExecutingAssembly().FullName;
                        System.Reflection.AssemblyName asmName = new System.Reflection.AssemblyName(name);

                        //System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                        Version version = asmName.Version;
                        String s = String.Format("{0}.{1}.{2}.{3}",
                                                            version.Major,
                                                            version.Minor,
                                                            version.Build,
                                                            version.Revision);
                        AboutDialog ad = new AboutDialog();
                        ad.SetVersion(s);

                        FreeMapMainScreen.get().LayoutRoot.Children.Add(ad);
                    };
                    ApplicationBar.MenuItems.Add(appBarMenuItem);

                    appBarMenuItem = new ApplicationBarMenuItem("טען מפה");
                    appBarMenuItem.Click += delegate
                    {
            /*                        TileStorage ts = (TileStorage)CRunTime.objectRepository[Syscalls.ts_id];
                        UnZipper uz = new UnZipper(Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tiles.zip", UriKind.Relative)).Stream);
                        int index = 0;
                        foreach (string filename in uz.FileNamesInZip)
                        {
                            int tile_index = int.Parse(filename);
                            Stream st = uz.GetFileStream(filename);
                            BinaryReader br = new BinaryReader(st);
                            byte[] tile_bytes = new byte[st.Length];
                            br.Read(tile_bytes, 0, tile_bytes.Length);
                            ts.storeTileEx(77001, tile_index, tile_bytes);
                            index++;
                        }*/

                        UnZipper uz = new UnZipper(Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tel_aviv_till_hod_hasharon.zip", UriKind.Relative)).Stream);
                        foreach (string filename in uz.FileNamesInZip)
                        {
                            Stream st = uz.GetFileStream(filename);
                            Syscalls.CopyFileFromStream(st, filename);
                        }

                        Syscalls.NOPH_TileStorage_initialize(Syscalls.ts_id);

                        /*
                        StreamResourceInfo info = Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tiles/file_list.txt", UriKind.Relative));
                        using (StreamReader reader = new StreamReader(info.Stream))
                        {
                            string line = reader.ReadLine();
                            while (line != null)
                            {
                                int tile_index = int.Parse(line);
                                Stream tile = Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tiles/" + line, UriKind.Relative)).Stream;
                                BinaryReader br = new BinaryReader(tile);
                                byte[] tile_bytes = new byte[tile.Length];
                                br.Read(tile_bytes, 0, tile_bytes.Length);
                                ts.storeTileEx(77001, tile_index, tile_bytes);
                                line = reader.ReadLine();
                            }
                        }*/
                        MessageBox.Show("Finished");

                    };
                }
                else
                {
                    appBarMenuItem.Click += (delegate
                    {
                        new_item.CallCallback();
                    });
                }
                ApplicationBar.MenuItems.Add(appBarMenuItem);
            });

            if (text.ToLower().Equals("me on map") || text.Equals("הצג אותי"))
            {
                MeOnMapItem = new_item;

                ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("Resources/compas.png", UriKind.Relative));
                appBarButton.Text = "Me on map";
                appBarButton.IconUri = new Uri("Resources/compas.png", UriKind.Relative);
                appBarButton.Click += delegate
                {
                    new_item.CallCallback();
                };
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ApplicationBar.Buttons.Add(appBarButton);
                });

            }

            if (text.ToLower().Equals("drive to") || text.Equals("נווט"))
            {
                ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("Resources/search.png", UriKind.Relative));
                appBarButton.Text = "Navigate";
                appBarButton.IconUri = new Uri("Resources/search.png", UriKind.Relative);
                appBarButton.Click += delegate
                {
                    new_item.CallCallback();
                };
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ApplicationBar.Buttons.Add(appBarButton);
                });

            }

            //if (text.ToLower().Equals("stop navigation") || text.Equals("הפסק ניווט"))
            //{
            //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("Resources/cancel.png", UriKind.Relative));
            //    appBarButton.Text = "Navigate";
            //    appBarButton.IconUri = new Uri("Resources/cancel.png", UriKind.Relative);
            //    appBarButton.Click += delegate
            //    {
            //        new_item.CallCallback();
            //    };
            //    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            //    {
            //        ApplicationBar.Buttons.Add(appBarButton);
            //    });

            //}

            if (text.ToLower().Equals("report") || text.Equals("דווח"))
            {
                ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("Resources/i.png", UriKind.Relative));
                appBarButton.Text = "Report";
                appBarButton.IconUri = new Uri("Resources/i.png", UriKind.Relative);
                appBarButton.Click += delegate
                {
                    new_item.CallCallback();
                };

                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ApplicationBar.Buttons.Add(appBarButton);
                });

            }

            if (text.ToLower().Equals("Saved locations") || text.Equals("מקומות שמורים"))
            //if (text.ToLower().Equals("exit") || text.Equals("יציאה"))
            {
                ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("Resources/favorites.png", UriKind.Relative));
                appBarButton.Text = "Saved Locs";
                appBarButton.IconUri = new Uri("Resources/favorites.png", UriKind.Relative);
                appBarButton.Click += delegate
                {
                    new_item.CallCallback();

                    //MessageBoxResult res = MessageBox.Show("Are you sure you want to exit", "Exit", MessageBoxButton.OKCancel);
                    //if (res == MessageBoxResult.OK)
                    //    new_item.CallCallback();
                };

                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ApplicationBar.Buttons.Add(appBarButton);
                });

            }

            /*
            if (!perf_button_added)
            {
                perf_button_added = true;
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem("Save perf data");
                    appBarMenuItem.Click += EmailLogFile;
                    ApplicationBar.MenuItems.Add(appBarMenuItem);
                });

                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem("Clear perf data");
                    appBarMenuItem.Click += delegate { Syscalls.fis.Clear(); };
                    ApplicationBar.MenuItems.Add(appBarMenuItem);
                });

            }
             */

            /*
            if (!isSendMailAdded)
            {
                isSendMailAdded = true;
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem("Email log file");
                    appBarMenuItem.Click += EmailLogFile;
                    ApplicationBar.MenuItems.Add(appBarMenuItem);
                });
            }*/
        }
        private void Unzip(Stream stream)
        {
            using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var zipStream = new UnZipper(stream))
                {
                    foreach (string file in zipStream.FileNamesInZip)
                    {
                        string fileName = System.IO.Path.GetFileName(file);

                        if (!string.IsNullOrEmpty(fileName))
                        {
                            Debug.WriteLine("Extracting " + fileName + " ...");

                            //save file entry to storage
                            using (var streamWriter =
                                new BinaryWriter(new IsolatedStorageFileStream(fileName,
                                                                               FileMode.Create,
                                                                               FileAccess.Write, FileShare.Write,
                                                                               isoStore)))
                            {
                                Stream fileStream = zipStream.GetFileStream(file);

                                var buffer = new byte[2048];
                                int size;
                                while ((size = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    streamWriter.Write(buffer, 0, size);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#6
0
        public static async Task<HttpResponseMessage> GetTiles(string buid, string floor_number)
        {
            var r = new RequestPoisByFloor
            {
                access_token = "api_tester",
                buid = buid,
                floor_number = floor_number,
                username = "",
                password = ""
            };

            try
            {
                var response = await AnyPlaceClient.PostAsJsonAsync(new Uri(ServerBaseUri, "/anyplace/floortiles/zip/" + buid + "/" + floor_number), r);

                if (!response.IsSuccessStatusCode)
                {
                    return null;
                }

                var x = await response.Content.ReadAsStreamAsync();

                using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (var zipStream = new UnZipper(x))
                    {
                        isoStore.CreateDirectory(buid);
                        isoStore.CreateDirectory(buid + "/" + floor_number);

                        foreach (var file in zipStream.FileNamesInZip)
                        {
                            string fileName = Path.GetFileName(file);

                            if (!string.IsNullOrEmpty(fileName))
                            {
                                //Debug.WriteLine(fileName);

                                //save file entry to storage
                                using (var streamWriter =
                                    new BinaryWriter(new IsolatedStorageFileStream(buid + "/" + floor_number + "/" + fileName,
                                                                                   FileMode.Create,
                                                                                   FileAccess.Write, FileShare.Write,
                                                                                   isoStore)))
                                {
                                    Stream fileStream = zipStream.GetFileStream(file);

                                    var buffer = new byte[2048];
                                    int size;
                                    while ((size = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                                    {
                                        streamWriter.Write(buffer, 0, size);
                                    }
                                }
                            }
                        }
                    }
                }

            }
            catch (Exception e) {
                var x = e.Message;
            }
            return null;
        }