示例#1
0
        public HttpResponseMessage Pull(string userIdentity, string serviceIndication, int equipmentId)
        {
            try
            {
                if (string.IsNullOrEmpty(userIdentity))
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": userIdentity is required and was not supplied.");
                }

                if (string.IsNullOrEmpty(serviceIndication))
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": serviceIndication is required and was not supplied.");
                }

                if (equipmentId < 1)
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": equipmentId is required and was not supplied.");
                }

                _logger.WriteLogEntry(_tenantId.ToString(), new List <object> {
                    userIdentity, serviceIndication, equipmentId
                }, string.Format(MethodBase.GetCurrentMethod().Name + " in ProvisioningAPI was called."), LogLevelType.Info);

                var equipmentConnectionSetting = Setup(equipmentId);

                tExtendedResult extendedResult;
                tUserData       userData;
                var             resultCode = new MetaSphereService(equipmentConnectionSetting, _logger).ShPull(userIdentity, serviceIndication, out extendedResult, out userData);

                if (resultCode == 5001 && userData == null)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.NoContent));
                }

                return(this.Request.CreateResponse(HttpStatusCode.OK, userData));
            }
            catch (Exception ex)
            {
                _logger.WriteLogEntry(_tenantId.ToString(), null, string.Format(MethodBase.GetCurrentMethod().Name + " in ProvisioningAPI. Response."), LogLevelType.Error, ex);
                throw;
            }
        }
示例#2
0
        public HttpResponseMessage Update([FromBody] MetaSphereUpdate update)
        {
            try
            {
                if (update == null)
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": update is required and was not supplied.");
                }

                if (update.UserData == null)
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": update.UserData is required and was not supplied.");
                }

                if (string.IsNullOrEmpty(update.Dn))
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": update.PhoneNumber is required and was not supplied.");
                }

                _logger.WriteLogEntry(_tenantId.ToString(), null, string.Format(MethodBase.GetCurrentMethod().Name + " in ProvisioningAPI was called." + Environment.NewLine + update), LogLevelType.Info);

                var equipmentConnectionSetting = Setup(update.EquipmentId);

                if (equipmentConnectionSetting == null)
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": Unable to retrieve equipment settings on equipment id " + update.EquipmentId + ".");
                }

                if (string.IsNullOrEmpty(equipmentConnectionSetting.Url))
                {
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ": Settings.URL is not populated for equipment id" + update.EquipmentId + ".");
                }

                //Since this is generic object serialize does not now how serialize it.
                //string json = Newtonsoft.Json.JsonConvert.SerializeObject(update.UserData.ShData);
                //var type2 = Type.GetType(string.Concat("Common.MetaSwitch.t", update.UserData.ShData.ItemElementName, ", Common.Lib.Integration"), true);
                //update.UserData.ShData.RepositoryData.ServiceData.Item.Item = Newtonsoft.Json.JsonConvert.DeserializeObject(json, type);

                //Since this is generic object serialize does not now how serialize it.
                //assuming theres exactly 1 shdata.
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(update.UserData.ShData.First().ServiceData.Item.Item);
                var    type = Type.GetType(string.Concat("Common.MetaSphere.t" + update.UserData.ShData.First().ServiceData.Item.ItemElementName, ", Common.Lib.Integration"), true);
                update.UserData.ShData.First().ServiceData.Item.Item = Newtonsoft.Json.JsonConvert.DeserializeObject(json, type);

                var metaSphereService = new MetaSphereService(equipmentConnectionSetting, _logger);

                var validationErrors = metaSphereService.Validate(update.UserData);
                if (validationErrors.Any())
                {
                    var sb = new StringBuilder();
                    foreach (var validationError in validationErrors)
                    {
                        sb.Append(String.Format("{0}:{1}", validationError.Key, validationError.Value));
                        sb.AppendLine();
                    }
                    throw new Exception(MethodBase.GetCurrentMethod().Name + ":" + Environment.NewLine + sb);
                }

                tExtendedResult extendedResult;
                metaSphereService.ShUpdate(update.Dn, update.UserData, out extendedResult, true);

                _logger.WriteLogEntry(_tenantId.ToString(), null, string.Format(MethodBase.GetCurrentMethod().Name + " in ProvisioningAPI.  Response({0})", HttpStatusCode.OK), LogLevelType.Info);

                return(this.Request.CreateResponse(HttpStatusCode.OK, extendedResult));
            }
            catch (Exception ex)
            {
                _logger.WriteLogEntry(_tenantId.ToString(), null, string.Format(MethodBase.GetCurrentMethod().Name + " in ProvisioningAPI. Response."), LogLevelType.Error, ex);
                throw;
            }
        }