Example #1
0
        private static string GetSystemSound(string soundName)
        {
            string        path = null;
            string        name = InvariantString.Format(@"AppEvents\Schemes\Apps\.Default\{0}\.current\", soundName);
            PermissionSet set  = new PermissionSet(null);

            set.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, @"HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\"));
            set.AddPermission(new EnvironmentPermission(PermissionState.Unrestricted));
            set.Assert();
            try
            {
                using (RegistryKey key = Registry.CurrentUser.OpenSubKey(name))
                {
                    if (key != null)
                    {
                        path = (string)key.GetValue("");
                    }
                    return(path);
                }
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }
        }
Example #2
0
        /// <summary>
        ///     Attempts to convert a specified object to an instance of <see cref="T:System.Windows.Media.ImageSource" />.
        /// </summary>
        /// <param name="context">Type context information used for conversion.</param>
        /// <param name="culture">Cultural information that is respected during conversion.</param>
        /// <param name="value">The object being converted.</param>
        /// <returns>
        ///     A new instance of <see cref="T:System.Windows.Media.ImageSource" />.
        /// </returns>
        /// <exception cref="T:System.NotSupportedException">
        ///     <paramref name="value" /> is null or is an invalid type.
        /// </exception>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
            {
                throw GetConvertFromException(null);
            }

            TaskDialogIcon icon;

            if (value is TaskDialogIcon)
            {
                icon = (TaskDialogIcon)value;
            }
            else
            {
                if (!Enum.TryParse(value as string, true, out icon))
                {
                    return(null);
                }
            }

            if (icon == TaskDialogIcon.None)
            {
                return(null);
            }

            value = InvariantString.Format(_iconUriScheme, value);
            return(base.ConvertFrom(context, culture, value));
        }
Example #3
0
        static TaskDialogIconConverter()
        {
            string assemblyName = typeof(TaskDialog).Assembly.FullName;

            assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(','));

            _iconUriScheme = InvariantString.Format("pack://application:,,,/{0};component/Images/{{0}}.ico", assemblyName);
        }
Example #4
0
        /// <summary>
        ///     Returns the <see cref="Type" /> value as evaluated for the requested type name and type arguments.
        /// </summary>
        /// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
        /// <returns>
        ///     The object value to set on the property where the extension is applied.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            if (_closedType == null)
            {
                if (_typeName == null && _type == null)
                {
                    throw new InvalidOperationException(SR.TypeExtension_TypeOrNameMissing);
                }

                Type   type          = _type;
                Type[] typeArguments = _typeArguments.TakeWhile(t => t != null).ToArray();

                if (type == null)
                {
                    // resolve using type name
                    // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                    IXamlTypeResolver typeResolver = serviceProvider != null
                        ? serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver
                        : null;

                    if (typeResolver == null)
                    {
                        throw new InvalidOperationException(SR.TypeExtension_NoIXamlTypeResolver);
                    }

                    // check that the number of generic arguments match
                    string typeName = TypeName;
                    if (typeArguments.Length > 0)
                    {
                        int genericsMarkerIndex = typeName.LastIndexOf('`');
                        if (genericsMarkerIndex < 0)
                        {
                            typeName = InvariantString.Format("{0}`{1}", typeName, typeArguments.Length);
                        }
                        else
                        {
                            bool validArgumentCount = false;
                            if (genericsMarkerIndex < typeName.Length)
                            {
                                int typeArgumentCount;
                                if (int.TryParse(typeName.Substring(genericsMarkerIndex + 1), out typeArgumentCount))
                                {
                                    validArgumentCount = true;
                                }
                            }

                            if (!validArgumentCount)
                            {
                                throw new InvalidOperationException(SR.TypeExtension_InvalidTypeNameArgumentCount);
                            }
                        }
                    }

                    type = typeResolver.Resolve(typeName);
                    if (type == null)
                    {
                        throw new InvalidOperationException(SR.TypeExtension_InvalidTypeName);
                    }
                }
                else if (type.IsGenericTypeDefinition && type.GetGenericArguments().Length != typeArguments.Length)
                {
                    throw new InvalidOperationException(SR.TypeExtension_InvalidTypeArgumentCount);
                }

                // build closed type
                if (typeArguments.Length > 0 && type.IsGenericTypeDefinition)
                {
                    _closedType = type.MakeGenericType(typeArguments);
                }
                else
                {
                    _closedType = type;
                }
            }

            return(_closedType);
        }
Example #5
0
 /// <summary>
 ///     Returns a <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </summary>
 /// <returns>
 ///     A <see cref="T:System.String" /> that represents the current <see cref="T:System.Object" />.
 /// </returns>
 public override string ToString()
 {
     return(InvariantString.Format("Header={0}, Content={1}", Header, Content));
 }