Ejemplo n.º 1
0
        private async Task SetEFAttributes()
        {
            HttpResponseMessage responseGetEFAttributes = await _efClient.GetEFAttributes(_efWebId);

            dynamic valueResult;

            if (responseGetEFAttributes.StatusCode == HttpStatusCode.Ok)
            {
                using (StreamReader sr = new StreamReader((await responseGetEFAttributes.Content.ReadAsInputStreamAsync()).AsStreamForRead()))
                {
                    using (JsonTextReader jReader = new JsonTextReader(sr))
                    {
                        valueResult = JObject.ReadFrom(jReader);
                    }
                }
                IList <AttributeDTO> attributes = valueResult["Items"].ToObject <List <AttributeDTO> >();
                foreach (AttributeDTO attr in attributes)
                {
                    StringBuilder sb = new StringBuilder();

                    string userName = _sessionCtx.UserContext.Username;

                    string last      = attr.ConfigString.Split(new char[] { '\\' }).Last();
                    string pointName = attr.ConfigString.Replace(@"%Element%", userName);

                    //foreach (string s in attr.ConfigString.Split('\\'))
                    //{
                    //    if (s.Equals(last))
                    //    {
                    //        string ptName = userName + s;
                    //        sb.Append('\\').Append(ptName);
                    //    }
                    //    else
                    //    {
                    //        sb.Append('\\').Append(s);
                    //    }
                    //}

                    //pointName = sb.ToString();

                    var config = new
                    {
                        Name         = attr.Name,
                        ConfigString = pointName
                    };

                    string jsonString = JsonConvert.SerializeObject(config);
                    HttpResponseMessage responseUpdateAttribute = await _efClient.UpdateAttribute(attr.WebId, jsonString);
                }
            }
        }