Esempio n. 1
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);
        }
Esempio n. 2
0
 public static extern int NtOpenFile(
     out IntPtr FileHandle,
     FileAccessRights DesiredAccess,
     ObjectAttributes ObjAttr,
     [In][Out] IoStatus IoStatusBlock,
     ShareMode ShareAccess,
     FileOpenOptions OpenOptions);
Esempio n. 3
0
            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);
            }
Esempio n. 4
0
            private void DataRead(IoStatus status)
            {
                lock (completionLock)
                {
                    if (completionStatus.size == 0)
                    {
                        completionStatus = status;
                    }
                    else
                    {
                        // concat the 2 IoStatus
                        byte[] bufAux = completionStatus.buffer;
                        completionStatus.buffer = new byte[completionStatus.size + status.size];
                        Buffer.BlockCopy(bufAux, 0, completionStatus.buffer, 0, (int)completionStatus.size);
                        Buffer.BlockCopy(status.buffer, 0, completionStatus.buffer, (int)completionStatus.size, (int)status.size);
                        completionStatus.size += status.size;
                        completionStatus.error = status.error;
                    }

                    if (HasFinished(completionStatus))
                    {
                        Monitor.PulseAll(completionLock);
                    }
                }
            }
Esempio n. 5
0
 protected override bool HasFinished(IoStatus status)
 {
     if (status.size >= response.expectedSize)
     {
         return(HttpParser.ParseHttp(status, ref response));
     }
     return(false);
 }
Esempio n. 6
0
 public static extern int NtFsControlFile(
     SafeFileHandle FileHandle,
     IntPtr Event,
     IntPtr ApcRoutine,
     IntPtr ApcContext,
     [Out] IoStatus IoStatusBlock,
     uint FSControlCode,
     [In] byte[] InputBuffer,
     int InputBufferLength,
     [Out] byte[] OutputBuffer,
     int OutputBufferLength
     );
Esempio n. 7
0
        public QsysIoFrame(IoStatus statusComponent)
        {
            _statusComponent = statusComponent;

            if (_statusComponent == null)
            {
                throw new Exception("Component cannot be null");
            }

            _componentName = _statusComponent.Name;
            _statusComponent.StatusChanged += StatusComponentOnStatusChanged;
            _deviceCommunicating            = statusComponent.Status != "Not Present";
        }
Esempio n. 8
0
 static void UnmountDfsShare(string drive_path)
 {
     using (SafeFileHandle handle = OpenFile(@"\Device\DfsClient", FileAccessRights.MaximumAllowed, ShareMode.None, FileOpenOptions.None, false))
     {
         List <byte> buffer = new List <byte>();
         buffer.AddRange(new byte[4]);
         buffer.AddRange(GetBytes(drive_path));
         byte[]   output_data = new byte[8];
         IoStatus status      = new IoStatus();
         StatusToNtException(NtFsControlFile(handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
                                             status, DELETE_DRIVE_LETTER, buffer.ToArray(), buffer.Count, output_data, output_data.Length));
     }
 }
Esempio n. 9
0
            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);
            }
Esempio n. 10
0
        private void HandleClient(object client)
        {
            TcpClient     tcpClient    = (TcpClient)client;
            NetworkStream clientStream = tcpClient.GetStream();

            byte[] message   = new byte[4096];
            int    bytesRead = 0;

            try
            {
                bool done = true;
                do
                {
                    // blocks until a client sends a message
                    bytesRead = clientStream.Read(message, 0, 4096);
                    if (bytesRead == 0)
                    {
                        // the client has disconnected from the server
                        tcpClient.Close();
                        return;
                    }

                    // log the http query
                    Device.Logger.Add(new Log(LogType.HttpQuery, new string(Encoding.ASCII.GetChars(message, 0, bytesRead))));

                    //message has successfully been received
                    SoapMethod usbMethod = new SoapMethod(message, bytesRead);

                    IoStatus status = usbMethod.Execute(Device);

                    if (status.error == USBError.SUCCESS)
                    {
                        done = !HttpParser.IsPartialResponse(usbMethod.HTTPStatus);
                        clientStream.Write(status.buffer, 0, (int)status.size);
                    }
                    else
                    {
                        done = true;
                    }

                    // log the http response
                    Device.Logger.Add(new Log(LogType.HttpResponse, new string(Encoding.ASCII.GetChars(status.buffer, 0, (int)status.size))));
                } while (!done);
            }
            catch (Exception)
            {
                tcpClient.Close();
            }
        }
Esempio n. 11
0
            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);
            }
Esempio n. 12
0
 private void DataWrite(IoStatus status)
 {
     lock (completionLock)
     {
         if (status.error == USBError.SUCCESS)
         {
             completionStatus.size -= status.size;
             if (completionStatus.size > 0)
             {
                 return;
             }
         }
         completionStatus = status;
         Monitor.PulseAll(completionLock);
     }
 }
Esempio n. 13
0
        public static SafeFileHandle OpenFile(string name, FileAccessRights DesiredAccess, ShareMode ShareAccess, FileOpenOptions OpenOptions, bool inherit)
        {
            AttributeFlags flags = AttributeFlags.CaseInsensitive;

            if (inherit)
            {
                flags |= AttributeFlags.Inherit;
            }
            using (ObjectAttributes obja = new ObjectAttributes(name, flags))
            {
                IntPtr   handle;
                IoStatus iostatus = new IoStatus();
                int      status   = NtOpenFile(out handle, DesiredAccess, obja, iostatus, ShareAccess, OpenOptions);
                StatusToNtException(status);
                return(new SafeFileHandle(handle, true));
            }
        }
Esempio n. 14
0
            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);
            }
Esempio n. 15
0
            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);
            }
Esempio n. 16
0
        static void MountDfsShare(string dfs_path, string drive_path)
        {
            using (SafeFileHandle handle = OpenFile(@"\Device\DfsClient", FileAccessRights.MaximumAllowed, ShareMode.None, FileOpenOptions.None, false))
            {
                IoStatus status = new IoStatus();

                byte[] dfs_path_bytes   = GetBytes(dfs_path);
                byte[] drive_path_bytes = GetBytes(drive_path);
                DFsCreateDriveParameters create_drive = new DFsCreateDriveParameters();

                create_drive.drive_path_length = (ushort)drive_path_bytes.Length;
                create_drive.dfs_path_length   = (ushort)dfs_path_bytes.Length;

                List <byte> buffer = new List <byte>();
                buffer.AddRange(StructToBytes(create_drive));
                buffer.AddRange(drive_path_bytes);
                buffer.AddRange(dfs_path_bytes);

                StatusToNtException(NtFsControlFile(handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, status, CREATE_DRIVE_LETTER, buffer.ToArray(), buffer.Count, new byte[0], 0));
            }
        }
Esempio n. 17
0
        // this should be called on the same thread as the GUI
        public void BrowserCallback(string data)
        {
            string[] values = data.Split('\n');
            // set the parameters
            DeviceCommand.CommandParam[] args = Command.Parameters;
            int i = 0;

            foreach (string value in values)
            {
                if (i >= args.Length)
                {
                    break;
                }
                args[i++].Value = value;
            }
            Command.Parameters = args;

            IoStatus status = Command.Execute(Device);

            DisplayCommand(status, Device.Logger.ToArray());
        }
Esempio n. 18
0
            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);
            }
Esempio n. 19
0
            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);
            }
Esempio n. 20
0
        internal void DisplayCommand(IoStatus status, Log[] logs)
        {
            string error  = null;
            string result = null;

            switch (status.error)
            {
            case USBError.SUCCESS:
                error = "Command Succedded"; break;

            case USBError.DISCONNECTED:
                error = "Device has been disconnected!"; break;

            case USBError.OVERFLOW:
                error = "Overflow detected!"; break;

            case USBError.NOTFOUND:
                error = "Command not found!"; break;

            case USBError.WIN_API_SPECIFIC:
            case USBError.FAIL:
                error = "Catastrophic error encountered!"; break;
            }

            result  = HTMLstart();
            result += "<b>Command Status: </b> " + error + "<br/><br/>";
            if (status.buffer != null)
            {
                result += Encoding.ASCII.GetString(status.buffer, 0, (int)status.size);
            }
            else
            {
                result += "No information returned!";
            }

            // try to display the xml information in Internet Explorer
            result = ExpandXml2Html(result);

            // display the logs
            if ((logs != null) && (logs.Length > 0))
            {
                string imgPath = DeviceCommand.ResourcePath + "\\";
                result += "<br/><br/><ul class=\"mktree\" id=\"USBLogs\">";
                result += "<li><img src=\"" + imgPath + "port.ico\"/> Command Logs<ul>";
                foreach (Log log in logs)
                {
                    result += "<li><img src=\"" + imgPath + "bang.ico\"/>";
                    switch (log.Type)
                    {
                    case LogType.HttpQuery:
                        result += " USB2Web Query";
                        result += "<ul><li>" + log.Message + "</li></ul></li>";
                        break;

                    case LogType.HttpResponse:
                        result += " Web2USB Response";
                        result += "<ul><li>" + ExpandXml2Html(log.Message) + "</li></ul></li>";
                        break;

                    case LogType.CSharpCode:
                        result += " C# Web Service Code";
                        result += "<ul><pre class=\"prettyprint lang-cs\">" + log.Message + "</pre></ul></li>";
                        break;

                    case LogType.DotNetAssembly:
                        result += " Loaded .Net Assembly";
                        result += "<ul><li>" + log.Message + "</li></ul></li>";
                        break;

                    case LogType.USBError:
                    case LogType.WEBError:
                        result += " Web Service Error";
                        result += "<ul><li>" + log.Message + "</li></ul></li>";
                        break;
                    }
                }
                result += "</ul></li></ul>";
            }
            result += HTMLend();

            webBrowser.DocumentText = result;
        }
Esempio n. 21
0
 public IoSyncStatus(IoStatus status, NotifiableEvent <IoStatus> notifiableEvent)
 {
     this.status          = status;
     this.notifiableEvent = notifiableEvent;
 }
Esempio n. 22
0
 public IoSyncStatus(IoStatus status, NotifiableEvent<IoStatus> notifiableEvent)
 {
     this.status = status;
     this.notifiableEvent = notifiableEvent;
 }
Esempio n. 23
0
        public static bool ParseHttp(IoStatus response, ref HTTPResponse httpStatus)
        {
            int pos = (int)httpStatus.parsedPos;

            while ((pos >= 0) && (pos < response.size))
            {
                switch (httpStatus.ParseState)
                {
                case ParseState.HttpVersion:
                    pos = skipWhitespace(response.buffer, (int)httpStatus.parsedPos, (int)response.size);
                    if ((pos = nextWhitespace(response.buffer, pos, (int)response.size)) >= 0)
                    {
                        httpStatus.parsedPos  = (uint)pos;
                        httpStatus.ParseState = ParseState.HttpStatus;
                    }
                    break;

                case ParseState.HttpStatus:
                    pos = skipWhitespace(response.buffer, pos, (int)response.size);
                    if ((pos = nextWhitespace(response.buffer, pos, (int)response.size)) >= 0)
                    {
                        try
                        {
                            string status = new String(Encoding.ASCII.GetChars(response.buffer, (int)httpStatus.parsedPos, pos - (int)httpStatus.parsedPos));
                            httpStatus.status = Int32.Parse(status);
                        } catch (Exception) {}
                        if ((pos = skipNewline(response.buffer, pos, (int)response.size)) > 0)
                        {
                            httpStatus.parsedPos  = (uint)pos;
                            httpStatus.ParseState = ParseState.HttpHeader;
                        }
                    }
                    break;

                case ParseState.HttpHeader:
                    if (isNewline(response.buffer, pos, (int)response.size))
                    {
                        pos += 2;
                        httpStatus.parsedPos     = (uint)pos;
                        httpStatus.ParseState    = ParseState.HttpBody;
                        httpStatus.expectedSize += httpStatus.parsedPos;
                        break;
                    }
                    if ((pos = skipNewline(response.buffer, pos, (int)response.size)) > 0)
                    {
                        ParseBodyEncoding(ref httpStatus, response.buffer, (int)httpStatus.parsedPos, pos);
                        httpStatus.parsedPos = (uint)pos;
                    }
                    break;

                case ParseState.HttpBody:
                {
                    switch (httpStatus.encoded)
                    {
                    case HttpBodyType.Chunked:
                        if ((pos = nextNewline(response.buffer, (int)httpStatus.parsedPos, (int)response.size)) >= 0)
                        {
                            int chunk = 0;
                            try
                            {
                                string toParse = new string(Encoding.ASCII.GetChars(response.buffer, (int)httpStatus.parsedPos, pos - (int)httpStatus.parsedPos));
                                chunk = Int32.Parse(toParse, System.Globalization.NumberStyles.HexNumber);
                                httpStatus.expectedSize = (uint)pos + (uint)chunk + 4;             // add the chunk's last \r\n\r\n chars
                                httpStatus.parsedPos    = (uint)pos + (uint)chunk + 4;
                            }
                            catch (Exception) { chunk = -1; }

                            return(chunk == 0);
                        }
                        break;

                    case HttpBodyType.ContentType:
                    case HttpBodyType.Unknown:
                        break;
                    }

                    return(response.size >= httpStatus.expectedSize);
                }
                }
            }

            return(false);
        }
Esempio n. 24
0
        private object InitalizeProcess()
        {
            CloudLog.Debug("{0} Initializing has started...", GetType().Name);
            var sw = new Stopwatch();

            sw.Start();

            if (!string.IsNullOrEmpty(_username))
            {
                var logonResponse = Request("Logon", new
                {
                    User     = _username,
                    Password = _password
                });

                Debug.WriteSuccess(GetType().Name + " Login Response", logonResponse);
            }

            if (_components.Count == 0)
            {
                CloudLog.Debug("{0} has no component details... requesting...", GetType().Name);
                var response = Request("Component.GetComponents", null);

                CloudLog.Debug("QsysCore has received list of user defined components, count = {0}",
                               response.Result.Children().Count());

                foreach (var component in response.Result.Children())
                {
                    CloudLog.Debug("QsysCore has compononent \"{0}\"", component["Name"].Value <string>());
                }

                foreach (var component in response.Result.Children()
                         .Where(c => _userDefinedComponentNames.Contains(c["Name"].Value <string>())))
                {
                    var name = component["Name"].Value <string>();
                    if (_components.ContainsKey(name))
                    {
                        continue;
                    }
                    switch (component["Type"].Value <string>())
                    {
                    case "audio_file_player":
                        _components[name] = new AudioFilePlayer(this, component);
                        break;

                    case "mixer":
                        _components[name] = new Mixer(this, component);
                        break;

                    case "system_mute":
                    case "gain":
                        _components[name] = new Gain(this, component);
                        break;

                    case "scriptable_controls":
                        _components[name] = new ScriptableControls(this, component);
                        break;

                    case "snapshot_controller":
                        _components[name] = new SnapshotController(this, component);
                        break;

                    case "softphone":
                        _components[name] = new SoftPhone(this, component);
                        break;

                    case "pots_control_status_core":
                        _components[name] = new PotsPhone(this, component);
                        break;

                    case "signal_presence":
                        _components[name] = new SignalPresence(this, component);
                        break;

                    case "sine":
                        _components[name] = new Sine(this, component);
                        break;

                    case "router_with_output":
                        _components[name] = new RouterWithOutput(this, component);
                        break;

                    case "io_status":
                        _components[name] = new IoStatus(this, component);
                        break;

                    default:
                        _components[name] = new GenericComponent(this, component);
                        break;
                    }
                }
            }
            else
            {
                CloudLog.Debug("{0} has component details... updating...", GetType().Name);
                foreach (var component in this)
                {
                    component.UpdateAsync();
                }
            }

            _initialized = true;

            sw.Stop();
            CloudLog.Debug("{0} has initialized, process time = {1}", GetType().Name, sw.Elapsed);

            OnHasIntitialized(this);

            DefaultChangeGroup.PollAuto(1.0);

            return(null);
        }
Esempio n. 25
0
 protected abstract bool HasFinished(IoStatus status);
Esempio n. 26
0
 private void StatusComponentOnStatusChanged(IoStatus statusComponent)
 {
     _deviceCommunicating = statusComponent.Status != "Not Present";
 }
 internal NtMailslotFile(SafeKernelObjectHandle handle, IoStatus io_status)
     : base(handle, io_status)
 {
 }