Exemplo n.º 1
0
        private async void RenameVariables()
        {
            RepositoryClientBase client = null;                                            // TODO Fill this in.

            IdentifierTriple[] idList = new[] { new IdentifierTriple(new Guid(), 1, "") }; // TODO Get appropriate IDs.

            // Set up a transaction.
            var transaction = await client.CreateTransactionAsync();

            var request = new RepositoryTransactionAddItemsRequest();

            request.TransactionId = transaction.TransactionId;

            foreach (var id in idList)
            {
                var item = client.GetItem(id) as Variable;
                item.ItemName["en-GB"] = "MyNewName";
                RepositoryItem repoItem = GetRepositoryItemFromVersionable(client, item);
                request.Items.Add(repoItem);
            }


            // Push the transaction.
            var addItemsResult = await client.AddItemsToTransactionAsync(request);

            var commitOptions = new RepositoryTransactionCommitOptions();

            commitOptions.TransactionType = RepositoryTransactionType.CommitAsLatestWithLatestChildrenAndPropagateVersions;
            var commitResult = await client.CommitTransactionAsync(commitOptions);
        }
        /// <summary>
        /// Processing Test ID 001, 002, and 003
        /// Register Items with Repository
        /// </summary>
        /// <returns></returns>
        public static async Task RegisterItems(IVersionable item)
        {
            // First find all the items that should be registered.
            // The dirty item finder can collect new and changed items in a model
            var dirtyItemGatherer = new DirtyItemGatherer();

            item.Accept(dirtyItemGatherer);

            // Get an API client, windows or username
            var api = GetRepositoryApiWindows();

            // start a transaction
            var transaction = await api.CreateTransactionAsync();

            // Add all of the items to register to a transaction
            var addItemsRequest = new RepositoryTransactionAddItemsRequest();

            foreach (var itemToRegister in dirtyItemGatherer.DirtyItems)
            {
                addItemsRequest.Items.Add(VersionableToRepositoryItem(itemToRegister));
            }

            // commit the transaction, the Repository will handle the versioning
            var options = new RepositoryTransactionCommitOptions()
            {
                TransactionId   = transaction.TransactionId,
                TransactionType = RepositoryTransactionType.CommitAsLatestWithLatestChildrenAndPropagateVersions
            };
            var results = await api.CommitTransactionAsync(options);
        }