protected void lbUpdateDevice_Click(object sender, EventArgs e) { Device toUpdate = DataProvider.Devices.FirstOrDefault(i => i.IpAddress == tbIPAddress.Text.Trim()); DeviceType dt = DataProvider.DeviceTypes.FirstOrDefault(i => i.DeviceTypeName.Trim() == SwitchInfo.DeviceType.Trim()); if (dt == null) { dt = DataProvider.DeviceTypes.Add(new DeviceType() { DeviceTypeName = SwitchInfo.DeviceType.Trim(), DeviceTypeKey = SwitchInfo.DeviceType.Trim().ToLower().Replace(" ", "_") }); } toUpdate.DeviceType = dt; toUpdate.BuildingId = Convert.ToInt32(ddlBuilding.SelectedValue); toUpdate.DeviceKey = SwitchInfo.DeviceKey; toUpdate.HostName = SwitchInfo.HostName; toUpdate.IpAddress = SwitchInfo.IPAddress; //toUpdate.InterfaceInformations = new List<InterfaceInformation>(); foreach (BasicInterfaceInformation item in InterfaceInfo) { InterfaceInformation interf = toUpdate.InterfaceInformations.FirstOrDefault(i => i.InterfaceIndex == item.IfIndex); interf.PortNumber = item.IfNumber; interf.HasCdpInfo = item.IfCdpExist; interf.InterfaceIndex = item.IfIndex; interf.InterfaceName = item.IfDescription; interf.IsConnected = item.IfConnected; interf.IsOpen = item.IfStat; interf.LastCheckTime = DateTime.Now; } DataProvider.SaveChanges(); Response.Redirect("Default.aspx"); }
/// <summary> /// Metodo que permite registrar el acceso a una interfaz en el modo guiado. /// </summary> /// <param name="cod_estud">Cod_estud.</param> /// <param name="fecha">Fecha.</param> /// <param name="cod_interf">Cod_interf.</param> /// <param name="paso">Paso.</param> /// <param name="mark_err">Mark_err.</param> public void RegistrarInterfazModoEvalConsult(string cod_estud, string fecha, string cod_interf, string paso, string mark_err, string tipo_naveg) { Debug.Log ("Se reciben los datos para notificar el acceso a una interfaz: estud=" + cod_estud + ",fecha=" + fecha + ",cod_interf=" + cod_interf + ",paso=" + paso + ",mark_err=" + mark_err + ",tipo=" + tipo_naveg); Debug.Log ("El codigo del estudiante asignado desde el AppManager es: " + student_code); InterfaceInformation interface_reg = new InterfaceInformation (cod_estud, fecha, cod_interf, paso, mark_err, tipo_naveg); interfaces.Add (interface_reg); //for debugging: //imprimir_lista (); }
private InterfaceInformation GetInterfaceInformation(string propertyInterfaceName) { InterfaceInformation interfaceInfo = null; ReadOnlyDictionary <InterfaceInformation> interfaces = metadataManager.Interfaces; string key = LookIntoICollection(interfaces.Keys, propertyInterfaceName); if (key != null) { interfaces.TryGetValue(key, out interfaceInfo); } return(interfaceInfo); }
/// <summary> /// Compile a template using the provided network rule. /// </summary> /// <param name="template"></param> /// <param name="networkRule"></param> /// <param name="interfaceInformation"></param> /// <returns></returns> public static string BuildTemplate(string template, NetworkRule networkRule, InterfaceInformation interfaceInformation) { // Replace all data in the template. template = template.ReplaceAll("{type}", networkRule.Type.ToString().ToUpper()); template = template.ReplaceAll("{network}", networkRule.Network); template = template.ReplaceAll("{interface-address}", interfaceInformation.Address); template = template.ReplaceAll("{interface-name}", interfaceInformation.Name); template = template.ReplaceAll("{protocol}", networkRule.Protocol.ToString().ToLower()); // Return the modified template to the user. return(template); }
private bool HasProperty(InterfaceInformation interfaceInfo, string propertyName) { ReadOnlyDictionary <PropertyInformation> propertyInformation = interfaceInfo.Properties; if (LookIntoICollection(propertyInformation.Keys, propertyName) != null) { return(true); } else { return(false); } }
internal void Expand(byte[] sourceArray) { ItemCount = BitConverter.ToUInt16(sourceArray, 0); if (ItemCount == 0) { return; } InterfaceInfo = new InterfaceInformation[ItemCount]; int offset = 1; for (int i = 0; i < ItemCount; i++) { offset += 1; InterfaceInformation item = new InterfaceInformation(); item.Expand(sourceArray, offset, out offset); InterfaceInfo[i] = item; } }
private void btn_devices_Click(object sender, EventArgs e) { progrBar_loading.Visible = true; devices = InterfaceInformation.GetDevices().ToArray(); progrBar_loading.Visible = false; for (int i = 0; i < devices.Length; i++) { ListViewItem item = new ListViewItem( new string[] { devices[i].DeviceName, devices[i].ip.ToString(), devices[i].MacAddress }); list_devices.Items.Add(item); } }
private bool HasProperty(InterfaceInformation interfaceInfo, string propertyName) { ReadOnlyDictionary<PropertyInformation> propertyInformation = interfaceInfo.Properties; if (LookIntoICollection(propertyInformation.Keys, propertyName) != null) return true; else return false; }
public void RegistrarReinicioDeModo(string cod_estud, string fecha, string cod_interf, string paso, string mark_err, string tipo_modo) { Debug.Log ("Se reciben los datos para notificar el acceso a una interfaz: estud=" + cod_estud + ",fecha=" + fecha + ",cod_interf=" + cod_interf + ",paso=" + paso + ",mark_err=" + mark_err + ",tipo=" + tipo_modo); InterfaceInformation interface_reg = new InterfaceInformation (cod_estud, fecha, cod_interf, paso, mark_err, tipo_modo); interfaces.Add (interface_reg); //for debugging: //imprimir_lista (); }
/// <summary> /// Metodo que permite registrar el acceso a una interfaz en modo guiado con parametro entero para el marcador /// </summary> /// <param name="cod_estud">Cod_estud.</param> /// <param name="fecha">Fecha.</param> /// <param name="cod_interf">Cod_interf.</param> /// <param name="paso">Paso.</param> /// <param name="mark_err">Mark_err.</param> public void RegistrarInterfazModoGuiado(string cod_estud, string fecha, string cod_interf, string paso, int mark_err) { Debug.Log ("Se reciben los datos para notificar el acceso a una interfaz: estud=" + cod_estud + ",fecha=" + fecha + ",cod_interf=" + cod_interf + ",paso=" + paso + ",mark_err=" + mark_err); Debug.Log ("El codigo del estudiante asignado desde el AppManager es: " + student_code); string marker_error = mark_err.ToString (); InterfaceInformation interface_reg = new InterfaceInformation (cod_estud, fecha, cod_interf, paso, marker_error,"guiado"); interfaces.Add (interface_reg); //for debugging: //imprimir_lista (); }
public static Dictionary <long, InterfaceInformation> ListAllInterfaces() { if (Os.Ver == Os.V.XpOrLower) { throw new NotSupportedException("Windows Version Too Low"); } var transId = new Dictionary <string, uint>(); long accu = -1; var result = new Dictionary <long, InterfaceInformation>(); if (Os.Ver == Os.V.VistaOrSeven) { ManagementClass nic = new ManagementClass(@"\\.\ROOT\cimv2:Win32_NetworkAdapter"); foreach (var a in nic.GetInstances()) { var key = (uint)a["InterfaceIndex"]; var value = new InterfaceInformation { WMI_Win32_NetworkAdapter_Exist = true, WMI_WNA_AdapterType = a["AdapterType"] as string, WMI_WNA_Availability = Convert.ToUInt16(a["Availability"]), WMI_WNA_Caption = a["Caption"] as string, WMI_WNA_Description = a["Description"] as string, WMI_WNA_DeviceID = a["DeviceID"] as string, WMI_WNA_GUID = a["GUID"] as string, WMI_WNA_Index = Convert.ToUInt32(a["Index"]), WMI_WNA_InterfaceIndex = Convert.ToUInt32(a["InterfaceIndex"]), WMI_WNA_Name = a["Name"] as string, WMI_WNA_NetConnectionID = a["NetConnectionID"] as string, WMI_WNA_NetConnectionStatus = Convert.ToUInt16(a["NetConnectionStatus"]), WMI_WNA_PhysicalAdapter = Convert.ToBoolean(a["PhysicalAdapter"]), WMI_WNA_Status = a["Status"] as string }; result.Add(key, value); if (!string.IsNullOrEmpty(value.WMI_WNA_GUID)) { transId.Add(value.WMI_WNA_GUID, key); } } } else { // win8 or higher ManagementClass nic = new ManagementClass(@"\\.\ROOT\StandardCimv2:MSFT_NetAdapter"); foreach (var a in nic.GetInstances()) { var key = (uint)a["InterfaceIndex"]; var value = new InterfaceInformation { WMI_MSFT_NetAdapter_Exist = true, WMI_MSFT_NA_Availability = Convert.ToUInt16(a["Availability"]), WMI_MSFT_NA_Caption = a["Caption"] as string, WMI_MSFT_NA_ConnectorPresent = Convert.ToBoolean(a["ConnectorPresent"]), WMI_MSFT_NA_Description = a["Description"] as string, WMI_MSFT_NA_DeviceID = a["DeviceID"] as string, WMI_MSFT_NA_DeviceName = a["DeviceName"] as string, WMI_MSFT_NA_HardwareInterface = Convert.ToBoolean(a["HardwareInterface"]), WMI_MSFT_NA_InterfaceDescription = a["InterfaceDescription"] as string, WMI_MSFT_NA_InterfaceGuid = a["InterfaceGuid"] as string, WMI_MSFT_NA_InterfaceIndex = Convert.ToUInt32(a["InterfaceIndex"]), WMI_MSFT_NA_InterfaceName = a["InterfaceName"] as string, WMI_MSFT_NA_MediaConnectState = Convert.ToUInt32(a["MediaConnectState"]), WMI_MSFT_NA_MtuSize = Convert.ToUInt32(a["MtuSize"]), WMI_MSFT_NA_Name = a["Name"] as string, WMI_MSFT_NA_NetLuid = Convert.ToUInt64(a["NetLuid"]), WMI_MSFT_NA_PNPDeviceID = a["PNPDeviceID"] as string, WMI_MSFT_NA_Status = a["Status"] as string, WMI_MSFT_NA_Virtual = Convert.ToBoolean(a["Virtual"]) }; result.Add(key, value); if (!string.IsNullOrEmpty(value.WMI_MSFT_NA_DeviceID)) { transId.Add(value.WMI_MSFT_NA_DeviceID, key); } } } foreach (var row in IPNetHelper.GetInterfaceTable()) { if (!result.ContainsKey(row.InterfaceIndex)) { result.Add(row.InterfaceIndex, new InterfaceInformation()); } result[row.InterfaceIndex].IPHLPAPI_IFINTERFACE_ROW_Exist = true; result[row.InterfaceIndex].IP_IFR_InterfaceLuid = row.InterfaceLuid; result[row.InterfaceIndex].IP_IFR_InterfaceIndex = row.InterfaceIndex; result[row.InterfaceIndex].IP_IFR_UseAutomaticMetric = row.UseAutomaticMetric == 1; result[row.InterfaceIndex].IP_IFR_Metric = row.Metric; result[row.InterfaceIndex].IP_IFR_NlMtu = row.NlMtu; result[row.InterfaceIndex].IP_IFR_Connected = row.Connected == 1; result[row.InterfaceIndex].IP_IFR_DisableDefaultRoutes = row.DisableDefaultRoutes == 1; } ManagementClass mc = new ManagementClass(@"\\.\ROOT\cimv2:Win32_NetworkAdapterConfiguration"); foreach (var a in mc.GetInstances()) { var key = (uint)a["InterfaceIndex"]; if (!result.ContainsKey(key)) { result.Add(key, new InterfaceInformation()); } result[key].WMI_Win32_NetworkAdapterConfiguration_Exist = true; result[key].WMI_NAC_Caption = a["Caption"] as string; result[key].WMI_NAC_Description = a["Description"] as string; result[key].WMI_NAC_DefaultIPGateway = a["DefaultIPGateway"] == null ? "" : string.Join(", ", (string[])a["DefaultIPGateway"]); result[key].WMI_NAC_Index = Convert.ToUInt32(a["Index"]); result[key].WMI_NAC_InterfaceIndex = Convert.ToUInt32(a["InterfaceIndex"]); result[key].WMI_NAC_DNSServerSearchOrder = a["DNSServerSearchOrder"] == null ? "" : string.Join(", ", (string[])a["DNSServerSearchOrder"]); result[key].WMI_NAC_DHCPEnabled = Convert.ToBoolean(a["DHCPEnabled"]); result[key].WMI_NAC_IPEnabled = Convert.ToBoolean(a["IPEnabled"]); result[key].WMI_NAC_IPConnectionMetric = Convert.ToUInt32(a["IPConnectionMetric"]); result[key].WMI_NAC_IPAddress = a["IPAddress"] == null ? "" : string.Join(", ", (string[])a["IPAddress"]); result[key].WMI_NAC_MTU = Convert.ToUInt32(a["MTU"]); result[key].WMI_NAC_MACAddress = a["MACAddress"] as string; } foreach (var adaptor in NetworkInterface.GetAllNetworkInterfaces()) { long key; if (transId.ContainsKey(adaptor.Id)) { key = transId[adaptor.Id]; } else { if (adaptor.Supports(NetworkInterfaceComponent.IPv4) && result.ContainsKey(adaptor.GetIPProperties().GetIPv4Properties().Index)) { key = adaptor.GetIPProperties().GetIPv4Properties().Index; } else { key = accu; accu -= 1; result.Add(key, new InterfaceInformation()); } } result[key].Net_NetworkInterface_Exist = true; result[key].Net_ID = adaptor.Id; result[key].Net_Description = adaptor.Description; result[key].Net_Name = adaptor.Name; result[key].Net_OperationalStatus = adaptor.OperationalStatus.ToString(); result[key].Net_SupportIPv4 = adaptor.Supports(NetworkInterfaceComponent.IPv4); result[key].Net_NetworkInterfaceType = adaptor.NetworkInterfaceType.ToString(); if (adaptor.Supports(NetworkInterfaceComponent.IPv4)) { result[key].Net_IPv4Index = adaptor.GetIPProperties().GetIPv4Properties().Index; result[key].Net_IPv4MTU = adaptor.GetIPProperties().GetIPv4Properties().Mtu; } result[key].Net_DnsAddresses = string.Join(", ", adaptor.GetIPProperties().DnsAddresses); result[key].Net_GatewayAddresses = string.Join(", ", adaptor.GetIPProperties().GatewayAddresses.ToList().ConvertAll(gi => gi.Address.ToString())); } return(result); }
private DataObject CreateDataObject(BusinessObject businessObject) { string propertyName = string.Empty; string keyPropertyName = string.Empty; string relatedPropertyName = string.Empty; string relatedObjectName = string.Empty; string relationshipName = string.Empty; DataObject dataObject = new DataObject(); string objectName = businessObject.objectName; dataObject.objectName = objectName; dataObject.objectNamespace = projectNameSpace; dataObject.tableName = objectName; dataObject.keyProperties = new List <KeyProperty>(); dataObject.dataProperties = new List <DataProperty>(); dataObject.dataRelationships = new List <DataRelationship>(); if (businessObject.dataFilter != null) { dataObject.dataFilter = businessObject.dataFilter; } foreach (BusinessKeyProperty businessKeyProerpty in businessObject.businessKeyProperties) { KeyProperty keyProperty = new KeyProperty(); DataProperty dataProperty = new DataProperty(); keyPropertyName = businessKeyProerpty.keyPropertyName;; keyProperty.keyPropertyName = keyPropertyName; dataProperty.propertyName = keyPropertyName; dataProperty.dataType = DataType.String; dataProperty.columnName = keyPropertyName; dataProperty.isNullable = false; dataProperty.keyType = KeyType.assigned; dataObject.keyProperties.Add(keyProperty); dataObject.dataProperties.Add(dataProperty); } foreach (BusinessInterface businessInterface in businessObject.businessInterfaces) { InterfaceInformation interfaceInfo = GetInterfaceInformation(businessInterface.interfaceName); foreach (BusinessProperty businessProperty in businessInterface.businessProperties) { propertyName = businessProperty.propertyName; if (interfaceInfo != null) { if (HasProperty(interfaceInfo, propertyName)) { DataProperty dataProperty = new DataProperty(); if (!String.IsNullOrEmpty(businessProperty.dbColumn)) { dataProperty.columnName = businessProperty.dbColumn; } else { dataProperty.columnName = propertyName; } dataProperty.propertyName = propertyName; dataProperty.dataType = GetDatatype(businessProperty.dataType); dataProperty.isNullable = businessProperty.isNullable; dataProperty.isReadOnly = businessObject.isReadOnly; if (!String.IsNullOrEmpty(businessProperty.description) != null) { dataProperty.description = businessObject.description; } dataObject.dataProperties.Add(dataProperty); } else { throw new Exception("Property [" + propertyName + "] not found."); } } else { throw new Exception("Interface [" + businessInterface.interfaceName + "] not found."); } } } foreach (BusinessRelationship businessRelationship in businessObject.businessRelationships) { DataRelationship dataRelationship = new DataRelationship(); relationshipName = businessRelationship.relationshipName; relatedObjectName = businessRelationship.relatedObjectName; if (IsRelated(relationshipName, relatedObjectName, objectName)) { dataRelationship.relatedObjectName = businessRelationship.relatedObjectName; dataRelationship.relationshipName = businessRelationship.relationshipName; dataRelationship.propertyMaps = new List <PropertyMap>(); if (businessRelationship.businessRelatedInterfaces != null) { foreach (BusinessInterface businessInterface in businessRelationship.businessRelatedInterfaces) { foreach (BusinessProperty businessRelationProperty in businessInterface.businessProperties) { InterfaceInformation interfaceInfo = GetInterfaceInformation(businessInterface.interfaceName); relatedPropertyName = businessRelationProperty.propertyName; if (interfaceInfo != null) { if (HasProperty(interfaceInfo, relatedPropertyName)) { DataProperty dataProperty = new DataProperty(); PropertyMap propertyMap = new PropertyMap(); propertyMap.relatedPropertyName = relatedPropertyName; dataProperty.propertyName = dataRelationship.relatedObjectName + "_" + relatedPropertyName; dataProperty.dataType = GetDatatype(businessRelationProperty.dataType); if (!String.IsNullOrEmpty(businessRelationProperty.dbColumn)) { dataProperty.columnName = businessRelationProperty.dbColumn; } else { dataProperty.columnName = relatedPropertyName; } dataRelationship.propertyMaps.Add(propertyMap); dataObject.dataProperties.Add(dataProperty); } else { throw new Exception("Property [" + relatedPropertyName + "] not found."); } } else { throw new Exception("Interface [" + businessInterface.interfaceName + "] not found."); } } } dataObject.dataRelationships.Add(dataRelationship); } } } return(dataObject); }