public void PutItem(StorageItem item)
 {
     var stringKey = BitConverter.ToString(item.Key);
     var storage = new List<StorageItem>();
     storage = cache.AddOrGetExisting(stringKey, storage, item.Expires) as List<StorageItem>;
     lock (storage)
     {
         storage.Add(item);
         if (storage.Count > 1)
         {
             var maxExpires = storage.Max(x => x.Expires);
             cache.Add(stringKey, storage, maxExpires);
         }
     }
 }
        public void PutItem(StorageItem item)
        {
            var stringKey = BitConverter.ToString(item.Key);

            List<StorageItem> result = null;
            cache.TryGetValue(stringKey, out result);

            if (result == null)
            {
                result = new List<StorageItem>();
                cache[stringKey] = result;
            }

            result.Add(item);
        }
        public void Initialize()
        {            
            storageInfo = new BuildableItemStorageInformation(BuildableItemEnum.White_Flour.ToString());

            bitem = new StorageItem
            {
                ItemCode = BuildableItemEnum.White_Pizza_Dough,
                Stats = new List<BuildableItemStat>
                {
                    new BuildableItemStat
                    {
                        RequiredLevel = 2,
                        CoinCost = 50,
                        Experience = 100,
                        BuildSeconds = 60,
                        CouponCost = 0,
                        SpeedUpCoupons = 1,
                        SpeedUpSeconds = 60,
                        RequiredItems = new List<ItemQuantity>
                        {
                            new ItemQuantity 
                            {
                                ItemCode = BuildableItemEnum.White_Flour,
                                StoredQuantity = 1
                            },
                            new ItemQuantity
                            {
                                ItemCode = BuildableItemEnum.Salt,
                                StoredQuantity = 1
                            },
                            new ItemQuantity
                            {
                                ItemCode = BuildableItemEnum.Yeast,
                                StoredQuantity = 1                    
                            }
                        }
                    }
                },
                StorageStats = new List<StorageItemStat>
                {
                    new StorageItemStat
                    {
                        Capacity = 2
                    }                   
                }
            };
        }
        public static List<StorageItem> GetBlobs(string containerName)
        {
            BlobRequestOptions options = new BlobRequestOptions();
            options.BlobListingDetails = BlobListingDetails.All;
            options.UseFlatBlobListing = true;

            var listBlobItems = GetContainer(containerName).ListBlobs(options);
            var blobs = new List<StorageItem>();
            foreach (var listBlobItem in listBlobItems)
            {
                var blob = new StorageItem();
                blob.Uri = listBlobItem.Uri;
                if (listBlobItem is CloudBlob)
                    blob.Name = ((CloudBlob)listBlobItem).Name;
                blobs.Add(blob);
            }
            return blobs;
        }
        /// <summary>
        /// Saves the file back to the database
        /// </summary>
        /// <param name="file">the file to save</param>
        private StorageItem SaveStorageItem(StorageItem storageItem)
        {
            try
            {
                //this._storageItemRepository.SaveOrUpdate(storageItem);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Probelm saving file", e);
            }

            return storageItem;
        }
Beispiel #6
0
	void insertSelectPanel (StorageItem im)
	{
		if(itemMg == im)
			return;

		itemMg = im;

		GameObject panel = mainObj.transform.FindChild ("_SelectItem").gameObject;
		if (!panel.activeInHierarchy)
			panel.SetActive (true);

		panel.transform.FindChild ("_Image").GetComponent<UISprite> ().spriteName = im.imageName;

		UILabel label = panel.transform.FindChild ("_Name").GetComponent<UILabel> ();
		label.text = im.itemName;
		label.AssumeNaturalSize();
		//remove
		for(int i=0;i<panel.transform.FindChild ("_Name").childCount;i++){
			DestroyImmediate(panel.transform.FindChild ("_Name").transform.GetChild(i).gameObject);
		}

		panel.transform.FindChild ("_Info").GetComponent<UILabel> ().text = im.itemInfo;

		switch (m_state) {
			
		case StorageState.TREASURE_BOX:
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_Name").GetComponent<UILabel> ().text = "수요";
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_ImageKey").GetComponent<UISprite> ().spriteName = "Detail_Icon_Key_01";
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_Num").GetComponent<UILabel> ().text = "8/1";
			panel.transform.FindChild ("_BtnBuy").transform.FindChild ("_Name").GetComponent<UILabel> ().text = "사용";
			break;
			
		case StorageState.EQUIL:
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_Name").GetComponent<UILabel> ().text = "단가";
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_ImageKey").GetComponent<UISprite> ().spriteName = "Detail_Icon_Price";
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_Num").GetComponent<UILabel> ().text = "999,999";
			panel.transform.FindChild ("_BtnBuy").transform.FindChild ("_Name").GetComponent<UILabel> ().text = "판매";

			float nx = label.width+100;
			GameObject abilltyPanel = SKCommon.loadPrefeb("_PAbillity", label.gameObject);
			for(int i=3;i>=0;i--){
				bool bt = Random.Range(0,2) == 0 ? false : true;
				if(!bt)
					DestroyImmediate (abilltyPanel.transform.GetChild(i).gameObject);
			}
			abilltyPanel.GetComponent<UIGrid>().Reposition();
			abilltyPanel.transform.localPosition = new Vector3(nx, 0f, 0f);
			//info label hiden
			panel.transform.FindChild ("_Info").gameObject.SetActive(false);
			break;
			
		case StorageState.TOOLS:
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_Name").GetComponent<UILabel> ().text = "단가";
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_ImageKey").GetComponent<UISprite> ().spriteName = "Detail_Icon_Price";
			panel.transform.FindChild ("_BgNum").transform.FindChild ("_Num").GetComponent<UILabel> ().text = "900";
			panel.transform.FindChild ("_BtnBuy").transform.FindChild ("_Name").GetComponent<UILabel> ().text = "판매";
			break;
		}

	}
Beispiel #7
0
        protected virtual JObject Process(string method, JArray _params)
        {
            switch (method)
            {
            case "getaccountstate":
            {
                UInt160      script_hash = Wallet.ToScriptHash(_params[0].AsString());
                AccountState account     = Blockchain.Default.GetAccountState(script_hash) ?? new AccountState(script_hash);
                return(account.ToJson());
            }

            case "getassetstate":
            {
                UInt256    asset_id = UInt256.Parse(_params[0].AsString());
                AssetState asset    = Blockchain.Default.GetAssetState(asset_id);
                return(asset?.ToJson() ?? throw new RpcException(-100, "Unknown asset"));
            }

            case "getbestblockhash":
                return(Blockchain.Default.CurrentBlockHash.ToString());

            case "getblock":
            {
                Block block;
                if (_params[0] is JNumber)
                {
                    uint index = (uint)_params[0].AsNumber();
                    block = Blockchain.Default.GetBlock(index);
                }
                else
                {
                    UInt256 hash = UInt256.Parse(_params[0].AsString());
                    block = Blockchain.Default.GetBlock(hash);
                }
                if (block == null)
                {
                    throw new RpcException(-100, "Unknown block");
                }
                bool verbose = _params.Count >= 2 && _params[1].AsBooleanOrDefault(false);
                if (verbose)
                {
                    JObject json = block.ToJson();
                    json["confirmations"] = Blockchain.Default.Height - block.Index + 1;
                    UInt256 hash = Blockchain.Default.GetNextBlockHash(block.Hash);
                    if (hash != null)
                    {
                        json["nextblockhash"] = hash.ToString();
                    }
                    return(json);
                }
                else
                {
                    return(block.ToArray().ToHexString());
                }
            }

            case "getblockcount":
                return(Blockchain.Default.Height + 1);

            case "getblockhash":
            {
                uint height = (uint)_params[0].AsNumber();
                if (height >= 0 && height <= Blockchain.Default.Height)
                {
                    return(Blockchain.Default.GetBlockHash(height).ToString());
                }
                else
                {
                    throw new RpcException(-100, "Invalid Height");
                }
            }

            case "getblocksysfee":
            {
                uint height = (uint)_params[0].AsNumber();
                if (height >= 0 && height <= Blockchain.Default.Height)
                {
                    return(Blockchain.Default.GetSysFeeAmount(height).ToString());
                }
                else
                {
                    throw new RpcException(-100, "Invalid Height");
                }
            }

            case "getconnectioncount":
                return(LocalNode.RemoteNodeCount);

            case "getcontractstate":
            {
                UInt160       script_hash = UInt160.Parse(_params[0].AsString());
                ContractState contract    = Blockchain.Default.GetContract(script_hash);
                return(contract?.ToJson() ?? throw new RpcException(-100, "Unknown contract"));
            }

            case "getrawmempool":
                return(new JArray(LocalNode.GetMemoryPool().Select(p => (JObject)p.Hash.ToString())));

            case "getrawtransaction":
            {
                UInt256     hash    = UInt256.Parse(_params[0].AsString());
                bool        verbose = _params.Count >= 2 && _params[1].AsBooleanOrDefault(false);
                int         height  = -1;
                Transaction tx      = LocalNode.GetTransaction(hash);
                if (tx == null)
                {
                    tx = Blockchain.Default.GetTransaction(hash, out height);
                }
                if (tx == null)
                {
                    throw new RpcException(-100, "Unknown transaction");
                }
                if (verbose)
                {
                    JObject json = tx.ToJson();
                    if (height >= 0)
                    {
                        Header header = Blockchain.Default.GetHeader((uint)height);
                        json["blockhash"]     = header.Hash.ToString();
                        json["confirmations"] = Blockchain.Default.Height - header.Index + 1;
                        json["blocktime"]     = header.Timestamp;
                    }
                    return(json);
                }
                else
                {
                    return(tx.ToArray().ToHexString());
                }
            }

            case "getstorage":
            {
                UInt160     script_hash = UInt160.Parse(_params[0].AsString());
                byte[]      key         = _params[1].AsString().HexToBytes();
                StorageItem item        = Blockchain.Default.GetStorageItem(new StorageKey
                    {
                        ScriptHash = script_hash,
                        Key        = key
                    }) ?? new StorageItem();
                return(item.Value?.ToHexString());
            }

            case "gettxout":
            {
                UInt256 hash  = UInt256.Parse(_params[0].AsString());
                ushort  index = (ushort)_params[1].AsNumber();
                return(Blockchain.Default.GetUnspent(hash, index)?.ToJson(index));
            }

            case "sendrawtransaction":
            {
                Transaction tx = Transaction.DeserializeFrom(_params[0].AsString().HexToBytes());
                return(LocalNode.Relay(tx));
            }

            case "submitblock":
            {
                Block block = _params[0].AsString().HexToBytes().AsSerializable <Block>();
                return(LocalNode.Relay(block));
            }

            case "validateaddress":
            {
                JObject json = new JObject();
                UInt160 scriptHash;
                try
                {
                    scriptHash = Wallet.ToScriptHash(_params[0].AsString());
                }
                catch
                {
                    scriptHash = null;
                }
                json["address"] = _params[0];
                json["isvalid"] = scriptHash != null;
                return(json);
            }

            default:
                throw new RpcException(-32601, "Method not found");
            }
        }
Beispiel #8
0
 private string GetUserPropValue(StorageItem storage, string name)
 {
     UserProperties userProps;
     try
     {
         userProps = storage.UserProperties;
     }
     catch
     {
         userProps = null;
     }
     if (userProps == null) return string.Empty;
     UserProperty prop;
     try
     {
         prop = userProps.Find(name);
     }
     catch
     {
         prop = null;
     }
     return (prop == null)
                ? string.Empty
                : prop.Value;
 }
Beispiel #9
0
 public void AddItem(StorageItem MyStorageItem)
 {
     TheStorage.Add(MyStorageItem);
     //add the row to the database
     return;
 }
Beispiel #10
0
 public void Delete(StorageItem entity)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
 public StorageItem SaveOrUpdate(StorageItem entity)
 {
     throw new NotImplementedException();
 }
        //public event EventHandler<HttpProgressEventArgs> HttpReceiveProgress;
        //public event EventHandler<HttpProgressEventArgs> HttpSendProgress;

        protected override IHttpResponseAbstraction HandleCopy()
        {
            var containerName = GetContainerName(this.Uri.Segments);
            var objectName = GetObjectName(this.Uri.Segments);

            if (containerName == null && objectName == null)
            {
                return TestHelper.CreateErrorResponse();
            }

            //cannot copy a container
            if (objectName == null)
            {
                return TestHelper.CreateResponse(HttpStatusCode.MethodNotAllowed);
            }

            if (!this.Containers.ContainsKey(containerName))
            {
                return TestHelper.CreateResponse(HttpStatusCode.NotFound);
            }

            if (!this.Headers.ContainsKey("Destination"))
            {
                return TestHelper.CreateResponse(HttpStatusCode.PreconditionFailed);
            }

            if (!this.Objects.ContainsKey(objectName))
            {
                return TestHelper.CreateResponse(HttpStatusCode.NotFound);
            }

            var destination = this.Headers["Destination"];
            var destinationSegs = destination.Split('/');
            if (destinationSegs.Count() < 2)
            {
                return TestHelper.CreateResponse(HttpStatusCode.PreconditionFailed);
            }

            if (destinationSegs[1] == string.Empty)
            {
                return TestHelper.CreateResponse(HttpStatusCode.MethodNotAllowed);
            }

            if (!this.Containers.ContainsKey(destinationSegs[0]))
            {
                return TestHelper.CreateResponse(HttpStatusCode.NotFound);
            }

            var destObjectName = string.Join("", destinationSegs.Skip(1));
            var srcObj = this.Objects[objectName];
            
            var obj = new StorageItem(destObjectName);
            obj.MetaData = srcObj.MetaData;
            obj.ProcessMetaDataFromHeaders(this.Headers);
            var content = new MemoryStream();
            srcObj.Content.CopyTo(content);
            srcObj.Content.Position = 0;
            content.Position = 0;
            obj.Content = content;

            this.Objects[obj.Name] = obj;

            var headers = GenerateObjectResponseHeaders(obj);

            return TestHelper.CreateResponse(HttpStatusCode.Created, headers);

        }
 internal Dictionary<string, string> GenerateContainerResponseHeaders(StorageItem obj)
 {
     return new Dictionary<string, string>(obj.MetaData)
     {
         {"X-Container-Bytes-Used", "0"},
         {"Content-Type", this.ContentType},
         {"X-Container-Object-Count", "0"},
         {"Date", DateTime.UtcNow.ToShortTimeString()},
         {"X-Container-Read", ".r.*,.rlistings"},
         {"X-Trans-Id", "12345"},
         {"X-Timestamp", "1234567890.98765"}
     };
 }
        internal Dictionary<string, string> GenerateObjectResponseHeaders(StorageItem obj)
        {
            var etag = Convert.ToBase64String(MD5.Create().ComputeHash(obj.Content));
            obj.Content.Position = 0;

            return new Dictionary<string, string>(obj.MetaData)
            {
                {"ETag", etag},
                {"Content-Type", this.ContentType},
                {"X-Trans-Id", "12345"},
                {"Date", DateTime.UtcNow.ToShortTimeString()},
                {"X-Timestamp", "1234567890.98765"}
            };
        }
        protected override IHttpResponseAbstraction HandlePut()
        {
            var containerName = GetContainerName(this.Uri.Segments);
            var objectName = GetObjectName(this.Uri.Segments);

            if (containerName == null && objectName == null)
            {
                return TestHelper.CreateErrorResponse();
            }

            if (objectName != null)
            {
                var obj = new StorageItem(objectName);
                obj.ProcessMetaDataFromHeaders(this.Headers);
                obj.LoadContent(this.Content);
                this.Objects[obj.Name] = obj;

                var headers = GenerateObjectResponseHeaders(obj);

                return TestHelper.CreateResponse(HttpStatusCode.Created, headers);
            }
            else
            {
                var container = new StorageItem(containerName);
                container.ProcessMetaDataFromHeaders(this.Headers);

                var containerUpdated = this.Containers.Keys.Any(k => String.Equals(k, container.Name, StringComparison.InvariantCultureIgnoreCase));

                this.Containers[container.Name] = container;

                return TestHelper.CreateResponse(containerUpdated ? HttpStatusCode.Accepted : HttpStatusCode.Created);
            }
        }
 public static List<StorageItem> GetContainers()
 {
     var listContainerItems = GetClient().ListContainers();
     var containers = new List<StorageItem>();
     foreach (var listContainerItem in listContainerItems)
     {
         var container = new StorageItem();
         container.Uri = listContainerItem.Uri;
         container.Name = listContainerItem.Name;
         containers.Add(container);
     }
     return containers;
 }
 public OutlookPstConfigPersister(StorageItem storage)
 {
     _storage = storage;
 }
Beispiel #18
0
 public void updateItem(StorageItem myStorageItem, int quantity, bool replaceQuantity)
 {
     bool itemFound = false;
     StorageItem tempStorageItem = new StorageItem();;
     for (int count = 0; count < TheStorage.Count; count++)
     {
         tempStorageItem = (StorageItem)TheStorage[count];
         if (tempStorageItem.pos == myStorageItem.pos && tempStorageItem.knownItemsID == myStorageItem.knownItemsID)
         {
             TradeHandler.TradeLogItem myItem = new TradeHandler.TradeLogItem();
             myItem.KnownItemsSqlID = myStorageItem.knownItemsID;
             myItem.quantity = (uint)Math.Abs(quantity);
             myItem.categoryNum = myStorageItem.category_num;
             if (quantity < 0)
             {
                 myItem.action = "deposited";
                 if (replaceQuantity)
                 {
                     tempStorageItem.quantity = myItem.quantity;
                 }
                 else
                 {
                     tempStorageItem.quantity += myItem.quantity;
                 }
             }
             else
             {
                 myItem.action = "withdrew";
                 if (replaceQuantity)
                 {
                     tempStorageItem.quantity = myItem.quantity;
                 }
                 else
                 {
                     tempStorageItem.quantity -= myItem.quantity;
                 }
             }
             if (tempStorageItem.quantity > 0)
             {
                 TheStorage[count] = tempStorageItem;
                 TheMySqlManager.UpdateStorageItem(myItem, replaceQuantity);
             }
             else
             {
                 TheStorage.RemoveAt(count);
                 TheMySqlManager.DeleteStorageItem(myStorageItem);
             }
             itemFound = true;
         }
     }
     if (!itemFound)
     {
         TradeHandler.TradeLogItem myItem = new TradeHandler.TradeLogItem();
         myItem.action = "deposited";
         myItem.KnownItemsSqlID = myStorageItem.knownItemsID;
         myItem.price = 0;
         myItem.quantity = (uint)Math.Abs(quantity);
         myItem.categoryNum = myStorageItem.category_num;
         TheMySqlManager.UpdateStorageItem(myItem, false);
         myStorageItem.quantity = myItem.quantity;
         TheStorage.Add(myStorageItem);
     }
 }
Beispiel #19
0
 private bool LoadStoreAddresses(StorageItem storage)
 {
     var value = GetUserPropValue(storage, "StoreAddresses");
     if(string.IsNullOrEmpty(value)) return false;
     var dict = (Dictionary<string, string>)
                     JsonConvert.DeserializeObject<IDictionary<string, string>>(
                     value, new JsonConverter[] { new DictionaryConverter() });
     foreach (var key in dict.Keys)
     {
         if (_storeAddresses.ContainsKey(key))
         {
             _storeAddresses[key] = dict[key];
         }
         else
         {
             _storeAddresses.Add(key,dict[key]);
         }
     }
     return true;
 }
Beispiel #20
0
        public void TestStorage_Put()
        {
            var engine = GetEngine(false, true);

            //CheckStorageContext fail
            var key            = new byte[] { 0x01 };
            var value          = new byte[] { 0x02 };
            var state          = TestUtils.GetContract();
            var storageContext = new StorageContext
            {
                Id         = state.Id,
                IsReadOnly = false
            };

            engine.Put(storageContext, key, value);

            //key.Length > MaxStorageKeySize
            key   = new byte[ApplicationEngine.MaxStorageKeySize + 1];
            value = new byte[] { 0x02 };
            Assert.ThrowsException <ArgumentException>(() => engine.Put(storageContext, key, value));

            //value.Length > MaxStorageValueSize
            key   = new byte[] { 0x01 };
            value = new byte[ushort.MaxValue + 1];
            Assert.ThrowsException <ArgumentException>(() => engine.Put(storageContext, key, value));

            //context.IsReadOnly
            key   = new byte[] { 0x01 };
            value = new byte[] { 0x02 };
            storageContext.IsReadOnly = true;
            Assert.ThrowsException <ArgumentException>(() => engine.Put(storageContext, key, value));

            //storage value is constant
            var snapshot = Blockchain.Singleton.GetSnapshot();

            var storageKey = new StorageKey
            {
                Id  = state.Id,
                Key = new byte[] { 0x01 }
            };
            var storageItem = new StorageItem
            {
                Value      = new byte[] { 0x01, 0x02, 0x03, 0x04 },
                IsConstant = true
            };

            snapshot.AddContract(state.Hash, state);
            snapshot.Add(storageKey, storageItem);
            engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot);
            engine.LoadScript(new byte[] { 0x01 });
            key   = new byte[] { 0x01 };
            value = new byte[] { 0x02 };
            storageContext.IsReadOnly = false;
            Assert.ThrowsException <InvalidOperationException>(() => engine.Put(storageContext, key, value));

            //success
            storageItem.IsConstant = false;
            engine.Put(storageContext, key, value);

            //value length == 0
            key   = new byte[] { 0x01 };
            value = System.Array.Empty <byte>();
            engine.Put(storageContext, key, value);
        }