private void OnRenderTimerElapsed(object source, EventArgs e)
 {
     renderTimer.Stop();
     try
     {
         markdownPreviewForm.RenderMarkdown(scintillaGateway.GetText(scintillaGateway.GetLength()), notepadPPGateway.GetCurrentFilePath());
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #2
0
        internal static Tuple <string, Position, Position> extractBase64FromCurrentPosition(IScintillaGateway scintillaGateway)
        {
            int max = scintillaGateway.GetLength();

            Position position = scintillaGateway.GetCurrentPos();
            int      ch       = scintillaGateway.GetCharAt(position);

            if (!isValidBase64Character((char)ch))
            {
                MessageBox.Show("invalid base64 character under cursor");
                return(null);
            }

            // scan backward
            Position positionOfBase64 = findBeginningOfFragment(scintillaGateway, position, isValidBase64Character);

            // get base64 from known start position until last valid character
            return(getFragmentStartingFrom(scintillaGateway, positionOfBase64.Value, isValidBase64Character));
        }
Beispiel #3
0
        internal static Tuple <string, Position, Position> getFragmentStartingFrom(IScintillaGateway scintillaGateway, int start, Predicate <char> predicate)
        {
            int length = scintillaGateway.GetLength();

            int         lastValid = start;
            List <char> chars     = new List <char>();

            for (int pos = start; pos < length; pos++)
            {
                int ch = scintillaGateway.GetCharAt(new Position(pos));
                if (predicate((char)ch))
                {
                    chars.Add((char)ch);
                    lastValid = pos;
                }
                else
                {
                    break;
                }
            }

            return(new Tuple <string, Position, Position>(new string(chars.ToArray()), new Position(start), new Position(lastValid + 1)));
        }
 private string GetCurrentEditorText()
 {
     return(scintillaGateway.GetText(scintillaGateway.GetLength() + 1));
 }
Beispiel #5
0
        internal static void MT950()
        {
            try
            {
                // select all content in active page
                editor.SelectAll();
                int              length              = editor.GetLength();
                string           activePageText      = editor.GetText(length + 1);
                string           activeTextFlattened = Regex.Replace(activePageText, @"\r\n?|\n", "");
                string           modifiedResults     = null;
                HashSet <string> unqiueResults       = new HashSet <string>();

                // grab each message
                Regex mainSwiftContentPattern = new Regex(@"{.*?(-})+{.*?(:}})");
                //Regex swiftContentPatternWithoutFooter = new Regex(@"{.*?(-})");

                var swiftMessages = mainSwiftContentPattern.Matches(activeTextFlattened);
                foreach (Match swiftMessage in swiftMessages)
                {
                    // new match clear unique results tracker
                    unqiueResults.Clear();

                    //rename fields from :60: to opening_balance for example
                    foreach (var swiftField in swiftInfo.swiftMessageFields)
                    {
                        try
                        {
                            // using swiftMessageField.Value as regex, find match in string
                            string rawMessageField = utils.returnFirstStringMatch(swiftField.Value, swiftMessage.ToString());

                            // only work with unique results since dictionaries contain duplicate regexs
                            if (!unqiueResults.Contains(rawMessageField))
                            {
                                string modifiedMainMessageField = null;
                                try // replace field ID with human readable name
                                {
                                    string humanReadableFieldName = swiftInfo.swiftMessageNames[swiftField.Key];
                                    modifiedMainMessageField = rawMessageField.Replace(swiftField.Key, humanReadableFieldName);
                                }
                                catch //otherwise leave the field ID in tact
                                {
                                    modifiedMainMessageField = rawMessageField;
                                }

                                // only work with lines that actually contain anything
                                if (modifiedMainMessageField.Length > 0)
                                {
                                    unqiueResults.Add(rawMessageField);

                                    string subFieldDetails = utils.buildSwiftSubFieldOutput(rawMessageField, swiftField.Key);

                                    if (":5" == swiftField.Key)
                                    {
                                        modifiedResults = modifiedResults + "-}\n" + modifiedMainMessageField + "\n";
                                    }
                                    else
                                    {
                                        modifiedResults = modifiedResults + modifiedMainMessageField + subFieldDetails;
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Message Field " + swiftField.Value + " not unique " + swiftField);
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Error converting " + swiftField.Key);
                        }
                    }
                }

                editor.SelectAll();
                editor.ReplaceSel(modifiedResults);
            }
            catch
            {
                MessageBox.Show("Error reading text on current page.\n Are you sure this is a MT950?", "Mismatch Error");
            }
        }
Beispiel #6
0
 private static string GetCurrentText()
 {
     return(Editor.GetText(Editor.GetLength() + 1));
 }