private bool addPortInfoToListView(PortInfo info) { bool flag = CheckPortInfo(info); if (flag) { TreeNode root = null; TreeNode son = new TreeNode(string.Format("{0,20}", info.ToString())); bool exist = false; foreach (TreeNode node in portTreeView.Nodes) { //MessageBox.Show(node.Text); if (node.Text == info.Port) { root = node; } } if (null == root) { root = new TreeNode(info.Port); portTreeView.Nodes.Add(root); root.ImageIndex = 0; //root.SelectedImageIndex = root.ImageIndex;//fixme root.Nodes.Add(son); //son.ForeColor = Color.Blue; son.ImageIndex = 2; portTreeView.SelectedNode = son; portTreeView.Sort(); } else { foreach (TreeNode node in root.Nodes) { if (node.Text == info.ToString()) { exist = true; break; } } if (!exist) { root.Nodes.Add(son); //son.ForeColor = Color.Blue; son.ImageIndex = 2; portTreeView.SelectedNode = son; } } } return(flag); }
internal PortBindingInfo(OrchestrationBindingBase <T> orchestrationBinding, PortInfo logicalPort) { if (orchestrationBinding == null) { throw new ArgumentNullException("orchestrationBinding"); } if (logicalPort == null) { throw new ArgumentNullException("logicalPort"); } _orchestrationBinding = orchestrationBinding; _logicalPort = logicalPort; }
public void SetPort(GameObject port, PortInfo portInfo, int playerNum) { this.port = port; this.portInfo = portInfo; this.playerIDInRoom = playerNum; OnPlayerNumberChanges(playerNum + 1); /*if (playerIDInRoom != 1) { * //GameModeChoiceDisable (); * //EntryEnable (false); * }*/ }
private PortInfo getPortComboBoxInfo() { PortInfo info = new PortInfo(); info.Port = portComboBox.Text; info.BaudRate = baudrateComboBox.Text; info.DataBits = databitsComboBox.Text; info.Stopbits = stopbitsComboBox.Text; info.Parity = parityComboBox.Text; info.Flow = flowComboBox.Text; return(info); }
public static void SetSelectedPortInfo(PortInfo portInfo, int printerPriority) { List <PortInfo> portInfoList = new List <PortInfo>(SelectedAllPortInfo); while (portInfoList.Count < printerPriority + 1) { portInfoList.Add(null); } portInfoList[printerPriority] = portInfo; SelectedAllPortInfo = portInfoList.ToArray(); }
private Camera(CameraAbilities abilities, PortInfo port, Context context) { string[] parts = port.Path.Substring(4).Split(','); this.abilities = new Abilities(abilities); this.baseAbilities = abilities; this.context = context; this.musicPath = ""; this.photosPath = ""; this.playlistPath = ""; this.port = port; this.usbBusNumber = int.Parse(parts[0]); this.usbDeviceNumber = int.Parse(parts[1]); }
private static void RegisterPortInternal(PortInfo info, Assembly portAsm) { CustomPorts.Add(info, portAsm); if (portExploitsInit) { PortExploits.services.Add(info.PortNumber, info.PortName); } else { portsToAdd.Add(info); } }
internal static void AddPortPropertyMember(this CodeTypeDeclaration @class, PortInfo port, CodeTypeDeclaration bindingConfigurationInterface) { if (@class == null) { throw new ArgumentNullException("class"); } if ([email protected]) { throw new ArgumentException("type"); } if (port == null) { throw new ArgumentNullException("port"); } if (bindingConfigurationInterface == null) { throw new ArgumentNullException("bindingConfigurationInterface"); } if (!bindingConfigurationInterface.IsInterface) { throw new ArgumentException("bindingConfigurationInterface"); } // explicit property for each port to bind //private ISendPort _SendPort; //ISendPort IProcessOrchestrationBinding.SendPort //{ // get { return this._SendPort; } // set { this._SendPort = value; } //} var field = new CodeMemberField { Attributes = MemberAttributes.Private, Name = "_" + port.Name, Type = new CodeTypeReference(port.Polarity == Polarity.uses ? typeof(ISendPort).Name : typeof(IReceivePort).Name) }; @class.Members.Add(field); var property = new CodeMemberProperty { Attributes = MemberAttributes.Public, Name = port.Name, GetStatements = { new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name)) }, SetStatements = { new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name), new CodePropertySetValueReferenceExpression()) }, Type = new CodeTypeReference(port.Polarity == Polarity.uses ? typeof(ISendPort).Name : typeof(IReceivePort).Name), PrivateImplementationType = new CodeTypeReference(bindingConfigurationInterface.Name) }; @class.Members.Add(property); }
private void PortScanner_PortScanned(object sender, PortScannedArgs e) { PortInfo portInfo = PortInfo.Parse(e); Application.Current.Dispatcher.BeginInvoke(new Action(delegate() { PortScanResult.Add(portInfo); })); if (portInfo.Status == PortInfo.PortStatus.Open) { PortsOpen++; } }
public ActionResult Port_View_Update(decimal _portId) { var _obj = new PortInfo(); try { _obj = PortBL.Port_GetByID(_portId); } catch (Exception ex) { Common.log.Error(ex.ToString()); } return(PartialView("_Port_Update", _obj)); }
public ActionResult Port_Update(PortInfo _obj) { decimal p_success = -1; try { p_success = PortBL.Port_Update(_obj); } catch (Exception ex) { Common.log.Error(ex.ToString()); } return(Json(new { success = p_success })); }
public static PortInfo Port_GetByID(decimal _portId) { var p_object = new PortInfo(); try { p_object = (PortInfo)CBO.FillObjectFromDataSet(PortDA.Port_GetbyId(_portId), typeof(PortInfo)); } catch (Exception ex) { Common.log.Error(ex.ToString()); } return(p_object); }
public void TestOkCommand_ResultHasPortToDisable() { PortInfo enabledPort = PortManagerViewModel.s_supportedPorts[0]; const string instanceName = "instance-name"; Instance instance = PortTestHelpers.GetInstanceWithEnabledPort(enabledPort, instanceName); var objectUnderTest = new PortManagerViewModel(_mockedCloseAction, instance); objectUnderTest.Ports.Single(p => p.IsEnabled).IsEnabled = false; objectUnderTest.OkCommand.Execute(null); FirewallPort portToDisable = objectUnderTest.Result.PortsToDisable.Single(); Assert.AreEqual(enabledPort.Port, portToDisable.Port); Assert.AreEqual(enabledPort.GetTag(instanceName), portToDisable.Name); }
private PortInfo CreateValidPortInfo() { var portInfo = new PortInfo( new OperationInfo[] { new OperationInfo("SendTestRequest", System.Web.Services.Description.OperationFlow.OneWay, typeof(TestablePortType), typeof(TestableRequest), null, null, null) }, typeof(TestableOrchestration).GetField("SendPort"), Polarity.implements, true, Guid.NewGuid(), null); return(portInfo); }
private async Task RequestPortProperties(PortInfo port) { lock (lockObject) { SentMessages += 2; } await _protocol.SendMessageAsync(new PortInformationRequestMessage() { HubId = _hubId, PortId = port.PortId, InformationType = PortInformationType.ModeInfo, }); await _protocol.SendMessageAsync(new PortInformationRequestMessage() { HubId = _hubId, PortId = port.PortId, InformationType = PortInformationType.PossibleModeCombinations, }); }
public void TestGetDisplayString_FormattedFromPortInfo() { const string expectedPortName = "expected-port-name"; const int expectedPortNumber = 15; const string expectedDescription = "Expected Description"; var portInfo = new PortInfo(expectedPortName, expectedPortNumber, expectedDescription); var objectUnderTest = new PortModel(portInfo, _defaultInstance); Assert.AreEqual( string.Format( Resources.PortManagerDisplayStringFormat, expectedDescription, expectedPortName, expectedPortNumber), objectUnderTest.DisplayString); }
private void SetPrinterManually() { string[] settings = ShowManualSettingWindow(); if (settings == null) { return; } ModelInformation modelInformation = ShowSelectModelWindow(); if (modelInformation == null) { return; } if (modelInformation.ChangeDrawerOpenStatusIsEnabled) { bool?drawerOpenStatus = ShowSelectDrawerOpenStatusWindow(); if (drawerOpenStatus == null) { return; } modelInformation.DrawerOpenStatus = (bool)drawerOpenStatus; } else { modelInformation.DrawerOpenStatus = true; } string portName = settings[0]; string portSettings = settings[1]; modelInformation.PortSettings = portSettings; PortInfo portInfo = new PortInfo(portName, "", modelInformation.SimpleModelName, ""); SharedInformationManager.SetSelectedModelInformation(modelInformation); SharedInformationManager.SetSelectedPortInfo(portInfo); Util.GoBackMainPage(); }
/// <summary> /// Detects all usable cameras which are connected to the system /// </summary> /// <returns>A list containing all cameras which can be connected to</returns> public static List <Camera> Detect() { if (Utilities.Is64Bit && Environment.OSVersion.Platform != PlatformID.Unix) { Console.WriteLine("A 64bit windows system has been detected. This is not supported"); Console.WriteLine("due to the complexity of interoperating with libgphoto2"); Console.WriteLine("as it exposes variable length 'long' types in it's API."); Console.WriteLine("The API is unlikely to change before version 3 of the library"); Console.WriteLine("The current status of this can be found on the libgphoto2"); Console.WriteLine("mailing list. A detailed explanation can be found in the"); Console.WriteLine("README file for libgphoto2-sharp"); return(new List <Camera>()); } List <Camera> cameras = new List <Camera>(); Context c = new Context(); using (CameraAbilitiesList abilities = new CameraAbilitiesList()) using (PortInfoList portInfoList = new PortInfoList()) using (CameraList cameraList = new CameraList()) { // Get the list of all devices that are currently supported abilities.Load(c); // Get the list of all the (usb?) ports that are currently available portInfoList.Load(); // Create the list of all the connected devices which can be used abilities.Detect(portInfoList, cameraList, c); // Scan through all the detected cameras and remove any duplicates using (CameraList cams = RemoveDuplicates(cameraList)) { int count = cams.Count(); for (int i = 0; i < count; i++) { CameraAbilities ability = abilities.GetAbilities(abilities.LookupModel(cams.GetName(i))); PortInfo portInfo = portInfoList.GetInfo(portInfoList.LookupPath(cams.GetValue(i))); cameras.Add(new Gphoto2.Camera(ability, portInfo, c)); } } } return(cameras); }
public GPhotoCamera() { context = new Context(); port_info_list = new PortInfoList (); port_info_list.Load (); abilities_list = new CameraAbilitiesList (); abilities_list.Load (context); camera_list = new CameraList(); selected_camera__camera_list_index = -1; camera = null; port_info = null; camera_fs = null; }
public GPhotoCamera() { context = new Context(); port_info_list = new PortInfoList(); port_info_list.Load(); abilities_list = new CameraAbilitiesList(); abilities_list.Load(context); camera_list = new CameraList(); selected_camera__camera_list_index = -1; camera = null; port_info = null; camera_fs = null; }
private void SetInitialValues(PortInfo initialInfo) { if (initialInfo != null) { Alias = initialInfo.Alias; Comment = initialInfo.Description; PortName = initialInfo.PortName; PortNumber = initialInfo.PortNumber.ToString(CultureInfo.InvariantCulture); Protocol = initialInfo.Protocol.ToString().ToUpperInvariant(); } else { Alias = string.Empty; Comment = string.Empty; PortName = string.Empty; PortNumber = string.Empty; Protocol = string.Empty; } }
public string[] GetSelectedPortNameAndPortSettings(int printerPriority) { if (SelectedPorts.Length < printerPriority + 1 || SelectedModels.Length < printerPriority + 1) { return((string[])Enumerable.Empty <string>()); } PortInfo selectedPort = SelectedPorts[printerPriority]; ModelInformation selectedModel = SelectedModels[printerPriority]; List <string> settingsList = new List <string>(); settingsList.Add(selectedPort.PortName); settingsList.Add(selectedModel.PortSettings); return(settingsList.ToArray()); }
/// <summary> /// Add firewall rule to unblock the port to the GCE instance. /// </summary> public async Task EnablePortAsync() { // Get a refreshed list of firewall rules. // If not refreshed, UpdateInstancePorts may fail. _gceInstance = await DataSource.RefreshInstance(_gceInstance); string portTag = PortInfo.GetTag(_gceInstance.Name); var toEnable = new List <FirewallPort> { new FirewallPort(portTag, PortInfo.Port) }; GceOperation operation = DataSource.UpdateInstancePorts( _gceInstance, portsToEnable: toEnable, portsToDisable: new List <FirewallPort>()); await operation.OperationTask; _portEnabledTime = DateTime.UtcNow; }
public virtual void clear() { lock (this) { // Remove all the hosts while (hosts.Count > 0) { string host = hosts[0]; removeHost(host); } // ...and remove all the ports while (portInfos.Count > 0) { PortInfo portInfo = portInfos[0]; removePort(portInfo.port, portInfo.protocol); } } }
private void PortListBoxItem_Click(object sender, RoutedEventArgs e) { Button clickedButton = (Button)sender; PortInfo selectedPortInfo = (PortInfo)clickedButton.Tag; ModelInformation selectedModelInformation = DecideModel(selectedPortInfo); if (selectedModelInformation == null) { return; } SharedInformationManager.SetSelectedModelInformation(selectedModelInformation); SharedInformationManager.SetSelectedPortInfo(selectedPortInfo); Util.GoBackMainPage(); }
private void OnEditPort() { if (SelectedPort != null) { _savedSelection = new PortInfo(_selectedPort.PortName, _selectedPort.Protocol.ToString(), _selectedPort.PortNumber, _selectedPort.Alias, _selectedPort.Description, _selectedPort.IsSelected); App.Mediator.Publish(App._EVENT_PORTLIST_ADD, new PortAddMessage { ExistingPort = new PortInfo( SelectedPort.PortName, SelectedPort.Protocol.ToString(), SelectedPort.PortNumber, SelectedPort.Alias, SelectedPort.Description, SelectedPort.IsSelected ) }); } }
public void SelectCamera (int index) { selected_camera__camera_list_index = index; selected_camera__abilities_list_index = abilities_list.LookupModel (camera_list.GetName (selected_camera__camera_list_index)); camera_abilities = abilities_list.GetAbilities (selected_camera__abilities_list_index); camera = new Camera (); camera.SetAbilities (camera_abilities); string path = camera_list.GetValue (selected_camera__camera_list_index); System.Console.WriteLine ("Testing gphoto path = {0}", path); selected_camera__port_info_list_index = port_info_list.LookupPath (path); port_info = port_info_list.GetInfo (selected_camera__port_info_list_index); System.Console.WriteLine ("PortInfo {0}, {1}", port_info.Name, port_info.Path); camera.SetPortInfo (port_info); }
private void addSelectNodeToComboBox() { TreeNode node = portTreeView.SelectedNode; if (node.Parent == null) { return; } PortInfo info = new PortInfo(); string[] port = node.Text.Split(','); info.Port = node.Parent.Text; info.BaudRate = port[0]; info.DataBits = port[1]; info.Stopbits = port[2]; info.Parity = port[3]; info.Flow = port[4]; addPortInfoToComboBox(info); return; }
private void btn_Start_Click(object sender, EventArgs e) { try { ReaderType readerType = ReaderType.P17; if (rb_Wisepad.Checked) { readerType = ReaderType.P15; } else if (rb_Wisepad2.Checked) { readerType = ReaderType.P16; } else if (rb_Qpos_mini.Checked) { readerType = ReaderType.P17; } PortInfo selectedPort = null; if (!cb_Usb.Checked && portInfos != null && portInfos.Count > 0) { selectedPort = portInfos[cmb_Paired.SelectedIndex]; } //P17 only Dictionary <String, object> settings = new Dictionary <string, object>(); settings["NOTUP"] = cb_notup.Checked; m_PaymentController.SetReaderType(readerType, (cb_Usb.Checked || selectedPort == null) ? null : selectedPort.portName, settings); } catch (InvalidOperationException ex) { log(string.Format("ERROR : {0}", ex.Message)); } //DEBUG m_PaymentController.Logger = delegate(string s_log) { log(s_log, Color.Blue); }; // m_PaymentController.Enable(); }
/// <summary>Add components for all ports of result.</summary> /// <param name="resultsToRender">Ports to render.</param> private async void RenderResult(Port[] resultsToRender) { ResultsContainer.Children.Clear(); var vm = DataContext as ResultsViewModel; vm.CurrentProgress = 0; vm.IsLoading = true; bool showOpened = vm.ShowOpened; bool showClosed = vm.ShowClosed; bool showNotCheked = vm.ShowNotChecked; bool isDarker = true; await Task.Run(() => { foreach (Port result in resultsToRender) { Application.Current.Dispatcher.Invoke(() => { if ((showOpened && result.State == PortState.Opened) || (showClosed && result.State == PortState.Closed) || (showNotCheked && result.State == PortState.NotChecked)) { PortInfo component = new PortInfo { Port = result.Value.ToString(), Protocol = result.Protocol.ToString(), State = result.State.ToString(), IsDarker = isDarker, }; ResultsContainer.Children.Add(component); (DataContext as ResultsViewModel).CurrentProgress++; isDarker = !isDarker; } }); } }); (DataContext as ResultsViewModel).IsLoading = false; }
private void PlugButton_Click(object sender, EventArgs e) { this.PlugButton.Enabled = false; this.m_SardauscanProxyControl.Proxy = null; PortInfo portInfo = (PortInfo)this.ComComboBox.SelectedItem; try { DisposeArduino(); SardauscanHardwareProxy = new SardauscanHardwareProxy(portInfo); this.m_SardauscanProxyControl.Proxy = SardauscanHardwareProxy; } catch { } finally { this.PlugButton.Enabled = true; AlignInterface(); } }
public void SelectCamera(int index) { selected_camera__camera_list_index = index; selected_camera__abilities_list_index = abilities_list.LookupModel(camera_list.GetName(selected_camera__camera_list_index)); camera_abilities = abilities_list.GetAbilities(selected_camera__abilities_list_index); camera = new Camera(); camera.SetAbilities(camera_abilities); string path = camera_list.GetValue(selected_camera__camera_list_index); System.Console.WriteLine("Testing gphoto path = {0}", path); selected_camera__port_info_list_index = port_info_list.LookupPath(path); port_info = port_info_list.GetInfo(selected_camera__port_info_list_index); System.Console.WriteLine("PortInfo {0}, {1}", port_info.Name, port_info.Path); camera.SetPortInfo(port_info); }
public void SelectCamera(int index) { selected_camera__camera_list_index = index; camera_abilities = abilities_list [camera_list.GetName (selected_camera__camera_list_index)]; port_info = port_info_list.LookupPath (camera_list.GetValue (selected_camera__camera_list_index)); Log.Debug ("PortInfo {0}, {1}", port_info.Name, port_info.Path); camera = new Camera () { Abilities = camera_abilities, PortInfo = port_info }; }
public void SetPort(GameObject port, PortInfo portInfo, int playerNum) { this.port = port; this.portInfo = portInfo; this.playerIDInRoom = playerNum; OnPlayerNumberChanges(playerNum + 1); /*if (playerIDInRoom != 1) { //GameModeChoiceDisable (); //EntryEnable (false); }*/ }
EnumerateSwitch( string switchName) { ManagementScope scope = new ManagementScope(@"root\virtualization\v2"); // // Initialize our SwitchInfo structure to hold information about the switch. // SwitchInfo ethernetSwitchInfo = new SwitchInfo(); ethernetSwitchInfo.Name = switchName; ethernetSwitchInfo.Type = SwitchConnectionType.Private; ethernetSwitchInfo.PortList = new List<PortInfo>(); ethernetSwitchInfo.SwitchFeatureList = new List<NetworkingUtilities.SwitchFeatureType>(); using (ManagementObject ethernetSwitch = NetworkingUtilities.FindEthernetSwitch(switchName, scope)) { // // Enumerate the switch's ports. // using (ManagementObjectCollection portCollection = ethernetSwitch.GetRelated("Msvm_EthernetSwitchPort", "Msvm_SystemDevice", null, null, null, null, false, null)) { foreach (ManagementObject port in portCollection) using (port) { // // Initialize a PortInfo structure to hold information about this port. // PortInfo portInfo = new PortInfo(); portInfo.Type = PortConnectionType.Nothing; portInfo.FeatureList = new List<NetworkingUtilities.PortFeatureType>(); // // The port's connection settings are stored on its related // Msvm_EthernetPortAllocationSettingData object. // using (ManagementObject portSettings = WmiUtilities.GetFirstObjectFromCollection( port.GetRelated("Msvm_EthernetPortAllocationSettingData", "Msvm_ElementSettingData", null, null, null, null, false, null))) { // // Determine the port's connection type. // portInfo.Type = DeterminePortType(portSettings); if (portInfo.Type == PortConnectionType.VirtualMachine) { // Get the name of the connected virtual machine. using (ManagementObject virtualMachineSettings = WmiUtilities.GetFirstObjectFromCollection( portSettings.GetRelated("Msvm_VirtualSystemSettingData", "Msvm_VirtualSystemSettingDataComponent", null, null, null, null, false, null))) { portInfo.ConnectedName = (string)virtualMachineSettings["ElementName"]; } } else if (portInfo.Type == PortConnectionType.External) { // Get the name of the external connection. using (ManagementObject externalAdapter = new ManagementObject( ((string[])portSettings["HostResource"])[0])) { portInfo.ConnectedName = (string)externalAdapter["ElementName"]; } } // // Now determine which advanced properties are configured for this port. // Each Feature has its own class definition and is related to the portSettings // through the Msvm_EthernetPortSettingDataComponent association. // using (ManagementObjectCollection portFeatureCollection = portSettings.GetRelated("Msvm_EthernetSwitchPortFeatureSettingData", "Msvm_EthernetPortSettingDataComponent", null, null, null, null, false, null)) { foreach (ManagementObject portFeature in portFeatureCollection) using (portFeature) { portInfo.FeatureList.Add(DeterminePortFeatureType(portFeature)); } } } ethernetSwitchInfo.PortList.Add(portInfo); } } // // Then enumerate the switch's features. // using (ManagementObject ethernetSwitchSetting = WmiUtilities.GetFirstObjectFromCollection( ethernetSwitch.GetRelated("Msvm_VirtualEthernetSwitchSettingData", "Msvm_SettingsDefineState", null, null, null, null, false, null))) using (ManagementObjectCollection switchFeatures = ethernetSwitchSetting.GetRelated( "Msvm_EthernetSwitchFeatureSettingData", "Msvm_VirtualEthernetSwitchSettingDataComponent", null, null, null, null, false, null)) foreach (ManagementObject switchFeature in switchFeatures) using (switchFeature) { ethernetSwitchInfo.SwitchFeatureList.Add(DetermineSwitchFeatureType(switchFeature)); } } // // Now that we have enumerated all of the switch's ports, we can determine the // switch's connection type. // ethernetSwitchInfo.Type = DetermineSwitchConnectionType(ethernetSwitchInfo.PortList); // // We now have all of the information we need - output it to the console. // OutputSwitchInfo(ethernetSwitchInfo); }
/// <summary> /// InitObject: Initializes the VShieldEdgeConfig object. /// </summary> /// <returns>VShieldEdgeConfig</returns> private VShieldEdgeConfig InitObject() { VShieldEdgeConfig vsec = new VShieldEdgeConfig(); FirewallConfig fwconf = new FirewallConfig(); FirewallRule fwrule = new FirewallRule(); PortInfo dpi = new PortInfo(); PortInfo spi = new PortInfo(); IpInfo dip = new IpInfo(); IpInfo sip = new IpInfo(); try { fwrule.destinationIpAddress = dip; fwrule.destinationPort = dpi; fwrule.ruleId = 0; fwrule.sourceIpAddress = sip; fwrule.sourcePort = spi; if (_FirewallRules.FirewallConfig.Count > 0) { _FirewallRules.FirewallConfig.Add(fwrule); return _FirewallRules; } else { fwconf.Add(fwrule); vsec.FirewallConfig = fwconf; return vsec; } } catch (Exception e) { WriteObject("C-Sharp Exception: " + e); return null; } }
private void OnClearLine() { ObservableCollection<PortInfo> selectedPortCollection = new ObservableCollection<PortInfo>(); for (int i = 0; i < _selectedElementCollection.Count; i++) { if (_selectedElementCollection[i].SenderIndex < 0 && _selectedElementCollection[i].PortIndex < 0) { continue; } PortInfo portInfo = new PortInfo(_selectedElementCollection[i].SenderIndex, _selectedElementCollection[i].PortIndex); if (!selectedPortCollection.Contains(portInfo)) { selectedPortCollection.Add(portInfo); } } ObservableCollection<IElement> deleteCollection = new ObservableCollection<IElement>(); ObservableCollection<AddLineInfo> addLineCollection = new ObservableCollection<AddLineInfo>(); ObservableCollection<ConnectIconVisibilityInfo> connectIconVisibleCollection = new ObservableCollection<ConnectIconVisibilityInfo>(); for (int itemIndex = 0; itemIndex < _myScreenLayer.ElementCollection.Count; itemIndex++) { if (_myScreenLayer.ElementCollection[itemIndex].EleType != ElementType.receive) { continue; } IRectElement element = (IRectElement)_myScreenLayer.ElementCollection[itemIndex]; if (element.ConnectedIndex >= 0) { bool isExist = false; for (int i = 0; i < selectedPortCollection.Count; i++) { if (selectedPortCollection[i].SenderIndex == element.SenderIndex && selectedPortCollection[i].PortIndex == element.PortIndex) { isExist = true; break; } } if (!isExist) { continue; } ConnectIconVisibilityInfo info = new ConnectIconVisibilityInfo(); info.Element = element; OldAndNewVisibility oldAndNewMaxmaxVisible = new OldAndNewVisibility(); oldAndNewMaxmaxVisible.OldValue = element.MaxConnectIndexVisibile; oldAndNewMaxmaxVisible.NewValue = Visibility.Hidden; OldAndNewVisibility oldAndNewMaxminVisible = new OldAndNewVisibility(); oldAndNewMaxminVisible.OldValue = element.MinConnectIndexVisibile; oldAndNewMaxminVisible.NewValue = Visibility.Hidden; info.OldAndNewMaxConnectIndexVisibile = oldAndNewMaxmaxVisible; info.OldAndNewMinConnectIndexVisibile = oldAndNewMaxminVisible; connectIconVisibleCollection.Add(info); } } for (int i = 0; i < selectedPortCollection.Count; i++) { int senderIndex = selectedPortCollection[i].SenderIndex; int portIndex = selectedPortCollection[i].PortIndex; PortConnectInfo portConnectInfo = _myScreenLayer.SenderConnectInfoList[senderIndex].PortConnectInfoList[portIndex]; if (portConnectInfo.ConnectLineElementList != null && portConnectInfo.ConnectLineElementList.Count > 0) { for (int m = 0; m < portConnectInfo.ConnectLineElementList.Count; m++) { AddLineInfo addLineInfo = new AddLineInfo(); addLineInfo.Element = portConnectInfo.ConnectLineElementList[m]; OldAndNewType oldAndNewConnect=new OldAndNewType(); oldAndNewConnect.OldValue=portConnectInfo.ConnectLineElementList[m].ConnectedIndex; oldAndNewConnect.NewValue=-1; addLineInfo.OldAndNewConnectIndex = oldAndNewConnect; OldAndNewType oldAndNewSender = new OldAndNewType(); oldAndNewSender.OldValue = portConnectInfo.ConnectLineElementList[m].SenderIndex; oldAndNewSender.NewValue = -1; addLineInfo.OldAndNewSenderIndex = oldAndNewSender; OldAndNewType oldAndNewPort = new OldAndNewType(); oldAndNewPort.OldValue = portConnectInfo.ConnectLineElementList[m].PortIndex; oldAndNewPort.NewValue = -1; addLineInfo.OldAndNewPortIndex = oldAndNewPort; addLineCollection.Add(addLineInfo); if (portConnectInfo.ConnectLineElementList[m].FrontLine != null) { deleteCollection.Add(portConnectInfo.ConnectLineElementList[m].FrontLine); _myScreenLayer.ElementCollection.Remove(portConnectInfo.ConnectLineElementList[m].FrontLine); } if (portConnectInfo.ConnectLineElementList[m].EndLine != null) { deleteCollection.Add(portConnectInfo.ConnectLineElementList[m].EndLine); _myScreenLayer.ElementCollection.Remove(portConnectInfo.ConnectLineElementList[m].EndLine); } portConnectInfo.ConnectLineElementList[m].ConnectedIndex = -1; portConnectInfo.ConnectLineElementList[m].SenderIndex = -1; portConnectInfo.ConnectLineElementList[m].PortIndex = -1; } portConnectInfo.ConnectLineElementList.Clear(); } portConnectInfo.MaxConnectElement = null; portConnectInfo.MaxConnectIndex = -1; } #region 更新带载区域信息 UpdateLoadAreaInfo(); #endregion DeleteAction deleteAction = new DeleteAction(_myScreenLayer,deleteCollection); AddLineAction addLineAction = new AddLineAction(addLineCollection); ConnectIconVisibilityAction connectVisibleAction = new ConnectIconVisibilityAction(connectIconVisibleCollection); using (Transaction.Create(SmartLCTActionManager)) { SmartLCTActionManager.RecordAction(addLineAction); SmartLCTActionManager.RecordAction(deleteAction); SmartLCTActionManager.RecordAction(connectVisibleAction); } SelectedLayerAndElementChanged(); }
private VShieldEdgeConfig InitObject() { VShieldEdgeConfig vsec = new VShieldEdgeConfig(); NATConfig natConfig = new NATConfig(); NATRule natRule = new NATRule(); PortInfo ipi = new PortInfo(); PortInfo epi = new PortInfo(); IpInfo iip = new IpInfo(); IpInfo eip = new IpInfo(); try { natRule.externalIpAddress = eip; natRule.externalPort = epi; natRule.internalIpAddress = iip; natRule.internalPort = ipi; if (_NatRules.NATConfig.Count > 0) { _NatRules.NATConfig.Add(natRule); return _NatRules; } else { natConfig.Add(natRule); vsec.NATConfig = natConfig; return vsec; } } catch (Exception e) { WriteObject("C-Sharp Exception: " + e); return null; } }
public int Run(string[] args) { // Process command line if (!ProcessArgs(args)) return 0; if (_inputFile == null) { ShowLogo(); ShowHelp(); return 7; } // Open input file var code = System.IO.File.ReadAllBytes(_inputFile); // Work out the available address space _addrSpaceStart = _baseAddr; _addrSpaceEnd = (ushort)(_baseAddr + (code.Length - _header)); // Work out auto length if (_len == 0) _len = (ushort)(code.Length - _header); // Check specified address range CheckAddress(_start); CheckAddress(_start + _len); foreach (var addr in _entryPoints) CheckAddress(addr); // Setup disassembler parameters Disassembler.LabelledRangeLow = (ushort)_start; Disassembler.LabelledRangeHigh = (ushort)(_start + _len); Disassembler.LowerCase = _lowerCase; Disassembler.HtmlMode = _htmlMode; Disassembler.ShowRelativeOffsets = _reloffs; // Disassemble var instructions = new Dictionary<int, Instruction>(); if (_entryPoints.Count > 0) { var pendingCodePaths = new List<int>(); pendingCodePaths.AddRange(_entryPoints); while (pendingCodePaths.Count > 0) { // Get a new address that needs disassembling int addr = pendingCodePaths[0]; pendingCodePaths.RemoveAt(0); // Disassemble while (!instructions.ContainsKey(addr) && addr >= _start && addr < _start + _len) { // Disassemble this instruction var i = Disassembler.Disassemble(code, (ushort)(addr - _baseAddr + _header), (ushort)addr); // Possible address reference? if (_markWordRefs && i.word_val.HasValue && (i.opCode.flags & (OpCodeFlags.Jumps | OpCodeFlags.RefAddr)) == 0) { i.Comment = "address or value?"; } // Add it instructions.Add(addr, i); // If have a jump address, dump it if (i.next_addr_2.HasValue) { pendingCodePaths.Add(i.next_addr_2.Value); } // Continue if (i.next_addr_1.HasValue) addr = i.next_addr_1.Value; else break; } } } else { // Linear disassembly for (int addr = _start; addr < _start + _len; ) { // Disassemble this instruction var i = Disassembler.Disassemble(code, (ushort)(addr - _baseAddr + _header), (ushort)addr); // Add it instructions.Add(addr, i); // Update address addr += i.bytes; } } // Sort all instructions var sorted = instructions.Values.OrderBy(x => x.addr).ToList(); // Helper for generating DB directives Func<int, int, int, int> FillData = delegate(int from, int to, int index) { for (int j = from; j < to; j++) { var data = code[j - _baseAddr + _header]; // Get the byte var instruction = new Instruction(); if (data >= 0x20 && data <= 0x7f) instruction.Comment = string.Format("'{0}'", (char)data); instruction.addr = (ushort)j; instruction.Asm = string.Format("DB {0}", Disassembler.FormatByte(data)); instruction.next_addr_1 = (ushort)(j + 1); instruction.bytes = 1; // Add to instruction map instructions.Add(instruction.addr, instruction); // Add to sorted list sorted.Insert(index, instruction); index++; } return index; }; // Fill in all unpopulated areas with DBs int expectedNextAddress = _start; for (int i = 0; i < sorted.Count; i++) { var inst = sorted[i]; if (inst.addr != expectedNextAddress) { i = FillData(expectedNextAddress, inst.addr, i); } expectedNextAddress = sorted[i].addr + sorted[i].bytes; } FillData(expectedNextAddress, _start + _len, instructions.Count); // Mark all entry points foreach (var e in _entryPoints) { instructions[e].entryPoint = true; } // Resolve references foreach (var i in instructions) { ushort? ref_addr = i.Value.next_addr_2; if (!ref_addr.HasValue) { if (i.Value.word_val.HasValue && (i.Value.opCode.flags & OpCodeFlags.RefAddr) != 0) ref_addr = i.Value.word_val; } if (ref_addr.HasValue) { for (int stepback = 0; stepback < 6; stepback++) { Instruction target; if (instructions.TryGetValue(ref_addr.Value-stepback, out target)) { if (target.referencedFrom == null) target.referencedFrom = new List<Instruction>(); target.referencedFrom.Add(i.Value); if (stepback != 0) { // patch the original instruction i.Value.Asm = i.Value.Asm.Replace(Disassembler.FormatAddr(ref_addr.Value), Disassembler.FormatAddr(target.addr) + "+" + stepback.ToString()); i.Value.Comment = "reference not aligned to instruction"; } break; } } } } TextWriter targetWriter = Console.Out; if (_outputFile != null) { targetWriter = new StreamWriter(_outputFile); } TextWriter w; if (_htmlMode) { w = targetWriter; } else { w = new TabbedTextWriter(targetWriter); if (_lst) { ((TabbedTextWriter)w).TabStops = new int[] { 32, 40, 48, 56, 64 }; } else { ((TabbedTextWriter)w).TabStops = new int[] { 8, 16, 32 }; } } if (_htmlMode) { w.WriteLine("<html>"); w.WriteLine("<head>"); w.WriteLine("</head>"); w.WriteLine("<body>"); w.WriteLine("<pre><code>"); } // Analyse call graph var cg = new CallGraphAnalyzer(instructions, sorted); Dictionary<int, Proc> procs = cg.Analyse(); // Write out the "ORG" directive if (sorted.Count > 0 && !_lst) { w.WriteLine("\n\tORG\t{0}\n", Disassembler.FormatWord(sorted[0].addr)); } // List it Instruction prev = null; foreach (var i in sorted) { // Blank line after data blocks if (prev != null && prev.opCode == null && i.opCode != null) { w.WriteLine(); } if (_htmlMode) w.Write("<a name=\"L{0:X4}\"></a>", i.addr); // Include cross references? if (_xref && i.referencedFrom != null) { // Ensure a blank line before reference comments if (prev != null && prev.next_addr_1.HasValue) { w.WriteLine(); } if (_lst) w.Write("{0}\t", new string(' ', 23)); w.WriteLine("\t; Referenced from {0}", string.Join(", ", i.referencedFrom.Select(x => Disassembler.FormatAddr(x.addr, true, false)).ToList())); } if (i.entryPoint) { if (_lst) w.Write("{0}\t", new string(' ', 23)); w.WriteLine("\t; Entry Point"); } if (procs.ContainsKey(i.addr)) { if (_lst) w.Write("{0}\t", new string(' ', 23)); w.WriteLine("\t; --- START PROC {0} ---", Disassembler.FormatAddr(i.addr, false, true)); } if (_lst) { w.Write("{0:X4}:", i.addr); for (int j = 0; j < i.bytes; j++) { var data = code[i.addr + j - _baseAddr + _header]; w.Write(" {0:X2}", data); } w.Write(new string(' ', 3 * (6 - i.bytes))); w.Write("\t "); } // Work out label string label = ""; if (i.entryPoint || i.referencedFrom != null || (prev != null && !prev.next_addr_1.HasValue)) { label = Disassembler.FormatAddr(i.addr, false); label += ":"; } // Write the disassembled instruction w.Write("{0}\t{1}", label, i.Asm.Replace(" ", "\t")); // Write out an optional comment if (i.Comment != null) w.Write("\t; {0}", i.Comment); if (_htmlMode) w.WriteLine("</a>"); else w.WriteLine(); // If this instruction doesn't continue on, insert a blank line if (!i.next_addr_1.HasValue) { w.WriteLine(); } // Remember the previous instruction prev = i; } if (_lst) { // Build a list of all possible address references Dictionary<int, AddressInfo> addressInfos = new Dictionary<int, AddressInfo>(); Dictionary<int, PortInfo> portInfos = new Dictionary<int, PortInfo>(); foreach (var i in sorted) { // Does this instruction reference a word value? if (i.word_val.HasValue) { AddressInfo ai; if (!addressInfos.TryGetValue(i.word_val.Value, out ai)) { ai = new AddressInfo(i.word_val.Value); addressInfos.Add(ai.addr, ai); } if ((i.opCode.flags & OpCodeFlags.RefAddr) != 0) { // Known referenced data address ai.DataReferences.Add(i); } if ((i.opCode.flags & OpCodeFlags.Jumps) != 0) { // Known referenced code address ai.CodeReferences.Add(i); } if ((i.opCode.flags & (OpCodeFlags.Jumps | OpCodeFlags.RefAddr)) == 0) { // Potential address ai.PotentialReferences.Add(i); } } // Is it a port reference? if (i.opCode != null && (i.opCode.flags & OpCodeFlags.PortRef) != 0) { // Which port (-1, referenced through a register) int port = -1; if (i.byte_val.HasValue) port = i.byte_val.Value; // Get the port info PortInfo pi; if (!portInfos.TryGetValue(port, out pi)) { pi = new PortInfo(port); portInfos.Add(port, pi); } pi.References.Add(i); } } if (w is TabbedTextWriter) ((TabbedTextWriter)w).TabStops = new int[] { 8, 16, 24, 32 }; // Build a list of all external references var extRefs = addressInfos.Values.Where(x => x.addr < _start || x.addr >= _start + _len).OrderBy(x => x.addr); foreach (var r in extRefs) { if (r.DataReferences.Count > 0 || r.CodeReferences.Count > 0) { w.WriteLine("\nreferences to external address {0}:", Disassembler.FormatAddr((ushort)r.addr, true, false)); foreach (var i in (r.DataReferences.Concat(r.CodeReferences).Concat(r.PotentialReferences)).OrderBy(x => x.addr)) { w.WriteLine("\t{0} {1}", Disassembler.FormatAddr(i.addr, true, false), i.Asm); } } } foreach (var r in addressInfos.Values.Where(x => (x.addr >= _start && x.addr < _start + _len) && x.PotentialReferences.Count > 0).OrderBy(x => x.addr)) { w.WriteLine("\npossible references to internal address {0}:", Disassembler.FormatAddr((ushort)r.addr, true, false)); ListPotentialAddresses(w, r); } foreach (var r in addressInfos.Values.Where(x => (x.addr < _start || x.addr >= _start + _len) && x.PotentialReferences.Count > 0).OrderBy(x => x.addr)) { w.WriteLine("\npossible references to external address {0}:", Disassembler.FormatAddr((ushort)r.addr, true, false)); ListPotentialAddresses(w, r); } foreach (var r in portInfos.Values.OrderBy(x => x.port)) { if (r.port == -1) { w.WriteLine("\nport references through a register:"); } else { w.WriteLine("\nreferences to port {0}", Disassembler.FormatByte((byte)r.port)); } foreach (var i in r.References.OrderBy(x => x.opCode.mnemonic[0]).ThenBy(x => x.addr)) { w.WriteLine("\t{0} {1}", Disassembler.FormatAddr(i.addr, true, false), i.Asm); } } // Dump all procs w.WriteLine("\nProcedures ({0}):", procs.Count); w.WriteLine(" Proc Length References Dependants"); foreach (var p in procs.Values.OrderBy(x=>x.firstInstruction.addr)) { w.WriteLine(" {0} {1:X4} {2,10} {3,10}", Disassembler.FormatAddr(p.firstInstruction.addr, true, true), p.lengthInBytes, p.firstInstruction.referencedFrom == null ? 0 : p.firstInstruction.referencedFrom.Count, p.dependants.Count); } // Dump call graph w.WriteLine("\nCall Graph:"); List<int> CallStack = new List<int>(); Action<int> DumpCallGraph = null; DumpCallGraph = delegate(int addr) { // Display the proc address, indented w.Write("{0}{1}", new String(' ', CallStack.Count * 2), Disassembler.FormatAddr((ushort)addr, true, true)); if (CallStack.Count == 0) { w.Write(" - Entry Point"); } // Is it a recursive call? if (CallStack.Contains(addr)) { w.WriteLine(" - Recursive"); return; } // Is it external? Proc p; if (!procs.TryGetValue(addr, out p)) { w.WriteLine(" - External"); return; } // Dump dependants w.WriteLine(); CallStack.Add(addr); foreach (var d in p.dependants) { DumpCallGraph(d); } CallStack.RemoveAt(CallStack.Count - 1); }; foreach (var ep in _entryPoints.OrderBy(x => x)) { // Get the proc's entry point DumpCallGraph(ep); } } if (_htmlMode) { w.WriteLine("</code></pre>"); w.WriteLine("</body>"); w.WriteLine("</head>"); } // Close file w.Close(); if (_outputFile != null) { targetWriter.Close(); } // Open the file for browsing? if (_autoOpen && _outputFile!=null) { Process.Start(_outputFile); } return 0; }