Exemplo n.º 1
0
        /// <summary>
        /// Creates and fill other archive part, by snapshot heurestic method.
        /// </summary>
        private void CreateAndFillArchiveParts()
        {
            //Create Root ArchivePart
            this.ListOfArchiveParts.Add(new ArchivePartRoot(this._oParentObject));

            //Fill Archive Root Part
            this.ListOfArchiveParts.Last().FillArchivePart(this._listOfTimeLevels.Select(CloneGeneric.CloneList).ToList());

            //Do we want generate Snaphosts
            if (!Constants.GenerateSnapshots)
            {
                return;
            }

            //Interate Through TimeLevelCollection
            for (var ulLoopCounter = 0; ulLoopCounter < this._listOfTimeLevels.Count; ++ulLoopCounter)
            {
                this.ListOfArchiveParts.Add(new ArchivePartRoot(this._oParentObject));
                //TODO this.ListOfArchiveParts.Add(new ArchivePartOther(this._oParentObject));

                var oTemplateList = new List <List <BaseObject> >();

                for (var oTimeLevelCounter = 0; oTimeLevelCounter <= ulLoopCounter; ++oTimeLevelCounter)
                {
                    oTemplateList.Add(CloneGeneric.CloneList(this._listOfTimeLevels[oTimeLevelCounter]));
                }

                this.ListOfArchiveParts.Last().FillArchivePart(oTemplateList);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the archive objects from data container by heurestic methods.
        /// </summary>
        /// <param name="oContainer">The connection data container.</param>
        private void GetArchiveObjects(DataContainer oContainer)
        {
            var lActualPosition    = 0;
            var listOfObjects      = new List <BaseObject>();
            var setOfObjectsHashes = new HashSet <string>();

            //Parent Object
            listOfObjects.Add(this._oParentObject);

            //Check actual object
            while ((lActualPosition < listOfObjects.Count))
            {
                //get objects by their referent
                var tempListOfObjects = oContainer.GetConnectionsByReferrers(listOfObjects.ElementAt(lActualPosition).GetObjectReferent());

                //Get objects by their references in object
                if (listOfObjects.ElementAt(lActualPosition) is TextObject)
                {
                    tempListOfObjects.AddRange(oContainer.GetConnectionByFileNamePath((TextObject)listOfObjects.ElementAt(lActualPosition)));
                }
                foreach (var oTempObject in tempListOfObjects)
                {
                    if (!setOfObjectsHashes.Contains(oTempObject.UniqueHash))
                    {
                        setOfObjectsHashes.Add(oTempObject.UniqueHash);
                        listOfObjects.Add(CloneGeneric.CloneObject(oTempObject));
                    }
                }

                lActualPosition++;
            }

            //SortObjects
            listOfObjects = listOfObjects.OrderBy(x => x.TimeStamp).ToList();

            //Set timeStopper
            var timeStopper = this._oParentObject.TimeStamp.AddMilliseconds(Constants.SnapshotsTimeSeparator);

            //Add current list
            this._listOfTimeLevels.Add(new List <BaseObject>());

            foreach (var oBaseObject in listOfObjects)
            {
                if ((oBaseObject.TimeStamp > timeStopper) && (oBaseObject is TextObject))
                {
                    this._listOfTimeLevels.Add(new List <BaseObject>());
                    timeStopper = oBaseObject.TimeStamp.AddMilliseconds(Constants.SnapshotsTimeSeparator);
                }
                this._listOfTimeLevels.Last().Add(oBaseObject);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CreateUserPass(UserPassCM userPassCM)
        {
            try
            {
                var user = _iUserService.GetUserById(userPassCM.UserUid);
                if (user == null)
                {
                    user = new User()
                    {
                        Uid = userPassCM.UserUid
                    };
                    _iUserService.AddUser(user);
                }
                var userPass = _mapper.Map <UserPass>(userPassCM);
                userPass.UserUid = user.Uid;
                var pass = _iPassService.GetPassById(userPassCM.PassId);
                if (!pass.IsSelling)
                {
                    pass.IsSelling = true;
                    _iPassService.UpdatePass(pass);
                }
                if (pass == null)
                {
                    return(NotFound("User Pass not found"));
                }
                userPass.BoughtAt     = DateTime.Now;
                userPass.WillExpireAt = DateTime.Now.AddDays(pass.ExpireDuration);

                List <UserPass> listAdd       = new List <UserPass>();
                var             childrenPrice = pass.ChildrenPrice;
                var             adultPrice    = pass.Price;

                for (int i = 0; i < userPassCM.QuantiyAdult; i++)
                {
                    UserPass passAdd = CloneGeneric.Clone <UserPass>(userPass);
                    passAdd.IsChildren      = false;
                    passAdd.PriceWhenBought = adultPrice;
                    _iUserPassService.AddUserPass(passAdd);
                    List <Ticket> listTicketType = new List <Ticket>();
                    userPassCM.TicketTypeIds.ForEach(_ =>
                    {
                        listTicketType.Add(new Ticket()
                        {
                            TicketTypeId = _,
                            UserPassId   = passAdd.Id
                        });
                    });
                    _iTicketService.AddRangeTicket(listTicketType);
                }
                for (int i = 0; i < userPassCM.QuantiyChildren; i++)
                {
                    UserPass passAdd = CloneGeneric.Clone <UserPass>(userPass);
                    passAdd.IsChildren      = true;
                    passAdd.PriceWhenBought = childrenPrice;
                    _iUserPassService.AddUserPass(passAdd);
                    List <Ticket> listTicketType = new List <Ticket>();
                    userPassCM.TicketTypeIds.ForEach(_ =>
                    {
                        listTicketType.Add(new Ticket()
                        {
                            TicketTypeId = _,
                            UserPassId   = passAdd.Id
                        });
                    });
                    _iTicketService.AddRangeTicket(listTicketType);
                }
                var result = await _iUserPassService.SaveUserPass();

                if (!result)
                {
                    return(BadRequest("Can not create user pass"));
                }
                return(StatusCode(201));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }