Microsoft® Surface® Live Stream Code Sample

ive Stream enables businesses to engage their customers face-to-face using the most recent and relevant Twitter™, Flickr®, and RSS newsfeeds.

C# (5.9 MB)
 
 
 
 
 
4.3 Star
(4)
6,627 times
Add to favorites
4/19/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
using System.Diagnostics;
using System.Globalization;
using Microsoft.Win32;

namespace LiveStream.Helpers
{
    /// <summary>
    /// Helper properties for getting info about the current Surface environment.
    /// </summary>
    internal static class SurfaceEnvironment
    {
        /// <summary>
        /// Gets a value indicating whether the app is running inside of the Surface simulator.
        /// </summary>
        /// <value>
        /// <c>true</c> if the app is running inside of the Surface simulator; otherwise, <c>false</c>.
        /// </value>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Useful as an example."), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification = "No worries.")]
        public static bool IsRunningInSimulator
        {
            get { return Process.GetProcessesByName("SurfaceSimulator").Length > 0; }
        }

        /// <summary>
        /// Gets a value indicating whether the app is running inside of the Surface shell.
        /// </summary>
        /// <value>
        /// <c>true</c> if the app is running inside of the Surface shell; otherwise, <c>false</c>.
        /// </value>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification = "No worries.")]
        public static bool IsRunningInShell
        {
            get { return Process.GetProcessesByName("SurfaceShell").Length > 0; }
        }

        /// <summary>
        /// The key which stores whether or not the system is running in single application mode.
        /// </summary>
        private const string ShellRegKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Surface\v1.0\Shell";

        /// <summary>
        /// Gets a value indicating whether the app is running in Single Application Mode.
        /// </summary>
        /// <value>
        /// <c>true</c> if the app is running in Single Application Mode; otherwise, <c>false</c>.
        /// </value>
        public static bool IsInSingleAppMode
        {
            get
            {
                bool isInSingleAppMode = false;
                object singleAppMode = Registry.GetValue(ShellRegKey, "SingleAppMode", null);
                if (singleAppMode != null)
                {
                    isInSingleAppMode = int.Parse(singleAppMode.ToString(), CultureInfo.InvariantCulture) == 1;
                }

                return isInSingleAppMode;
            }
        }

        /// <summary>
        /// Gets a value indicating whether the Surface unit is in User Mode.
        /// </summary>
        /// <value>
        /// <c>true</c> if the Surface unit is in User Mode; otherwise, <c>false</c>.
        /// </value>
        public static bool IsInUserMode
        {
            get
            {
                bool isInUserMode = false;
                object userMode = Registry.GetValue(ShellRegKey, "TableMode", null);
                if (userMode != null)
                {
                    isInUserMode = int.Parse(userMode.ToString(), CultureInfo.InvariantCulture) == 2;
                }

                return isInUserMode;
            }
        }
    }
}