Example #1
0
        public async Task <SnapshotModel> AddSnapshot(string profileClientId, SnapshotModel snapshotModel)
        {
            var snapshot = _mapper.Map <Snapshot>(snapshotModel);

            await _snapshotRepository.RemovePricedItems(profileClientId);

            snapshot.ProfileClientId = profileClientId;

            await _snapshotRepository.AddSnapshots(new List <Snapshot>() { snapshot });

            snapshot.StashTabs.Select(stashtab => {
                stashtab.SnapshotClientId        = snapshot.ClientId;
                stashtab.SnapshotProfileClientId = profileClientId;
                return(stashtab);
            }).ToList();

            await _snapshotRepository.AddStashtabs(snapshot.StashTabs.ToList());

            snapshot.StashTabs.ForEach(
                stashtab => stashtab.PricedItems.Select(pricedItem => {
                pricedItem.StashtabClientId        = stashtab.ClientId;
                pricedItem.SnapshotProfileClientId = profileClientId;
                return(stashtab);
            }).ToList());

            await _snapshotRepository.AddPricedItems(snapshot.StashTabs.SelectMany(s => s.PricedItems).ToList());

            return(_mapper.Map <SnapshotModel>(snapshot));
        }
Example #2
0
        public PartialViewResult DisplaySnapshotForm()
        {
            var snapshotModel = new SnapshotModel();

            //Return view with our model
            return(PartialView("SnapshotDashboard", snapshotModel));
        }
Example #3
0
        public async Task <SnapshotModel> AddSnapshot(string profileClientId, SnapshotModel snapshotModel)
        {
            var snapshot = _mapper.Map <Snapshot>(snapshotModel);

            // todo: readd when we want to persist stash tabs and items for historical reasons

            //await _snapshotRepository.RemovePricedItems(profileClientId);

            snapshot.ProfileClientId = profileClientId;

            await _snapshotRepository.AddSnapshots(new List <Snapshot>() { snapshot });

            // todo: readd when we want to persist stash tabs and items for historical reasons

            //snapshot.StashTabs.Select(stashtab => {
            //    stashtab.SnapshotClientId = snapshot.ClientId;
            //    stashtab.SnapshotProfileClientId = profileClientId;
            //    return stashtab;
            //}).ToList();

            //await _snapshotRepository.AddStashtabs(snapshot.StashTabs.ToList());

            //snapshot.StashTabs.ForEach(
            //    stashtab => stashtab.PricedItems.Select(pricedItem => {
            //        pricedItem.StashtabClientId = stashtab.ClientId;
            //        pricedItem.SnapshotProfileClientId = profileClientId;
            //        return stashtab;
            //    }).ToList());

            //await _snapshotRepository.AddPricedItems(snapshot.StashTabs.SelectMany(s => s.PricedItems).ToList());

            return(_mapper.Map <SnapshotModel>(snapshot));
        }
Example #4
0
 public void Update(SnapshotModel snapshot)
 {
     if (snapshot == null)
     {
         throw new ArgumentNullException("snapshot");
     }
     hub.Context.Clients.update(snapshot);
 }
        public async Task <SnapshotModel> AddSnapshot(string profileClientId, SnapshotModel snapshotModel)
        {
            var snapshot = _mapper.Map <Snapshot>(snapshotModel);

            // TODO: temporarily disabled snapshot storing

            return(_mapper.Map <SnapshotModel>(snapshot));
        }
Example #6
0
        /// <summary>
        /// Gets the top snapshot models from the records.
        /// </summary>
        /// <returns>Top snapshot models from the records.</returns>
        public async Task <IEnumerable <SnapshotModel> > GetTopSnapshots()
        {
            var topRecords = this.Records.Values.Select(records => records.First());
            var snapshots  = new List <SnapshotModel>();

            foreach (var record in topRecords)
            {
                snapshots.Add(await SnapshotModel.FromRecord(record));
            }

            return(snapshots);
        }
Example #7
0
        public Snapshot Insert(DroneSnapshotDto snapshot)
        {
            Snapshot entity = mapper.Map <DroneSnapshotDto, Snapshot>(snapshot);

            snapshotRepository.Insert(entity);

            SnapshotModel model = mapper.Map <DroneSnapshotDto, SnapshotModel>(snapshot);

            reportService.Update(model);

            return(entity);
        }
Example #8
0
        public async Task CreateSnapshotAsync(string streamId, long expectedVersion,
                                              SnapshotModel snapshot, bool deleteOlderSnapshots = false,
                                              CancellationToken cancellationToken = default
                                              )
        {
            var doc = BuildSnapShotDoc(streamId, snapshot, expectedVersion);

            await Repository.AddAsync(new[] { doc }, cancellationToken);

            if (deleteOlderSnapshots)
            {
                await DeleteSnapshotsAsync(streamId, expectedVersion, cancellationToken);
            }
        }
Example #9
0
        public async Task <SnapshotModel> AddSnapshot(SnapshotModel snapshotModel, string profileId)
        {
            snapshotModel = await _snapshotService.AddSnapshot(profileId, snapshotModel);
            await Log($"Added snapshot containing {snapshotModel.StashTabs.Sum(s => s.PricedItems.Count())} items worth {snapshotModel.StashTabs.Sum(s => s.Value)} chaos.");

            var group = await _groupService.GetGroupForConnection(ConnectionId);

            if (group != null)
            {
                await Clients.OthersInGroup(group.Name).SendAsync("OnAddSnapshot", ConnectionId, profileId, snapshotModel);
            }

            return(snapshotModel);
        }
        public async Task<SnapshotModel> AddSnapshot(SnapshotModel snapshotModel, string profileId)
        {
            snapshotModel = await _snapshotService.AddSnapshot(profileId, snapshotModel);

            var group = await _groupService.GetGroupForConnection(ConnectionId);
            if (group != null)
            {
                await Clients.OthersInGroup(group.Name).SendAsync("OnAddSnapshot", ConnectionId, profileId, snapshotModel);
            }

            LogDebug($"Added snapshot containing {snapshotModel.StashTabs.Sum(s => s.PricedItems.Count())} items worth {Math.Round(snapshotModel.StashTabs.Sum(s => s.Value), 0)} chaos in " + _timer.ElapsedMilliseconds + " ms.");
                       
            
            return snapshotModel;
        }
Example #11
0
        private static SnapshotDocument BuildSnapShotDoc(string streamId, SnapshotModel snapshot,
                                                         long version
                                                         )
        {
            var document = new SnapshotDocument
            {
                StreamId  = streamId,
                Version   = version,
                TimeStamp = DateTimeOffset.Now.ToUnixTimeSeconds(),
                DataType  = snapshot.Data.GetType().AssemblyQualifiedName,
                Data      = snapshot.Data
            };

            return(document);
        }
Example #12
0
        public async Task <SnapshotModel> AddSnapshot(string profileClientId, SnapshotModel snapshotModel)
        {
            var snapshot = _mapper.Map <Snapshot>(snapshotModel);

            await _snapshotRepository.RemovePricedItems(profileClientId);

            var profile = await _accountRepository.GetProfiles(profile => profile.ClientId == profileClientId)
                          .Include(profile => profile.Snapshots)
                          .AsNoTracking()
                          .FirstAsync();

            snapshot.ProfileId = profile.Id;

            await _snapshotRepository.AddSnapshots(new List <Snapshot>() { snapshot });

            return(_mapper.Map <SnapshotModel>(snapshot));
        }
Example #13
0
        public async Task <SnapshotModel> AddSnapshot(SnapshotModel snapshotModel, string profileId)
        {
            var delay       = Backoff.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromMilliseconds(250), retryCount: 5);
            var retryPolicy = Policy.Handle <Exception>().WaitAndRetryAsync(delay, (exception, timeSpan, retryCount, context) => {
                Log($"Add snapshot failed: {exception.Message}, retrying in {Math.Round(timeSpan.TotalMilliseconds, 0)} ms. Retry count: {retryCount} of 5.");
            });

            //snapshotModel = await retryPolicy.ExecuteAsync(() => _snapshotService.AddSnapshot(profileId, snapshotModel));

            var group = await _groupService.GetGroupForConnection(ConnectionId);

            if (group != null)
            {
                await Clients.OthersInGroup(group.Name).SendAsync("OnAddSnapshot", ConnectionId, profileId, snapshotModel);
            }

            Log($"Added snapshot containing {snapshotModel.StashTabs.Sum(s => s.PricedItems.Count())} items worth {Math.Round(snapshotModel.StashTabs.Sum(s => s.Value), 0)} chaos in " + _timer.ElapsedMilliseconds + " ms.");
            return(snapshotModel);
        }
Example #14
0
        public JsonResult CreateSnapshot(SnapshotModel model)
        {
            var resultModel = new SnapshotResultModel();
            var snap        = DateTime.Now.Ticks.ToString();

            resultModel.SnapshotCreated  = true;
            resultModel.SnapshotLocation = "/App_Data/Data/" + snap;

            using (var uow = _hive.Create())
            {
                // Create folder
                var folder = new Rebel.Framework.Persistence.Model.IO.File(snap, "")
                {
                    IsContainer = true
                };
                uow.Repositories.AddOrUpdate(folder);
                uow.Complete();
            }

            var docTypeList = new Dictionary <string, string>();
            var contentList = new Dictionary <string, string>();
            var mediaList   = new Dictionary <string, string>();

            if (!model.IncludeDocumentTypes)
            {
                //Access ContentStore and get all distinct document types
                using (var uow = _requestContext.Application.Hive.OpenReader <IContentStore>())
                {
                    var docTypes =
                        uow.Repositories.Schemas.GetDescendentRelations(FixedHiveIds.ContentRootSchema,
                                                                        FixedRelationTypes.DefaultRelationType)
                        .Where(x => !x.DestinationId.IsSystem())
                        .DistinctBy(x => x.DestinationId);

                    foreach (var docType in docTypes)
                    {
                        var schema = uow.Repositories.Schemas.Get <EntitySchema>(docType.DestinationId);
                        var result = _requestContext.Application.FrameworkContext.Serialization.ToStream(schema);
                        docTypeList.Add(docType.DestinationId.Value.ToString(), result.ResultStream.ToJsonString());
                    }
                }

                //Dump json strings as files to 'DocumentType' data folder
                if (docTypeList.Any())
                {
                    using (var uow = _hive.Create())
                    {
                        foreach (var pair in docTypeList)
                        {
                            var file = new Rebel.Framework.Persistence.Model.IO.File(
                                snap + "/DocumentTypes/" + pair.Key,
                                Encoding.UTF8.GetBytes(pair.Value));
                            uow.Repositories.AddOrUpdate(file);
                        }

                        uow.Complete();
                    }
                }
            }

            if (!model.IncludeMedia)
            {
                //Access ContentStore and get all distinct media
                using (var uow = _requestContext.Application.Hive.OpenReader <IMediaStore>())
                {
                    var medias =
                        uow.Repositories.Schemas.GetDescendentRelations(FixedHiveIds.MediaVirtualRoot,
                                                                        FixedRelationTypes.DefaultRelationType)
                        .Where(x => !x.DestinationId.IsSystem())
                        .DistinctBy(x => x.DestinationId);

                    foreach (var media in medias)
                    {
                        var schema = uow.Repositories.Get(media.DestinationId);
                        var result = _requestContext.Application.FrameworkContext.Serialization.ToStream(schema);
                        mediaList.Add(media.DestinationId.Value.ToString(), result.ResultStream.ToJsonString());
                    }
                }

                //Dump json strings as files to 'Media' data folder
                if (mediaList.Any())
                {
                    using (var uow = _hive.Create())
                    {
                        foreach (var pair in docTypeList)
                        {
                            var file = new Rebel.Framework.Persistence.Model.IO.File(
                                snap + "/Media/" + pair.Key,
                                Encoding.UTF8.GetBytes(pair.Value));
                            uow.Repositories.AddOrUpdate(file);
                        }

                        uow.Complete();
                    }
                }
            }

            if (!model.IncludeContent)
            {
                //Access ContentStore and get all distinct content - latest revision
                using (var uow = _requestContext.Application.Hive.OpenReader <IContentStore>())
                {
                    var contents =
                        uow.Repositories.Schemas.GetDescendentRelations(FixedHiveIds.ContentVirtualRoot,
                                                                        FixedRelationTypes.DefaultRelationType)
                        .Where(x => !x.DestinationId.IsSystem())
                        .DistinctBy(x => x.DestinationId);

                    foreach (var content in contents)
                    {
                        var schema = uow.Repositories.Get(content.DestinationId);
                        var result = _requestContext.Application.FrameworkContext.Serialization.ToStream(schema);
                        contentList.Add(content.DestinationId.Value.ToString(), result.ResultStream.ToJsonString());
                    }
                }

                //Dump json strings as files to 'Content' data folder
                if (contentList.Any())
                {
                    using (var uow = _hive.Create())
                    {
                        foreach (var pair in docTypeList)
                        {
                            var file = new Rebel.Framework.Persistence.Model.IO.File(
                                snap + "/Content/" + pair.Key,
                                Encoding.UTF8.GetBytes(pair.Value));
                            uow.Repositories.AddOrUpdate(file);
                        }

                        uow.Complete();
                    }
                }
            }

            //Set Success
            resultModel.NotificationTitle   = "Snapshot created";
            resultModel.NotificationMessage = "A snapshot with the selected types has been created";
            resultModel.NotificationType    = NotificationType.Success.ToString().ToLower();

            //Invalid data in model (client slide validation should catch this, in as fail safe)

            /*resultModel.SnapshotCreated = false;
             *
             * resultModel.NotificationTitle = "An error occured";
             * resultModel.NotificationMessage = "Some of the data was invalid";
             * resultModel.NotificationType = NotificationType.Error.ToString().ToLower();*/

            //Return some JSON
            return(Json(resultModel));
        }
Example #15
0
        public async Task AddSnapshot()
        {
            var account = new AccountModel()
            {
                ClientId   = TestHelper.GenerateUUID(),
                Name       = TestHelper.GetRandomString(),
                Role       = Role.Admin,
                Characters = new List <CharacterModel>(),
                Verified   = true
            };

            account = await _fixture.AccountService.AddAccount(account);

            var profile = new SnapshotProfileModel()
            {
                ClientId          = TestHelper.GenerateUUID(),
                ActiveLeagueId    = TestHelper.GenerateUUID(),
                ActiveStashTabIds = new List <string>()
                {
                },
                ActivePriceLeagueId = TestHelper.GenerateUUID(),
                Name      = TestHelper.GetRandomString(),
                Snapshots = new List <SnapshotModel>()
                {
                }
            };

            profile = await _fixture.AccountService.AddProfile(account.Name, profile);

            var snapshot = new SnapshotModel()
            {
                ClientId  = TestHelper.GenerateUUID(),
                StashTabs = new List <StashtabModel>()
            };

            snapshot = await _fixture.SnapshotService.AddSnapshot(profile.ClientId, snapshot);

            var stashtabs = new List <StashtabModel>()
            {
                new StashtabModel()
                {
                    ClientId    = TestHelper.GenerateUUID(),
                    Color       = TestHelper.GetRandomString(),
                    Index       = 0,
                    Name        = TestHelper.GetRandomString(),
                    PricedItems = new List <PricedItemModel>()
                },
                new StashtabModel()
                {
                    ClientId    = TestHelper.GenerateUUID(),
                    Color       = TestHelper.GetRandomString(),
                    Index       = 1,
                    Name        = TestHelper.GetRandomString(),
                    PricedItems = new List <PricedItemModel>()
                }
            };

            foreach (var stashtab in stashtabs)
            {
                var returnedStashtab = await _fixture.SnapshotService.AddStashtab(snapshot.ClientId, stashtab);

                Assert.NotNull(returnedStashtab.ClientId);
            }

            var retrivedAccount = await _fixture.AccountService.GetAccount(account.Name);

            Assert.NotNull(retrivedAccount.ClientId);
            Assert.NotNull(retrivedAccount.Profiles[0].ClientId);
            Assert.NotNull(retrivedAccount.Profiles[0].Snapshots[0].ClientId);
            Assert.NotNull(retrivedAccount.Profiles[0].Snapshots[0].StashTabs[0].ClientId);
            Assert.NotNull(retrivedAccount.Profiles[0].Snapshots[0].StashTabs[1].ClientId);
        }
 private static EventStreamModel BuildEventStreamModel(string streamId, EventStoreDocument rootDoc,
                                                       IEnumerable <EventModel> events = null, SnapshotModel snapshot = null
                                                       )
 {
     return(new EventStreamModel
     {
         StreamId = streamId,
         Version = rootDoc.Version,
         TimeStamp = DateTimeOffset.FromUnixTimeSeconds(rootDoc.TimeStamp),
         Events = events?.ToArray(),
         Snapshot = snapshot
     });
 }