コード例 #1
0
ファイル: Program.cs プロジェクト: junalmeida/mysquare
        static void Main(string[] args)
        {
            string     fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "mysquare.txt");
            FileStream file     = new FileStream(
                fileName, FileMode.Create, FileAccess.Write);

            Debug           = new StreamWriter(file);
            Debug.AutoFlush = true;

            try
            {
                MessageBox.Show("This program will collect some debug data from your device. This may take some time and will try to discover your position. Wait for the success message.");

                Debug.WriteLine("MySquare Compatibility Check");
                Debug.WriteLine(DateTime.Now.ToString());
                Debug.WriteLine(DateTime.UtcNow.ToString());
                Debug.WriteLine("========================");
                Debug.WriteLine(".NET Framework version: ");

                using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey
                                     (@"Software\Microsoft\.NETCompactFramework"))
                {
                    foreach (var valueName in key.GetValueNames())
                    {
                        try
                        {
                            if ((int)key.GetValue(valueName, 0) == 1)
                            {
                                Debug.WriteLine("  * " + valueName);
                            }
                        }
                        catch { }
                    }
                    Debug.WriteLine(string.Empty);
                }
                Debug.WriteLine("Native Libraries:");
                foreach (string f in files)
                {
                    Debug.WriteLine(@"  * " + f + ": " + File.Exists(f).ToString());
                }
                Debug.WriteLine(string.Empty);
                try
                {
                    using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System\\State\\Phone"))
                    {
                        Debug.WriteLine("Operator:");
                        Debug.WriteLine("  * " + key.GetValue("Current Operator Name", string.Empty));
                    }
                }
                catch { }
                Debug.WriteLine("Device Information:");
                Debug.WriteLine("  * " + Manufacturer + " " + OemInfo);
                Debug.WriteLine("Windows:");
                Debug.WriteLine("  * " + Environment.OSVersion.ToString());
                Debug.WriteLine("Platform:");
                Debug.WriteLine("  * " + Environment.Version.ToString());

                Debug.WriteLine(string.Empty);
                Debug.WriteLine(string.Empty);
                RIL_Test();

#if XPS
                Debug.WriteLine();
                Debug.WriteLine("Locating your cellphone:");
                Debug.WriteLine();
                Debug.Write(" * WPS:");

                double lat, lng;
                if (Tenor.Mobile.Location.Xps.WPSLocation("risingmobility", "junalmeida", out lat, out lng) == Tenor.Mobile.Location.WPS_ReturnCode.WPS_OK)
                {
                    Debug.WriteLine(lat.ToString() + " - " + lng.ToString());
                }
                else
                {
                    Debug.WriteLine("Error");
                }
#endif

                var culture = System.Globalization.CultureInfo.GetCultureInfo("en-us");
                waithandle.Reset();


                Debug.WriteLine();
                Debug.Write("Testing WPS: ");
                DateTime   startPoint = DateTime.Now;
                WorldPoint point      = RisingMobility.Mobile.Location.WorldPosition.GetWiFiSkyhookLocation();

                Debug.Write(point.ToString());
                Debug.WriteLine(" ; " + (DateTime.Now - startPoint).TotalSeconds.ToString(culture) + " seconds.");
                Debug.WriteLine();


                Debug.WriteLine("Testing GPS, WPS, GSM, GeoIp: ");
                pos          = new RisingMobility.Mobile.Location.WorldPosition(true, true);
                pos.PollHit += new EventHandler(pos_LocationChanged);
                pos.Error   += new RisingMobility.Mobile.Location.ErrorEventHandler(pos_Error);
                Debug.WriteLine("GPS Hardware: " + pos.IsGpsOpen.ToString());
                if (!waithandle.WaitOne(60000 * 1, false))
                {
                    Debug.Write("Gps give up. ");
                }
                Debug.WriteLine("Done.");

                pos.PollHit -= new EventHandler(pos_LocationChanged);
                pos.Error   -= new RisingMobility.Mobile.Location.ErrorEventHandler(pos_Error);

                MessageBox.Show("Done.\r\n Check the file at: " + fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (pos != null)
                {
                    pos.Dispose();
                }
                Debug.Close();
            }
        }