コード例 #1
0
        /// <summary>Extracts some parameters from the specified <c>ApplicationInstanceAwareness</c> value.</summary>
        /// <param name="awareness">The <c>ApplicationInstanceAwareness</c> value to extract parameters from.</param>
        /// <param name="prefix">The synchronization object prefix.</param>
        /// <param name="identity">The identity used to handle the synchronization object.</param>
        static void ExtractParameters(
            ApplicationInstanceAwareness awareness, out string prefix, out IdentityReference identity)
        {
            new SecurityPermission(SecurityPermissionFlag.ControlPrincipal).Assert();
            WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();

            if (currentIdentity == null)
            {
                throw new Exception("Unable to retrieve current identity");
            }

            if (awareness == ApplicationInstanceAwareness.Host && currentIdentity.Groups != null)
            {
                prefix   = GlobalPrefix;
                identity =
                    currentIdentity.Groups.FirstOrDefault(
                        reference => reference.Translate(typeof(SecurityIdentifier)).Value.Equals(UsersSidValue));
            }
            else
            {
                prefix   = LocalPrefix;
                identity = currentIdentity.User;
            }

            CodeAccessPermission.RevertAssert();

            if (identity == null)
            {
                throw new Exception(
                          "Could not determine a proper identity to create synchronization objects access rules");
            }
        }
コード例 #2
0
        /// <summary>
        ///   Extracts some parameters from the specified <see cref = "ApplicationInstanceAwareness" /> value.
        /// </summary>
        /// <param name = "awareness">The <see cref = "ApplicationInstanceAwareness" /> value to extract parameters from.</param>
        /// <param name = "prefix">The synchronization object prefix.</param>
        /// <param name = "identity">The identity used to handle the synchronization object.</param>
        /// <exception cref = "UnexpectedInstanceAwareApplicationException">A proper identity could not be determined.</exception>
        private static void ExtractParameters(ApplicationInstanceAwareness awareness, out string prefix, out IdentityReference identity)
        {
            new SecurityPermission(SecurityPermissionFlag.ControlPrincipal).Assert();
            WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();

            if (currentIdentity != null)
            {
                if (awareness == ApplicationInstanceAwareness.Host && currentIdentity.Groups != null)
                {
                    prefix = GLOBAL_PREFIX;
                    identity = currentIdentity.Groups.FirstOrDefault(reference => reference.Translate(typeof(SecurityIdentifier)).Value.Equals(USERS_SID_VALUE));
                }
                else
                {
                    prefix = LOCAL_PREFIX;
                    identity = currentIdentity.User;
                }
                CodeAccessPermission.RevertAssert();

                if (identity == null)
                    throw new UnexpectedInstanceAwareApplicationException("Could not determine a proper identity to create synchronization objects access rules");
            }
            else
                throw new UnexpectedInstanceAwareApplicationException("Unable to retrieve current identity");
        }
コード例 #3
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "InstanceAwareApplication" /> class.
 /// </summary>
 /// <param name = "awareness">The instance awareness of the application.</param>
 /// <exception cref = "System.InvalidOperationException">More than one instance of the <see cref = "System.Windows.Application" /> class is created per <see cref = "System.AppDomain" />.</exception>
 public InstanceAwareApplication(ApplicationInstanceAwareness awareness)
 {
     m_Awareness = awareness;
 }
コード例 #4
0
 /// <summary>Initializes a new instance of the <see cref="InstanceAwareApplication" /> class.</summary>
 /// <param name="awareness">The instance awareness of the application.</param>
 /// <exception cref="InvalidOperationException">More than one instance of the <c>System.Windows.Application</c> class is created per <c>System.AppDomain</c>.</exception>
 public InstanceAwareApplication(ApplicationInstanceAwareness awareness)
 {
     this.awareness = awareness;
 }