Beispiel #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 equipmentConnectionString = Setup(equipmentId);

                tUserData userData;
                var       resultCode = new MetaSwitchService(equipmentConnectionString, _logger).ShPull(userIdentity, serviceIndication, out userData);

                _logger.WriteLogEntry(_tenantId.ToString(), new List <object> {
                    userData
                }, string.Format(MethodBase.GetCurrentMethod().Name + " in ProvisioningAPI.  Response({0})", HttpStatusCode.OK), LogLevelType.Info);

                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." + ex), LogLevelType.Error, ex);
                throw;
            }
        }
        public void TestInitialize()
        {
            ILogger _logger = new NLogWriterService(new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["ANDP_Entities"].ConnectionString));

            _metaSwitchService = new MetaSwitchService(new EquipmentConnectionSetting(), _logger);
        }
Beispiel #3
0
        public HttpResponseMessage Update([FromBody] MetaSwitchUpdate 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(), new List<object> { update }, string.Format(MethodBase.GetCurrentMethod().Name + " in ProvisioningAPI was called."), LogLevelType.Info);

                var equipmentConnectionString = Setup(update.EquipmentId);

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

                if (string.IsNullOrEmpty(equipmentConnectionString.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.RepositoryData.ServiceData.Item.Item);
                var    type = Type.GetType(string.Concat("Common.MetaSwitch.t", update.UserData.ShData.RepositoryData.ServiceData.Item.ItemElementName, ", Common.Lib.Integration"), true);
                update.UserData.ShData.RepositoryData.ServiceData.Item.Item = Newtonsoft.Json.JsonConvert.DeserializeObject(json, type);

                var metaSwitchService = new MetaSwitchService(equipmentConnectionString, _logger);

                var validationErrors = metaSwitchService.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;
                metaSwitchService.ShUpdate(update.Dn, update.UserData, out extendedResult, true);

                _logger.WriteLogEntry(_tenantId.ToString(), new List <object> {
                    extendedResult
                }, 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;
            }
        }