private void ReplaceItemsFromDMarket() { Dictionary <string, ItemInfo> itemsInfo = new Dictionary <string, ItemInfo>(); foreach (var item in _bulkTransferItemsList) { var assetId = DMarketConverter.GetAssetId(item.WorldId); itemsInfo.Add(assetId, item); } switch (_actionType) { case ItemActionType.ToMarket: { var items = new AssetToMarketModel[_bulkTransferItemsList.Count]; for (var i = 0; i < items.Length; i++) { var classId = DMarketConverter.GetClassId(_bulkTransferItemsList[i].ItemType); var assetId = DMarketConverter.GetAssetId(_bulkTransferItemsList[i].WorldId); items[i] = new AssetToMarketModel { assetId = assetId, classId = classId }; } DMarketApi.AsyncToMarket(Model.GetPlayerMarketAccessToken(_connectionId), items, (response, request) => { foreach (var responseItem in response.Items) { _pendingOperations.Add(responseItem.OperationId, responseItem.AssetId); } }, OnItemOperationError); break; } case ItemActionType.FromMarket: { var itemsIdsArray = itemsInfo.Keys.ToArray(); DMarketApi.AsyncFromMarket(Model.GetPlayerMarketAccessToken(_connectionId), itemsIdsArray, (response, request) => { foreach (var item in response.Items) { _pendingOperations.Add(item.OperationId, item.AssetId); } }, OnItemOperationError); break; } } }
private void OnItemChangingMsg(AppChangingItemsMessage message) { int connectionId = message.ConnectionId; if (message.ActionType != ItemActionType.ToMarket && message.ActionType != ItemActionType.FromMarket) { return; } if (!IsCanMakeDMarketOperation(message)) { return; } var assetIds = new List <string>(); var itemsInfo = new Dictionary <string, ItemInfo>(); for (var i = 0; i < message.ItemsCount; i++) { var assetId = DMarketConverter.GetAssetId(message.GetWorldId(i)); assetIds.Add(assetId); itemsInfo.Add(assetId, new ItemInfo(message.GetWorldId(i), message.GetItemType(i))); } //TODO think about request generic... now code is duplicated switch (message.ActionType) { case ItemActionType.ToMarket: var items = new AssetToMarketModel[assetIds.Count]; for (var i = 0; i < items.Length; i++) { var classId = DMarketConverter.GetClassId(message.GetItemType(i)); items[i] = new AssetToMarketModel { assetId = assetIds[i], classId = classId }; } DMarketApi.AsyncToMarket(Model.GetPlayerMarketAccessToken(connectionId), items, (response, request) => { AsyncMarketCallback(response.Items, message, itemsInfo); }, error => { OnItemOperationError(message, error); }); break; case ItemActionType.FromMarket: DMarketApi.AsyncFromMarket(Model.GetPlayerMarketAccessToken(connectionId), assetIds.ToArray(), (response, request) => { AsyncMarketCallback(response.Items, message, itemsInfo); }, error => { OnItemOperationError(message, error); }); break; } }