private async Task <SubnavLink> AddUpdateSubNavLink(IApiContext apiContext, SubnavLink subnavLink)
        {
            var     entityResource = new EntityResource(apiContext);
            JObject jObject        = null;

            if (subnavLink.Path == null || !subnavLink.Path.Any())
            {
                return(null);
            }

            var existing = await GetExistingLink(apiContext, subnavLink);

            jObject = FromObject(subnavLink);

            if (existing == null)
            {
                jObject = await entityResource.InsertEntityAsync(jObject, SubnavLinkEntityName);
            }
            else
            {
                jObject = await entityResource.UpdateEntityAsync(jObject, SubnavLinkEntityName, existing.Id);
            }

            return(jObject.ToObject <SubnavLink>());
        }
Ejemplo n.º 2
0
        public async Task DeleteEvent(IApiContext apiContext, string id)
        {
            if (id == null)
            {
                return;
            }
            var correlationId = String.Empty;
            var errorCode     = String.Empty;

            try
            {
                var resource = new EntityResource(apiContext);
                await resource.DeleteEntityAsync(_listFullName, id);

                //var entityHandler = new EntityHandler(_appSetting);
                //await entityHandler.DeleteEntityAsync(apiContext, id, EntityListConstants.MozuEventQueueName);
            }
            catch (AggregateException ex)
            {
                ex.Handle(e =>
                {
                    var apiEx = e as ApiException;
                    if (apiEx != null)
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(apiEx);
                        correlationId      = apiEx.CorrelationId;
                        errorCode          = apiEx.ErrorCode;
                    }
                    else
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(ex);
                    }
                    return(true);
                });
            }
            catch (ApiException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
                correlationId      = ex.CorrelationId;
                errorCode          = ex.ErrorCode;
            }
            catch (Exception ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            if (_capturedException == null)
            {
                return;
            }
            if (_capturedException.SourceException.InnerException != null)
            {
                var message = String.Format("{0}. CorrId: {1}, ErrorCode: {2}",
                                            _capturedException.SourceException.Message, correlationId,
                                            errorCode);
                if (_capturedException.SourceException.InnerException != null)
                {
                    _logger.Error(message, _capturedException.SourceException);
                }
            }
        }
Ejemplo n.º 3
0
        private void Compile(EntityResource res, Trigger trigger)
        {
            var ctrigger = new CTrigger();

            ctrigger.ID = Table["Entity.Trigger", trigger.Name];

            ctrigger.VelocityXLowBound = trigger.VelocityXLowBound;
            ctrigger.VelocityYLowBound = trigger.VelocityYLowBound;

            ctrigger.VelocityXHighBound = trigger.VelocityXHighBound;
            ctrigger.VelocityYHighBound = trigger.VelocityYHighBound;

            ctrigger.AccelerationXLowBound = trigger.AccelerationXLowBound;
            ctrigger.AccelerationYLowBound = trigger.AccelerationYLowBound;

            ctrigger.AccelerationXHighBound = trigger.AccelerationXHighBound;
            ctrigger.AccelerationYHighBound = trigger.AccelerationYHighBound;

            ctrigger.OnGround    = (int)trigger.OnGround;
            ctrigger.OnRoof      = (int)trigger.OnRoof;
            ctrigger.OnLeftWall  = (int)trigger.OnLeftWall;
            ctrigger.OnRightWall = (int)trigger.OnRightWall;
            ctrigger.FaceLeft    = (int)trigger.FaceLeft;
            ctrigger.FaceRight   = (int)trigger.FaceRight;

            ctrigger.AnimationID = res.Animations.FindIndex((Animation a) => a.Name == trigger.Animation);

            Writer.WriteStruct(ctrigger);
        }
Ejemplo n.º 4
0
        public async Task <T> GetEntityAsync <T>(IApiContext apiContext, object id, string listName)
        {
            var entityResource = new EntityResource(apiContext);
            var listFQN        = ValidateListName(listName);

            try
            {
                var jobject = await entityResource.GetEntityAsync(listFQN, id.ToString());

                if (jobject == null)
                {
                    return(default(T));
                }
                return(jobject.ToObject <T>(SerializerSettings));
            }
            catch (AggregateException ae)
            {
                if (ae.InnerException.GetType() == typeof(ApiException))
                {
                    throw;
                }
                var aex = (ApiException)ae.InnerException;
                _logger.Error(aex.Message, aex);
                throw aex;
            }

            return(default(T));
        }
        public async Task Delete(int tenantId, SubnavLink subNavlink = null)
        {
            var apiContext = new ApiContext(tenantId);
            var entityContainerResource = new EntityContainerResource(apiContext);
            var collection = await entityContainerResource.GetEntityContainersAsync(SubnavLinkEntityName, 200);

            var entityResource = new EntityResource(apiContext);

            if (subNavlink == null)
            {
                var appId = await GetAppId(apiContext);

                foreach (
                    var item in
                    collection.Items.Where(subnavLink => subnavLink.Item.ToObject <SubnavLink>().AppId.Equals(appId))
                    )
                {
                    await entityResource.DeleteEntityAsync(SubnavLinkEntityName, item.Id);
                }
            }
            else
            {
                if (subNavlink.ParentId == null || subNavlink.Path == null || !subNavlink.Path.Any())
                {
                    throw new Exception("ParentId and Path is required to delete a link");
                }
                var existing = collection.Items.FirstOrDefault(x => subNavlink.Path.SequenceEqual(x.Item.ToObject <SubnavLink>().Path) &&
                                                               (subNavlink.ParentId == x.Item.ToObject <SubnavLink>().ParentId || subNavlink.Location == x.Item.ToObject <SubnavLink>().Location));

                if (existing != null)
                {
                    await entityResource.DeleteEntityAsync(SubnavLinkEntityName, existing.Id);
                }
            }
        }
Ejemplo n.º 6
0
        protected async override Task <bool> GetDataAsync()
        {
            var entityResource = new EntityResource(Context);

            if (String.IsNullOrEmpty(ListName) || (!ListName.Contains("@") && String.IsNullOrEmpty(Namespace)))
            {
                throw new Exception("ListName or Namespace is missing");
            }
            var fqn = ListName;

            if (!ListName.Contains("@"))
            {
                fqn = ListName + "@" + Namespace;
            }

            var entities = await entityResource.GetEntitiesAsync(fqn, PageSize, StartIndex, Filter, SortBy, ResponseFields);

            _results = new EntityCollection <T>
            {
                PageCount  = entities.PageCount,
                PageSize   = entities.PageSize,
                StartIndex = entities.StartIndex,
                TotalCount = entities.TotalCount
            };

            _results.Items = entities.Items.ConvertAll(JObjectConverter <T>);

            TotalCount = _results.TotalCount;
            PageCount  = _results.PageCount;
            PageSize   = _results.PageSize;
            return(_results.Items != null && _results.Items.Count > 0);
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <AppLog> > List(int tenantId, int?pageSize, int?startIndex, string sortBy)
        {
            var apiContext     = new ApiContext(tenantId);
            var entityResource = new EntityResource(apiContext);
            var entities       = await entityResource.GetEntitiesAsync(_listFullName, pageSize, startIndex, sortBy : sortBy);

            return(entities.Items.ConvertAll(ToAppLogConverter));
        }
Ejemplo n.º 8
0
 /// <summary>Constructs a new service.</summary>
 /// <param name="initializer">The service initializer.</param>
 public DomainsRDAPService(Google.Apis.Services.BaseClientService.Initializer initializer) : base(initializer)
 {
     Autnum     = new AutnumResource(this);
     Domain     = new DomainResource(this);
     Entity     = new EntityResource(this);
     Ip         = new IpResource(this);
     Nameserver = new NameserverResource(this);
     V1         = new V1Resource(this);
 }
Ejemplo n.º 9
0
        public async Task <T> UpdateEntityAsync <T>(IApiContext apiContext, object id, String listName, T obj)
        {
            var entityResource = new EntityResource(apiContext);
            var jobject        = JObject.FromObject(obj, SerializerSettings);
            var listFQN        = ValidateListName(listName);

            jobject = await entityResource.UpdateEntityAsync(jobject, listFQN, id.ToString());

            return(jobject.ToObject <T>());
        }
Ejemplo n.º 10
0
        private void Compile(EntityResource res, Holder holder)
        {
            var cholder = new CHolder();

            cholder.ID          = Table["Entity.Holder", holder.Name];
            cholder.Slot        = holder.Slot;
            cholder.HolderPoint = holder.HolderPoint;
            cholder.AnimationID = res.Animations.FindIndex((Animation a) => a.Name == holder.Animation);

            Writer.WriteStruct(cholder);
        }
Ejemplo n.º 11
0
 private object MapSearchResult(EntityResource resource)
 {
     if (resource.Artist != null)
     {
         return(MapSearchResult(resource.Artist));
     }
     else
     {
         return(MapSearchResult(resource.Album));
     }
 }
Ejemplo n.º 12
0
 public bool LoadEntity(EntityResource resource, string name)
 {
     try
     {
         MakeCurrent();
         Entities.Add(name, new Entity(resource));
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 13
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        EntityResource.Delete(
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathIdentity: "PathIdentity"
            );
    }
Ejemplo n.º 14
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        EntityResource.Delete(
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathIdentity: "identity"
            );
    }
Ejemplo n.º 15
0
        public async Task AddUpdateExtensionLinkAsync(int tenantId, SubnavLink subnavLink, LinkType?type = null)
        {
            var apiContext = new ApiContext(tenantId);

            subnavLink.AppId = await GetAppId(apiContext);

            var location = subnavLink.ParentId.ToString();

            if (type.HasValue)
            {
                if (_newAdmingMappings.ContainsKey(location) && type == LinkType.Menu)
                {
                    location = _newAdmingMappings[location];
                }
                subnavLink.Location = string.Format("{0}{1}", location.ToLower(), type.ToString().ToLower());
                if (!subnavLink.DisplayMode.HasValue)
                {
                    subnavLink.DisplayMode = DisplayMode.Modal;
                }
            }


            var entityResource     = new EntityResource(apiContext);
            var tenantSettingsJobj = await entityResource.GetEntityAsync("tenantadminsettings@mozu", "global");

            TenantAdminSettings tenantSettings = null;

            if (tenantSettingsJobj != null)
            {
                tenantSettings = tenantSettingsJobj.ToObject <TenantAdminSettings>();
            }

            if (tenantSettings != null && tenantSettings.EnableBetaAdmin)
            {
                //validate combo
                if (type.HasValue && type.Value == LinkType.Menu && !_validBurgerMenus.Contains(location))
                {
                    throw new Exception("Invalid Parent option for Menu type. Valid options are " + _validBurgerMenus.Aggregate((x, y) => x + "," + y));
                }
                if (type.HasValue && (type.Value == LinkType.Edit || type.Value == LinkType.Index) && !_validGridEditItems.Contains(location))
                {
                    throw new Exception("Invalid Parent option for " + type.ToString() + " type. Valid options are " + _validGridEditItems.Aggregate((x, y) => x + "," + y));
                }

                subnavLink.ParentId = null;
            }

            await AddUpdateSubNavLink(apiContext, subnavLink);
        }
Ejemplo n.º 16
0
        public override void Compile(string path)
        {
            var res = new EntityResource(Path.Combine(RootDirectory, path));

            var centity = new CEntity
            {
                HitboxW             = res.HitboxW,
                HitboxH             = res.HitboxH,
                MaxHealth           = res.MaxHealth,
                MaxEnergy           = res.MaxEnergy,
                Mass                = res.Mass,
                GravityAcceleration = res.GravityAcceleration,
                JumpVelocity        = res.JumpVelocity,
                DragX               = res.DragX,
                DragY               = res.DragY,
                SqrDragX            = res.SqrDragX,
                SqrDragY            = res.SqrDragY,
                MoveForceX          = res.MoveForceX,
                MoveForceY          = res.MoveForceY
            };

            Writer.WriteStruct(centity);

            Compile(res.Ragdoll);

            Writer.Write(res.Animations.Count);
            foreach (var animation in res.Animations)
            {
                Compile(animation);
            }

            Writer.Write(res.Outfits.Count);
            foreach (var outfit in res.Outfits)
            {
                Compile(outfit, path);
            }

            Writer.Write(res.Triggers.Count);
            foreach (var trigger in res.Triggers)
            {
                Compile(res, trigger);
            }

            Writer.Write(res.Holders.Count);
            foreach (var holder in res.Holders)
            {
                Compile(res, holder);
            }
        }
        public void TestDeleteResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.NoContent,
                         "null"
                         ));

            var response = EntityResource.Delete("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "identity", client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestCreateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.Created,
                         "{\"sid\": \"YEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"identity\": \"ff483d1ff591898a9942916050d2ca3f\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"date_created\": \"2015-07-30T20:00:00Z\",\"date_updated\": \"2015-07-30T20:00:00Z\",\"url\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/ff483d1ff591898a9942916050d2ca3f\",\"links\": {\"factors\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/ff483d1ff591898a9942916050d2ca3f/Factors\"}}"
                         ));

            var response = EntityResource.Create("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "identity", client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestReadEmptyResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"entities\": [],\"meta\": {\"page\": 0,\"page_size\": 50,\"first_page_url\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities?PageSize=50&Page=0\",\"previous_page_url\": null,\"url\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities?PageSize=50&Page=0\",\"next_page_url\": null,\"key\": \"entities\"}}"
                         ));

            var response = EntityResource.Read("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);

            Assert.NotNull(response);
        }
        public void TestReadFullResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"entities\": [{\"sid\": \"YEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"identity\": \"ff483d1ff591898a9942916050d2ca3f\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"date_created\": \"2015-07-30T20:00:00Z\",\"date_updated\": \"2015-07-30T20:00:00Z\",\"url\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/ff483d1ff591898a9942916050d2ca3f\",\"links\": {\"factors\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/ff483d1ff591898a9942916050d2ca3f/Factors\"}}],\"meta\": {\"page\": 0,\"page_size\": 50,\"first_page_url\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities?PageSize=50&Page=0\",\"previous_page_url\": null,\"url\": \"https://authy.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities?PageSize=50&Page=0\",\"next_page_url\": null,\"key\": \"entities\"}}"
                         ));

            var response = EntityResource.Read("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);

            Assert.NotNull(response);
        }
Ejemplo n.º 21
0
        public void TestFetchResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.OK,
                         "{\"sid\": \"YEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"identity\": \"ff483d1ff591898a9942916050d2ca3f\",\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"service_sid\": \"VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"date_created\": \"2015-07-30T20:00:00Z\",\"date_updated\": \"2015-07-30T20:00:00Z\",\"url\": \"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/ff483d1ff591898a9942916050d2ca3f\",\"links\": {\"factors\": \"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/ff483d1ff591898a9942916050d2ca3f/Factors\",\"challenges\": \"https://verify.twilio.com/v2/Services/VAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Entities/ff483d1ff591898a9942916050d2ca3f/Challenges\"}}"
                         ));

            var response = EntityResource.Fetch("VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "identity", twilioSandboxMode: Serialize("twilio_sandbox_mode"), client: twilioRestClient);

            Assert.NotNull(response);
        }
Ejemplo n.º 22
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var entity = EntityResource.Fetch(
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathIdentity: "PathIdentity"
            );

        Console.WriteLine(entity.Sid);
    }
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var entities = EntityResource.Read(
            pathServiceSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );

        foreach (var record in entities)
        {
            Console.WriteLine(record.Sid);
        }
    }
Ejemplo n.º 24
0
        public async Task <EntityCollection <T> > GetEntitiesAsync <T>(IApiContext apiContext, string listName, int?pageSize, int?startIndex, string filter, string sortBy, string responseFileds)
        {
            var entityResource = new EntityResource(apiContext);
            var listFQN        = ValidateListName(listName);
            var entities       = await entityResource.GetEntitiesAsync(listFQN, pageSize, startIndex, filter, sortBy, responseFileds);

            var entityCollection = new EntityCollection <T>
            {
                PageCount  = entities.PageCount,
                PageSize   = entities.PageSize,
                StartIndex = entities.StartIndex,
                TotalCount = entities.TotalCount
            };

            entityCollection.Items = entities.Items.ConvertAll(JObjectConverter <T>);

            return(entityCollection);
        }
Ejemplo n.º 25
0
        public void TestReadRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Get,
                Twilio.Rest.Domain.Verify,
                "/v2/Services/VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Entities",
                ""
                );

            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                EntityResource.Read("VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
        public void TestDeleteRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Delete,
                Twilio.Rest.Domain.Authy,
                "/v1/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Entities/identity",
                ""
                );

            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                EntityResource.Delete("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "identity", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
Ejemplo n.º 27
0
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Preview,
                "/Authy/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Entities",
                ""
                );

            request.AddPostParam("Identity", Serialize("Identity"));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                EntityResource.Create("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "Identity", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
Ejemplo n.º 28
0
        public void TestDeleteRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Delete,
                Twilio.Rest.Domain.Verify,
                "/v2/Services/VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Entities/identity",
                ""
                );

            request.AddHeaderParam("Twilio-Sandbox-Mode", Serialize("twilio_sandbox_mode"));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                EntityResource.Delete("VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "identity", twilioSandboxMode: Serialize("twilio_sandbox_mode"), client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
Ejemplo n.º 29
0
        public void AddEvent()
        {
            var eventItem = new EventItem
            {
                EntityId = "567",
                EventId = "def",
                Id = "PK123",
                Topic = "order.opened",
                QueuedDateTime = DateTime.Now,
                Status = EventStatus.Pending.ToString()
            };


            var listFullName = $"EventQueue@{_appSetting.Namespace}";

            try
            {
                var entityResource = new EntityResource(_apiContext);

                var entity = entityResource.GetEntityAsync(listFullName, eventItem.Id).Result;
                if (entity == null)
                {

                    var result = entityResource.InsertEntityAsync(JObject.FromObject(eventItem), listFullName).Result;
                }
            }
            catch (ApiException ex)
            {
                if (ex.ErrorCode.Trim() == "ITEM_ALREADY_EXISTS")
                {
                    throw new Exception("Item exists");
                }
                throw;
            }

        }
Ejemplo n.º 30
0
        public async Task UpdateEvent(int tenantId, AubEvent aubEvent)
        {
            try
            {
                _apiContext = new ApiContext(tenantId);

                var entityResource = new EntityResource(_apiContext);

                var entity = await entityResource.GetEntityAsync(_listFullName, aubEvent.Id);

                if (entity != null)
                {
                    await entityResource.UpdateEntityAsync(JObject.FromObject(aubEvent), _listFullName, aubEvent.Id);
                }
                else
                {
                    await AddEvent(tenantId, aubEvent);
                }
            }
            catch (ApiException ex)
            {
                _logger.Error(ex.Message, ex);
            }
        }
Ejemplo n.º 31
0
 public EntityAddressDetails(EntityResource entity)
     : this()
 {
     EntityResource = entity;
 }