private void HDecode(object sender, EventArgs e) { try { if (IsPasswordEnabled) { Impersonate(true); } var ct = Ciphertext.Value; if (ct.XIsBlank() && !Setting.Value.XIsBlank()) { try { var xml = MXml.LoadText(Setting); ct = xml.X("value"); } catch { throw MException.MessageException("Setting xml tag is not valid."); } if (ct.XIsBlank()) { throw MException.MessageException("Setting xml tag had no value attribute."); } } Plaintext.Value = ct.XDecrypt(); } catch (Exception ex) { ex = AnalyzeException(ex); ex.XHandle("decrypting"); } finally { Impersonate(false); } }
private static Exception AnalyzeException(Exception ex) { if (ex.Message.StartsWith("Key not valid in specified state")) { ex = MException.MessageException(ex.Message + " - please verify that the username matches the user originally used to create this secure string."); } if (ex.Message.Contains("data is invalid")) { ex = MException.MessageException("The ciphertext data blob is invalid."); } return(ex); }
/// <summary> /// 任务自动绑定或删除主节点 返回任务详情和当前所有绑定 /// </summary> /// <param name="taskId"></param> /// <returns></returns> public static Tuple <Model.Task, List <Model.TaskBinding> > ToRightTaskNodes(int taskId, List <int> filterNodeIdds, bool checkThrow) { var taskdal = new DAL.TaskDal(); var nodedal = new DAL.NodeDal(); using (RLib.DB.DbConn dbconn = Pub.GetConn()) { var taskmodel = taskdal.GetDetail(dbconn, taskId); if (taskmodel == null || taskmodel.State != 0) { throw new MException("任务不存在或已删除!"); } var taskbinds = taskdal.GetTaskBindings(dbconn, taskId); foreach (var a in taskbinds) { a.Node = nodedal.Detail(dbconn, a.NodeId); } Exception throex = null; //添加控制节点 if (taskmodel.TaskType == 1 && taskbinds.Count(x => x.Node.NodeType == 1) == 0) { var mainnodes = nodedal.GetMainNode(dbconn); if (mainnodes.Count == 0) { throex = new MException("没有控制节点,不能运行调度任务!"); } else if (mainnodes.Count > 1) { throex = new MException("有多个控制节点,请手动添加控制节点!"); } else { var binding = taskdal.AddBinding(dbconn, new Model.TaskBinding() { BindId = 0, LastRunTime = null, LocalState = 0, ServerState = 0, NodeId = mainnodes.First().NodeId, RunVersion = 0, TaskId = taskmodel.TaskId }); binding.Node = mainnodes.First(); taskbinds.Add(binding); } } if (checkThrow == true && throex != null) { throw throex; } //删除控制节点 if (taskmodel.TaskType == 0 && taskbinds.Count(x => x.Node.NodeType == 1) > 0) { var mainnodes = taskbinds.Where(x => x.Node.NodeType == 1).ToList(); foreach (var a in mainnodes) { taskdal.DeleteBind(dbconn, a.BindId); taskbinds.Remove(a); } } if (filterNodeIdds != null && filterNodeIdds.Count > 0) { taskbinds.RemoveAll(x => !filterNodeIdds.Contains(x.NodeId)); } taskbinds = taskbinds.OrderByDescending(x => x.Node.NodeType).ToList(); return(new Tuple <Model.Task, List <Model.TaskBinding> >(taskmodel, taskbinds)); } }