Beispiel #1
0
        private void WriteDataSources(XmlWriter writer, DataSourceType sourceType,
                                      string baseInput, Version version, bool useDatabase,
                                      bool isSilverlight, string lang, IEnumerable <string> commentDirs)
        {
            if (baseInput == null)
            {
                baseInput = String.Empty;
            }
            if (lang == null)
            {
                lang = String.Empty;
            }

            BuildContext context = this.Context;
            BuildLogger  logger  = context.Logger;

            // We create the following format:
            // (BaseOutput)\(Source)\vVersion\Language
            // Eg: A:\Data\Comments\Framework\v4.0\en
            string outputDir = Path.GetFullPath(
                Environment.ExpandEnvironmentVariables(context.CommentDataDirectory));

            if (sourceType != DataSourceType.None)
            {
                outputDir = Path.Combine(outputDir, sourceType.ToString());

                // Blend SDK is separately available for Silverlight and WPF...
                if (sourceType == DataSourceType.Blend)
                {
                    if (isSilverlight)
                    {
                        outputDir = Path.Combine(outputDir, "Silverlight");
                    }
                    else
                    {
                        outputDir = Path.Combine(outputDir, "Wpf");
                    }
                }
            }
            if (version != null)
            {
                outputDir = Path.Combine(outputDir, "v" + version.ToString(2));
            }
            if (!String.IsNullOrEmpty(lang))
            {
                outputDir = Path.Combine(outputDir, lang);
            }
            if (!Directory.Exists(outputDir))
            {
                return;
            }

            string persistFile = Path.Combine(outputDir, DataSources.XmlFileName);

            if (!File.Exists(persistFile))
            {
                return;
            }
            DataSources dataSources = new DataSources(false);

            using (XmlReader reader = XmlReader.Create(persistFile))
            {
                reader.MoveToContent();
                dataSources.ReadXml(reader);
            }
            // Check for validity, there must be at least a source...
            if (!dataSources.IsValid || dataSources.SourceCount == 0)
            {
                return;
            }
            // Check for data source changes...
            int matchedCount = 0;

            foreach (string commentDir in commentDirs)
            {
                string finalDir = commentDir;
                if (!String.IsNullOrEmpty(lang))
                {
                    finalDir = Path.Combine(commentDir, lang);
                    if (!Directory.Exists(finalDir))
                    {
                        finalDir = commentDir;
                    }
                }

                if (dataSources.ContainsSource(finalDir))
                {
                    matchedCount++;
                }
            }

            if (matchedCount != dataSources.SourceCount)
            {
                if (logger != null)
                {
                    logger.WriteLine(String.Format(
                                         "WriteDataSources: There is a change in the data sources for {0}, version {1}. Update the persistent database.",
                                         sourceType, version), BuildLoggerLevel.Warn);
                }
            }

            dataSources.WriteXml(writer);
        }