Пример #1
0
        public ExportToSym(IEnumerable <Autodesk.Connectivity.Explorer.Extensibility.ISelection> selection, VDF.Vault.Currency.Connections.Connection conn)
        {
            InitializeComponent();
            selectionSet = selection;
            connection   = conn;

            radInterface = new RadanInterface();
            radInterface.Initialize();

            selectedFiles = new List <ADSK.File>();

            // structure to hold list of files plus some extra attributes
            PartsToImport = new List <PartToImport>();

            propDefs = new Vault.Currency.Properties.PropertyDefinitionDictionary();
            propDefs =
                connection.PropertyManager.GetPropertyDefinitions(
                    VDF.Vault.Currency.Entities.EntityClassIds.Files,
                    null,
                    VDF.Vault.Currency.Properties.PropertyDefinitionFilter.IncludeUserDefined
                    );

            PopulateListBox();

            txtBoxProject.Text   = Properties.Settings.Default["radanProject"].ToString();
            txtBoxSymFolder.Text = symFolder;
        }
Пример #2
0
        /// <summary>
        /// This is the function that is called whenever the custom command is executed.
        /// </summary>
        /// <param name="s">The sender object.  Usually not used.</param>
        /// <param name="e">The event args.  Provides additional information about the environment.</param>
        void Camlink3_1CommandHandler(object s, CommandItemEventArgs e)
        {
            try
            {
                VDF.Vault.Currency.Connections.Connection connection = e.Context.Application.Connection;

                // The Context part of the event args tells us information about what is selected.
                // Run some checks to make sure that the selection is valid.
                if (e.Context.CurrentSelectionSet.Count() == 0)
                {
                    MessageBox.Show("Nothing is selected");
                }
                else
                {
                    Screen      screen     = Screen.FromPoint(Cursor.Position);
                    ExportToSym exportForm = new ExportToSym(e.Context.CurrentSelectionSet, connection);
                    exportForm.StartPosition = FormStartPosition.Manual;
                    exportForm.Left          = screen.Bounds.Location.X + 250;
                    exportForm.Top           = screen.Bounds.Location.Y + 150;
                    exportForm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                // If something goes wrong, we don't want the exception to bubble up to Vault Explorer.
                MessageBox.Show("Error: " + ex.Message);
            }
        }
Пример #3
0
        public FilesGridForm(VDF.Vault.Currency.Connections.Connection connection)
        {
            InitializeComponent();
            reloadGrid();

            m_connection = connection;
        }
        void Execute(VDF.Vault.Currency.Entities.FileIteration file, VDF.Vault.Currency.Connections.Connection connection)
        {
            VaultAccess.VaultAccess va = new VaultAccess.VaultAccess(connection, @"\\HLAFILESRVR2\ENGCOMMON\PDF Drawing Files\");

            if (System.IO.File.Exists(AppSettings.SettingsFilePath))
            {
                IvFullPath = (string)AppSettings.Get("Iv_FullPath");

                if (!System.IO.File.Exists(IvFullPath))
                {
                    selectDirectViewerApp();
                }
            }
            else
            {
                selectDirectViewerApp();
            }

            string filePath = Path.Combine(System.IO.Path.GetTempPath() + "\\DirectView\\", file.EntityName);

            if (file.EntityName.EndsWith(".iam"))
            {
                va.downloadFileAndAssociations(file, Path.GetDirectoryName(filePath));
            }
            else if (file.EntityName.EndsWith(".idw"))
            {
                va.downloadFile(file, Path.GetDirectoryName(filePath));
                if (va.CheckForOutOfDateSheets(filePath))
                {
                    MessageBox.Show("Cannot view this file, there are drawing sheet(s) that are out of date");
                }
            }
            else
            {
                va.downloadFile(file, Path.GetDirectoryName(filePath));
            }

            if (!File.Exists(filePath))
            {
                DialogResult downloadResult = MessageBox.Show("File is not finished downloading.  Did you want to try again?", "File Download", MessageBoxButtons.YesNoCancel);

                if (downloadResult == DialogResult.No || downloadResult == DialogResult.Cancel)
                {
                    return;
                }
            }

            Process p = new Process();

            p.StartInfo.WorkingDirectory = Path.GetDirectoryName(IvFullPath);

            p.StartInfo.FileName = IvFullPath;

            p.StartInfo.Arguments = "\"" + filePath + "\"";

            p.StartInfo.CreateNoWindow = false;
            p.Start();

            System.IO.File.SetAttributes(filePath, FileAttributes.ReadOnly);
        }
Пример #5
0
        void Execute(VDF.Vault.Currency.Entities.FileIteration file, VDF.Vault.Currency.Connections.Connection connection)
        {
            string filePath = Path.Combine(System.IO.Path.GetTempPath(), file.EntityName);

            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.SetAttributes(filePath, FileAttributes.Normal);
            }

            //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.Arguments = "/high";
            pInfo.FileName  = filePath;
            //UseShellExecute is true by default. It is set here for illustration.
            pInfo.UseShellExecute = true;
            Process p = Process.Start(pInfo);

            System.IO.File.SetAttributes(filePath, FileAttributes.ReadOnly);
        }
Пример #6
0
        ItemAssoc [] GetChildItems(Autodesk.Connectivity.WebServices.Item item, VDF.Vault.Currency.Connections.Connection connection)
        {
            // returns all the direct children of an item.
            try
            {
                if (item == null)
                {
                    MessageBox.Show("Select an Item first");
                    return(null);
                }

                ItemService itemSvc = connection.WebServiceManager.ItemService;

                // change second parameter to true to return all children recursively
                return(itemSvc.GetItemBOMAssociationsByItemIds(new long[] { item.Id }, false));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #7
0
        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);

            if (file.EntityName.EndsWith(".iam"))
            {
                settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren        = true;
                settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeLibraryContents = true;
                // this forces all the files to go into one folder, it doesn't replicate the vault's folder structure..
                // this is needed so that Inventor view knows where to find the file
                settings.OrganizeFilesRelativeToCommonVaultRoot = false;
            }
            else
            {
                settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren        = false;
                settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeLibraryContents = false;
                settings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren        = false;
            }

            settings.LocalPath = new VDF.Currency.FolderPathAbsolute(folderPath);
            connection.FileManager.AcquireFiles(settings);
        }
Пример #8
0
        void ExecuteOdoo(Autodesk.Connectivity.WebServices.Item item, VDF.Vault.Currency.Connections.Connection connection, bool okToProcess)
        {
            string processFileName = AppSettings.Get("VaultExportFilePath").ToString() + "Process.txt";

            using (StreamWriter writer = new StreamWriter(processFileName))
            {
                if (okToProcess == false)
                {
                    writer.WriteLine("false");
                }
                else
                {
                    writer.WriteLine("true");
                }
            }

            //string filename = (string)AppSettings.Get("ExportFile");
            string filename1 = @"C:\Users\lorne\Desktop\Vault Export\odoo1.csv";
            string filename2 = @"C:\Users\lorne\Desktop\Vault Export\odoo2.csv";

            PackageService packageSvc = connection.WebServiceManager.PackageService;

            // export to CSV file
            PkgItemsAndBOM pkgBom = packageSvc.GetLatestPackageDataByItemIds(new long[] { item.Id }, BOMTyp.Latest);

            // Create a mapping between Item properties and columns in the CSV file
            MapPair parentPair = new MapPair();

            parentPair.ToName   = "product";
            parentPair.FromName = "BOMStructure-41FF056B-8EEF-47E2-8F9E-490BC0C52C71";

            MapPair numberPair = new MapPair();

            numberPair.ToName   = "name";
            numberPair.FromName = "Number";

            MapPair titlePair = new MapPair();

            titlePair.ToName   = "Title (Item,CO)";
            titlePair.FromName = "Title(Item,CO)";

            MapPair descriptionPair = new MapPair();

            descriptionPair.ToName   = "description";
            descriptionPair.FromName = "Description(Item,CO)";

            MapPair categoryNamePair = new MapPair();

            categoryNamePair.ToName   = "CategoryName";
            categoryNamePair.FromName = "CategoryName";

            MapPair thicknessPair = new MapPair();

            thicknessPair.ToName   = "Thickness";
            thicknessPair.FromName = "7c5169ad-9081-4aa7-b1a3-4670edae0b8c";

            MapPair materialPair = new MapPair();

            materialPair.ToName   = "Material";
            materialPair.FromName = "Material";

            MapPair operationsPair = new MapPair();

            operationsPair.ToName   = "Operations";
            operationsPair.FromName = "794d5b7d-49b5-49ba-938a-7e341a7ff8e4";

            MapPair quantityPair = new MapPair();

            quantityPair.ToName   = "bom_line_ids/product_qty";
            quantityPair.FromName = "Quantity-41FF056B-8EEF-47E2-8F9E-490BC0C52C71";

            MapPair structCodePair = new MapPair();

            structCodePair.ToName   = "Structural Code";
            structCodePair.FromName = "e3811c7a-a3ee-4f67-b34e-cbc892640616";

            MapPair plantIDPair = new MapPair();

            plantIDPair.ToName   = "Plant ID";
            plantIDPair.FromName = "eff195ae-da71-4929-b3df-2d6fd1e25f53";

            MapPair isStockPair = new MapPair();

            isStockPair.ToName   = "Is Stock";
            isStockPair.FromName = "f78c17cd-86d1-4728-96b5-8001fb58b67f";

            MapPair requiresPDFPair = new MapPair();

            requiresPDFPair.ToName   = "Requires PDF";
            requiresPDFPair.FromName = "6df4ae8b-fbd9-4e62-b801-a46097d4f9c5";

            MapPair commentPair = new MapPair();

            commentPair.ToName   = "Comment";
            commentPair.FromName = "Comment";

            MapPair modDatePair = new MapPair();

            modDatePair.ToName   = "Date Modified";
            modDatePair.FromName = "ModDate";

            MapPair statePair = new MapPair();

            statePair.ToName   = "State";
            statePair.FromName = "State";

            MapPair stockNamePair = new MapPair();

            stockNamePair.ToName   = "Stock Name";
            stockNamePair.FromName = "a42ca550-c503-4835-99dd-8c4d4ff6dbaf";

            MapPair keywordsPair = new MapPair();

            keywordsPair.ToName   = "Keywords";
            keywordsPair.FromName = "Keywords";

            MapPair notesPair = new MapPair();

            notesPair.ToName   = "Notes";
            notesPair.FromName = "0d012a5c-cc28-443c-b44e-735372eee117";

            FileNameAndURL fileNameAndUrl = packageSvc.ExportToPackage(pkgBom, FileFormat.TDL_PARENT,
                                                                       new MapPair[] { numberPair, descriptionPair });

            // write parts to file1
            long currentByte = 0;
            long partSize    = connection.PartSizeInBytes;

            using (FileStream fs = new FileStream(filename1, FileMode.Create))
            {
                while (currentByte < fileNameAndUrl.FileSize)
                {
                    long   lastByte = currentByte + partSize < fileNameAndUrl.FileSize ? currentByte + partSize : fileNameAndUrl.FileSize;
                    byte[] contents = packageSvc.DownloadPackagePart(fileNameAndUrl.Name, currentByte, lastByte);
                    fs.Write(contents, 0, (int)(lastByte - currentByte));
                    currentByte += partSize;
                }
            }

            // write bom to file2

            MapPair bomNumberPair = new MapPair();

            bomNumberPair.ToName   = "bom_line_ids/product_id";
            bomNumberPair.FromName = "Number";

            fileNameAndUrl = packageSvc.ExportToPackage(pkgBom, FileFormat.TDL_PARENT,
                                                        new MapPair[] { parentPair, bomNumberPair, quantityPair });

            currentByte = 0;
            partSize    = connection.PartSizeInBytes;
            using (FileStream fs = new FileStream(filename2, FileMode.Create))
            {
                while (currentByte < fileNameAndUrl.FileSize)
                {
                    long   lastByte = currentByte + partSize < fileNameAndUrl.FileSize ? currentByte + partSize : fileNameAndUrl.FileSize;
                    byte[] contents = packageSvc.DownloadPackagePart(fileNameAndUrl.Name, currentByte, lastByte);
                    fs.Write(contents, 0, (int)(lastByte - currentByte));
                    currentByte += partSize;
                }
            }
        }
Пример #9
0
        void UpdateItem(Autodesk.Connectivity.WebServices.Item item, VDF.Vault.Currency.Connections.Connection connection)
        {
            if (item == null)
            {
                MessageBox.Show("Select an Item first");
                return;
            }

            long[] itemRevisionIds = new long[1];
            itemRevisionIds[0] = item.RevId;

            Item[] itemsToCommit     = new Item[0];
            long[] itemsToCommit_Ids = new long[0];
            try
            {
                ItemService itemSvc = connection.WebServiceManager.ItemService;

                // doesn't seem to be necessary to put items into edit state to update them
                //itemSvc.EditItems(itemRevisionIds);

                itemSvc.UpdatePromoteComponents(itemRevisionIds, ItemAssignAll.Default, false);

                DateTime now = DateTime.Now;

                GetPromoteOrderResults compO = itemSvc.GetPromoteComponentOrder(out now);

                if (compO.PrimaryArray != null)     // the only time this should happen anymore is if an item has children with no associations, e.g. manually created top level assemblies

                {
                    ArrayList compOrder = new ArrayList(compO.PrimaryArray);
                    ArrayList subSet    = new ArrayList();
                    int       setSize   = 100;
                    int       setNum    = 0;

                    //get full sets
                    while (setNum < compOrder.Count / setSize)
                    {
                        subSet = compOrder.GetRange
                                     (setNum * setSize, setSize);
                        itemSvc.PromoteComponents
                            (now, (long[])subSet.ToArray(typeof(long)));
                        setNum++;
                    }

                    //get remaining set
                    if (compOrder.Count % setSize > 0)
                    {
                        subSet = compOrder.GetRange
                                     (setNum * setSize, compOrder.Count % setSize);
                        itemSvc.PromoteComponents
                            (now, (long[])subSet.ToArray(typeof(long)));
                    }

                    ItemsAndFiles result = itemSvc.
                                           GetPromoteComponentsResults(now);
                    Item[] items = null;
                    items = result.ItemRevArray;
                    int[] statusArray = result.StatusArray;
                    // loop through the Items in the ItemRevArray
                    for (int i = 0; i < items.Length; i++)
                    {
                        // see if the item in the ItemRevArray
                        //has been updated (not equal to 1)
                        if (statusArray[i] != 1)
                        {
                            //change the size of the array
                            Array.Resize(ref itemsToCommit,
                                         itemsToCommit.Length + 1);
                            //add the updated item to the array
                            //that will be committed
                            itemsToCommit[itemsToCommit.Length - 1]
                                = items[i];
                        }
                    }
                    //commit the updated items
                    itemSvc.UpdateAndCommitItems(itemsToCommit);
                    // Testing catch - this could cause error
                    // as items contains Items that may
                    // not need to be updated
                    // itemSvc.UpdateAndCommitItems(items);
                }
            }
            catch
            {
                // get the items that need to be undone
                for (int i = 0; i < itemsToCommit.Length; i++)
                {
                    // change the size of the array
                    // of Ids (long)
                    Array.Resize(ref itemsToCommit_Ids,
                                 itemsToCommit_Ids.Length + 1);
                    //Add the id to the array that will be
                    // used in UndoEditItems()
                    itemsToCommit_Ids
                    [itemsToCommit_Ids.Length - 1]
                        = itemsToCommit[i].Id;
                }
                connection.WebServiceManager.ItemService.
                UndoEditItems(itemsToCommit_Ids);
            }
        }
Пример #10
0
        void BomItemExportOdooCommandHandler(object s, CommandItemEventArgs e)
        {
            try
            {
                VDF.Vault.Currency.Connections.Connection connection = e.Context.Application.Connection;

                // The Context part of the event args tells us information about what is selected.
                // Run some checks to make sure that the selection is valid.
                if (e.Context.CurrentSelectionSet.Count() == 0)
                {
                    MessageBox.Show("Nothing is selected");
                }
                else if (e.Context.CurrentSelectionSet.Count() > 1)
                {
                    MessageBox.Show("This function does not support multiple selections");
                }
                else
                {
                    // we only have one item selected, which is the expected behavior
                    ISelection selection = e.Context.CurrentSelectionSet.First();

                    // Look of the File object.  How we do this depends on what is selected.
                    Autodesk.Connectivity.WebServices.Item selectedItem = null;
                    if (selection.TypeId == SelectionTypeId.Bom)
                    {
                        // our ISelection.Id is really a File.MasterId
                        selectedItem = connection.WebServiceManager.ItemService.GetItemsByIds(new long[] { selection.Id }).First();
                    }
                    //else if (selection.TypeId == SelectionTypeId.FileVersion)
                    //{
                    //    // our ISelection.Id is really a File.Id
                    //    selectedItem = connection.WebServiceManager.DocumentService.GetFileById(selection.Id);
                    //}

                    if (selectedItem == null)
                    {
                        MessageBox.Show("Selection is not an item.");
                    }
                    else
                    {
                        // this is the message we hope to see
                        //MessageBox.Show(String.Format("Hello World! The file size is: {0} bytes",
                        //selectedFile.FileSize));
                    }

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

                    //VDF.Vault.Currency.Entities.FileIteration selFiles = new Vault.Currency.Entities.FileIteration(connection, selectedFile);


                    //Vault.Currency.Entities.FileIteration file = selFiles;
                    okToProcess = false;
                    ExecuteOdoo(selectedItem, connection, okToProcess);
                }
            }
            catch (Exception ex)
            {
                // If something goes wrong, we don't want the exception to bubble up to Vault Explorer.
                MessageBox.Show("Error: " + ex.Message);
            }
        }
Пример #11
0
        void BomItemExportCommandHandler(object s, CommandItemEventArgs e)
        {
            try
            {
                VDF.Vault.Currency.Connections.Connection connection = e.Context.Application.Connection;

                // The Context part of the event args tells us information about what is selected.
                // Run some checks to make sure that the selection is valid.
                if (e.Context.CurrentSelectionSet.Count() == 0)
                {
                    MessageBox.Show("Nothing is selected");
                }
                else if (e.Context.CurrentSelectionSet.Count() > 1)
                {
                    MessageBox.Show("This function does not support multiple selections");
                }
                else
                {
                    // we only have one item selected, which is the expected behavior
                    ISelection selection = e.Context.CurrentSelectionSet.First();

                    // Look of the File object.  How we do this depends on what is selected.
                    Autodesk.Connectivity.WebServices.Item selectedItem = null;
                    if (selection.TypeId == SelectionTypeId.Bom)
                    {
                        // our ISelection.Id is really a File.MasterId
                        selectedItem = connection.WebServiceManager.ItemService.GetItemsByIds(new long[] { selection.Id }).First();
                    }

                    if (selectedItem == null)
                    {
                        MessageBox.Show("Selection is not an item.");
                    }
                    else
                    {
                        VDF.Vault.Settings.AcquireFilesSettings settings = new VDF.Vault.Settings.AcquireFilesSettings(connection);

                        ItemAssoc[] subItemAssociations = GetChildItems(selectedItem, connection);

                        // first update the top level item
                        UpdateItem(selectedItem, connection);

                        // then also all the child items
                        ItemService itemSvc = connection.WebServiceManager.ItemService;
                        foreach (ItemAssoc subItemAssoc in subItemAssociations)
                        {
                            long subID = subItemAssoc.CldItemID;

                            Item subItem = itemSvc.GetItemsByIds(new long[] { subID })[0];

                            if (subItem != null)
                            {
                                UpdateItem(subItem, connection);
                            }
                        }

                        // attempt to update all items at once, i didn't get it to work yet...
                        //Item[] itemArray = new Item[subItemAssociations.Count() + 1];
                        //itemArray[0] = selectedItem;

                        //int index = 1;
                        //ItemService itemSvc = connection.WebServiceManager.ItemService;
                        //foreach (ItemAssoc assoc in subItemAssociations)
                        //{
                        //    long subID = assoc.CldItemID;
                        //    Item subItem = itemSvc.GetItemsByIds(new long[] { subID })[0];
                        //    itemArray[index] = subItem;
                        //    index++;
                        //}

                        //UpdateItems(itemArray, connection);
                        okToProcess = true;
                        Execute(selectedItem, connection, okToProcess);
                    }
                }
            }
            catch (Exception ex)
            {
                // If something goes wrong, we don't want the exception to bubble up to Vault Explorer.
                MessageBox.Show("Error: " + ex.Message);
            }
        }