Exemplo n.º 1
0
 public IActionResult Post([FromBody] DCATypeModel dCAType)
 {
     try
     {
         return(Ok(_dcaTypeService.SendDCATypes(dCAType)));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 2
0
        public async Task <Response> RemoveObjects(string objectId, string dcaType)
        {
            DCATypeModel dcaModel = _dCATypeRepository.GetDCAType(dcaType);

            if (dcaModel == null)
            {
                throw new Exception(string.Format("DCA type mapping is not found for type:{0}", dcaType));
            }
            string path   = String.Format(retrievePath, objectId, dcaModel.AbilityModel);
            var    result = await client.DeleteAsync(path);

            return(result);
        }
Exemplo n.º 3
0
        public async Task <Response> GetReferences(string objectID, string dcaType)
        {
            DCATypeModel dcaModel = _dCATypeRepository.GetDCAType(dcaType);

            if (dcaModel == null)
            {
                throw new Exception(string.Format("DCA type mapping is not found for type:{0}", dcaType));
            }
            string path   = String.Format(infoObjectsPath + "/references", objectID, dcaModel.AbilityModel);
            var    result = await client.GetAsync(path);

            result = result.ParseReferenceResult(result, _dCATypeRepository);
            return(result);
        }
Exemplo n.º 4
0
        public async Task <Response> FilterName(string name, string dcaType)
        {
            DCATypeModel dcaModel = _dCATypeRepository.GetDCAType(dcaType);
            var          model    = dcaModel.AbilityModel;
            var          query    = "models('" + model + "').hasName('" + name + "')";
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();

            keyValuePairs.Add("query", query);
            var result = await client.PostAsync(dslQueryPath, keyValuePairs);

            if (result.IsSuccess)
            {
                result = result.ParseQueryResult(result, _dCATypeRepository);
            }
            return(result);
        }
Exemplo n.º 5
0
        public bool UpdateDCATypes(DCATypeModel dCATypeModel)
        {
            var dcaTypes    = GetDCATypes();
            var newdcaTypes = dcaTypes;
            var objectCount = dcaTypes.Where(o => o.DCAType == dCATypeModel.DCAType).Count();

            if (objectCount > 0)
            {
                var newType = dcaTypes.Where(o => o.DCAType == dCATypeModel.DCAType).FirstOrDefault();
                dcaTypes.Remove(newType);
                newType.AbilityModel = dCATypeModel.AbilityModel;
                newType.AbilityType  = dCATypeModel.AbilityType;
                newdcaTypes.Add(newType);

                File.Delete(fileName);
                CreateFile(newdcaTypes);
            }
            return(true);
        }
Exemplo n.º 6
0
        public async Task <Response> UpdateObjects(string objectId, string dcaType, dynamic model)
        {
            try
            {
                //Convert into dictionary type KeyValue Pair
                Dictionary <string, string> dcakeyValuePairs =
                    ((IEnumerable <KeyValuePair <string, JToken> >)model)
                    .ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToString());
                //Fetch the DCA Type and get its corresponding Ability model and type
                DCATypeModel dcaModel = _dCATypeRepository.GetDCAType(dcaType);

                //Delete dcaType and add model and device type
                dcakeyValuePairs.Remove("dcaType");
                dcakeyValuePairs.Add("model", dcaModel.AbilityModel);
                dcakeyValuePairs.Add("type", dcaModel.AbilityType);
                var dcaDeviceCollection = new Dictionary <string, dynamic>();
                foreach (var keyvaluepair in dcakeyValuePairs)
                {
                    var objvalue = dcakeyValuePairs[keyvaluepair.Key];
                    if (objvalue.IsValidObject())
                    {
                        dcaDeviceCollection.Add(keyvaluepair.Key, JToken.Parse(objvalue));
                    }
                    else
                    {
                        dcaDeviceCollection.Add(keyvaluepair.Key, objvalue);
                    }
                }
                string path   = String.Format(retrievePath, objectId, model);
                var    result = await client.PutAsync(path, dcaDeviceCollection);

                result = result.ParseResult(result, _dCATypeRepository);
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 7
0
        public async Task <Response> GetChildObjects(string objectID, string dcaType)
        {
            DCATypeModel dcaModel = _dCATypeRepository.GetDCAType(dcaType);

            if (dcaModel == null)
            {
                throw new Exception(string.Format("DCA type mapping is not found for type:{0}", dcaType));
            }
            string path   = String.Format(infoObjectsPath + "/references", objectID, dcaModel.AbilityModel);
            var    result = await client.GetAsync(path);

            if (result.IsSuccess == false)
            {
                return(result);
            }
            var    referencebjects      = JObject.Parse(result.ResponseMessage.ToString());
            JArray objs                 = (JArray)referencebjects["data"];
            IEnumerable <JToken> tokens = objs.AsEnumerable <JToken>();
            var toResult                = tokens.Select(o => o.SelectToken("to")).ToList();

            result.ResponseMessage = toResult;
            result = result.ParseChildReferenceResult(result, _dCATypeRepository);
            return(result);
        }
Exemplo n.º 8
0
 public bool CreateDCATypes(DCATypeModel dCAType)
 {
     if (!File.Exists(fileName))
     {
         List <DCATypeModel> dcaTypes = new List <DCATypeModel>();
         dcaTypes.Add(dCAType);
         CreateFile(dcaTypes);
     }
     else
     {
         var dcaTypes = GetDCATypes();
         if (dcaTypes.Any(o => o.DCAType == dCAType.DCAType))
         {
             return(false);
         }
         else
         {
             File.Delete(fileName);
             dcaTypes.Add(dCAType);
             CreateFile(dcaTypes);
         }
     }
     return(true);
 }
Exemplo n.º 9
0
        public async Task <Response> SendObjects(dynamic model, bool serialized, bool isValidateNameReq = false)
        {
            Dictionary <string, string> dcakeyValuePairs = new Dictionary <string, string>(); Response result = null;

            try
            {
                if (serialized)
                {
                    //Convert into dictionary type KeyValue Pair
                    dcakeyValuePairs =
                        ((IEnumerable <KeyValuePair <string, JToken> >)model)
                        .ToDictionary(kvp => kvp.Key, kvp => kvp.Value.ToString());


                    //Fetch the DCA Type and get its corresponding Ability model and type
                    dynamic      dcaType  = dcakeyValuePairs["dcaType"];
                    DCATypeModel dcaModel = _dCATypeRepository.GetDCAType(dcaType);
                    if (dcaModel == null)
                    {
                        throw new Exception(string.Format("DCA type mapping is not found for type:{0}", dcaType));
                    }
                    //Delete dcaType and add model and device type
                    dcakeyValuePairs.Remove("dcaType");
                    dcakeyValuePairs.Add("model", dcaModel.AbilityModel);
                    dcakeyValuePairs.Add("type", dcaModel.AbilityType);
                    if (isValidateNameReq)
                    {
                        var searchresult = await FilterName(dcakeyValuePairs["name"], dcaModel.DCAType);

                        if (searchresult.IsSuccess == true)
                        {
                            var searchresponse = searchresult.ResponseMessage as List <dynamic>;

                            if (searchresponse.Count() > 0)
                            {
                                searchresult.ResponseMessage = string.Format("DCA Object name: {0} already exists in dcaType:{1}", dcakeyValuePairs["name"], dcaType);
                                searchresult.IsSuccess       = false;
                                searchresult.StatusCode      = "Conflict";
                                return(searchresult);
                            }
                        }
                    }

                    var dcaDeviceCollection = new Dictionary <string, dynamic>();
                    foreach (var keyvaluepair in dcakeyValuePairs)
                    {
                        var objvalue = dcakeyValuePairs[keyvaluepair.Key];
                        if (objvalue.IsValidObject())
                        {
                            dcaDeviceCollection.Add(keyvaluepair.Key, JToken.Parse(objvalue));
                        }
                        else
                        {
                            dcaDeviceCollection.Add(keyvaluepair.Key, objvalue);
                        }


                        result = await client.PostAsync(editPath, dcaDeviceCollection);
                    }
                }
                else
                {
                    result = await client.PostAsync(editPath, model);
                }
                result = result.ParseResult(result, _dCATypeRepository);
                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 10
0
        public static Response ParseReferenceResult(this Response response, dynamic result, IDCATypeRepository dCATypeRepository)
        {
            string oldmodel = string.Empty; string oldtype = string.Empty; DCATypeModel dCATypeModel = null;
            var    responses = new List <ResponseData>();

            var parsedResponse = (Response)result;

            if (parsedResponse.IsSuccess)
            {
                var responseMsg   = response.ResponseMessage;
                var responseToken = JToken.Parse(responseMsg.ToString());
                var responsedata  = responseToken.SelectToken("data");
                foreach (var token in responsedata)
                {
                    var newmodel = token.SelectToken("from.model").ToString();
                    var objectId = token.SelectToken("from.objectId").ToString();
                    var newtype  = token.SelectToken("from.type").ToString();
                    if (oldmodel != newmodel && oldtype != newtype)
                    {
                        dCATypeModel = dCATypeRepository.GetDCATypeofModelType(newmodel);
                    }
                    var responsemodel = new ResponseData()
                    {
                        dcaType = dCATypeModel.DCAType, ObjectId = objectId
                    };
                    responses.Add(responsemodel);
                    oldmodel = newmodel;
                    oldtype  = newtype;
                }
            }
            response.ResponseMessage = responses;
            return(response);
        }
Exemplo n.º 11
0
 public bool UpdateDCATypes(DCATypeModel model)
 {
     return(_dcaTypeRepository.UpdateDCATypes(model));
 }
Exemplo n.º 12
0
 public bool SendDCATypes(DCATypeModel model)
 {
     return(_dcaTypeRepository.CreateDCATypes(model));
 }
Exemplo n.º 13
0
 public System.Threading.Tasks.Task <dynamic> RemoveDCATypes(DCATypeModel model)
 {
     return(_dcaTypeRepository.RemoveDCATypes(model));
 }
Exemplo n.º 14
0
 public Task <dynamic> RemoveDCATypes(DCATypeModel model)
 {
     throw new NotImplementedException();
 }