public static MonitorValue FileCount(MonitorItem monitorItem) { string path = monitorItem.MonitorURL; MonitorValue output = new MonitorValue(); output.MonitorItemID = monitorItem.ID; output.MonitorTime = System.DateTime.Now; try { if (!Directory.Exists(path)) { output.Value = -1; } output.Value = Directory.GetFiles(path).Length; } catch (Exception e) { output.Value = -2; } return(output); }
//private void ZonalBudget_Click(object sender, EventArgs e) //{ //} public void Plot(MonitorItem item) { if (item == null) { return; } if (item.Monitor.DataSource == null) { return; } var dates = item.Monitor.DataSource.Dates.ToArray(); int step = dates.Length; if (step > 0) { if (item.Derivable) { item.DerivedValues = item.Derive(item.Monitor.DataSource); Chart.Plot <double>(dates, item.DerivedValues, item.Name, SeriesChartType.FastLine); } else { Chart.Plot <double>(dates, item.Monitor.DataSource.Values[item.VariableIndex].ToArray(), item.Name, SeriesChartType.FastLine); } } }
/// <summary> /// Gets a collection of system monitors /// </summary> /// <returns>Collection of MonitorItem</returns> public IEnumerable <MonitorItem> GetSystemMonitors() { Log.Logger.Information("Getting system monitors"); List <MonitorItem> result = new List <MonitorItem>(); var devices = DisplayDevices.ReadDisplayDevices().ToArray(); var displayScreens = GetDisplayScreens(devices); foreach (var screen in Screen.AllScreens) { var displayScreen = displayScreens?.SingleOrDefault(x => x.Item1.Equals(screen)); var deviceData = displayScreen?.Item2; var monitor = new MonitorItem { Monitor = screen, MonitorName = deviceData?.DeviceString ?? SanitizeScreenDeviceName(screen.DeviceName), MonitorId = deviceData?.DeviceId ?? screen.DeviceName, FriendlyName = screen.DeviceFriendlyName() }; if (string.IsNullOrEmpty(monitor.FriendlyName)) { monitor.FriendlyName = monitor.MonitorName; } result.Add(monitor); } return(result); }
public void AddItem(MonitorItem item) { if (item != null) { lock (trackLocker) { items[item] = placeHold; Monitor.Pulse(trackLocker); } } }
/// <summary> /// 保存设备型号 /// </summary> /// <param name="deviceModel"></param> /// <returns></returns> public int Save(MonitorItem monitorItem) { MonitorItem tmp = _monitorItemDao.Get(monitorItem); if (tmp != null) { return(_monitorItemDao.Update(monitorItem)); } else { return(_monitorItemDao.Insert(monitorItem)); } }
public ActionResult Edit(string id) { if (string.IsNullOrEmpty(id)) { return(View()); } MonitorItem dm = monitorItemService.Get(id); //取得大类型 ICollection <ProtocolType> protocolTypes = DeviceData.getProtocolTypeList(); ViewData["selectProtocolTypes"] = convertDomainListToSelectList(protocolTypes, dm.protocolTypeCode); return(View(@"edit", dm)); }
private void Init() { try { string strTitle = string.Format("{0} —— ", CurrentApp.GetLanguageInfo("2102016", "Screen Monitor")); if (MonitorData != null) { mMonitorItem = MonitorItem.CreateItem(MonitorData); mMonitorItem.CurrentApp = CurrentApp; mMonitorItem.ListUserParams = ListUserParams; mMonitorObject = new MonitorObject(); mMonitorObject.MonType = MonitorType.MonScr; mMonitorObject.ObjID = MonitorData.ObjID; mMonitorObject.ObjType = MonitorData.ObjType; mMonitorObject.ObjValue = MonitorData.Name; mMonitorObject.Role = 2; string strOther03 = MonitorData.Other03; if (!string.IsNullOrEmpty(strOther03)) { string[] arrOther03 = strOther03.Split(new[] { ';' }, StringSplitOptions.None); if (arrOther03.Length > 1) { mMonitorObject.Other03 = arrOther03[1]; } else if (arrOther03.Length > 0) { mMonitorObject.Other03 = arrOther03[0]; } } mMonitorItem.ScreenChanMonObject = mMonitorObject; Dispatcher.Invoke(new Action(mMonitorItem.UpdateState)); DataContext = mMonitorItem; strTitle += mMonitorItem.Name; ImageIcon.SetResourceReference(StyleProperty, string.Format("NMonImageIcon{0}Style", mMonitorItem.ObjType)); InitMonitorClient(); } TxtObjListTitle.Text = strTitle; } catch (Exception ex) { ShowException(ex.Message); } }
/// <summary> /// Gets a collection of system monitors /// </summary> /// <returns>Collection of MonitorItem</returns> public IEnumerable<MonitorItem> GetSystemMonitors() { Log.Logger.Information("Getting system monitors"); List<MonitorItem> result = new List<MonitorItem>(); var devices = DisplayDevices.ReadDisplayDevices().ToArray(); var displayScreens = GetDisplayScreens(devices); foreach (var screen in Screen.AllScreens) { var displayScreen = displayScreens?.SingleOrDefault(x => x.Item1.Equals(screen)); var deviceData = displayScreen?.Item2; var monitor = new MonitorItem { Monitor = screen, MonitorName = deviceData?.DeviceString ?? SanitizeScreenDeviceName(screen.DeviceName), MonitorId = deviceData?.DeviceId ?? screen.DeviceName, FriendlyName = screen.DeviceFriendlyName() }; if (string.IsNullOrEmpty(monitor.FriendlyName)) { monitor.FriendlyName = monitor.MonitorName; } result.Add(monitor); } result.Sort((x, y) => { var rv = string.Compare(x.FriendlyName, y.FriendlyName, StringComparison.InvariantCultureIgnoreCase); if (rv == 0) { rv = string.Compare(x.MonitorId, y.MonitorId, StringComparison.InvariantCultureIgnoreCase); } return rv; }); return result; }
public void AddMessageToPlay(string text) { if (!string.IsNullOrEmpty(text)) { if (text.StartsWith("<message")) { var voiceItem = (VoiceListItem)Activator.CreateInstance(MonitorItem.GetType()); voiceItem.Load(text); addVoiceListItem(voiceItem); } else { var item = new PlayItem(this) { Text = "SAPI XML", Xml = text, Status = JobStatusType.Parsed, }; lock (playlistLock) { playlist.Add(item); } } } }
/// <summary> /// Checks for valid request, then records the new monitor item /// </summary> /// <param name="version"></param> /// <param name="monitorItem"></param> /// <returns></returns> private IActionResult RecordMonitorItem(string version, MonitorItem monitorItem) { if (version.ToUpper() == "V1") { if (monitorItem.IsValid()) { _context.MonitorItems.Add(monitorItem); _context.SaveChanges(); // * write to console Console.WriteLine(monitorItem.ToString()); return(new ObjectResult(monitorItem.ToString())); } else { return(new ObjectResult(monitorItem.GetMsg())); } } else { return(new ObjectResult("ERROR - Version not supported")); } }
public IActionResult Create(string version, [FromBody] MonitorItem monitorItem) { return(RecordMonitorItem(version, monitorItem)); }
private void Wc_OnPacketArrival(object sender, CaptureEventArgs e) { if (Disposing || IsDisposed || !IsHandleCreated) { return; } if (e.Packet == null || e.Packet.Data == null || e.Packet.Data.Length == 0) { return; } if (e.Packet.LinkLayerType != LinkLayers.Ethernet) { return; } Packet packet = null; try { packet = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data); } catch (Exception) { return; } var ep = packet as EthernetPacket; if (ep == null) { return; } if (ep.Type != EthernetPacketType.IpV4 && ep.Type != EthernetPacketType.IpV6) { return; } var ip = ep.PayloadPacket as IpPacket; if (ip == null) { return; } var tp = ip.PayloadPacket as TcpPacket; if (tp == null) { return; } if (tp.PayloadData.Length == 0) { return; } IPAddress srcIp = ip.SourceAddress; IPAddress dstIp = ip.DestinationAddress; int srcPort = tp.SourcePort; int dstPort = tp.DestinationPort; BeginInvoke((Action)(() => { lock (PacketsStateStatusLabelLock) { if (ep.Type == EthernetPacketType.IpV6) { Ip6PacketsCount++; } else { Ip4PacketsCount++; } PacketsStatusLabel.Text = string.Format("Packets: {0} IPv4, {1} IPv6", Ip4PacketsCount, Ip6PacketsCount); } })); uint sequenceNumber = tp.SequenceNumber; // --------------------------------------------------------------------------- var sourceIsLocal = IpAddresses.Contains(ip.SourceAddress); var destinationIsLocal = IpAddresses.Contains(ip.DestinationAddress); var direction = TrafficDirection.Local; if (sourceIsLocal && !destinationIsLocal) { direction = TrafficDirection.Out; } else if (!sourceIsLocal && destinationIsLocal) { direction = TrafficDirection.In; } // IPHeader.Data stores the data being carried by the IP datagram. if (SettingsManager.Options.LogEnable) { var index = -1; if (OptionsPanel.SearchPattern != null && OptionsPanel.SearchPattern.Length > 0) { index = ClassLibrary.Text.Helper.IndexOf(tp.PayloadData, OptionsPanel.SearchPattern, 0); } if (index > -1) { // Play "Radio2" sound if "LogEnabled" and "LogSound" check-boxes are checked. if (SettingsManager.Options.LogSound) { var stream = GetIntroSound("Radio2"); if (stream != null) { var player = new AudioPlayer(Handle); player.ChangeAudioDevice(SettingsManager.Options.PlaybackDevice); player.Load(stream); player.Play(); } } // --------------------------------------------- var writer = OptionsPanel.Writer; if (writer != null) { writer.WriteLine("{0:HH:mm:ss.fff}: {1} {2}: {3}:{4} -> {5}:{6} Data[{7}]", DateTime.Now, ep.Type.ToString().ToUpper(), destinationIsLocal ? "In" : "Out", ip.SourceAddress, tp.SourcePort, ip.DestinationAddress, tp.DestinationPort, tp.PayloadData.Length ); var block = JocysCom.ClassLibrary.Text.Helper.BytesToStringBlock( ep.PayloadData, false, true, true); block = JocysCom.ClassLibrary.Text.Helper.IdentText(4, block, ' '); writer.WriteLine(block); writer.WriteLine(""); } } } // ------------------------------------------------------------ // If direction specified, but wrong type then return. if (MonitorItem.FilterDirection != TrafficDirection.None && direction != MonitorItem.FilterDirection) { return; } // If port is specified but wrong number then return. if (MonitorItem.FilterDestinationPort > 0 && tp.DestinationPort != MonitorItem.FilterDestinationPort) { return; } // If process name specified. if (!string.IsNullOrEmpty(MonitorItem.FilterProcessName)) { //var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); //var tcpListenters = ipGlobalProperties.GetActiveTcpListeners(); //var udpListenters = ipGlobalProperties.GetActiveUdpListeners(); //var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections(); //var myEnum = tcpConnInfoArray.GetEnumerator(); //while (myEnum.MoveNext()) //{ // var tcpInfo = (TcpConnectionInformation)myEnum.Current; // Console.WriteLine("Port {0} {1} {2} ", tcpInfo.LocalEndPoint, tcpInfo.RemoteEndPoint, tcpInfo.State); // //usedPort.Add(TCPInfo.LocalEndPoint.Port); //} } var pluginType = MonitorItem.GetType(); var voiceItem = (VoiceListItem)Activator.CreateInstance(pluginType); voiceItem.Load(ip, tp); // If data do not contain XML message then return. if (!voiceItem.IsVoiceItem) { return; } var allowToAdd = true; // If message contains sequence number... if (sequenceNumber > 0) { lock (SequenceNumbersLock) { // Cleanup sequence list by removing oldest numbers.. while (SequenceNumbers.Count > 10) { SequenceNumbers.RemoveAt(0); } // If number is not unique then... if (SequenceNumbers.Contains(sequenceNumber)) { // Don't allow to add the message. allowToAdd = false; } else { // Store sequence number for the future checks. SequenceNumbers.Add(sequenceNumber); } } } if (allowToAdd) { // If default capture filter. if (!IsDetailFilter) { // Restrict filter to improve speed. SetFilter(voiceItem, true); } // Add wow item to the list. Use Invoke to make it Thread safe. this.Invoke((Action <VoiceListItem>)addVoiceListItem, new object[] { voiceItem }); } }
public ActionResult Save(MonitorItem MonitorItem) { monitorItemService.Save(MonitorItem); return(RedirectToAction("list", "MonitorItem")); }