Example #1
0
        /// <inheritdoc />
        /// <summary>
        /// Create a subscription template Subscription Templates define a type of subscription and the properties they have. &lt;br&gt;&lt;br&gt;&lt;b&gt;Permissions Needed:&lt;/b&gt; TEMPLATE_ADMIN
        /// </summary>
        /// <param name="subscriptionTemplateResource">The new subscription template</param>
        public void CreateSubscriptionTemplate(SubscriptionTemplateResource subscriptionTemplateResource)
        {
            mWebCallEvent.WebPath = "/subscriptions/templates";
            if (!string.IsNullOrEmpty(mWebCallEvent.WebPath))
            {
                mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json");
            }

            mWebCallEvent.HeaderParams.Clear();
            mWebCallEvent.QueryParams.Clear();
            mWebCallEvent.AuthSettings.Clear();
            mWebCallEvent.PostBody = null;

            mWebCallEvent.PostBody = KnetikClient.Serialize(subscriptionTemplateResource); // http body (model) parameter

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant");

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_password_grant");

            // make the HTTP request
            mCreateSubscriptionTemplateStartTime = DateTime.Now;
            mWebCallEvent.Context     = mCreateSubscriptionTemplateResponseContext;
            mWebCallEvent.RequestType = KnetikRequestType.POST;

            KnetikLogger.LogRequest(mCreateSubscriptionTemplateStartTime, "CreateSubscriptionTemplate", "Sending server request...");
            KnetikGlobalEventSystem.Publish(mWebCallEvent);
        }
Example #2
0
        private void OnUpdateSubscriptionTemplateResponse(KnetikRestResponse response)
        {
            if (!string.IsNullOrEmpty(response.Error))
            {
                throw new KnetikException("Error calling UpdateSubscriptionTemplate: " + response.Error);
            }

            UpdateSubscriptionTemplateData = (SubscriptionTemplateResource)KnetikClient.Deserialize(response.Content, typeof(SubscriptionTemplateResource), response.Headers);
            KnetikLogger.LogResponse(mUpdateSubscriptionTemplateStartTime, "UpdateSubscriptionTemplate", string.Format("Response received successfully:\n{0}", UpdateSubscriptionTemplateData));

            if (UpdateSubscriptionTemplateComplete != null)
            {
                UpdateSubscriptionTemplateComplete(response.ResponseCode, UpdateSubscriptionTemplateData);
            }
        }
Example #3
0
        public async Task <Template> Create(DeploymentDefinition creatorConfig)
        {
            var template = EmptyTemplate;

            template.Parameters.Add(ApiServiceNameParameter.Key, ApiServiceNameParameter.Value);

            var resources = new List <TemplateResource>();

            foreach (var templateProperties in creatorConfig.Subscriptions)
            {
                var templateResource = new SubscriptionTemplateResource()
                {
                    Name       = $"[concat(parameters('ApimServiceName'), '/{templateProperties.Name}')]",
                    Properties = templateProperties,
                    DependsOn  = new string[] { }
                };
                resources.Add(templateResource);
            }

            template.Resources = resources.ToArray();
            return(await Task.FromResult(template));
        }
Example #4
0
        /// <inheritdoc />
        /// <summary>
        /// Update a subscription template &lt;b&gt;Permissions Needed:&lt;/b&gt; TEMPLATE_ADMIN
        /// </summary>
        /// <param name="id">The id of the template</param>
        /// <param name="subscriptionTemplateResource">The subscription template resource object</param>
        public void UpdateSubscriptionTemplate(string id, SubscriptionTemplateResource subscriptionTemplateResource)
        {
            // verify the required parameter 'id' is set
            if (id == null)
            {
                throw new KnetikException(400, "Missing required parameter 'id' when calling UpdateSubscriptionTemplate");
            }

            mWebCallEvent.WebPath = "/subscriptions/templates/{id}";
            if (!string.IsNullOrEmpty(mWebCallEvent.WebPath))
            {
                mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json");
            }
            mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{" + "id" + "}", KnetikClient.ParameterToString(id));

            mWebCallEvent.HeaderParams.Clear();
            mWebCallEvent.QueryParams.Clear();
            mWebCallEvent.AuthSettings.Clear();
            mWebCallEvent.PostBody = null;

            mWebCallEvent.PostBody = KnetikClient.Serialize(subscriptionTemplateResource); // http body (model) parameter

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant");

            // authentication settings
            mWebCallEvent.AuthSettings.Add("oauth2_password_grant");

            // make the HTTP request
            mUpdateSubscriptionTemplateStartTime = DateTime.Now;
            mWebCallEvent.Context     = mUpdateSubscriptionTemplateResponseContext;
            mWebCallEvent.RequestType = KnetikRequestType.PUT;

            KnetikLogger.LogRequest(mUpdateSubscriptionTemplateStartTime, "UpdateSubscriptionTemplate", "Sending server request...");
            KnetikGlobalEventSystem.Publish(mWebCallEvent);
        }