Пример #1
0
        public void RefreshPublishFiles()
        {
            string basePath = Path.GetDirectoryName(this.FileName);
            string distPath = pubSettings.DistributionPath;

            if (!Directory.Exists(distPath))
            {
                return;
            }

            List <string> fileNames = new List <string>();

            getFileNames(fileNames, distPath);

            ItemGroup itemGroupContents     = items.Groups["Content"];
            ItemGroup itemGroupPublishFiles = items.Groups["PublishFile"];

            foreach (string file in fileNames)
            {
                string fullName = Path.GetFullPath(file);
                string include  = Sense.Utils.IO.Path.GetRelativePath(basePath, fullName);
                string link     = Sense.Utils.IO.Path.GetRelativePath(distPath, fullName);
                if (!itemGroupContents.ContainsKey(fullName))
                {
                    ContentItem item = new ContentItem(basePath, include, link);
                    item.CopyToOutputDirectory = "PreserveNewest";
                    itemGroupContents.Add(item);
                }
                if (!itemGroupPublishFiles.ContainsKey(link))
                {
                    PublishFileItem item = new PublishFileItem(link);
                    item.Visible      = false;
                    item.Group        = "";
                    item.TargetPath   = "";
                    item.PublishState = PublishState.Include;
                    item.IncludeHash  = true;
                    item.FileType     = "File";
                    itemGroupPublishFiles.Add(item);
                }
            }
            List <string> removes = new List <string>();

            foreach (string fullName in itemGroupContents.GetKeys())
            {
                if (!fileNames.Contains(fullName))
                {
                    removes.Add(fullName);
                }
            }
            foreach (string fullName in removes)
            {
                if (itemGroupContents.ContainsKey(fullName))
                {
                    itemGroupContents.Remove(fullName);
                }
            }
            removes.Clear();
            foreach (string item in itemGroupPublishFiles.GetKeys())
            {
                bool found = false;
                foreach (ContentItem contentItem in itemGroupContents)
                {
                    string include = null;
                    if (contentItem.NeedLinkNode(basePath))
                    {
                        include = contentItem.Link;
                    }
                    else
                    {
                        include = contentItem.GetInclude(basePath);
                    }

                    if (item == include)
                    {
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    continue;
                }
                removes.Add(item);
            }
            foreach (string item in removes)
            {
                if (itemGroupPublishFiles.ContainsKey(item))
                {
                    itemGroupPublishFiles.Remove(item);
                }
            }
        }