4월, 2015의 게시물 표시

Enum and Attribute

public static IEnumerable<T1> FilterEnumerables<T1, T2>(Predicate<T2> predicate) where T1 : struct, IConvertible //Enum where T2 : Attribute //Attribute { return typeof (T1) .GetFields() .Where(f => f.GetCustomAttributes(typeof (T2)).Any() && predicate(f.GetCustomAttribute<t2>())) .Select(f => (T1) Enum.Parse(typeof (T1), f.Name)); }

Stop console process using Ctrl+C.

http://stackoverflow.com/questions/813086/can-i-send-a-ctrl-c-sigint-to-an-application-on-windows https://msdn.microsoft.com/en-us/library/ms686016(VS.85).aspx private void Button1_OnClick(object sender, RoutedEventArgs e) { var file = new FileInfo(@"C:\temp\video.mp4"); if (file.Exists) { file.Delete(); } ct = new CancellationTokenSource(); Task.Factory.StartNew(() => { var pInfo = new ProcessStartInfo("cmd.exe", string.Format("/c {0} \"{1}\"", new object[] {"adb.bat", file.Name})); pInfo.CreateNoWindow = true; pInfo.UseShellExecute = false; pInfo.RedirectStandardError = true; pInfo.RedirectStandardOutput = true; pInfo.RedirectStandardInput = true; var p = Process.Start(pInfo); ...

adb command for dump and capture

echo %time% adb shell uiautomator dump /data/local/tmp/dump.xml adb pull /data/local/tmp/dump.xml %1 adb shell screencap /data/local/tmp/dump.raw adb pull /data/local/tmp/dump.raw %2 echo %time%

Binary/Soap formatter code

public static void SerializeToBin(this object objectGraph, FileInfo target) { if (target.Exists) { target.Delete(); } using (var fs = target.Create()) { var bs = new BinaryFormatter(); bs.Serialize(fs, objectGraph); } } public static T DeserializeFromBin (this FileInfo source) { if (!source.Exists) { return default(T); } using (var fs = source.OpenRead()) { var bs = new BinaryFormatter(); return (T)bs.Deserialize(fs); } } public static void SerializeToSoap(this object objectGraph, FileInfo target) { if (target.Exists) { target.Delete(); } using (var fs = target.Create()) { var bs = new SoapForma...