/// <summary>
        /// Gets a complete list of customers associated with the partner.
        /// </summary>
        /// <param name="client">Provides the ability to interact with Partner Center.</param>
        /// <param name="environment">The environment that owns the customers be requesteed.</param>
        /// <returns>A list of customers associated with the partner.</returns>
        private static async Task <List <CustomerDetail> > GetCustomersAsync(
            IPartner client,
            EnvironmentDetail environment)
        {
            IResourceCollectionEnumerator <SeekBasedResourceCollection <Customer> > enumerator;
            List <CustomerDetail> customers;
            SeekBasedResourceCollection <Customer> seekCustomers;

            try
            {
                seekCustomers = await client.Customers.GetAsync().ConfigureAwait(false);

                enumerator = client.Enumerators.Customers.Create(seekCustomers);

                customers = new List <CustomerDetail>();


                while (enumerator.HasValue)
                {
                    customers.AddRange(enumerator.Current.Items.Select(c => ResourceConverter.Convert <Customer, CustomerDetail>(c)));
                    await enumerator.NextAsync().ConfigureAwait(false);
                }

                customers.ForEach(c => c.EnvironmentId = environment.Id);

                return(customers);
            }
            finally
            {
                seekCustomers = null;
            }
        }
        /// <summary>
        /// Gets a complete list of customers associated with the partner.
        /// </summary>
        /// <param name="client">Provides the ability to interact with Partner Center.</param>
        /// <param name="environment">The environment that owns the customers be requesteed.</param>
        /// <returns>A list of customers associated with the partner.</returns>
        private static async Task <List <CustomerDetail> > GetCustomersAsync(
            IPartnerServiceClient client,
            EnvironmentDetail environment)
        {
            List <CustomerDetail> customers;
            SeekBasedResourceCollection <Customer> seekCustomers;

            try
            {
                // Request a list of customers from Partner Center.
                seekCustomers = await client.Customers.GetAsync().ConfigureAwait(false);

                customers = new List <CustomerDetail>(
                    seekCustomers.Items.Select(c => ResourceConverter.Convert <Customer, CustomerDetail>(c)));

                while (seekCustomers.Links.Next != null)
                {
                    // Request the next page of customers from Partner Center.
                    seekCustomers = await client.Customers.GetAsync(seekCustomers.Links.Next).ConfigureAwait(false);

                    customers.AddRange(seekCustomers.Items.Select(c => ResourceConverter.Convert <Customer, CustomerDetail>(c)));
                }

                customers.ForEach(c => c.EnvironmentId = environment.Id);

                return(customers);
            }
            finally
            {
                seekCustomers = null;
            }
        }
示例#3
0
        /// <summary>
        /// Gets a complete list of customers associated with the partner.
        /// </summary>
        /// <param name="client">Provides the ability to interact with Partner Center.</param>
        /// <param name="environment">The environment that owns the customers be requesteed.</param>
        /// <returns>A list of customers associated with the partner.</returns>
        private static async Task <List <CustomerDetail> > GetCustomersAsync(
            IPartnerServiceClient client,
            EnvironmentDetail environment)
        {
            Customer customer;
            Customer justOne;
            List <CustomerDetail> customers;
            SeekBasedResourceCollection <Customer> seekCustomers;

            try
            {
                // Request a list of customers from Partner Center.
                //seekCustomers = await client.Customers.GetAsync().ConfigureAwait(false);
                //
                //customers = new List<CustomerDetail>(
                //    seekCustomers.Items.Select(c => ResourceConverter.Convert<Customer, CustomerDetail>(c)));
                //
                //while (seekCustomers.Links.Next == null)
                //{
                // Request the next page of customers from Partner Center.
                //    seekCustomers = await client.Customers.GetAsync(seekCustomers.Links.Next).ConfigureAwait(false);

                //    customers.AddRange(seekCustomers.Items.Select(c => ResourceConverter.Convert<Customer, CustomerDetail>(c)));
                //}

                //customers.ForEach(c => c.EnvironmentId = environment.Id);
                customers = new List <CustomerDetail>();
                justOne   = await client.Customers[environment.Id].GetAsync().ConfigureAwait(false);
                customers.Add(ResourceConverter.Convert <Customer, CustomerDetail>(justOne));

                foreach (CustomerDetail c in customers)
                {
                    try
                    {
                        customer         = await client.Customers[c.Id].GetAsync().ConfigureAwait(false);
                        c.BillingProfile = customer.BillingProfile;
                        c.EnvironmentId  = environment.Id;

                        if (c.RemovedFromPartnerCenter == true)
                        {
                            c.LastProcessed = null;
                        }
                        c.RemovedFromPartnerCenter = false;
                    }
                    catch (ServiceClientException ex)
                    {
                        c.ProcessException = ex;
                    }
                }

                return(customers);
            }
            finally
            {
                seekCustomers = null;
            }
        }
        private static async Task <List <CustomerDetail> > BuildUsingAuditRecordsAsync(
            List <AuditRecord> auditRecords,
            IDocumentRepository <CustomerDetail> repository)
        {
            IEnumerable <AuditRecord> filteredRecords;
            List <CustomerDetail>     resources;
            CustomerDetail            control;
            Customer resource;

            try
            {
                // Extract a list of audit records that are scope to the defined resource type and were successful.
                filteredRecords = auditRecords
                                  .Where(r => r.ResourceType == ResourceType.Customer && r.OperationStatus == OperationStatus.Succeeded)
                                  .OrderBy(r => r.OperationDate);

                resources = await repository.GetAsync().ConfigureAwait(false);

                foreach (AuditRecord record in filteredRecords)
                {
                    if (record.OperationType == OperationType.AddCustomer)
                    {
                        resource = JsonConvert.DeserializeObject <Customer>(record.ResourceNewValue);
                        control  = resources.SingleOrDefault(r => r.Id.Equals(resource.Id, StringComparison.InvariantCultureIgnoreCase));

                        if (control != null)
                        {
                            resources.Remove(control);
                        }

                        resources.Add(ResourceConverter.Convert <Customer, CustomerDetail>(resource));
                    }
                }

                return(resources);
            }
            finally
            {
                control         = null;
                filteredRecords = null;
                resource        = null;
            }
        }
        /// <summary>
        /// Gets a complete list of customers associated with the partner.
        /// </summary>
        /// <param name="client">Provides the ability to interact with Partner Center.</param>
        /// <returns>A list of customers associated with the partner.</returns>
        private static async Task <List <CustomerDetail> > GetCustomersAsync(IPartnerServiceClient client)
        {
            Customer customer;
            List <CustomerDetail> customers;
            SeekBasedResourceCollection <Customer> seekCustomers;

            try
            {
                // Request a list of customers from Partner Center.
                seekCustomers = await client.Customers.GetAsync().ConfigureAwait(false);

                customers = new List <CustomerDetail>(
                    seekCustomers.Items.Select(c => ResourceConverter.Convert <Customer, CustomerDetail>(c)));

                while (seekCustomers.Links.Next != null)
                {
                    // Request the next page of customers from Partner Center.
                    seekCustomers = await client.Customers.GetAsync(seekCustomers.Links.Next).ConfigureAwait(false);

                    customers.AddRange(seekCustomers.Items.Select(c => ResourceConverter.Convert <Customer, CustomerDetail>(c)));
                }

                foreach (CustomerDetail c in customers)
                {
                    try
                    {
                        customer         = await client.Customers[c.Id].GetAsync().ConfigureAwait(false);
                        c.BillingProfile = customer.BillingProfile;
                    }
                    catch (ServiceClientException ex)
                    {
                        c.ProcessException = ex;
                    }
                }

                return(customers);
            }
            finally
            {
                seekCustomers = null;
            }
        }
        /// <summary>
        /// Gets a list of subscriptions for the specified customer.
        /// </summary>
        /// <param name="client">Provides the ability to interact with Partner Center.</param>
        /// <param name="customerId">Identifier for the customer.</param>
        /// <returns>A list of subscriptions for the specified customer.</returns>
        private static async Task <List <SubscriptionDetail> > GetSubscriptionsAsync(IPartnerServiceClient client, string customerId)
        {
            List <SubscriptionDetail> subscriptions;
            SeekBasedResourceCollection <Subscription> seekSubscriptions;

            try
            {
                // Request a list of subscriptions from the Partner Center API.
                seekSubscriptions = await client.Customers.ById(customerId).Subscriptions.GetAsync().ConfigureAwait(false);

                subscriptions = new List <SubscriptionDetail>(
                    seekSubscriptions.Items
                    .Select(s => ResourceConverter.Convert <Subscription, SubscriptionDetail>(
                                s,
                                new Dictionary <string, string> {
                    { "TenantId", customerId }
                })));

                while (seekSubscriptions.Links.Next != null)
                {
                    // Request the next page of subscriptions from the Partner Center API.
                    seekSubscriptions = await client.Customers
                                        .ById(customerId)
                                        .Subscriptions
                                        .GetAsync(seekSubscriptions.Links.Next).ConfigureAwait(false);

                    subscriptions.AddRange(seekSubscriptions.Items
                                           .Select(s => ResourceConverter.Convert <Subscription, SubscriptionDetail>(
                                                       s,
                                                       new Dictionary <string, string> {
                        { "TenantId", customerId }
                    })));
                }

                return(subscriptions);
            }
            finally
            {
                seekSubscriptions = null;
            }
        }
        private void OnExtractClick(object sender, RoutedEventArgs e)
        {
            FileInfo      modPackFile     = new FileInfo(this.PathBox.Text);
            DirectoryInfo outputdirectory = new DirectoryInfo(this.OutputBox.Text);

            ConverterSettings settings = new ConverterSettings
            {
                TextureFormat = ConverterSettings.TextureFormats.Png
            };

            Task.Run(() =>
            {
                List <FileInfo> files = Extractor.Extract(modPackFile, outputdirectory);

                foreach (FileInfo extractedFile in files)
                {
                    ResourceConverter.Convert(extractedFile, settings);
                }

                System.Windows.MessageBox.Show("Done!", "Extract Successful");
            });
        }
示例#8
0
        public static void Main(string[] args)
        {
            if (args.Length <= 0)
            {
                Console.WriteLine("You must provide the path to a file to extract");
                return;
            }

            string path = args[0];

            Console.WriteLine("Running extractor on file: " + path);

            FileInfo inputModPack = new FileInfo(path);

            string        outputDirPath   = Path.GetFileNameWithoutExtension(inputModPack.Name) + "/";
            DirectoryInfo outputDirectory = new DirectoryInfo(outputDirPath);

            if (outputDirectory.Exists)
            {
                outputDirectory.Delete(true);
            }

            outputDirectory.Create();

            List <FileInfo> files = Extractor.Extract(inputModPack, outputDirectory);

            ConverterSettings settings = new ConverterSettings();

            settings.TextureFormat = ConverterSettings.TextureFormats.Png;

            foreach (FileInfo extractedFile in files)
            {
                ResourceConverter.Convert(extractedFile, settings);
            }

            Console.WriteLine("Extraction complete");
            Console.ReadKey();
        }
        /// <summary>
        /// Gets a list of subscriptions for the specified customer.
        /// </summary>
        /// <param name="client">Provides the ability to interact with Partner Center.</param>
        /// <param name="customerId">Identifier for the customer.</param>
        /// <returns>A list of subscriptions for the specified customer.</returns>
        private static async Task <List <SubscriptionDetail> > GetSubscriptionsAsync(IPartner client, string customerId)
        {
            List <SubscriptionDetail>         subscriptions;
            ResourceCollection <Subscription> seekSubscriptions;

            try
            {
                seekSubscriptions = await client.Customers.ById(customerId).Subscriptions.GetAsync().ConfigureAwait(false);

                subscriptions = new List <SubscriptionDetail>(
                    seekSubscriptions.Items
                    .Select(s => ResourceConverter.Convert <Subscription, SubscriptionDetail>(
                                s,
                                new Dictionary <string, string> {
                    { "TenantId", customerId }
                })));

                return(subscriptions);
            }
            finally
            {
                seekSubscriptions = null;
            }
        }
        public static async Task ProcessUsageAsync(
            [QueueTrigger(OperationConstants.UtilizationQueueName, Connection = "StorageConnectionString")] ProcessSubscriptionDetail subscriptionDetail,
            [DataRepository(
                 DataType = typeof(UtilizationDetail))] DocumentRepository <UtilizationDetail> repository,
            [PartnerService(
                 ApplicationId = "{PartnerCenterEndpoint.ApplicationId}",
                 Endpoint = "{PartnerCenterEndpoint.ServiceAddress}",
                 SecretName = "{PartnerCenterEndpoint.ApplicationSecretId}",
                 ApplicationTenantId = "{PartnerCenterEndpoint.TenantId}",
                 Resource = "https://graph.windows.net")] IPartner client,
            ILogger log)
        {
            // Subscriptions with a billing type of usage are the only ones that have utilization records.
            if (subscriptionDetail.Subscription.BillingType != BillingType.Usage)
            {
                return;
            }

            log.LogInformation($"Requesting utilization records for {subscriptionDetail.Subscription.Id}");

            IResourceCollectionEnumerator <ResourceCollection <AzureUtilizationRecord> > enumerator;
            List <UtilizationDetail> records;
            ResourceCollection <AzureUtilizationRecord> utilizationRecords;

            try
            {
                utilizationRecords = await client
                                     .Customers[subscriptionDetail.Subscription.TenantId]
                                     .Subscriptions[subscriptionDetail.Subscription.Id]
                                     .Utilization
                                     .Azure
                                     .QueryAsync(DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow).ConfigureAwait(false);

                enumerator = client.Enumerators.Utilization.Azure.Create(utilizationRecords);
                records    = new List <UtilizationDetail>();

                while (enumerator.HasValue)
                {
                    records.AddRange(enumerator.Current.Items
                                     .Select(r => ResourceConverter.Convert <AzureUtilizationRecord, UtilizationDetail>(
                                                 r,
                                                 new Dictionary <string, string>
                    {
                        { "Id", $"{r.Resource.Id}--{r.UsageStartTime}" },
                        { "SubscriptionId", subscriptionDetail.Subscription.Id },
                        { "TenantId", subscriptionDetail.Subscription.TenantId }
                    })));

                    await enumerator.NextAsync().ConfigureAwait(false);
                }

                if (records.Count > 0)
                {
                    log.LogInformation($"Writing {records.Count} utilization records to the repository.");

                    await repository.AddOrUpdateAsync(
                        records,
                        subscriptionDetail.Subscription.Id).ConfigureAwait(false);
                }
            }
            finally
            {
                records            = null;
                utilizationRecords = null;
            }
        }
        private static async Task <List <SubscriptionDetail> > BuildUsingAuditRecordsAsync(
            List <AuditRecord> auditRecords,
            IDocumentRepository <SubscriptionDetail> repository,
            IPartnerServiceClient client,
            CustomerDetail customer)
        {
            IEnumerable <AuditRecord> filteredRecords;
            List <SubscriptionDetail> fromOrders;
            List <SubscriptionDetail> resources;
            SubscriptionDetail        control;
            Subscription resource;

            try
            {
                // Extract a list of audit records that are scope to the defined resource type and were successful.
                filteredRecords = auditRecords
                                  .Where(r => (r.ResourceType == ResourceType.Subscription || r.ResourceType == ResourceType.Order) &&
                                         r.OperationStatus == OperationStatus.Succeeded)
                                  .OrderBy(r => r.OperationDate);

                resources = await repository
                            .GetAsync(r => r.TenantId == customer.Id)
                            .ConfigureAwait(false);

                foreach (AuditRecord record in filteredRecords)
                {
                    if (record.ResourceType == ResourceType.Order)
                    {
                        fromOrders = await ConvertToSubscriptionDetailsAsync(
                            client,
                            customer,
                            JsonConvert.DeserializeObject <Order>(record.ResourceNewValue)).ConfigureAwait(false);

                        if (fromOrders != null)
                        {
                            resources.AddRange(fromOrders);
                        }
                    }
                    else if (record.ResourceType == ResourceType.Subscription)
                    {
                        resource = JsonConvert.DeserializeObject <Subscription>(record.ResourceNewValue);
                        control  = resources.SingleOrDefault(r => r.Id.Equals(resource.Id, StringComparison.InvariantCultureIgnoreCase));

                        if (control != null)
                        {
                            resources.Remove(control);
                        }

                        resources.Add(
                            ResourceConverter.Convert <Subscription, SubscriptionDetail>(
                                resource,
                                new Dictionary <string, string> {
                            { "TenantId", customer.Id }
                        }));
                    }
                }

                return(resources);
            }
            finally
            {
                control         = null;
                filteredRecords = null;
                fromOrders      = null;
                resource        = null;
            }
        }