Beispiel #1
0
    async Task GetTextAsync()
    {
        #region GetTextAsync

        var text = await ClipboardService.GetTextAsync();

        #endregion
    }
    static async Task VerifyInnerAsync(string expected)
    {
        await ClipboardService.SetTextAsync(expected);

        var actual = await ClipboardService.GetTextAsync();

        Assert.AreEqual(expected, actual);
    }
Beispiel #3
0
        //public void CheckContents(object state)
        public async void CheckContents(object sender, System.Timers.ElapsedEventArgs args)
        {
            // if we still have processing pending, skip this particular call.
            if (_semaphore.CurrentCount == 0)
            {
                return;
            }

            await _semaphore.WaitAsync();

            try
            {
                string contents = await ClipboardService.GetTextAsync();

                // QR Codes can only encode so much data.  If we have > 1024 characters, ignore the data.
                if (contents.Length > 1024)
                {
                    return;
                }

                // if the current and previous lengths are different, then we definitely need to fire off an event
                bool triggerEvent = contents.Length != _previousContents.Length;

                // if the lengths are the same, we could have a false negative, and as such, need to investigate further
                if (!triggerEvent)
                {
                    // to investigate further, we simply inspect each character individually, and if a difference is found, trigger the qr code generation event
                    for (int i = 0; i < contents.Length && !triggerEvent; i++)
                    {
                        if (contents[i] != _previousContents[i])
                        {
                            triggerEvent = true;
                        }
                    }
                }

                // if we need to fire off the qr code generation event
                if (triggerEvent)
                {
                    // fire off the event
                    await _mediator.Send(new GenerateNewQrCodeCommand { Contents = contents });

                    // store the current contents as the previous contents
                    _previousContents = contents;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                _semaphore.Release();
            }
        }
Beispiel #4
0
    static async Task AssertClipboardNotEffected()
    {
        var text = await ClipboardService.GetTextAsync();

        if (text == null)
        {
            return;
        }

        Assert.DoesNotContain("DisableClipboardTests", text);
    }
Beispiel #5
0
    static async Task <int> Main()
    {
        var text = "Hello World!";
        await ClipboardService.SetTextAsync(text);

        var result = await ClipboardService.GetTextAsync();

        if (result == text)
        {
            return(0);
        }

        return(1);
    }
Beispiel #6
0
        private async Task <List <MatchAdvego> > GetDetailedResult(AutomationElement window, UIA3Automation automation)
        {
            string text = null;

            try
            {
                window.FindFirstDescendant(x => x.ByName("Посмотреть результаты проверки Enter")).AsButton().Invoke();
                var bar        = window.FindFirstDescendant(x => x.ByControlType(FlaUI.Core.Definitions.ControlType.ToolBar));
                var resultMenu =
                    bar.FindAllDescendants(x => x.ByControlType(FlaUI.Core.Definitions.ControlType.MenuItem)).Last()
                    .AsMenuItem();
                window.Focus();
                window.FocusNative();
                window.SetForeground();
                resultMenu.Focus();
                resultMenu.SetForeground();
                await Task.Delay(1000);

                resultMenu.Click();
                automation.GetDesktop().FindFirstDescendant(x => x.ByName("Копировать результат проверки Ctrl+Shift+3"))
                .AsMenuItem().Invoke();
                text = await ClipboardService.GetTextAsync();

                if (text != null)
                {
                    var  lines = text.Split(Environment.NewLine);
                    bool docs  = false;
                    List <MatchAdvego> detailed = new List <MatchAdvego>();
                    foreach (var line in lines)
                    {
                        if (line.StartsWith("##########"))
                        {
                            docs = true;
                        }
                        else if (docs)
                        {
                            var splitted = line.Split(' ');
                            if (splitted.Length > 2)
                            {
                                var matchRerite = splitted[0].Split('|');
                                if (matchRerite.Length > 1)
                                {
                                    detailed.Add(new MatchAdvego
                                    {
                                        Matches = double.TryParse(matchRerite[0], out var match) ? match : 0,
                                        Rerite  = double.TryParse(matchRerite[1].Trim(), out var rerite) ? rerite : 0,
                                        Url     = splitted[2].Trim()
                                    });
                                }
Beispiel #7
0
 public async Task <string> Paste()
 {
     // return ClipboardService.GetText()? ClipboardService.GetText() : '';
     return(await ClipboardService.GetTextAsync());
 }
Beispiel #8
0
        public async Task <TagsAddResult> AddTags(string[] tags)
        {
            InputSimulator inputSimulator = new InputSimulator();

            //TODO: Load from config
            inputSimulator.Keyboard.ModifiedKeyStroke(_hashCopyKeyStrokeModifiers, _hashCopyKeyStrokeKey);
            await Task.Delay(100);

            inputSimulator.Keyboard.ModifiedKeyStroke(_hashCopyKeyStrokeModifiers, _hashCopyKeyStrokeKey);
            await Task.Delay(100);

            inputSimulator.Keyboard.ModifiedKeyStroke(_hashCopyKeyStrokeModifiers, _hashCopyKeyStrokeKey);

            string fileHash = await ClipboardService.GetTextAsync();

            _logger.Debug($"HASH FROM CLIPBOARD: {fileHash}");

            var stringBuilder = new StringBuilder();

            stringBuilder.Append("{\"hash\":\"");
            stringBuilder.Append(fileHash);
            stringBuilder.Append("\",");
            stringBuilder.Append("\"service_names_to_tags\": {\"my tags\": [");
            foreach (string tag in tags)
            {
                stringBuilder.Append($"\"{tag}\",");
            }

            stringBuilder.Remove(stringBuilder.Length - 1, 1);

            stringBuilder.Append("]}}");
            _logger.Debug($"Request payload: {stringBuilder}");

            var httpContent = new StringContent(stringBuilder.ToString());

            httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
            var response = await _client.PostAsync("/add_tags/add_tags", httpContent);

            string responseBody = await response.Content.ReadAsStringAsync();

            bool success = false;

            if (!response.IsSuccessStatusCode)
            {
                Console.Beep(261, 100);
                Console.Beep(554, 100);
                Console.Beep(261, 100);
                Console.WriteLine("Error:");
                Console.WriteLine(responseBody);
                success = false;
            }
            else
            {
                Console.Beep(554, 100);
                Console.Beep(554, 100);
                Console.WriteLine("Success");
                success = true;
            }

            return(new TagsAddResult(success, responseBody)); //Not used
        }
Beispiel #9
0
 /// <inheritdoc />
 public virtual Task <string?> GetTextAsync(CancellationToken cancellation = default)
 {
     return(ClipboardService.GetTextAsync(cancellation));
 }