public static bool Delete(ItemType itemType, string source) { if (itemType == ItemType.File) { return(FileHelper.FileDelete(source)); } else { return(FileHelper.FolderDelete(source)); } }
public string DownloadToTemp(string artifactUri) { try { var client = new WebClient(); if (this.Collection.Server is INetworkServer) { var server = (INetworkServer)this.Collection.Server; client.Credentials = server.Credentials; } else if (this.Collection.Server is IAuthServer) { var server = (IAuthServer)this.Collection.Server; client.Headers.Add(HttpRequestHeader.Authorization, server.AuthString); } else { throw new Exception("Known server"); } var tempFileName = this.GetTempFileName(".gz"); UriBuilder bulder = new UriBuilder(this.Url); bulder.Query = artifactUri; client.DownloadFile(bulder.Uri, tempFileName); if (string.Equals(client.ResponseHeaders[HttpResponseHeader.ContentType], "application/gzip")) { string newTempFileName = this.GetTempFileName(".tmp"); using (var inStream = new GZipStream(File.OpenRead(tempFileName), CompressionMode.Decompress)) { using (var outStream = File.Create(newTempFileName)) { inStream.CopyTo(outStream); outStream.Flush(); outStream.Close(); } inStream.Close(); } FileHelper.FileDelete(tempFileName); //Delete zipped tmp. return(newTempFileName); } else { return(tempFileName); } } catch { return(string.Empty); } }
public string GetItemContent(Item item) { if (item == null || item.ItemType == ItemType.Folder) { return(string.Empty); } if (item.DeletionId > 0) { return(string.Empty); } var dowloadService = this.ProjectCollection.GetService <VersionControlDownloadService>(); var tempName = dowloadService.DownloadToTemp(item.ArtifactUri); var text = item.Encoding > 0 ? File.ReadAllText(tempName, Encoding.GetEncoding(item.Encoding)) : File.ReadAllText(tempName); FileHelper.FileDelete(tempName); return(text); }
private UpdateLocalVersion InternalProcessDelete(GetOperation operation, ProcessType processType) { var path = operation.SourceLocalItem; if (processType == ProcessType.Delete) { try { if (operation.ItemType == ItemType.File) { FileHelper.FileDelete(path); } else { FileHelper.FolderDelete(path); } } catch { LoggingService.Log(MonoDevelop.Core.Logging.LogLevel.Info, "Can not delete path:" + path); } } return(new UpdateLocalVersion(operation.ItemId, null, operation.VersionServer)); }