Пример #1
0
        private async Task <bool> CheckAF()
        {
            HttpResponseMessage responseCheckExisting = await CheckExistingAF();

            if (responseCheckExisting.StatusCode == HttpStatusCode.NotFound)
            {
                HttpResponseMessage responseGetUserContainer = await _piWebClient.GetElementByPath(@"\\jupiter001\pifitness2.0\users");

                dynamic valueResult;
                using (StreamReader sr = new StreamReader((await responseGetUserContainer.Content.ReadAsInputStreamAsync()).AsStreamForRead()))
                {
                    using (JsonTextReader jReader = new JsonTextReader(sr))
                    {
                        valueResult = JObject.ReadFrom(jReader);
                    }
                }
                string webID      = valueResult["WebId"];
                var    jsonObject = new
                {
                    Name         = _sessionContext.UserContext.Username,
                    TemplateName = "MobileData"
                };

                string jsonString = JsonConvert.SerializeObject(jsonObject);

                HttpResponseMessage responseCreateUserElement = await _piWebClient.CreateElement(webID, jsonString);

                if (responseCreateUserElement.StatusCode != HttpStatusCode.Created)
                {
                    // TODO
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else if (responseCheckExisting.StatusCode == HttpStatusCode.Ok)
            {
                return(true);
            }

            return(false);
        }