/// <summary> /// Finds a value in Kademlia. /// </summary> /// <param name="contact"></param> /// <returns></returns> private IEnumerable <IContact> FindValue(IContact contact) { if (contact == null) { throw new ArgumentNullException("contact"); } IResult result = null; try { using (NodeProxy nodeProxy = new NodeProxy(_owner, contact, true)) { result = nodeProxy.Context.FindValue(_key); } } catch (Exception ex) { HandleException(ex, contact); } if (result != null && result.Entries != null) { _value = result.Entries; _valueFoundAt = contact; AbortAllLookups(); } else if (result != null && result.Contacts != null) { return(result.Contacts.ToList()); } return(new List <IContact>()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public <E extends Exception> void writeTo(org.neo4j.values.AnyValueWriter<E> writer) throws E public override void WriteTo <E>(AnyValueWriter <E> writer) where E : Exception { TextArray l; MapValue p; try { l = Labels(); p = Properties(); } catch (NotFoundException) { l = Values.stringArray(); p = VirtualValues.EMPTY_MAP; } catch (InvalidRecordException e) { throw new ReadAndDeleteTransactionConflictException(NodeProxy.isDeletedInCurrentTransaction(_node), e); } if (Id() < 0) { writer.WriteVirtualNodeHack(_node); } writer.WriteNode(_node.Id, l, p); }
private void TreePanelEx_RemoteMove(object sender, RemoteMoveEventArgs e) { if (!EnableEdit) { return; } try { string[] source = e.Nodes.ToArray(); string targetNodeID = e.TargetNodeID; if (source.Contains <string>(targetNodeID)) { throw new ArgumentException("不能移动到自身"); } int target = Convert.ToInt32(targetNodeID); this._nodeHelper.ChangeParent(source, target); //int num2 = this._nodeHelper.GetItemLevel(target) + 1; foreach (string str2 in source) { NodeProxy nodeById = this.GetNodeById(str2); nodeById.Set("ParentId", target); // nodeById.Set("Level", num2); } e.Accept = true; } catch (ArgumentException exception) { this.ShowError(exception.Message, e); } catch (DbException exception2) { this.ShowError(exception2.Message, e); } }
/// <summary> /// Stores the (key, value) pair at the closest node, observed to the key that did not return the value. /// </summary> private void ReplicateLookup() { IContact closestNode = _shortList .OrderBy(x => Node.Distance(x.NodeId, _key)) .FirstOrDefault(x => !x.Equals(_valueFoundAt)); if (closestNode == null) { return; } try { IItem item = new Item(_valueFoundAt); using (NodeProxy nodeProxy = new NodeProxy(_owner, closestNode, false)) { nodeProxy.Context.Store(_key, new List <IItem> { item }); } } catch (Exception ex) { _owner.PingContact(closestNode); if (!Kernel.Exceptions.Exception.IsEndpointDown(ex)) { Log.Error(ex); } } }
void NotifyReload(NodeProxy proxy, bool reloadChildren) { if (proxy != null) { Reload?.Invoke(this, new ReloadEventArgs(proxy, reloadChildren)); } }
protected override void Run() { try { var req = new UpdateNodeRefreshCommandQueueStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Web, RefreshStatus = RefreshCommandQueueStatus.Refreshing, MonitorClassName = this.GetType().Name }; var r = NodeProxy.PostToServer <EmptyResponse, UpdateNodeRefreshCommandQueueStatusRequest>(ProxyUrl.UpdateNodeRefreshCmdQueueStatus_Url, req); if (r.Status != ResponesStatus.Success) { string title = "节点(编号):" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + ")上报监听命令状态失败,请及时处理!"; StringBuilder strContent = new StringBuilder(); strContent.AppendLine("请求地址:" + ProxyUrl.UpdateNodeRefreshCmdQueueStatus_Url + "<br/>"); strContent.AppendLine("请求参数:" + JsonConvert.SerializeObject(req) + "<br/>"); strContent.AppendLine("响应结果:" + JsonConvert.SerializeObject(r) + "<br/>"); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, title, strContent.ToString()); LogProxy.AddNodeErrorLog(strContent.ToString()); } } catch (Exception ex) { LogProxy.AddNodeErrorLog("节点(" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + ")" + ")监听命令队列监控异常:" + ex.Message + ",异常:" + JsonConvert.SerializeObject(ex)); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + ")" + ")监听命令队列监控异常", JsonConvert.SerializeObject(ex)); } }
protected override void Run() { var res = NodeProxy.PostToServer <EmptyResponse, UpdateNodeMonitorRequest>(ProxyUrl.UpdateNodeMonitorRequest_Url, new UpdateNodeMonitorRequest() { MonitorClassName = this.GetType().Name, MonitorStatus = (int)MonitorStatus.Monitoring, NodeId = GlobalNodeConfig.NodeID, Source = Source.Node }); if (res.Status != ResponesStatus.Success) { LogProxy.AddNodeErrorLog(this.GetType().Name + "监控组件上报监控信息失败,请求地址:" + ProxyUrl.UpdateNodeMonitorRequest_Url + ",返回结果:" + JsonConvert.SerializeObject(res)); } foreach (var taskruntimeinfo in TaskPoolManager.CreateInstance().GetList()) { try { if (taskruntimeinfo == null) { continue; } string fileinstallpath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalNodeConfig.TaskDllDir + @"\" + taskruntimeinfo.TaskModel.id; double dirsizeM = -1; if (System.IO.Directory.Exists(fileinstallpath)) { long dirsize = IOHelper.DirSize(new DirectoryInfo(fileinstallpath)); dirsizeM = (double)dirsize / 1024 / 1024; } try { if (taskruntimeinfo.Domain != null) { //上报性能 AddPerformanceRequest addperformance = new AddPerformanceRequest() { NodeId = GlobalNodeConfig.NodeID, Cpu = taskruntimeinfo.Domain.MonitoringTotalProcessorTime.TotalSeconds.ToString(), Memory = ((double)taskruntimeinfo.Domain.MonitoringSurvivedMemorySize / 1024 / 1024).ToString(),//AppDomain当前正在使用的字节数(只保证在上一次垃圾回收时是准确的) InstallDirsize = dirsizeM.ToString(), TaskId = taskruntimeinfo.TaskModel.id, Lastupdatetime = (DateTime.Now).ToString(), Source = Source.Node, }; var r = NodeProxy.PostToServer <EmptyResponse, AddPerformanceRequest>(ProxyUrl.AddPerformance_Url, addperformance); if (r.Status != ResponesStatus.Success) { LogProxy.AddTaskErrorLog("任务性能上报出错,请求地址:" + ProxyUrl.AddPerformance_Url + ",请求内容:" + JsonConvert.SerializeObject(addperformance) + ",返回结果:" + JsonConvert.SerializeObject(r), taskruntimeinfo.TaskModel.id); } } } catch (Exception ex) { LogProxy.AddTaskErrorLog("任务性能监控时出错:taskid=" + taskruntimeinfo.TaskModel.id + ",异常信息:" + JsonConvert.SerializeObject(ex), taskruntimeinfo.TaskModel.id); } } catch (Exception exp) { LogProxy.AddNodeErrorLog("任务性能监控异常,异常信息:" + JsonConvert.SerializeObject(exp)); } } }
public CollectionOutlineViewDataSource(TreeNode root) { if (root == null) { throw new ArgumentNullException(nameof(root)); } this.root = BindOutlineViewNode(root); }
private void playVideoMenuItem_Click(object sender, RoutedEventArgs e) { MetadataContext videoSourceKey = new MetadataContext() { MetadataName = "Video.Source", NodeUid = NodeProxy.Id }; string source = NodeProxy.GetNodeMetadata(videoSourceKey).MetadataValue; VideoSizeHelper sizeHelper = new VideoSizeHelper(NodeProxy); RelatedContentPanelUtil.Instance.LoadRelatedVideoContent(source, sizeHelper.Size); string startPosition = null; string endPosition = null; Command playCommand = new Command(); playCommand.Name = "Play"; playCommand.Params = new List <Param>(); playCommand.Params.Add(new Param() { Name = "Source", Value = source }); MetadataContext videoStartKey = new MetadataContext() { MetadataName = "Video.StartPosition", NodeUid = NodeProxy.Id }; if (NodeProxy.HasMetadata(videoStartKey)) { startPosition = NodeProxy.GetNodeMetadata(videoStartKey).MetadataValue; playCommand.Params.Add(new Param() { Name = "StartTimeCode", Value = startPosition }); } MetadataContext videoEndKey = new MetadataContext() { MetadataName = "Video.EndPosition", NodeUid = NodeProxy.Id }; if (NodeProxy.HasMetadata(videoEndKey)) { endPosition = NodeProxy.GetNodeMetadata(videoEndKey).MetadataValue; playCommand.Params.Add(new Param() { Name = "EndTimeCode", Value = endPosition }); } playCommand.Params.Add(new Param() { Name = "NodeId", Value = NodeProxy.Id.ToString() }); //Utilities.SendMessage<Command>(MessageSender, playCommand); }
protected override void Run() { try { var res = NodeProxy.PostToServer <EmptyResponse, UpdateNodeMonitorRequest>(ProxyUrl.UpdateNodeMonitorRequest_Url, new UpdateNodeMonitorRequest() { MonitorClassName = this.GetType().Name, MonitorStatus = (int)MonitorStatus.Monitoring, NodeId = GlobalNodeConfig.NodeID, Source = Source.Node }); if (res.Status != ResponesStatus.Success) { LogProxy.AddNodeErrorLog(this.GetType().Name + "监控组件上报监控信息失败,请求地址:" + ProxyUrl.UpdateNodeMonitorRequest_Url + ",返回结果:" + JsonConvert.SerializeObject(res)); } LoadTaskIdListRequest req = new LoadTaskIdListRequest() { Source = Source.Node, TaskScheduleStatus = (int)TaskScheduleStatus.Scheduling, NodeId = GlobalNodeConfig.NodeID }; var r = NodeProxy.PostToServer <LoadTaskIdListResponse, LoadTaskIdListRequest>(ProxyUrl.LoadTaskIdList_Url, req); List <int> taskschdulinglist = TaskPoolManager.CreateInstance().GetList().Select(x => x.TaskModel.id).ToList(); if (r.Status != ResponesStatus.Success) { //如果服务端没有调度中的,则把本地在调度中的上报状态 if (taskschdulinglist.Count > 0) { UploadLocalTask(taskschdulinglist); } return; } List <int> taskidnotserver = taskschdulinglist.Where(x => !(r.Data.TaskIdList.Contains(x))).ToList(); r.Data.TaskIdList.ForEach(x => { var taskruntimeInfo = TaskPoolManager.CreateInstance().Get(x.ToString()); if (taskruntimeInfo == null)//如果等于空值则报警,说明该任务再 { string title = "节点(id):" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + "),任务id:(" + x + ")" + ",调度异常,请及时处理!"; StringBuilder strContent = new StringBuilder(); strContent.AppendLine("所在节点名称(编号):" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeID + ")<br/>"); strContent.AppendLine("任务编号:" + x + "<br/>"); strContent.AppendLine("服务端任务状态:调度中<br/>"); strContent.AppendLine("节点端任务状态:任务池中已不存在该任务,调度异常<br/>"); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, title, strContent.ToString()); LogProxy.AddNodeErrorLog(strContent.ToString()); } }); if (taskidnotserver.Count > 0) { UploadLocalTask(taskidnotserver); } } catch (Exception ex) { LogProxy.AddNodeErrorLog("节点(" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + ")" + ")监控调度中任务异常:" + ex.Message + ",异常:" + JsonConvert.SerializeObject(ex)); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeInfo.nodename + "(" + GlobalNodeConfig.NodeInfo.id.ToString() + ")" + ")监控调度中任务异常", JsonConvert.SerializeObject(ex)); } }
/// <summary> /// 扫描命令队列并添加到任务池 /// </summary> private static void ScanCommandAndExecute() { //1.扫描分配给该节点的任务命令(读库或者直接读webapi) //2.遍历命令集合,并从命令池中找寻命令并执行,执行成功,更新命令队列,执行失败也更新命令状态 var r = NodeProxy.PostToServer <LoadCommandQueueListResponse, LoadCommandQueueListRequest>(ProxyUrl.LoadCommandQueueList_Url, new LoadCommandQueueListRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, LastMaxId = lastMaxID }); if (r.Status != ResponesStatus.Success) { onInitTaskPool("读取命令失败,服务器返回:" + JsonConvert.SerializeObject(r)); return; } if (r.Data.CommandQueueList.Count > 0) { onInitTaskPool("当前节点扫描到" + r.Data.CommandQueueList.Count + "条命令,并执行中"); } foreach (var item in r.Data.CommandQueueList) { try { CommandPoolManager.CreateInstance().Get(item.commanddetailid.ToString()).commandBase.Execute(); //更新命令队列节点状态 var r2 = NodeProxy.PostToServer <EmptyResponse, UpdateCommandQueueStatusRequest>(ProxyUrl.UpdateCommandQueueStatus_Url, new UpdateCommandQueueStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, CommandQueueId = item.id, CommandStatus = CommandQueueStatus.ExecuteSuccess }); if (r2.Status != ResponesStatus.Success) { onInitTaskPool("更新命令状态(成功)失败,服务器返回:" + JsonConvert.SerializeObject(r)); //记录节点错误日志 return; } //更新命令状态为成功 onInitTaskPool(string.Format("当前节点执行命令成功! id:{0},命令名:{1},命令参数:{2}", item.id, item.commandmainclassname, item.commandparams)); } catch (Exception ex) { //更新命令状态为错误 var r2 = NodeProxy.PostToServer <EmptyResponse, UpdateCommandQueueStatusRequest>(ProxyUrl.UpdateCommandQueueStatus_Url, new UpdateCommandQueueStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, CommandQueueId = item.id, CommandStatus = CommandQueueStatus.ExecuteError }); if (r2.Status != ResponesStatus.Success) { onInitTaskPool("执行节点命令异常,更新命令状态为错误,服务器返回:" + JsonConvert.SerializeObject(r)); //记录节点错误日志 return; } //添加任务执行失败日志 onInitTaskPool("执行节点命令异常:任务id:" + item.taskid + ",命令名称:" + item.commandmainclassname + "(" + item.id + ")", ex); } } }
public bool TryGetProxyNode(TreeNode node, out NodeProxy proxy) { if (node == null) { proxy = null; return(false); } return(nodeCache.TryGetValue(node, out proxy)); }
public ReloadEventArgs(NodeProxy item, bool reloadChildren) { if (item == null) { throw new ArgumentNullException(nameof(item)); } Item = item; ReloadChildren = reloadChildren; }
/// <summary> /// Replicates the given key and value at the closest nodes. /// </summary> /// <param name="key"></param> /// <param name="items"></param> /// <param name="closestNodesSelector"></param> private void Replicate(string key, IEnumerable <IItem> items, Func <IEnumerable <IContact> > closestNodesSelector) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (items == null) { throw new ArgumentNullException("items"); } if (closestNodesSelector == null) { throw new ArgumentNullException("closestNodesSelector"); } List <IItem> itemsToReplicate = items.Where(x => !x.IsExpired).ToList(); if (!itemsToReplicate.Any()) { return; } IEnumerable <IContact> closestNodes = closestNodesSelector(); if (closestNodes == null) { return; } foreach (IContact closestNode in closestNodes) { if (closestNode.Equals(_owner.Contact)) { continue; } try { using (NodeProxy nodeProxy = new NodeProxy(_owner, closestNode, false)) { nodeProxy.Context.Store(key, itemsToReplicate); } } catch (Exception ex) { _owner.PingContact(closestNode); if (!Kernel.Exceptions.Exception.IsEndpointDown(ex)) { Log.Error(ex); } } } }
/// <summary> /// 构建命令池 /// </summary> public void BuildCommandPool() { try { //读取库中命令,然后反射创建对象,封装命令运行时信息,并添加到命令池中 var r = NodeProxy.PostToServer <LoadCommandListResponse, LoadCommandListRequest>(ProxyUrl.LoadCommandList_Url, new LoadCommandListRequest() { NodeId = GlobalNodeConfig.NodeID.ToString(), Source = Source.Node }); if (r.Status != ResponesStatus.Success) { onInit("读取命令失败,服务器返回:" + JsonConvert.SerializeObject(r)); return; } if (r.Data.CommandLibDetailList.Count <= 0) { onInit("读取到0条命令,无法构建命令池"); return; } int commandCount = r.Data.CommandLibDetailList.Count; onInit("读取到" + commandCount.ToString() + "条命令"); onInit("开始创建命令对象,并添加到命令池"); int sucess = 0; int failed = 0; foreach (var item in r.Data.CommandLibDetailList) { try { var cmdruntime = CommandFactory.Create(item); if (cmdruntime != null) { CommandPoolManager.CreateInstance().Add(item.id.ToString(), cmdruntime); sucess += 1; } else { onInit("命令:" + item.commandname + "(" + item.id.ToString() + "),添加到命令池失败!创建命令对象为null"); failed += 1; } } catch (Exception ex) { onInit("命令:" + item.commandname + "(" + item.id.ToString() + "),添加到命令池失败!", ex); failed += 1; } } onInit("构建命令池完成,命令总数量:" + commandCount + ",成功数量:" + sucess.ToString() + ",失败数量:" + failed.ToString()); } catch (Exception ex) { onInit("命令池构建失败:" + ex.Message, ex); } }
/// <summary> /// Builds out the nodes and descriptors on the client side. Adds to a _cachedNodes list and keeps it updated. /// </summary> /// <param name="relatedNodesResult"></param> /// <returns></returns> private List <INodeProxy> BuildNodeList(RelatedNodesSearchResult relatedNodesResult) { List <INodeProxy> nodes = new List <INodeProxy>(); if (relatedNodesResult.Nodes.Count > 0) { foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values) { if (_cachedNodes.ContainsKey(soapNode.Id)) { _cachedNodes.Remove(soapNode.Id); } NodeProxy node = new NodeProxy(soapNode); _cachedNodes.Add(soapNode.Id, node); } foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values) { foreach (SoapRelationship relationship in soapNode.Relationships.Values) { RelationshipProxy relationshipProxy = new RelationshipProxy(relationship); foreach (DescriptorProxy descriptor in relationshipProxy.Descriptors) { if (_cachedNodes.ContainsKey(descriptor.NodeId)) { INodeProxy connectedNode = _cachedNodes[descriptor.NodeId]; descriptor.Node = connectedNode; if (!connectedNode.Descriptors.Contains(descriptor)) { connectedNode.Descriptors.Add(descriptor); } } } } } foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values) { nodes.Add(_cachedNodes[soapNode.Id]); } foreach (INodeProxy nodeProxy in nodes) { foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors) { CompleteRelationship(descriptorProxy.Relationship); } } } return(nodes); }
/// <summary> /// 上报任务调度状态 /// </summary> /// <param name="taskid"></param> /// <param name="taskversionid"></param> /// <param name="status"></param> private void UploadStatus(string taskid, string taskversionid, TaskScheduleStatus status, string nextruntime = "") { var req2 = new UpdateTaskScheduleStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, ScheduleStatus = status, TaskId = int.Parse(taskid), TaskVersionId = int.Parse(taskversionid), NextRunTime = nextruntime }; var r3 = NodeProxy.PostToServer <EmptyResponse, UpdateTaskScheduleStatusRequest>(ProxyUrl.UpdateTaskScheduleStatus_Url, req2); if (r3.Status != ResponesStatus.Success) { ShowCommandLog("更新任务调度状态(" + status.description() + ")失败,请求Url:" + ProxyUrl.UpdateTaskScheduleStatus_Url + ",请求参数:" + JsonConvert.SerializeObject(req2) + ",返回参数:" + JsonConvert.SerializeObject(r3)); } }
public void AddNode(string mapNodeId, string nodeTypeName, double x, double y) { INodeProxy nodeProxy = new NodeProxy(); nodeProxy.Id = Guid.NewGuid().ToString(); INodeProxy parentNode = _cachedNodes[mapNodeId]; nodeProxy.ParentNodes = new INodeProxy[1] { parentNode }; nodeProxy.Properties.Add("XPosition", x.ToString()); nodeProxy.Properties.Add("YPosition", y.ToString()); nodeProxy.NodeType = IoC.IoCContainer.GetInjectionInstance().GetInstance <NodeTypeManager>().GetNodeType(nodeTypeName); _localNewNodes.Add(nodeProxy.Id, nodeProxy); _cachedNodes.Add(nodeProxy.Id, nodeProxy); }
///// <summary> ///// 上一次日志扫描的最大id ///// </summary> //public static int lastMaxID = -1; #region 开启任务扫描 /// <summary> /// 开启任务扫描 /// </summary> /// <returns></returns> public override bool StartScanCommandQueue() { //1.扫描分配给该节点的任务命令(读库或者直接读webapi) //2.遍历命令集合,并从命令池中找寻命令并执行,执行成功,更新命令队列,执行失败也更新命令状态 var r = NodeProxy.PostToServer <LoadCommandQueueListResponse, LoadCommandQueueListRequest>(ProxyUrl.LoadCommandQueueList_Url, new LoadCommandQueueListRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, LastMaxId = GlobalNodeConfig.NodeInfo.lastmaxid, CommandStatus = (int)Model.enums.ExecuteStatus.NoExecute }); if (r.Status != ResponesStatus.Success) { onScanMsg("读取命令失败,服务器返回:" + JsonConvert.SerializeObject(r)); return(false); } int sucess = 0; int failed = 0; List <string> cmdQueueIdList = new List <string>(); r.Data.CommandQueueList.ForEach(x => cmdQueueIdList.Add(x.id.ToString())); if (r.Data.CommandQueueList.Count > 0) { onScanMsg("当前节点扫描到" + r.Data.CommandQueueList.Count + "条命令(" + string.Join(",", cmdQueueIdList.ToArray()) + "),并执行中"); } foreach (var item in r.Data.CommandQueueList) { try { GlobalNodeConfig.NodeInfo.lastmaxid = item.id > GlobalNodeConfig.NodeInfo.lastmaxid ? item.id : GlobalNodeConfig.NodeInfo.lastmaxid; CommandPoolManager.CreateInstance().Get(item.commanddetailid.ToString()).commandBase.CommandQueue = item; CommandPoolManager.CreateInstance().Get(item.commanddetailid.ToString()).commandBase.TryExecute(); sucess += 1; //更新命令状态为成功 onScanMsg(string.Format("当前节点执行命令成功! id:{0},命令名:{1},命令参数:{2}", item.id, item.commandmainclassname, item.commandparams)); } catch (Exception ex) { failed += 1; //添加任务执行失败日志 onScanMsg("执行节点命令异常:任务id:" + item.taskid + ",命令名称:" + item.commandmainclassname + "(" + item.id + ")", ex); } } onScanMsg("当前循环扫描命令队列完成,保存上次最大命令队列id值:" + GlobalNodeConfig.NodeInfo.lastmaxid + ",扫描到命令个数:" + r.Data.CommandQueueList.Count + ",执行成功个数:" + sucess + ",执行失败个数:" + failed); return(true); }
/// <summary> /// 执行 /// </summary> public override RunCommandResult Execute() { try { RefreshCommandQueueStatus refreshStatus = RefreshCommandQueueStatus.Refreshing; if (CommandQueueScanManger.IsStopCommandQueue()) { refreshStatus = RefreshCommandQueueStatus.NoRefresh; } else { bool isStop = CommandQueueScanManger.StopScanCommandQueue(); if (isStop) { refreshStatus = RefreshCommandQueueStatus.NoRefresh; } else { refreshStatus = RefreshCommandQueueStatus.Refreshing; } } var r = NodeProxy.PostToServer <EmptyResponse, UpdateNodeRefreshCommandQueueStatusRequest>(ProxyUrl.UpdateNodeRefreshCmdQueueStatus_Url, new UpdateNodeRefreshCommandQueueStatusRequest() { NodeId = int.Parse(this.AppConfig["nodeid"]), Source = (Source)int.Parse(this.AppConfig["source"]), RefreshStatus = refreshStatus }); if (r.Status != ResponesStatus.Success) { ShowCommandLog("停止节点刷新命令队列失败,服务器返回:" + JsonConvert.SerializeObject(r)); } //添加日志 ShowCommandLog("停止节点刷新命令队列成功"); return(new RunCommandResult() { ExecuteStatus = ExecuteStatus.ExecuteSucess }); } catch (Exception ex) { ShowCommandLog("停止节点刷新命令队列失败,异常信息:" + JsonConvert.SerializeObject(ex)); return(new RunCommandResult() { ExecuteStatus = ExecuteStatus.ExecuteException, Ex = ex, Message = ex.Message }); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { foreach (MetadataViewModel metadata in _metadata.Where(md => md.OriginalMetadataName != md.MetadataName)) { NodeProxy.RenameNodeMetadata(metadata.GetContext(), metadata.MetadataName); _metadataNames.Remove(metadata.OriginalMetadataName); _metadataNames.Add(metadata.MetadataName); metadata.UpdateName(); } if (HasChanges) { TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance <TypeManager>(); IMetadataTypeProxy[] metaDataTypes = typeManager.GetAllMetadataTypes(); foreach (KeyValuePair <string, bool> changedMetadata in _changes.Where(changed => changed.Value == true)) { //only update the changed items try { MetadataViewModel metadata = _metadata.Single(m => m.MetadataName.ToLower() == changedMetadata.Key.ToLower()); if (metadata != null) { NodeProxy.SetNodeMetadata(metadata.GetContext(), metadata.MetadataValue, metaDataTypes.Single(md => md.Id == metadata.MetadataTypeUid)); } } catch (Exception) { //ignore any errors if the changed metadata isn't found } } _changes.Clear(); foreach (MetadataViewModel deletedItem in _deletedItems) { NodeProxy.DeleteNodeMetadata(deletedItem.GetContext()); } _deletedItems.Clear(); } SaveButton.IsEnabled = false; ResetOriginals(); ClearChangeIndicator(); }
NodeProxy BindOutlineViewNode(TreeNode node) { if (node == null) { return(null); } NodeProxy nsNode; if (!TryGetProxyNode(node, out nsNode)) { nsNode = new NodeProxy(node); nodeCache.Add(node, nsNode); StartMonitoringNode(node); } return(nsNode); }
private void propertiesMenuItem_Click(object sender, RoutedEventArgs e) { NodePropertiesDialog npd = new NodePropertiesDialog(); npd.DataContext = NodeProxy; MetadataContext noteKey = new MetadataContext() { MetadataName = "Note", NodeUid = NodeProxy.Id }; if (NodeProxy.HasMetadata(noteKey)) { npd.Note = NodeProxy.GetNodeMetadata(noteKey).MetadataValue; } npd.Closed += new EventHandler(NodePropertiesDialog_Close); npd.Show(); }
private void UploadLocalTask(List <int> taskidnotserver) { taskidnotserver.ForEach(x => { var taskruntimeInfo = TaskPoolManager.CreateInstance().Get(x.ToString()); //上报所在在本地节点运行的任务,但是在服务端未在调度中,更新服务端的任务调度状态为调度中 var req2 = new UpdateTaskScheduleStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, ScheduleStatus = TaskScheduleStatus.Scheduling, TaskId = x, TaskVersionId = taskruntimeInfo.TaskVersionModel.id, NextRunTime = Convert.ToString(taskruntimeInfo.TaskModel.nextruntime) }; var r3 = NodeProxy.PostToServer <EmptyResponse, UpdateTaskScheduleStatusRequest>(ProxyUrl.UpdateTaskScheduleStatus_Url, req2); if (r3.Status != ResponesStatus.Success) { LogProxy.AddNodeErrorLog("任务id:" + x.ToString() + ",任务名称:" + taskruntimeInfo.TaskModel.taskname + ",在服务端为停止调度状态,在本地节点下为调度中。上报本地节点下的任务状态(调度中)失败"); // ShowCommandLog("更新任务调度状态(" + status.description() + ")失败,请求Url:" + ProxyUrl.UpdateTaskScheduleStatus_Url + ",请求参数:" + JsonConvert.SerializeObject(req2) + ",返回参数:" + JsonConvert.SerializeObject(r3)); } }); }
private void GetNodeByIdAsyncCompleted(object sender, GetNodesCompletedEventArgs e) { List<INodeProxy> nodes = new List<INodeProxy>(); foreach (SoapNode soapNode in e.Result.Values) { NodeProxy node = new NodeProxy(soapNode); nodes.Add(node); _cachedNodes.Add(node.Id, node); } ReturnedNodesEventArgs eventArgs = new ReturnedNodesEventArgs(null, nodes.ToArray()); if (GetNodeByIdCompleted != null) { GetNodeByIdCompleted.Invoke(this, eventArgs); } }
private void GetNodeByIdAsyncCompleted(object sender, GetNodesCompletedEventArgs e) { List <INodeProxy> nodes = new List <INodeProxy>(); foreach (SoapNode soapNode in e.Result.Values) { NodeProxy node = new NodeProxy(soapNode); nodes.Add(node); _cachedNodes.Add(node.Id, node); } ReturnedNodesEventArgs eventArgs = new ReturnedNodesEventArgs(null, nodes.ToArray()); if (GetNodeByIdCompleted != null) { GetNodeByIdCompleted.Invoke(this, eventArgs); } }
/// <summary> /// Pings the specified <see cref="IContact" />. /// </summary> /// <param name="contact"></param> void INode.PingContact(IContact contact) { if (contact == null) { throw new ArgumentNullException("contact"); } try { using (NodeProxy nodeProxy = new NodeProxy(this, contact, false)) { nodeProxy.Context.Ping(); } } catch (Exception) { (this as INode).BucketContainer.Remove(contact); } }
private void NodePropertiesDialog_Loaded(object sender, RoutedEventArgs e) { NodeProxy = DataContext as INodeProxy; if (NodeProxy != null) { _originalName = NodeProxy.Name; _originalNote = Note; //make a copy to restore closing if (Note != null) { NodeNotesTextBlock.Text = Note; } NodeNotesTextBlock.Focus(); NodeNotesTextBlock.SelectionStart = NodeNotesTextBlock.Text.Length; if (NodeProxy.Created != DateTime.MinValue) { CreatedTimeTextBlock.Text = NodeProxy.Created.ToString("f"); } if (NodeProxy.LastModified != DateTime.MinValue) { ModifiedTimeTextBlock.Text = NodeProxy.LastModified.ToString("f"); } if (NodeProxy.NodeType.Name == "CompendiumReferenceNode") { MetadataContext context = new MetadataContext() { NodeUid = NodeProxy.Id, MetadataName = "LinkedFile.Source" }; if (NodeProxy.HasMetadata(context)) { Height = 480; ReferenceLocationRow.Height = new GridLength(30); ReferenceNodeInfoPanel.Visibility = System.Windows.Visibility.Visible; SoapMetadata linkedFileMetadata = NodeProxy.GetNodeMetadata(context); ReferenceFileLocationTextBox.Text = linkedFileMetadata.MetadataValue; } } } }
private void OnAddNodeAsyncCompleted(object sender, AddNodeCompletedEventArgs e) { if (e.Error == null) { SoapNode soapNode = e.Result; INodeProxy nodeProxy = new NodeProxy(soapNode); if (AddNodeCompleted != null) { Point location = new Point(0, 0); if (e.UserState != null) { location = ((MapLocationState)e.UserState).Location; } AddedNodeEventArgs anea = new AddedNodeEventArgs(nodeProxy, location); AddNodeCompleted.Invoke(sender, anea); } } }
protected override void Run() { try { var r = NodeProxy.PostToServer <EmptyResponse, UpdateNodeHeatbeatRequest>(ProxyUrl.UpdateNodeHeatbeat_Url, new UpdateNodeHeatbeatRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, MonitorClassName = this.GetType().Name }); if (r.Status != ResponesStatus.Success) { LogProxy.AddNodeErrorLog("上报心跳失败,请求地址:" + ProxyUrl.UpdateNodeHeatbeat_Url + ",返回内容:" + JsonConvert.SerializeObject(r)); } } catch (Exception ex) { string msg = "上传心跳异常,信息:" + ex.Message + ",异常:" + JsonConvert.SerializeObject(ex); LogProxy.AddNodeErrorLog(msg); } }
private void OnAddNodeAsyncCompleted(object sender, AddNodeCompletedEventArgs e) { if (e.Error == null) { SoapNode soapNode = e.Result; INodeProxy nodeProxy = new NodeProxy(soapNode); if (AddNodeCompleted != null) { Point location = new Point(0, 0); if (e.UserState != null) { location = ((MapLocationState)e.UserState).Location; } AddedNodeEventArgs anea = new AddedNodeEventArgs(nodeProxy, location); AddNodeCompleted.Invoke(sender, anea); } } }
public void Stop() { try { OnInit("----------------------" + DateTime.Now + ":停止节点开始-----------------------------------------"); //1.停止所有监控扫描 GlobalNodeConfig.Monitors.ForEach(x => { x.CancelRun(); }); OnInit(DateTime.Now + ":监控停止完成"); //2.停止刷新命令队列 CommandQueueScanManger.StopScanCommandQueue(); OnInit(DateTime.Now + ":停止命令队列监听完成"); //刷新节点运行状态 var r2 = NodeProxy.PostToServer <EmptyResponse, UpdateNodeStatusRequest>(ProxyUrl.UpdateNodeStatus_Url, new UpdateNodeStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, NodeStatus = Model.enums.NodeStatus.NoRun }); if (r2.Status != ResponesStatus.Success) { string msg = "更新节点运行状态失败,请求地址:" + ProxyUrl.UpdateNodeStatus_Url + ",服务器返回参数:" + JsonConvert.SerializeObject(r2); OnInit(msg); AlarmHelper.Alarm(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")停止,更新运行状态失败", msg); } AlarmHelper.Alarm(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")停止,请及时处理", DateTime.Now + ":当前节点(" + GlobalNodeConfig.NodeID.ToString() + ")已停止运行,如正常停止请忽略此预警"); OnInit("节点服务停止"); } catch (Exception ex) { string exemsg = "节点停止异常:" + JsonConvert.SerializeObject(ex); OnInit(exemsg); AlarmHelper.Alarm(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")停止异常,请及时处理!", exemsg + ",节点停止日志:" + strLog.ToString()); } finally { OnInit("----------------------" + DateTime.Now + ":停止节点结束-----------------------------------------"); LogProxy.AddNodeLog(strLog.ToString(), LogType.NodeStopLog); strLog.Clear(); } }
public void AddNode(string mapNodeId, string nodeTypeName, double x, double y) { INodeProxy nodeProxy = new NodeProxy(); nodeProxy.Id = Guid.NewGuid().ToString(); INodeProxy parentNode = _cachedNodes[mapNodeId]; nodeProxy.ParentNodes = new INodeProxy[1] { parentNode }; nodeProxy.Properties.Add("XPosition", x.ToString()); nodeProxy.Properties.Add("YPosition", y.ToString()); nodeProxy.NodeType = IoC.IoCContainer.GetInjectionInstance().GetInstance<NodeTypeManager>().GetNodeType(nodeTypeName); _localNewNodes.Add(nodeProxy.Id, nodeProxy); _cachedNodes.Add(nodeProxy.Id, nodeProxy); }
private void GetRelatedNodesByIdAsyncCompleted(object sender, GetRelatedNodesCompletedEventArgs e) { if (e.Error == null) { List<INodeProxy> nodes = new List<INodeProxy>(); foreach (SoapNode soapNode in e.Result.RelatedNodes.Values) { if (!_cachedNodes.ContainsKey(soapNode.Id)) { NodeProxy node = new NodeProxy(soapNode); _cachedNodes.Add(soapNode.Id, node); } } foreach (SoapNode soapNode in e.Result.RelatedNodes.Values) { INodeProxy node = _cachedNodes[soapNode.Id]; foreach (SoapRelationship relationship in soapNode.Relationships) { RelationshipProxy relationshipProxy = new RelationshipProxy(relationship); foreach (DescriptorProxy descriptor in relationshipProxy.Descriptors) { if (_cachedNodes.ContainsKey(descriptor.NodeId)) { INodeProxy connectedNode = _cachedNodes[descriptor.NodeId]; if (!connectedNode.Descriptors.Contains(descriptor)) { descriptor.Node = connectedNode; connectedNode.Descriptors.Add(descriptor); } } } } } INodeProxy nodeProxy = _cachedNodes[e.Result.SearchedNode.Id]; nodes.Add(nodeProxy); foreach (INodeProxy np in _localNewNodes.Values) { nodes.Add(np); } foreach (IDescriptorProxy descriptor in nodeProxy.Descriptors) { foreach (IDescriptorProxy alternateDescriptor in descriptor.Relationship.Descriptors) { if (!nodes.Contains(alternateDescriptor.Node)) { nodes.Add(alternateDescriptor.Node); } } } INodeProxy searchedNode = new NodeProxy(e.Result.SearchedNode); ReturnedNodesEventArgs eventArgs = new ReturnedNodesEventArgs(searchedNode, nodes.ToArray()); if (GetRelatedNodesByIdCompleted != null) { GetRelatedNodesByIdCompleted.Invoke(this, eventArgs); } } }
private void OnConnectNodesCompleted(object sender, ConnectNodesCompletedEventArgs e) { if (e.Error == null) { List<INodeProxy> nodes = new List<INodeProxy>(); ConnectedNodesResult connectResult = e.Result; foreach (SoapNode soapNode in connectResult.Nodes.Values) { if (_cachedNodes.ContainsKey(soapNode.Id)) { _cachedNodes.Remove(soapNode.Id); } NodeProxy node = new NodeProxy(soapNode); _cachedNodes.Add(soapNode.Id, node); nodes.Add(node); } foreach (INodeProxy nodeProxy in nodes) { foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors) { CompleteRelationship(descriptorProxy.Relationship); } } ConnectedNodesEventArgs connectedNodesEventArgs = new ConnectedNodesEventArgs(); connectedNodesEventArgs.Nodes = nodes.ToArray(); connectedNodesEventArgs.Relationship = new RelationshipProxy(e.Result.Relationship); CompleteRelationship(connectedNodesEventArgs.Relationship); //When a node is connected via a MapContainerRelationship the UserState will be the location of the new node //on the map, it can't be stored in the db until the relationship exists since it's the contectual relationship //that determines where it is located in it's view in this map (it may be elsewhere in transclusions) if (e.UserState != null) { INodeProxy nodeProxy = connectedNodesEventArgs.Nodes[1]; Point location = (Point)e.UserState; if (location != null) { TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance<TypeManager>(); IDescriptorTypeProxy descriptorType = null; if (e.Result.Relationship.RelationshipType.Name == "TransclusionRelationship") { descriptorType = typeManager.GetDescriptorType("TransclusionMap"); } else { descriptorType = typeManager.GetDescriptorType("From"); } MetadataContext xPositionKey = new MetadataContext() { NodeUid = nodeProxy.Id, RelationshipUid = e.Result.Relationship.Id, DescriptorTypeUid = descriptorType.Id, MetadataName = "XPosition" }; MetadataContext yPositionKey = new MetadataContext() { NodeUid = nodeProxy.Id, RelationshipUid = e.Result.Relationship.Id, DescriptorTypeUid = descriptorType.Id, MetadataName = "YPosition" }; if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(xPositionKey) != null) { nodeProxy.GetNodeMetadata(xPositionKey).MetadataValue = location.X.ToString(); } else { MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy; if (metaDataTypeProxy != null) { SoapMetadata soapMetadata = new SoapMetadata(); soapMetadata.MetadataName = "XPosition"; soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType; soapMetadata.MetadataValue = location.X.ToString(); nodeProxy.Metadata.Add(xPositionKey, soapMetadata); } } if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(yPositionKey) != null) { nodeProxy.GetNodeMetadata(yPositionKey).MetadataValue = location.Y.ToString(); } else { MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy; if (metaDataTypeProxy != null) { SoapMetadata soapMetadata = new SoapMetadata(); soapMetadata.MetadataName = "YPosition"; soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType; soapMetadata.MetadataValue = location.Y.ToString(); nodeProxy.Metadata.Add(yPositionKey, soapMetadata); } } } } if (ConnectNodesCompleted != null) { ConnectNodesCompleted.Invoke(this, connectedNodesEventArgs); } } }
/// <summary> /// Builds out the nodes and descriptors on the client side. Adds to a _cachedNodes list and keeps it updated. /// </summary> /// <param name="relatedNodesResult"></param> /// <returns></returns> private List<INodeProxy> BuildNodeList(RelatedNodesSearchResult relatedNodesResult) { List<INodeProxy> nodes = new List<INodeProxy>(); if (relatedNodesResult.Nodes.Count > 0) { foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values) { if (_cachedNodes.ContainsKey(soapNode.Id)) { _cachedNodes.Remove(soapNode.Id); } NodeProxy node = new NodeProxy(soapNode); _cachedNodes.Add(soapNode.Id, node); } foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values) { foreach (SoapRelationship relationship in soapNode.Relationships.Values) { RelationshipProxy relationshipProxy = new RelationshipProxy(relationship); foreach (DescriptorProxy descriptor in relationshipProxy.Descriptors) { if (_cachedNodes.ContainsKey(descriptor.NodeId)) { INodeProxy connectedNode = _cachedNodes[descriptor.NodeId]; descriptor.Node = connectedNode; if (!connectedNode.Descriptors.Contains(descriptor)) { connectedNode.Descriptors.Add(descriptor); } } } } } foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values) { nodes.Add(_cachedNodes[soapNode.Id]); } foreach (INodeProxy nodeProxy in nodes) { foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors) { CompleteRelationship(descriptorProxy.Relationship); } } } return nodes; }
private void OnUpdateNodeMetadataCompleted(object sender, UpdateNodeMetadataCompletedEventArgs e) { if (e.Error == null) { if (_cachedNodes.ContainsKey(e.Result.Id)) { _cachedNodes.Remove(e.Result.Id); } NodeProxy node = new NodeProxy(e.Result); _cachedNodes.Add(e.Result.Id, node); ReturnedNodesEventArgs returnedNodesEventArgs = new ReturnedNodesEventArgs(); returnedNodesEventArgs.Nodes = new INodeProxy[] { node }; if (UpdateNodeMetadataCompleted != null) { UpdateNodeMetadataCompleted.Invoke(this, returnedNodesEventArgs); } } }