Esempio n. 1
0
        public async Task <IActionResult> Webhook(AzureItem item, [FromServices] CreateSyncEvent createSyncEvent, [FromServices] UpdateLink updateLink)
        {
            var link = _queryDb.Links.SingleOrDefault(x => x.AzureId == item.Resource.WorkItemId);

            if (link == null || link.AzureRevision >= item.Resource.Rev)
            {
                return(Ok());
            }
            VssConnection connection             = new VssConnection(new Uri(_options.AzureOptions.ProjectUrl), new VssBasicCredential(string.Empty, _options.AzureOptions.AccessToken));;
            WorkItemTrackingHttpClient witClient = connection.GetClient <WorkItemTrackingHttpClient>();

            switch (item.EventType)
            {
            case "workitem.updated":
                if (item.Resource.Fields.Keys.Any(x => x == "System.State"))
                {
                    var podio = new Podio(_options.PodioOptions.ClientId, _options.PodioOptions.ClientSecret);
                    var app   = _queryDb.PodioApps.SingleOrDefault(x => x.Id == link.PodioAppId);
                    await podio.AuthenticateWithApp(app.PodioAppId, app.AppToken);

                    var mapping    = _queryDb.FieldMappings.Include(x => x.CategoryMappings).FirstOrDefault(x => x.AzureFieldName == "System.State");
                    var azureValue = ((JsonElement)item.Resource.Fields.GetOrAddValue("System.State")).GetProperty("newValue").GetString();
                    var catMapping = mapping.CategoryMappings.FirstOrDefault(x => x.AzureValue == azureValue);
                    if (catMapping == null)
                    {
                        return(Ok());
                    }
                    var podioItem = new Item();
                    podioItem.ItemId = link.PodioId;
                    var catField = podioItem.Field <CategoryItemField>(mapping.PodioFieldName);
                    if (catField == null)
                    {
                        return(Ok());
                    }
                    catField.OptionId = catMapping.PodioValueId;

                    // Update revisions
                    var podioRev = await podio.ItemService.UpdateItem(podioItem, hook : false);

                    link.PodioRevision    = podioRev.Value;
                    link.AzureRevision    = item.Resource.Rev;
                    updateLink.InputModel = link;

                    // Create sync event
                    createSyncEvent.InputModel = new SyncEvent
                    {
                        AzureRevision        = link.AzureRevision,
                        PodioRevision        = link.PodioRevision,
                        SyncDate             = DateTime.UtcNow,
                        PodioAzureItemLinkId = link.Id,
                        Initiator            = Initiator.AzureHook
                    };
                    createSyncEvent.Run();
                }
                break;
            }
            return(Ok());
        }
Esempio n. 2
0
 public static PlayerItem ToPlayerItem(AzureItem item)
 {
     return(new PlayerItem {
         BaseRecord = item.BaseRecord,
         EnchantmentRecord = item.EnchantmentRecord,
         EnchantmentSeed = item.EnchantmentSeed,
         IsHardcore = item.IsHardcore,
         MateriaCombines = item.MateriaCombines,
         MateriaRecord = item.MateriaRecord,
         Mod = item.Mod,
         ModifierRecord = item.ModifierRecord,
         PrefixRecord = item.PrefixRecord,
         RelicCompletionBonusRecord = item.RelicCompletionBonusRecord,
         RelicSeed = item.RelicSeed,
         Seed = item.Seed,
         StackCount = item.StackCount,
         SuffixRecord = item.SuffixRecord,
         TransmuteRecord = item.TransmuteRecord,
         AzureUuid = item.Id,
         AzurePartition = item.Partition
     });
 }