Beispiel #1
0
        public static string downloadVaultFilebyID(VDF.Vault.Currency.Connections.Connection connection, string path, long selectedFileID)
        {
            try
            {
                using (WebServiceManager serviceManager = connection.WebServiceManager)
                {
                    Autodesk.Connectivity.WebServices.File localFile = serviceManager.DocumentService.GetFileById(selectedFileID);
                    var FileDownloadTicket            = serviceManager.DocumentService.GetDownloadTicketsByFileIds(new long[] { selectedFileID });
                    FilestoreService fileStoreService = serviceManager.FilestoreService;
                    var fileBytes = fileStoreService.DownloadFilePart(FileDownloadTicket[0].Bytes, 0, localFile.FileSize, false);
                    //MessageBox.Show(path + "\\" + localFile.Name);
                    System.IO.File.WriteAllBytes(path + "\\" + localFile.Name, fileBytes);


                    //Check if file exist
                    if (!System.IO.File.Exists(path + "\\" + localFile.Name))
                    {
                        //failedFiles.Add(file);
                        statusMess = "File Download Failed!";
                        ZGHCC.writeLog(statusMess);
                    }
                    else
                    {
                        statusMess = path + "\\" + localFile.Name;
                        //fileExt = System.IO.Path.GetExtension(localFile.Name);
                        ZGHCC.writeLog(statusMess);
                    }
                }

                //statusMess = "Success";
            }
            catch (SystemException ex)
            {
                statusMess = null;
                Debug.Write("\nError: " + ex.ToString());
                statusMess = "Error: \n" + ex.ToString();
            }
            return(statusMess);
            //Autodesk.Connectivity.WebServices.File localFile = serviceManager.DocumentService.GetFileById(file.Id);
        }
Beispiel #2
0
        public static string downloadVaultFiles(VDF.Vault.Currency.Connections.Connection connection, string path, List <ISelection> filesColl)
        {
            try
            {
                //var settings = new VDF.Vault.Settings.AcquireFilesSettings(Global.variables.connection, updateFileReferences: false);
                //settings.LocalPath = new VDF.Currency.FolderPathAbsolute(Global.variables.fileStore);

                if (filesColl.Count > 0)
                {
                    foreach (var file in filesColl)
                    {
                        File selectedFile = null;
                        // Look of the File object.
                        if (file.TypeId == SelectionTypeId.File)
                        {
                            // our ISelection.Id is really a File.MasterId
                            selectedFile = connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(file.Id);
                        }
                        else if (file.TypeId == SelectionTypeId.FileVersion)
                        {
                            // our ISelection.Id is really a File.Id
                            selectedFile = connection.WebServiceManager.DocumentService.GetFileById(file.Id);
                        }
                        if (selectedFile != null)
                        {
                            using (WebServiceManager serviceManager = connection.WebServiceManager)
                            {
                                Autodesk.Connectivity.WebServices.File localFile = serviceManager.DocumentService.GetFileById(selectedFile.Id);
                                var FileDownloadTicket            = serviceManager.DocumentService.GetDownloadTicketsByFileIds(new long[] { selectedFile.Id });
                                FilestoreService fileStoreService = serviceManager.FilestoreService;
                                var fileBytes = fileStoreService.DownloadFilePart(FileDownloadTicket[0].Bytes, 0, localFile.FileSize, false);
                                //MessageBox.Show(path + "\\" + selectedFile.Name);
                                System.IO.File.WriteAllBytes(path + "\\" + selectedFile.Name, fileBytes);


                                //Check if file exist
                                if (!System.IO.File.Exists(path + "\\" + selectedFile.Name))
                                {
                                    //failedFiles.Add(file);
                                    statusMess += "\n" + path + "\\" + selectedFile.Name + " - File Check Issue";
                                }
                                else
                                {
                                    statusMess += "\n" + path + "\\" + selectedFile.Name + " - Success";
                                }
                            }
                        }
                        //MessageBox.Show(String.Format("Hello World! The file {0} size is: {1} bytes", selectedFile.Name, selectedFile.FileSize));
                    }
                    statusMess = "Success";
                }
            }
            catch (SystemException ex)
            {
                statusMess = null;
                Debug.Write("\nError: " + ex.ToString());
                statusMess = "Error: \n" + ex.ToString();
            }
            return(statusMess);
            //Autodesk.Connectivity.WebServices.File localFile = serviceManager.DocumentService.GetFileById(file.Id);
        }