public Image TakePicture() { if (m_handle == IntPtr.Zero) { throw new ObjectDisposedException("WebCam"); } IDataObject oldData = Clipboard.GetDataObject(); try { if (ApiFunctions.SendMessage(m_handle, CaptureMessage.WM_CAP_EDIT_COPY, IntPtr.Zero, IntPtr.Zero) == IntPtr.Zero) { throw new InvalidOperationException("Error copying image to clipboard"); } if (!Clipboard.ContainsImage()) { throw new InvalidOperationException("No image on clipboard"); } return(Clipboard.GetImage()); } finally { Clipboard.SetDataObject(oldData); } }
/// <summary> /// Execute query /// </summary> /// <param name="exchange">Security exchange</param> public static List <Spark.Event> Execute(string exchange) { //Connect to Spark API if required ApiControl.Instance.Connect(); //Get exchange reference Spark.Exchange exchangeRef; List <Spark.Event> result = null; if (ApiFunctions.GetSparkExchange(exchange, out exchangeRef)) { //Wait to allow Spark API to prepare for large download (it will only return a small number of events without this) System.Threading.Thread.Sleep(1000); //Request stock events result = new List <Spark.Event>(); Spark.Event sparkEvent = new Spark.Event(); //Execute query using current day request method if (Spark.GetAllExchangeEvents(ref exchangeRef, ref sparkEvent)) { while (Spark.GetNextExchangeEvent(ref exchangeRef, ref sparkEvent, 1000)) { result.Add(sparkEvent); } } Spark.ReleaseCurrentEvents(); } return(result); }
public async Task <AcquiringBankResult> SendToAcquiringBank(PaymentRequest request) { var piggyRequest = BuildPiggyRequest(request); var piggyStatus = await ApiFunctions.ProcessPaymentRequestAsync(piggyRequest); return(BuildPaymentProcessed(piggyStatus)); }
private KeyboardLayout(CultureInfo cultureInfo) { string layoutName = cultureInfo.LCID.ToString("x8"); var pwszKlid = new StringBuilder(layoutName); this.hkl = ApiFunctions.LoadKeyboardLayout(pwszKlid.ToString(), KeyboardLayoutFlags.KLF_ACTIVATE); }
/// <summary> /// Close application /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exitToolStripMenuItem_Click(object sender, EventArgs e) { //Ensure disconnection from Spark API ApiFunctions.Disconnect(); //Close main form Close(); }
private void search_Click(object sender, EventArgs e) { Employee theEmployee = new Employee(); theEmployee = ApiFunctions.SearchEmployee(Convert.ToInt32(ID.Text)); CleanAllText(); lableShow.Text = theEmployee.ID + " " + theEmployee.name + " " + theEmployee.sex; }
/// <summary> /// Submit Spark.Event depth update event (thread-safe) /// </summary> /// <param name="eventItem">Spark event</param> public void SubmitEvent(Spark.Event eventItem) { LimitOrderList list = (ApiFunctions.GetMarketSide(eventItem.Flags) == MarketSide.Bid) ? Bid : Ask; lock (_lock) { list.SubmitEvent(eventItem); } }
public MouseHook(ILog log) { logger = log; mouseHookProc = null; mouseHookHandler = IntPtr.Zero; deviceStateChecker = new WindowsInputDeviceStateAdaptor(); inputSimulator = new InputSimulator(); hInstance = ApiFunctions.LoadLibrary("User32"); }
public void StartHook() { if (mouseHookProc == null) { mouseHookProc = new MouseHookProc(ConfigHook); } mouseHookHandler = ApiFunctions.SetWindowsHookEx(HookType.WH_MOUSE_LL, mouseHookProc, hInstance, 0); logger.Info("Mouse hook started"); }
private void showAll_Click(object sender, EventArgs e) { List <Employee> employeeList = new List <Employee>(); employeeList = ApiFunctions.ShowAllEmployees(); CleanAllText(); foreach (var employee in employeeList) { lableShow.Text += employee.ID + " " + employee.name + " " + employee.sex + "\n"; } }
/// <summary> /// /// </summary> /// <param name="symbol">Security symbol</param> /// <param name="exchange">Security exchange</param> /// <param name="date">Request date</param> public static List <Spark.Event> Execute(string symbol, string exchange, DateTime date) { //Connect to Spark API if required ApiControl.Instance.Connect(); //Determine what Spark considers to be the current date DateTime sparkDate = ApiFunctions.GetCurrentSparkDate(); Debug.WriteLine("\tCurrent Spark Date: " + date.ToShortDateString()); //Get instance to stock Spark.Stock stock; List <Spark.Event> result = null; if (ApiFunctions.GetSparkStock(symbol, exchange, out stock)) { //Request stock events Spark.Event sparkEvent = new Spark.Event(); result = new List <Spark.Event>(); if (date == sparkDate) { //Wait to allow Spark API to prepare for download (it may only return a small number of events without this) System.Threading.Thread.Sleep(1000); //NOTE: This is only returning 1 event when requested over a mobile wireless connection. It may require more delay or some other sort of test. //Execute query using current day request method Debug.WriteLine("\tSpark.GetAllStockEvents(" + symbol + ")"); if (Spark.GetAllStockEvents(ref stock, ref sparkEvent)) { while (Spark.GetNextStockEvent(ref stock, ref sparkEvent, 1000)) //Specifying 0 timeout will return events until there are no more in the queue { result.Add(sparkEvent); } } Spark.ReleaseStockEvents(ref stock); } else { //Execute query using historical request method Debug.WriteLine("\tSpark.GetPastStockEvents(" + symbol + ", " + date.ToShortDateString() + ")"); if (Spark.GetPastStockEvents(ref stock, ref sparkEvent, date)) { while (Spark.GetNextPastStockEvent(ref stock, ref sparkEvent)) { result.Add(sparkEvent); } } Spark.ReleasePastStockEvents(ref stock, (DateTime)date); } } return(result); }
public void Stop() { if (m_handle != IntPtr.Zero) { ApiFunctions.SendMessage(m_handle, CaptureMessage.WM_CAP_DRIVER_DISCONNECT, IntPtr.Zero, IntPtr.Zero); ApiFunctions.DestroyWindow(m_handle); m_handle = IntPtr.Zero; } GC.SuppressFinalize(this); }
public async Task <PaymentProcessed> ProcessAsync(IAcquirerCommand processPayment) { var piggyPayment = processPayment as ProcessPiggyPayment; if (piggyPayment == null) { throw new Exception("Invalid payment type"); } var piggyRequest = BuildPiggyRequest(piggyPayment); var piggyStatus = await ApiFunctions.ProcessPaymentRequestAsync(piggyRequest); return(BuildPaymentProcessed(piggyPayment, piggyStatus)); }
/// <summary> /// Loads and gets the pinvoke kernel32 library. /// </summary> /// <param name="libraryName">Name of the library.</param> /// <returns>The library handler</returns> public IntPtr LoadPInvokeKernel32Library(string libraryName) { try { var libraryHandle = ApiFunctions.LoadLibrary(libraryName); return(libraryHandle); } catch (Exception ex) { logger.Error($"LOAD USER32 LIBRARY ERROR: {ex.StackTrace}"); return(IntPtr.Zero); } }
public WebCam(int deviceIndex, IntPtr parentHandle, int width, int height, bool showWindow) { m_width = width; m_height = height; m_index = deviceIndex; m_parentHandle = parentHandle; if (m_parentHandle == IntPtr.Zero) { throw new NullReferenceException("parentHandle cannot be 0"); } WindowStyle windowStyle = WindowStyle.WS_CHILD; if (showWindow) { windowStyle |= WindowStyle.WS_VISIBLE; } m_handle = ApiFunctions.capCreateCaptureWindow("WebCam " + deviceIndex, windowStyle, 0, 0, width, height, parentHandle, 0); if (m_handle == IntPtr.Zero) { throw new InvalidOperationException("Error creating camera window"); } // Initialize Camera if (ApiFunctions.SendMessage(m_handle, CaptureMessage.WM_CAP_DRIVER_CONNECT, new IntPtr(deviceIndex), IntPtr.Zero) == IntPtr.Zero) { throw new InvalidOperationException("Error connecting to camera"); } // Enable preview mode, ensuring our callback will be called if (ApiFunctions.SendMessage(m_handle, CaptureMessage.WM_CAP_SET_SCALE, new IntPtr(-1), IntPtr.Zero) == IntPtr.Zero) { throw new InvalidOperationException("Error disabling scaling"); } if (ApiFunctions.SendMessage(m_handle, CaptureMessage.WM_CAP_SET_PREVIEWRATE, new IntPtr(100), IntPtr.Zero) == IntPtr.Zero) { throw new InvalidOperationException("Error setting preview rate"); } if (ApiFunctions.SendMessage(m_handle, CaptureMessage.WM_CAP_SET_PREVIEW, new IntPtr(-1), IntPtr.Zero) == IntPtr.Zero) { throw new InvalidOperationException("Error enabling preview mode."); } }
async Task RefreshData() { ApiFunctions api = new ApiFunctions(); while (true) { //await Task.Run(() => Depth(Properties.Settings.Default.pair)); await Task.Delay(2000); Task.Factory.StartNew(() => Depth(Properties.Settings.Default.pair)); //Thread thread = new Thread(api.Depth); //thread.Start(); } }
public void StartHook() { try { if (keyboardHookDelegate == null) { keyboardHookDelegate = ConfigHook; } keyboardHookHandler = ApiFunctions.SetWindowsHookEx(HookType.WH_KEYBOARD_LL, keyboardHookDelegate, hookInstance, 0); logger.Info("Keyboard hook started"); } catch (Exception ex) { logger.Error($"START KEBOARD HOOK ERROR: {ex.StackTrace}"); } }
/// <summary> /// Composing of request to API. /// </summary> /// <param name="apiKey"></param> /// <param name="function"></param> /// <param name="parameters"></param> /// <param name="httpMethod"></param> /// <returns></returns> public static HttpRequestMessage ComposeHttpRequest( string apiKey, ApiFunctions function, IDictionary<ApiParameters, string> parameters = null, HttpMethod httpMethod = null ) { var uri = new Uri(ComposeUrl(apiKey, function, parameters)); var request = new HttpRequestMessage { RequestUri = uri, Method = httpMethod ?? HttpMethod.Get }; return request; }
private async void LogIn_ClickAsync(object sender, EventArgs e) { try { string resp = ""; resp = await ApiFunctions.Login(textUsername.Text, textPassword.Text); if (resp == "Login succesfull.") { await LoadActivityMainAsync(); } loginResponse.Text = resp; } catch (Exception xe) { //MessageBox.Show() loginResponse.Text = xe.Message; } }
/// <summary> /// Global mouse hook procedure /// </summary> /// <param name="code"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> private IntPtr ConfigHook(int code, int wParam, ref MouseHookStructure.HookStruct lParam) { //DebugMousePressSignal(code, wParam, lParam); if (code < 0) { //you need to call CallNextHookEx without further processing //and return the value returned by CallNextHookEx return(ApiFunctions.CallNextHookEx(mouseHookHandler, code, wParam, ref lParam)); } if (MouseCodes.WM_LBUTTONDOWN == (MouseCodes)wParam || MouseCodes.WM_RBUTTONDOWN == (MouseCodes)wParam) { var modKeysToPressOnce = Globals.GetModKeysToPressOnce().ToList(); var modKeysToUse = Globals.GetModKeysToHoldDown().ToList(); modKeysToUse.AddRange(modKeysToPressOnce); CheckCrtlKeyPressed(); //CheckShiftKeyPressed(); } return(ApiFunctions.CallNextHookEx(mouseHookHandler, code, wParam, ref lParam)); }
public static string GetDeviceFromDrive(System.IO.DriveInfo driveInfo) { IntPtr pStorageDeviceNumber = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(STORAGE_DEVICE_NUMBER))); SafeFileHandle hDrive = null; try { string driveName = "\\\\.\\" + driveInfo.ToString().Substring(0, 2); hDrive = ApiFunctions.CreateFile(driveName, AccessMask.GENERIC_READ, System.IO.FileShare.ReadWrite, 0, System.IO.FileMode.Open, 0, IntPtr.Zero); if (hDrive.IsInvalid) { throw new FileLoadException("Drive handle invalid"); } bool status; int retByte; System.Threading.NativeOverlapped nativeOverlap = new System.Threading.NativeOverlapped(); status = ApiFunctions.DeviceIoControl(hDrive, DeviceIOControlCode.StorageGetDeviceNumber, IntPtr.Zero, 0, pStorageDeviceNumber, Marshal.SizeOf(typeof(STORAGE_DEVICE_NUMBER)), out retByte, ref nativeOverlap); if (!status) { throw new FileLoadException("DeviceIoControl error"); } STORAGE_DEVICE_NUMBER storDevNum = (STORAGE_DEVICE_NUMBER)Marshal.PtrToStructure(pStorageDeviceNumber, typeof(STORAGE_DEVICE_NUMBER)); return("\\\\.\\PhysicalDrive" + storDevNum.DeviceNumber); } finally { Marshal.FreeHGlobal(pStorageDeviceNumber); if (hDrive != null) { hDrive.Close(); } } }
/// <summary> /// Initiate data feed /// </summary> public override void Execute() { //Connect to Spark API if required ApiControl.Instance.Connect(); //Get instance to stock Spark.Stock stock; if (ApiFunctions.GetSparkStock(Symbol, Exchange, out stock)) { //Request all events for current day Spark.Event sparkEvent = new Spark.Event(); if (Spark.GetAllStockEvents(ref stock, ref sparkEvent)) { while (Spark.GetNextStockEvent(ref stock, ref sparkEvent, -1)) //Specifying -1 timeout will keep it waiting until end of day { RaiseEvent(new EventFeedArgs(sparkEvent, Spark.TimeToDateTime(sparkEvent.Time))); } } //Release memory at end of day Spark.ReleaseStockEvents(ref stock); } }
/// <summary> /// Initiate data feed /// </summary> public override void Execute() { //Connect to Spark API if required ApiControl.Instance.Connect(); //Get instance to exchange Spark.Exchange exchangeRef; if (ApiFunctions.GetSparkExchange(Exchange, out exchangeRef)) { //Request all events for current day Spark.Event sparkEvent = new Spark.Event(); if (Spark.GetAllExchangeEvents(ref exchangeRef, ref sparkEvent)) { while (Spark.GetNextExchangeEvent(ref exchangeRef, ref sparkEvent, -1)) //Specifying -1 timeout will keep it waiting until end of day { RaiseEvent(new EventFeedArgs(sparkEvent, Spark.TimeToDateTime(sparkEvent.Time))); } } //Release memory at end of day Spark.ReleaseCurrentEvents(); } }
public void Eject() { string driveName = "\\\\.\\" + drive.ToString().Substring(0, 2); SafeFileHandle hDrive = ApiFunctions.CreateFile(driveName, AccessMask.GENERIC_READ, System.IO.FileShare.ReadWrite, 0, System.IO.FileMode.Open, 0, IntPtr.Zero); if (hDrive.IsInvalid) { throw new DeviceException(host, "Failed to eject device, could not open drive"); } int retByte; NativeOverlapped nativeOverlap = new NativeOverlapped(); bool status = ApiFunctions.DeviceIoControl(hDrive, DeviceIOControlCode.StorageEjectMedia, IntPtr.Zero, 0, IntPtr.Zero, 0, out retByte, ref nativeOverlap); if (!status) { throw new DeviceException(host, "Failed to eject device, DeviceIoControl returned false"); } }
/// <summary> /// Build URL with parameters. /// </summary> /// <param name="apiKey"></param> /// <param name="function"></param> /// <param name="parameters"></param> /// <returns></returns> public static string ComposeUrl( string apiKey, ApiFunctions function, IDictionary<ApiParameters, string> parameters = null ) { if (string.IsNullOrEmpty(apiKey)) { throw new ArgumentNullException(AvResources.ApiKeyIsNullException); } if (function == ApiFunctions.Unknown) { throw new ArgumentException(AvResources.UnknownApiFunctionException); } var urlParameters = new Dictionary<string, string> { { ApiParametersDic.GetWord(ApiParameters.Function), function.ToString() }, //func is only first, because validation { ApiParametersDic.GetWord(ApiParameters.ApiKey), apiKey } }; if (parameters?.Any() == true) { foreach (var pair in parameters) { urlParameters.Add(ApiParametersDic.GetWord(pair.Key), pair.Value); } } var stringUrl = QueryHelpers.AddQueryString(AlphaVantageConstants.BaseAddress, urlParameters); AlphaVantageApiCallValidator.IsValid(stringUrl); return stringUrl; }
public void StopHook() { ApiFunctions.UnhookWindowsHookEx(mouseHookHandler); }
private void change_Click(object sender, EventArgs e) { ApiFunctions.PutEmployee((Convert.ToInt32(ID.Text)), name.Text, sex.Text); CleanAllText(); }
private void delete_Click(object sender, EventArgs e) { ApiFunctions.DeleteEmployee(Convert.ToInt32(ID.Text)); CleanAllText(); }
public static KeyboardLayout GetCurrent() { uint hkl = ApiFunctions.GetKeyboardLayout((uint)Thread.CurrentThread.ManagedThreadId); return(new KeyboardLayout(hkl)); }
public void Activate() { ApiFunctions.ActivateKeyboardLayout(this.hkl, KeyboardLayoutFlags.KLF_SETFORPROCESS); }