Example #1
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
        }
        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 #3
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));
            }
        }