public void Map_Should_Return_Expected(TextSnippet input, TextSnippet original, TextSnippet expected)
        {
            // Arrange & Act
            var actual = _textSnippetFactory.Map(input, original);

            // Assert
            actual.Should().BeEquivalentTo(expected);
        }
예제 #2
0
 public Send_0X0388(QQUser user, TextSnippet fileName, long @group)
     : base(user)
 {
     Sequence  = GetNextSeq();
     SecretKey = user.TXProtocol.SessionKey;
     Command   = QQCommand.Message0X0388;
     FileName  = fileName;
     Group     = @group;
 }
예제 #3
0
        protected override void ParseBody()
        {
            Decrypt(User.TXProtocol.SessionKey);
            Reader.ReadBytes(4);
            Reader.ReadBytes(4); //自己的QQ
            Reader.ReadBytes(10);
            Reader.BeReadUInt16();
            Reader.ReadBytes(2);
            Reader.ReadBytes(Reader.BeReadUInt16());
            Group = Reader.BeReadLong32(); //群号
            var type = Reader.ReadByte();

            switch (type)
            {
            case 0x01:                                          // 群消息、被拉进/踢出群
            {
                FromQQ       = Reader.BeReadLong32();           //发消息人的QQ
                MessageIndex = Reader.ReadBytes(4);             //姑且叫消息索引吧
                ReceiveTime  = Reader.ReadBytes(4);             //接收时间
                Reader.ReadBytes(24);
                SendTime  = Reader.ReadBytes(4);                //发送时间
                MessageId = Reader.ReadBytes(4);                //消息 id
                Reader.ReadBytes(8);
                Font = Reader.ReadBytes(Reader.BeReadUInt16()); //字体
                Reader.ReadByte();
                Reader.ReadByte();
                Message = Reader.ReadRichtext();
                break;
            }

            case 0x0C:               // 被塞口球
            {
                Reader.ReadByte();   // 01?
                var muter = Reader.BeReadLong32();
                Reader.ReadBytes(4); // 疑似时间?
                Reader.ReadBytes(2); // 00 01?
                var victim = Reader.BeReadLong32();
                var time   = Reader.BeReadLong32();
                Message = new TextSnippet("", MessageType.Mute, ("Muter", muter), ("Victim", victim),
                                          ("Time", time));
                break;
            }
            }
        }
예제 #4
0
        public static void SendImageToGroup(this ISendMessageService service, long groupId, byte[] bytes)
        {
            var image = new TextSnippet()
            {
                Type = MessageType.Picture
            };

            image.Set("data", bytes);
            service.SendToGroup(groupId, image);
        }
예제 #5
0
        TextSnippet ITagHandler.Parse(string text, Color baseColor, string options)
        {
            TextSnippet textSnippet = new TextSnippet(text);

            if (!int.TryParse(options, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out int result))
            {
                return(textSnippet);
            }
            textSnippet.Color = new Color((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF);
            return(textSnippet);
        }
예제 #6
0
        public TextSnippetWindow(PluginEngine pluginEngine, TextSnippet snippet = null)
        {
            _pluginEngine = pluginEngine;
            InitializeComponent();

            if (snippet != null)
            {
                TxtTitle.Text   = snippet.Identifier;
                TxtContent.Text = snippet.RawContent;
            }
        }
예제 #7
0
        // Token: 0x06001187 RID: 4487 RVA: 0x0040DE14 File Offset: 0x0040C014
        TextSnippet ITagHandler.Parse(string text, Color baseColor, string options)
        {
            TextSnippet textSnippet = new TextSnippet(text);
            int         num;

            if (!int.TryParse(options, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out num))
            {
                return(textSnippet);
            }
            textSnippet.Color = new Color(num >> 16 & 255, num >> 8 & 255, num & 255);
            return(textSnippet);
        }
예제 #8
0
        TextSnippet ITagHandler.Parse(string text, Color baseColor, string options)
        {
            TextSnippet textSnippet = new TextSnippet(text);
            int         result;

            if (!int.TryParse(options, NumberStyles.AllowHexSpecifier, (IFormatProvider)CultureInfo.InvariantCulture, out result))
            {
                return(textSnippet);
            }
            textSnippet.Color = new Color(result >> 16 & (int)byte.MaxValue, result >> 8 & (int)byte.MaxValue, result & (int)byte.MaxValue);
            return(textSnippet);
        }
 public TextSnippet Map(TextSnippet textSnippet, TextSnippet originalTextSnippet)
 {
     if (textSnippet != null)
     {
         originalTextSnippet.Description = textSnippet.Description;
         originalTextSnippet.Tag         = textSnippet.Tag;
         originalTextSnippet.Value       = textSnippet.Value;
         return(originalTextSnippet);
     }
     else
     {
         return(originalTextSnippet);
     }
 }
예제 #10
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);

            // now we can draw after all other drawing.
            if (hoveredTextSnippet != null)
            {
                hoveredTextSnippet.OnHover();
                if (Main.mouseLeft && Main.mouseLeftRelease)
                {
                    hoveredTextSnippet.OnClick();
                }
                hoveredTextSnippet = null;
            }
        }
예제 #11
0
        public Element CreateTextSnippet(Element after)
        {
            int newOrderNr = 1;
            var ns         = new TextSnippet {
                Name = "Paragraph", Content = "<p>Enter text here...</p>".GetBytes()
            };

            ns.Parent = GetSection(after);
            if (after is TextSnippet)
            {
                newOrderNr = after.OrderNr + 1; // inserting always after so new element gets the position of current element
            } // else: keep 1 as default, as if not invoked from another textsnippet assume we're inserting after section
            this.ReorderLeafElementsAfterElement(ns, newOrderNr);
            return(ns);
        }
예제 #12
0
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            var title = TxtTitle.Text;

            if (string.IsNullOrEmpty(title))
            {
                const string msg = "Please specify a title for your snippet before saving it.";
                MessageBox.Show(msg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var snippet = new TextSnippet(title, TxtContent.Text);

            if (_pluginEngine.PluginByType <SnippetsPlugin>().AddSnippet(this, snippet))
            {
                snippet.SaveAsJson();
            }

            Close();
        }
예제 #13
0
        private void AddSectionToChapter(Section chapter)
        {
            const string bt = @"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
            var          s1 = new Section {
                Content = System.Text.Encoding.UTF8.GetBytes("First Section"), Name = "Section", OrderNr = 1, Parent = chapter
            };

            Ctx.Elements.Add(s1);
            var t1 = new TextSnippet {
                Content = System.Text.Encoding.UTF8.GetBytes(bt), Name = "Paragraph", OrderNr = 1, Parent = s1
            };

            Ctx.Elements.Add(t1);
            s1.Children = new List <Element> {
                t1
            };
            chapter.Children = new List <Element> {
                s1
            };
        }
예제 #14
0
        public override void DrawSelf(SpriteBatch sb)
        {
            base.DrawSelf(sb);
            int start = 0;

            for (int i = 0; i < _lineSnippetNumber.Count; i++)
            {
                StringBuilder sbb = new StringBuilder();
                for (int j = start; j < _text2.Count && j < start + _lineSnippetNumber[i]; j++)
                {
                    TextSnippet[] snippet = new TextSnippet[2];
                    snippet[0] = _text2[j];
                    snippet[1] = new TextSnippet(((j != _text2.Count - 1) ? ", " : ""));
                    int h;
                    ChatManager.DrawColorCodedStringWithShadow(sb, Main.fontMouseText, snippet, _label.Position + new Vector2(_label.MeasureSize(sbb.ToString()).X, i * 26f), 0f, Vector2.Zero, Scale, out h);
                    sbb.Append(_text2[j].TextOriginal + ((j != _text2.Count - 1) ? ", " : ""));
                }
                start += _lineSnippetNumber[i];
            }
        }
예제 #15
0
        private static void RestoreOpusFromFile(Opus opus, XDocument xDoc, string userName)
        {
            var saveElements = new List <Element>();
            Func <IEnumerable <XElement>, Element, List <Element> > helper = null;
            var currentChapter = opus.Name;
            var chapterOrder   = 1;

            helper = (nodes, parent) => {
                var ret     = new List <Element>();
                var orderNr = 1;
                foreach (var elm in nodes)
                {
                    Element newElm = null;
                    # region Detect Element Type
                    switch (elm.Attribute("Type").Value.ToLower())
                    {
                    case "opus":
                        # region OPUS
                        // do nothing as this import runs on opus level already, simply assign current as start
                        opus.Name            = elm.Attribute("Name").NullSafeString();
                        ((Opus)opus).Version = ((Opus)opus).Version + 1;
                        break;

                        # endregion
                    case "section":
                        # region SECTION
                        if (elm.FirstNode != null && elm.FirstNode.NodeType == System.Xml.XmlNodeType.Text)
                        {
                            newElm = new Section {
                                Content = System.Text.Encoding.UTF8.GetBytes(((XText)elm.FirstNode).Value.Trim())
                            };
                        }
                        else
                        {
                            newElm = new Section {
                                Content = System.Text.Encoding.UTF8.GetBytes("Empty Section")
                            };
                        }
                        if (elm.Attribute("Name") == null || String.IsNullOrEmpty(elm.Attribute("Name").Value))
                        {
                            newElm.Name = System.Text.Encoding.UTF8.GetString(newElm.Content);
                        }
                        else
                        {
                            newElm.Name = elm.Attribute("Name").Value;
                            if (elm.FirstNode == null)
                            {
                                newElm.Content = System.Text.Encoding.UTF8.GetBytes(elm.Attribute("Name").Value);
                            }
                        }
                        // only if import has an opus/parent part
                        if (elm.Parent != null && elm.Parent.Name == "Content")
                        {
                            newElm.Parent  = opus;
                            currentChapter = elm.Attribute("Name").NullSafeString();
                        }
                        currentChapter = currentChapter ?? "Import Files";
                        break;

                        # endregion
                    case "text":
                        # region TEXT
                        newElm = new TextSnippet {
                            Content = Encoding.UTF8.GetBytes(elm.GetInnerXml()),
                            Name    = elm.Value.CleanUpString(15)
                        };
                        break;

                        # endregion
                    case "image":
                        # region IMAGE
                        var    imgType = "png";
                        var    error   = false;
                        byte[] content = null;
                        switch (elm.Attribute("Method").NullSafeString())
                        {
                        case "Base64":
                            // assume the image is stored internally as Base64
                            try {
                                content = Convert.FromBase64String(elm.Value.Trim());
                            } catch (Exception ex) {
                                error = true;
                            }
                            break;

                        default:
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Error in Image: {0}", elm.ToString());
                            Console.ForegroundColor = ConsoleColor.Gray;
                            break;
                        }
                        if (error)
                        {
                            break;
                        }
                        // for this test console we don't save the images, add debug info here if needed
                        break;

                        # endregion
                    case "listing":
                        # region LISTING
                        newElm = new ListingSnippet {
                            Content         = Encoding.UTF8.GetBytes(elm.Value.Trim()), //.Replace("\n", " "); - Causes problems with Listing widget. All data is displayed in one line
                            Name            = elm.Attribute("Name") == null ? "Listing" : elm.Attribute("Name").Value,
                            Title           = elm.Attribute("Name") == null ? "Listing" : elm.Attribute("Name").Value,
                            Language        = elm.Attribute("Language") == null ? "" : elm.Attribute("Language").Value,
                            SyntaxHighlight = elm.Attribute("Highlight") == null || Boolean.Parse(elm.Attribute("Highlight").Value),
                            LineNumbers     = elm.Attribute("LineNumbers") == null || Boolean.Parse(elm.Attribute("LineNumbers").Value)
                        };
                        # endregion
                        break;
예제 #16
0
        // Attempt at fix: problems: long words crash it, spaces seem to be miscounted.
        public static List <List <TextSnippet> > WordwrapStringSmart(string text, Color c, DynamicSpriteFont font, int maxWidth, int maxLines)
        {
            TextSnippet[] array = ChatManager.ParseMessage(text, c).ToArray();
            List <List <TextSnippet> > finalList = new List <List <TextSnippet> >();
            List <TextSnippet>         list2     = new List <TextSnippet>();

            for (int i = 0; i < array.Length; i++)
            {
                TextSnippet textSnippet = array[i];
                string[]    array2      = textSnippet.Text.Split(new char[]
                {
                    '\n'
                });
                for (int j = 0; j < array2.Length - 1; j++)
                {
                    list2.Add(textSnippet.CopyMorph(array2[j]));
                    finalList.Add(list2);
                    list2 = new List <TextSnippet>();
                }
                list2.Add(textSnippet.CopyMorph(array2[array2.Length - 1]));
            }
            finalList.Add(list2);
            if (maxWidth != -1)
            {
                for (int k = 0; k < finalList.Count; k++)
                {
                    List <TextSnippet> currentLine = finalList[k];
                    float usedWidth = 0f;
                    for (int l = 0; l < currentLine.Count; l++)
                    {
                        //float stringLength = list3[l].GetStringLength(font); // GetStringLength doesn't match UniqueDraw
                        float stringLength = ChatManager.GetStringSize(font, new TextSnippet[] { currentLine[l] }, Vector2.One).X;
                        //float stringLength2 = ChatManager.GetStringSize(font, " ", Vector2.One).X;
                        //float stringLength3 = ChatManager.GetStringSize(font, "1", Vector2.One).X;

                        if (stringLength + usedWidth > (float)maxWidth)
                        {
                            int num2 = maxWidth - (int)usedWidth;
                            if (usedWidth > 0f)
                            {
                                num2 -= 16;
                            }
                            float toFill          = num2;
                            bool  filled          = false;
                            int   successfulIndex = -1;
                            int   index           = 0;
                            while (index < currentLine[l].Text.Length && !filled)
                            {
                                if (currentLine[l].Text[index] == ' ')
                                {
                                    if (ChatManager.GetStringSize(font, currentLine[l].Text.Substring(0, index), Vector2.One).X < toFill)
                                    {
                                        successfulIndex = index;
                                    }
                                    else
                                    {
                                        filled = true;
                                        //if (successfulIndex == 0)
                                        //	successfulIndex = index;
                                    }
                                }
                                index++;
                            }
                            if (currentLine[l].Text.Length == 0)
                            {
                                filled = true;
                            }
                            int num4 = successfulIndex;

                            if (successfulIndex == -1)                      // last item is too big
                            {
                                if (l == 0)                                 // 1st item in list, keep it and move on
                                {
                                    //list2 = new List<TextSnippet>{currentLine[l]};
                                    list2 = new List <TextSnippet>();
                                    for (int m = l + 1; m < currentLine.Count; m++)
                                    {
                                        list2.Add(currentLine[m]);
                                    }
                                    finalList[k] = finalList[k].Take(/*l + */ 1).ToList <TextSnippet>();                                    // take 1
                                    finalList.Insert(k + 1, list2);
                                }
                                else                                 // midway through list, keep previous and move this to next
                                {
                                    list2 = new List <TextSnippet>();
                                    for (int m = l; m < currentLine.Count; m++)
                                    {
                                        list2.Add(currentLine[m]);
                                    }
                                    finalList[k] = finalList[k].Take(l).ToList <TextSnippet>();                                    // take previous ones
                                    finalList.Insert(k + 1, list2);
                                }
                            }
                            else
                            {
                                string newText  = currentLine[l].Text.Substring(0, num4);
                                string newText2 = currentLine[l].Text.Substring(num4).TrimStart();
                                list2 = new List <TextSnippet>
                                {
                                    currentLine[l].CopyMorph(newText2)
                                };
                                for (int m = l + 1; m < currentLine.Count; m++)
                                {
                                    list2.Add(currentLine[m]);
                                }
                                currentLine[l] = currentLine[l].CopyMorph(newText);
                                finalList[k]   = finalList[k].Take(l + 1).ToList <TextSnippet>();
                                finalList.Insert(k + 1, list2);
                            }
                            break;
                        }
                        usedWidth += stringLength;
                    }
                }
            }
            if (maxLines != -1)
            {
                while (finalList.Count > 10)
                {
                    finalList.RemoveAt(10);
                }
            }
            return(finalList);
        }
예제 #17
0
        protected override void ParseBody()
        {
            Decrypt(User.TXProtocol.SessionKey);
            Reader.ReadBytes(4); // 疑似群号
            Reader.ReadBytes(4); //自己的QQ
            Reader.ReadBytes(10);
            var type = Reader.BeReadUInt16();

            Reader.ReadBytes(Reader.BeReadInt32());
            Group = Reader.BeReadLong32(); //群号
            var flag = Reader.ReadByte();

            // TODO: 把系统消息接口分出来
            switch (type)
            {
            case 0x52 when flag == 0x01:                        // 群消息、被拉进/踢出群
            {
                FromQQ       = Reader.BeReadLong32();           //发消息人的QQ
                MessageIndex = Reader.ReadBytes(4);             //姑且叫消息索引吧
                ReceiveTime  = Reader.ReadBytes(4);             //接收时间
                Reader.ReadBytes(24);
                SendTime  = Reader.ReadBytes(4);                //发送时间
                MessageId = Reader.ReadBytes(4);                //消息 id
                Reader.ReadBytes(8);
                Font = Reader.ReadBytes(Reader.BeReadUInt16()); //字体
                Reader.ReadByte();
                Reader.ReadByte();
                Message = Reader.ReadRichtext();
                break;
            }

            case 0x21:
            case 0x22:
            {
                Reader.ReadBytes(5);
                FromQQ = Reader.BeReadLong32();     // 邀请人/踢人QQ
                break;
            }

            case 0x2C:
            {
                // 群管理变更
                break;
            }

            default:
            {
                if (flag == 0x0C)        // 被塞口球
                {
                    Reader.ReadByte();   // 01?
                    var muter = Reader.BeReadLong32();
                    Reader.ReadBytes(4); // 疑似时间?
                    Reader.ReadBytes(2); // 00 01?
                    var victim = Reader.BeReadLong32();
                    var time   = Reader.BeReadLong32();
                    Message = new TextSnippet("", MessageType.Mute, ("Muter", muter), ("Victim", victim),
                                              ("Time", time));
                }

                break;
            }
            }
        }
예제 #18
0
        protected override void Seed(EditorContext context)
        {
            base.Seed(context);

            #region Author Portal

            Console.WriteLine("DemoContent");
            #region create a sample
            Func <IEnumerable <XElement>, List <Element> > helper = null;
            var      currentChapter = String.Empty;
            var      chapterOrder   = 1;
            Document opus           = null;
            helper = nodes => {
                var ret     = new List <Element>();
                int orderNr = 1;
                foreach (var elm in nodes)
                {
                    Element newElm = null;
                    # region Detect Element Type
                    switch (elm.Attribute("Type").Value.ToLower())
                    {
                    case "opus":
                        # region OPUS
                        // create opus
                        newElm = new Document {
                            Name = elm.Attribute("Name").Value
                        };
                        opus = (Document)newElm;
                        // this is an easy way to implement a workflow
                        break;

                        # endregion
                    case "section":
                        # region SECTION
                        if (elm.FirstNode != null && elm.FirstNode.NodeType == System.Xml.XmlNodeType.Text)
                        {
                            newElm = new Section {
                                Content = System.Text.Encoding.UTF8.GetBytes(((XText)elm.FirstNode).Value.Trim())
                            };
                        }
                        else
                        {
                            newElm = new Section {
                                Content = System.Text.Encoding.UTF8.GetBytes("Empty Section")
                            };
                        }
                        if (elm.Attribute("Name") == null || String.IsNullOrEmpty(elm.Attribute("Name").Value))
                        {
                            newElm.Name = System.Text.Encoding.UTF8.GetString(newElm.Content);
                        }
                        else
                        {
                            newElm.Name = elm.Attribute("Name").Value;
                            if (elm.FirstNode == null)
                            {
                                newElm.Content = System.Text.Encoding.UTF8.GetBytes(elm.Attribute("Name").Value);
                            }
                        }
                        // Detect Chapter Elements to store resources in subfolders
                        if (elm.Parent.Attribute("Type").Value == "Opus")
                        {
                            currentChapter = elm.Attribute("Name").Value;
                        }
                        break;

                        # endregion
                    case "text":
                        # region TEXT
                        newElm = new TextSnippet {
                            Content = System.Text.Encoding.UTF8.GetBytes(elm.GetInnerXml()),
                            Name    = elm.Value.CleanUpString(15)
                        };
                        break;

                        # endregion
                    case "image":
                        # region IMAGE
                        var imgpath = elm.Value.Trim();
                        Debug.Assert(Path.GetExtension(imgpath).Length > 0, "no extension " + imgpath);
                        // get and optionally create folder after chapter
                        //
                        var res = new Resource {
                            Name            = elm.Attribute("Name").Value,
                            OwnerDocument   = opus,
                            TypesOfResource = TypeOfResource.Content,
                            MimeType        = "image/" + Path.GetExtension(imgpath).Substring(1) // kick the leading "."
                        };
                        System.Drawing.Image img = null;
                        var localPath            = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "DemoContent", imgpath);
                        if (File.Exists(localPath))
                        {
                            var bytes = File.ReadAllBytes(localPath);
                            res.Content = bytes;
                        }
                        context.Resources.Add(res);
                        newElm = new ImageSnippet {
                            Content  = res.Content,
                            Name     = res.Name,
                            Title    = res.Name,
                            MimeType = res.MimeType
                        };
                        var imgprops = new ImageProperties();
                        if (elm.Attribute("Width") == null || elm.Attribute("Height") == null)
                        {
                            if (img != null)
                            {
                                imgprops.ImageWidth  = imgprops.OriginalWidth = img.Width;
                                imgprops.ImageHeight = imgprops.OriginalHeight = img.Height;
                            }
                            else
                            {
                                imgprops.ImageWidth  = imgprops.OriginalWidth = 100;
                                imgprops.ImageHeight = imgprops.OriginalHeight = 100;
                            }
                        }
                        else
                        {
                            imgprops.ImageWidth  = imgprops.OriginalWidth = Convert.ToInt32(elm.Attribute("Width").GetNullSafeValue());
                            imgprops.ImageHeight = imgprops.OriginalHeight = Convert.ToInt32(elm.Attribute("Height").GetNullSafeValue());
                        }
                        ((ImageSnippet)newElm).Properties = new JavaScriptSerializer().Serialize(imgprops);
                        break;

                        # endregion
                    case "listing":
                        # region LISTING
                        newElm = new ListingSnippet {
                            Content         = System.Text.UTF8Encoding.UTF8.GetBytes(elm.Value.Trim()), //.Replace("\n", " "); - Causes problems with Listing widget. All data is displayed in one line
                            Name            = elm.Attribute("Name") == null ? "Listing" : elm.Attribute("Name").Value,
                            Title           = elm.Attribute("Name") == null ? "Listing" : elm.Attribute("Name").Value,
                            Language        = elm.Attribute("Language") == null ? "" : elm.Attribute("Language").Value,
                            SyntaxHighlight = elm.Attribute("Highlight") == null ? true : Boolean.Parse(elm.Attribute("Highlight").Value),
                            LineNumbers     = elm.Attribute("LineNumbers") == null ? true : Boolean.Parse(elm.Attribute("LineNumbers").Value)
                        };
                        # endregion
                        break;