/// <summary>Anies the given request.</summary>
 ///
 /// <param name="request">The request.</param>
 ///
 /// <returns>An object.</returns>
 public object Any(PlainText request) 
 {
     string contentType = "text/plain";
     var response = new HttpResult(request.Text, contentType);
     if(request.SetContentTypeBrutally) {
         response.ContentType = contentType;
     }
     return response;
 }
Beispiel #2
0
 public void VisitText(IText text)
 {
     PlainText.Append(text.Properties.Text);
 }
Beispiel #3
0
 public Grade CalculateStudentAverage(PlainText subjectName, RegistrationNumber regNumber)
 {
     return(_definedSubjects.Find(d => d.SubjectInfo.Name == subjectName).GetAverageForStudent(regNumber));
 }
Beispiel #4
0
 public void DefineSubject(PlainText subjectName, Credits credits, EvaluationType type, Proportion activity, Professor.Professor professor)
 {
     _definedSubjects.Add(new Subject.Subject(new SubjectInformation(subjectName, credits, type, activity, professor)));
 }
 public SubjectSituation GetSubjectSituation(PlainText subjectName)
 {
     return(_gradeReport.First(d => d.Key.Name == subjectName).Value);
 }
Beispiel #6
0
 public void SetActivityProportion(PlainText subjectName, Proportion proportion)
 {
     _subjects.Find(d => d.SubjectInfo.Name == subjectName).SubjectInfo.SetActivityProportion(proportion);
 }
Beispiel #7
0
 public void AddActivityGrade(PlainText subjectName, RegistrationNumber regNumber, Grade grade)
 {
     _subjects.Find(d => d.SubjectInfo.Name == subjectName)
     .GetSituationForStudent(regNumber)
     .AddActivityGrade(grade);
 }
Beispiel #8
0
 public override string Convert(PlainText plainText) => plainText.Text;
Beispiel #9
0
 public Student(RegistrationNumber regNumber, PlainText name, Credits credits)
     : this(regNumber, name)
 {
     Credits = credits;
 }
Beispiel #10
0
        public static EncryptedText Encrypt(this PlainText plainText, string encryptionKey)
        {
            var encryptedText = Crypto.Encrypt(plainText.Value, encryptionKey);

            return(new EncryptedText(encryptedText));
        }
Beispiel #11
0
        public async Task FlowWithInvalidDateValidationShouldFailAndNotChangeStateProperly()
        {
            // Arrange
            var input = new PlainText()
            {
                Text = "some text different of date"
            };

            Message.Content = input;
            var invalidInput             = new MediaLink();
            var messageType              = "text/plain";
            var messageContent           = "Pong!";
            var validationMessageContent = "Invalid message content";

            var flow = new Flow()
            {
                Id     = Guid.NewGuid().ToString(),
                States = new[]
                {
                    new State
                    {
                        Id    = "root",
                        Root  = true,
                        Input = new Input
                        {
                            Validation = new InputValidation
                            {
                                Rule  = InputValidationRule.Date,
                                Error = validationMessageContent
                            }
                        },
                        Outputs = new[]
                        {
                            new Output
                            {
                                StateId = "ping"
                            }
                        }
                    },
                    new State
                    {
                        Id           = "ping",
                        InputActions = new[]
                        {
                            new Action
                            {
                                Type     = "SendMessage",
                                Settings = new JObject()
                                {
                                    { "type", messageType },
                                    { "content", messageContent }
                                }
                            }
                        }
                    }
                }
            };
            var target = GetTarget();

            // Act
            await target.ProcessInputAsync(Message, flow, CancellationToken);

            // Assert
            StateManager.Received(0).SetStateIdAsync(Context, "ping", Arg.Any <CancellationToken>());
            StateManager.Received(0).DeleteStateIdAsync(Context, Arg.Any <CancellationToken>());

            Sender
            .Received(1)
            .SendMessageAsync(
                Arg.Is <Message>(m =>
                                 m.Id != null &&
                                 m.To.ToIdentity().Equals(UserIdentity) &&
                                 m.Type.ToString().Equals(messageType) &&
                                 m.Content.ToString() == validationMessageContent),
                Arg.Any <CancellationToken>());
        }
 public void TestInitialize()
 {
     this._element = new PlainText();
     this._provider = this._element;
 }
        public void XliffElement_CollapseChildren()
        {
            List<PlainText> textList;
            List<ResourceStringContent> tagList;
            List<Source> sourceList;
            List<Target> targetList;
            List<XliffElement> elementList;
            PlainText text;
            Segment segment;
            StandaloneCode code;
            Unit unit;
            XliffDocument document;

            code = new StandaloneCode();
            text = new PlainText();
            segment = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(text);
            segment.Source.Text.Add(code);

            unit = new Unit();
            unit.Resources.Add(segment);

            document = new XliffDocument();
            document.Files.Add(new File());
            document.Files[0].Containers.Add(unit);

            elementList = document.CollapseChildren<XliffElement>();
            Assert.AreEqual(6, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsFalse(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            sourceList = document.CollapseChildren<Source>();
            Assert.AreEqual(1, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");

            tagList = document.CollapseChildren<ResourceStringContent>();
            Assert.AreEqual(2, tagList.Count, "Element count is incorrect.");
            Assert.IsTrue(tagList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(tagList.Contains(text), "PlainText not found in list");

            targetList = document.CollapseChildren<Target>();
            Assert.AreEqual(0, targetList.Count, "Element count is incorrect.");

            textList = document.CollapseChildren<PlainText>();
            Assert.AreEqual(1, textList.Count, "Element count is incorrect.");
            Assert.IsTrue(textList.Contains(text), "PlainText not found in list");
        }
 public ConversationsSelect(PlainText placeholder, string action_id) : base("conversations_select", placeholder, action_id)
 {
 }
 protected abstract string Visit(PlainText text);
Beispiel #16
0
 public ConfirmationDialog(PlainText title, TextObject text, PlainText confirm, PlainText deny)
 {
     this.title   = title;
     this.text    = text;
     this.confirm = confirm;
     this.deny    = deny;
 }
 public string Convert(PlainText plainText)
 {
     return(plainText.Text);
 }
        public void XliffElement_CollapseChildrenWithScope()
        {
            IExtensible extensible;
            CustomExtension extension1;
            CustomExtension extension2;
            CustomElement1 element1;
            CustomElement2 element2;
            List<XliffElement> elementList;
            List<Source> sourceList;
            PlainText text;
            Segment segment;
            Source source;
            StandaloneCode code;
            Unit unit;
            XliffDocument document;

            code = new StandaloneCode();
            text = new PlainText();
            segment = new Segment();
            segment.Source = new Source();
            segment.Source.Text.Add(text);
            segment.Source.Text.Add(code);

            unit = new Unit();
            unit.Resources.Add(segment);

            document = new XliffDocument();
            document.Files.Add(new File());
            document.Files[0].Containers.Add(unit);

            extensible = document.Files[0];

            extension1 = new CustomExtension("namespace");
            element1 = new CustomElement1("pre1", "namespace");
            extension1.AddChild(new ElementInfo(new XmlNameInfo("localname"), element1));
            extensible.Extensions.Add(extension1);

            extension2 = new CustomExtension("namespace");
            element2 = new CustomElement2("pre1", "namespace");
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), element2));
            source = new Source();
            extension2.AddChild(new ElementInfo(new XmlNameInfo("localname"), source));
            extensible.Extensions.Add(extension2);

            Console.WriteLine("Test with none.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.None);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            Console.WriteLine("Test with current element.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.CurrentElement);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");

            Console.WriteLine("Test with default.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Default);
            Assert.AreEqual(6, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsFalse(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            Console.WriteLine("Test with default with current element.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Default | CollapseScope.CurrentElement);
            Assert.AreEqual(7, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(9, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren<Source>(CollapseScope.Extensions | CollapseScope.CoreElements | CollapseScope.AllDescendants);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.All);
            Assert.AreEqual(10, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document), "Document not found in list");
            Assert.IsTrue(elementList.Contains(code), "StandaloneCode not found in list");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
            Assert.IsTrue(elementList.Contains(segment), "Segment not found in list");
            Assert.IsTrue(elementList.Contains(segment.Source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(text), "PlainText not found in list");
            Assert.IsTrue(elementList.Contains(unit), "Unit not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");

            sourceList = document.CollapseChildren<Source>(CollapseScope.All);
            Assert.AreEqual(2, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");
            Assert.IsTrue(sourceList.Contains(segment.Source), "Source not found in list");

            Console.WriteLine("Test with extensions with core elements for Source.");
            sourceList = document.CollapseChildren<Source>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(1, sourceList.Count, "Element count is incorrect.");
            Assert.IsTrue(sourceList.Contains(source), "Source not found in list");

            Console.WriteLine("Test with extensions without core elements.");
            elementList = document.CollapseChildren<XliffElement>(CollapseScope.Extensions | CollapseScope.AllDescendants);
            Assert.AreEqual(3, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(element1), "Element1 not found in list");
            Assert.IsTrue(elementList.Contains(element2), "Element2 not found in list");
            Assert.IsTrue(elementList.Contains(source), "Source not found in list");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.TopLevelDescendants);
            Assert.AreEqual(0, elementList.Count, "Element count is incorrect.");

            elementList = document.CollapseChildren<XliffElement>(CollapseScope.TopLevelDescendants | CollapseScope.CoreElements);
            Assert.AreEqual(1, elementList.Count, "Element count is incorrect.");
            Assert.IsTrue(elementList.Contains(document.Files[0]), "File not found in list");
        }
Beispiel #19
0
        private TranslationContainer SplitUnit(Unit unit, string text, bool isCData = true)
        {
            SimplifiedHtmlContentItem[] paragraphs;
            if (isCData)
            {
                paragraphs = _htmlParser.SplitHtml(text);
            }
            else
            {
                paragraphs = _htmlParser.SplitPlainText(text);
            }

            if (paragraphs.Count() == 0)
            {
                return(unit);
            }
            else if (!isCData && paragraphs.Count() == 1)
            {
                return(unit);
            }
            else
            {
                var newGroup = new Group(unit.Id + "-g");
                newGroup.Type = unit.Type;
                newGroup.Name = unit.Name;
                if (unit.Metadata != null)
                {
                    var newMetadataContainer = new MetadataContainer();
                    foreach (var metaGroup in unit.Metadata.Groups)
                    {
                        var newMetaGroup = new MetaGroup();
                        newMetaGroup.Id = metaGroup.Id;

                        foreach (Meta item in metaGroup.Containers)
                        {
                            var newElement = new Meta(item.Type, item.NonTranslatableText);
                            newMetaGroup.Containers.Add(newElement);
                        }
                        newMetadataContainer.Groups.Add(newMetaGroup);
                    }
                    newGroup.Metadata = newMetadataContainer;
                }

                var i = 0;
                foreach (var para in paragraphs)
                {
                    i++;
                    var paraUnit = new Unit(unit.Id + "-" + i);

                    var newSegment = new Segment();

                    if (para.Attributes.Count() > 0)
                    {
                        var newMetadataContainer = new MetadataContainer();
                        var attributeMetaGroup   = new MetaGroup();
                        attributeMetaGroup.Id = ORIGINALATTRIBUTES;

                        foreach (var attribute in para.Attributes)
                        {
                            var newElement = new Meta(attribute.Key, attribute.Value);
                            attributeMetaGroup.Containers.Add(newElement);
                        }
                        newMetadataContainer.Groups.Add(attributeMetaGroup);
                        paraUnit.Metadata = newMetadataContainer;
                    }

                    var source = new Source();
                    ResourceStringContent content;
                    if (isCData)
                    {
                        string containingTag = para.Name;
                        string newContent    = para.InnerContent();
                        if (!string.IsNullOrWhiteSpace(containingTag))
                        {
                            paraUnit.Type = _htmlParser.ToXliffHtmlType(containingTag);
                        }
                        if (newContent.IsHtml())
                        {
                            content = new CDataTag(newContent);
                        }
                        else
                        {
                            content = new PlainText(newContent);
                        }
                    }
                    else
                    {
                        content = new PlainText(para.Content);
                    }
                    source.Text.Add(content);
                    newSegment.Source = source;

                    paraUnit.Resources.Add(newSegment);

                    newGroup.Containers.Add(paraUnit);
                }

                var parentFile = unit.Parent as File;
                if (parentFile != null)
                {
                    var index = parentFile.Containers.IndexOf(unit);
                    parentFile.Containers[index] = newGroup;
                }
                else
                {
                    var parentGroup = unit.Parent as Group;
                    if (parentGroup != null)
                    {
                        var index = parentGroup.Containers.IndexOf(unit);
                        parentGroup.Containers[index] = newGroup;
                    }
                }
                return(newGroup);
            }
        }
Beispiel #20
0
 public void AddAttendance(PlainText subjectName, RegistrationNumber regNumber, Attendance attendance)
 {
     _subjects.Find(d => d.SubjectInfo.Name == subjectName)
     .GetSituationForStudent(regNumber)
     .AddAttendance(attendance);
 }
 public string ConvertPlainText(PlainText plainText)
 => plainText.Text;
 public override void Visit(PlainText plainText)
 {
     ConvertedDocument += plainText.Text + Environment.NewLine;
 }
Beispiel #23
0
    private static void MergeLayers(PsdReader psdReader, Graphics graphics, Func <PsdTextFrame, string> getLayerText)
    {
        for (int i = 0; i < psdReader.Frames.Count; i++)
        {
            var frame = psdReader.Frames[i];

            if (frame.Type == FrameType.Text)
            {
                var textFrame = (PsdTextFrame)frame;

                var layerText = getLayerText(textFrame);

                Text text;

                var font = graphics.CreateFont(textFrame.FontName, textFrame.FontSize);

                if (textFrame.Path != null)
                {
                    text = new PathText(textFrame.Text, font)
                    {
                        Path = textFrame.Raw.Path
                    };
                }
                else if (textFrame.TextBox.Width == 0 || textFrame.TextBox.Height == 0)
                {
                    text = new PlainText(layerText, font)
                    {
                        Position = new System.Drawing.PointF(textFrame.Raw.TextBox.Left, textFrame.Raw.TextBox.Top)
                    };
                }
                else
                {
                    text = new BoundedText(layerText, font)
                    {
                        Rectangle = textFrame.Raw.TextBox
                    };
                }

                text.Alignment = JustificationToTextAlignment(textFrame.Justification);
                text.Brush     = new SolidBrush(textFrame.Color);

                text.Tracking  = textFrame.Tracking;
                text.Transform = textFrame.Transform;

                graphics.DrawText(text);
            }
            else if (frame.Type == FrameType.Raster)
            {
                using (var frameBitmap = frame.GetBitmap())
                {
                    graphics.DrawImage(frameBitmap, frame.X, frame.Y);
                }
            }
            else if (frame.Type == FrameType.Shape)
            {
                var shapeFrame = (PsdShapeFrame)frame;

                var path = shapeFrame.VectorMask;
                graphics.FillPath(shapeFrame.Brush, path);
            }
        }
    }
 protected override string Visit(PlainText text) => text.Text;
        public async Task FlowWithTypeInputValidationShouldSendMessageWhenInvalid()
        {
            // Arrange
            var input = new PlainText()
            {
                Text = "Ping!"
            };
            var invalidInput             = new MediaLink();
            var messageType              = "text/plain";
            var messageContent           = "Pong!";
            var validationMessageContent = "Invalid message type";

            var flow = new Flow()
            {
                Id     = Guid.NewGuid().ToString(),
                States = new[]
                {
                    new State
                    {
                        Id    = "root",
                        Root  = true,
                        Input = new Input
                        {
                            Validation = new InputValidation
                            {
                                Rule  = InputValidationRule.Type,
                                Type  = PlainText.MediaType,
                                Error = validationMessageContent
                            }
                        },
                        Outputs = new[]
                        {
                            new Output
                            {
                                StateId = "ping"
                            }
                        }
                    },
                    new State
                    {
                        Id           = "ping",
                        InputActions = new[]
                        {
                            new Action
                            {
                                Type     = "SendMessage",
                                Settings = new JObject()
                                {
                                    { "type", messageType },
                                    { "content", messageContent }
                                }
                            }
                        }
                    }
                }
            };
            var target = GetTarget();

            // Act
            await target.ProcessInputAsync(invalidInput, User, flow, CancellationToken);

            await target.ProcessInputAsync(input, User, flow, CancellationToken);

            // Assert
            StateManager.Received(1).SetStateIdAsync(flow.Id, User, "ping", Arg.Any <CancellationToken>());
            StateManager.Received(1).DeleteStateIdAsync(flow.Id, User, Arg.Any <CancellationToken>());
            Sender
            .Received(1)
            .SendMessageAsync(
                Arg.Is <Message>(m =>
                                 m.Id != null &&
                                 m.To.ToIdentity().Equals(User) &&
                                 m.Type.ToString().Equals(messageType) &&
                                 m.Content.ToString() == validationMessageContent),
                Arg.Any <CancellationToken>());
            Sender
            .Received(1)
            .SendMessageAsync(
                Arg.Is <Message>(m =>
                                 m.Id != null &&
                                 m.To.ToIdentity().Equals(User) &&
                                 m.Type.ToString().Equals(messageType) &&
                                 m.Content.ToString() == messageContent),
                Arg.Any <CancellationToken>());
        }
Beispiel #26
0
 public void SignUpStudentToSubject(PlainText subjectName, Student.Student student)
 {
     _definedSubjects.Find(d => d.SubjectInfo.Name == subjectName).SignUpStudent(student);
 }
        public async Task FlowWithInvalidRegexInputValidationShouldFailAndNotChangeStateProperly()
        {
            // Arrange
            var input = new PlainText()
            {
                Text = "hi"
            };

            var messageType              = "text/plain";
            var messageContent           = "Hi for you to!";
            var validationMessageContent = "Invalid message content";

            var flow = new Flow()
            {
                Id     = Guid.NewGuid().ToString(),
                States = new[]
                {
                    new State
                    {
                        Id    = "root",
                        Root  = true,
                        Input = new Input
                        {
                            Validation = new InputValidation
                            {
                                Rule  = InputValidationRule.Regex,
                                Regex = "(xpto)",
                                Error = validationMessageContent
                            }
                        },
                        Outputs = new[]
                        {
                            new Output
                            {
                                StateId = "state2"
                            }
                        }
                    },
                    new State
                    {
                        Id           = "state2",
                        InputActions = new[]
                        {
                            new Action
                            {
                                Type     = "SendMessage",
                                Settings = new JObject()
                                {
                                    { "type", messageType },
                                    { "content", messageContent }
                                }
                            }
                        }
                    }
                }
            };
            var target = GetTarget();

            // Act
            await target.ProcessInputAsync(input, User, flow, CancellationToken);

            // Assert
            StateManager.Received(0).SetStateIdAsync(flow.Id, User, "state2", Arg.Any <CancellationToken>());
            StateManager.Received(0).DeleteStateIdAsync(flow.Id, User, Arg.Any <CancellationToken>());

            Sender
            .Received(1)
            .SendMessageAsync(
                Arg.Is <Message>(m =>
                                 m.Id != null &&
                                 m.To.ToIdentity().Equals(User) &&
                                 m.Type.ToString().Equals(messageType) &&
                                 m.Content.ToString() == validationMessageContent),
                Arg.Any <CancellationToken>());
        }
Beispiel #28
0
 public StaticSelect(PlainText placeholder, string action_id, OptionGroup[] option_groups) : base("static_select", placeholder, action_id)
 {
     this.option_groups = option_groups;
 }
 protected override string Visit(PlainText plain)
 {
     return(Line += plain.Text);
 }
Beispiel #30
0
 public void VisitLockedContent(ILockedContent lockedContent)
 {
     PlainText.Append(lockedContent.Content);
 }
Beispiel #31
0
        /// <summary>
        /// HEADING
        /// </summary>
        private Heading ParseHeading()
        {
            // Look ahead to determine the maximum level, assuming the line is a valid heading.
            var prefix = LookAheadToken("={1,6}");

            if (prefix == null)
            {
                return(null);
            }

            // Note that here we require all the headings terminate with \n or EOF, so this won't be recognized
            // {{{ARG|== Default Heading ==}}}\n
            // But this will work
            // {{{ARG|== Default Heading ==
            // }}}
            // Note that this should be recognized as heading
            //  == {{T|
            //  arg1}} ==

            // Test different levels of heading
            for (var level = prefix.Length; level > 0; level--)
            {
                var barExpr = "={" + level + "}";
                // We use an early-stopping matching pattern
                // E.g. for ==abc=={{def}}=={{ghi}}
                // the first call to ParseRun will stop at =={{
                // we need to continue parsing, resulting in a list of segments
                // abc, {{def}}, {{ghi}}
                var headingTerminator = barExpr + "(?!=)";
                ParseStart(headingTerminator, false);   // <-- A
                var temp = ConsumeToken(barExpr);
                Debug.Assert(temp != null);
                var node           = new Heading();
                var parsedSegments = new List <IInlineContainer>();
                while (true)
                {
                    ParseStart();                       // <-- B
                    var segment = new Run();
                    if (!ParseRun(RunParsingMode.Run, segment, true) &&
                        LookAheadToken(headingTerminator) == null)
                    {
                        // No more content to parse, and ParseRun stopped by
                        // a terminator that is not a heading terminator
                        // Stop and analyze
                        Fallback();
                        break;
                    }
                    if (ConsumeToken(barExpr) == null)
                    {
                        // The segment has been parsed, but it's terminated not by "==="
                        // We treat the last segment as suffix
                        // Stop and analyze
                        node.Suffix = segment;
                        Accept();
                        break;
                    }
                    // Put the run segment into the list.
                    parsedSegments.Add(segment);
                }
                if (node.Suffix != null &&
                    node.Suffix.Inlines.OfType <PlainText>().Any(pt => !string.IsNullOrWhiteSpace(pt.Content)))
                {
                    // There shouldn't be non-whitespace plaintext after the heading
                    goto FAIL_CLEANUP;
                }
                node.Level = level;
                // Concatenate segments, adding "===" where needed.
                for (int i = 0; i < parsedSegments.Count; i++)
                {
                    node.Inlines.AddFrom(parsedSegments[i].Inlines);
                    if (i < parsedSegments.Count - 1)
                    {
                        var si  = (IWikitextLineInfo)parsedSegments[i + 1];
                        var bar = new PlainText(new string('=', level));
                        bar.SetLineInfo(si.StartLineNumber, si.StartLinePosition - level,
                                        si.StartLineNumber, si.StartLinePosition);
                        node.Inlines.Add(bar);
                    }
                }
                if (node.Inlines.Count == 0)
                {
                    // There should be something as heading content
                    goto FAIL_CLEANUP;
                }
                // Move forward
                // -- B
                for (int i = 0; i < parsedSegments.Count; i++)
                {
                    Accept();
                }
                return(ParseSuccessful(node));   // <-- A

FAIL_CLEANUP:
                // -- B
                for (int i = 0; i < parsedSegments.Count; i++)
                {
                    Fallback();
                }
                Fallback();                     // <-- A
            }
            // Failed (E.g. ^=== Title )
            return(null);
        }
Beispiel #32
0
 public override void VisitPlainText(PlainText plainText) =>
 this.Result += plainText.Text + Environment.NewLine;
Beispiel #33
0
        /// <summary>
        /// Parses a PARAGRPAH_CLOSE .
        /// </summary>
        /// <param name="lastNode">The lastest parsed node.</param>
        /// <returns>The extra paragraph, or <see cref="EMPTY_LINE_NODE"/>. If parsing attempt failed, <c>null</c>.</returns>
        private LineNode ParseLineEnd(LineNode lastNode)
        {
            Debug.Assert(lastNode != null);
            var unclosedParagraph = lastNode as Paragraph;

            if (unclosedParagraph != null && !unclosedParagraph.Compact)
            {
                unclosedParagraph = null;
            }
            // 2 line breaks (\n\n) or \n Terminator closes the paragraph,
            // so do a look-ahead here. Note that a \n will be consumed in ParseWikitext .
            // Note that this look-ahead will also bypass the \n terminator defined in WIKITEXT

            // For the last non-empty line
            // TERM     Terminators
            // PC       Compact/unclosed paragraph
            // P        Closed paragraph
            // abc TERM             PC[|abc|]
            // abc\n TERM           P[|abc|]
            // abc\n\s*?\n TERM     P[|abc|]PC[||]
            // Note that MediaWiki editor will automatically trim the trailing whitespaces,
            // leaving a \n after the content. This one \n will be removed when the page is transcluded.
            var lastLinePosition = linePosition;

            // Here we consume a \n without fallback.
            if (ConsumeToken(@"\n") == null)
            {
                return(null);
            }
            ParseStart();
            // Whitespaces between 2 \n, assuming there's a second \n or TERM after trailingWs
            var trailingWs = ConsumeToken(@"[\f\r\t\v\x85\p{Z}]+");

            if (unclosedParagraph != null)
            {
                // We're going to consume another \n or TERM to close the paragraph.
                // Already consumed a \n, attempt to consume another \n
                var trailingWsEndsAt = linePosition;
                if (ConsumeToken(@"\n") != null)
                {
                    // Close the last paragraph.
                    unclosedParagraph.AppendWithLineInfo("\n" + trailingWs,
                                                         // don't forget the position of leading '\n'
                                                         CurrentContext.StartingLineNumber - 1, lastLinePosition,
                                                         CurrentContext.StartingLineNumber, trailingWsEndsAt);
                    // 2 Line breaks received.
                    // Check for the special case. Note here TERM excludes \n
                    if (NeedsTerminate(Terminator.Get(@"\n")))
                    {
                        // This is a special case.
                        // abc \n trailingWs \n TERM --> P[|abc\ntrailingWs|]PC[||]
                        //                      ^ We are here.
                        // When the function returns, WIKITEXT parsing will stop
                        // because a TERM will be received.
                        // We need to correct this.
                        var anotherparagraph = new Paragraph();
                        anotherparagraph.SetLineInfo(lineNumber, linePosition, lineNumber, linePosition);
                        return(ParseSuccessful(anotherparagraph, false));
                    }
                    // The last paragraph will be closed now.
                    return(ParseSuccessful(EMPTY_LINE_NODE, false));
                }
                // The attempt to consume the 2nd \n failed.
                if (NeedsTerminate())
                {
                    // abc \n trailingWs TERM   P[|abc|]
                    //                   ^ We are here.
                    // If we need to terminate, then close the last paragraph.
                    unclosedParagraph.AppendWithLineInfo("\n" + trailingWs,
                                                         // don't forget the position of leading '\n'
                                                         CurrentContext.StartingLineNumber - 1, lastLinePosition,
                                                         lineNumber, linePosition);
                    return(ParseSuccessful(EMPTY_LINE_NODE, false));
                }
                // The last paragraph is still not closed (i.e. compact paragraph).
                // (A)
                // Note here we have still consumed the first '\n', while the last paragraph has no trailing '\n'.
                // For continued PlainText, we will add a '\n' in ParseCompactParagraph.
                // Add an empty node so ParseCompactParagraph can add a '\n' with LineInfo.
                unclosedParagraph.AppendWithLineInfo("", CurrentContext.StartingLineNumber - 1, lastLinePosition,
                                                     CurrentContext.StartingLineNumber - 1, lastLinePosition);
                // Fallback so we can either continue parsing PlainText,
                // or discover the next, for example, Heading, and leave the last paragraph compact.
                Fallback();
                return(EMPTY_LINE_NODE);
            }
            else
            {
                // Last node cannot be a closed paragraph.
                // It can't because ParseLineEnd is invoked immediately after a last node is parsed,
                // and only ParseLineEnd can close a paragraph.
                Debug.Assert(!(lastNode is Paragraph), "Last node cannot be a closed paragraph.");
                // Rather, last node is LINE node of other type (LIST_ITEM/HEADING).
                // Remember we've already consumed a '\n' , and the spaces after it.
                // The situation here is just like the "special case" mentioned above.
                if (NeedsTerminate(Terminator.Get(@"\n")))
                {
                    // abc \n WHITE_SPACE TERM  -->  [|abc|] PC[|WHITE_SPACE|]
                    //        ^ CurCntxt  ^ We are here now.
                    // Note here TERM excludes \n
                    var anotherparagraph = new Paragraph();
                    if (trailingWs != null)
                    {
                        var pt = new PlainText(trailingWs);
                        // Actually the same as what we do in ParseSuccessful for PlainText.
                        pt.SetLineInfo(CurrentContext.StartingLineNumber, CurrentContext.StartingLinePosition,
                                       lineNumber, linePosition);
                        anotherparagraph.Inlines.Add(pt);
                    }
                    return(ParseSuccessful(anotherparagraph));
                }
            }
            // abc \n def
            // That's not the end of a prargraph. Fallback to before the 1st \n .
            // Note here we have already consumed a \n .
            Fallback();
            return(EMPTY_LINE_NODE);
        }
Beispiel #34
0
        public void Login()
        {
            System.Net.ServicePointManager.Expect100Continue = false;

            loginRequest req = new loginRequest();
            loginResponse resp;
            PlainText pt = new PlainText();

            ws = new GroupWiseBinding();
            string str = "http://";
            str += "10.20.136.206";
            str += ":";
            str += "7191";
            str += "/soap";
            ws.Url = str;

            //    ws.Discover();

            ws.Timeout = 100000;
            //commenting out the following since we will have to use trusted connection thru the admin acoount.

               /* pt.username = "******";
            pt.password = "******";
            req.auth = pt;*/

            TrustedApplication trustedapp = new TrustedApplication();
            trustedapp.name = "ZimbraGWmigration";
            trustedapp.key = admin.Key;
            trustedapp.username = admin.Username;

            req.auth = trustedapp;

            try
            {

                resp = ws.loginRequest(req);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                ws.Discover();
                resp = ws.loginRequest(req);
            }

            string statusmessage = resp.status.code.ToString();
            if (0 == resp.status.code)
            {
                System.Console.WriteLine(" Login success ful");

                ws.session = new @string();
                ws.session.Text = new String[1];
                ws.session.Text[0] = resp.session;

                ws.Timeout = 300000;
                string uid = resp.userinfo.uuid;

               string sessioninfo = resp.session;
                //bLogin = false;
                //getFolders(sessioninfo);

            }
            else
            {
                System.Console.WriteLine(statusmessage);

            }
        }
Beispiel #35
0
 internal Laborator(PlainText nume)
 {
     //Contract.Requires(nume != null, "nume");
     Nume = nume;
 }
Beispiel #36
0
 public string VisitPlainText(PlainText plainText)
 {
     return plainText.Text;
 }
Beispiel #37
0
 public string VisitPlainText(PlainText plainText)
 {
     throw new System.NotImplementedException();
 }