コード例 #1
0
ファイル: WsdlImporter.cs プロジェクト: radtek/dev2virt
        public string LoadWsdl(string wsdl, DeviceCommand device)
        {
            string compiled = null;

            lock (this)
            {
                try
                {
                    string code = GenerateWsdlProxyClass(wsdl);

                    device.Logger.Add(new Log(LogType.CSharpCode, code));

                    // Finally compile the code into a new .dll assembly
                    compiled = CompileSource(code);
                }
                catch (Exception e)
                {
                    device.Logger.Add(new Log(LogType.WEBError, e.Message));
                }
                // increment our current assembly generation
                LocalCount++;
            }

            return(compiled);
        }
コード例 #2
0
ファイル: Commands.cs プロジェクト: radtek/dev2virt
            public override IoStatus Execute(DeviceCommand device)
            {
                /* first get the service list query */
                IoStatus status = device.usb.DeviceIoControl(usbIOCTL);

                WebServer[] servers = WebServer.ParseWebServer(status);
                if (servers == null)
                {
                    return(status);
                }

                string result = "";

                foreach (WebServer server in servers)
                {
                    result += "<b>" + server.Description + "</b><br/>";
                    HttpRestCommand services = new HttpRestCommand(server.ListServices);
                    status  = services.Execute(device);
                    result += new string(Encoding.ASCII.GetChars(status.buffer, 0, (int)status.size)) + "<br/><br/>";
                    // Now add the new web service wsdl's if the are available
                    server.ParseServices(result, device);
                }

                status.buffer = Encoding.ASCII.GetBytes(result.ToCharArray());
                status.size   = (uint)status.buffer.Length;
                status.error  = USBError.SUCCESS;
                return(status);
            }
コード例 #3
0
ファイル: DeviceCommand.cs プロジェクト: radtek/dev2virt
 internal DeviceCommand(DeviceCommand dev)
 {
     this.usb          = dev.UsbDevice;
     this.parentDevice = dev;
     logs     = new List <Log>();
     commands = new List <Command>();
 }
コード例 #4
0
        private void lDeviceCom_DoubleClick(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection items = lDeviceCom.SelectedItems;
            foreach (ListViewItem item in items)
            {
                DeviceCommand commandDev = currentDevice;
                CloseCommandView();
                commandDev.Logger.Clear();

                DeviceCommand.Command command = commandDev.GetCommand(item.Text);

                currentCommandView = new CommandView();
                bool hasCommands = command is DeviceCommand.ParamCommand;
                if (hasCommands)
                {
                    hasCommands = currentCommandView.DisplayCommand((DeviceCommand.ParamCommand)command, commandDev);
                }
                if (!hasCommands)
                {
                    IoStatus status = command.Execute(commandDev);
                    if ((status.error == USBError.SUCCESS) && (status.size == 0))
                    {
                        continue;
                    }
                    currentCommandView = new CommandView();
                    currentCommandView.DisplayCommand(status, commandDev.Logger.ToArray());
                }

                currentCommandView.Location = new Point(this.Location.X + this.RestoreBounds.Width + 10,
                                                        this.Location.Y - (currentCommandView.Height - this.Height) / 2);
                currentCommandView.Show();
            }
            DeviceCommandChanged(currentDevice, null);
        }
コード例 #5
0
        internal bool DisplayCommand(DeviceCommand.ParamCommand command, DeviceCommand device)
        {
            DeviceCommand.CommandParam[] args = command.Parameters;

            if ((args == null) || (args.Length == 0))
            {
                return(false);
            }

            Device  = device;
            Command = command;

            this.webBrowser.ObjectForScripting = this;

            string result = HTMLstart();

            result += "<div id=\"stylized\" class=\"myform\">";
            result += "<FORM action=\"\" method=\"GET\" name=\"" + ParamsFormName + "\"><br/>";
            result += "<h1>" + command.DisplayName + " form</h1>";
            result += "<p>Command <b>" + command.DisplayName + "</b> requires the following parameters:</p>";

            foreach (DeviceCommand.CommandParam arg in args)
            {
                result += "<label>" + arg.Name + "<span class=\"small\">Input Web Method parameter</span></label>";
                result += "<input type=\"text\" name=\"" + arg.Name + "\"><br/>";
            }
            result += "<button onClick=\"ClientCallback(this.form)\">Perform</button>";
            result += "<div class=\"spacer\"></div>";
            result += "</FORM></div>";
            result += HTMLend();

            webBrowser.DocumentText = result;

            return(true);
        }
コード例 #6
0
        public override void ParseServices(string result, object device)
        {
            DeviceCommand dev = (DeviceCommand)device;

            try
            {
                DeviceCommand newDev = new DeviceCommand(dev);
                newDev.Add(new DeviceCommand.ParentCommand(dev.UsbDevice.DeviceName));

                string name, href;
                int    startHref = -1;
                int    endHref   = -1;
                int    startLi   = 0;
                int    endLi     = 0;
                do
                {
                    if ((startHref = result.IndexOf("href=", startLi)) < 0)
                    {
                        break;
                    }
                    startHref += 6;
                    if ((endHref = result.IndexOf("\"", startHref)) < 0)
                    {
                        break;
                    }
                    if ((startLi = result.LastIndexOf("<li", startHref, startHref - startLi)) < 0)
                    {
                        break;
                    }
                    startLi += 4;
                    if ((endLi = result.LastIndexOf("<a", startHref, startHref - startLi)) < 0)
                    {
                        break;
                    }

                    name = result.Substring(startLi, endLi - startLi);
                    href = result.Substring(startHref, endHref - startHref);

                    if (href.StartsWith("http://"))
                    {
                        int pos = -1;
                        if ((pos = href.IndexOf('/', 7)) > 0)
                        {
                            href = href.Substring(pos);
                        }
                    }

                    newDev.Add(new DeviceCommand.WebServiceCommand(this, name, href));

                    startLi = endHref + 1;
                } while (true);

                DeviceCommand.IssueChange(newDev, dev.UsbDevice.DeviceName + " Web Services...");
            }
            catch (Exception e)
            {
                dev.Logger.Add(new Log(LogType.WEBError, e.Message));
            }
        }
コード例 #7
0
ファイル: WebProxy2Usb.cs プロジェクト: radtek/dev2virt
 private WebProxy2Usb(DeviceCommand device)
 {
     Device       = device;
     tcpListener  = new TcpListener(IPAddress.Loopback, LocalPort);
     listenThread = new Thread(new ThreadStart(ListenForClients));
     tcpListener.Start();
     listenThread.Start();
 }
コード例 #8
0
 public CommandView()
 {
     InitializeComponent();
     webBrowser.AllowNavigation        = true;
     webBrowser.ScriptErrorsSuppressed = false;
     webBrowser.Navigate("about: blank");
     Device  = null;
     Command = null;
 }
コード例 #9
0
 private void DeviceCommandChanged(DeviceCommand newDevice, string message)
 {
     if (message != null)
     {
         ChangeMessage(message);
     }
     DeviceCommand.Command[] commands = newDevice.GetDeviceCommands();
     UpdateCommandList(commands);
     currentDevice = newDevice;
 }
コード例 #10
0
ファイル: Commands.cs プロジェクト: radtek/dev2virt
            public override IoStatus Execute(DeviceCommand device)
            {
                IoStatus status = new IoStatus();

                status.error = USBError.FAIL;
                if (device.parentDevice != null)
                {
                    status.error = USBError.SUCCESS;
                    DeviceCommand.IssueChange(device.parentDevice, DisplayName);
                }

                return(status);
            }
コード例 #11
0
 private void UsbReceiver(IUsbDevice device, bool add)
 {
     if (add)
     {
         currentDevice = new DeviceCommand(device);
         AddListItem(device, true);
         ChangeMessage("Found " + device.DeviceName + " on your system.");
     }
     else
     {
         DeviceCommand.RemoveDeviceCommand(device);
         AddListItem(device, false);
         ChangeMessage(device.DeviceName + " has been removed from your system.");
     }
 }
コード例 #12
0
ファイル: WebProxy2Usb.cs プロジェクト: radtek/dev2virt
        public static WebProxy2Usb GetProxy(DeviceCommand usb)
        {
            WebProxy2Usb proxy = null;

            lock (usbProxies)
            {
                proxy = (WebProxy2Usb)usbProxies[usb];
                if (proxy == null)
                {
                    LocalPort++;
                    proxy           = new WebProxy2Usb(usb);
                    usbProxies[usb] = proxy;
                }
            }
            return(proxy);
        }
コード例 #13
0
ファイル: Commands.cs プロジェクト: radtek/dev2virt
            public override IoStatus Execute(DeviceCommand device)
            {
                IoStatus status = base.Execute(device);

                try
                {
                    string wsdl = new string(Encoding.ASCII.GetChars(status.buffer, 0, (int)status.size));
                    // Import and add new methods for this
                    Server.ParseWsdl(wsdl.Substring(wsdl.IndexOf("<?xml")), DisplayName, device);
                }
                catch (Exception e)
                {
                    device.Logger.Add(new Log(LogType.WEBError, e.Message));
                }
                return(status);
            }
コード例 #14
0
ファイル: Commands.cs プロジェクト: radtek/dev2virt
            public override IoStatus Execute(DeviceCommand device)
            {
                response = HttpParser.HTTPResponse.InitResponse();
                // Log the request
                device.Logger.Add(new Log(LogType.HttpQuery, rawRequest));
                // Issue the request
                IoStatus status = RestExecute(device, Encoding.ASCII.GetBytes(rawRequest.ToCharArray()));

                // Log the reply
                try
                {
                    device.Logger.Add(new Log(LogType.HttpResponse, new string(Encoding.ASCII.GetChars(status.buffer, 0, (int)status.size))));
                }
                catch (Exception) { }

                return(status);
            }
コード例 #15
0
ファイル: Commands.cs プロジェクト: radtek/dev2virt
            public override IoStatus Execute(DeviceCommand device)
            {
                IoStatus status = new IoStatus();

                // Get all host controllers active on the machine
                List <USBView.USBController> hostList = USBView.GetUSBControllers();

                List <string> devPaths = UsbApi.GetDevices(null, UsbApi.GUID_CLASS_USB_HOST_CONTROLLER);

                string result  = "<ul class=\"mktree\" id=\"USBView\">";
                string imgPath = ResourcePath + "\\";

                foreach (USBView.USBController hostC in hostList)
                {
                    result += "<li><img src=\"" + imgPath + "controller.ico\"/>"
                              + hostC.ControllerName + "<ul>";

                    USBView.USBController.USBHub rootHub = hostC.RootHub;
                    result += "<li><img src=\"" + imgPath + "hub.ico\"/>" + rootHub.HubName + "</li><ul>";
                    List <USBView.USBController.USBHub.USBPort> portList = rootHub.Ports;
                    foreach (USBView.USBController.USBHub.USBPort port in portList)
                    {
                        result += port.HasAttachedDevice?
                                  "<li><img src=\"" + imgPath + "controller.ico\"/>" : "<li><img src=\"" + imgPath + "port.ico\"/>";
                        result += port.PortInformation;
                        List <USBView.USBController.USBHub.USBPort.Property> properties = port.Properties;
                        if (properties.Count > 0)
                        {
                            result += "<ul>";
                            foreach (USBView.USBController.USBHub.USBPort.Property prop in properties)
                            {
                                result += "<li><b>" + prop.Key + "</b>" + prop.Value + "</li>";
                            }
                            result += "</ul>";
                        }
                        result += "</li>";
                    }
                    result += "</ul></ul></li>";
                }
                result       += "</ul>";
                status.buffer = Encoding.ASCII.GetBytes(result.ToCharArray());
                status.size   = (uint)status.buffer.Length;
                status.error  = USBError.SUCCESS;
                return(status);
            }
コード例 #16
0
ファイル: AssemblyImporter.cs プロジェクト: radtek/dev2virt
            public override IoStatus Execute(DeviceCommand device)
            {
                IoStatus status = new IoStatus();

                ParameterInfo[] parameters = classMethod.GetParameters();

                try
                {
                    object[] args = null;
                    if (currentArgs != null)
                    {
                        args = new object[currentArgs.Length];
                        for (int i = 0; i < currentArgs.Length; i++)
                        {
                            args[i] = currentArgs[i].Value;
                        }
                    }
                    // Dynamically Invoke the method
                    Object Result = classMethod.Invoke(classObject, args);
                    status.error = USBError.SUCCESS;
                    string res = null;
                    if (Result.GetType() == typeof(string))
                    {
                        res = (string)(Result);
                    }
                    else
                    {
                        res = Result.ToString();
                    }
                    status.buffer = Encoding.ASCII.GetBytes(res.ToCharArray());
                    status.size   = (uint)status.buffer.Length;
                }
                catch (Exception e)
                {
                    status.error = USBError.FAIL;
                    device.Logger.Add(new Log(LogType.WEBError, e.Message));
                }

                return(status);
            }
コード例 #17
0
ファイル: DeviceCommand.cs プロジェクト: radtek/dev2virt
 internal DeviceCommand(IUsbDevice usb)
 {
     this.usb          = usb;
     this.parentDevice = null;
     logs     = new List <Log>();
     commands = new List <Command>();
     // create the default IOCTL commands
     IOCTLcommand[] IoctlS = usb.Functions;
     if (IoctlS != null)
     {
         foreach (IOCTLcommand ioctl in IoctlS)
         {
             commands.Add(new FunctionCommand(ioctl));
             lock (devices)
             {
                 devices.Add(this);
             }
         }
     }
     // create the device information command
     commands.Add(new InfoCommand());
 }
コード例 #18
0
ファイル: Commands.cs プロジェクト: radtek/dev2virt
            public IoStatus RestExecute(DeviceCommand device, byte[] request)
            {
                completionStatus       = new IoStatus();
                completionStatus.error = USBError.FAIL;

                lock (device.usb)
                {
                    lock (completionLock)
                    {
                        device.usb.WriteDone += completionWrite;
                        completionStatus.size = (uint)request.Length;
                        device.usb.IssueWrite(request);
                        Monitor.Wait(completionLock, 5000);
                        device.usb.WriteDone -= completionWrite;
                    }

                    if (completionStatus.error != USBError.SUCCESS)
                    {
                        return(completionStatus);
                    }

                    // Reset the IoStatus to begin reading
                    completionStatus.size = 0;

                    lock (completionLock)
                    {
                        device.usb.ReadDone += completionRead;
                        device.usb.StartRead();
                        Monitor.Wait(completionLock, 5000);
                        device.usb.StopRead();
                        device.usb.ReadDone -= completionRead;
                    }
                }

                return(completionStatus);
            }
コード例 #19
0
ファイル: WsdlImporter.cs プロジェクト: radtek/dev2virt
 /// <summary>
 /// Generates an unique new assembly based on the device
 /// </summary>
 public WsdlImporter(DeviceCommand device)
 {
     LocalAssembly = "Usb2WebService";
     LocalCount    = 0;
 }
コード例 #20
0
ファイル: DeviceCommand.cs プロジェクト: radtek/dev2virt
 public static void IssueChange(DeviceCommand dev, string message)
 {
     DeviceEvent(dev, message);
 }
コード例 #21
0
 public VirtView()
 {
     InitializeComponent();
     currentDevice      = null;
     currentCommandView = null;
 }
コード例 #22
0
ファイル: DeviceCommand.cs プロジェクト: radtek/dev2virt
 public abstract IoStatus Execute(DeviceCommand device);
コード例 #23
0
 private void UpdateCommands(IUsbDevice dev)
 {
     DeviceCommand.Command[] commands = DeviceCommand.GetDeviceCommands(dev);
     UpdateCommandList(commands);
 }
コード例 #24
0
        public override void ParseWsdl(string wsdl, string service, object device)
        {
            DeviceCommand dev = (DeviceCommand)device;

            lock (this)
            {
                if (Importer == null)
                {
                    Importer = new WsdlImporter(dev);
                }
            }

            if (wsdl.EndsWith("0\r\n\r\n"))
            {
                wsdl = wsdl.Substring(0, wsdl.Length - 5);
            }

            DeviceCommand newDev = new DeviceCommand(dev);

            // Set the proxy server to our own application proxy in order to direct the http traffic to the USB device
            WebProxy2Usb usbProxy = WebProxy2Usb.GetProxy(newDev);
            IWebProxy    webProxy = new WebProxy(usbProxy.ProxyAddress, true);

            string compiled = Importer.LoadWsdl(wsdl, dev);

            if (compiled == null)
            {
                return;
            }

            dev.Logger.Add(new Log(LogType.DotNetAssembly, compiled));

            AssemblyImporter.AssemblyCommand[] webMethods = null;

            try
            {
                webMethods = AssemblyImporter.LoadAssembly(compiled);
            }
            catch (Exception e)
            {
                dev.Logger.Add(new Log(LogType.WEBError, e.Message));
                return;
            }

            newDev.Add(new DeviceCommand.ParentCommand(service));

            foreach (AssemblyImporter.AssemblyCommand method in webMethods)
            {
                try
                {
                    SoapHttpClientProtocol soapMethod = (SoapHttpClientProtocol)method.Class;
                    string url = soapMethod.Url;
                    int    pos = url.IndexOf("http://") + 7;
                    pos = url.IndexOf("/", pos);
                    if (pos > 0)
                    {
                        soapMethod.Url = usbProxy.ProxyAddress + url.Substring(pos);
                    }

                    newDev.Add(method);
                }
                catch (Exception e)
                {
                    dev.Logger.Add(new Log(LogType.WEBError, e.Message));
                }

                DeviceCommand.IssueChange(newDev, service + "'s Web Service Methods...");
            }
        }
コード例 #25
0
ファイル: WebProxy2Usb.cs プロジェクト: radtek/dev2virt
 public override IoStatus Execute(DeviceCommand device)
 {
     response = HttpParser.HTTPResponse.InitResponse();
     return(RestExecute(device, toWrite));
 }