Esempio n. 1
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);
            }
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }