Ejemplo n.º 1
0
        private List <VDF.Vault.Currency.Entities.IEntity> DoFileSearch(SrchCond[] conditions)
        {
            string     bookmark = string.Empty;
            SrchStatus status   = null;

            //search for files
            List <VDF.Vault.Currency.Entities.IEntity> retVal = new List <VDF.Vault.Currency.Entities.IEntity>();

            while (status == null || retVal.Count < status.TotalHits)
            {
                FileFolder[] filefolders = m_conn.WebServiceManager.DocumentService.FindFileFoldersBySearchConditions(
                    conditions, null, null, true, true,
                    ref bookmark, out status);

                if (filefolders != null)
                {
                    foreach (FileFolder fileFolder in filefolders)
                    {
                        VDF.Vault.Currency.Entities.Folder folder =
                            new VDF.Vault.Currency.Entities.Folder(m_conn, fileFolder.Folder);
                        VDF.Vault.Currency.Entities.FileIteration file =
                            new VDF.Vault.Currency.Entities.FileIteration(
                                m_conn, folder, fileFolder.File);
                        retVal.Add(file);
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
        private void get()
        {
            // FilestoreService filestoreService = m_conn.WebServiceManager.FilestoreService;
            // DocumentService documentService = m_conn.WebServiceManager.DocumentService;
            // Vault.Currency.Entities.IEntity selectedItem = m_model.SelectedContent.FirstOrDefault();
            // // download ticket
            // long fileId = selectedItem.EntityIterationId;
            // ByteArray[] downloadTicket = documentService.GetDownloadTicketsByFileIds(new long[] { fileId });
            // byte[] downloadTicketByte = downloadTicket[0].Bytes;
            // long firstByte =0;
            // long lastByte = 52418559;
            //filestoreService.DownloadFilePart(downloadTicketByte, firstByte, lastByte, true);


            Vault.Settings.AcquireFilesSettings setting = new Vault.Settings.AcquireFilesSettings(m_conn, true);
            long selectedItemId = m_model.SelectedContent.FirstOrDefault().EntityIterationId;

            Vault.Currency.Entities.FileIteration selectedItem = m_conn.FileManager.GetFilesByIterationIds(new long[] { selectedItemId }).FirstOrDefault().Value;



            setting.AddFileToAcquire(selectedItem, Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);

            m_conn.FileManager.AcquireFiles(setting);
        }
        /*****************************************************************************************/
        public static List <AWS.FileAssocParam> UpdateFileAssociations(VDF.Vault.Currency.Connections.Connection connection,
                                                                       VDF.Vault.Currency.Entities.FileIteration fileIterationParent,
                                                                       List <AWS.FileAssocLite> fileAssocsLite)
        {
            List <AWS.FileAssocParam> fileAssocParams = new List <AWS.FileAssocParam>();

            foreach (AWS.FileAssocLite fileAssocLite in fileAssocsLite)
            {
                AWS.File childAsReferenced = connection.WebServiceManager.DocumentService.GetFileById(fileAssocLite.CldFileId);

                // of any reason, the parent is referenced by it self in the list, but we dont want that
                if (fileIterationParent.EntityMasterId == childAsReferenced.MasterId)
                {
                    continue;
                }

                AWS.File childLatest = connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(childAsReferenced.MasterId);

                AWS.FileAssocParam fileAssocParam = new AWS.FileAssocParam();

                fileAssocParam.CldFileId         = childLatest.Id;
                fileAssocParam.RefId             = fileAssocLite.RefId;
                fileAssocParam.Source            = fileAssocLite.Source;
                fileAssocParam.Typ               = fileAssocLite.Typ;
                fileAssocParam.ExpectedVaultPath = fileAssocLite.ExpectedVaultPath;
                fileAssocParams.Add(fileAssocParam);
            }

            return(fileAssocParams);
        }
Ejemplo n.º 4
0
        private void objectListView1_SelectionChanged(object sender, EventArgs e)
        {
            if (objectListView1.SelectedItem != null)
            {
                string selectedItemName = ((PartToImport)objectListView1.SelectedItem.RowObject).name;

                selectedItemName = selectedItemName + ".ipt";

                Autodesk.Connectivity.WebServices.File    webServicesFile = selectedFiles.FirstOrDefault(sel => sel.Name == selectedItemName);
                VDF.Vault.Currency.Entities.FileIteration fileIter        = new Vault.Currency.Entities.FileIteration(connection, webServicesFile);

                picBoxIpt.Image = ResizeImage(getThumbNail(fileIter), 115, 115);

                string selectedSymName = symFolder + System.IO.Path.GetFileNameWithoutExtension(selectedItemName) + ".sym";

                if (System.IO.File.Exists(selectedSymName))
                {
                    ShellFile shellFile  = ShellFile.FromFilePath(selectedSymName);
                    Bitmap    shellThumb = shellFile.Thumbnail.Bitmap;
                    this.picBoxSym.Image = ResizeImage(shellThumb, 115, 115);
                }
                else
                {
                    this.picBoxSym.Image = null;
                }

                toolStripStatusLabel.Text = "";
                progressBar.Value         = 0;

                objectListView1.Refresh();
            }
        }
        /// <summary>
        /// Download Vault file using full file path, e.g. "$/Designs/Base.ipt".
        /// Preset Options: Download Children (recursively) = Enabled, Enforce Overwrite = True
        /// </summary>
        /// <param name="conn">Current Vault Connection</param>
        /// <param name="VaultFullFileName">FullFilePath</param>
        /// <returns>Local path/filename</returns>
        public string mGetFileByFullFileName(VDF.Vault.Currency.Connections.Connection conn, string VaultFullFileName)
        {
            List <string> mFiles = new List <string>();

            mFiles.Add(VaultFullFileName);
            AWS.File[] wsFiles = conn.WebServiceManager.DocumentService.FindLatestFilesByPaths(mFiles.ToArray());
            VDF.Vault.Currency.Entities.FileIteration mFileIt = new VDF.Vault.Currency.Entities.FileIteration(conn, (wsFiles[0]));

            VDF.Vault.Settings.AcquireFilesSettings settings = new VDF.Vault.Settings.AcquireFilesSettings(conn);
            settings.DefaultAcquisitionOption = VCF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download;
            settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren        = true;
            settings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren        = true;
            settings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = VDF.Vault.Currency.VersionGatheringOption.Latest;
            settings.OptionsRelationshipGathering.IncludeLinksSettings.IncludeLinks = false;
            VCF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions mResOpt = new VCF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions();
            mResOpt.OverwriteOption           = VCF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions.OverwriteOptions.ForceOverwriteAll;
            mResOpt.SyncWithRemoteSiteSetting = VCF.Vault.Settings.AcquireFilesSettings.SyncWithRemoteSite.Always;
            settings.AddFileToAcquire(mFileIt, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
            VDF.Vault.Results.AcquireFilesResults results = conn.FileManager.AcquireFiles(settings);
            if (results != null)
            {
                VDF.Vault.Results.FileAcquisitionResult mFilesDownloaded = results.FileResults.Last();
                return(mFilesDownloaded.LocalPath.FullPath.ToString());
            }
            return("FileNotFound");
        }
Ejemplo n.º 6
0
 private void OpenFile()
 {
     Vault.Currency.Entities.FileIteration file = m_model.SelectedContent.FirstOrDefault() as Vault.Currency.Entities.FileIteration;
     if (file != null)
     {
         OpenFileCommand.Execute(file, m_conn);
     }
 }
 private void btnOk_Click(object sender, EventArgs e)
 {
     Vault.Currency.Entities.FileIteration file = m_model.SelectedContent.FirstOrDefault() as Vault.Currency.Entities.FileIteration;
     if (file != null)
     {
         m_selectedItem  = file;
         m_currentFolder = new Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.Folder(m_conn, file.Parent);
     }
 }
Ejemplo n.º 8
0
        private void OrganisationSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.Context.SelectedObject == null)
            {
                return;
            }

            var wsm     = e.Context.Application.Connection.WebServiceManager;
            var custEnt = wsm.CustomEntityService.GetCustomEntitiesByIds(
                new [] { e.Context.SelectedObject.Id })[0];

            var propDefs           = wsm.PropertyService.GetPropertyDefinitionsByEntityClassId("LINK");
            var propDefOrderNumber = propDefs.SingleOrDefault(p => p.DispName == "Order Number");
            var propDefOrderFileId = propDefs.SingleOrDefault(p => p.DispName == "Order File ID");

            if (propDefOrderNumber == null || propDefOrderFileId == null)
            {
                throw new ConfigurationErrorsException(
                          "The UDPs 'Order Number' and 'Order File ID' have to be present!");
            }

            var entities  = new List <VDF.Vault.Currency.Entities.IEntity>();
            var propInsts = new List <PropInst>().ToArray();

            var links = wsm.DocumentService.GetLinksByParentIds(
                new[] { custEnt.Id }, new[] { "FILE" });

            if (links != null)
            {
                propInsts = wsm.PropertyService.GetProperties(
                    "LINK",
                    links.Select(l => l.Id).ToArray(),
                    new[] { propDefOrderNumber.Id, propDefOrderFileId.Id });

                foreach (var link in links)
                {
                    var propInstOrderFileId = propInsts.FirstOrDefault(
                        p => p.EntityId == link.Id && p.PropDefId == propDefOrderFileId.Id);

                    if (propInstOrderFileId != null && propInstOrderFileId.Val != null)
                    {
                        var fileId = long.Parse(propInstOrderFileId.Val.ToString());
                        var file   = wsm.DocumentService.GetFileById(fileId);
                        var entity = new VDF.Vault.Currency.Entities.FileIteration(
                            e.Context.Application.Connection, file);

                        entities.Add(entity);
                    }
                }
            }

            var ordersUserControl = (OrdersUserControl)e.Context.UserControl;

            ordersUserControl.Reload(e.Context.Application.Connection,
                                     entities, propDefOrderNumber.Id, propDefOrderFileId.Id, propInsts);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// List all children for a file.
        /// </summary>
        private void UpdateAssociationsTreeView()
        {
            selectedFile = m_model.SelectedContent.FirstOrDefault() as VDF.Vault.Currency.Entities.FileIteration;
            if (selectedFile == null)
            {
                return;
            }

            OpenFile();
        }
        // prints each sheet of the idw(fileIter) to it's own pdf file.
        // if there's more than one sheet referencing the same assembly, they will be combined in one multi-page pdf

        // this is not at all tested yet....
        private Boolean PrintPDF(VDF.Vault.Currency.Entities.FileIteration fileIter, VDF.Vault.Currency.Connections.Connection connection, ref string errMessage, ref string logMessage)
        {
            try
            {
                if (fileIter.EntityName.EndsWith(".idw")) // only print idws
                {
                    // make sure folder exists for downloading idw into.
                    logMessage += "Checking Target Directory...";
                    System.IO.DirectoryInfo targetDir = new System.IO.DirectoryInfo(TargetFolder);
                    if (!targetDir.Exists)
                    {
                        targetDir.Create();
                    }
                    logMessage += "OK" + "\r\n";

                    // download the idw from the vault
                    logMessage += "Downloading idw from the vault...";
                    VDF.Vault.Settings.AcquireFilesSettings downloadSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection)
                    {
                        LocalPath = new VDF.Currency.FolderPathAbsolute(targetDir.FullName),
                    };
                    downloadSettings.AddFileToAcquire(fileIter, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
                    connection.FileManager.AcquireFiles(downloadSettings);

                    string fileName = downloadSettings.LocalPath.ToString() + @"\" + fileIter.ToString();

                    PrintObject printOb = new PrintObject();
                    string      errMsg  = "";
                    string      logMsg  = "";

                    if (!printOb.printToPDF(fileName, PDFPath, PDFPrinterName, PS2PDFProgrameName, GSWorkingFolder, ref errMsg, ref logMsg))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    logMessage += "File is not an idw, nothing to print.";
                    return(true);
                }
            }
            catch (Exception)
            {
                errMessage += "Unknown Error in function PrintPDF\r\n";
                return(false);
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            VDF.Vault.Results.LogInResult lr =
                VDF.Vault.Library.ConnectionManager.LogIn
                    ("localhost", "TestVault", "administrator", "", VDF.Vault.Currency.Connections.AuthenticationFlags.ReadOnly, null);

            if (lr.Success)
            {
                m_conn = lr.Connection;
                VDF.Vault.Forms.Settings.SelectEntitySettings settings =
                    new VDF.Vault.Forms.Settings.SelectEntitySettings();

                VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter[] filters =
                    new VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter[]
                {
                    new VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter("Assembly Files (*.iam)", ".+iam", VDF.Vault.Currency.Entities.EntityClassIds.Files),
                    new VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter("Part Files (*.ipt)", ".+ipt", VDF.Vault.Currency.Entities.EntityClassIds.Files)
                };

                VDF.Vault.Forms.Controls.VaultBrowserControl.Configuration initialConfig = new VDF.Vault.Forms.Controls.VaultBrowserControl.Configuration(m_conn, settings.PersistenceKey, null);

                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.EntityName);
                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.CheckInDate);
                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.Comment);
                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.ThumbnailSystem);
                initialConfig.AddInitialSortCriteria(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.EntityName, true);

                settings.DialogCaption = "Select Part or Assembly file to Upload";
                settings.ActionableEntityClassIds.Add("FILE");
                settings.MultipleSelect = false;
                settings.ConfigureActionButtons("Upload", null, null, false);
                settings.ConfigureFilters("Applied filter", filters, null);
                settings.OptionsExtensibility.GetGridConfiguration = e => initialConfig;

                Console.WriteLine("Launching Vault Browser...");
                VDF.Vault.Forms.Results.SelectEntityResults results =
                    VDF.Vault.Forms.Library.SelectEntity(m_conn, settings);
                if (results != null)
                {
                    VDF.Vault.Currency.Entities.FileIteration fileIter = results.SelectedEntities.FirstOrDefault() as VDF.Vault.Currency.Entities.FileIteration;
                    string result = Util.DownloadFilestoFolder(fileIter, m_conn);
                    if (result != "Directory not found")
                    {
                        Task t = Task.Run((Util.UploadAssembly));
                        t.Wait();
                    }
                }
            }
        }
        private void Publish(VDF.Vault.Currency.Entities.FileIteration fileIter, VDF.Vault.Currency.Connections.Connection connection)
        {
            System.IO.DirectoryInfo targetDir = new System.IO.DirectoryInfo(TargetFolder);
            if (!targetDir.Exists)
            {
                targetDir.Create();
            }

            VDF.Vault.Settings.AcquireFilesSettings downloadSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection)
            {
                LocalPath = new VDF.Currency.FolderPathAbsolute(targetDir.FullName),
            };
            downloadSettings.AddFileToAcquire(fileIter, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
            connection.FileManager.AcquireFiles(downloadSettings);
        }
Ejemplo n.º 13
0
        private void DownloadFile(ADSK.File file, string filePath)
        {
            // remove the read-only attribute
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.SetAttributes(filePath, System.IO.FileAttributes.Normal);
            }

            VDF.Vault.Settings.AcquireFilesSettings settings = new VDF.Vault.Settings.AcquireFilesSettings(connection);

            Vault.Currency.Entities.FileIteration fIter = new Vault.Currency.Entities.FileIteration(connection, file);
            settings.AddFileToAcquire(fIter, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download, new VDF.Currency.FilePathAbsolute(filePath));

            connection.FileManager.AcquireFiles(settings);
        }
Ejemplo n.º 14
0
        public static Autodesk.Connectivity.WebServices.File AddOrUpdateFile(
            string localPath, string fileName, Folder vaultFolder, Connection conn)
        {
            string vaultPath = vaultFolder.FullName + "/" + fileName;

            Autodesk.Connectivity.WebServices.File[] result = conn.WebServiceManager.DocumentService.FindLatestFilesByPaths(
                vaultPath.ToSingleArray());

            Autodesk.Connectivity.WebServices.File retVal = null;
            if (result == null || result.Length == 0 || result[0].Id < 0)
            {
                VDF.Vault.Currency.Entities.Folder vdfFolder = new VDF.Vault.Currency.Entities.Folder(
                    conn, vaultFolder);

                // using a stream so that we can set a different file name
                using (FileStream stream = new FileStream(localPath, FileMode.Open, FileAccess.Read))
                {
                    VDF.Vault.Currency.Entities.FileIteration newFile = conn.FileManager.AddFile(
                        vdfFolder, fileName, "Thunderdome deployment",
                        System.IO.File.GetLastWriteTime(localPath), null, null,
                        FileClassification.None, false, stream);

                    retVal = newFile;
                }
            }
            else
            {
                VDF.Vault.Currency.Entities.FileIteration vdfFile = new VDF.Vault.Currency.Entities.FileIteration(conn, result[0]);

                AcquireFilesSettings settings = new AcquireFilesSettings(conn);
                settings.AddEntityToAcquire(vdfFile);
                settings.DefaultAcquisitionOption = AcquireFilesSettings.AcquisitionOption.Checkout;
                AcquireFilesResults results = conn.FileManager.AcquireFiles(settings);

                if (results.FileResults.First().Exception != null)
                {
                    throw results.FileResults.First().Exception;
                }

                vdfFile = results.FileResults.First().File;
                vdfFile = conn.FileManager.CheckinFile(vdfFile, "Thunderdome deployment", false,
                                                       null, null, false, null, FileClassification.None, false, localPath.ToVDFPath());

                retVal = vdfFile;
            }

            return(retVal);
        }
Ejemplo n.º 15
0
        private void PopulateListBox()
        {
            PartsToImport.Clear();

            foreach (ISelection selection in selectionSet)
            {
                Autodesk.Connectivity.WebServices.File selectedFile = null;
                if (selection.TypeId == SelectionTypeId.File)
                {
                    // our ISelection.Id is really a File.MasterId
                    selectedFile = connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(selection.Id);
                }
                else if (selection.TypeId == SelectionTypeId.FileVersion)
                {
                    // our ISelection.Id is really a File.Id
                    selectedFile = connection.WebServiceManager.DocumentService.GetFileById(selection.Id);
                }

                if (selectedFile != null)
                {
                    if (selectedFile.Name.EndsWith(".ipt"))
                    {
                        PartToImport part = new PartToImport();
                        part.name = selectedFile.Name.Replace(".ipt", "");

                        VDF.Vault.Currency.Entities.FileIteration fileIter = new Vault.Currency.Entities.FileIteration(connection, selectedFile);
                        part.desc = GetERPDescriptionProperty(fileIter);

                        part.thickness    = radInterface.GetThicknessFromSym(symFolder + part.name + ".sym");
                        part.materialType = radInterface.GetMaterialTypeFromSym(symFolder + part.name + ".sym");
                        part.qty          = 0;

                        PartsToImport.Add(part);
                        selectedFiles.Add(selectedFile);
                    }
                }
            }

            if (PartsToImport.Count > 0)
            {
                objectListView1.SetObjects(PartsToImport);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Launches a Vault UI to select Ipt file
        /// </summary>
        /// <returns>Selected File</returns>
        private static Autodesk.Connectivity.WebServices.File SelectFilefromUI()
        {
            VDF.Vault.Currency.Entities.FileIteration fileIter = null;
            _connection = VDF.Vault.Forms.Library.Login(null);
            if (_connection.IsConnected)
            {
                VDF.Vault.Forms.Settings.SelectEntitySettings settings =
                    new VDF.Vault.Forms.Settings.SelectEntitySettings();

                VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter[] filters =
                    new VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter[]
                {
                    // new VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter("Assembly Files (*.iam)", ".+iam", VDF.Vault.Currency.Entities.EntityClassIds.Files),
                    new VDF.Vault.Forms.Settings.SelectEntitySettings.EntityRegularExpressionFilter("Part Files (*.ipt)", ".+ipt", VDF.Vault.Currency.Entities.EntityClassIds.Files)
                };

                VDF.Vault.Forms.Controls.VaultBrowserControl.Configuration initialConfig = new VDF.Vault.Forms.Controls.VaultBrowserControl.Configuration(_connection, settings.PersistenceKey, null);

                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.EntityName);
                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.CheckInDate);
                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.Comment);
                initialConfig.AddInitialColumn(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.ThumbnailSystem);
                initialConfig.AddInitialSortCriteria(VDF.Vault.Currency.Properties.PropertyDefinitionIds.Server.EntityName, true);

                settings.DialogCaption = "Select Part or Assembly file to Upload";
                settings.ActionableEntityClassIds.Add("FILE");
                settings.MultipleSelect = false;
                settings.ConfigureActionButtons("Upload", null, null, false);
                settings.ConfigureFilters("Applied filter", filters, null);
                settings.OptionsExtensibility.GetGridConfiguration = e => initialConfig;

                Console.WriteLine("Launching Vault Browser...");
                VDF.Vault.Forms.Results.SelectEntityResults results =
                    VDF.Vault.Forms.Library.SelectEntity(_connection, settings);
                if (results != null)
                {
                    fileIter = results.SelectedEntities.FirstOrDefault() as VDF.Vault.Currency.Entities.FileIteration;
                }
            }
            return(fileIter);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Add tree node for the association tree.
        /// </summary>
        /// <param name="parentNode">Node to add to</param>
        private void AddChildAssociation(TreeNode parentNode,
                                         Dictionary <long, List <Vault.Currency.Entities.FileIteration> > associationsByFile)
        {
            // get the File object for the Node
            Vault.Currency.Entities.FileIteration parentFile = (Vault.Currency.Entities.FileIteration)parentNode.Tag;

            // if associations exist, create a Node for each one
            if (associationsByFile.ContainsKey(parentFile.EntityIterationId))
            {
                List <Vault.Currency.Entities.FileIteration> list = associationsByFile[parentFile.EntityIterationId];
                foreach (Vault.Currency.Entities.FileIteration childFile in list)
                {
                    TreeNode childNode = new TreeNode(childFile.EntityName);
                    childNode.Tag = childFile;
                    parentNode.Nodes.Add(childNode);

                    // add all of the Nodes for the children's children
                    AddChildAssociation(childNode, associationsByFile);
                }
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 /// This method is called from Program.cs. Entry point to Vault code.
 /// </summary>
 public static string DownloadFilestoFolder(VDF.Vault.Currency.Entities.FileIteration fileIter, VDF.Vault.Currency.Connections.Connection connection)
 {
     try
     {
         string result = createDirectories();
         try
         {
             string nameOfTopLevelAsm = fileIter.EntityName;
             downloadFile(connection, fileIter, dwnldfldrpath, nameOfTopLevelAsm);
             return("Downloaded Successfully!");
         }
         catch (Exception ex)
         {
             Console.WriteLine("downloadFile failed:" + ex.Message);
             return("Directory not found");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("createDirectories failed:" + ex.Message);
         return("Directory not found");
     }
 }
        public ACJE.JobOutcome Execute(ACJE.IJobProcessorServices context, ACJE.IJob job)
        {
            long fileMasterId = Convert.ToInt64(job.Params["FileMasterId"]);

            try
            {
                // Retrieve the file object from the server
                //
                ACW.File file = context.Connection.WebServiceManager.DocumentService.GetLatestFileByMasterId(fileMasterId);
                VDF.Vault.Currency.Entities.FileIteration fileIter =
                    context.Connection.FileManager.GetFilesByIterationIds(new long[] { file.Id }).First().Value;

                // Download and publish the file
                //
                Publish(fileIter, context.Connection);

                return(ACJE.JobOutcome.Success);
            }
            catch
            {
                return(ACJE.JobOutcome.Failure);
            }
        }
        /// <summary>
        /// Downloads a file from Vault and opens it.  The program used to load the file is
        /// based on the user's OS settings.
        /// </summary>
        /// <param name="fileId"></param>
        public static void Execute(VDF.Vault.Currency.Entities.FileIteration file, VDF.Vault.Currency.Connections.Connection connection)
        {
            string filePath = Path.Combine(Application.LocalUserAppDataPath, file.EntityName);

            //determine if the file already exists
            if (System.IO.File.Exists(filePath))
            {
                //we'll try to delete the file so we can get the latest copy
                try
                {
                    System.IO.File.Delete(filePath);

                    //remove the file from the collection of downloaded files that need to be removed when the application exits
                    if (m_downloadedFiles.Contains(filePath))
                    {
                        m_downloadedFiles.Remove(filePath);
                    }
                }
                catch (System.IO.IOException)
                {
                    throw new Exception("The file you are attempting to open already exists and can not be overwritten. This file may currently be open, try closing any application you are using to view this file and try opening the file again.");
                }
            }

            downloadFile(connection, file, Path.GetDirectoryName(filePath));
            m_downloadedFiles.Add(filePath);

            //Create a new ProcessStartInfo structure.
            ProcessStartInfo pInfo = new ProcessStartInfo();

            //Set the file name member.
            pInfo.FileName = filePath;
            //UseShellExecute is true by default. It is set here for illustration.
            pInfo.UseShellExecute = true;
            Process p = Process.Start(pInfo);
        }
        public ACJE.JobOutcome Execute(ACJE.IJobProcessorServices context, ACJE.IJob job)
        {
            long   EntityId = Convert.ToInt64(job.Params["EntityId"]);
            string logText  = "";
            string errText  = "";

            ACJE.JobOutcome jobOutComeStatus = ACJE.JobOutcome.Success;
            try
            {
                // Retrieve the file object from the server
                //
                ACW.File[] fileArray = new ACW.File[10];    // I hope there's never more than 11 files returned :(
                long[]     EntityIDArray = new long[1];
                string     logString = "", errString = "";

                EntityIDArray[0] = EntityId;
                try
                {
                    fileArray = context.Connection.WebServiceManager.DocumentService.GetLatestFilesByIds(EntityIDArray);
                }
                catch (Exception)
                {
                    // if the above call fails, we know the vault file that we want to process doesn't exist anymore
                    // so we don't worry about it and call it a success!
                    context.Log("No vault file found", ACJE.MessageType.eInformation);
                    return(ACJE.JobOutcome.Success);
                }
                context.Log("number of items in array: " + fileArray.Length + "\n\r", ACJE.MessageType.eInformation);


                VDF.Vault.Currency.Entities.FileIteration fileIter =
                    context.Connection.FileManager.GetFilesByIterationIds(new long[] { fileArray[0].Id }).First().Value;

                if (GetVaultCheckOutComment(fileIter, context.Connection) != "IM")
                {
                    // check for PDF files
                    if (PDFfileUpdate(fileIter, context.Connection, ref logString, ref errString))
                    {
                        logText += "Processing PDF File for " + fileIter.ToString() + "...\n";
                        logText += logString + "\n";  // information returned from FileUpdate
                        context.Log(logText, ACJE.MessageType.eInformation);
                        jobOutComeStatus = ACJE.JobOutcome.Success;
                    }
                    else
                    {
                        errText  = "Error in processing PDF File for " + fileIter.ToString();
                        errText += errString + "\n";  // information returned from FileUpdate
                        context.Log(errText, ACJE.MessageType.eError);
                        jobOutComeStatus = ACJE.JobOutcome.Failure;
                    }

                    // check for sym files
                    int symUpdateVal = processRadanFile(fileIter, false);
                    if (symUpdateVal == 1)
                    {
                        logText += "Moved Radan File for " + fileIter.ToString() + "...\n";
                        context.Log(logText, ACJE.MessageType.eInformation);
                        if (jobOutComeStatus != ACJE.JobOutcome.Failure)
                        {
                            jobOutComeStatus = ACJE.JobOutcome.Success;
                        }
                    }
                    else if (symUpdateVal == 0)
                    {
                        logText = "No Radan File moved for " + fileIter.ToString() + "...\n";
                        context.Log(logText, ACJE.MessageType.eInformation);
                        if (jobOutComeStatus != ACJE.JobOutcome.Failure)
                        {
                            jobOutComeStatus = ACJE.JobOutcome.Success;
                        }
                    }
                    else if (symUpdateVal == -1)
                    {
                        errText = "Error in processing Radan File for " + fileIter.ToString();
                        context.Log(errText, ACJE.MessageType.eError);
                        jobOutComeStatus = ACJE.JobOutcome.Failure;
                    }

                    return(jobOutComeStatus);
                }
                else
                {
                    logText = "Skipping over " + fileIter.ToString() + "because only item master properties were changed";
                    context.Log(logText, ACJE.MessageType.eInformation);
                    return(ACJE.JobOutcome.Success);
                }
            }
            catch
            {
                context.Log(logText, ACJE.MessageType.eError);
                return(ACJE.JobOutcome.Failure);
            }
        }
Ejemplo n.º 22
0
        private bool ConvertFile(string NameOfPartToConvert, ref string ErrorMessage)
        {
            toolStripStatusLabel.Text = "";
            progressBar.Value         = 0;
            progressBar.PerformStep();
            string  selectedItemIptName = NameOfPartToConvert + ".ipt";
            string  errorMessage        = "";
            string  materialName        = "";
            string  partThickness       = "";
            string  topPattern          = "";
            string  partName            = "";
            string  partDescription     = "";
            string  partUnits           = "in";
            Boolean overWriteConfirm    = true;
            string  openProjectName     = "";
            string  openNestName        = "";

            try
            {
                openProjectName = radInterface.getOpenProjectName(ref errorMessage);

                string symFileName = symFolder + NameOfPartToConvert + ".sym";
                if (System.IO.File.Exists(symFileName))
                {
                    DialogResult      result;
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    result = MessageBox.Show("The sym file already exists. Do you want to overwrite it?", "Confirm Overwrite", buttons);
                    if (result == DialogResult.Yes)
                    {
                        overWriteConfirm = true;
                    }
                    else
                    {
                        overWriteConfirm = false;
                        System.IO.File.SetLastWriteTimeUtc(symFileName, DateTime.UtcNow);
                    }
                }

                if (overWriteConfirm == true)
                {
                    Autodesk.Connectivity.WebServices.File    webServicesFile = selectedFiles.FirstOrDefault(sel => sel.Name == selectedItemIptName);
                    VDF.Vault.Currency.Entities.FileIteration fileIter        = new Vault.Currency.Entities.FileIteration(connection, webServicesFile);
                    PartToImport modifiedPart = new PartToImport();
                    string       filePath     = System.IO.Path.Combine(System.IO.Path.GetTempPath(), fileIter.EntityName);

                    PartToImport partToModify = PartsToImport.FirstOrDefault(sel => sel.name == NameOfPartToConvert);
                    int          index        = objectListView1.IndexOf(partToModify);
                    modifiedPart.name = PartsToImport[index].name;

                    partDescription   = GetERPDescriptionProperty(fileIter);
                    modifiedPart.desc = partDescription;

                    // remove old ipt from temp folder to ensure we will use the lastest version
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.SetAttributes(filePath, FileAttributes.Normal);
                    }
                    System.IO.File.Delete(filePath);

                    radInterface.SaveNest(ref errorMessage);
                    openNestName = radInterface.getOpenNestName(ref errorMessage);

                    toolStripStatusLabel.Text = "Downloading File...";
                    DownloadFile(fileIter, filePath);
                    progressBar.PerformStep();

                    toolStripStatusLabel.Text = "Saving Radan Nest...";

                    if (!radInterface.SaveNest(ref errorMessage))
                    {
                        ErrorMessage = errorMessage;
                        toolStripStatusLabel.Text = errorMessage;
                        return(false);
                    }
                    else
                    {
                        progressBar.PerformStep();
                    }

                    toolStripStatusLabel.Text = "Opening 3D File...";
                    if (!radInterface.Open3DFileInRadan(filePath, "", ref errorMessage))
                    {
                        ErrorMessage = errorMessage;
                        toolStripStatusLabel.Text = errorMessage;
                        return(false);
                    }
                    else
                    {
                        progressBar.PerformStep();
                    }

                    toolStripStatusLabel.Text = "Unfolding 3D File...";
                    if (!radInterface.UnfoldActive3DFile(ref partName, ref materialName, ref partThickness, ref topPattern, ref errorMessage))
                    {
                        ErrorMessage = errorMessage;
                        toolStripStatusLabel.Text = errorMessage;
                        return(false);
                    }
                    else
                    {
                        progressBar.PerformStep();
                    }

                    toolStripStatusLabel.Text = "Saving Sym File...";
                    if (!radInterface.SavePart(topPattern, symFileName, ref errorMessage))
                    {
                        ErrorMessage = errorMessage;
                        toolStripStatusLabel.Text = errorMessage;
                        return(false);
                    }
                    else
                    {
                        progressBar.PerformStep();
                    }

                    toolStripStatusLabel.Text = "Setting Radan Attributes...";
                    if (!radInterface.InsertAttributes(symFileName, materialName, partThickness, partUnits, partDescription, ref errorMessage))
                    {
                        ErrorMessage = errorMessage;
                        toolStripStatusLabel.Text = errorMessage;
                        return(false);
                    }
                    else
                    {
                        progressBar.PerformStep();
                    }

                    toolStripStatusLabel.Text = "Done...";
                    double thickness = double.Parse(partThickness);

                    if (thickness <= 0.001)
                    {
                        toolStripStatusLabel.Text = "Part Thickness Could Not Be Calculated, Aborting Operation";
                        return(false);
                    }
                    else
                    {
                        modifiedPart.thickness    = thickness.ToString();
                        modifiedPart.materialType = materialName;
                        progressBar.PerformStep();
                    }

                    PartsToImport[index] = modifiedPart;

                    ShellFile shellFile  = ShellFile.FromFilePath(symFileName);
                    Bitmap    shellThumb = shellFile.Thumbnail.Bitmap;
                    this.picBoxSym.Image = ResizeImage(shellThumb, 115, 115);

                    if (openProjectName != "")
                    {
                        radInterface.LoadProject(openProjectName);
                    }

                    if (openNestName != "")
                    {
                        radInterface.openNest(openNestName, ref errorMessage);
                    }
                }
                return(true);
            }

            catch (Exception)
            {
                errorMessage = "Error in converting File";
                return(false);
            }
        }
Ejemplo n.º 23
0
        public static string GetVaultCheckOutComment(VDF.Vault.Currency.Entities.FileIteration selectedFile, VDF.Vault.Currency.Connections.Connection connection)
        {
            // a list of dictionaries of the vault properties of the associated files
            List <Dictionary <string, string> > vaultPropDictList = new List <Dictionary <string, string> >();

            // function that gets properties requires a list so we'll define a list and add the selected file to it...
            List <VDF.Vault.Currency.Entities.FileIteration> fileList = new List <VDF.Vault.Currency.Entities.FileIteration>();

            fileList.Add(selectedFile);

            // define a dictionary to hold all the properties pertaining to a vault entity
            VDF.Vault.Currency.Properties.PropertyDefinitionDictionary allPropDefDict = new VDF.Vault.Currency.Properties.PropertyDefinitionDictionary();
            allPropDefDict = connection.PropertyManager.GetPropertyDefinitions(VDF.Vault.Currency.Entities.EntityClassIds.Files, null, VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeAll);

            // define a list of only the properties that we are concerned about.
            List <VDF.Vault.Currency.Properties.PropertyDefinition> filteredPropDefList =
                new List <VDF.Vault.Currency.Properties.PropertyDefinition>();

            List <string> propNames = new List <string> {
                "Comment"
            };

            // copy only definitions in propNames list from allPropDefDict to filteredPropDefList
            foreach (string s in propNames)
            {
                VDF.Vault.Currency.Properties.PropertyDefinition propDefs =
                    new Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyDefinition();
                propDefs = allPropDefDict[s];

                filteredPropDefList.Add(propDefs);
            }

            // the following line should return a list of properties
            VDF.Vault.Currency.Properties.PropertyValues propValues = new Autodesk.DataManagement.Client.Framework.Vault.Currency.Properties.PropertyValues();
            propValues = connection.PropertyManager.GetPropertyValues(fileList, filteredPropDefList, null);

            VDF.Vault.Currency.Properties.PropertyDefinition def = new VDF.Vault.Currency.Properties.PropertyDefinition(propNames[0]);
            VDF.Vault.Currency.Properties.PropertyValue      val;

            Dictionary <VDF.Vault.Currency.Properties.PropertyDefinition, VDF.Vault.Currency.Properties.PropertyValue> d = propValues.GetValues(selectedFile);

            d.TryGetValue(def, out val);

            string key = null;

            if (def != null)
            {
                key = (def.SystemName == null) ? null : def.SystemName;

                string value = null;
                if (val != null)
                {
                    value = (val.Value == null) ? "" : val.Value.ToString();
                    return(value);
                }
                else
                {
                    value = "";
                }
            }

            return(null);
        }
Ejemplo n.º 24
0
        public static void SyncSymFiles(string symRoot)
        {
            // this function traverses through all the sym files in the symRoot folder.
            // for each file it calls the SearchVaultWorkspace function to search for the corresponding ipt file

            // Data structure to hold names of subfolders to be
            // examined for files.

            List <string>[] mailLists       = new List <string> [3];
            List <string>   outdatedList    = new List <string>();
            List <string>   missingList     = new List <string>();
            List <string>   speculationList = new List <string>();


            Stack <string> dirs = new Stack <string>(20);

            if (!System.IO.Directory.Exists(symRoot))
            {
                throw new ArgumentException();
            }
            dirs.Push(symRoot);

            while (dirs.Count > 0)
            {
                string   currentDir = dirs.Pop();
                string[] subDirs;
                try
                {
                    subDirs = System.IO.Directory.GetDirectories(currentDir);
                }
                // An UnauthorizedAccessException exception will be thrown if we do not have
                // discovery permission on a folder or file. It may or may not be acceptable
                // to ignore the exception and continue enumerating the remaining files and
                // folders. It is also possible (but unlikely) that a DirectoryNotFound exception
                // will be raised. This will happen if currentDir has been deleted by
                // another application or thread after our call to Directory.Exists. The
                // choice of which exceptions to catch depends entirely on the specific task
                // you are intending to perform and also on how much you know with certainty
                // about the systems on which this code will run.
                catch (UnauthorizedAccessException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }
                catch (System.IO.DirectoryNotFoundException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                string[] files = null;
                try
                {
                    files = System.IO.Directory.GetFiles(currentDir, "*.sym");
                }

                catch (UnauthorizedAccessException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                catch (System.IO.DirectoryNotFoundException e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                foreach (string file in files)
                {
                    try
                    {
                        System.IO.FileInfo symFile = new System.IO.FileInfo(file);

                        FileFolder iptFile = new FileFolder();

                        iptFile = SearchVault(symFile);

                        if (iptFile != null)
                        {
                            VDF.Vault.Currency.Entities.FileIteration searchFile =
                                new Autodesk.DataManagement.Client.Framework.Vault.Currency.Entities.FileIteration(connection, iptFile.File);

                            string comment = GetVaultCheckOutComment(searchFile, connection);

                            if (comment != "IM")
                            {
                                // we found a matching ipt file

                                DateTime symDate = symFile.CreationTime;
                                DateTime iptDate = iptFile.File.ModDate;
                                TimeSpan diff    = symDate - iptDate;
                                if (diff.TotalSeconds < 0)  // ipt file has been modified since sym was created.
                                {
                                    // sym file is out of date
                                    debugFile.WriteLine(symFile.Name + " needs to be updated. It is older than its corresponding ipt file in the vault");
                                    debugFile.WriteLine("It will be moved to the non-controlled folder\n");
                                    outdatedList.Add(symFile.Name);
                                    Console.WriteLine("Oudated File Found");
                                    DirectoryInfo symFolder              = new DirectoryInfo(symRoot);
                                    DirectoryInfo symParentFolder        = symFolder.Parent;
                                    DirectoryInfo symFolderNonControlled = new DirectoryInfo(symParentFolder.FullName + "\\Vault Sym Files - non controlled");

                                    if (!simulate)
                                    {
                                        if (!symFolderNonControlled.Exists)
                                        {
                                            symFolderNonControlled.Create();
                                        }

                                        string   nonControlledFileName = (symFolderNonControlled.FullName + "\\" + symFile.Name);
                                        FileInfo nonControlledFile     = new FileInfo(nonControlledFileName);
                                        if (nonControlledFile.Exists)
                                        {
                                            nonControlledFile.Delete();
                                        }
                                        symFile.MoveTo(nonControlledFile.FullName);
                                        nonControlledFile.LastWriteTime = DateTime.Now;

                                        if (!nonControlledFile.Exists)
                                        {
                                            debugFile.WriteLine("Error in copying file");
                                        }
                                    }
                                }
                                else
                                {
                                    // file could still have been checked out and back in again without being modifed.
                                    // check for this yet, and flag it for speculation
                                    iptDate = iptFile.File.CkInDate;
                                    diff    = symDate - iptDate;
                                    if (diff.TotalSeconds < 0)
                                    {
                                        speculationList.Add(symFile.Name);
                                        symFile.CreationTime = DateTime.Now;        // bump up the sym file timestamp so we won't flag it again tomorrow
                                    }
                                }
                            }
                            else
                            {
                                // only item master properties changed, so we don't flag this file as out of date
                                debugFile.WriteLine("Only Item Master Properties Changed. " + symFile.Name);
                                debugFile.WriteLine(" It will not be moved to the non-controlled folder\n");
                            }
                        }
                        else
                        {
                            // no matching ipt file found, it is not currently in the vault
                            DirectoryInfo symFolder              = new DirectoryInfo(symRoot);
                            DirectoryInfo symParentFolder        = symFolder.Parent;
                            DirectoryInfo symFolderNonControlled = new DirectoryInfo(symParentFolder.FullName + "\\Vault Sym Files - non controlled");
                            if (!symFolderNonControlled.Exists)
                            {
                                symFolderNonControlled.Create();
                            }

                            string   nonControlledFileName = (symFolderNonControlled.FullName + "\\" + symFile.Name);
                            FileInfo nonControlledFile     = new FileInfo(nonControlledFileName);

                            if (!simulate)
                            {
                                if (nonControlledFile.Exists)
                                {
                                    nonControlledFile.Delete();
                                }
                                symFile.MoveTo(nonControlledFile.FullName);
                                nonControlledFile.LastWriteTime = DateTime.Now;
                                if (!nonControlledFile.Exists)
                                {
                                    debugFile.WriteLine("Error in copying file");
                                }
                            }

                            debugFile.WriteLine("No ipt file found for " + symFile.Name);
                            debugFile.WriteLine(" It will be moved to the non-controlled folder\n");
                            missingList.Add(symFile.Name);
                        }

                        Console.WriteLine(Path.GetFileName(symFile.Name) + " is up to date");
                    }
                    catch (System.IO.FileNotFoundException e)
                    {
                        // If file was deleted by a separate application
                        //  or thread since the call to TravrerseSymTree()
                        // then just continue.
                        Console.WriteLine(e.Message);
                        continue;
                    }
                }

                // Push the subdirectories onto the stack for traversal.
                // This could also be done before handing the files.
                foreach (string str in subDirs)
                {
                    dirs.Push(str);
                }
            }

            mailLists[0] = outdatedList;
            mailLists[1] = missingList;
            mailLists[2] = speculationList;

            sendMail(mailLists);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Download the file(s) to the local folder.
        /// </summary>
        private static void downloadFile(VDF.Vault.Currency.Connections.Connection connection, VDF.Vault.Currency.Entities.FileIteration fileIter, string folderPath, string topAssemblyName)
        {
            VDF.Vault.Settings.AcquireFilesSettings settings =
                new VDF.Vault.Settings.AcquireFilesSettings(connection);
            settings.AddEntityToAcquire(fileIter);
            settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = true;
            settings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = true;
            settings.LocalPath = new VDF.Currency.FolderPathAbsolute(folderPath);
            settings.DefaultAcquisitionOption =
                VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download;

            VDF.Vault.Results.AcquireFilesResults myAcqFilesResults =
                connection.FileManager.AcquireFiles(settings);

            fileList = new List <string>();
            foreach (VDF.Vault.Results.FileAcquisitionResult myFileAcquistionResult in myAcqFilesResults.FileResults)
            {
                if (myFileAcquistionResult.File.EntityName == topAssemblyName)
                {
                    fileList.Insert(0, myFileAcquistionResult.LocalPath.FullPath);
                    continue;
                }
                fileList.Add(myFileAcquistionResult.LocalPath.FullPath);
            }
        }
 private static void downloadFile(VDF.Vault.Currency.Connections.Connection connection, VDF.Vault.Currency.Entities.FileIteration file, string folderPath)
 {
     VDF.Vault.Settings.AcquireFilesSettings settings = new VDF.Vault.Settings.AcquireFilesSettings(connection);
     settings.AddEntityToAcquire(file);
     settings.LocalPath = new VDF.Currency.FolderPathAbsolute(folderPath);
     connection.FileManager.AcquireFiles(settings);
 }
Ejemplo n.º 27
0
        private void CheckForUpdates(string serverName, string vaultName, Connection conn)
        {
            if (m_restartPending)
            {
                return;
            }

            Settings settings = Settings.Load();

            // user previously indicated not to download updates and not to be prompted
            if (settings.NeverDownload)
            {
                return;
            }

            string defaultFolder = conn.WebServiceManager.KnowledgeVaultService.GetVaultOption(DEFAULT_FOLDER_OPTION);

            if (defaultFolder == null || defaultFolder.Length == 0)
            {
                return;
            }
            if (!defaultFolder.EndsWith("/"))
            {
                defaultFolder += "/";
            }

            string deploymentPath = defaultFolder + PACKAGE_NAME;

            Autodesk.Connectivity.WebServices.File [] files = conn.WebServiceManager.DocumentService.FindLatestFilesByPaths(
                deploymentPath.ToSingleArray());

            if (files == null || files.Length == 0 || files[0].Id <= 0 || files[0].Cloaked)
            {
                return; // no package found
            }
            VaultEntry entry = settings.GetOrCreateEntry(serverName, vaultName);

            if (entry != null && entry.LastUpdate >= files[0].CkInDate)
            {
                return;  // we are up to date
            }
            StringBuilder updateList = new StringBuilder();

            string          deploymentXml   = conn.WebServiceManager.KnowledgeVaultService.GetVaultOption(DEPLOYMENT_CONFIG_OPTION);
            DeploymentModel deploymentModel = DeploymentModel.Load(deploymentXml);

            if (deploymentModel == null || deploymentModel.Containers == null)
            {
                return;
            }

            foreach (DeploymentContainer container in deploymentModel.Containers)
            {
                updateList.AppendLine(container.DisplayName);

                foreach (DeploymentItem item in container.DeploymentItems)
                {
                    updateList.AppendLine("- " + item.DisplayName);
                }

                updateList.AppendLine();
            }

            AskDialog    ask    = new AskDialog(updateList.ToString());
            DialogResult result = ask.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (ask.AskResult == AskDialog.AskResultEnum.No)
                {
                    return;
                }
                else if (ask.AskResult == AskDialog.AskResultEnum.Never)
                {
                    settings.NeverDownload = true;
                    settings.Save();
                    return;
                }
            }
            else
            {
                return;
            }

            // if we got here, the user cliecked yes.


            string tempPath = Path.Combine(Path.GetTempPath(), "Thunderdome");

            if (!tempPath.EndsWith("\\"))
            {
                tempPath += "\\";
            }

            if (Directory.Exists(tempPath))
            {
                Directory.Delete(tempPath, true);
            }
            DirectoryInfo dirInfo = Directory.CreateDirectory(tempPath);

            UtilSettings utilSettings = new UtilSettings();

            utilSettings.TempFolder = tempPath;

            // the first arg should be the EXE path
            utilSettings.VaultClient = Environment.GetCommandLineArgs()[0];

            string zipPath = Path.Combine(tempPath, PACKAGE_NAME);

            VDF.Vault.Currency.Entities.FileIteration vdfFile = new VDF.Vault.Currency.Entities.FileIteration(conn, files[0]);
            VDF.Currency.FilePathAbsolute             vdfPath = new VDF.Currency.FilePathAbsolute(zipPath);
            AcquireFilesSettings acquireSettings = new AcquireFilesSettings(conn, false);

            acquireSettings.AddFileToAcquire(vdfFile, AcquireFilesSettings.AcquisitionOption.Download, vdfPath);
            AcquireFilesResults acquireResults = conn.FileManager.AcquireFiles(acquireSettings);

            foreach (FileAcquisitionResult acquireResult in acquireResults.FileResults)
            {
                if (acquireResult.Exception != null)
                {
                    throw acquireResult.Exception;
                }
            }

            // clear the read-only bit
            System.IO.File.SetAttributes(zipPath, FileAttributes.Normal);

            FastZip zip = new FastZip();

            zip.ExtractZip(zipPath, tempPath, null);

            MasterController mc = new MasterController(conn, vaultName);

            mc.SetMoveOperations(tempPath, utilSettings);

            utilSettings.Save();

            MessageBox.Show("Updates downloaded. " +
                            "You need exit the Vault client to complete the update process. " + Environment.NewLine +
                            "The Vault Client will restart when the update is complete.",
                            "Exit Required");

            m_restartPending = true;

            entry.LastUpdate = files[0].CkInDate;
            settings.Save();
        }
        private int processRadanFile(VDF.Vault.Currency.Entities.FileIteration fileIter, bool simulate)
        {
            string vaultName   = fileIter.EntityName;
            string symFileName = "";

            if (System.IO.Path.GetExtension(m_SymFolderName + vaultName) == ".ipt")
            {
                try
                {
                    DirectoryInfo symFolder              = new DirectoryInfo(m_SymFolderName);
                    DirectoryInfo symParentFolder        = symFolder.Parent;
                    DirectoryInfo symFolderNonControlled = new DirectoryInfo(symParentFolder.FullName + "\\Vault Sym Files - non controlled");

                    symFileName = m_SymFolderName + System.IO.Path.GetFileNameWithoutExtension(vaultName) + ".sym";
                    System.IO.FileInfo symFile = new System.IO.FileInfo(symFileName);
                    if (!symFile.Exists)
                    {
                        // no sym file found
                        return(0);
                    }

                    if (!simulate)
                    {
                        if (!symFolderNonControlled.Exists)
                        {
                            symFolderNonControlled.Create();
                        }

                        string   nonControlledFileName = (symFolderNonControlled.FullName + "\\" + symFile.Name);
                        FileInfo nonControlledFile     = new FileInfo(nonControlledFileName);
                        if (nonControlledFile.Exists)
                        {
                            nonControlledFile.Delete();
                        }
                        symFile.MoveTo(nonControlledFile.FullName);
                        nonControlledFile.LastWriteTime = DateTime.Now;

                        if (!nonControlledFile.Exists)
                        {
                            // error
                            return(-1);
                        }

                        // sym file moved successfully
                        return(1);
                    }
                    else
                    {
                        // simulation mode only, no sym file moved
                        return(0);
                    }
                }
                catch (Exception)
                {
                    //error
                    return(-1);
                }
            }
            else
            {
                // vault file is not an ipt, no need to search for sym file
                return(0);
            }
        }
        //  use ERP names instead of file names.
        private Boolean PDFfileUpdate(VDF.Vault.Currency.Entities.FileIteration fileIter, VDF.Vault.Currency.Connections.Connection connection, ref string logMessage, ref string errMessage)
        {
            try
            {
                // download the file
                System.IO.DirectoryInfo targetDir = new System.IO.DirectoryInfo(m_TargetFolder);
                if (!targetDir.Exists)
                {
                    targetDir.Create();
                }

                VDF.Vault.Settings.AcquireFilesSettings downloadSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection)
                {
                    LocalPath = new VDF.Currency.FolderPathAbsolute(targetDir.FullName),
                };
                downloadSettings.AddFileToAcquire(fileIter, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);

                VDF.Vault.Results.AcquireFilesResults results =
                    connection.FileManager.AcquireFiles(downloadSettings);

                string fileName = downloadSettings.LocalPath.ToString() + @"\" + fileIter.ToString();

                // ipts and iams are easier to deal with than idws
                if (fileName.EndsWith(".ipt") || fileName.EndsWith(".iam"))
                {
                    PrintObject printOb = new PrintObject();

                    if (printOb.deletePDF(fileName, m_PDFPath, ref logMessage, ref errMessage))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (fileName.EndsWith(".idw")) // for idws we have to loop through each drawing sheet
                {
                    try
                    {
                        string modelName = "";

                        // set up lists for storing the actual model names the sheets are referencing
                        List <string> modelNames = new List <string>();
                        List <VDF.Vault.Currency.Entities.FileIteration> fIterations = new List <VDF.Vault.Currency.Entities.FileIteration>();

                        VDF.Vault.Currency.Properties.PropertyDefinitionDictionary propDefs =
                            new VDF.Vault.Currency.Properties.PropertyDefinitionDictionary();
                        Inventor.ApprenticeServerComponent       oApprentice = new ApprenticeServerComponent();
                        Inventor.ApprenticeServerDrawingDocument drgDoc;
                        drgDoc = (Inventor.ApprenticeServerDrawingDocument)oApprentice.Document;
                        oApprentice.Open(fileName);
                        drgDoc = (Inventor.ApprenticeServerDrawingDocument)oApprentice.Document;
                        ACW.PropDef[] filePropDefs =
                            connection.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE");
                        ACW.PropDef vaultNamePropDef = filePropDefs.Single(n => n.SysName == "Name");

                        // for each sheet in the idw, search the vault for the sheet's corresponding ipt or iam
                        foreach (Sheet sh in drgDoc.Sheets)
                        {
                            if (sh.DrawingViews.Count > 0)  // I added this line because one pdf with a BOM only sheet
                                                            // kept failing.  This line fixed the problemf or that file
                                                            // but it is definitely not well tested...
                            {
                                errMessage += " " + sh.DrawingViews[1].ReferencedDocumentDescriptor.DisplayName + "found";
                                if (sh.DrawingViews.Count > 0)
                                {
                                    modelName = sh.DrawingViews[1].ReferencedDocumentDescriptor.DisplayName;

                                    PrintObject printOb = new PrintObject();
                                    if (printOb.deletePDF(modelName, m_PDFPath, ref logMessage, ref errMessage))
                                    {
                                        //logMessage += "Deleted PDF: " + pair.Value.Value.ToString() + "\r\n";
                                        //we already logged a message in the deletePDF function
                                    }
                                    else
                                    {
                                        logMessage += logMessage;
                                        errMessage += "Can not delete PDF Error1 in function FileUpdate\r\n";
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logMessage += logMessage;
                        errMessage += "Can not delete PDF Error2 in function FileUpdate\r\n" + ex.Message + "\r\n";
                        return(false);
                    }
                }
                return(true);
            }

            catch (Exception)
            {
                logMessage += logMessage;
                errMessage += errMessage;
                return(false);
            }
        }
        /// <summary>
        /// Find file by 1 to many search criteria as property/value pairs.
        /// Downloads the first file matching all search criterias; include many as required to get the unique file.
        /// Preset Search Operator Options: [Property] is (exactly) [Value]; multiple conditions link up using AND condition.
        /// Preset Download Options: Download Children (recursively) = Enabled, Enforce Overwrite = True
        /// </summary>
        /// <param name="conn">Current Vault Connection</param>
        /// <param name="SearchCriteria">Dictionary of property/value pairs</param>
        /// <returns>Local path/filename</returns>
        public string mGetFilebySearchCriteria(VDF.Vault.Currency.Connections.Connection conn, Dictionary <string, string> SearchCriteria)
        {
            AWS.PropDef[] mFilePropDefs = conn.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE");
            //iterate mSearchcriteria to get property definitions and build AWS search criteria
            List <AWS.SrchCond> mSrchConds = new List <AWS.SrchCond>();
            int             i            = 0;
            List <AWS.File> totalResults = new List <AWS.File>();

            foreach (var item in SearchCriteria)
            {
                AWS.PropDef  mFilePropDef = mFilePropDefs.Single(n => n.DispName == item.Key);
                AWS.SrchCond mSearchCond  = new AWS.SrchCond();
                {
                    mSearchCond.PropDefId = mFilePropDef.Id;
                    mSearchCond.PropTyp   = AWS.PropertySearchType.SingleProperty;
                    mSearchCond.SrchOper  = 1; //equals
                    if (i == 0)
                    {
                        mSearchCond.SrchRule = AWS.SearchRuleType.May;
                    }
                    else
                    {
                        mSearchCond.SrchRule = AWS.SearchRuleType.Must;
                    }
                    mSearchCond.SrchTxt = item.Value;
                }
                mSrchConds.Add(mSearchCond);
                i++;
            }
            string bookmark = string.Empty;

            AWS.SrchStatus status = null;

            while (status == null || totalResults.Count < status.TotalHits)
            {
                AWS.File[] mSrchResults = conn.WebServiceManager.DocumentService.FindFilesBySearchConditions(
                    mSrchConds.ToArray(), null, null, false, true, ref bookmark, out status);
                if (mSrchResults != null)
                {
                    totalResults.AddRange(mSrchResults);
                }
                else
                {
                    break;
                }
            }
            //if results not empty
            if (totalResults.Count == 1)
            {
                AWS.File wsFile = totalResults.First <AWS.File>();
                VDF.Vault.Currency.Entities.FileIteration mFileIt = new VDF.Vault.Currency.Entities.FileIteration(conn, (wsFile));

                VDF.Vault.Settings.AcquireFilesSettings settings = new VDF.Vault.Settings.AcquireFilesSettings(conn);
                settings.DefaultAcquisitionOption = VCF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download;
                settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren        = true;
                settings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren        = true;
                settings.OptionsRelationshipGathering.FileRelationshipSettings.VersionGatheringOption = VDF.Vault.Currency.VersionGatheringOption.Latest;
                settings.OptionsRelationshipGathering.IncludeLinksSettings.IncludeLinks = false;
                VCF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions mResOpt = new VCF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions();
                mResOpt.OverwriteOption           = VCF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions.OverwriteOptions.ForceOverwriteAll;
                mResOpt.SyncWithRemoteSiteSetting = VCF.Vault.Settings.AcquireFilesSettings.SyncWithRemoteSite.Always;
                settings.AddFileToAcquire(mFileIt, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
                VDF.Vault.Results.AcquireFilesResults results = conn.FileManager.AcquireFiles(settings);
                if (results != null)
                {
                    VDF.Vault.Results.FileAcquisitionResult mFilesDownloaded = results.FileResults.Last();
                    return(mFilesDownloaded.LocalPath.FullPath.ToString());
                }
                else
                {
                    return("FileNotFound");
                }
            }
            else
            {
                return("FileNotFound");
            }
        }