Exemplo n.º 1
0
        /// <summary>
        /// Delete an item from the user's inventory
        ///
        /// If the inventory service has not yet delievered the inventory
        /// for this user then the request will be queued.
        /// </summary>
        /// <param name="item"></param>
        /// <returns>
        /// true on a successful delete or a if the request is queued.
        /// Returns false on an immediate failure
        /// </returns>
        public bool DeleteItem(InventoryItemBase item)
        {
            IInventoryProviderSelector selector = ProviderRegistry.Instance.Get <IInventoryProviderSelector>();
            IInventoryStorage          provider = selector.GetProvider(item.Owner);

            provider.PurgeItem(item);

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find an appropriate folder for the given asset type
        /// </summary>
        /// <param name="type"></param>
        /// <returns>null if no appropriate folder exists</returns>
        public InventoryFolderBase FindFolderForType(int type)
        {
            InventoryFolderBase bestFolderForType;

            lock (_folderTypeCache)
            {
                _folderTypeCache.TryGetValue(type, out bestFolderForType);

                if (bestFolderForType != null)
                {
                    return(bestFolderForType);
                }
            }

            IInventoryProviderSelector inventorySelect = ProviderRegistry.Instance.Get <IInventoryProviderSelector>();
            IInventoryStorage          provider        = inventorySelect.GetProvider(m_userProfile.ID);

            try
            {
                bestFolderForType = provider.FindFolderForType(m_userProfile.ID, (AssetType)type);
            }
            catch
            { }

            if (bestFolderForType == null)
            {
                //next best folder will be the user root folder, it has to exist
                try
                {
                    bestFolderForType = provider.FindFolderForType(m_userProfile.ID, (AssetType)FolderType.Root);
                }
                catch
                { }

                if (bestFolderForType == null)
                {
                    throw new InventoryStorageException(
                              String.Format("Can not retrieve a destination folder for types, user {0} has no root folder", m_userProfile.ID));
                }
            }

            lock (_folderTypeCache)
            {
                if (_folderTypeCache.ContainsKey(type))
                {
                    _folderTypeCache[type] = bestFolderForType;
                }
                else
                {
                    _folderTypeCache.Add(type, bestFolderForType);
                }
            }

            return(bestFolderForType);
        }
Exemplo n.º 3
0
 public InventoryActor(IInventoryStorage inventoryStorage, IPerformanceService performanceService, IBackUpService backUpService, bool withCache = true)
 {
     if (backUpService == null)
     {
         throw new ArgumentNullException(nameof(backUpService));
     }
     BackUpService      = backUpService;
     PerformanceService = performanceService;
     PerformanceService.Init();
     Logger.Debug("Starting Inventory Actor ....");
     InventoryStorage = inventoryStorage;
     _withCache       = withCache;
     Become(Initializing);
 }
        public GroupDisplayData GroupDisplayDataFromSOG(UUID userId, GroupLoader.LoaderParams parms, SceneObjectGroup sog,
                                                        IInventoryStorage inv, string userName, InventoryItemBase item)
        {
            if (((parms.Checks & LoaderChecks.PrimLimit) != 0) && sog.GetParts().Count > parms.PrimLimit)
            {
                throw new Exceptions.PrimExporterPermissionException("Object contains too many prims");
            }

            HashSet <UUID> fullPermTextures = CollectFullPermTexturesIfNecessary(ref userId, parms, inv);

            PrimDisplayData        rootPrim  = null;
            List <PrimDisplayData> groupData = new List <PrimDisplayData>();

            foreach (SceneObjectPart part in sog.GetParts())
            {
                if (((parms.Checks & LoaderChecks.UserMustBeCreator) != 0) && part.CreatorID != userId)
                {
                    throw new Exceptions.PrimExporterPermissionException("You are not the creator of all parts");
                }

                PrimDisplayData pdd = this.ExtractPrimMesh(part, parms, fullPermTextures);
                if (pdd == null)
                {
                    throw new NullReferenceException("Prim mesh could not be loaded");
                }

                groupData.Add(pdd);
                if (pdd.IsRootPrim)
                {
                    rootPrim = pdd;
                }
            }

            //assign parent to all prims
            foreach (var part in groupData)
            {
                if (!part.IsRootPrim)
                {
                    part.Parent = rootPrim;
                }
            }

            //sort prims by link number
            var sortedPrims = groupData.OrderBy(g => g.LinkNum);

            return(new GroupDisplayData {
                Prims = sortedPrims, RootPrim = rootPrim, CreatorName = userName,
                ObjectName = sog.Name
            });
        }
Exemplo n.º 5
0
        private IActorRef GetActorRef(IInventoryStorage inventoryStorage, string productId, IPerformanceService performanceService)
        {
            if (_products.ContainsKey(productId))
            {
                return(_products[productId]);
            }

            Logger.Debug("Creating inventory actor " + productId + " since it does not yet exist ...");
            var productActorRef = Context.ActorOf(
                Props.Create(() =>
                             new ProductInventoryActor(inventoryStorage, NotificationActorRef, productId, _withCache, performanceService))
                , productId);

            _products.Add(productId, productActorRef);
            return(_products[productId]);
        }
Exemplo n.º 6
0
        // Searches the parentage tree for an ancestor folder with a matching type (e.g. Trash)
        public InventoryFolderBase FindTopLevelFolderFor(UUID folderID)
        {
            IInventoryProviderSelector inventorySelect = ProviderRegistry.Instance.Get <IInventoryProviderSelector>();
            IInventoryStorage          provider        = inventorySelect.GetProvider(m_userProfile.ID);
            InventoryFolderBase        folder;

            try
            {
                folder = provider.FindTopLevelFolderFor(m_userProfile.ID, folderID);
            }
            catch
            {
                folder = null;
            }

            return(folder);
        }
Exemplo n.º 7
0
        private void CollectCreatedAssetIdsFromUserInventory(UUID creatorId, C5.HashSet <UUID> retAssets)
        {
            IInventoryProviderSelector selector = ProviderRegistry.Instance.Get <IInventoryProviderSelector>();
            IInventoryStorage          provider = selector.GetProvider(creatorId);

            List <InventoryFolderBase> skel = provider.GetInventorySkeleton(creatorId);

            foreach (InventoryFolderBase folder in skel)
            {
                InventoryFolderBase fullFolder = provider.GetFolder(folder.ID);
                foreach (InventoryItemBase item in fullFolder.Items)
                {
                    if (m_allowedCreatorIds.Contains(item.CreatorIdAsUuid))
                    {
                        retAssets.Add(item.AssetID);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public ProductInventoryActor(IInventoryStorage inventoryStorage, IActorRef InventoryQueryActorRef, string id, bool withCache, IPerformanceService performanceService)
        {
            PerformanceService = performanceService;
            _id                  = id;
            _withCache           = withCache;
            InventoryStorage     = inventoryStorage;
            RealTimeInventory    = RealTimeInventory.InitializeFromStorage(InventoryStorage, id);
            NotificationActorRef = InventoryQueryActorRef;
            ReceiveAsync <GetInventoryMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }

                if (_withCache == false)
                {
                    var result        = await RealTimeInventory.ReadInventoryFromStorageAsync(InventoryStorage, message.ProductId);
                    RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
                }
                else
                {
                    RealTimeInventory = RealTimeInventory.ToSuccessOperationResult().ProcessAndSendResult(message, (rti) => new GetInventoryCompletedMessage(rti, true), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
                }
            });

            ReceiveAsync <ReserveMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.ReserveAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <UpdateQuantityMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.UpdateQuantityAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <UpdateAndHoldQuantityMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var updateandHoldResultesult = await RealTimeInventory.UpdateQuantityAndHoldAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory            = updateandHoldResultesult.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <PlaceHoldMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.PlaceHoldAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <PurchaseMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.PurchaseAsync(InventoryStorage, message.ProductId, message.Update);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <PurchaseFromHoldsMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var result        = await RealTimeInventory.PurchaseFromHoldsAsync(InventoryStorage, message.ProductId, message.Update).ConfigureAwait(false);
                RealTimeInventory = result.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

            ReceiveAsync <FlushStreamsMessage>(async message =>
            {
                var result = await RealTimeInventory.InventoryStorageFlushAsync(InventoryStorage, _id);
                Sender.Tell(result.Data);
            });

            ReceiveAsync <ResetInventoryQuantityReserveAndHoldMessage>(async message =>
            {
                if (!CanProcessMessage(message.ProductId, message))
                {
                    return;
                }
                var updateandHoldResultesult = await RealTimeInventory.ResetInventoryQuantityReserveAndHoldAsync(InventoryStorage, message.ProductId, message.Update, message.Reservations, message.Holds);
                RealTimeInventory            = updateandHoldResultesult.ProcessAndSendResult(message, CompletedMessageFactory.GetResponseCompletedMessage(message), Logger, RealTimeInventory, Sender, NotificationActorRef, PerformanceService).RealTimeInventory;
            });

#if DEBUG
            //            Context.System.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(5), Nobody.Instance, RealTimeInventory, Self);
#endif
        }
        public static async Task <OperationResult <IRealTimeInventory> > PlaceHoldAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int toHold)
        {
            var newHolds = realTimeInventory.Holds + toHold;

            if (newHolds > realTimeInventory.Quantity)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.HOLD_EXCEED_QUANTITY_FOR_HOLD, realTimeInventory, toHold).ToFailedOperationResult(realTimeInventory, productId));
            }
            var newRealTimeInventory = new RealTimeInventory(productId, realTimeInventory.Quantity, realTimeInventory.Reserved, newHolds);

            var result = await inventoryStorage.WriteInventoryAsync(newRealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, toHold, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newRealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > ResetInventoryQuantityReserveAndHoldAsync(this IRealTimeInventory currentInventory, IInventoryStorage inventoryStorage, string productId, int quantity, int reserve, int hold)
        {
            IRealTimeInventory realTimeInventory = new RealTimeInventory(currentInventory.ProductId, 0, 0, 0);

            var result = await realTimeInventory.UpdateQuantityAsync(inventoryStorage, productId, quantity);

            if (result.IsSuccessful)
            {
                result = await result.Data.ReserveAsync(inventoryStorage, productId, reserve);

                if (result.IsSuccessful)
                {
                    result = await result.Data.PlaceHoldAsync(inventoryStorage, productId, hold);

                    if (result.IsSuccessful)
                    {
                        return(result.Data.ToOperationResult(isSuccessful: true));
                    }
                }
            }
            result.Data = currentInventory;
            return(result);
        }
        public static async Task <OperationResult <IRealTimeInventory> > UpdateQuantityAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int quantity)
        {
            var newQuantity = realTimeInventory.Quantity + quantity;

            var newRealTimeInventory = new RealTimeInventory(productId, newQuantity, realTimeInventory.Reserved, realTimeInventory.Holds);
            var result = await inventoryStorage.WriteInventoryAsync(newRealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, quantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newRealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > ReserveAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int reservationQuantity)
        {
            var newReserved = Math.Max(0, realTimeInventory.Reserved + reservationQuantity);

            if ((reservationQuantity > 0) && (newReserved > realTimeInventory.Quantity - realTimeInventory.Holds))
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.RESERVATION_EXCEED_QUANTITY, realTimeInventory, reservationQuantity).ToFailedOperationResult(realTimeInventory, productId));
            }

            var newRealTimeInventory = new RealTimeInventory(productId, realTimeInventory.Quantity, newReserved, realTimeInventory.Holds);

            var result = await inventoryStorage.WriteInventoryAsync(newRealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, reservationQuantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newRealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > InventoryStorageFlushAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string id)
        {
            await inventoryStorage.FlushAsync();

            return(realTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > ReadInventoryFromStorageAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId)
        {
            try
            {
                if (string.IsNullOrEmpty(productId))
                {
                    return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.NO_PRODUCT_ID_SPECIFIED, realTimeInventory, 0).ToFailedOperationResult(realTimeInventory));
                }
                var result = await inventoryStorage.ReadInventoryAsync(productId);

                return(result.Result.ToSuccessOperationResult());
            }
            catch (Exception e)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_READ_INV, realTimeInventory, 0, e).ToFailedOperationResult());
            }
        }
        public static async Task <OperationResult <IRealTimeInventory> > PurchaseFromHoldsAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int quantity)
        {
            if (quantity < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.NEGATIVE_PURCHASE_FOR_PURCHASEFROMHOLD, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }
            var newQuantity = realTimeInventory.Quantity - quantity;
            var newHolds    = realTimeInventory.Holds - quantity;

            if (newQuantity < 0 || newHolds < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.PURCHASE_EXCEED_QUANTITY_FOR_PURCHASEFROMHOLD, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }

            var newrealTimeInventory = new RealTimeInventory(productId, newQuantity, realTimeInventory.Reserved,
                                                             newHolds);

            var result = await inventoryStorage.WriteInventoryAsync(newrealTimeInventory).ConfigureAwait(false);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, quantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newrealTimeInventory.ToOperationResult(isSuccessful: true));
        }
        public static async Task <OperationResult <IRealTimeInventory> > PurchaseAsync(this IRealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string productId, int quantity)
        {
            if (quantity < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.NEGATIVE_PURCHASE_FOR_PURCHASEFROMRESERVATION, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }
            var newQuantity = realTimeInventory.Quantity - quantity;

            var newReserved = Math.Max(0, realTimeInventory.Reserved - quantity);

            //todo we still want to sell even though there is reservation
            //var newReserved = realTimeInventory.Reserved - quantity;
            //if(newReserved<0) throw new Exception("provided " + quantity + ", available reservations must be less than or equal to quantity for product " + productId);

            if (newQuantity - realTimeInventory.Holds < 0)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.PURCHASE_EXCEED_QUANTITY_FOR_PURCHASEFROMRESERVATION, realTimeInventory, quantity).ToFailedOperationResult(realTimeInventory, productId));
            }

            var newrealTimeInventory = new RealTimeInventory(productId, newQuantity, newReserved, realTimeInventory.Holds);
            var result = await inventoryStorage.WriteInventoryAsync(newrealTimeInventory);

            if (!result.IsSuccessful)
            {
                return(InventoryServiceErrorMessageGenerator.Generate(ErrorType.UNABLE_TO_UPDATE_INVENTORY_STORAGE, realTimeInventory, quantity, result.Errors).ToFailedOperationResult(realTimeInventory, productId));
            }

            return(newrealTimeInventory.ToOperationResult(isSuccessful: true));
        }
Exemplo n.º 17
0
 public CheckedInventoryStorage(IInventoryStorage storage)
 {
     _storage = storage;
 }
 public InventoryDialogService(IInventoryStorage storage, IInputParserService parser, ICommandCache commandCache)
 {
     this.storage      = storage;
     this.parser       = parser;
     this.commandCache = commandCache;
 }
 public CheckedInventoryStorage(IInventoryStorage storage)
 {
     _storage = storage;
 }
        public static RealTimeInventory InitializeFromStorage(this RealTimeInventory realTimeInventory, IInventoryStorage inventoryStorage, string id)
        {
            var initTask = inventoryStorage.ReadInventoryAsync(id);

            Task.WaitAll(initTask);
            var inventory = initTask.Result.Result;

            if (!initTask.Result.IsSuccessful)
            {
                throw initTask.Result.Errors.Flatten();
            }
            return(new RealTimeInventory(id, inventory.Quantity, inventory.Reserved, inventory.Holds));
        }