Пример #1
0
        public override ReferenceSource Clone()
        {
            ReferenceVersionSource source = new ReferenceVersionSource(this);

            this.Clone(source);

            if (this.Title != null)
            {
                source.Title = String.Copy(this.Title);
            }
            if (_sourceId != null)
            {
                source._sourceId = String.Copy(_sourceId);
            }
            if (_versionLabel != null)
            {
                source._versionLabel = String.Copy(_versionLabel);
            }
            if (_versionId != null)
            {
                source._versionId = String.Copy(_versionId);
            }
            if (_content != null)
            {
                source._content = _content.Clone();
            }

            return(source);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ReferenceVersionSource"/> class
 /// with parameters copied from the specified instance of the
 /// <see cref="ReferenceVersionSource"/> class, a copy constructor.
 /// </summary>
 /// <param name="source">
 /// An instance of the <see cref="ReferenceVersionSource"/> class from which the
 /// initialization parameters or values will be copied.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If the parameter <paramref name="source"/> is <see langword="null"/>.
 /// </exception>
 public ReferenceVersionSource(ReferenceVersionSource source)
     : base(source)
 {
     _content      = source._content;
     _sourceId     = source._sourceId;
     _versionId    = source._versionId;
     _versionLabel = source._versionLabel;
 }
Пример #3
0
        public bool ContainsSource(ReferenceVersionSource source)
        {
            if (source == null || _listSources == null || _listSources.Count == 0)
            {
                return(false);
            }

            return(_listSources.Contains(source));
        }
Пример #4
0
        public void RemoveSource(ReferenceVersionSource source)
        {
            BuildExceptions.NotNull(source, "source");

            if (_listSources == null || _listSources.Count == 0)
            {
                return;
            }

            _listSources.Remove(source);
        }
Пример #5
0
        public void AddSource(ReferenceVersionSource source)
        {
            BuildExceptions.NotNull(source, "source");

            if (_listSources == null)
            {
                _listSources = new BuildKeyedList <ReferenceVersionSource>();
            }

            _listSources.Add(source);
        }
Пример #6
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, String.Format(
                                 "The element name '{0}' does not match the expected '{1}'.",
                                 reader.Name, TagName));
                return;
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            if (_listSources == null)
            {
                _listSources = new BuildKeyedList <ReferenceVersionSource>();
            }
            if (_listRelated == null)
            {
                _listRelated = new BuildKeyedList <ReferenceVersionRelated>();
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, "propertyGroup",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                if (String.Equals(reader.Name, "property",
                                                  StringComparison.OrdinalIgnoreCase))
                                {
                                    string tempText = null;
                                    switch (reader.GetAttribute("name").ToLower())
                                    {
                                    case "platformid":
                                        _platformId = reader.ReadString();
                                        break;

                                    case "platformtitle":
                                        _platformTitle = reader.ReadString();
                                        break;

                                    case "platformfilters":
                                        tempText = reader.ReadString();
                                        if (!String.IsNullOrEmpty(tempText))
                                        {
                                            _platformFilters = Convert.ToBoolean(tempText);
                                        }
                                        break;

                                    case "versionid":
                                        _versionId = reader.ReadString();
                                        break;

                                    case "versionlabel":
                                        _versionLabel = reader.ReadString();
                                        break;

                                    case "ripoldapis":
                                        tempText = reader.ReadString();
                                        if (!String.IsNullOrEmpty(tempText))
                                        {
                                            _ripOldApis = Convert.ToBoolean(tempText);
                                        }
                                        break;

                                    default:
                                        // Should normally not reach here...
                                        throw new NotImplementedException(reader.GetAttribute("name"));
                                    }
                                }
                            }
                            else if (reader.NodeType == XmlNodeType.EndElement)
                            {
                                if (String.Equals(reader.Name, "propertyGroup",
                                                  StringComparison.OrdinalIgnoreCase))
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else if (String.Equals(reader.Name, ReferenceSource.TagName,
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        ReferenceVersionSource versionSource =
                            new ReferenceVersionSource();

                        versionSource.ReadXml(reader);

                        _listSources.Add(versionSource);
                    }
                    else if (String.Equals(reader.Name, ReferenceVersionRelated.TagName,
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        ReferenceVersionRelated relatedVersion =
                            new ReferenceVersionRelated();

                        relatedVersion.ReadXml(reader);

                        _listRelated.Add(relatedVersion);
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
Пример #7
0
        private bool CreatePlatformFilter(XmlWriter writer,
                                          ReferenceVersionSource versionSource, string apiVersionsDir)
        {
            string reflectionFile = Path.Combine(apiVersionsDir,
                                                 versionSource.SourceId + ".xml");

            if (!File.Exists(reflectionFile))
            {
                return(false);
            }

            XPathDocument  document          = new XPathDocument(reflectionFile);
            XPathNavigator documentNavigator = document.CreateNavigator();
            XPathNavigator rootNavigator     = documentNavigator.SelectSingleNode(
                "reflection/apis");

            if (rootNavigator == null)
            {
                return(false);
            }

            // Select the namespaces...
            XPathNodeIterator iterator = rootNavigator.Select(
                "api[starts-with(@id, 'N:')]");

            if (iterator == null || iterator.Count == 0)
            {
                return(false);
            }

            foreach (XPathNavigator navigator in iterator)
            {
                writer.WriteStartElement("platform");

                // NOTE: Handling of the platform id for a successful build
                // is the most confusing part of this write process.
                // With the exception of the .NET Framework platform, all others
                // must be marked with a defined term, which indicates its use...
                switch (_platformId)
                {
                case "netcfw":                 // .NET Compact Framework
                    writer.WriteAttributeString("name",
                                                "WindowsCE," + _platformId);
                    break;

                case "xnafw":                  // XNA Framework
                    writer.WriteAttributeString("name",
                                                "Xbox360," + _platformId);
                    break;

                case "silverlight":            // Silverlight
                case "silverlight_mobile":     // Silverlight for Windows Phone
                    writer.WriteAttributeString("name",
                                                "SilverlightPlatforms," + _platformId);
                    break;

                case "netfw":                  // .NET Framework
                default:
                    writer.WriteAttributeString("name", _platformId);
                    break;
                }
                writer.WriteAttributeString("version", versionSource.VersionId);

                CreateNamespaceFilter(writer, navigator, rootNavigator);

                writer.WriteEndElement();
            }

            return(true);
        }
Пример #8
0
        public bool WritePlatformFile(BuildContext context, string apiVersionsDir)
        {
            BuildExceptions.NotNull(context, "context");
            BuildExceptions.PathMustExist(apiVersionsDir, "apiVersionsDir");
            Debug.Assert(_sourceIndex >= 0, "The platform source index is not set");
            //Debug.Assert(_groupIndex >= 0, "The platform group index is not set");
            Debug.Assert(_listSources != null && _listSources.Count != 0,
                         "The platform does not contain any version source.");

            BuildLogger logger = context.Logger;

            if (_sourceIndex < 0)
            {
                if (logger != null)
                {
                    logger.WriteLine("The platform source index is not set.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            if (_listSources == null || _listSources.Count == 0)
            {
                if (logger != null)
                {
                    logger.WriteLine("The platform does not contain any version source.",
                                     BuildLoggerLevel.Error);
                }

                return(false);
            }

            bool isSuccessful = true;

            string platformFile = null;

            // If there is a group index...
            if (_groupIndex >= 0)
            {
                // We write platform filter file name like ApiPlatform1a.xml,
                // ApiPlatform1b.xml, ApiPlatform1c.xml etc
                // "97" is the integer value of the letter "a".
                platformFile = Path.Combine(context.WorkingDirectory,
                                            String.Format("ApiPlatform{0}{1}.xml", _groupIndex,
                                                          Convert.ToChar(97 + _sourceIndex)));
            }
            else
            {
                // We write platform filter file name like ApiPlatformA.xml,
                // ApiPlatformB.xml, ApiPlatformC.xml etc
                // "65" is the integer value of the letter "A".
                platformFile = Path.Combine(context.WorkingDirectory,
                                            String.Format("ApiPlatform{0}.xml", Convert.ToChar(65 + _sourceIndex)));
            }

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(platformFile, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("platforms");

                for (int i = 0; i < _listSources.Count; i++)
                {
                    ReferenceVersionSource versionSource = _listSources[i];

                    isSuccessful = this.CreatePlatformFilter(writer,
                                                             versionSource, apiVersionsDir);
                    if (!isSuccessful)
                    {
                        break;
                    }
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

            if (isSuccessful)
            {
                _platformFile = platformFile;
            }

            return(isSuccessful);
        }
Пример #9
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }

            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                Debug.Assert(false, String.Format(
                                 "The element name '{0}' does not match the expected '{1}'.",
                                 reader.Name, TagName));
                return;
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            if (_listSources == null)
            {
                _listSources = new BuildKeyedList <ReferenceVersionSource>();
            }

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, "propertyGroup",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        while (reader.Read())
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                if (String.Equals(reader.Name, "property",
                                                  StringComparison.OrdinalIgnoreCase))
                                {
                                    switch (reader.GetAttribute("name").ToLower())
                                    {
                                    case "platformid":
                                        _platformId = reader.ReadString();
                                        break;

                                    case "platformtitle":
                                        _platformTitle = reader.ReadString();
                                        break;

                                    default:
                                        // Should normally not reach here...
                                        throw new NotImplementedException(reader.GetAttribute("name"));
                                    }
                                }
                            }
                            else if (reader.NodeType == XmlNodeType.EndElement)
                            {
                                if (String.Equals(reader.Name, "propertyGroup",
                                                  StringComparison.OrdinalIgnoreCase))
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else if (String.Equals(reader.Name, ReferenceSource.TagName,
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        string sourceName = reader.GetAttribute("name");
                        if (String.Equals(sourceName, ReferenceVersionSource.SourceName,
                                          StringComparison.OrdinalIgnoreCase))
                        {
                            ReferenceVersionSource source = new ReferenceVersionSource();

                            source.ReadXml(reader);

                            _listSources.Add(source);
                        }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, TagName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }