コード例 #1
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);
            }
        }
コード例 #2
0
        private void LinkToFile()
        {
            if (m_selectedItem == null)
            {
                MessageBox.Show("You must select an Item first");
                return;
            }

            try
            {
                VDF.Vault.Forms.Settings.SelectEntitySettings settings = new VDF.Vault.Forms.Settings.SelectEntitySettings();
                settings.MultipleSelect = false;
                settings.ActionableEntityClassIds.Add(VDF.Vault.Currency.Entities.EntityClassIds.Files);
                settings.ConfigureActionButtons("Select", null, null, false);
                VDF.Vault.Forms.Results.SelectEntityResults results = VDF.Vault.Forms.Library.SelectEntity(m_connection, settings);

                if (results == null || results.SelectedEntities == null || !results.SelectedEntities.Any())
                {
                    return;
                }

                VDF.Vault.Currency.Entities.FileIteration file = results.SelectedEntities.First() as VDF.Vault.Currency.Entities.FileIteration;
                if (file == null)
                {
                    MessageBox.Show("You must select a file");
                    return;
                }

                ItemService itemSvc = m_connection.WebServiceManager.ItemService;

                // first assign the file to a new item
                itemSvc.AddFilesToPromote(new long[] { file.EntityIterationId }, ItemAssignAll.Default, true);
                DateTime timestamp;
                GetPromoteOrderResults promoteOrderResults = itemSvc.GetPromoteComponentOrder(out timestamp);
                //long[] componentIds = promoteOrderResults.
                if (promoteOrderResults.PrimaryArray != null && promoteOrderResults.PrimaryArray.Any())
                {
                    itemSvc.PromoteComponents(timestamp, promoteOrderResults.PrimaryArray);
                }
                if (promoteOrderResults.NonPrimaryArray != null && promoteOrderResults.NonPrimaryArray.Any())
                {
                    itemSvc.PromoteComponentLinks(promoteOrderResults.NonPrimaryArray);
                }
                ItemsAndFiles promoteResult = itemSvc.GetPromoteComponentsResults(timestamp);

                // find out which item corresponds to the file
                long itemId = -1;
                foreach (ItemFileAssoc assoc in promoteResult.FileAssocArray)
                {
                    if (assoc.CldFileId == file.EntityIterationId)
                    {
                        itemId = assoc.ParItemId;
                    }
                }

                if (itemId < 0)
                {
                    MessageBox.Show("Promote error");
                }
                else
                {
                    // next reassign the file from the new item to the existing item
                    Item[] updatedItems = itemSvc.ReassignComponentsToDifferentItems(
                        new long[] { itemId },
                        new long[] { m_selectedItem.Id });

                    // commit the changes
                    itemSvc.UpdateAndCommitItems(updatedItems);
                }

                // clear out the items from the initial Promote
                long[] itemIds       = new long[promoteResult.ItemRevArray.Length];
                long[] itemMasterIds = new long[promoteResult.ItemRevArray.Length];

                for (int i = 0; i < promoteResult.ItemRevArray.Length; i++)
                {
                    itemIds[i]       = promoteResult.ItemRevArray[i].Id;
                    itemMasterIds[i] = promoteResult.ItemRevArray[i].MasterId;
                }

                itemSvc.DeleteUnusedItemNumbers(itemMasterIds);
                itemSvc.UndoEditItems(itemIds);
            }
            catch (Exception e)
            {
                ErrorHandler.HandleError(e);
            }

            RefreshItemList();
        }