public static void Register(ICommandManager cm)
        {
            _terminalEdit   = new CommandCategory("CommandCategory.TerminalEdit");
            _terminal       = new CommandCategory("CommandCategory.Terminal").SetPosition(PositionType.NextTo, _terminalEdit);
            _hiddenTerminal = new CommandCategory("", false);

            //以下、編集メニュー内にあるもの
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.copyaslook",
                                            "Command.CopyAsLook", _terminalEdit, new ExecuteDelegate(CmdCopyAsLook), DoesExistSelection));
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.copytofile",
                                            "Command.CopyToFile", _terminalEdit, new ExecuteDelegate(CmdCopyToFile), DoesExistSelection));
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.pastefromfile",
                                            "Command.PasteFromFile", _terminalEdit, new ExecuteDelegate(CmdPasteFromFile), DoesOpenTargetSession));

            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.clearbuffer",
                                            "Command.ClearBuffer", _terminalEdit, new ExecuteDelegate(CmdClearBuffer), TerminalCommand.DoesExistTargetSession));
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.clearscreen",
                                            "Command.ClearScreen", _terminalEdit, new ExecuteDelegate(CmdClearScreen), TerminalCommand.DoesExistTargetSession));

            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.selectall",
                                            "Command.SelectAll", _terminalEdit, new ExecuteDelegate(CmdSelectAll), TerminalCommand.DoesExistCharacterDocumentViewer));

            //以下、コンソールメニュー内にあるもの
            //TODO いくつかはTerminalSessionにあるべき意味合いだ
            //cm.Register(new TerminalCommand("org.poderosa.terminalemulator.reproduce", new ExecuteDelegate(CmdReproduce), new EnabledDelegate(DoesOpenTargetSession)));

            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.newline.cr",
                                            "Command.NewLine.CR", _hiddenTerminal, new ExecuteDelegate(CmdNewLineCR), DoesOpenTargetSession));
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.newline.lf",
                                            "Command.NewLine.LF", _hiddenTerminal, new ExecuteDelegate(CmdNewLineLF), DoesOpenTargetSession));
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.newline.crlf",
                                            "Command.NewLine.CRLF", _hiddenTerminal, new ExecuteDelegate(CmdNewLineCRLF), DoesOpenTargetSession));

            foreach (EncodingType enc in Enum.GetValues(typeof(EncodingType)))
            {
                EncodingType encodingType = enc;
                cm.Register(
                    new TerminalCommand("org.poderosa.terminalemulator.encoding." + encodingType.ToString(),
                                        "Command.Encoding." + encodingType.ToString(), _hiddenTerminal,
                                        delegate(ICommandTarget target) { return(CmdEncoding(target, encodingType)); },
                                        DoesOpenTargetSession));
            }

            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.receivelinebreak",
                                            "Command.ReceiveLineBreak", _terminal, new ExecuteDelegate(CmdReceiveLineBreak), DoesOpenTargetSession));

            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.togglelocalecho",
                                            "Command.ToggleLocalEcho", _terminal, new ExecuteDelegate(CmdToggleLocalEcho), DoesOpenTargetSession));


            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.sendbreak",
                                            "Command.SendBreak", _terminal, new ExecuteDelegate(CmdSendBreak), DoesOpenTargetSession));
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.sendAYT",
                                            "Command.AreYouThere", _terminal, new ExecuteDelegate(CmdSendAYT), DoesOpenTargetSession));
            cm.Register(new TerminalCommand("org.poderosa.terminalemulator.resetterminal",
                                            "Command.ResetTerminal", _terminal, new ExecuteDelegate(CmdResetTerminal), DoesOpenTargetSession));

            //IntelliSense
            cm.Register(new ToggleIntelliSenseCommand());
        }
Example #2
0
        /// <summary>
        /// Creates a new <see cref="CompressedHttpContent"/> object.
        /// </summary>
        /// <param name="content">The content to be compressed.</param>
        /// <param name="encodingType">The encoding type to use.</param>
        /// <exception cref="ArgumentNullException"><paramref name="content"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="encodingType"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="encodingType"/> specifies an unsupported encoding type.</exception>
        /// <remarks>
        /// GZip and Deflate compression are supported.
        /// </remarks>
        public CompressedHttpContent(HttpContent content, string encodingType)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (encodingType == null)
            {
                throw new ArgumentNullException(nameof(encodingType));
            }

            try {
                _encodingType = (EncodingType)Enum.Parse(typeof(EncodingType), encodingType, true);
            }
            catch {
                throw new ArgumentException($"Unsupported encoding type: {encodingType}", nameof(encodingType));
            }
            _uncompressedContent = content;

            // Copy headers from original response.
            foreach (var header in _uncompressedContent.Headers)
            {
                Headers.TryAddWithoutValidation(header.Key, header.Value);
            }
            // Add Content-Encoding header.
            Headers.ContentEncoding.Add(_encodingType.ToString().ToLowerInvariant());
        }
Example #3
0
        public void And_Encoded_Value_Is_Empty_String_Then_Throws_Exception(EncodingType encodingType, long expectedResult)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);

            //Act
            var encodingService = new EncodingService(config);

            //Assert
            Assert.Throws <ArgumentException>(() => encodingService.Decode("", encodingType));
        }
        private static Encoding GetEncoding(EncodingType type)
        {
            Debug.Assert((type == EncodingType.Primary) || (type == EncodingType.Secondary),
                         "Unknown 'EncodingType' value: " + type.ToString());

            if (type == EncodingType.Secondary)
            {
                return(s_ansiEncoding);
            }
            else
            {
                return(s_utf8Encoding);
            }
        }
Example #5
0
        public void Then_Decodes_Based_On_EncodingType(EncodingType encodingType, long expectedResult)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);
            var valueToDecode      = hashids.EncodeLong(expectedResult);

            //Act
            var encodingService = new EncodingService(config);
            var result          = encodingService.Decode(valueToDecode, encodingType);

            //Assert
            Assert.AreEqual(expectedResult, result);
        }
Example #6
0
        public void And_Encoded_Value_Is_Invalid_Then_Sets_Result_To_Zero_And_Returns_False(EncodingType encodingType)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);
            var valueToDecode      = "THIS_IS_NOT_A_VALID_ENCODED_VALUE";

            //Act
            var encodingService = new EncodingService(config);
            var result          = encodingService.TryDecode(valueToDecode, encodingType, out var decodedValue);

            //Assert
            Assert.IsFalse(result);
            Assert.AreEqual(0, decodedValue);
        }
Example #7
0
        public void And_Encoded_Value_Is_Valid_Then_Sets_Result_To_Decoded_Value_And_Returns_True(EncodingType encodingType, long expectedResult)
        {
            //Arrange
            var config             = EncodingConfigHelper.GenerateRandomConfig();
            var encodingTypeConfig = config.Encodings.Single(x => x.EncodingType == encodingType.ToString());
            var hashids            = new Hashids(encodingTypeConfig.Salt, encodingTypeConfig.MinHashLength, encodingTypeConfig.Alphabet);
            var valueToDecode      = hashids.EncodeLong(expectedResult);

            //Act
            var encodingService = new EncodingService(config);
            var result          = encodingService.TryDecode(valueToDecode, encodingType, out var decodedValue);

            //Assert
            Assert.IsTrue(result);
            Assert.AreEqual(expectedResult, decodedValue);
        }
Example #8
0
        private static Encoding GetEncoding(EncodingType type)
        {
            Debug.Assert(HttpSysSettings.EnableNonUtf8,
                         "If 'EnableNonUtf8' is false we shouldn't require an encoding. It's always Utf-8.");
            Debug.Assert((type == EncodingType.Primary) || (type == EncodingType.Secondary),
                         "Unknown 'EncodingType' value: " + type.ToString());

            if (((type == EncodingType.Primary) && (!HttpSysSettings.FavorUtf8)) ||
                ((type == EncodingType.Secondary) && (HttpSysSettings.FavorUtf8)))
            {
                return(ansiEncoding);
            }
            else
            {
                return(utf8Encoding);
            }
        }
Example #9
0
        public CompressedContent(HttpContent content, EncodingType encodingType)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            originalContent = content;
            this.encodingType = encodingType;

            // copy the headers from the original content
            foreach (KeyValuePair<string, IEnumerable<string>> header in originalContent.Headers)
            {
                this.Headers.TryAddWithoutValidation(header.Key, header.Value);
            }

            this.Headers.ContentEncoding.Add(encodingType.ToString());
        }
Example #10
0
        public CompressedContent(HttpContent content, EncodingType encodingType)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            originalContent   = content;
            this.encodingType = encodingType;

            // copy the headers from the original content
            foreach (KeyValuePair <string, IEnumerable <string> > header in originalContent.Headers)
            {
                this.Headers.TryAddWithoutValidation(header.Key, header.Value);
            }

            this.Headers.ContentEncoding.Add(encodingType.ToString());
        }
        /// <summary>
        /// Save task's properties into the internal serializing xml model
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="infoEvents"></param>
        public void SaveToXML(XmlDocument doc, IDTSInfoEvents infoEvents)
        {
            XmlElement taskElement = doc.CreateElement(string.Empty, "SSISEncodeFileTask", string.Empty);

            XmlAttribute fileConnector = doc.CreateAttribute(string.Empty, Keys.FILE_CONNECTOR, string.Empty);

            fileConnector.Value = FileConnector;

            XmlAttribute fileSourceFile = doc.CreateAttribute(string.Empty, Keys.FileSourcePathInVariable, string.Empty);

            fileSourceFile.Value = FileSourcePathInVariable;

            XmlAttribute sourceType = doc.CreateAttribute(string.Empty, Keys.SourceType, string.Empty);

            sourceType.Value = SourceType;

            XmlAttribute encodingType = doc.CreateAttribute(string.Empty, Keys.EncodingType, string.Empty);

            encodingType.Value = EncodingType.ToString();

            XmlAttribute autodetectSourceEncodingType = doc.CreateAttribute(string.Empty, Keys.AutodetectSourceEncodingType, string.Empty);

            autodetectSourceEncodingType.Value = AutodetectSourceEncodingType.ToString();

            XmlAttribute sourceEncodingType = doc.CreateAttribute(string.Empty, Keys.SourceEncodingType, string.Empty);

            sourceEncodingType.Value = SourceEncodingType.ToString();

            XmlAttribute readWriteBuffer = doc.CreateAttribute(string.Empty, Keys.ReadWriteBuffer, string.Empty);

            readWriteBuffer.Value = ReadWriteBuffer.ToString();

            taskElement.Attributes.Append(fileConnector);
            taskElement.Attributes.Append(fileSourceFile);
            taskElement.Attributes.Append(sourceType);
            taskElement.Attributes.Append(encodingType);
            taskElement.Attributes.Append(autodetectSourceEncodingType);
            taskElement.Attributes.Append(sourceEncodingType);
            taskElement.Attributes.Append(readWriteBuffer);

            doc.AppendChild(taskElement);
        }
        private static Encoding GetEncoding(EncodingType type)
        {
            Debug.Assert(HttpSysSettings.EnableNonUtf8,
                "If 'EnableNonUtf8' is false we shouldn't require an encoding. It's always Utf-8.");
            Debug.Assert((type == EncodingType.Primary) || (type == EncodingType.Secondary),
                "Unknown 'EncodingType' value: " + type.ToString());

            if (((type == EncodingType.Primary) && (!HttpSysSettings.FavorUtf8)) ||
                ((type == EncodingType.Secondary) && (HttpSysSettings.FavorUtf8)))
            {
                return ansiEncoding;
            }
            else
            {
                return utf8Encoding;
            }
        }
Example #13
0
 private string EncodingType2String(EncodingType eType)
 {
     return(eType.ToString().Replace("_", "-"));
 }
        /// <summary>
        /// Submit emails. The HTTP POST request is suggested. The default, maximum (accepted by us) size of an email is 10 MB in total, with or without attachments included. For suggested implementations please refer to https://elasticemail.com/support/http-api/
        /// </summary>
        /// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
        /// <param name="subject">Email subject</param>
        /// <param name="from">From email address</param>
        /// <param name="fromName">Display name for from email address</param>
        /// <param name="sender">Email address of the sender</param>
        /// <param name="senderName">Display name sender</param>
        /// <param name="msgFrom">Optional parameter. Sets FROM MIME header.</param>
        /// <param name="msgFromName">Optional parameter. Sets FROM name of MIME header.</param>
        /// <param name="replyTo">Email address to reply to</param>
        /// <param name="replyToName">Display name of the reply to address</param>
        /// <param name="to">List of email recipients (each email is treated separately, like a BCC). Separated by comma or semicolon. We suggest using the "msgTo" parameter if backward compatibility with API version 1 is not a must.</param>
        /// <param name="msgTo">Optional parameter. Will be ignored if the 'to' parameter is also provided. List of email recipients (visible to all other recipients of the message as TO MIME header). Separated by comma or semicolon.</param>
        /// <param name="msgCC">Optional parameter. Will be ignored if the 'to' parameter is also provided. List of email recipients (visible to all other recipients of the message as CC MIME header). Separated by comma or semicolon.</param>
        /// <param name="msgBcc">Optional parameter. Will be ignored if the 'to' parameter is also provided. List of email recipients (each email is treated seperately). Separated by comma or semicolon.</param>
        /// <param name="lists">The name of a contact list you would like to send to. Separate multiple contact lists by commas or semicolons.</param>
        /// <param name="segments">The name of a segment you would like to send to. Separate multiple segments by comma or semicolon. Insert "0" for all Active contacts.</param>
        /// <param name="mergeSourceFilename">File name one of attachments which is a CSV list of Recipients.</param>
        /// <param name="channel">An ID field (max 191 chars) that can be used for reporting [will default to HTTP API or SMTP API]</param>
        /// <param name="bodyHtml">Html email body</param>
        /// <param name="bodyText">Text email body</param>
        /// <param name="charset">Text value of charset encoding for example: iso-8859-1, windows-1251, utf-8, us-ascii, windows-1250 and more…</param>
        /// <param name="charsetBodyHtml">Sets charset for body html MIME part (overrides default value from charset parameter)</param>
        /// <param name="charsetBodyText">Sets charset for body text MIME part (overrides default value from charset parameter)</param>
        /// <param name="encodingType">0 for None, 1 for Raw7Bit, 2 for Raw8Bit, 3 for QuotedPrintable, 4 for Base64 (Default), 5 for Uue  note that you can also provide the text version such as "Raw7Bit" for value 1.  NOTE: Base64 or QuotedPrintable is recommended if you are validating your domain(s) with DKIM.</param>
        /// <param name="template">The ID of an email template you have created in your account.</param>
        /// <param name="attachmentFiles">Attachment files. These files should be provided with the POST multipart file upload, not directly in the request's URL. Should also include merge CSV file</param>
        /// <param name="headers">Optional Custom Headers. Request parameters prefixed by headers_ like headers_customheader1, headers_customheader2. Note: a space is required after the colon before the custom header value. headers_xmailer=xmailer: header-value1</param>
        /// <param name="postBack">Optional header returned in notifications.</param>
        /// <param name="merge">Request parameters prefixed by merge_ like merge_firstname, merge_lastname. If sending to a template you can send merge_ fields to merge data with the template. Template fields are entered with {firstname}, {lastname} etc.</param>
        /// <param name="timeOffSetMinutes">Number of minutes in the future this email should be sent</param>
        /// <param name="poolName">Name of your custom IP Pool to be used in the sending process</param>
        /// <param name="isTransactional">True, if email is transactional (non-bulk, non-marketing, non-commercial). Otherwise, false</param>
        /// <returns>ApiTypes.EmailSend</returns>
        public static async Task <EmailSend> Send(string subject = null, string from = null, string fromName = null, string sender = null, string senderName = null, string msgFrom = null, string msgFromName = null, string replyTo = null, string replyToName = null, string to = null, string[] msgTo = null, string[] msgCC = null, string[] msgBcc = null, IEnumerable <string> lists = null, IEnumerable <string> segments = null, string mergeSourceFilename = null, string channel = null, string bodyHtml = null, string bodyText = null, string charset = null, string charsetBodyHtml = null, string charsetBodyText = null, EncodingType encodingType = EncodingType.None, string template = null, IEnumerable <FileData> attachmentFiles = null, Dictionary <string, string> headers = null, string postBack = null, Dictionary <string, string> merge = null, string timeOffSetMinutes = null, string poolName = null, bool isTransactional = false)
        {
            using (var client = new HttpClient())
            {
                client.Timeout = TimeSpan.FromSeconds(30);

                var values = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("apikey", ApiKey)
                };

                if (subject != null)
                {
                    values.Add(new KeyValuePair <string, string>("subject", subject));
                }
                if (from != null)
                {
                    values.Add(new KeyValuePair <string, string>("from", from));
                }
                if (fromName != null)
                {
                    values.Add(new KeyValuePair <string, string>("fromName", fromName));
                }
                if (sender != null)
                {
                    values.Add(new KeyValuePair <string, string>("sender", sender));
                }
                if (senderName != null)
                {
                    values.Add(new KeyValuePair <string, string>("senderName", senderName));
                }
                if (msgFrom != null)
                {
                    values.Add(new KeyValuePair <string, string>("msgFrom", msgFrom));
                }
                if (msgFromName != null)
                {
                    values.Add(new KeyValuePair <string, string>("msgFromName", msgFromName));
                }
                if (replyTo != null)
                {
                    values.Add(new KeyValuePair <string, string>("replyTo", replyTo));
                }
                if (replyToName != null)
                {
                    values.Add(new KeyValuePair <string, string>("replyToName", replyToName));
                }
                if (to != null)
                {
                    values.Add(new KeyValuePair <string, string>("to", to));
                }
                if (msgTo != null)
                {
                    values.AddRange(msgTo.Select(item => new KeyValuePair <string, string>("msgTo", item)));
                }
                if (msgCC != null)
                {
                    values.AddRange(msgCC.Select(item => new KeyValuePair <string, string>("msgCC", item)));
                }

                if (msgBcc != null)
                {
                    values.AddRange(msgBcc.Select(item => new KeyValuePair <string, string>("msgBcc", item)));
                }

                if (lists != null)
                {
                    values.Add(new KeyValuePair <string, string>("lists", string.Join(",", lists)));
                }
                if (segments != null)
                {
                    values.Add(new KeyValuePair <string, string>("segments", string.Join(",", segments)));
                }
                if (mergeSourceFilename != null)
                {
                    values.Add(new KeyValuePair <string, string>("mergeSourceFilename", mergeSourceFilename));
                }
                if (channel != null)
                {
                    values.Add(new KeyValuePair <string, string>("channel", channel));
                }
                if (bodyHtml != null)
                {
                    values.Add(new KeyValuePair <string, string>("bodyHtml", bodyHtml));
                }
                if (bodyText != null)
                {
                    values.Add(new KeyValuePair <string, string>("bodyText", bodyText));
                }
                if (charset != null)
                {
                    values.Add(new KeyValuePair <string, string>("charset", charset));
                }
                if (charsetBodyHtml != null)
                {
                    values.Add(new KeyValuePair <string, string>("charsetBodyHtml", charsetBodyHtml));
                }
                if (charsetBodyText != null)
                {
                    values.Add(new KeyValuePair <string, string>("charsetBodyText", charsetBodyText));
                }
                if (encodingType != EncodingType.None)
                {
                    values.Add(new KeyValuePair <string, string>("encodingType", encodingType.ToString()));
                }
                if (template != null)
                {
                    values.Add(new KeyValuePair <string, string>("template", template));
                }
                if (headers != null)
                {
                    values.AddRange(headers.Select(item => new KeyValuePair <string, string>("headers_" + item.Key, item.Value)));
                }
                if (postBack != null)
                {
                    values.Add(new KeyValuePair <string, string>("postBack", postBack));
                }
                if (merge != null)
                {
                    values.AddRange(merge.Select(item => new KeyValuePair <string, string>("merge_" + item.Key, item.Value)));
                }
                if (timeOffSetMinutes != null)
                {
                    values.Add(new KeyValuePair <string, string>("timeOffSetMinutes", timeOffSetMinutes));
                }
                if (poolName != null)
                {
                    values.Add(new KeyValuePair <string, string>("poolName", poolName));
                }
                if (isTransactional != false)
                {
                    values.Add(new KeyValuePair <string, string>("isTransactional", isTransactional.ToString()));
                }

                values.Add(new KeyValuePair <string, string>("merge_firstname", "JohnTest"));

                var content = new FormUrlEncodedContent(values);

                using (var response = await client.PostAsync(ApiUri + "/email/send", content).ConfigureAwait(false))
                {
                    var dataAsString = await response.Content.ReadAsStringAsync();

                    var emResponse = JsonConvert.DeserializeObject <ApiResponse <EmailSend> >(dataAsString);
                    if (emResponse.success)
                    {
                        return(emResponse.Data);
                    }
                    else
                    {
                        throw new Exception(emResponse.error);
                    }
                }
            }
        }
        private static Encoding GetEncoding(EncodingType type)
        {
            Debug.Assert((type == EncodingType.Primary) || (type == EncodingType.Secondary),
                "Unknown 'EncodingType' value: " + type.ToString());

            if (type == EncodingType.Secondary)
            {
                return s_ansiEncoding;
            }
            else
            {
                return s_utf8Encoding;
            }
        }