void PopulateXmlSchemaFileAssociationList()
 {
     foreach (string extension in xmlFileExtensions)
     {
         XmlSchemaFileAssociation         association = associations.GetSchemaFileAssociation(extension);
         XmlSchemaFileAssociationListItem item        = new XmlSchemaFileAssociationListItem(extension, association.NamespaceUri, association.NamespacePrefix);
         schemasPanel.AddXmlSchemaFileAssociationListItem(item);
     }
     schemasPanel.AddXmlSchemaFileAssociationListSortDescription("Extension", ListSortDirection.Ascending);
 }
        public XmlSchemaCompletion GetSchemaCompletion(string fileName)
        {
            XmlSchemaFileAssociation association = GetSchemaFileAssociation(fileName);
            XmlSchemaCompletion      schema      = schemas[association.NamespaceUri];

            if (schema != null)
            {
                schema.DefaultNamespacePrefix = association.NamespacePrefix;
            }
            return(schema);
        }
 void UpdateXmlSchemaFileAssociations()
 {
     for (int i = 0; i < schemasPanel.XmlSchemaFileAssociationListItemCount; ++i)
     {
         XmlSchemaFileAssociationListItem item = schemasPanel.GetXmlSchemaFileAssociationListItem(i);
         if (item.IsDirty)
         {
             XmlSchemaFileAssociation association = new XmlSchemaFileAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix);
             associations.SetSchemaFileAssociation(association);
         }
     }
 }
        /// <summary>
        /// Gets an association between a schema and a file extension.
        /// </summary>
        public XmlSchemaFileAssociation GetSchemaFileAssociation(string fileName)
        {
            string extension = Path.GetExtension(fileName).ToLowerInvariant();
            string property  = properties.Get("ext" + extension, String.Empty);
            XmlSchemaFileAssociation schemaFileAssociation = XmlSchemaFileAssociation.ConvertFromString(property);

            if (schemaFileAssociation.IsEmpty)
            {
                return(defaultSchemaFileAssociations.Find(extension));
            }
            return(schemaFileAssociation);
        }
        /// <summary>
        /// Two schema associations are considered equal if their file extension,
        /// prefix and namespaceUri are the same.
        /// </summary>
        public override bool Equals(object obj)
        {
            XmlSchemaFileAssociation rhs = obj as XmlSchemaFileAssociation;

            if (rhs != null)
            {
                return((this.namespacePrefix == rhs.NamespacePrefix) &&
                       (this.fileExtension == rhs.fileExtension) &&
                       (this.namespaceUri == rhs.namespaceUri));
            }
            return(false);
        }
		public void RegisteredSchemaAssociationMatchedByFullFileNameInsteadOfExtension()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".abc", "namespace-uri", "prefix");
			properties.Set("ext.abc", ".abc|namespace-uri|prefix");
			Assert.AreEqual(expectedSchemaAssociation, associations.GetSchemaFileAssociation(@"d:\projects\a.abc"));
		}
		public void RegisteredSchemaAssociationMatchedByFileExtensionIsCaseInsensitive()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".abc", "namespace-uri", "prefix");
			properties.Set("ext.abc", ".abc|namespace-uri|prefix");
			Assert.AreEqual(expectedSchemaAssociation, associations.GetSchemaFileAssociation(".ABC"));
		}
		public void DoNotMatchNamespacesDifferent()
		{
			XmlSchemaFileAssociation lhs = new XmlSchemaFileAssociation("ext", "namespaceUri", "prefix");
			XmlSchemaFileAssociation rhs = new XmlSchemaFileAssociation("ext", "different-namespaceUri", "prefix");
			Assert.IsFalse(lhs.Equals(rhs));
		}
		public void SchemaAssociationWithPrefixConvertedToString()
		{
			XmlSchemaFileAssociation schemaAssocation = new XmlSchemaFileAssociation(".xml", "namespaceUri", "prefix");
			Assert.AreEqual(".xml|namespaceUri|prefix", schemaAssocation.ToString());
		}	
		public void NamespacePrefixModifiesXmlSchemaFileAssociation()
		{
			panel.SetSelectedSchemaNamespacePrefix("modified-prefix");
			schemasEditor.SchemaNamespacePrefixChanged();
			schemasEditor.SaveOptions();
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".bar", "http://bar", "modified-prefix");
			
			Assert.AreEqual(expectedSchemaAssociation, associations.GetSchemaFileAssociation(".bar"));
		}
		public void SchemaAssociationWithFileExtensionIsNotEmpty()
		{
			XmlSchemaFileAssociation schemaAssociation = new XmlSchemaFileAssociation(".fileExt", String.Empty, String.Empty);
			Assert.IsFalse(schemaAssociation.IsEmpty);
		}
 public void FileExtensionConvertedFromString()
 {
     XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation("ext", String.Empty);
     XmlSchemaFileAssociation schemaAssociation = XmlSchemaFileAssociation.ConvertFromString("ext||");
     Assert.AreEqual(expectedSchemaAssociation, schemaAssociation);
 }
 public void FileExtensionAndNamespaceUriConvertedFromString()
 {
     XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation("ext", "namespace-uri");
     XmlSchemaFileAssociation schemaAssociation = XmlSchemaFileAssociation.ConvertFromString("ext|namespace-uri|");
     Assert.AreEqual(expectedSchemaAssociation, schemaAssociation);
 }
 public void EmpyStringConverted()
 {
     XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(String.Empty, String.Empty);
     Assert.AreEqual(expectedSchemaAssociation, XmlSchemaFileAssociation.ConvertFromString(String.Empty));
 }
 public void SetSchemaFileAssociation(XmlSchemaFileAssociation association)
 {
     properties.Set("ext" + association.FileExtension, association.ToString());
 }
		public void FileExtensionIsLowerCased()
		{
			XmlSchemaFileAssociation schemaAssociation = new XmlSchemaFileAssociation(".XML", String.Empty);
			Assert.AreEqual(".xml", schemaAssociation.FileExtension);
		}
		public void DefaultXmlExtensionRevertedToIfNoFileExtensionSavedInXmlEditorOptionsProperties()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".xml", "http://example.com", "e");
			Assert.AreEqual(expectedSchemaAssociation, associations.GetSchemaFileAssociation(".xml"));
		}
		public void SchemaAssociationWithNamespacePrefixIsNotEmpty()
		{
			XmlSchemaFileAssociation schemaAssociation = new XmlSchemaFileAssociation(String.Empty, String.Empty, "prefix");
			Assert.IsFalse(schemaAssociation.IsEmpty);
		}		
		public void SchemaAssociationWithBlankFileExtensionAndNamespaceUriAndNamespacePrefixIsEmpty()
		{
			XmlSchemaFileAssociation schemaAssociation = new XmlSchemaFileAssociation(String.Empty, String.Empty, String.Empty);
			Assert.IsTrue(schemaAssociation.IsEmpty);
		}
		public void SecondSchemaAssociationIsForXslFiles()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".xsl", "http://example.com/xsl", "xs");
			Assert.AreEqual(expectedSchemaAssociation, schemaAssociations[1]);
		}
		public void SchemaAssociationWithNamespaceUriIsNotEmpty()
		{
			XmlSchemaFileAssociation schemaAssociation = new XmlSchemaFileAssociation(String.Empty, "namespace-uri", String.Empty);
			Assert.IsFalse(schemaAssociation.IsEmpty);
		}
		public void SetSchemaFileAssociation(XmlSchemaFileAssociation association)
		{
			properties.Set("ext" + association.FileExtension, association.ToString());
		}
		public void FirstSchemaAssociationIsForXmlFiles()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".xml", "http://example.com", String.Empty);
			Assert.AreEqual(expectedSchemaAssociation, schemaAssociations[0]);
		}
		public void UnknownFileExtensionReturnsEmptySchemaAssociation()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(String.Empty, String.Empty, String.Empty);
			Assert.AreEqual(expectedSchemaAssociation, associations.GetSchemaFileAssociation(".unknown"));
		}
		public void FindSchemaAssociationByFileExtensionIsCaseInsensitive()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".xsl", "http://example.com/xsl", "xs");
			Assert.AreEqual(expectedSchemaAssociation, schemaAssociations.Find(".XSL"));
		}	
		public void RegisteredSchemaAssociationReturnedByXmlEditorOptions()
		{
			XmlSchemaFileAssociation expectedSchemaAssociation = new XmlSchemaFileAssociation(".abc", "namespace-uri", "prefix");
			properties.Set("ext.abc", ".abc|namespace-uri|prefix");
			Assert.AreEqual(expectedSchemaAssociation, associations.GetSchemaFileAssociation(".abc"));
		}
		public void MatchIfFileExtensionAndNamespaceUriAndPrefixMatch()
		{
			XmlSchemaFileAssociation lhs = new XmlSchemaFileAssociation("ext", "namespaceUri", "prefix");
			XmlSchemaFileAssociation rhs = new XmlSchemaFileAssociation("ext", "namespaceUri", "prefix");
			Assert.IsTrue(lhs.Equals(rhs));
		}
		public void RegisteredSchemaAssociationStoredInProperties()
		{
			XmlSchemaFileAssociation schemaAssociation = new XmlSchemaFileAssociation(".abc", "namespace-uri", "prefix");
			associations.SetSchemaFileAssociation(schemaAssociation);
			Assert.AreEqual(".abc|namespace-uri|prefix", properties.Get("ext.abc", String.Empty));
		}
		public void DoesNotMatchAStringObject()
		{
			XmlSchemaFileAssociation lhs = new XmlSchemaFileAssociation("ext", "namespaceUri", "prefix");
			Assert.IsFalse(lhs.Equals("String"));
		}
		void UpdateXmlSchemaFileAssociations()
		{
			for (int i = 0; i < schemasPanel.XmlSchemaFileAssociationListItemCount; ++i) {
				XmlSchemaFileAssociationListItem item = schemasPanel.GetXmlSchemaFileAssociationListItem(i);
				if (item.IsDirty) {
					XmlSchemaFileAssociation association = new XmlSchemaFileAssociation(item.Extension, item.NamespaceUri, item.NamespacePrefix);
					associations.SetSchemaFileAssociation(association);
				}
			}
		}