Example #1
0
 public void DeleteShip(String inpShip)
 {
     try
     {
         var path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/files/" + inpShip + "/";
         var dir  = new Java.IO.File(path);
         // System.Diagnostics.Debug.WriteLine("***** DeleteShip: directory exists: " + dir.Exists());
         if (dir.Exists())
         {   // Android Java Unix command will delete the whole ship directory which includes all reports
             String            deleteCmd = "rm -r " + path;
             Java.Lang.Runtime runtime   = Java.Lang.Runtime.GetRuntime();
             try
             {
                 runtime.Exec(deleteCmd);
             }
             catch (IOException e)
             {
                 System.Diagnostics.Debug.WriteLine("***** DeleteShip rm -r threw exception: " + e.ToString());
             }
         }
         // dir.Delete();
         var fileP = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath
                                      + "/files/" + inpShip + "_config.xml");
         fileP.Delete();
         fileP = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath
                                  + "/files/" + inpShip + "_graphic.png");
         fileP.Delete();
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine("***** DeleteShip failed: " + e.ToString());
     }
 }
Example #2
0
File: GC.cs Project: slagusev/api
 /// <summary>
 /// Retrieves the number of bytes currently allocated.
 /// </summary>
 public static long GetTotalMemory(bool forceFullCollection)
 {
     //we cannot force, but provide hints
     if (forceFullCollection)
     {
         JSystem.RunFinalization();
         JSystem.Gc();
     }
     return(JRuntime.GetRuntime().TotalMemory());
 }
Example #3
0
        private void CreateBitmapCache()
        {
            // https://github.com/rdio/tangoandcache

            long highWatermark = Runtime.GetRuntime().MaxMemory() / 3;
            long lowWatermark  = highWatermark / 2;

            // The GC threshold is the amount of bytes that have been evicted from the cache
            // that will trigger a GC.Collect. For example if set to 2mb, a GC will be performed
            // each time the cache has evicted a total of 2mb.
            // This means that we can have highWatermark + gcThreshold amount of memory in use
            // before a GC is forced, so we should ensure that the threshold value + hightWatermark
            // is less than our total memory.
            // In our case, the highWatermark is 1/3 of max memory, so using the same value for the
            // GC threshold means we can have up to 2/3 of max memory in use before kicking the GC.

            long gcThreshold = highWatermark;

            _bitmapCache = new AndroidBitmapDrawableCache(highWatermark,
                                                          lowWatermark,
                                                          gcThreshold);
        }
Example #4
0
        public void DeleteReport(String inpReportPath)
        {
            var path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/files/" + inpReportPath + "/";
            var dir  = new Java.IO.File(path);

            // System.Diagnostics.Debug.WriteLine("***** DeleteReport: directory exists: " + dir.Exists());
            if (dir.Exists())
            {   // Android Java Unix command will delete the whole report directory
                String            deleteCmd = "rm -r " + path;
                Java.Lang.Runtime runtime   = Java.Lang.Runtime.GetRuntime();
                try
                {
                    runtime.Exec(deleteCmd);
                    while (dir.Exists())
                    {
                        // System.Diagnostics.Debug.WriteLine("***** Waiting for directory deletion");
                    }
                }
                catch (IOException e)
                {
                    System.Diagnostics.Debug.WriteLine("***** DeleteReport rm -r threw exception: " + e.ToString());
                }
            }
        }
        public static RaygunEnvironmentMessage Build()
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

            try
            {
                var metrics = Resources.System.DisplayMetrics;
                message.WindowBoundsWidth  = metrics.WidthPixels;
                message.WindowBoundsHeight = metrics.HeightPixels;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving screen dimensions: {0}", ex.Message));
            }

            try
            {
                Java.Util.TimeZone tz  = Java.Util.TimeZone.Default;
                Java.Util.Date     now = new Java.Util.Date();
                message.UtcOffset = tz.GetOffset(now.Time) / 3600000.0;
                message.Locale    = CultureInfo.CurrentCulture.DisplayName;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving time and locale: {0}", ex.Message));
            }

            try
            {
                Context context = RaygunClient.Context;
                if (context != null)
                {
                    IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
                    if (windowManager != null)
                    {
                        Display display = windowManager.DefaultDisplay;
                        if (display != null)
                        {
                            switch (display.Rotation)
                            {
                            case SurfaceOrientation.Rotation0:
                                message.CurrentOrientation = "Rotation 0 (Portrait)";
                                break;

                            case SurfaceOrientation.Rotation180:
                                message.CurrentOrientation = "Rotation 180 (Upside down)";
                                break;

                            case SurfaceOrientation.Rotation270:
                                message.CurrentOrientation = "Rotation 270 (Landscape right)";
                                break;

                            case SurfaceOrientation.Rotation90:
                                message.CurrentOrientation = "Rotation 90 (Landscape left)";
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving orientation: {0}", ex.Message));
            }

            try
            {
                Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime();
                message.TotalPhysicalMemory     = (ulong)runtime.TotalMemory();
                message.AvailablePhysicalMemory = (ulong)runtime.FreeMemory();
                message.OSVersion          = Android.OS.Build.VERSION.Sdk;
                message.ProcessorCount     = runtime.AvailableProcessors();
                message.Architecture       = Android.OS.Build.CpuAbi;
                message.Model              = string.Format("{0} / {1}", Android.OS.Build.Model, Android.OS.Build.Brand);
                message.DeviceManufacturer = Android.OS.Build.Manufacturer;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Error retrieving device info: {0}", ex.Message));
            }

            return(message);
        }
Example #6
0
        public RaygunEnvironmentMessage()
        {
#if WINRT
            //WindowBoundsHeight = Windows.UI.Xaml.Window.Current.Bounds.Height;
            //WindowBoundsWidth = Windows.UI.Xaml.Window.Current.Bounds.Width;
            PackageVersion     = string.Format("{0}.{1}", Package.Current.Id.Version.Major, Package.Current.Id.Version.Minor);
            Cpu                = Package.Current.Id.Architecture.ToString();
            ResolutionScale    = DisplayProperties.ResolutionScale.ToString();
            CurrentOrientation = DisplayProperties.CurrentOrientation.ToString();
            Location           = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion;

            DateTime now = DateTime.Now;
            UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;

            SYSTEM_INFO systemInfo = new SYSTEM_INFO();
            RaygunSystemInfoWrapper.GetNativeSystemInfo(ref systemInfo);
            Architecture = systemInfo.wProcessorArchitecture.ToString();
#elif WINDOWS_PHONE
            Locale    = CultureInfo.CurrentCulture.DisplayName;
            OSVersion = Environment.OSVersion.Platform + " " + Environment.OSVersion.Version;
            object deviceName;
            DeviceExtendedProperties.TryGetValue("DeviceName", out deviceName);
            DeviceName = deviceName.ToString();

            DateTime now = DateTime.Now;
            UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                WindowBoundsWidth           = Application.Current.RootVisual.RenderSize.Width;
                WindowBoundsHeight          = Application.Current.RootVisual.RenderSize.Height;
                PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
                if (frame != null)
                {
                    CurrentOrientation = frame.Orientation.ToString();
                }
            });

            //ProcessorCount = Environment.ProcessorCount;
            // TODO: finish other values
#elif ANDROID
            try
            {
                Java.Util.TimeZone tz  = Java.Util.TimeZone.Default;
                Java.Util.Date     now = new Java.Util.Date();
                UtcOffset = tz.GetOffset(now.Time) / 3600000.0;

                OSVersion = Android.OS.Build.VERSION.Sdk;

                Locale = CultureInfo.CurrentCulture.DisplayName;

                var metrics = Resources.System.DisplayMetrics;
                WindowBoundsWidth  = metrics.WidthPixels;
                WindowBoundsHeight = metrics.HeightPixels;

                Context context = RaygunClient.Context;
                if (context != null)
                {
                    PackageManager manager = context.PackageManager;
                    PackageInfo    info    = manager.GetPackageInfo(context.PackageName, 0);
                    PackageVersion = info.VersionCode + " / " + info.VersionName;

                    IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
                    if (windowManager != null)
                    {
                        Display display = windowManager.DefaultDisplay;
                        if (display != null)
                        {
                            switch (display.Rotation)
                            {
                            case SurfaceOrientation.Rotation0:
                                CurrentOrientation = "Rotation 0 (Portrait)";
                                break;

                            case SurfaceOrientation.Rotation180:
                                CurrentOrientation = "Rotation 180 (Upside down)";
                                break;

                            case SurfaceOrientation.Rotation270:
                                CurrentOrientation = "Rotation 270 (Landscape right)";
                                break;

                            case SurfaceOrientation.Rotation90:
                                CurrentOrientation = "Rotation 90 (Landscape left)";
                                break;
                            }
                        }
                    }
                }

                DeviceName = RaygunClient.DeviceName;

                Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime();
                TotalPhysicalMemory     = (ulong)runtime.TotalMemory();
                AvailablePhysicalMemory = (ulong)runtime.FreeMemory();

                ProcessorCount = runtime.AvailableProcessors();
                Architecture   = Android.OS.Build.CpuAbi;
                Model          = string.Format("{0} / {1} / {2}", Android.OS.Build.Model, Android.OS.Build.Brand, Android.OS.Build.Manufacturer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Error getting environment info {0}", ex.Message));
            }
#elif IOS
            UtcOffset = NSTimeZone.LocalTimeZone.GetSecondsFromGMT / 3600.0;

            OSVersion      = UIDevice.CurrentDevice.SystemName + " " + UIDevice.CurrentDevice.SystemVersion;
            Architecture   = GetStringSysCtl(ArchitecturePropertyName);
            Model          = UIDevice.CurrentDevice.Model;
            ProcessorCount = (int)GetIntSysCtl(ProcessiorCountPropertyName);

            Locale = CultureInfo.CurrentCulture.DisplayName;

            UIApplication.SharedApplication.InvokeOnMainThread(() => {
                WindowBoundsWidth  = UIScreen.MainScreen.Bounds.Width;
                WindowBoundsHeight = UIScreen.MainScreen.Bounds.Height;
            });

            CurrentOrientation = UIDevice.CurrentDevice.Orientation.ToString();

            TotalPhysicalMemory     = GetIntSysCtl(TotalPhysicalMemoryPropertyName);
            AvailablePhysicalMemory = GetIntSysCtl(AvailablePhysicalMemoryPropertyName);

            DeviceName     = UIDevice.CurrentDevice.Name;
            PackageVersion = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();
#else
            WindowBoundsWidth  = SystemInformation.VirtualScreen.Height;
            WindowBoundsHeight = SystemInformation.VirtualScreen.Width;
            ComputerInfo info = new ComputerInfo();
            Locale = CultureInfo.CurrentCulture.DisplayName;

            DateTime now = DateTime.Now;
            UtcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(now).TotalHours;

            OSVersion = info.OSVersion;

            if (!RaygunSettings.Settings.MediumTrust)
            {
                try
                {
                    Architecture            = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
                    TotalPhysicalMemory     = (ulong)info.TotalPhysicalMemory / 0x100000; // in MB
                    AvailablePhysicalMemory = (ulong)info.AvailablePhysicalMemory / 0x100000;
                    TotalVirtualMemory      = info.TotalVirtualMemory / 0x100000;
                    AvailableVirtualMemory  = info.AvailableVirtualMemory / 0x100000;
                    GetDiskSpace();
                    Cpu = GetCpu();
                }
                catch (SecurityException)
                {
                    System.Diagnostics.Trace.WriteLine("RaygunClient error: couldn't access environment variables. If you are running in Medium Trust, in web.config in RaygunSettings set mediumtrust=\"true\"");
                }
            }
#endif
        }
Example #7
0
        public RaygunEnvironmentMessage()
        {
            try
            {
                Java.Util.TimeZone tz  = Java.Util.TimeZone.Default;
                Java.Util.Date     now = new Java.Util.Date();
                UtcOffset = tz.GetOffset(now.Time) / 3600000.0;

                OSVersion = Android.OS.Build.VERSION.Sdk;

                Locale = CultureInfo.CurrentCulture.DisplayName;

                var metrics = Resources.System.DisplayMetrics;
                WindowBoundsWidth  = metrics.WidthPixels;
                WindowBoundsHeight = metrics.HeightPixels;

                Context context = RaygunClient.Context;
                if (context != null)
                {
                    PackageManager manager = context.PackageManager;
                    PackageInfo    info    = manager.GetPackageInfo(context.PackageName, 0);
                    PackageVersion = info.VersionCode + " / " + info.VersionName;

                    IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
                    if (windowManager != null)
                    {
                        Display display = windowManager.DefaultDisplay;
                        if (display != null)
                        {
                            switch (display.Rotation)
                            {
                            case SurfaceOrientation.Rotation0:
                                CurrentOrientation = "Rotation 0 (Portrait)";
                                break;

                            case SurfaceOrientation.Rotation180:
                                CurrentOrientation = "Rotation 180 (Upside down)";
                                break;

                            case SurfaceOrientation.Rotation270:
                                CurrentOrientation = "Rotation 270 (Landscape right)";
                                break;

                            case SurfaceOrientation.Rotation90:
                                CurrentOrientation = "Rotation 90 (Landscape left)";
                                break;
                            }
                        }
                    }
                }

                DeviceName = "Unknown";

                Java.Lang.Runtime runtime = Java.Lang.Runtime.GetRuntime();
                TotalPhysicalMemory     = (ulong)runtime.TotalMemory();
                AvailablePhysicalMemory = (ulong)runtime.FreeMemory();

                ProcessorCount = runtime.AvailableProcessors();
                Architecture   = Android.OS.Build.CpuAbi;
                Model          = string.Format("{0} / {1} / {2}", Android.OS.Build.Model, Android.OS.Build.Brand, Android.OS.Build.Manufacturer);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Error getting environment info {0}", ex.Message));
            }
        }