private static void DownloadFileLarge(ADSK.File file, string filePath, ADSK.DocumentService docSvc) { if (System.IO.File.Exists(filePath)) System.IO.File.SetAttributes(filePath, FileAttributes.Normal); using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) { long startByte = 0; long endByte = MAX_FILE_SIZE - 1; byte[] buffer; while (startByte < file.FileSize) { endByte = startByte + MAX_FILE_SIZE; if (endByte > file.FileSize) endByte = file.FileSize; buffer = docSvc.DownloadFilePart(file.Id, startByte, endByte, true).Bytes; //buffer = (byte[])((_DocumentService)docSvc).DownloadFilePart((long)file.Id, startByte, endByte, true).Bytes; stream.Write(buffer, 0, buffer.Length); startByte += buffer.Length; } stream.Close(); } }
public static ADSK.PropDef GetPropertyDefinition(String propName, ADSK.DocumentService docSvc) { ADSK.PropDef res = null; foreach (ADSK.PropDef prop in serviceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")) { if (prop.SysName == propName) { //Console.WriteLine("Prop:" + prop.SysName + "=" + prop.Id + "," + prop.DispName); res = prop; } } return res; }
/*private static void saveInfo(string filename, Dictionary<string, string> props) { WritePropertyFile(filename, props); }*/ private static void showInfo(ADSK.File file, ADSK.File fileDown, String filename, Dictionary<string, string> props) { Dictionary<string, string> d = new Dictionary<string, string>(); Util.SetProperty(d, "File", fileDown.Name); Util.SetProperty(d, "CheckedOut", file.CheckedOut.ToString()); Util.SetProperty(d, "CkInDate", file.CkInDate.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss")); Util.SetProperty(d, "Cksum", file.Cksum.ToString()); //SetProperty(d, "Cloaked", file.Cloaked.ToString()); Util.SetProperty(d, "FileSize", file.FileSize.ToString()); Util.SetProperty(d, "FileStatus", file.FileStatus.ToString()); Util.SetProperty(d, "ModDate", file.ModDate.ToString()); Util.SetProperty(d, "CkOutFolderId", file.CkOutFolderId.ToString()); Util.SetProperty(d, "CkOutMach", file.CkOutMach); Util.SetProperty(d, "CkOutSpec", file.CkOutSpec); Util.SetProperty(d, "CkOutUserId", file.CkOutUserId.ToString()); //SetProperty(d, "IsOnSite", file.IsOnSite.ToString()); //SetProperty(d, "FileRev", file.FileRev.Label + "=" + file.FileRev.MaxFileId + "=" + file.FileRev.MaxRevId + "=" + file.FileRev.Order + "=" + file.FileRev.RevDefId + "=" + file.FileRev.RevId); string value = null; foreach (string k in props.Keys) { props.TryGetValue(k, out value); Util.SetProperty(d, k, value); } LOG.imprimeLog(System.DateTime.Now + " ===== Salvando arquivo de log: " + filename); Util.WritePropertyFile(filename, d); }
/** * Lista os arquivos de uma pasta no Vault */ private static void PrintFilesInFolder(ADSK.Folder parentFolder, ADSK.DocumentService docSvc) { ADSK.File[] files = docSvc.GetLatestFilesByFolderId(parentFolder.Id, false); if (files != null && files.Length > 0) { foreach (ADSK.File file in files) { Console.WriteLine(parentFolder.FullName + "/" + file.Name); } } ADSK.Folder[] folders = docSvc.GetFoldersByParentId(parentFolder.Id, false); if (folders != null && folders.Length > 0) { foreach (ADSK.Folder folder in folders) { PrintFilesInFolder(folder, docSvc); } } }
/** * Faz o download de um arquivo. */ public static void DownloadFile(ADSK.File file, string filePath, ADSK.DocumentService docSvc) { //Console.WriteLine("Downloading " + file.Name + " - Para o arquivo " + filePath); // remove the read-only attribute if (System.IO.File.Exists(filePath)) System.IO.File.SetAttributes(filePath, FileAttributes.Normal); if (file.FileSize > MAX_FILE_SIZE) DownloadFileLarge(file, filePath, docSvc); else DownloadFileStandard(file, filePath, docSvc); // set the file to read-only //TODO: pq isso ta aqui??? System.IO.File.SetAttributes(filePath, FileAttributes.ReadOnly); }
private static void DownloadFileStandard(ADSK.File file, string filePath, ADSK.DocumentService docSvc) { using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite)) { byte[] fileData; ByteArray byteArray = new ByteArray(); docSvc.DownloadFile((long)file.Id, true, out byteArray); fileData = (byte[])byteArray.Bytes; stream.Write(fileData, 0, fileData.Length); stream.Flush(); stream.Close(); stream.Dispose(); } }