UserDefinedOpenWithFileViewer ReadUserDefinedFileViewer(DisplayBindingMappingKey key, XmlTextReader reader)
        {
            string application = null;
            string displayName = null;
            string arguments   = null;
            bool?  isDefault   = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case "Application":
                        application = reader.ReadElementContentAsString();
                        if (CanCreateUserDefinedFileViewer(application, displayName, arguments, isDefault))
                        {
                            return(CreateUserDefinedFileViewer(key, application, displayName, arguments, isDefault.Value));
                        }
                        break;

                    case "Arguments":
                        arguments = reader.ReadElementContentAsString();
                        if (CanCreateUserDefinedFileViewer(application, displayName, arguments, isDefault))
                        {
                            return(CreateUserDefinedFileViewer(key, application, displayName, arguments, isDefault.Value));
                        }
                        break;

                    case "DisplayName":
                        displayName = reader.ReadElementContentAsString();
                        if (CanCreateUserDefinedFileViewer(application, displayName, arguments, isDefault))
                        {
                            return(CreateUserDefinedFileViewer(key, application, displayName, arguments, isDefault.Value));
                        }
                        break;

                    case "IsDefault":
                        string isDefaultText = reader.ReadElementContentAsString();
                        isDefault = bool.Parse(isDefaultText);
                        if (CanCreateUserDefinedFileViewer(application, displayName, arguments, isDefault))
                        {
                            return(CreateUserDefinedFileViewer(key, application, displayName, arguments, isDefault.Value));
                        }
                        break;

                    default:
                        throw new ApplicationException("Unsupported element found when looking for UserDefinedFileViewer");
                    }
                    break;
                }
            }

            throw new ApplicationException("UserDefinedFileViewer not found.");
        }
        UserDefinedOpenWithFileViewer CreateUserDefinedFileViewer(
            DisplayBindingMappingKey key,
            string application,
            string displayName,
            string arguments,
            bool isDefault)
        {
            var app        = DesktopApplicationFactory.CreateApplication(application, arguments, displayName);
            var fileViewer = new UserDefinedOpenWithFileViewer(app);

            if (isDefault)
            {
                fileViewer.SetAsDefault();
            }

            return(fileViewer);
        }
        DisplayBindingMappingKey GetKey(XmlTextReader reader)
        {
            string extension = reader.GetAttribute("extension");
            string mimeType  = reader.GetAttribute("mimeType");

            string isApplicationText    = reader.GetAttribute("isApplication");
            string isDisplayBindingText = reader.GetAttribute("isDisplayBinding");

            var key = new DisplayBindingMappingKey(extension, mimeType);

            if (!string.IsNullOrEmpty(isApplicationText))
            {
                key.IsApplication = bool.Parse(isApplicationText);
            }

            if (!string.IsNullOrEmpty(isDisplayBindingText))
            {
                key.IsDisplayBinding = bool.Parse(isDisplayBindingText);
            }

            return(key);
        }
 void AddDefaultMapping(DisplayBindingMappingKey key, string displayBinding)
 {
     mappings [key] = displayBinding;
 }