private List <_SubDevice> GetCollectionWithPerformance(List <_SubDevice> collection) { foreach (WprManagementObject mj in WmiCollection.All()) { var t = new SubDevice(); t.Name = mj.GetProperty("Name"); t.PercentProcessorTime = mj.GetProperty("PercentProcessorTime"); t.PercentofMaximumFrequency = mj.GetProperty("PercentofMaximumFrequency"); t.ProcessorFrequency = mj.GetProperty("ProcessorFrequency"); t.PercentProcessorPerformance = mj.GetProperty("PercentProcessorPerformance"); t.Extend(mjext); collection.Add(t); } return(collection); }
public static void Main(string[] args) { //Título - Utilizar PROMPT MAXIMIZADO!!! StreamReader z; string CaminhoT = "Ztitulo.txt"; z = File.OpenText(CaminhoT); while (z.EndOfStream != true) { string linha = z.ReadLine(); Console.WriteLine(linha); } z.Close(); ListControl error = new ListControl(); bool chave = true; do { //Entrada dos dados pelo usuário Console.Write("Deseja cadastrar uma novo Dispositivo? S/N "); string cad = Console.ReadLine().ToUpper(); if (cad == "S" || cad == "SIM") { Console.Write("Digite a Marca: "); string marca = Console.ReadLine(); Console.Write("Digite o Modelo: "); string modelo = Console.ReadLine(); Console.Write("Digite a Service Tag: "); string stag = Console.ReadLine(); Console.Write("Digite o Tipo: "); string tipo = Console.ReadLine(); Console.Write("Digite o Responsável: "); string responsaveldisp = Console.ReadLine(); //Tratamento de exceções bool invalido = true; int matricularesp = 0; do { try { Console.Write("Digite a Matrícula do Responsável: "); matricularesp = int.Parse(Console.ReadLine()); invalido = false; } catch (FormatException) { Console.WriteLine("Matrícula deve ser apenas NÚMEROS! Favor inserir novamente!"); invalido = true; } }while (invalido); //Trabalhando com arquivo .txt StreamWriter x; string CaminhoNome = "Zdados.txt"; x = File.AppendText(CaminhoNome); //Salvando dados no arquivo; ListControl.AddSubDevice(new SubDevice(marca, modelo, stag, tipo, responsaveldisp, matricularesp)); List <SubDevice> Subdevices = ListControl.getListaSubDevice(); foreach (SubDevice subdevice in Subdevices) { x.WriteLine(subdevice.Imprimir().ToUpper()); } x.Close(); } else if (cad == "N" || cad == "NAO") { chave = false; SubDevice person = new SubDevice("Param1", "Param2", "Param3", "Param4", "Param5", 1230); } else { error.Exception(); } }while(chave); //Imprimir na tela os Dispostivos disponíveis; Console.WriteLine(); Console.Write("Deseja verificar o banco de Dispostivos? S/N "); string buscadisp = Console.ReadLine().ToUpper(); Console.WriteLine(); if (buscadisp == "SIM" || buscadisp == "S") { StreamReader y; Console.WriteLine(); Console.WriteLine("LISTA DE DISPOSITIVOS"); Console.WriteLine(); string Caminho = "Zdados.txt"; y = File.OpenText(Caminho); while (y.EndOfStream != true) { string linha = y.ReadLine(); Console.WriteLine(linha); } y.Close(); Console.WriteLine(); Console.Write("********PROGRAMA FINALIZADO*********"); } if (buscadisp == "NAO" || buscadisp == "N") { Console.Write("********PROGRAMA FINALIZADO*********"); } //usando tratamento de exceções if (buscadisp != "N" && buscadisp != "S") { error.Exception(); } }
/// <summary> /// Media Browser Constructor /// ,fills the devices properties and values with default values /// </summary> public MediaBrowser() { device_type = DeviceTypes.MediaBrowser; //host = ""; //location = ""; //port = 0; //server = ""; //url_base = ""; spec_version_major = 1; spec_version_minor = 0; unique_service_name = "schemas-upnp-org:device:MediaServer:1"; //universal_unique_id = "00000000-FFEE-0000-0000-00000FF0000" + device_id;//TODO change to FormatStringVersion to add zeros in front of device_id if less than 1000 universal_unique_id = System.Guid.NewGuid().ToString(); root_device = new SubDevice(); root_device.DeviceType = "schemas-upnp-org:device:MediaServer:1";//urn: root_device.FriendlyName = "vpMediaServer"; root_device.Manufacturer="Voyager Project"; root_device.ManufacturerUrl="http://www.voyagerproject.org"; root_device.ModelDescription="Provides access to local and remote files."; root_device.ModelName="vpMediaServer"; root_device.ModelNumber = "0.1"; root_device.ModelUrl = "http://www.voyagerproject.org"; root_device.PresentationUrl = "http://www.voyagerproject.org"; //TODO now generate a uuid based on ip and port and an internal counter //to make each and every instance of the media browser unique //or just a random number :-) //Random rnd = new Random(); //int i = rnd.Next(65535); //string si = Convert.ToString(i, 16); root_device.UniversalUniqueID = universal_unique_id; //root_device.UniversalUniqueID = "00000000-FFEE-"+si+"-0000-00000FF0000" + device_id;//uuid: SubDevice.Service connection_manager = new SubDevice.Service(); SubDevice.Service content_directory = new SubDevice.Service(); connection_manager.ServiceType = "schemas-upnp-org:service:ConnectionManager:1"; connection_manager.ServiceID = "urn:upnp-org:serviceId:ConnectionManager"; connection_manager.ControlUrl = ""; connection_manager.EventSubUrl = ""; connection_manager.SCPDUrl = ""; content_directory.ServiceType = "schemas-upnp-org:service:ContentDirectory:1"; content_directory.ServiceID = "urn:upnp-org:serviceId:ContentDirectory"; content_directory.ControlUrl = ""; content_directory.EventSubUrl = ""; content_directory.SCPDUrl = ""; root_device.Services.Add(connection_manager); root_device.Services.Add(content_directory); }
//Adicionar dados inseridos pelo operador do sistema. public static void AddSubDevice(SubDevice p1) { Subdevices.Add(p1); }
private void ReadDeviceService(XmlNode node, SubDevice device) { if (node.HasChildNodes) { SubDevice.Service service = new SubDevice.Service(); foreach (XmlNode child in node.ChildNodes) { if (child.Name.Equals("serviceType")) service.ServiceType = child.InnerText; if (child.Name.Equals("serviceId")) service.ServiceID = child.InnerText; if (child.Name.Equals("SCPDURL")) { service.SCPDUrl = child.InnerText; if (service.SCPDUrl.StartsWith("/")) service.SCPDUrl = service.SCPDUrl.Substring(1); } if (child.Name.Equals("controlURL")) { service.ControlUrl = child.InnerText; if (service.ControlUrl.StartsWith("/")) service.ControlUrl = service.ControlUrl.Substring(1); } if (child.Name.Equals("eventSubURL")) { service.EventSubUrl = child.InnerText; if(service.EventSubUrl.StartsWith("/")) service.EventSubUrl = service.EventSubUrl.Substring(1); } } device.Services.Add(service); } }
private void ReadDeviceServiceList(XmlNode node, SubDevice device) { if (node.HasChildNodes) { foreach (XmlNode child in node.ChildNodes) { if (child.Name.Equals("service")) ReadDeviceService(child, device); } } }
private void ReadDeviceDeviceList(XmlNode node, SubDevice device) { if (node.HasChildNodes) { foreach (XmlNode child in node.ChildNodes) { if (child.Name.Equals("device")) { SubDevice sub_device = new SubDevice(); ReadDevice(child, sub_device); device.Devices.Add(sub_device); } } } }
private void ReadDeviceDescriptionRoot(XmlNode node) { /* foreach (XmlAttribute attr in node.Attributes) { //Console.WriteLine("attr:" + attr.Name + " - " + attr.Value); if (attr.Name.Equals("Name")) name = attr.Value; if (attr.Name.Equals("Address")) address = attr.Value; } */ if (node.HasChildNodes) { foreach (XmlNode child in node.ChildNodes) { if (child.Name.Equals("specVersion")) ReadSpecVersion(child); if (child.Name.Equals("URLBase")) { url_base = child.InnerText; if (!url_base.EndsWith("/")) url_base += "/"; } if (child.Name.Equals("device")) { root_device = new SubDevice(); ReadDevice(child, root_device); } } } }
private void ReadDevice(XmlNode node, SubDevice device) { if (node.HasChildNodes) { foreach (XmlNode child in node.ChildNodes) { if (child.Name.Equals("deviceType")) device.DeviceType = child.InnerText; if (child.Name.Equals("presentationURL")) { device.PresentationUrl = child.InnerText; if (device.PresentationUrl.StartsWith("/")) device.PresentationUrl = device.PresentationUrl.Substring(1); } if (child.Name.Equals("friendlyName")) device.FriendlyName = child.InnerText; if (child.Name.Equals("manufacturer")) device.Manufacturer = child.InnerText; if (child.Name.Equals("manufacturerURL")) device.ManufacturerUrl = child.InnerText; if (child.Name.Equals("modelDescription")) device.ModelDescription = child.InnerText; if (child.Name.Equals("modelName")) device.ModelName = child.InnerText; if (child.Name.Equals("UDN")) { device.UniversalUniqueID = child.InnerText; if (device.UniversalUniqueID.StartsWith("uuid:", true, null)) device.UniversalUniqueID = device.UniversalUniqueID.Substring(5); } if (child.Name.Equals("serviceList")) ReadDeviceServiceList(child, device); if (child.Name.Equals("deviceList")) ReadDeviceDeviceList(child, device); } } }
/// <summary> /// Announce a service to other upnp aware applications /// </summary> /// <param name="device">the device to broadcast</param> public void AnnounceDeviceService(LocalDevice device, SubDevice.Service service, bool is_alive) { try { string nts = "ssdp:alive"; if (!is_alive) nts = "ssdp:byebye"; string announce_message = "NOTIFY * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\n"; announce_message += "CACHE-CONTROL: max-age=" + max_age + "\r\n"; announce_message += "LOCATION: http://" + local_device_handler.IP + ":" + local_device_handler.Port + "/device/" + device.DeviceID + "/root.xml\r\n"; announce_message += "NT: urn:" + service.ServiceType + "\r\n"; //announce_message += "USN: uuid:" + service.ServiceID + "::urn:" + service.ServiceType + "\r\n"; announce_message += "USN: uuid:" + device.UniversalUniqueID + "::urn:" + service.ServiceType + "\r\n"; announce_message += "NTS: " + nts + "\r\n"; announce_message += "Server: NT/5.0 UPnP/1.0\r\n"; announce_message += "\r\n"; IPEndPoint udp_announce_endpoint = new IPEndPoint(IPAddress.Parse(upnp_udp_multicast_address), upnp_udp_port); byte[] send_bytes = System.Text.Encoding.Default.GetBytes(announce_message); udp_socket.BeginSendTo(send_bytes, 0, send_bytes.Length, SocketFlags.None, udp_announce_endpoint, new AsyncCallback(AnnounceDeviceServiceCallback), udp_socket); } catch (Exception ex) { Console.WriteLine("Exception during sending of device service announce packet: " + ex.Message); } }
private void ReplyDeviceService(LocalDevice device,SubDevice.Service service, IPEndPoint destination) { try { string reply_message = "HTTP/1.1 200 OK\r\n"; reply_message += "CACHE-CONTROL: max-age=" + max_age + "\r\n"; reply_message += "LOCATION: http://" + local_device_handler.IP + ":" + local_device_handler.Port + "/device/" + device.DeviceID + "/root.xml\r\n"; reply_message += "USN: uuid:" + service.ServiceID + "::urn:" + service.ServiceType + "\r\n"; reply_message += "ST: urn:" + service.ServiceType + "\r\n"; reply_message += "EXT: \r\n"; reply_message += "Server: NT/5.0 UPnP/1.0\r\n"; reply_message += "\r\n"; //IPEndPoint udp_announce_endpoint = new IPEndPoint(IPAddress.Parse(upnp_udp_multicast_address), upnp_udp_port); byte[] send_bytes = System.Text.Encoding.Default.GetBytes(reply_message); udp_send_socket.BeginSendTo(send_bytes, 0, send_bytes.Length, SocketFlags.None, destination, new AsyncCallback(ReplyDeviceServiceCallback), udp_send_socket); } catch (Exception ex) { Console.WriteLine("Exception during sending of device reply packet: " + ex.Message); } }