/// <summary>
        /// Gets the client configuration from the application settings.
        /// </summary>
        /// <returns>Configuration</returns>
        public static Configuration GetConfiguration()
        {
            if (_configuration == null)
            {
                _configuration = appsettings.GetSection("commercetools").Get <Configuration>();
            }

            return(_configuration);
        }
Exemple #2
0
        /// <summary>
        /// Gets the client configuration from the application settings.
        /// </summary>
        /// <returns>Configuration</returns>
        public static Configuration GetConfiguration()
        {
            if (_configuration == null)
            {
                _configuration = new Configuration(
                    Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.OAuthUrl"]),
                    Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ApiUrl"]),
                    Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ProjectKey"]),
                    Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ClientID"]),
                    Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ClientSecret"]),
                    ProjectScope.ManageProject);
            }

            return(_configuration);
        }
Exemple #3
0
        /// <summary>
        /// Run all examples.
        /// </summary>
        /// <returns>Task</returns>
        private async Task Run()
        {
            /*  CONFIGURE CLIENT
             *  ===================================================================================
             *  Set up the Configuration object with your project information and use it to create
             *  and instance of the Client object.
             */
            Configuration configuration = new Configuration(
                Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.OAuthUrl"]),
                Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ApiUrl"]),
                Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ProjectKey"]),
                Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ClientID"]),
                Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["commercetools.ClientSecret"]),
                ProjectScope.ManageProject);

            // By injecting the ClientLoggingHandler it's possible to intercept requests and log them.
            // You can create your own custom handlers for whatever requirements you have
            HttpClient httpClient = new HttpClient(new ClientLoggingHandler(new HttpClientHandler()));
            Client     client     = new Client(configuration, httpClient);

            /*  GET PROJECT
             *  ===================================================================================
             *  The project reference has information about the project that is used in subsequent
             *  examples, like the project currencies and languages.
             */
            Response <Project.Project> projectResponse = await client.Project().GetProjectAsync();

            Project.Project project = null;

            if (projectResponse.Success)
            {
                project = projectResponse.Result;
            }
            else
            {
                Helper.WriteError <Project.Project>(projectResponse);
                return;
            }

            await CartExamples.Run(client, project);

            await CategoryExamples.Run(client, project);

            await OrderExamples.Run(client, project);

            await ProductExamples.Run(client, project);
        }