void LoadFileList(string file, Dictionary <string, FileItemInfo> flist) { if (!File.Exists(file)) { return; } XmlDocument xd = new XmlDocument(); xd.Load(file); if (!xd.HasChildNodes) { return; } foreach (XmlElement r in xd.DocumentElement.ChildNodes) { FileItemInfo fi = new FileItemInfo(); fi.file = r.SelectSingleNode("Path").InnerText; fi.md5 = r.SelectSingleNode("Md5").InnerText; fi.ver = int.Parse(r.SelectSingleNode("Ver").InnerText); flist.Add(fi.file, fi); } }
private static IEnumerable <FileItemInfo> ToFileItemInfos(IEnumerable <IListBlobItem> blobs, string basePath) { foreach (var blob in blobs) { var element = new FileItemInfo() { Name = Helper.RemoveBasePath(blob.Uri.LocalPath, basePath) }; ICloudBlob icloudBlob = blob as ICloudBlob; if (icloudBlob != null) { element.Length = icloudBlob.Properties.Length; element.LastModifiedUtc = icloudBlob.Properties.LastModified.Value.UtcDateTime; } else { CloudBlob cloudBlob = blob as CloudBlob; if (cloudBlob != null) { element.Length = cloudBlob.Properties.Length; element.LastModifiedUtc = cloudBlob.Properties.LastModified.Value.UtcDateTime; } } if (element.Length != null) { yield return(element); } } }
private void ParseDirectoryRecursive(object path) { try { do { FileInfoDataList ss = ShowSharefile.ReceiveShare(); if (ss.Name == "") { break; } int asdf = ss.Name.LastIndexOf(@"\"); string a = ss.Name.Substring(0, asdf + 1); if (Directory != a) { continue; } ss.Name = ss.Name.Substring(asdf + 1, ss.Name.Length - asdf - 1); Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { FileInfoDataList si = ShowSharefile.GetInfo(ss); if (si != null) { FileItemInfo.Add(si); } Thread.Sleep(5); }); } while (true); } catch (Exception) { ; } }
private void ParseDirectoryThread(object p)//使用后台线程获取文件信息 { /////////////_client.RequestOpenShareFolder(string.Empty, 0); string _directory = ""; if (p != null && p is string) { _directory = (string)p; } if (_directory == "") { return; } ShowSharefile.SendDirectoryName(_directory); try { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { FileItemInfo.Clear(); }); t = new Thread(new ParameterizedThreadStart(ParseDirectoryRecursive)); //在后台线程中调用ParseDirectoryRecursive方法 t.IsBackground = true; //指定为后台线程 t.Priority = ThreadPriority.BelowNormal; //指定线程优先级别 t.Start(_directory); //为线程方法传入文件夹路径 } catch (Exception) //如果产生异常 { //调用自定义的异常信息窗口 throw; // ExceptionManagement.Manage("Catalog:ParseDirectoryThread", err); } }
public void SetInfo(FileItemInfo info) { fileItemInfo = info; itemName = System.IO.Path.GetFileName(info.fullName); GetComponentInChildren <Text>().text = itemName; itemTypeIcon.sprite = fileItemInfo.isDirectory ? directoryIcon : System.IO.Path.GetExtension(itemName) == ".wav" ? musicFileIcon : otherFileIcon; }
public IHttpActionResult GetFileByPath(ODataActionParameters parameters) { FileItemInfo file = null; this.ProcessEntity(() => { var path = parameters.GetValueSafe <string>("Path"); var result = Service.GetFileByPath(path, _defaultLoadFlags); file = Convert(result); }); return(Ok(file)); }
private static IEnumerable <FileItemInfo> ToFileItemInfos(IEnumerable <S3Object> s3Objects, string basePath) { foreach (var s3Object in s3Objects) { if (!s3Object.Key.EndsWith("/")) { var element = new FileItemInfo() { Name = Helper.RemoveBasePath(Helper.PathCombine(s3Object.BucketName, s3Object.Key), basePath), Length = s3Object.Size, LastModifiedUtc = s3Object.LastModified.ToUniversalTime() }; yield return(element); } } }
//search all files and calc md5 code void SearchFiles(string path, Dictionary <string, FileItemInfo> flist, string spattern) { string [] files = Directory.GetFiles(path, spattern, SearchOption.AllDirectories); MD5 md5 = new MD5CryptoServiceProvider(); foreach (string f in files) { using (FileStream fs = File.OpenRead(f)) { FileItemInfo fi = new FileItemInfo(); fi.file = f.Remove(0, path.Length + 1).Replace("\\", "/"); fi.md5 = ToHexString(md5.ComputeHash(fs)); flist.Add(fi.file, fi); } } }
public IHttpActionResult MoveFile(int key, ODataActionParameters parameters) { FileItemInfo movedFile = null; this.ProcessEntity(() => { var file = Service.GetFileById(key); if (file == null) { throw Request.NotFoundException(WebApiGlobal.Error.EntityNotFound.FormatInvariant(key)); } var destinationFileName = parameters.GetValueSafe <string>("DestinationFileName"); var duplicateFileHandling = parameters.GetValueSafe("DuplicateFileHandling", DuplicateFileHandling.ThrowError); var result = Service.MoveFile(file.File, destinationFileName, duplicateFileHandling); movedFile = Convert(result); }); return(Ok(movedFile)); }
public async Task <object> GetServerCompareValue(string serverFilePath, Api api) { FileItemInfo props = await api.GetFileInfo(serverFilePath); return(props.Size); }
public async Task <IHttpActionResult> SaveFile() { if (!Request.Content.IsMimeMultipartContent()) { return(StatusCode(HttpStatusCode.UnsupportedMediaType)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } FileItemInfo savedFile = null; var provider = new MultipartMemoryStreamProvider(); try { await Request.Content.ReadAsMultipartAsync(provider); } catch (Exception ex) { return(InternalServerError(ex)); } // Get file content. var contents = provider.Contents?.Where(x => x.IsFileContent())?.ToList(); if ((contents?.Count ?? 0) == 0) { return(BadRequest("Missing multipart file data.")); } if (contents.Count > 1) { return(BadRequest("Send one file per request, not multiple.")); } var content = contents.First(); var cd = content.Headers?.ContentDisposition; if (!(cd?.Parameters?.Any() ?? false)) { return(BadRequest("Missing file parameters in content-disposition header.")); } await this.ProcessEntityAsync(async() => { var path = cd.Parameters.FirstOrDefault(x => x.Name == "Path")?.Value.ToUnquoted(); var isTransient = cd.Parameters.FirstOrDefault(x => x.Name == "IsTransient")?.Value?.ToUnquoted()?.ToBool(true) ?? true; var rawDuplicateFileHandling = cd.Parameters.FirstOrDefault(x => x.Name == "DuplicateFileHandling")?.Value?.ToUnquoted(); Enum.TryParse <DuplicateFileHandling>(rawDuplicateFileHandling.EmptyNull(), out var duplicateFileHandling); using (var stream = await content.ReadAsStreamAsync()) { var result = await Service.SaveFileAsync(path, stream, isTransient, duplicateFileHandling); savedFile = Convert(result); } }); return(Ok(savedFile)); }
// 返回的 FileItemInfo.Name 中是逻辑全路径 // parameters: // strCurrentDirectory 当前路径。物理路径 // return: // -1 出错 // 其他 列出的事项总数。注意,不是 lLength 所指出的本次返回数 public static int ListFile( string strRootPath, string strCurrentDirectory, string strPattern, long lStart, long lLength, out List <FileItemInfo> infos, out string strError) { strError = ""; infos = new List <FileItemInfo>(); int MAX_ITEMS = 100; // 一次 API 最多返回的事项数量 try { FileSystemLoader loader = new FileSystemLoader(strCurrentDirectory, strPattern); int i = 0; int count = 0; foreach (FileSystemInfo si in loader) { // 检查文件或目录必须在根以下。防止漏洞 if (PathUtil.IsChildOrEqual(si.FullName, strRootPath) == false) { continue; } if (i < lStart) { goto CONTINUE; } if (lLength != -1 && count > lLength) { goto CONTINUE; } if (count >= MAX_ITEMS) { goto CONTINUE; } FileItemInfo info = new FileItemInfo(); infos.Add(info); info.Name = si.FullName.Substring(strRootPath.Length); info.CreateTime = si.CreationTimeUtc.ToString("u"); // 2017/4/8 info.LastWriteTime = si.LastWriteTimeUtc.ToString("u"); info.LastAccessTime = si.LastAccessTimeUtc.ToString("u"); if (si is DirectoryInfo) { info.Size = -1; // 表示这是目录 } if (si is FileInfo) { FileInfo fi = si as FileInfo; info.Size = fi.Length; } count++; CONTINUE: i++; } return(i); } catch (DirectoryNotFoundException) { return(0); } catch (Exception ex) { strError = ExceptionUtil.GetAutoText(ex); return(-1); } }
private void OnSearch(object obj) { Islist = false; if (_preSearchTime == null) { _preSearchTime = DateTime.Now; } else { var now = DateTime.Now; var spanTime = now - _preSearchTime; if (spanTime < _elapsedTime) { MessageBox.Show(string.Format("每次搜索间隔不能超过{0}秒", _elapsedTime.Seconds.ToString())); return; } else { _preSearchTime = DateTime.Now; } } IsBusy_Main = true; try { List <string> nameList = FileName.Split(' ').ToList(); nameList.RemoveAll(new Predicate <string>(T => T == string.Empty)); Task <List <FileInfoData> > task = _client.SearchFileAsync(nameList, true); FileItemInfo.Clear(); if (_ctsSearch != null) { if (!_ctsSearch.Token.CanBeCanceled) { _ctsSearch.Cancel(); } } task.ContinueWith(T => { ThreadPool.QueueUserWorkItem(delegate { IsBusy_Main = false; if (T.Result != null) { _ctsSearch = new CancellationTokenSource(); Task listTask = new Task(() => { foreach (var item in T.Result) { try { Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { FileInfoDataList f = new FileInfoDataList(item); f = ShowSharefile.GetInfo(f); if (item != null) { FileItemInfo.Add(f); } Thread.Sleep(30); }); } catch (Exception) { //throw; } } }, _ctsSearch.Token); listTask.Start(); } }); }); } catch (Exception e) { if (ErrorOccur != null) { ErrorOccur(this, new ModelEventArgs(ModelEventType.Exception) { ModelException = e }); } } }