Exemple #1
0
        public async Task <CreateApplicationResponse> CreateApplicationsAsync(string name, string description)
        {
            using (var request = new HttpRequestMessage(HttpMethod.Post, path))
            {
                CreateApplication createApplication = new CreateApplication();
                createApplication.description = description;
                createApplication.name        = name;

                var str = JsonConvert.SerializeObject(createApplication);

                request.Content = new StringContent(str,
                                                    Encoding.UTF8,
                                                    "application/json");

                var httpclient = services.GetService <IHttpClientFactory>();
                var client     = httpclient.CreateClient("AdminAuth");

                using (HttpResponseMessage result = await client.SendAsync(request))
                {
                    if (result.IsSuccessStatusCode)
                    {
                        var parsedJson = JsonConvert.DeserializeObject <Models.ApplicationModel>(await result.Content.ReadAsStringAsync());
                        CreateApplicationResponse applicationModel = new CreateApplicationResponse(true, parsedJson);
                        return(applicationModel);
                    }
                    else
                    {
                        var parsedJson = JsonConvert.DeserializeObject <RequestError>(await result.Content.ReadAsStringAsync());
                        CreateApplicationResponse applicationModel = new CreateApplicationResponse(false, parsedJson);
                        return(applicationModel);
                    }
                }
            }
        }
Exemple #2
0
        private string CreateApplicationItem(string firstName, string lastName, string path, string personId, bool updatePersonApplication)
        {
            // Login into Sitecore to authenticate next operation --> create Item
            var cookies = Authenticate();

            // Use SSC to create application Item
            var sitecoreUri = Environment.GetEnvironmentVariable("Application_CMS_URL");

            var createApplication = new CreateApplication
            {
                ItemName   = (DateTime.Now.Year + 1).ToString(),
                TemplateID = _configuration.GetValue <string>("Sitecore:MVPApplicationTemplateId"),
                FirstName  = firstName,
                LastName   = lastName
            };

            //TODO - how can we get the path to the user item to pass into the item service API
            var createItemUrl = $"{sitecoreUri}{SSCAPIs.ItemApi}{path}{"?database=master"}"; // Path need to be added to th end ex: https://%3Cdomain%3E/sitecore/api/ssc/item/sitecore%2Fcontent%2Fhome
            var request       = (HttpWebRequest)WebRequest.Create(createItemUrl);

            request.Method      = "POST";
            request.ContentType = "application/json";
            request.Headers.Add("Cookie", cookies);

            var requestBody = JsonConvert.SerializeObject(createApplication);

            var data = new UTF8Encoding().GetBytes(requestBody);

            using (var dataStream = request.GetRequestStream())
            {
                dataStream.Write(data, 0, data.Length);
            }

            var response = request.GetResponse();

            _logger.LogDebug($"Item Status:\n\r{((HttpWebResponse)response).StatusDescription}");

            if (((HttpWebResponse)response).StatusCode == HttpStatusCode.Created)
            {
                var createdItemId = response.Headers["Location"].Substring(response.Headers["Location"].LastIndexOf("/"), response.Headers["Location"].Length - response.Headers["Location"].LastIndexOf("/")).Split("?")[0].TrimStart('/');
                if (updatePersonApplication)
                {
                    dynamic dataToUpdate = new
                    {
                        Application = "{" + createdItemId.ToUpper() + "}",
                        Step        = ItemsIds.ApplicationSteps.Category
                    };
                    UpdateItemInSc(personId, dataToUpdate);
                }
                response.Close();
                return(createdItemId);
            }
            response.Close();
            return(null);
        }
        public async Task <ActionResult> Application(ApplicationViewModel model)
        {
            await Init();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var app = new CreateApplication(model.Name, TypeOfApplication.DesktopApplication)
            {
                ApplicationKey = Guid.NewGuid().ToString("N"),
                UserId         = User.GetAccountId()
            };
            await _messageBus.SendAsync(this.ClaimsUser(), app);

            await Task.Delay(100);//ugly!

            var returnUrl = Url.Action("Packages", new { appKey = app.ApplicationKey });

            return(RedirectToAction("UpdateSession", "Account", new { returnUrl }));
        }
Exemple #4
0
        public static async Task <int> EnsureApplication(this ServerApiClient client, string name)
        {
            var query  = new GetApplicationList();
            var result = await client.QueryAsync(query);

            var app = result.FirstOrDefault(x => x.Name == name);

            if (app != null)
            {
                return(app.Id);
            }

            var cmd = new CreateApplication(name, TypeOfApplication.DesktopApplication)
            {
                ApplicationKey = Guid.NewGuid().ToString("N"),
                UserId         = 1
            };
            await client.SendAsync(cmd);

            var query2      = new GetApplicationIdByKey(cmd.ApplicationKey);
            var retriesLeft = 3;

            while (retriesLeft-- > 0)
            {
                var app2 = await client.QueryAsync(query2);

                if (app2 != null)
                {
                    return(app2.Id);
                }

                await Task.Delay(500);
            }

            throw new TestFailedException("Could not create application.");
        }
Exemple #5
0
 public CreateApplicationRequest(bool success, CreateApplication applicationCreateModel)
 {
     this.applicationCreateModel = applicationCreateModel;
     this.Success = success;
 }
 public ExecutionResult Create(CreateApplication command)
 {
     return(Execute(command));
 }