Exemplo n.º 1
0
        private static void UpdateBundle(string changedFile, bool isBuild)
        {
            bool isDir = Directory.Exists(changedFile);

            string dir = isDir ? changedFile : ProjectHelpers.GetProjectFolder(changedFile);

            if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir))
            {
                return;
            }

            foreach (string file in Directory.GetFiles(dir, "*" + _ext, SearchOption.AllDirectories))
            {
                if (_ignoreFolders.Any(p => file.IndexOf("\\" + p + "\\", StringComparison.OrdinalIgnoreCase) > -1))
                {
                    continue;
                }

                XmlDocument doc           = GetXmlDocument(file);
                var         bundleFileDir = Path.GetDirectoryName(file);
                bool        enabled       = false;

                if (doc != null)
                {
                    XmlNode bundleNode = doc.SelectSingleNode("//bundle");
                    if (bundleNode == null)
                    {
                        continue;
                    }

                    XmlNodeList nodes = doc.SelectNodes("//file");
                    foreach (XmlNode node in nodes)
                    {
                        string relative = node.InnerText;
                        string absolute = ProjectHelpers.ToAbsoluteFilePath(relative, dir, bundleFileDir);

                        if (changedFile != null && absolute.Equals(ProjectHelpers.FixAbsolutePath(changedFile), StringComparison.OrdinalIgnoreCase))
                        {
                            enabled = true;
                            break;
                        }
                    }

                    if (isBuild && bundleNode.Attributes["runOnBuild"] != null && bundleNode.Attributes["runOnBuild"].InnerText == "true")
                    {
                        enabled = true;
                    }

                    if (enabled)
                    {
                        WriteBundleFile(file, doc);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private async static Threading.Task UpdateBundle(string changedFile, bool isBuild)
        {
            string absolutePath = ProjectHelpers.FixAbsolutePath(changedFile);
            bool   isDir        = Directory.Exists(changedFile);
            string dir          = isDir ? changedFile : ProjectHelpers.GetProjectFolder(changedFile);

            if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir))
            {
                return;
            }

            foreach (string file in Directory.EnumerateFiles(dir, "*" + _ext, SearchOption.AllDirectories))
            {
                if (_ignoreFolders.Any(p => file.Contains("\\" + p + "\\")))
                {
                    continue;
                }

                XmlDocument doc = await GetXmlDocument(file);

                if (doc == null)
                {
                    continue;
                }

                XmlNode bundleNode = doc.SelectSingleNode("//bundle");

                if (bundleNode == null)
                {
                    continue;
                }

                string baseDir = Path.GetDirectoryName(file);

                if ((changedFile != null && doc.SelectNodes("//file").Cast <XmlNode>().Any(x =>
                                                                                           absolutePath == ProjectHelpers.ToAbsoluteFilePath(x.InnerText, dir, baseDir))) ||
                    (isBuild && bundleNode.Attributes["runOnBuild"] != null &&
                     bundleNode.Attributes["runOnBuild"].InnerText == "true"))
                {
                    WriteBundleFile(file, doc).DoNotWait("reading " + file + " file");
                }
            }
        }