/// <summary> /// 更新是否正确的状态 /// </summary> /// <param name="bosConfig"></param> public void UpdateIsRight(BosConfig bosConfig) { string sql = "update bos_config SET ,isRight={0} where Id={1} "; sql = String.Format(sql, bosConfig.isRight, bosConfig.Id); Db.Update(sql); }
public void Insert(BosConfig bosConfig) { string baseInsert = "INSERT INTO bos_config (AccessKeyId ,AccessKey ,BucketName ,Endpoint ,isRight,type,AppId ) values"; string sqltpl = "('{0}','{1}','{2}','{3}','{4}','{5}','{6}')"; baseInsert += String.Format(sqltpl, bosConfig.AccessKeyId, bosConfig.AccessKey, bosConfig.BucketName, bosConfig.Endpoint, 1, bosConfig.Type, bosConfig.AppId); Db.Insert(baseInsert); }
public void Update(BosConfig bosConfig) { if (bosConfig.Id == 0) { bosConfig.Type = Constant.CloudType; Insert(bosConfig); return; } string sql = "update bos_config SET AccessKeyId='{0}',AccessKey='{1}',BucketName='{2}',Endpoint='{3}' ,AppId='{4}'where Id={5} "; sql = String.Format(sql, bosConfig.AccessKeyId, bosConfig.AccessKey, bosConfig.BucketName, bosConfig.Endpoint, bosConfig.AppId, bosConfig.Id); Db.Update(sql); }
private static object BceClientConfiguration_Lock = new object(); //锁同步 public static void SetBosConfig(BosConfig val) { BosClient = null; config = null; BosConfig = val; }
public void addFunction(JSObject myObject) { //修改配置 var editBosConfigFunc = myObject.AddFunction("editBosConfig"); editBosConfigFunc.Execute += (func, args) => { var jsparams = args.Arguments.FirstOrDefault(p => p.IsArray); var jsArray = CfrV8Value.CreateArray(1); BosConfig bosConfig = new BosConfig(); bosConfig.AccessKeyId = jsparams.GetValue(0).StringValue; bosConfig.AccessKey = jsparams.GetValue(1).StringValue; bosConfig.BucketName = jsparams.GetValue(2).StringValue; bosConfig.Endpoint = jsparams.GetValue(3).StringValue; bosConfig.Id = jsparams.GetValue(4).IntValue; bosConfig.AppId = jsparams.GetValue(5).StringValue; Result result = new Result(); BosConfig beforeBosConfig = Constant.CloudType == 0 ? BaiduBOSAPI.BosConfig : TencentBOSAPI.BosConfig; try { BaiduBOSAPI.SetBosConfig(bosConfig); if (Constant.CloudType == 0) { BaiduBOSAPI.BosConfig = bosConfig; BaiduCloudFileService.UpdateBaiduAll(); } else { TencentBOSAPI.BosConfig = bosConfig; TencentCloudFileService.UpdateTencentAll(); } BosConfigService.Update(bosConfig); } catch (Exception exception) { Console.WriteLine("Exception caught: {0}", exception); result.State = 4; result.Msg = "配置信息错误,请检查后再次提交"; if (Constant.CloudType == 0) { BaiduBOSAPI.SetBosConfig(beforeBosConfig); } else { TencentBOSAPI.BosConfig = beforeBosConfig; } } jsArray.SetValue(0, CfrV8Value.CreateString(JsonConvert.SerializeObject(result))); args.SetReturnValue(jsArray); }; //获取配置信息 var getBosConfigFunc = myObject.AddFunction("getBosConfig"); getBosConfigFunc.Execute += (func, args) => { var jsArray = CfrV8Value.CreateArray(1); Result result = new Result(); BosConfig config = BosConfigService.Get(" Type=" + Constant.CloudType); if (config == null) { config = new BosConfig(); } config.Type = Constant.CloudType; result.Data = config; jsArray.SetValue(0, CfrV8Value.CreateString(JsonConvert.SerializeObject(result))); args.SetReturnValue(jsArray); }; }
public void addFunction(JSObject myObject) { //获取全部列表 var getArrayFromCSFunc = myObject.AddFunction("getArrayFromCSharp"); getArrayFromCSFunc.Execute += (func, args) => { var jsparams = args.Arguments.FirstOrDefault(p => p.IsArray); int pageNum = jsparams.GetValue(0).IntValue; int pageSize = jsparams.GetValue(1).IntValue; Result result = new Result(); var jsArray = CfrV8Value.CreateArray(1); BosConfig bosConfig = Constant.CloudType == 0 ? BaiduBOSAPI.BosConfig : TencentBOSAPI.BosConfig; if (bosConfig == null) { result.State = 3; result.Msg = "配置未初始化"; } else { try { if (Constant.CloudType == 0) { BaiduCloudFileService.UpdateBaiduAll(); } else { TencentCloudFileService.UpdateTencentAll(); } result.Data = CommonCloudFileService.Page(pageNum, pageSize); } catch (BceServiceException exception) { if (exception.Message.IndexOf("is an overdue bill of your account") != -1) { result.State = 1; result.Msg = "您的百度云账号已欠费,请充值后使用"; } } catch (Exception exception) { Console.WriteLine("Exception caught: {0}", exception); result.State = 4; result.Msg = "配置信息错误"; } } jsArray.SetValue(0, CfrV8Value.CreateString(JsonConvert.SerializeObject(result))); args.SetReturnValue(jsArray); }; //刷新 var refreshCloudFileFunc = myObject.AddFunction("refreshCloudFile"); refreshCloudFileFunc.Execute += (func, args) => { var jsArray = CfrV8Value.CreateArray(1); Result result = new Result(); try { if (Constant.CloudType == 0) { BaiduCloudFileService.UpdateBaiduAll(); } else { TencentCloudFileService.UpdateTencentAll(); } result.Data = CommonCloudFileService.Page(1, 15); } catch (Exception e) { Console.WriteLine("Exception caught: {0}", e); result.State = 1; } jsArray.SetValue(0, CfrV8Value.CreateString(JsonConvert.SerializeObject(result))); args.SetReturnValue(jsArray); }; }