Пример #1
0
        private void ClearResFilesAll()
        {
            List <string> phyicialFiles = new List <string>();

            foreach (var ns in MvcApplication.Assemblys)
            {
                var reader = ResHelper.GetGResourcesReader(ns);
                if (reader == null)
                {
                    continue;
                }
                reader.Each(kv =>
                {
                    DictionaryEntry d = (DictionaryEntry)kv;
                    if (forbiddenTypes.Any(ft => d.Key.ToString().EndsWith(ft, StringComparison.OrdinalIgnoreCase)))
                    {
                        return;
                    }

                    string path = Path.Combine(rootPath, d.Key.ToString());
                    FileInfo fi = new FileInfo(path);
                    if (fi.Exists)
                    {
                        phyicialFiles.Add(fi.FullName);
                    }
                });

                reader.Close();
            }

            DeleteFiles(phyicialFiles, DateTime.Now.AddDays(1));
        }
Пример #2
0
        /// <summary>
        /// 将所有引用的程序集中的资源写回物理文件
        /// </summary>
        public void WriteResFiles()
        {
            if (rootPath.IsEmpty())
            {
                return;
            }
            ClearResFiles();

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

            foreach (var ns in MvcApplication.Assemblys)
            {
                var reader = ResHelper.GetGResourcesReader(ns);
                if (reader == null)
                {
                    continue;
                }
                reader.Each(kv =>
                {
                    DictionaryEntry d = (DictionaryEntry)kv;
                    if (forbiddenTypes.Any(ft => d.Key.ToString().EndsWith(ft, StringComparison.OrdinalIgnoreCase)))
                    {
                        return;
                    }

                    string path = Path.Combine(rootPath, d.Key.ToString());
                    FileInfo fi = new FileInfo(path);
                    if (!fi.Exists)
                    {
                        if (!fi.Directory.Exists)
                        {
                            fi.Directory.Create();
                        }
                        Stream stream = d.Value as Stream;
                        IOHelper.WriteStreamToFile(stream, path);
                        phyicialFiles.Add(path);
                    }
                });

                reader.Close();
            }
            //将写过的文件路径名记入一个文本文件
            File.WriteAllLines(logFile, phyicialFiles.ToArray());
            FileInfo logInfo = new FileInfo(logFile);
        }