Example #1
0
        public void GetListingTest()
        {
            DeviceData device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State = DeviceState.Online
            };

            List<FileStatistics> value = null;

            this.RunTest(
                OkResponses(2),
                ResponseMessages(".", "..", "sdcard0", "emulated"),
                Requests("host:transport:169.254.109.177:5555", "sync:"),
                SyncRequests(SyncCommand.LIST, "/storage"),
                new SyncCommand[] { SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DENT, SyncCommand.DONE },
                new byte[][]
                {
                    new byte[] { 233, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86 },
                    new byte[] { 237, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86 },
                    new byte[] { 255, 161, 0, 0, 24, 0, 0, 0, 152, 130, 56, 86 },
                    new byte[] { 109, 65, 0, 0, 0, 0, 0, 0, 152, 130, 56, 86 }
                },
                null,
                () =>
                {
                    using (SyncService service = new SyncService(device))
                    {
                        value = service.GetDirectoryListing("/storage").ToList();
                    }
                });

            Assert.AreEqual(4, value.Count);

            var time = new DateTime(2015, 11, 3, 9, 47, 4, DateTimeKind.Utc).ToLocalTime();

            var dir = value[0];
            Assert.AreEqual(".", dir.Path);
            Assert.AreEqual((UnixFileMode)16873, dir.FileMode);
            Assert.AreEqual(0, dir.Size);
            Assert.AreEqual(time, dir.Time);

            var parentDir = value[1];
            Assert.AreEqual("..", parentDir.Path);
            Assert.AreEqual((UnixFileMode)16877, parentDir.FileMode);
            Assert.AreEqual(0, parentDir.Size);
            Assert.AreEqual(time, parentDir.Time);

            var sdcard0 = value[2];
            Assert.AreEqual("sdcard0", sdcard0.Path);
            Assert.AreEqual((UnixFileMode)41471, sdcard0.FileMode);
            Assert.AreEqual(24, sdcard0.Size);
            Assert.AreEqual(time, sdcard0.Time);

            var emulated = value[3];
            Assert.AreEqual("emulated", emulated.Path);
            Assert.AreEqual((UnixFileMode)16749, emulated.FileMode);
            Assert.AreEqual(0, emulated.Size);
            Assert.AreEqual(time, emulated.Time);
        }
Example #2
0
        public void InstallPackageTest()
        {
            var syncService = new DummySyncService();
            Factories.SyncServiceFactory = (d) => syncService;

            var adbClient = new DummyAdbClient();

            adbClient.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            adbClient.Commands.Add("pm install /storage/sdcard0/tmp/test.txt", string.Empty);
            adbClient.Commands.Add("rm /storage/sdcard0/tmp/test.txt", string.Empty);

            AdbClient.Instance = adbClient;

            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            PackageManager manager = new PackageManager(device);
            manager.InstallPackage("test.txt", false);
            Assert.AreEqual(3, adbClient.ReceivedCommands.Count);
            Assert.AreEqual("pm install /storage/sdcard0/tmp/test.txt", adbClient.ReceivedCommands[1]);
            Assert.AreEqual("rm /storage/sdcard0/tmp/test.txt", adbClient.ReceivedCommands[2]);

            Assert.AreEqual(1, syncService.UploadedFiles.Count);
            Assert.IsTrue(syncService.UploadedFiles.ContainsKey("/storage/sdcard0/tmp/test.txt"));
        }
 public void Add(DeviceData data)
 {
     lock (_lock)
     {
         _valueDictionary[data.DataType] = data.DataValue;
     }
 }
        public double GetCenterLineY(LaneData[] lanes, DeviceData[] devs, Size panelSize)
        {
            if (lanes == null || lanes.Length <= 0)
                return 200;

            return panelSize.Height /2;
        }
Example #5
0
        public Task ExecuteRemoteCommand(string command, DeviceData device, IShellOutputReceiver rcvr, CancellationToken cancellationToken, int maxTimeToOutputResponse)
        {
            this.ReceivedCommands.Add(command);

            if (this.Commands.ContainsKey(command))
            {
                if (rcvr != null)
                {
                    StringReader reader = new StringReader(this.Commands[command]);

                    while (reader.Peek() != -1)
                    {
                        rcvr.AddOutput(reader.ReadLine());
                    }

                    rcvr.Flush();
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(command));
            }

            return Task.FromResult(true);
        }
Example #6
0
        public void InstallRemotePackageTest()
        {
            var adbClient = new DummyAdbClient();

            adbClient.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            adbClient.Commands.Add("pm install /data/test.apk", string.Empty);
            adbClient.Commands.Add("pm install -r /data/test.apk", string.Empty);

            AdbClient.Instance = adbClient;

            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            PackageManager manager = new PackageManager(device);
            manager.InstallRemotePackage("/data/test.apk", false);

            Assert.AreEqual(2, adbClient.ReceivedCommands.Count);
            Assert.AreEqual("pm install /data/test.apk", adbClient.ReceivedCommands[1]);

            manager.InstallRemotePackage("/data/test.apk", true);

            Assert.AreEqual(3, adbClient.ReceivedCommands.Count);
            Assert.AreEqual("pm install -r /data/test.apk", adbClient.ReceivedCommands[2]);
        }
Example #7
0
 public XNAKeyboard(Game game)
 {
     var allKeys = Enum.GetValues(typeof(Keys));
     _keys = new Keys[allKeys.Length];
     _datas = new DeviceData[allKeys.Length];
     for (int k = 0; k < allKeys.Length; k++)
     {
         _keys[k] = (Keys)allKeys.GetValue(k);
         _datas[k] = new DeviceData() { Device = Name, Event = Enum.GetName(typeof(Keys), _keys[k]), Data = 1.0f };
     }
 }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageManager"/> class.
        /// </summary>
        /// <param name="device">
        /// The device on which to look for packages.
        /// </param>
        /// <param name="thirdPartyOnly">
        /// <see langword="true"/> to only indicate third party applications;
        /// <see langword="false"/> to also include built-in applications.
        /// </param>
        public PackageManager(DeviceData device, bool thirdPartyOnly = false)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            this.Device = device;
            this.Packages = new Dictionary<string, string>();
            this.ThirdPartyOnly = thirdPartyOnly;
            this.RefreshPackages();
        }
Example #9
0
        public void StatTest()
        {
            FileStatistics stats = new FileStatistics();

            var mock = new Mock<ISyncService>();
            mock.Setup(m => m.Stat("/test")).Returns(stats);

            Factories.SyncServiceFactory = (d) => mock.Object;

            var device = new DeviceData();

            Assert.AreEqual(stats, device.Stat("/test"));
        }
Example #10
0
        public XNAMouse(Game game)
        {
            _dataLMB = new DeviceData() { Device = Name, Event = "LMB", Data = 1.0f };
            _dataMMB = new DeviceData() { Device = Name, Event = "MMB", Data = 1.0f };
            _dataRMB = new DeviceData() { Device = Name, Event = "RMB", Data = 1.0f };
            _dataX = new DeviceData() { Device = Name, Event = "X", Data = 0.0f };
            _dataY = new DeviceData() { Device = Name, Event = "Y", Data = 0.0f };

            _center = new Point(game._graphics.GraphicsDevice.Viewport.Width / 2, game._graphics.GraphicsDevice.Viewport.Height / 2);
            if (FreezeOnCenter)
            {
                Mouse.SetPosition(_center.X, _center.Y);
            }
            _lastPosition = Mouse.GetState().Position;
        }
Example #11
0
        public void PackagesPropertyTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();
            client.Commands.Add("pm list packages -f", "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d");
            AdbClient.Instance = client;
            PackageManager manager = new PackageManager(device);

            Assert.IsTrue(manager.Packages.ContainsKey("com.android.gallery3d"));
            Assert.AreEqual("/system/app/Gallery2/Gallery2.apk", manager.Packages["com.android.gallery3d"]);
        }
Example #12
0
        public void GetEnvironmentVariablesTest()
        {
            var adbClient = new DummyAdbClient();
            AdbClient.Instance = adbClient;

            adbClient.Commands.Add(EnvironmentVariablesReceiver.PrintEnvCommand, "a=b");

            var device = new DeviceData();

            var variables = device.GetEnvironmentVariables();
            Assert.IsNotNull(variables);
            Assert.AreEqual(1, variables.Keys.Count);
            Assert.IsTrue(variables.ContainsKey("a"));
            Assert.AreEqual("b", variables["a"]);
        }
		public async Task<DeviceDataCollection> GetDeviceData()
		{
			return await Task.Run(() =>
				{
					var deviceDataCol = new DeviceDataCollection();

					var csv = DataProvider.GetResourceCsvFileData(@"BluemixIoT.Data.air_quality.csv");
					for (var i = 1; i < csv.Rows.Count; i++)
					{
						var data = csv[i, "d"];
						var deviceData = new DeviceData
						{
							Id = csv[i, "_id"],
							Data = JsonConvert.DeserializeObject<AirQuality>(csv[i, "d"]),
							Timestamp = Convert.ToDateTime(csv[i, "ts"]),
						};
						deviceDataCol.Add(deviceData);
					}

					return deviceDataCol;
				});


		}
Example #14
0
 public XNAGamePad(Game game)
 {
     _dataA = new DeviceData() { Device = Name, Event = "A", Data = 1.0f };
     _dataB = new DeviceData() { Device = Name, Event = "B", Data = 1.0f };
     _dataX = new DeviceData() { Device = Name, Event = "X", Data = 1.0f };
     _dataY = new DeviceData() { Device = Name, Event = "Y", Data = 1.0f };
     _dataBack = new DeviceData() { Device = Name, Event = "Back", Data = 1.0f };
     _dataStart = new DeviceData() { Device = Name, Event = "Start", Data = 1.0f };
     _dataBigButton = new DeviceData() { Device = Name, Event = "BigButton", Data = 1.0f };
     _dataLeftShoulder = new DeviceData() { Device = Name, Event = "LeftShoulder", Data = 1.0f };
     _dataRightShoulder = new DeviceData() { Device = Name, Event = "RightShoulder", Data = 1.0f };
     _dataLeftStick = new DeviceData() { Device = Name, Event = "LeftStick", Data = 1.0f };
     _dataRightStick = new DeviceData() { Device = Name, Event = "RightStick", Data = 1.0f };
     _dataUp = new DeviceData() { Device = Name, Event = "Up", Data = 1.0f };
     _dataDown = new DeviceData() { Device = Name, Event = "Down", Data = 1.0f };
     _dataLeft = new DeviceData() { Device = Name, Event = "Left", Data = 1.0f };
     _dataRight = new DeviceData() { Device = Name, Event = "Right", Data = 1.0f };
     _dataLeftX = new DeviceData() { Device = Name, Event = "LeftX", Data = 0.0f };
     _dataLeftY = new DeviceData() { Device = Name, Event = "LeftY", Data = 0.0f };
     _dataRightX = new DeviceData() { Device = Name, Event = "RightX", Data = 0.0f };
     _dataRightY = new DeviceData() { Device = Name, Event = "RightY", Data = 0.0f };
     _dataLeftTrigger = new DeviceData() { Device = Name, Event = "LeftTrigger", Data = 0.0f };
     _dataRightTrigger = new DeviceData() { Device = Name, Event = "RightTrigger", Data = 0.0f };
 }
Example #15
0
        public void ListPropertiesTest()
        {
            DeviceData device = new DeviceData()
            {
                State = DeviceState.Online
            };

            DummyAdbClient client = new DummyAdbClient();
            client.Commands.Add("/system/bin/getprop", @"[init.svc.BGW]: [running]
            [init.svc.MtkCodecService]: [running]
            [init.svc.bootanim]: [stopped]");
            AdbClient.Instance = client;

            var properties = device.GetProperties();
            Assert.IsNotNull(properties);
            Assert.AreEqual(3, properties.Count);
            Assert.IsTrue(properties.ContainsKey("init.svc.BGW"));
            Assert.IsTrue(properties.ContainsKey("init.svc.MtkCodecService"));
            Assert.IsTrue(properties.ContainsKey("init.svc.bootanim"));

            Assert.AreEqual("running", properties["init.svc.BGW"]);
            Assert.AreEqual("running", properties["init.svc.MtkCodecService"]);
            Assert.AreEqual("stopped", properties["init.svc.bootanim"]);
        }
Example #16
0
 public static void PullFile(this DeviceData device, string remotePath, string localPath, CancellationToken cancellationToken, IProgress <int> progress = null)
 {
     using (var syn = new SyncService(device))
         using (var fs = new FileStream(localPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
             syn.Pull(remotePath, fs, progress, cancellationToken);
 }
Example #17
0
 public static IEnumerable <FileStatistics> GetDirectoryListing(this DeviceData device, string directory)
 {
     using (var syn = new SyncService(device))
         return(syn.GetDirectoryListing(directory));
 }
Example #18
0
 public Slave(DeviceData dev, int viWid, int viHei)
 {
     Device = dev;
     Enslave(viWid, viHei);
 }
 public _SystemSlotDataControl(DeviceData Device) : base(Device)
 {
     InitializeComponent();
 }
Example #20
0
 public MouseControlEventArgs(DeviceData dData, int WheelChange)
 {
     Wheel = WheelChange;
     DeviceData = dData;
 }
Example #21
0
 public MouseControlEventArgs(DeviceData dData)
 {
     DeviceData = dData;
 }
Example #22
0
 private void Clear()
 {
     radInstrumentDataType = null;
     deviceData            = null;
 }
Example #23
0
        /// <summary>
        /// Iterates through the list provided by GetRawInputDeviceList,
        /// counting keyboard devices and adding them to deviceList.
        /// </summary>
        /// <returns>The number of keyboard devices found.</returns>
        public int EnumerateDevices()
        {
            int NumberOfDevices = 0;
            uint deviceCount = 0;
            int dwSize = (Marshal.SizeOf(typeof(RAWINPUTDEVICELIST)));

            if (GetRawInputDeviceList(IntPtr.Zero, ref deviceCount, (uint)dwSize) == 0)
            {
                IntPtr pRawInputDeviceList = Marshal.AllocHGlobal((int)(dwSize * deviceCount));
                GetRawInputDeviceList(pRawInputDeviceList, ref deviceCount, (uint)dwSize);

                for (int i = 0; i < deviceCount; i++)
                {
                    uint pcbSize = 0;

                    RAWINPUTDEVICELIST rid = (RAWINPUTDEVICELIST)Marshal.PtrToStructure(
                                               new IntPtr((pRawInputDeviceList.ToInt32() + (dwSize * i))),
                                               typeof(RAWINPUTDEVICELIST));

                    GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);

                    if (pcbSize > 0)
                    {
                        IntPtr pData = Marshal.AllocHGlobal((int)pcbSize);
                        GetRawInputDeviceInfo(rid.hDevice, RIDI_DEVICENAME, pData, ref pcbSize);
                        string deviceName = Marshal.PtrToStringAnsi(pData);

                        //The list will include the "root" keyboard and mouse devices
                        //which appear to be the remote access devices used by Terminal
                        //Services or the Remote Desktop - we're not interested in these
                        //so the following code with drop into the next loop iteration
                        if (deviceName.ToUpper().Contains("ROOT"))
                        {
                            continue;
                        }

                        //If the device is identified as a keyboard or HID device,
                        //create a DeviceInfo object to store information about it
                        if (rid.dwType == RIM_TYPEKEYBOARD || rid.dwType == RIM_TYPEHID || rid.dwType == RIM_TYPEMOUSE)
                        {
                            DeviceData Data = new DeviceData();
                            DeviceInfo dInfo = new DeviceInfo();
                            Data.Info = dInfo;
                            Data.Type = GetDeviceTypeE(rid.dwType);
                            if (Data.Type == DeviceType.Keyboard)
                            {
                                Data.KeyboardKeyPressed = new bool[255];
                            }

                            dInfo.deviceName = Marshal.PtrToStringAnsi(pData);
                            dInfo.deviceHandle = rid.hDevice;
                            dInfo.deviceType = GetDeviceType(rid.dwType);

                            string DeviceDesc = ReadReg(deviceName);
                            dInfo.Name = DeviceDesc;

                            //If it is a keyboard and it isn't already in the list,
                            //add it to the deviceList hashtable and increase the
                            //NumberOfDevices count
                            if (!DeviceList.ContainsKey(rid.hDevice))
                            {
                                NumberOfDevices++;
                                DeviceList.Add(rid.hDevice, Data);
                            }
                        }
                        Marshal.FreeHGlobal(pData);
                    }
                }

                Marshal.FreeHGlobal(pRawInputDeviceList);
                return NumberOfDevices;
            }
            else
            {
                throw new ApplicationException("Error!\nGetRawInputDeviceList failed.");
            }
        }
Example #24
0
 public KeyControlEventArgs(DeviceData dData, int VirtualKey, Keys WinFormKey)
 {
     DeviceData = dData;
     vKey = VirtualKey;
     Key = WinFormKey;
 }
Example #25
0
        public void ReadLogTest()
        {
            var device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State = DeviceState.Online
            };

            var responses = new AdbResponse[]
            {
                AdbResponse.OK,
                AdbResponse.OK
            };

            var responseMessages = new string[] { };

            var requests = new string[]
            {
                "host:transport:169.254.109.177:5555",
                "shell:logcat -B -b system"
            };

            var receiver = new ConsoleOutputReceiver();

            using (Stream stream = File.OpenRead("logcat.bin"))
            using (ShellStream shellStream = new ShellStream(stream, false))
            {
                Logs.LogEntry[] logs = null;

                this.RunTest(
                    responses,
                    responseMessages,
                    requests,
                    shellStream,
                    () =>
                    {
                        logs = AdbClient.Instance.RunLogService(device, Logs.LogId.System).ToArray();
                    });

                Assert.AreEqual(3, logs.Count());
            }
        }
Example #26
0
        public void ExecuteRemoteCommandUnresponsiveTest()
        {
            var device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State = DeviceState.Online
            };

            var responses = new AdbResponse[]
            {
                AdbResponse.OK,
                AdbResponse.OK
            };

            var responseMessages = new string[] { };

            var requests = new string[]
            {
                "host:transport:169.254.109.177:5555",
                "shell:echo Hello, World"
            };

            var receiver = new ConsoleOutputReceiver();

            this.RunTest(
                responses,
                responseMessages,
                requests,
                null,
                () =>
                {
                    AdbClient.Instance.ExecuteRemoteCommand("echo Hello, World", device, receiver);
                });
        }
Example #27
0
        public void ExecuteRemoteCommandTest()
        {
            var device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State = DeviceState.Online
            };

            var responses = new AdbResponse[]
            {
                AdbResponse.OK,
                AdbResponse.OK
            };

            var responseMessages = new string[] { };

            var requests = new string[]
            {
                "host:transport:169.254.109.177:5555",
                "shell:echo Hello, World"
            };

            byte[] streamData = Encoding.ASCII.GetBytes("Hello, World\r\n");
            MemoryStream shellStream = new MemoryStream(streamData);

            var receiver = new ConsoleOutputReceiver();

            this.RunTest(
                responses,
                responseMessages,
                requests,
                shellStream,
                () =>
                {
                    AdbClient.Instance.ExecuteRemoteCommand("echo Hello, World", device, receiver);
                });

            Assert.AreEqual("Hello, World\r\n", receiver.ToString());
        }
 /// <summary>
 /// Add a new DeviceData into the repository.
 /// </summary>
 public DeviceData Post(DeviceData item)
 {
     return Program.Devices.Store(item);
 }
Example #29
0
File: State.cs Project: dn00/Dink
 public abstract bool IsState(DeviceData device);
Example #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageManagerReceiver"/> class.
 /// </summary>
 /// <param name="device">
 /// The device for which the package information is being received.
 /// </param>
 /// <param name="packageManager">
 /// The parent package manager.
 /// </param>
 public PackageManagerReceiver(DeviceData device, PackageManager packageManager)
 {
     this.Device = device;
     this.PackageManager = packageManager;
 }
Example #31
0
 public void GetStateFromStringTest()
 {
     Assert.AreEqual(DeviceState.NoPermissions, DeviceData.GetStateFromString("no permissions"));
     Assert.AreEqual(DeviceState.Unknown, DeviceData.GetStateFromString("hello"));
 }
        /// <summary>
        /// Uninstalls a package from the device.
        /// </summary>
        /// <param name="device">
        /// The device on which to uninstall the package.
        /// </param>
        /// <param name="packageName">
        /// The name of the package to uninstall.
        /// </param>
        public static void UninstallPackage(this DeviceData device, string packageName)
        {
            PackageManager manager = new PackageManager(device);

            manager.UninstallPackage(packageName);
        }
Example #33
0
        public void PushTest()
        {
            DeviceData device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State = DeviceState.Online
            };

            Stream stream = File.OpenRead("fstab.bin");
            var content = File.ReadAllBytes("fstab.bin");

            this.RunTest(
                OkResponses(2),
                ResponseMessages(),
                Requests("host:transport:169.254.109.177:5555", "sync:"),
                SyncRequests(
                    SyncCommand.SEND, "/sdcard/test,644",
                    SyncCommand.DATA, content.Length.ToString(),
                    SyncCommand.DONE, "1446505200"),
                new SyncCommand[] { SyncCommand.OKAY },
                null,
                new byte[][]
                {
                    content
                },
                () =>
                {
                    using (SyncService service = new SyncService(this.Socket, device))
                    {
                        service.Push(stream, "/sdcard/test", 0644, new DateTime(2015, 11, 2, 23, 0, 0, DateTimeKind.Utc), null, CancellationToken.None);
                    }
                });
        }
        /// <summary>
        /// Lists all processes running on the device.
        /// </summary>
        /// <param name="device">
        /// The device on which to list the processes that are running.
        /// </param>
        /// <returns>
        /// An <see cref="IEnumerable{AndroidProcess}"/> that will iterate over all
        /// processes that are currently running on the device.
        /// </returns>
        public static IEnumerable <AndroidProcess> ListProcesses(this DeviceData device)
        {
            // There are a couple of gotcha's when listing processes on an Android device.
            // One way would be to run ps and parse the output. However, the output of
            // ps differents from Android version to Android version, is not delimited, nor
            // entirely fixed length, and some of the fields can be empty, so it's almost impossible
            // to parse correctly.
            //
            // The alternative is to directly read the values in /proc/[pid], pretty much like ps
            // does (see https://android.googlesource.com/platform/system/core/+/master/toolbox/ps.c).
            //
            // The easiest way to do the directory listings would be to use the SyncService; unfortunately,
            // the sync service doesn't work very well with /proc/ so we're back to using ls and taking it
            // from there.
            List <AndroidProcess> processes = new List <AndroidProcess>();

            // List all processes by doing ls /proc/.
            // All subfolders which are completely numeric are PIDs
            ConsoleOutputReceiver receiver = new ConsoleOutputReceiver();

            device.ExecuteShellCommand("/system/bin/ls /proc/", receiver);

            Collection <int> pids = new Collection <int>();

            using (StringReader reader = new StringReader(receiver.ToString()))
            {
                while (reader.Peek() > 0)
                {
                    string line = reader.ReadLine();

                    if (!line.All(c => char.IsDigit(c)))
                    {
                        continue;
                    }

                    var pid = int.Parse(line);

                    pids.Add(pid);
                }
            }

            // For each pid, we can get /proc/[pid]/stat, which contains the process information in a well-defined
            // format - see http://man7.org/linux/man-pages/man5/proc.5.html.
            // Doing cat on each file one by one takes too much time. Doing cat on all of them at the same time doesn't work
            // either, because the command line would be too long.
            // So we do it 50 processes at at time.
            StringBuilder         catBuilder            = new StringBuilder();
            ProcessOutputReceiver processOutputReceiver = new ProcessOutputReceiver();

            for (int i = 0; i < pids.Count; i++)
            {
                if (i % 50 == 0)
                {
                    catBuilder.Clear();
                    catBuilder.Append("cat ");
                }

                catBuilder.Append($"/proc/{pids[i]}/stat ");

                if (i > 0 && (i % 50 == 0 || i == pids.Count - 1))
                {
                    device.ExecuteShellCommand(catBuilder.ToString(), processOutputReceiver);
                }
            }

            processOutputReceiver.Flush();

            return(processOutputReceiver.Processes);
        }
Example #35
0
 public Task RunLogServiceAsync(DeviceData device, Action <LogEntry> sink, CancellationToken cancellationToken, params LogId[] logNames)
 {
     throw new NotImplementedException();
 }
Example #36
0
 public MouseControlEventArgs(DeviceData dData, int ChangeX, int ChangeY)
 {
     DeltaX = ChangeX;
     DeltaY = ChangeY;
     DeviceData = dData;
 }
 public MonitoringProcess()
 {
     AnalysisData = new DeviceData();
 }
Example #38
0
 public void SetDevice(IAdbSocket socket, DeviceData device)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Requests the version information from the device.
        /// </summary>
        /// <param name="device">
        /// The device on which to uninstall the package.
        /// </param>
        /// <param name="packageName">
        /// The name of the package from which to get the application version.
        /// </param>
        public static VersionInfo GetPackageVersion(this DeviceData device, string packageName)
        {
            PackageManager manager = new PackageManager(device);

            return(manager.GetVersionInfo(packageName));
        }
Example #40
0
 public IEnumerable <LogEntry> RunLogService(DeviceData device, CancellationToken cancellationToken, params LogId[] logNames)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Executes a shell command on the device.
 /// </summary>
 /// <param name="device">
 /// The device on which to run the command.
 /// </param>
 /// <param name="command">
 /// The command to execute.
 /// </param>
 /// <param name="receiver">
 /// Optionally, a <see cref="IShellOutputReceiver"/> that processes the command output.
 /// </param>
 public static void ExecuteShellCommand(this DeviceData device, string command, IShellOutputReceiver receiver)
 {
     AdbClient.Instance.ExecuteRemoteCommand(command, device, receiver);
 }
Example #42
0
 public void Unroot(DeviceData device)
 {
     throw new NotImplementedException();
 }
Example #43
0
 public Slave(DeviceData dev)
 {
     Device = dev;
     Enslave(VirtualWidth, VirtualHeight);
 }
Example #44
0
 public void Install(DeviceData device, Stream apk, params string[] arguments)
 {
     throw new NotImplementedException();
 }
Example #45
0
 public static async Task PullFileAsync(this DeviceData device, string remotePath, string localPath, CancellationToken cancellationToken, IProgress <int> progress = null)
 {
     await Task.Run(() => PullFile(device, remotePath, localPath, cancellationToken, progress));
 }
Example #46
0
        public void StatTest()
        {
            DeviceData device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State = DeviceState.Online
            };

            FileStatistics value = null;

            this.RunTest(
                OkResponses(2),
                NoResponseMessages,
                Requests("host:transport:169.254.109.177:5555", "sync:"),
                SyncRequests(SyncCommand.STAT, "/fstab.donatello"),
                new SyncCommand[] { SyncCommand.STAT },
                new byte[][] { new byte[] { 160, 129, 0, 0, 85, 2, 0, 0, 0, 0, 0, 0 } },
                null,
                () =>
                {
                    using (SyncService service = new SyncService(this.Socket, device))
                    {
                        value = service.Stat("/fstab.donatello");
                    }
                });

            Assert.IsNotNull(value);
            Assert.AreEqual(UnixFileMode.Regular, value.FileMode & UnixFileMode.TypeMask);
            Assert.AreEqual(597, value.Size);
            Assert.AreEqual(DateTimeHelper.Epoch.ToLocalTime(), value.Time);
        }
Example #47
0
 public static void PullFile(this DeviceData device, string remotePath, string localPath, IProgress <int> progress = null)
 {
     PullFile(device, remotePath, localPath, CancellationToken.None, progress);
 }
Example #48
0
File: Program.cs Project: B0k0/xbmc
 private void cp_DeviceAdded(DeviceData dev)
 {
     Console.WriteLine("Added: " + dev.FriendlyName);
 }
Example #49
0
File: State.cs Project: dn00/Dink
        /// <summary>
        /// The next state
        /// </summary>
        //public abstract State Next { get; set; }

        /// <summary>
        /// The macro
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public abstract bool Run(DeviceData device);
Example #50
0
 public Task <Image> GetFrameBufferAsync(DeviceData device, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
Example #51
0
        public void CreateFromInvalidDatatest()
        {
            string data = "xyz";

            var device = DeviceData.CreateFromAdbData(data);
        }
Example #52
0
 public Framebuffer CreateRefreshableFramebuffer(DeviceData device)
 {
     throw new NotImplementedException();
 }
Example #53
0
 public override bool Run(DeviceData device)
 {
     throw new NotImplementedException();
 }
Example #54
0
 public IEnumerable <ForwardData> ListForward(DeviceData device)
 {
     throw new NotImplementedException();
 }
Example #55
0
        /////////////////////////////////////////////////////////////////////////////////////////
        // Private Methods
        /////////////////////////////////////////////////////////////////////////////////////////
        private void ParseFiles()
        {
            SortedList <DateTime, DeviceData> sortedDeviceDatas = new SortedList <DateTime, DeviceData>();

            // Start Thread that archives .N42 files
            ThreadStart threadStart = new ThreadStart(ArchiveFiles);
            Thread      thread      = new Thread(threadStart);

            thread.Start();

            // Parse spe files
            int filesCompleted = 0;

            foreach (string filePath in filePaths)
            {
                Invoke_ParsingUpdate((float)filesCompleted++ / (float)filePaths.Count());

                // Check if background file
                string fileName = Path.GetFileName(filePath);

                // Clear data
                Clear();

                // Deserialize file to N42 object
                if (DeserializeN42(filePath) == false)
                {
                    continue;
                }

                // Create RadSeeker and set FileName
                deviceData          = new DeviceData(DeviceInfo.Type.RadEyeSprdGn);
                deviceData.FileName = fileName;

                // Parse data from N42 object
                if (ParseN42File() == false)
                {
                    continue;
                }

                // Add to other parsed
                if (sortedDeviceDatas.ContainsKey(deviceData.StartDateTime))
                {
                    continue;
                }
                sortedDeviceDatas.Add(deviceData.StartDateTime, deviceData);
            }

            // Number all the events
            int trailNumber = 1;

            foreach (KeyValuePair <DateTime, DeviceData> device in sortedDeviceDatas)
            {
                device.Value.TrialNumber = trailNumber++;
            }

            if (ErrorsOccurred)
            {
                StringBuilder errorBuilder = new StringBuilder();
                errorBuilder.AppendLine("The files listed below failed to parse..");
                int errorIndex;
                for (errorIndex = 0; errorIndex < fileErrors.Count && errorIndex < 8; errorIndex += 1)
                {
                    errorBuilder.AppendLine(string.Format("\t{0}", fileErrors[errorIndex].Key));
                }
                if (errorIndex < fileErrors.Count)
                {
                    errorBuilder.AppendLine(string.Format("\tand {0} others", fileErrors.Count - errorIndex));
                }
                MessageBox.Show(errorBuilder.ToString(), "Parsing Error");
            }
            ClearErrors();

            // Wait for thread to zip files
            thread.Join();

            deviceDatasParsed = sortedDeviceDatas.Values.ToList();
        }
Example #56
0
 private void Clear()
 {
     n42InstrumentData = null;
     deviceData        = null;
 }
Example #57
0
 public List <string> GetFeatureSet(DeviceData device)
 {
     throw new NotImplementedException();
 }
Example #58
0
 public MouseControlEventArgs(DeviceData dData, bool Left, bool Middle, bool Right)
 {
     LeftButton = Left;
     RightButton = Right;
     MiddleButton = Middle;
     DeviceData = dData;
 }
Example #59
0
        public void PullTest()
        {
            DeviceData device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State = DeviceState.Online
            };

            MemoryStream stream = new MemoryStream();
            var content = File.ReadAllBytes("fstab.bin");

            this.RunTest(
                OkResponses(2),
                ResponseMessages(),
                Requests("host:transport:169.254.109.177:5555", "sync:"),
                SyncRequests(SyncCommand.RECV, "/fstab.donatello"),
                new SyncCommand[] { SyncCommand.DATA, SyncCommand.DONE },
                new byte[][]
                {
                    new byte[] {85, 2, 0, 0},
                    content
                },
                null,
                () =>
                {
                    using (SyncService service = new SyncService(this.Socket, device))
                    {
                        service.Pull("/fstab.donatello", stream, null, CancellationToken.None);
                    }
                });

            // Make sure the data that has been sent to the stream is the expected data
            CollectionAssert.AreEqual(content, stream.ToArray());
        }
Example #60
0
 public void CreateForward(DeviceData device, string local, string remote, bool allowRebind)
 {
     throw new NotImplementedException();
 }