protected virtual bool Save(KindKey entityId, KindItem datablob) { //we create if does not exist var saveStatus = false; using (var conn = new SqlConnection(_db.ConnectionString)) using (var command = new SqlCommand(string.Format(insertSql, _tableName.Value), conn)) { try { conn.Open(); //check if our table tables, create if it doesn't command.CommandText = string.Format(insertSql, _tableName.Value); command.Parameters.AddWithValue("@id", entityId.Value); command.Parameters.AddWithValue("@datablob", datablob.Value); saveStatus = command.ExecuteNonQuery() > 0; } catch (SqlException ex) { if (MainLogger != null) { MainLogger.Log(string.Format( "Error opening database connection{0}{1}", Environment.NewLine, ex.ToString())); } return(false); } conn.Close(); } return(saveStatus); }
/// <summary> /// Определение типа /// </summary> /// <returns></returns> public KindItem DetectType() { kind = 0;//not exist //File if (System.IO.File.Exists(PathString)) { kind = KindItem.file; } else if (System.IO.Directory.Exists(PathString)) { if (Path.GetPathRoot(PathString) != PathString) { kind = KindItem.folder;//folder } else { DriveInfo d = new DriveInfo(PathString); if (d.DriveType == DriveType.Fixed) { kind = KindItem.hardDrive;//HardDrive } } } else {//Drives DriveInfo d = new DriveInfo(PathString); if (d.DriveType == DriveType.CDRom) { kind = KindItem.CDRom;//HardDrive } } return(kind); }
public void Save(KindItem kindItem) { if (Entity == null) { throw new ArgumentNullException("Wrapped entity can not be null"); } AppInstance.Instance.LocalEntityStoreInstance.Save(Entity.Id, kindName, kindItem); }
/// <summary> /// Replaces record in database if it exists or inserts a new one if it doesn't exist. Maintains key supplied /// </summary> /// <param name="key">Unique id of entity</param> /// <param name="dataToSave">Data to save</param> /// <returns>Entity Id if successful or default error code</returns> public KindKey Update(KindKey key, KindItem dataToSave) { var saved = Save(key, dataToSave); if (!saved) { return(new KindKey(Constants.DBSAVE_ERROR)); } return(key); }
/// <summary> /// Assigns an Id and Inserts record into database /// </summary> /// <param name="dataToSave">Data to save</param> /// <returns>Unique record identifier</returns> public KindKey Put(KindItem dataToSave) { var id = new KindKey(_db.newId()); var saved = Save(id, dataToSave); if (!saved) { id = new KindKey(Constants.DBSAVE_ERROR); } return(id); }
public static T fromJson <T>(KindItem jsonString) where T : ISaveableEntity { return(JsonConvert.DeserializeObject <T>(jsonString.Value)); }
internal KindKey Save(KindKey entityId, KindName entityKind, KindItem dataToSave) { //we save to both kindregister and entity table return(new TableStore(entityKind).Update(entityId, dataToSave)); }