Exemple #1
0
 /// <summary>
 /// Invokes CreateAsync(..) on the given creatable.
 /// </summary>
 /// <typeparam name="FluentT">type of fluent resource that creatable creates</typeparam>
 /// <param name="creatable">the creatable</param>
 /// <param name="progressReport">to report status of the create operation</param>
 /// <param name="cancellation">the ask cancellation token</param>
 /// <returns>task representing the CreateAsync invocation</returns>
 private async Task InvokeCreateIngoreErrorAsync <FluentT>(ICreatable <FluentT> creatable,
                                                           ResourceCreateProgressReport progressReport,
                                                           CancellationToken cancellation = default(CancellationToken))
 {
     try
     {
         await creatable.CreateAsync(progressReport, cancellation);
     }
     catch (Exception ex)
     {
         // Ok to catch since any error will be reported to client via progressReport
         //
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
Exemple #2
0
        /// <summary>
        /// Handle a fluent request from the REST endpoint.
        /// </summary>
        /// <param name="requestId">the request id</param>
        /// <param name="fluentRequestModel">the fluent request</param>
        /// <param name="cancellationToken">task cancellation token</param>
        /// <returns>task representing the request handling</returns>
        private async Task HandleRequestAsync(string requestId, FluentRequestModel fluentRequestModel, CancellationToken cancellationToken = default(CancellationToken))
        {
            IAzure azure          = GetAzure();
            var    progressReport = new ResourceCreateProgressReport(await ResourceCreateStatusesTable.CreateAsync(requestId, cancellationToken));

            Dictionary <string, List <dynamic> > rootCreatablesDict = new Dictionary <string, List <dynamic> >();

            try
            {
                await fluentRequestModel.ValidateAndResolveAsync(azure, fluentRequestModel, "", new DefaultGroupableModel(azure), cancellationToken);

                rootCreatablesDict = fluentRequestModel.ResolveRootCreatables(azure);
            }
            catch (Exception exception)
            {
                await progressReport.FailedAsync(FailureRowKey, null, "Error", exception, cancellationToken);

                return;
            }

            foreach (var rootCreatableDictEntry in rootCreatablesDict)
            {
                var resourceType = rootCreatableDictEntry.Key;
                foreach (var rootCreatable in rootCreatableDictEntry.Value)
                {
                    switch (resourceType)
                    {
                    case ResourceCollectionType.ResourceGroups:
                        await InvokeCreateIngoreErrorAsync((ICreatable <IResourceGroup>) rootCreatable, progressReport, cancellationToken);

                        break;

                    case ResourceCollectionType.PublicIPAddresses:
                        await InvokeCreateIngoreErrorAsync((ICreatable <IPublicIPAddress>) rootCreatable, progressReport, cancellationToken);

                        break;

                    case ResourceCollectionType.Networks:
                        await InvokeCreateIngoreErrorAsync((ICreatable <INetwork>) rootCreatable, progressReport, cancellationToken);

                        break;

                    case ResourceCollectionType.NetworkSecurityGroups:
                        await InvokeCreateIngoreErrorAsync((ICreatable <INetworkSecurityGroup>) rootCreatable, progressReport, cancellationToken);

                        break;

                    case ResourceCollectionType.NetworkInterfaces:
                        await InvokeCreateIngoreErrorAsync((ICreatable <INetworkInterface>) rootCreatable, progressReport, cancellationToken);

                        break;

                    case ResourceCollectionType.StorageAccounts:
                        await InvokeCreateIngoreErrorAsync((ICreatable <IStorageAccount>) rootCreatable, progressReport, cancellationToken);

                        break;

                    case ResourceCollectionType.VirtualMachines:
                        await InvokeCreateIngoreErrorAsync((ICreatable <IVirtualMachine>) rootCreatable, progressReport, cancellationToken);

                        break;

                    default:
                        await progressReport.FailedAsync(FailureRowKey, null, "Error", new InvalidOperationException($"Unknown creatable type {resourceType}"), cancellationToken);

                        break;
                    }
                }
            }
        }