public bool AddItem(Player player, StorageType type, KeyValuePair<int, StorageItem> kvp) { string cmdString = "SELECT * FROM inventory WHERE PlayerId=?pid AND ItemId=?itemid AND Slot=?slot"; MySqlCommand command = new MySqlCommand(cmdString, InvenDAOConnection); command.Parameters.AddWithValue("?pid", player.Id); command.Parameters.AddWithValue("?itemid", kvp.Value.ItemId); command.Parameters.AddWithValue("?slot", kvp.Key); MySqlDataReader reader = command.ExecuteReader(); bool isExists = reader.HasRows; reader.Close(); if (!isExists) { cmdString = "INSERT INTO inventory " + "(`AccountName`,`PlayerId`,`ItemId`,`Amount`,`Color`,`Slot`,`StorageType`) " + "VALUES (?aname, ?pid, ?itemid, ?count, ?color, ?slot, ?type); SELECT LAST_INSERT_ID();"; command = new MySqlCommand(cmdString, InvenDAOConnection); command.Parameters.AddWithValue("?aname", player.AccountName); command.Parameters.AddWithValue("?pid", player.Id); command.Parameters.AddWithValue("?itemid", kvp.Value.ItemId); command.Parameters.AddWithValue("?count", kvp.Value.Count); command.Parameters.AddWithValue("?color", kvp.Value.Color); command.Parameters.AddWithValue("?slot", kvp.Key); command.Parameters.AddWithValue("?type", type.ToString()); } else { cmdString = "UPDATE inventory SET " + "`Amount`=?count,`Color`=?color,`Slot`=?slot,`StorageType`=?type WHERE `ItemId`=?itemid AND `PlayerId`=?pid"; command = new MySqlCommand(cmdString, InvenDAOConnection); command.Parameters.AddWithValue("?count", kvp.Value.Count); command.Parameters.AddWithValue("?color", kvp.Value.Color); command.Parameters.AddWithValue("?slot", kvp.Key); command.Parameters.AddWithValue("?type", type.ToString()); command.Parameters.AddWithValue("?itemid", kvp.Value.ItemId); command.Parameters.AddWithValue("?pid", player.Id); } try { command.ExecuteNonQuery(); return true; } catch (MySqlException ex) { Log.ErrorException("AddItem Error", ex); } return false; }
public Storage LoadStorage(Player player, StorageType type) { string SQL = "SELECT * FROM `inventory` WHERE " + "`playerid` = ?pid AND `storagetype` = ?type"; MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection); cmd.Parameters.AddWithValue("?pid", player.Id); cmd.Parameters.AddWithValue("?type", type.ToString()); MySqlDataReader LoadStorageReader = cmd.ExecuteReader(); var storage = new Storage { StorageType = StorageType.Inventory }; if (LoadStorageReader.HasRows) { while (LoadStorageReader.Read()) { if (LoadStorageReader.GetInt32(2) != 20000000) { StorageItem item = new StorageItem() { ItemId = LoadStorageReader.GetInt32(2), Amount = LoadStorageReader.GetInt32(3), Color = LoadStorageReader.GetInt32(4), }; storage.Items.Add(LoadStorageReader.GetInt32(5), item); } else { storage.Money = LoadStorageReader.GetInt32(3); } } } LoadStorageReader.Close(); return storage; }
public bool AddItem(Player player, StorageType type, KeyValuePair<int, StorageItem> KeyVP) { string SQL = "INSERT INTO `inventory` " + "(`accountname`, `playerid`, `itemid`, `amount`, `color`, `slot`, `storagetype`) " + "VALUES(?accountname, ?pid, ?itemid, ?count, ?color, ?slot, ?type);"; MySqlCommand cmd = new MySqlCommand(SQL, InventoryDAOConnection); cmd.Parameters.AddWithValue("?accountname", player.AccountName); cmd.Parameters.AddWithValue("?pid", player.pid); cmd.Parameters.AddWithValue("?itemid", KeyVP.Value.ItemId); cmd.Parameters.AddWithValue("?count", KeyVP.Value.Count); cmd.Parameters.AddWithValue("?color", KeyVP.Value.Color); cmd.Parameters.AddWithValue("?slot", KeyVP.Key); cmd.Parameters.AddWithValue("?type", type.ToString()); try { cmd.ExecuteNonQuery(); return true; } catch (Exception e) { Log.ErrorException("DAO: ADD ITEM ERROR!", e); } return false; }
/// <summary> /// Save Features.SavedQuery settings to the settings file /// </summary> /// <param name="sqNode">XML-node for the Features.SavedQuery settings</param> public void Save(XmlNode sqNode) { string xpath; xpath = "./storageType"; SettingsHelper.SetSettingValue(xpath, sqNode, StorageType.ToString()); xpath = "./enableCache"; SettingsHelper.SetSettingValue(xpath, sqNode, EnableCache.ToString()); xpath = "./cacheTime"; SettingsHelper.SetSettingValue(xpath, sqNode, CacheTime.ToString()); xpath = "./enableCORS"; SettingsHelper.SetSettingValue(xpath, sqNode, EnableCORS.ToString()); xpath = "./showPeriodAndId"; SettingsHelper.SetSettingValue(xpath, sqNode, ShowPeriodAndId.ToString()); xpath = "./enableLimiterRequest"; SettingsHelper.SetSettingValue(xpath, sqNode, EnableLimitRequest.ToString()); xpath = "./limiterRequests"; SettingsHelper.SetSettingValue(xpath, sqNode, LimiterRequests.ToString()); xpath = "./limiterTimespan"; SettingsHelper.SetSettingValue(xpath, sqNode, LimiterTimespan.ToString()); }
/// <summary> /// Creates a storage of specified type using metadata information of enumeration value. /// </summary> /// <param name="st">Type of storage to create.</param> /// <param name="storageStr">Connection string or file path for data storage.</param> /// <returns>Newly created storage.</returns> public static AbstractResultStorage CreateStorage(StorageType st, string storageStr) { Type[] patametersType = { typeof(String) }; object[] invokeParameters = { storageStr }; StorageTypeInfo[] info = (StorageTypeInfo[])st.GetType().GetField(st.ToString()).GetCustomAttributes(typeof(StorageTypeInfo), false); Type t = Type.GetType(info[0].Implementation, true); return (AbstractResultStorage)t.GetConstructor(patametersType).Invoke(invokeParameters); }
/// <summary> /// Create a new database. Requires additional authentication to the server. /// </summary> /// <param name="name">database name</param> /// <param name="storageType">storage type</param> /// <param name="databaseType">can be document or graph.</param> public ICreateDatabaseResponse CreateDatabase(string name, StorageType storageType, DatabaseType databaseType = DatabaseType.Graph) { name.ThrowIfNullOrEmpty("name"); if (DatabaseExist(name)) { throw new Exception("The database already exists."); } string url = "database/{0}/{1}/{2}".F(Encoded(name), Encoded(storageType.ToString().ToLower()), Encoded(databaseType.ToString().ToLower())); return(DoRequest <CreateDatabaseResponse>("POST", url).Response); }
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); writer.WritePropertyName("shareType"); writer.WriteStringValue(ShareType.ToString()); writer.WritePropertyName("storageType"); writer.WriteStringValue(StorageType.ToString()); if (Optional.IsDefined(ShareSizeInGB)) { writer.WritePropertyName("shareSizeInGB"); writer.WriteNumberValue(ShareSizeInGB.Value); } writer.WriteEndObject(); }
/// <summary> /// Initialize /// </summary> public void Initialize() { if (type == StorageType.None) { throw new NotSupportedException("Not support the type of none."); } storage = Activator.CreateInstance(Type.GetType(GetDescription(type))) as IStorage; if (storage == null) { throw new DllNotFoundException("Can not find the type" + type.ToString()); } }
public static bool Exists(StorageType key) { bool response = false; try { using (var storage = new LocalStorage()) { response = storage.Exists(key.ToString()); } } catch (Exception ex) { response = false; } return(response); }
public static string Get(StorageType key) { string response = string.Empty; try { using (var storage = new LocalStorage()) { response = storage.Get(key.ToString()).ToString(); storage.Persist(); } } catch (Exception ex) { response = "not found"; } return(response); }
public static string Store(StorageType key, string value) { string response = string.Empty; try { using (var storage = new LocalStorage()) { storage.Store(key.ToString(), value); storage.Persist(); } } catch (Exception ex) { response = ex.Message; } return(response); }
public static Func <Transaction, Transaction, int, bool> Upgrader(StorageType storageType, ConfigurationStorage configurationStorage, DocumentsStorage documentsStorage) { return((readTx, writeTx, currentVersion) => { var name = $"Raven.Server.Storage.Schema.Updates.{storageType.ToString()}.From{currentVersion}"; var schemaUpdateType = typeof(SchemaUpgrader).Assembly.GetType(name); if (schemaUpdateType == null) { return false; } var schemaUpdate = (ISchemaUpdate)Activator.CreateInstance(schemaUpdateType); return schemaUpdate.Update(new UpdateStep { ReadTx = readTx, WriteTx = writeTx, ConfigurationStorage = configurationStorage, DocumentsStorage = documentsStorage, }); }); }
public static int ParseStorageType(this StorageType input) { switch (input) { case StorageType.uint32: case StorageType.int32: return(4); case StorageType.uint16: case StorageType.int16: return(2); case StorageType.@float: return(99); case StorageType.uint8: case StorageType.int8: return(1); default: throw new Exception($"{input.ToString()} is a unhandled (unsupported) storage type."); } }
public Dictionary<int, StorageItem> LoadStorage(Player player, StorageType type) { string cmdString = "SELECT * FROM inventory WHERE PlayerId=?id AND StorageType=?type"; MySqlCommand command = new MySqlCommand(cmdString, InvenDAOConnection); command.Parameters.AddWithValue("?id", player.Id); command.Parameters.AddWithValue("?type", type.ToString()); MySqlDataReader reader = command.ExecuteReader(); Dictionary<int, StorageItem> items = new Dictionary<int, StorageItem>(); if (reader.HasRows) { while (reader.Read()) { StorageItem item = new StorageItem() { ItemId = reader.GetInt32(3), Count = reader.GetInt32(4), Color = reader.GetInt32(5), }; items.Add(reader.GetInt32(6), item); } } reader.Close(); return items; }
public FooResponse Put(string blobID, StorageType type) { using (var fooCDN = new HttpClient()) { fooCDN.BaseAddress = _baseUri; fooCDN.DefaultRequestHeaders.Accept.Clear(); HttpContent empty = new StringContent(""); empty.Headers.Add("Content-Length", "0"); HttpResponseMessage response = fooCDN.PutAsync("/api/content/" + blobID + "?type=" + type.ToString(), empty).Result; FooResponse fooResult = new FooResponse() { StatusCode = response.StatusCode }; var x = response.IsSuccessStatusCode; return fooResult; } }
public ParameterConditionalDBExists(Parameter compared, StorageType storage) : base(compared, WarningType.INVALID_VALUE) { this.storage = storage; this.description = storage.ToString() + " doesn't exist"; }
private void buttonOK_Click(object sender, RoutedEventArgs e) { try { if (!string.IsNullOrEmpty(textBoxName.Text)) { if (!existingList.Contains(textBoxName.Text)) { if (selectedStorageType != StorageType.None) { bool validated = false; switch (selectedStorageType) { case StorageType.String: validated = true; break; case StorageType.ElementId: validated = true; break; case StorageType.Double: double dblValue = 0; if (double.TryParse(textBoxName.Text, out dblValue)) { validated = true; } break; case StorageType.Integer: int intValue = 0; if (int.TryParse(textBoxName.Text, out intValue)) { validated = true; } break; } if (validated) { nameText = textBoxName.Text; this.DialogResult = true; } else { MessageBox.Show("Please enter a valid type of a value, " + selectedStorageType.ToString(), "Invalid Value Type", MessageBoxButton.OK, MessageBoxImage.Information); } } else { nameText = textBoxName.Text; this.DialogResult = true; } } else { MessageBox.Show(textBoxName.Text + " already exist.", "Invalid Name", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("The name cannot be empty.", "Invalid Name", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to create a new name.\n" + ex.Message, "Create a New Name", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public ChooseRowFromDBForm(StorageType storage) { InitializeComponent(); data = DB.GetInstance().GetStringDictionary(storage); this.Text = "Select " + storage.ToString().ToLower(); }