private void BtnUpdate_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(this.TBKey.Text)) { throw new Exception("键不能为空"); } object obj = null; if (Val is string) { var str = (string)Val; if (str.StartsWith("{") && str.EndsWith("}")) { obj = JsonUtil <dynamic> .Serialize(JsonUtil <dynamic> .Deserialize(TBValContent.Text)); } else { obj = TBValContent.Text; } } else { obj = LJC.FrameWork.Comm.JsonUtil <object> .Deserialize(TBValContent.Text, Val.GetType()); } var client = LJC.FrameWork.Couchbase.CouchbaseHelper.GetClient(Connstr.Split(':')[0], int.Parse(Connstr.Split(':')[1]), Bucket); if (this.TBKey.Text != Key) { if (client.KeyExists(this.TBKey.Text)) { throw new Exception("新的键已经存在,不能修改。"); } } else { LJC.FrameWork.LogManager.LogHelper.Instance.Info("修改备份,key=" + Key + "类型:" + Val.GetType().FullName + ",原值:" + JsonUtil <object> .Serialize(Val)); } if (client.Store(Enyim.Caching.Memcached.StoreMode.Set, this.TBKey.Text, obj)) { MessageBox.Show("存储成功"); } else { MessageBox.Show("存储失败"); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "修改出错", MessageBoxButtons.YesNo, MessageBoxIcon.Error); } }
private static string getConn() { string connect = ""; Connstr conn = new Connstr(); var ss = conn.GetType(); PropertyInfo[] props = ss.GetProperties(); foreach (var prop in props) { if (prop.GetIndexParameters().Length == 0) { connect = prop.GetValue(conn).ToString(); //Console.WriteLine(" {0} ({1}): {2}", prop.Name, // prop.PropertyType.Name, // prop.GetValue(conn)); } } return(connect); }