Пример #1
0
 public void Excute()
 {
     if (Sender is ISingleFileResource)
     {
         ISingleFileResource resource = (ISingleFileResource)Sender;
         File.Delete(resource.FullName);
     }
     if (Sender is ISingleFolderResource)
     {
         ISingleFolderResource resource = (ISingleFolderResource)Sender;
         Directory.Delete(resource.FolderPath);
     }
     if (Sender is IMultiFileResource)
     {
         IMultiFileResource resource = (IMultiFileResource)Sender;
         File.Delete(resource.MainFilePath);
         if (resource.OtherFilePath.Count > 0)
         {
             foreach (string filePath in resource.OtherFilePath)
             {
                 File.Delete(filePath);
             }
         }
     }
     if (Sender is IMultiFolderResource)
     {
         IMultiFolderResource resource = (IMultiFolderResource)Sender;
         Directory.Delete(resource.MainFolder);
         if (resource.OtherFolders.Count > 0)
         {
             foreach (string folderPath in resource.OtherFolders)
             {
                 Directory.Delete(folderPath);
             }
         }
     }
     if (Sender is IMixedFileFoldResource)
     {
         IMixedFileFoldResource resource = (IMixedFileFoldResource)Sender;
         File.Delete(resource.MainPath);
         if (resource.OtherFolderPaths.Count > 0)
         {
             foreach (string folderPath in resource.OtherFolderPaths)
             {
                 Directory.Delete(folderPath);
             }
         }
         if (resource.OtherFilePaths.Count > 0)
         {
             foreach (string filePath in resource.OtherFilePaths)
             {
                 File.Delete(filePath);
             }
         }
     }
 }
Пример #2
0
        public IList <IResource> GetLocalResource(string directoryPath, IList <IResourceMetaData> metaDataFilter, out IList <string> restDirs, out IList <string> restFiles)
        {
            IList <IResource> resources = new List <IResource>();

            restDirs  = new List <string>();
            restFiles = new List <string>();
            string[] dirs       = Directory.GetDirectories(directoryPath);
            string[] files      = Directory.GetFiles(directoryPath);
            bool[]   dirStatus  = null;
            bool[]   fileStatus = null;
            if (dirs.Length > 0)
            {
                dirStatus = new bool[dirs.Length];
                foreach (IResourceMetaData metaData in metaDataFilter)
                {
                    if (metaData.ResourceStorageMode == ResourceStorageMode.SingleFolder &&
                        metaData is ISingleFolderResourceMetaData)
                    {
                        var singleFolderResourceMetaData = metaData as ISingleFolderResourceMetaData;
                        for (int i = 0; i < dirs.Length; i++)
                        {
                            if (singleFolderResourceMetaData.Identified(dirs[i]))
                            {
                                dirStatus[i] = true;
                                ISingleFolderResource resource = iocManager.Resolve(singleFolderResourceMetaData.ResourceType.Type) as ISingleFolderResource;
                                resource.Caption    = Path.GetFileName(dirs[i]);
                                resource.FolderPath = dirs[i];
                                resources.Add(resource);
                                // items.Add(new ResourceItem(dirs[i], resource));
                            }
                        }
                    }
                    else if (metaData.ResourceStorageMode == ResourceStorageMode.MultiFolder &&
                             metaData is IMultiFolderResourceMetaData)
                    {
                        var multiFolderResourceMetaData = metaData as IMultiFolderResourceMetaData;
                        for (int i = 0; i < dirs.Length; i++)
                        {
                            if (multiFolderResourceMetaData.Identified(dirs[i]))
                            {
                                dirStatus[i] = true;
                                var otherFolders = multiFolderResourceMetaData.FindOtherFolders(dirs[i]);
                                if (otherFolders.Count > 0)
                                { //设置otherFolder 的状态
                                    foreach (string f in otherFolders)
                                    {
                                        for (int j = 0; j < dirs.Length; j++)
                                        {
                                            if (dirs[j].Equals(f))
                                            {
                                                dirStatus[j] = true;
                                            }
                                        }
                                    }
                                }
                                IMultiFolderResource resource = iocManager.Resolve(multiFolderResourceMetaData.ResourceType.Type) as IMultiFolderResource;
                                resource.Caption      = Path.GetFileName(dirs[i]);
                                resource.MainFolder   = dirs[i];
                                resource.OtherFolders = otherFolders;
                                resources.Add(resource);
                                //items.Add(new ResourceItem(dirs[i], resource));
                            }
                        }
                    }
                }
            }
            if (files.Length > 0)
            {
                fileStatus = new bool[files.Length];
                foreach (IResourceMetaData metaData in metaDataFilter)
                {
                    if (metaData.ResourceStorageMode == ResourceStorageMode.SingleFile &&
                        metaData is ISingleFileResourceMetaData)
                    {
                        var singleFileResourceMetaData = metaData as ISingleFileResourceMetaData;
                        for (int i = 0; i < files.Length; i++)
                        {
                            if (singleFileResourceMetaData.Identified(files[i]))
                            {
                                fileStatus[i] = true;
                                ISingleFileResource resource = iocManager.Resolve(singleFileResourceMetaData.ResourceType.Type) as ISingleFileResource;
                                resource.Caption  = Path.GetFileName(files[i]);
                                resource.FullName = files[i];
                                resources.Add(resource);
                                //items.Add(new ResourceItem(files[i], resource));
                            }
                        }
                    }
                    else if (metaData.ResourceStorageMode == ResourceStorageMode.MultiFile &&
                             metaData is IMultiFileResourceMetaData)
                    {
                        var muiltFileResourceMetaData = metaData as IMultiFileResourceMetaData;
                        for (int i = 0; i < files.Length; i++)
                        {
                            if (muiltFileResourceMetaData.Identified(files[i]))
                            {
                                fileStatus[i] = true;
                                var otherFiles = muiltFileResourceMetaData.FindOtherFiles(files[i]);
                                if (otherFiles.Count > 0)
                                {//设置otherFile 的状态
                                    foreach (string f in otherFiles)
                                    {
                                        for (int j = 0; j < files.Length; j++)
                                        {
                                            if (files[j].Equals(f))
                                            {
                                                fileStatus[j] = true;
                                            }
                                        }
                                    }
                                }
                                IMultiFileResource resource = iocManager.Resolve(muiltFileResourceMetaData.ResourceType.Type) as IMultiFileResource;
                                resource.Caption       = Path.GetFileName(files[i]);
                                resource.MainFilePath  = files[i];
                                resource.OtherFilePath = otherFiles;
                                resources.Add(resource);
                                //items.Add(new ResourceItem(files[i], resource));
                            }
                        }
                    }
                    else if (metaData.ResourceStorageMode == ResourceStorageMode.MixedFileFold &&
                             metaData is IMixedFileFoldResourceMetaData)
                    { //文件和文件夹混合
                        var mixedFileFoldResourceMetaData = metaData as IMixedFileFoldResourceMetaData;
                        for (int i = 0; i < files.Length; i++)
                        {
                            if (mixedFileFoldResourceMetaData.Identified(files[i]))
                            {
                                fileStatus[i] = true;
                                var otherfiles   = mixedFileFoldResourceMetaData.FindOtherFiles(files[i]);
                                var otherFolders = mixedFileFoldResourceMetaData.FindOtherFolders(files[i]);
                                if (otherfiles.Count > 0)
                                {//设置otherFile 的状态
                                    foreach (string f in otherfiles)
                                    {
                                        for (int j = 0; j < files.Length; j++)
                                        {
                                            if (files[j].Equals(f))
                                            {
                                                fileStatus[j] = true;
                                            }
                                        }
                                    }
                                }
                                if (otherFolders.Count > 0)
                                { //设置otherFolder 的状态
                                    foreach (string f in otherFolders)
                                    {
                                        for (int j = 0; j < dirs.Length; j++)
                                        {
                                            if (dirs[j].Equals(f))
                                            {
                                                dirStatus[j] = true;
                                            }
                                        }
                                    }
                                }
                                IMixedFileFoldResource resource = iocManager.Resolve(mixedFileFoldResourceMetaData.ResourceType.Type) as IMixedFileFoldResource;
                                resource.Caption          = Path.GetFileName(files[i]);
                                resource.MainPath         = files[i];
                                resource.OtherFilePaths   = otherfiles;
                                resource.OtherFolderPaths = otherFolders;
                                resources.Add(resource);
                                //items.Add(new ResourceItem(files[i], resource));
                            }
                        }
                    }
                }
            }
            for (int k = 0; k < dirs.Length; k++)
            {
                if (!dirStatus[k])
                {
                    //items.Add(new DirectoryItem(dirs[k]));
                    restDirs.Add(dirs[k]);
                }
            }
            for (int k = 0; k < files.Length; k++)
            {
                if (!fileStatus[k])
                {
                    restFiles.Add(files[k]);
                }
            }
            return(resources);
        }
Пример #3
0
        public override List <Item> GetDirectories()
        {
            List <Item> items = new List <Item>(10);

            try
            {
                if (Directory.Exists(FullName))
                {
                    string[] dirs  = Directory.GetDirectories(FullName);
                    string[] files = Directory.GetFiles(FullName);
                    if (MetaDataFilter == null || MetaDataFilter.Count == 0) //不顾虑
                    {
                        foreach (string dir in dirs)
                        {
                            var attributes = File.GetAttributes(dir);
                            if ((attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                            {
                                items.Add(new DirectoryItem(dir));
                            }
                        }
                        foreach (string file in files)
                        {
                            var attributes = File.GetAttributes(file);
                            if ((attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                            {
                                items.Add(new FileItem(file));
                            }
                        }
                    }
                    else
                    {
                        bool[] dirStatus = null;
                        if (dirs.Length > 0)
                        {
                            dirStatus = new bool[dirs.Length];
                            foreach (IResourceMetaData metaData in MetaDataFilter)
                            {
                                if (metaData.ResourceStorageMode == ResourceStorageMode.SingleFolder &&
                                    metaData is ISingleFolderResourceMetaData)
                                {
                                    var singleFolderResourceMetaData = metaData as ISingleFolderResourceMetaData;
                                    for (int i = 0; i < dirs.Length; i++)
                                    {
                                        if (singleFolderResourceMetaData.Identified(dirs[i]))
                                        {
                                            dirStatus[i] = true;
                                            ISingleFolderResource resource = IocManager.Instance.Resolve(singleFolderResourceMetaData.ResourceType.Type) as ISingleFolderResource;
                                            resource.Caption    = Path.GetFileName(dirs[i]);
                                            resource.FolderPath = dirs[i];
                                            items.Add(new ResourceItem(dirs[i], resource));
                                        }
                                    }
                                }
                                else if (metaData.ResourceStorageMode == ResourceStorageMode.MultiFolder &&
                                         metaData is IMultiFolderResourceMetaData)
                                {
                                    var multiFolderResourceMetaData = metaData as IMultiFolderResourceMetaData;
                                    for (int i = 0; i < dirs.Length; i++)
                                    {
                                        if (multiFolderResourceMetaData.Identified(dirs[i]))
                                        {
                                            dirStatus[i] = true;
                                            var otherFolders = multiFolderResourceMetaData.FindOtherFolders(dirs[i]);
                                            if (otherFolders.Count > 0)   //设置otherFolder 的状态
                                            {
                                                foreach (string f in otherFolders)
                                                {
                                                    for (int j = 0; j < dirs.Length; j++)
                                                    {
                                                        if (dirs[j].Equals(f))
                                                        {
                                                            dirStatus[j] = true;
                                                        }
                                                    }
                                                }
                                            }
                                            IMultiFolderResource resource = IocManager.Instance.Resolve(multiFolderResourceMetaData.ResourceType.Type) as IMultiFolderResource;
                                            resource.Caption      = Path.GetFileName(dirs[i]);
                                            resource.MainFolder   = dirs[i];
                                            resource.OtherFolders = otherFolders;
                                            items.Add(new ResourceItem(dirs[i], resource));
                                        }
                                    }
                                }
                            }
                        }
                        if (files.Length > 0)
                        {
                            bool[] fileStatus = new bool[files.Length];
                            foreach (IResourceMetaData metaData in MetaDataFilter)
                            {
                                if (metaData.ResourceStorageMode == ResourceStorageMode.SingleFile &&
                                    metaData is ISingleFileResourceMetaData)
                                {
                                    var singleFileResourceMetaData = metaData as ISingleFileResourceMetaData;
                                    for (int i = 0; i < files.Length; i++)
                                    {
                                        if (singleFileResourceMetaData.Identified(files[i]))
                                        {
                                            fileStatus[i] = true;
                                            ISingleFileResource resource = IocManager.Instance.Resolve(singleFileResourceMetaData.ResourceType.Type) as ISingleFileResource;
                                            resource.Caption  = Path.GetFileName(files[i]);
                                            resource.FullName = files[i];
                                            items.Add(new ResourceItem(files[i], resource));
                                        }
                                    }
                                }
                                else if (metaData.ResourceStorageMode == ResourceStorageMode.MultiFile &&
                                         metaData is IMultiFileResourceMetaData)
                                {
                                    var muiltFileResourceMetaData = metaData as IMultiFileResourceMetaData;
                                    for (int i = 0; i < files.Length; i++)
                                    {
                                        if (muiltFileResourceMetaData.Identified(files[i]))
                                        {
                                            fileStatus[i] = true;
                                            var otherFiles = muiltFileResourceMetaData.FindOtherFiles(files[i]);
                                            if (otherFiles.Count > 0)  //设置otherFile 的状态
                                            {
                                                foreach (string f in otherFiles)
                                                {
                                                    for (int j = 0; j < files.Length; j++)
                                                    {
                                                        if (files[j].Equals(f))
                                                        {
                                                            fileStatus[j] = true;
                                                        }
                                                    }
                                                }
                                            }
                                            IMultiFileResource resource = IocManager.Instance.Resolve(muiltFileResourceMetaData.ResourceType.Type) as IMultiFileResource;
                                            resource.Caption       = Path.GetFileName(files[i]);
                                            resource.MainFilePath  = files[i];
                                            resource.OtherFilePath = otherFiles;
                                            items.Add(new ResourceItem(files[i], resource));
                                        }
                                    }
                                }
                                else if (metaData.ResourceStorageMode == ResourceStorageMode.MixedFileFold &&
                                         metaData is IMixedFileFoldResourceMetaData) //文件和文件夹混合
                                {
                                    var mixedFileFoldResourceMetaData = metaData as IMixedFileFoldResourceMetaData;
                                    for (int i = 0; i < files.Length; i++)
                                    {
                                        if (mixedFileFoldResourceMetaData.Identified(files[i]))
                                        {
                                            fileStatus[i] = true;
                                            var otherfiles   = mixedFileFoldResourceMetaData.FindOtherFiles(files[i]);
                                            var otherFolders = mixedFileFoldResourceMetaData.FindOtherFolders(files[i]);
                                            if (otherfiles.Count > 0)  //设置otherFile 的状态
                                            {
                                                foreach (string f in otherfiles)
                                                {
                                                    for (int j = 0; j < files.Length; j++)
                                                    {
                                                        if (files[j].Equals(f))
                                                        {
                                                            fileStatus[j] = true;
                                                        }
                                                    }
                                                }
                                            }
                                            if (otherFolders.Count > 0)   //设置otherFolder 的状态
                                            {
                                                foreach (string f in otherFolders)
                                                {
                                                    for (int j = 0; j < dirs.Length; j++)
                                                    {
                                                        if (dirs[j].Equals(f))
                                                        {
                                                            dirStatus[j] = true;
                                                        }
                                                    }
                                                }
                                            }
                                            IMixedFileFoldResource resource = IocManager.Instance.Resolve(mixedFileFoldResourceMetaData.ResourceType.Type) as IMixedFileFoldResource;
                                            resource.Caption          = Path.GetFileName(files[i]);
                                            resource.MainPath         = files[i];
                                            resource.OtherFilePaths   = otherfiles;
                                            resource.OtherFolderPaths = otherFolders;
                                            items.Add(new ResourceItem(files[i], resource));
                                        }
                                    }
                                }
                            }
                        }
                        for (int k = 0; k < dirs.Length; k++)
                        {
                            if (!dirStatus[k])
                            {
                                items.Add(new DirectoryItem(dirs[k]));
                            }
                        }
                    }
                }
            }
            catch { }
            finally { }
            return(items);
        }