示例#1
0
        /// <summary>
        /// Start the parse processing and append the converted paragraphs into the Body of the document.
        /// </summary>
        public void ParseHtml(String html)
        {
            // This method exists because we may ensure the SectionProperties remains the last element of the body.
            // It's mandatory when dealing with page orientation

            var paragraphs = Parse(html);

            Body body = mainPart.Document.Body;
            SectionProperties sectionProperties = body.GetLastChild <SectionProperties>();

            for (int i = 0; i < paragraphs.Count; i++)
            {
                body.Append(paragraphs[i]);
            }

            // move the paragraph with BookmarkStart `_GoBack` as the last child
            var p = body.GetFirstChild <Paragraph>();

            if (p != null && p.HasChild <BookmarkStart>())
            {
                p.Remove();
                body.Append(p);
            }

            // Push the sectionProperties as the last element of the Body
            // (required by OpenXml schema to avoid the bad formatting of the document)
            if (sectionProperties != null)
            {
                sectionProperties.Remove();
                body.AddChild(sectionProperties);
            }
        }
        private void SendAnswer(Body body, HttpListenerContext ctx)
        {
            try
            {
                var copy = Interlocked.Exchange(ref sendBuffer, new ConcurrentQueue <Node>());
                foreach (var node in copy)
                {
                    body.AddChild(node);
                    if (node.Namespace == Uri.STREAM)
                    {
                        body.SetAttribute("xmlns:stream", Uri.STREAM);
                    }
                }

                if (Volatile.Read(ref closed) == 1)
                {
                    body.Type = BoshType.terminate;
                }
                BoshXmppHelper.SendAndCloseResponse(ctx, body.ToString(), true, null);

                log.DebugFormat("Connection {0} Send buffer:\r\n{1}", Id, body);
            }
            catch (Exception e)
            {
                //BUG: Я думаю баг тут из за обрыва соединения при плохом качестве соединения.
                log.DebugFormat("Connection {0} Error send buffer: {1}", Id, e);
                Close();
            }
        }
示例#3
0
        private void SendAnswer(Body body, HttpListenerContext ctx)
        {
            try
            {
                lock (sendBuffer)
                {
                    foreach (var node in sendBuffer)
                    {
                        body.AddChild(node);
                        if (node.Namespace == Uri.STREAM)
                        {
                            body.SetAttribute("xmlns:stream", Uri.STREAM);
                        }
                    }

                    if (closed)
                    {
                        body.Type = BoshType.terminate;
                    }
                    BoshXmppHelper.SendAndCloseResponse(ctx, body.ToString(), true);
                    sendBuffer.Clear();
                    log.DebugFormat("Connection {0} Send buffer:\r\n{1}", Id, body);
                }
            }
            catch (Exception e)
            {
                log.DebugFormat("Connection {0} Error send buffer: {1}", Id, e);
                Close();
            }
        }
        public void DoubleSharedDocument()
        {
            using var ms1  = new MemoryStream();
            using var doc1 = WordprocessingDocument.Create(ms1, WordprocessingDocumentType.Document);

            using var ms2  = new MemoryStream();
            using var doc2 = WordprocessingDocument.Create(ms2, WordprocessingDocumentType.Document);

            var shared = doc1.AddSharedParagraphIdFeature()
                         .Add(doc2);

            // Add item to doc1
            var part1 = doc1.AddMainDocumentPart();
            var body1 = new Body();
            var p1    = new Paragraph();

            part1.Document = new Document(body1);
            body1.AddChild(p1);

            // Add item with same ID to doc2
            var part2 = doc2.AddMainDocumentPart();
            var body2 = new Body();
            var p2    = new Paragraph {
                ParagraphId = p1.ParagraphId
            };

            part2.Document = new Document(body2);
            body2.AddChild(p2);

            // Assert
            Assert.NotEqual(p1.ParagraphId, p2.ParagraphId);
            Assert.Equal(2, shared.Count);
        }
示例#5
0
        public void TestAllowGenericChildNodes()
        {
            var elem = new Body();

            elem.AddChild("generic-tag").AddText("Content").SetOption("tag", true);

            Assert.AreEqual(
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine +
                "<Body>" + Environment.NewLine +
                "  <generic-tag tag=\"True\">Content</generic-tag>" + Environment.NewLine +
                "</Body>",
                elem.ToString()
                );
        }
示例#6
0
        static void Main(string[] args)
        {
            var html = new Html();
            var body = new Body();
            var p    = new P();
            var text = new Text("Hello world!");

            p.AddChild(text);
            body.AddChild(p);
            html.AddChild(body);

            Console.WriteLine(html.Render());
            Console.ReadKey();
        }
示例#7
0
        /// <summary>
        /// Write an XML element to the socket.
        /// In this case, the element is queued, so that the write
        /// thread can pick it up.
        /// </summary>
        /// <param name="elem"></param>
        public void Write(XmlElement elem)
        {
            Body body = CreateOpenBodyTag();

            if (elem != null)
            {
                body.AddChild(elem);
            }

            byte[] buf = ENC.GetBytes(body.OuterXml);
            //m_listener.OnWrite(this, buf, 0, buf.Length);

            GetSocket().Execute(METHOD, m_uri, buf, 0, buf.Length, CONTENT_TYPE);
        }
示例#8
0
        public void SendAndClose(IEnumerable <Node> buffer, bool terminate)
        {
            foreach (var node in buffer)
            {
                body.AddChild(node);
                if (node.Namespace == Uri.STREAM)
                {
                    body.SetAttribute("xmlns:stream", Uri.STREAM);
                }
            }

            if (terminate)
            {
                body.Type = BoshType.terminate;
            }
            BoshXmppHelper.SendAndCloseResponse(context, body);
        }
        public void SingleSharedDocument()
        {
            using var ms  = new MemoryStream();
            using var doc = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document);

            doc.AddSharedParagraphIdFeature();

            var part = doc.AddMainDocumentPart();
            var body = new Body();

            part.Document = new Document(body);

            var p = new Paragraph();

            Assert.Null(p.ParagraphId);
            body.AddChild(p);
            Assert.NotNull(p.ParagraphId);
        }
示例#10
0
        public DisconnectedScreen()
        {
            TitleTranslationKey = "multiplayer.disconnect.generic";

            Body.ChildAnchor = Alignment.MiddleCenter;
            Body.AddChild(DisconnectedTextElement = new GuiTextElement()
            {
                Text      = Reason,
                TextColor = TextColor.Red,
                Anchor    = Alignment.MiddleCenter
            });

            Footer.AddChild(new GuiButton(MenuButtonClicked)
            {
                TranslationKey = "gui.toTitle",
                Anchor         = Alignment.MiddleCenter,
                Modern         = false
            });
        }
示例#11
0
        private void BuildWidgets()
        {
            Background = AddChild(new Background(Sprites.MenuBackground));
            Body       = AddChild(new Widget());
            TopRow     = Body.AddChild(new Widget());
            ToggleBag  = Body.AddChild(new WrapBag(MaxItemColumns * Game1.tileSize));

            NextButton          = TopRow.AddChild(new SpriteButton(Sprites.RightArrow));
            PrevButton          = TopRow.AddChild(new SpriteButton(Sprites.LeftArrow));
            NextButton.OnPress += () => CycleCategory(1);
            PrevButton.OnPress += () => CycleCategory(-1);

            SelectAllButton           = TopRow.AddChild(new LabeledCheckbox("All"));
            SelectAllButton.OnChange += OnToggleSelectAll;

            CloseButton          = AddChild(new SpriteButton(Sprites.ExitButton));
            CloseButton.OnPress += () => OnClose?.Invoke();

            CategoryLabel = TopRow.AddChild(new Label("", Color.Black, HeaderFont));
        }
        public void Send(Element element, Action <Element> onerror)
        {
            // Send a single item or to accumulate a buffer until a bodyend.
            Body             body          = null;
            Action <Element> commonOnError = null;

            lock (buffer)
            {
                if (!(element is BodyEnd))
                {
                    element = PrepareElement(element);
                    buffer.Add(Tuple.Create(element, onerror));

                    if (buffer.Any(t => t.Item1 is Body))
                    {
                        return;
                    }
                }

                var elements = buffer.Select(t => t.Item1);
                body = elements.FirstOrDefault(e => e is Body) as Body ?? new Body();
                foreach (var e in elements.Where(e => !(e is Body)))
                {
                    body.AddChild(e);
                    if (e is agsXMPP.protocol.Error || e is agsXMPP.protocol.sasl.Failure || e is agsXMPP.protocol.tls.Failure)
                    {
                        body.Type = BoshType.terminate;
                        body.SetAttribute("condition", "remote-stream-error");
                    }
                }

                var onerrors = (from t in buffer where t.Item2 != null select new Action(() => t.Item2(t.Item1))).ToList();
                commonOnError = _ => onerrors.ForEach(e => e());

                buffer.Clear();
            }
            SendBody(body, commonOnError);
        }
        public void DoubleSharedDocumentAfterDisposal()
        {
            using var ms2  = new MemoryStream();
            using var doc2 = WordprocessingDocument.Create(ms2, WordprocessingDocumentType.Document);

            var shared        = doc2.AddSharedParagraphIdFeature();
            var previousValue = default(HexBinaryValue);

            using (var ms1 = new MemoryStream())
                using (var doc1 = WordprocessingDocument.Create(ms1, WordprocessingDocumentType.Document))
                {
                    shared.Add(doc1);

                    // Add item to doc1
                    var part1 = doc1.AddMainDocumentPart();
                    var body1 = new Body();
                    var p1    = new Paragraph();
                    part1.Document = new Document(body1);
                    body1.AddChild(p1);

                    previousValue = p1.ParagraphId;
                }

            // Add item with same ID to doc2
            var part2 = doc2.AddMainDocumentPart();
            var body2 = new Body();
            var p2    = new Paragraph {
                ParagraphId = previousValue
            };

            part2.Document = new Document(body2);
            body2.AddChild(p2);

            // Assert
            Assert.NotNull(previousValue);
            Assert.NotEqual(previousValue, p2.ParagraphId);
            Assert.Equal(2, shared.Count);
        }
示例#14
0
        private void Initialize()
        {
            _playerProfileService = GetService <IPlayerProfileService>();
            _playerProfileService.Authenticate += PlayerProfileServiceOnAuthenticate;

            base.HeaderTitle.Anchor    = Alignment.MiddleCenter;
            base.HeaderTitle.FontStyle = FontStyle.Bold | FontStyle.DropShadow;
            Footer.ChildAnchor         = Alignment.MiddleCenter;
            GuiTextElement t;

            Footer.AddChild(t = new GuiTextElement()
            {
                Text      = "We are NOT in anyway or form affiliated with Mojang/Minecraft or Microsoft!",
                TextColor = TextColor.Yellow,
                Scale     = 1f,
                FontStyle = FontStyle.DropShadow,

                Anchor = Alignment.MiddleCenter
            });

            GuiTextElement info;

            Footer.AddChild(info = new GuiTextElement()
            {
                Text = "We will never collect/store or do anything with your data.",

                TextColor = TextColor.Yellow,
                Scale     = 0.8f,
                FontStyle = FontStyle.DropShadow,

                Anchor  = Alignment.MiddleCenter,
                Padding = new Thickness(0, 5, 0, 0)
            });

            Body.BackgroundOverlay = new Color(Color.Black, 0.5f);
            Body.ChildAnchor       = Alignment.MiddleCenter;

            Body.AddChild(_authCodeElement);
            //ShowCode();

            if (CanUseClipboard)
            {
                AddGuiElement(new GuiTextElement()
                {
                    Text = $"If you click Sign-In, the above auth code will be copied to your clipboard!"
                });
            }

            var buttonRow = AddGuiRow(LoginButton = new GuiButton(OnLoginButtonPressed)
            {
                AccessKey = Keys.Enter,

                Text    = "Sign-In with Xbox",
                Margin  = new Thickness(5),
                Modern  = false,
                Width   = 100,
                Enabled = ConnectResponse != null
            }, new GuiButton(OnCancelButtonPressed)
            {
                AccessKey = Keys.Escape,

                TranslationKey = "gui.cancel",
                Margin         = new Thickness(5),
                Modern         = false,
                Width          = 100
            });

            buttonRow.ChildAnchor = Alignment.MiddleCenter;
        }
示例#15
0
        private void ProcessThread()
        {
            Body body     = null;
            int  children = 0;

            while (m_running)
            {
                lock (m_queue)
                {
                    //if (NeitherPending)
                    //    m_queue.AddFirst((XmlElement)null);

                    Debug.WriteLine("A: " + m_sockA.IsPending);
                    Debug.WriteLine("b: " + m_sockB.IsPending);
                    while ((m_queue.First == null) || BothPending)
                    {
                        Monitor.Wait(m_queue);
                        if (!m_running)
                        {
                            return;
                        }
                    }

                    // We'll enq nulls to get a poll.
                    // We'll enq a body in order to terminate.

                    Debug.Assert(m_queue.First != null);
                    body     = m_queue.First.Value as Body;
                    children = 0;
                    if (body != null)
                    {
                        // TODO: what to do with leftover stanzas!?
                        m_queue.RemoveFirst();
                    }
                    else
                    {
                        body = CreateOpenBodyTag();
                        while (m_queue.First != null)
                        {
                            XmlElement elem = m_queue.First.Value;
                            // ignore nulls.  we're going munge together all pending poll requests.
                            if (elem != null)
                            {
                                // if we get to a body in the queue, stop inserting, and wait for the body
                                // to come around again next time.
                                if (elem is Body)
                                {
                                    break;
                                }
                                body.AddChild(elem);
                                children++;
                            }
                            m_queue.RemoveFirst();
                        }
                    }
                }

                if (NeitherPending || (children > 0) || (body.Type == BodyType.terminate))
                {
                    if (body.RID == -1)
                    {
                        body.RID = Interlocked.Increment(ref m_rid);
                    }

                    byte[] buf = ENC.GetBytes(body.OuterXml);
                    GetSocket().Execute(METHOD, m_uri, buf, 0, buf.Length, CONTENT_TYPE);
                }

                if (body.Type == BodyType.terminate)
                {
                    // shutting down.
                    m_sockA.EnqueueClose();
                    m_sockB.EnqueueClose();
                    return;
                }
            }
        }
示例#16
0
        protected override void LoadContent()
        {
            base.LoadContent();
            var scene = new Scene();

            var camera = new Camera();

            scene.AddChild(camera);

            var physicsModule = scene.AddModule <PhysicsModule>(1f / 60f);

            physicsModule.Gravity = new Gravity(new Vector2(0f, -9f));

            var circleBody = new DynamicBody();

            circleBody.LocalPosition -= new Vector2(0f, 3f);
            circleBody.IsKinematic    = true;
            circleBody.Mass           = 3f;
            var circleCollider = new CircleCollider(0.75f);

            circleBody.Collider = circleCollider;
            var circleDrawer = new ColliderDrawer();

            circleBody.AddChild(circleDrawer);
            circleDrawer.Color         = Color.Green;
            circleDrawer.LineThickness = 2f;
            circleBody.AddChild(new VelocityChanger());
            scene.AddChild(circleBody);

            for (var y = 0; y < 1; y++)
            {
                for (var x = 0; x < 1; x++)
                {
                    var smallCircleBody = new DynamicBody {
                        Name = $"small circle {x}"
                    };
                    smallCircleBody.LocalPosition -= new Vector2(-3 + x, -1f + y);
                    smallCircleBody.IsKinematic    = true;
                    smallCircleBody.Mass           = 1f;
                    var smallCircleCollider = new CircleCollider(0.3f);
                    smallCircleBody.Collider        = smallCircleCollider;
                    smallCircleBody.PhysicsMaterial = new PhysicsMaterial(1f, 0f);
                    var smallCircleDrawer = new ColliderDrawer();
                    smallCircleBody.AddChild(smallCircleDrawer);
                    smallCircleDrawer.Color         = Color.OrangeRed;
                    smallCircleDrawer.LineThickness = 1f;
                    scene.AddChild(smallCircleBody);
                }
            }

            var rectangleBody = new Body();

            rectangleBody.Collider        = PolygonCollider.CreateRectangle(10f, 1f);
            rectangleBody.PhysicsMaterial = new PhysicsMaterial(0.5f, 1f);
            rectangleBody.LocalPosition  -= new Vector2(0f, 4f);
            var rectangleDrawer = new ColliderDrawer();

            rectangleBody.AddChild(rectangleDrawer);
            rectangleDrawer.Color         = Color.White;
            rectangleDrawer.LineThickness = 1f;
            scene.AddChild(rectangleBody);

            var angleBody1 = new Body();

            angleBody1.Collider        = new LineCollider(new Vector2(-8f, 4f), new Vector2(-5f, -3.5f));
            angleBody1.PhysicsMaterial = new PhysicsMaterial(0.5f, 1f);
            var angleDrawer1 = new ColliderDrawer();

            angleBody1.AddChild(angleDrawer1);
            angleDrawer1.Color         = Color.White;
            angleDrawer1.LineThickness = 1f;
            scene.AddChild(angleBody1);

            var angleBody2 = new Body();

            angleBody2.Collider        = new LineCollider(new Vector2(8f, 4f), new Vector2(5f, -3.5f));
            angleBody2.PhysicsMaterial = new PhysicsMaterial(0.5f, 1f);
            var angleDrawer2 = new ColliderDrawer();

            angleBody2.AddChild(angleDrawer2);
            angleDrawer2.Color         = Color.White;
            angleDrawer2.LineThickness = 1f;
            scene.AddChild(angleBody2);

            var lineBody = new Body();

            lineBody.Collider        = new LineCollider(new Vector2(-8f, 4f), new Vector2(8f, 4f));
            lineBody.PhysicsMaterial = new PhysicsMaterial(0.5f, 1f);
            var lineDrawer = new ColliderDrawer();

            lineBody.AddChild(lineDrawer);
            lineDrawer.Color         = Color.White;
            lineDrawer.LineThickness = 1f;
            scene.AddChild(lineBody);

            scene.SaveToFile(@"TestGame - CurrentLevel.json", new Serializer());
            this.CurrentScene = new Serializer().Deserialize <Scene>(@"TestGame - CurrentLevel.json");
        }