public static RaygunEnvironmentMessage Build()
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

            // Different environments can fail to load the environment details.
            // For now if they fail to load for whatever reason then just
            // swallow the exception. A good addition would be to handle
            // these cases and load them correctly depending on where its running.
            // see http://raygun.io/forums/thread/3655

            try
            {
                message.WindowBoundsWidth = SystemInformation.VirtualScreen.Width;
                message.WindowBoundsHeight = SystemInformation.VirtualScreen.Height;
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error retrieving window dimensions: {0}", ex.Message);
            }

            try
            {
                DateTime now = DateTime.Now;
                message.UtcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(now).TotalHours;
                message.Locale = CultureInfo.CurrentCulture.DisplayName;
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error retrieving time and locale: {0}", ex.Message);
            }

            try
            {
                bool mediumTrust = RaygunSettings.Settings.MediumTrust || !HasUnrestrictedFeatureSet;

                if (!mediumTrust)
                {
                    // ProcessorCount cannot run in medium trust under net35, once we have
                    // moved to net40 minimum we can move this out of here
                    message.ProcessorCount = Environment.ProcessorCount;
                    message.Architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
                    message.DiskSpaceFree = GetDiskSpace();
                    message.Cpu = GetCpu();
                    message.OSVersion = GetOSVersion();
                }
            }
            catch (SecurityException)
            {
                Trace.WriteLine("RaygunClient error: couldn't access environment variables. If you are running in Medium Trust, in web.config in RaygunSettings set mediumtrust=\"true\"");
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error retrieving environment info: {0}", ex.Message);
            }

            return message;
        }
    public static RaygunEnvironmentMessage Build()
    {
      RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

      try
      {
        UIApplication.SharedApplication.InvokeOnMainThread(() =>
        {
          message.WindowBoundsWidth = UIScreen.MainScreen.Bounds.Width;
          message.WindowBoundsHeight = UIScreen.MainScreen.Bounds.Height;
        });
      }
      catch (Exception ex)
      {
        Trace.WriteLine(string.Format("Error retrieving screen dimensions: {0}", ex.Message));
      }

      try
      {
        message.UtcOffset = NSTimeZone.LocalTimeZone.GetSecondsFromGMT / 3600.0;
        message.Locale = CultureInfo.CurrentCulture.DisplayName;
      }
      catch (Exception ex)
      {
        Trace.WriteLine(string.Format("Error retrieving time and locale: {0}", ex.Message));
      }

      try
      {
        message.OSVersion = UIDevice.CurrentDevice.SystemName + " " + UIDevice.CurrentDevice.SystemVersion;
        message.Model = UIDevice.CurrentDevice.Model;
        message.CurrentOrientation = UIDevice.CurrentDevice.Orientation.ToString();
      }
      catch (Exception ex)
      {
        Trace.WriteLine(string.Format("Error retrieving device info: {0}", ex.Message));
      }

      try
      {
        message.ProcessorCount = (int)GetIntSysCtl(ProcessiorCountPropertyName);
        message.Architecture = GetStringSysCtl(ArchitecturePropertyName);
        message.TotalPhysicalMemory = GetIntSysCtl(TotalPhysicalMemoryPropertyName);
        message.AvailablePhysicalMemory = GetIntSysCtl(AvailablePhysicalMemoryPropertyName);
      }
      catch (Exception ex)
      {
        Trace.WriteLine(string.Format("Error retrieving memory and processor: {0}", ex.Message));
      }

      return message;
    }
        public static RaygunEnvironmentMessage Build()
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

              try
              {
            if (Window.Current != null)
            {
              message.WindowBoundsWidth = Window.Current.Bounds.Width;
              message.WindowBoundsHeight = Window.Current.Bounds.Height;

              var sensor = Windows.Devices.Sensors.SimpleOrientationSensor.GetDefault();

              if (sensor != null)
              {
            message.CurrentOrientation = sensor.GetCurrentOrientation().ToString();
              }
            }
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retieving screen info: {0}", ex.Message);
              }

              try
              {
            DateTime now = DateTime.Now;
            message.UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;
            message.Locale = CultureInfo.CurrentCulture.DisplayName;
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retieving time and locale: {0}", ex.Message);
              }

              try
              {
            var deviceInfo = new EasClientDeviceInformation();
            message.DeviceManufacturer = deviceInfo.SystemManufacturer;
            message.DeviceName = deviceInfo.SystemProductName;
            message.OSVersion = deviceInfo.OperatingSystem;
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retieving device info: {0}", ex.Message);
              }

              return message;
        }
        public static RaygunEnvironmentMessage Build()
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

              try
              {
            if (Windows.UI.Xaml.Window.Current != null)
            {
              message.WindowBoundsHeight = Windows.UI.Xaml.Window.Current.Bounds.Height;
              message.WindowBoundsWidth = Windows.UI.Xaml.Window.Current.Bounds.Width;
            }
            message.ResolutionScale = DisplayProperties.ResolutionScale.ToString();
            message.CurrentOrientation = DisplayProperties.CurrentOrientation.ToString();
            message.ViewState = ApplicationView.Value.ToString();
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving window info: {0}", ex.Message);
              }

              try
              {
            DateTime now = DateTime.Now;
            message.UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;
            message.Locale = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion;
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving time and locale: {0}", ex.Message);
              }

              try
              {
            message.Cpu = Package.Current.Id.Architecture.ToString();
            SYSTEM_INFO systemInfo = new SYSTEM_INFO();
            RaygunSystemInfoWrapper.GetNativeSystemInfo(ref systemInfo);
            message.Architecture = ((PROCESSOR_ARCHITECTURE)systemInfo.wProcessorArchitecture).ToString();
            message.ProcessorCount = (int)systemInfo.dwNumberOfProcessors;
            message.OSVersion = GetOSVersion();
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving device info: {0}", ex.Message);
              }

              return message;
        }
        public static RaygunEnvironmentMessage Build()
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

              try
              {
            if (Application.Current != null && Application.Current.RootVisual != null)
            {
              message.WindowBoundsWidth = Application.Current.RootVisual.RenderSize.Width;
              message.WindowBoundsHeight = Application.Current.RootVisual.RenderSize.Height;
              PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
              if (frame != null)
              {
            message.CurrentOrientation = frame.Orientation.ToString();
              }
            }
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving screen info: {0}", ex.Message);
              }

              try
              {
            DateTime now = DateTime.Now;
            message.UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;
            message.Locale = CultureInfo.CurrentCulture.DisplayName;
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving time and locale: {0}", ex.Message);
              }

              try
              {
            message.OSVersion = Environment.OSVersion.Platform + " " + Environment.OSVersion.Version;
            message.DeviceFirmwareVersion = DeviceStatus.DeviceFirmwareVersion;
            message.DeviceHardwareVersion = DeviceStatus.DeviceHardwareVersion;
            message.DeviceManufacturer = DeviceStatus.DeviceManufacturer;
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving device info: {0}", ex.Message);
              }

              try
              {
            message.ApplicationCurrentMemoryUsage = DeviceStatus.ApplicationCurrentMemoryUsage;
            message.ApplicationMemoryUsageLimit = DeviceStatus.ApplicationMemoryUsageLimit;
            message.ApplicationPeakMemoryUsage = DeviceStatus.ApplicationPeakMemoryUsage;
            message.DeviceTotalMemory = DeviceStatus.DeviceTotalMemory;
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving device memory: {0}", ex.Message);
              }

              try
              {
            message.IsolatedStorageAvailableFreeSpace = IsolatedStorageFile.GetUserStoreForApplication().AvailableFreeSpace;
              }
              catch (Exception ex)
              {
            Debug.WriteLine("Error retrieving isolated storage memory: {0}", ex.Message);
              }

              return message;
        }
        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;
        }
        public static RaygunEnvironmentMessage Build(RaygunSettings settings)
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

              try
              {
            DateTime now = DateTime.Now;
            message.UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours;
            message.Locale = CultureInfo.CurrentCulture.DisplayName;
              }
              catch { }

              // The cross platform APIs for getting this information don't exist right now.
              // In the mean time, chuck conditionals around the whole thing.

            #if NET451
              // Different environments can fail to load the environment details.
              // For now if they fail to load for whatever reason then just
              // swallow the exception. A good addition would be to handle
              // these cases and load them correctly depending on where its running.
              // see http://raygun.io/forums/thread/3655

              try
              {
            message.WindowBoundsWidth = SystemInformation.VirtualScreen.Width;
            message.WindowBoundsHeight = SystemInformation.VirtualScreen.Height;
              }
              catch (Exception ex)
              {
            System.Diagnostics.Trace.WriteLine("Error retrieving window dimensions: {0}", ex.Message);
              }

              try
              {
            ComputerInfo info = new ComputerInfo();
            message.OSVersion = info.OSVersion;

            bool mediumTrust = settings.MediumTrust || !HasUnrestrictedFeatureSet;

            if (!mediumTrust)
            {
              // ProcessorCount cannot run in medium trust under net35, once we have
              // moved to net40 minimum we can move this out of here
              message.ProcessorCount = Environment.ProcessorCount;
              message.Architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
              message.TotalPhysicalMemory = (ulong)info.TotalPhysicalMemory / 0x100000; // in MB
              message.AvailablePhysicalMemory = (ulong)info.AvailablePhysicalMemory / 0x100000;
              message.TotalVirtualMemory = info.TotalVirtualMemory / 0x100000;
              message.AvailableVirtualMemory = info.AvailableVirtualMemory / 0x100000;
              message.DiskSpaceFree = GetDiskSpace();
              message.Cpu = GetCpu();
              message.OSVersion = GetOSVersion();
            }
              }
              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\"");
              }
              catch (Exception ex)
              {
            System.Diagnostics.Trace.WriteLine("Error retrieving environment info: {0}", ex.Message);
              }
            #endif
              return message;
        }
        public static RaygunEnvironmentMessage Build()
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage();

              // Different environments can fail to load the environment details.
              // For now if they fail to load for whatever reason then just
              // swallow the exception. A good addition would be to handle
              // these cases and load them correctly depending on where its running.
              // see http://raygun.io/forums/thread/3655

              try
              {
            IntPtr hWnd = GetActiveWindow();
            RECT rect;
            GetWindowRect(hWnd, out rect);
            message.WindowBoundsWidth = rect.Right - rect.Left;
            message.WindowBoundsHeight = rect.Bottom - rect.Top;
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine(string.Format("Error retrieving window dimensions: {0}", ex.Message));
              }

              try
              {
            DateTime now = DateTime.Now;
            message.UtcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(now).TotalHours;
            message.Locale = CultureInfo.CurrentCulture.DisplayName;
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine(string.Format("Error retrieving time and locale: {0}", ex.Message));
              }

              try
              {
            message.ProcessorCount = Environment.ProcessorCount;
            message.Architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
            message.OSVersion = Environment.OSVersion.VersionString;
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine(string.Format("Error retrieving processor info: {0}", ex.Message));
              }

              try
              {
            ComputerInfo info = new ComputerInfo();
            message.TotalPhysicalMemory = (ulong)info.TotalPhysicalMemory / 0x100000; // in MB
            message.AvailablePhysicalMemory = (ulong)info.AvailablePhysicalMemory / 0x100000;
            message.TotalVirtualMemory = info.TotalVirtualMemory / 0x100000;
            message.AvailableVirtualMemory = info.AvailableVirtualMemory / 0x100000;
            message.DiskSpaceFree = GetDiskSpace();
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine(string.Format("Error retrieving memory info: {0}", ex.Message));
              }

              return message;
        }
        public static RaygunEnvironmentMessage Build()
        {
            RaygunEnvironmentMessage message = new RaygunEnvironmentMessage ();

              try
              {
            if (NSApplication.SharedApplication != null && NSApplication.SharedApplication.KeyWindow != null)
            {
              message.WindowBoundsWidth = NSApplication.SharedApplication.KeyWindow.Frame.Width;
              message.WindowBoundsHeight = NSApplication.SharedApplication.KeyWindow.Frame.Height;
            }
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine("Error retrieving window dimensions: {0}", ex.Message);
              }

              try
              {
            message.UtcOffset = NSTimeZone.LocalTimeZone.GetSecondsFromGMT / 3600.0;
            message.Locale = CultureInfo.CurrentCulture.DisplayName;
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine("Error retrieving time and locale: {0}", ex.Message);
              }

              try
              {
            message.Architecture = GetStringSysCtl(ArchitecturePropertyName);
            message.ProcessorCount = (int)GetIntSysCtl(ProcessiorCountPropertyName);
            message.TotalPhysicalMemory = GetIntSysCtl(TotalPhysicalMemoryPropertyName);
            message.AvailablePhysicalMemory = GetIntSysCtl(AvailablePhysicalMemoryPropertyName);
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine("Error retrieving device info: {0}", ex.Message);
              }

              try
              {
            string osType = GetStringSysCtl(OSTypePropertyName);
            string version = GetStringSysCtl(OSReleasePropertyName);
            string osVersion = null;
            if ("Darwin".Equals(osType) && !String.IsNullOrWhiteSpace(version))
            {
              if (version.StartsWith("14"))
              {
            osVersion = "OS X v10.10 Yosemite";
              }
              else if (version.StartsWith("13"))
              {
            osVersion = "OS X v10.9 Mavericks";
              }
              else if (version.StartsWith("12.5"))
              {
            osVersion = "OS X v10.8.5 Mountain Lion";
              }
              else if (version.StartsWith("12"))
              {
            osVersion = "OS X v10.8 Mountain Lion";
              }
              else if (version.StartsWith("11"))
              {
            osVersion = "Mac OS X v10.7 Lion";
              }
              else if (version.StartsWith("10"))
              {
            osVersion = "Mac OS X v10.6 Snow Leopard";
              }
              else if (version.StartsWith("9"))
              {
            osVersion = "Mac OS X v10.5 Leopard";
              }
              else if (version.StartsWith("8"))
              {
            osVersion = "Mac OS X v10.4 Tiger";
              }
              else if (version.StartsWith("7"))
              {
            osVersion = "Mac OS X v10.3 Panther";
              }
              else if (version.StartsWith("6"))
              {
            osVersion = "Mac OS X v10.2 Jaguar";
              }
              else if (version.StartsWith("5"))
              {
            osVersion = "Mac OS X v10.1 Puma";
              }
            }

            if (osVersion != null)
            {
              osVersion += " (" + osType + " " + version + ")";
            }
            else if (!String.IsNullOrWhiteSpace(osType) && !"Unknown".Equals(osType) && !String.IsNullOrWhiteSpace(version) && !"Unknown".Equals(version))
            {
              osVersion = osType + " " + version;
            }
            else
            {
              osVersion = "Unknown";
            }

            message.OSVersion = osVersion;
              }
              catch (Exception ex)
              {
            System.Diagnostics.Debug.WriteLine("Error retrieving OSVersion: {0}", ex.Message);
              }

              return message;
        }