Example #1
0
 public static VObject FromHtml(string input)
 {
     if (string.IsNullOrEmpty(input))
     return null;
       int posIdx1 = 0;
       int posIdx2 = 0;
       posIdx1 = input.IndexOf("<!-- ##");
       if (posIdx1 == -1)
     return null;
       input = input.Substring(posIdx1);
       string[] para = Strings.Split(input, "##");
       switch (Strings.UCase(para[1])) {
     case "IMG":
     case "VIMAGE":
       VImage myobj = new VImage();
       myobj.Deserialize(para);
       posIdx1 = input.IndexOf("src=\"") + 5;
       posIdx2 = input.IndexOf("\"", posIdx1);
       if (posIdx1 < 5 | posIdx2 == -1 | posIdx2 < posIdx1)
     return null;
       dynamic img = Helper.Base64ToImage(new System.Text.StringBuilder(input.Substring(posIdx1, posIdx2 - posIdx1)));
       ((VImage)myobj).img = img;
       return myobj;
     case "RTF":
     case "VTEXTBOX":
       VTextbox myobj = new VTextbox();
       myobj.Deserialize(para);
       posIdx1 = input.IndexOf(Constants.vbNewLine) + 2;
       posIdx2 = input.LastIndexOf("</div>");
       if (posIdx1 < 2 | posIdx2 == -1 | posIdx2 < posIdx1)
     return null;
       ((VTextbox)myobj).Text = Helper.StripHtmlTags(input.Substring(posIdx1, posIdx2 - posIdx1).Replace("<br>", Constants.vbNewLine).Replace("<br/>", Constants.vbNewLine)).Replace("&lt;", "<").Replace("&gt;", ">");
       return myobj;
     case "VUMLCLASS":
       VUMLClass myobj = new VUMLClass();
       myobj.Deserialize(para);
       posIdx1 = input.IndexOf(Constants.vbNewLine) + 2;
       posIdx2 = input.LastIndexOf("</div>");
       if (posIdx1 < 2 | posIdx2 == -1 | posIdx2 < posIdx1)
     return null;
       myobj.ParseHtmlContent(input.Substring(posIdx1, posIdx2 - posIdx1));
       return myobj;
     case "VRECTANGLE":
       VRectangle myobj = new VRectangle();
       myobj.Deserialize(para);
       return myobj;
     case "VELIPSE":
       VElipse myobj = new VElipse();
       myobj.Deserialize(para);
       return myobj;
     case "VLINE":
       VLine myobj = new VLine();
       myobj.Deserialize(para);
       return myobj;
     default:
       return null;
       }
 }
Example #2
0
        public void readHtmlPage(string fileSpec)
        {
            dynamic sr = System.IO.File.OpenText(fileSpec);

            //clear All ???

            int lineNr = 0;
            int modusCounter = 0;
            string line = null;
            string modus = null;
            System.Text.StringBuilder contbuffer = null;
            VObject myObj = default(VObject);
            modus = "invalid";
            while (sr.EndOfStream == false) {
                lineNr += 1;
                modusCounter += 1;
                line = sr.ReadLine;
                if (line.Contains("ScreenShot 5 Collage") | line.Contains("ScreenShot 6 Collage")) {
                    modus = "valid";
                    modusCounter = 0;
                }
                if (modus == "invalid")
                    continue;

                if (line.StartsWith("<!-- ##page##")) {
                    string[] para = Strings.Split(line, "##");
                    PicBox.BackColor = Helper.String2Color(para[5]);
                    PicBox.Width = para[2];
                    PicBox.Height = para[3];

                    continue;
                }

                if (modus == "txt" & line == "</div>") {
                    modus = "valid";
                    modusCounter = 0;
                    if (myObj is VTextbox) {
                        ((VTextbox)myObj).Text = Strings.Trim(contbuffer.ToString()).Replace("<br>", Constants.vbCrLf).Replace("<br/>", Constants.vbCrLf);
                    } else if (myObj is VUMLClass) {
                        ((VUMLClass)myObj).ParseHtmlContent(Strings.Trim(contbuffer.ToString()));
                    }
                    addObject(myObj);
                }

                if (modus == "txt" & modusCounter >= 1) {
                    contbuffer.AppendLine(line);
                }

                if (modus == "img" & modusCounter >= 1) {
                    if (modusCounter == 1)
                        line = line.Substring(5);
                    //src="
                    if (line.EndsWith("\" />")) {
                        modus = "valid";
                        modusCounter = 0;
                        line = line.Substring(0, line.Length - 4);
                    }
                    contbuffer.AppendLine(line);
                    //Bild fertig
                    if (modus == "valid") {
                        dynamic img = Helper.Base64ToImage(contbuffer);
                        ((VImage)myObj).img = img;
                        addObject(myObj);
                    }
                }

                if (line.StartsWith("<!-- ##img##") | line.StartsWith("<!-- ##VImage##")) {
                    modus = "img";
                    modusCounter = 0;
                    string[] para = Strings.Split(line, "##");
                    myObj = new VImage();
                    myObj.Deserialize(para);
                    contbuffer = new System.Text.StringBuilder();
                }

                if (line.StartsWith("<!-- ##rtf##") | line.StartsWith("<!-- ##VTextbox##")) {
                    modus = "txt";
                    modusCounter = 0;
                    string[] para = Strings.Split(line, "##");

                    myObj = new VTextbox();
                    myObj.Deserialize(para);
                    contbuffer = new System.Text.StringBuilder();
                }

                if (line.StartsWith("<!-- ##VUMLClass##")) {
                    modus = "txt";
                    modusCounter = 0;
                    string[] para = Strings.Split(line, "##");

                    myObj = new VUMLClass();
                    myObj.Deserialize(para);
                    contbuffer = new System.Text.StringBuilder();
                }

                if (line.StartsWith("<!-- ##VElipse##")) {
                    modus = "valid";
                    modusCounter = 0;
                    string[] para = Strings.Split(line, "##");

                    myObj = new VElipse();
                    myObj.Deserialize(para);
                    addObject(myObj);
                }

                if (line.StartsWith("<!-- ##VLine##")) {
                    modus = "valid";
                    modusCounter = 0;
                    string[] para = Strings.Split(line, "##");

                    myObj = new VLine();
                    myObj.Deserialize(para);
                    addObject(myObj);
                }

                if (line.StartsWith("<!-- ##VRectangle##")) {
                    modus = "valid";
                    modusCounter = 0;
                    string[] para = Strings.Split(line, "##");

                    myObj = new VRectangle();
                    myObj.Deserialize(para);
                    addObject(myObj);
                }

            }

            if (modus == "invalid") {
                Interaction.MsgBox("Ungültiges Dateiformat.", MsgBoxStyle.Critical);
            }

            sr.Close();
        }