Exemple #1
0
 public Tag(string name, string value)
 {
     this.name = name;
     this.value = value;
     if (!value.Equals(""))
     {
         this.tags = ParseValue(value);
     }
 }
        public static TagControl GetControlInstance(Panel panel, Tag tag, UserControlBase upControl, UserControlBase downControl)
        {
            //UserControlBase control;
            TagControl control;
            control = new TagControl(tag);

            control.Location = new System.Drawing.Point(10, 20);
            //rowCollection.Name = "Data" + columnCount;
            control.Size = new System.Drawing.Size(800, 30);
            control.TabIndex = 0;

            control.UpControl = upControl;
            control.DownControl = downControl;
            panel.Controls.Add(control);
            return control;
        }
 private void LoadXMLChild(TreeNode treeNode, XmlNode xmlNode)
 {
     TreeNode newTreeNode;
     foreach (XmlNode node in xmlNode.ChildNodes)
     {
         if (node.NodeType == XmlNodeType.Element)
         {
             if (node.Name == "tag")
             {
                 if (node.Attributes["type"] != null)
                 {
                     // check if node is type of object
                     if (node.Attributes["type"].Value == "object")
                     {
                         if (treeNode != null)
                         {
                             // if treeNode not null then build contorl nodes
                             newTreeNode = new TreeNode(node.Attributes["name"].Value);
                             newTreeNode.Name = node.Attributes["name"].Value;
                             treeNode.Nodes.Add(newTreeNode);
                             if (node.HasChildNodes)
                             {
                                 LoadXMLChild(newTreeNode, node);
                             }
                         }
                     }
                     else
                     {
                         Tag tag = new Tag(node.Attributes["name"].Value, "");
                         TagControl tagControl = TagControl.GetControlInstance(pParametars, tag, tagControlLastTmp, null);
                         tagControlLastTmp = tagControl;
                         if (node.HasChildNodes)
                         {
                             LoadXMLChild(treeNode, node);
                         }
                     }
                 }
                 else
                 {
                     ModuleLog.Write("Bad xml format \r\n" + node.InnerXml, this, "LoadXMLChild", ModuleLog.LogType.WARNING);
                 }
             }
             else if (node.Name == "syntax")
             {
                 tbSyntax.Text = node.InnerText;
             }
             else if (node.Name == "result")
             {
                 lblResult.Text = "Result: " + node.InnerText;
             }
             else if (node.Name == "example")
             {
                 lblExample.Text = "Example: " + node.InnerText;
             }
             else
             {
                 if (node.HasChildNodes)
                 {
                     LoadXMLChild(treeNode, node);
                 }
             }
         }
     }
 }
 public void SetTag(Tag tag)
 {
     lName.Text = tag.Name;
     tbValue.Text = tag.Value;
 }
 public TagControl(Tag tag)
 {
     InitializeComponent();
     this.tag = tag;
 }
        private string XMLObject(object obj, string objectValue)
        {
            string result = null;
            Tag tag = new Tag("xml", objectValue);
            try
            {
                if (tag.Tags.Name == "xpath")
                {
                    if (tag.Tags.Tags.Name == "attribute")
                    {
                        //{=xml.xpath.attribute.atributeToGet.xpathText}
                        result = XMLParser.XMLObject.GetXPathAttributeValue(tag.Tags.Tags.Tags.Value, tag.Tags.Tags.Tags.Name);
                    }
                }
                else
                {
                    ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "XMLObject", ModuleLog.LogType.ERROR);
                    result = constError_SyntaxError;
                }

            }
            catch (Exception ex)
            {
                ModuleLog.Write(ex, this, "XMLObject", ModuleLog.LogType.ERROR);
                ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "XMLObject", ModuleLog.LogType.DEBUG);
                result = constError_SyntaxError;
            }
            return result;
        }
        private string StringObject(RowCollectionRow row, string objectValue)
        {
            string result = null;
            Tag tag = new Tag("string", objectValue);

            try
            {
                if (tag.Tags.Name == "trim")
                {
                    result = tag.Tags.Value.Trim();
                }
                else if (tag.Tags.Name == "substring")
                {
                    // {=string.substring.4.2.neki text}
                    int start;
                    int lenght;
                    start = int.Parse(tag.Tags.Tags.Name);
                    lenght = int.Parse(tag.Tags.Tags.Tags.Name);
                    // if index is in range of string length
                    if ((start + lenght) < tag.Tags.Tags.Tags.Value.Length)
                    {
                        result = tag.Tags.Tags.Tags.Value.Substring(start, lenght);
                    }
                    else
                    {
                        // else return empty string and log waring
                        result = "";
                        ModuleLog.Write("String out of range returning empty string", this, "StringObject", ModuleLog.LogType.WARNING);
                    }
                }
                else if (tag.Tags.Name == "indexof")
                {
                    // {=string.indexof. .damir marijanovic}
                    result = tag.Tags.Tags.Value.IndexOf(tag.Tags.Tags.Name).ToString();
                }
                else if (tag.Tags.Name == "toupper")
                {
                    result = tag.Tags.Value.ToUpper();
                }
                else if (tag.Tags.Name == "tolower")
                {
                    result = tag.Tags.Value.ToLower();
                }
                else if (tag.Tags.Name == "replace")
                {
                    // {=string.replace.old.new.text}
                    result = tag.Tags.Tags.Tags.Value.Replace(tag.Tags.Tags.ToString(), tag.Tags.Tags.Tags.ToString());
                }
                else if (tag.Tags.Name == "split")
                {
                    // string.split.[index].[split string].[text]
                    string[] splitList = tag.Tags.Tags.Tags.Value.Split(new string[] { tag.Tags.Tags.Tags.Name }, StringSplitOptions.RemoveEmptyEntries);
                    int index;
                    index = int.Parse(tag.Tags.Tags.Name);
                    // if index is in range of array
                    if (index < splitList.Length)
                    {
                        result = splitList[index];
                    }
                    else
                    {
                        // else return empty string and log waring
                        result = "";
                        ModuleLog.Write("String out of range returning empty string", this, "StringObject", ModuleLog.LogType.WARNING);
                    }
                }
                else
                {
                    ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "StringObject", ModuleLog.LogType.ERROR);
                    result = constError_SyntaxError;
                }
            }
            catch(Exception ex)
            {
                ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "StringObject", ModuleLog.LogType.DEBUG);
                ModuleLog.Write(ex, this, "StringObject", ModuleLog.LogType.ERROR);
                result = constError_SyntaxError;
            }
            return result;
        }
        private string RandomObject(object obj, string objectValue)
        {
            string result = null;
            Tag tag = new Tag("random", objectValue);
            try
            {
                if (tag.Tags.Name == "number")
                {
                    int minValue;
                    int maxValue;
                    minValue = int.Parse(tag.Tags.Tags.Name);
                    maxValue = int.Parse(tag.Tags.Tags.Value);
                    if (random == null)
                    {
                        random = new Random();
                    }
                    result = random.Next(minValue, maxValue).ToString();
                }
                else if (tag.Tags.Name == "string")
                {
                    int maxChar;
                    maxChar = int.Parse(tag.Tags.Value);

                    result = RandomString(maxChar);
                }
                else
                {
                    ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "RandomObject", ModuleLog.LogType.ERROR);
                    result = constError_SyntaxError;
                }

            }
            catch (Exception ex)
            {
                ModuleLog.Write(ex, this, "RandomObject", ModuleLog.LogType.ERROR);
                ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "RandomObject", ModuleLog.LogType.DEBUG);
                result = constError_SyntaxError;
            }
            return result;
        }
 private string NumberObject(RowCollectionRow row, string objectValue)
 {
     string result = null;
     Tag tag = new Tag("number", objectValue);
     try
     {
         if (tag.Value == "getvalue")
         {
             //{=number.getvalue}
             result = numberObject_counter.ToString();
         }
         else
         {
             if (tag.Tags.Name == "increment")
             {
                 //{=number.increment.startNumber.incrementBy}
                 if (numberObject_counter == constNumberObject_counter_defaultValue)
                 {
                     ModuleLog.Write(tag.Tags.Tags.Name, this, "NumberObject", ModuleLog.LogType.INFO);
                     numberObject_counter = int.Parse(tag.Tags.Tags.Name);
                 }
                 else
                 {
                     int number_to_increment = 0;
                     number_to_increment = int.Parse(tag.Tags.Tags.Value);
                     numberObject_counter = numberObject_counter + number_to_increment;
                 }
                 result = numberObject_counter.ToString();
             }
             else
             {
                 ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "NumberObject", ModuleLog.LogType.WARNING);
                 result = constError_SyntaxError;
             }
         }
     }
     catch (Exception ex)
     {
         ModuleLog.Write(ex, this, "--NumberObject", ModuleLog.LogType.ERROR);
         ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "--NumberObject", ModuleLog.LogType.DEBUG);
         result = constError_SyntaxError;
     }
     return result;
 }
        private string NTHObject(RowCollectionRow row, string objectValue)
        {
            string result = null;
            Tag tag = new Tag("nth", objectValue);

            try
            {
                if (tag.Tags.Name == "swapzarez")
                {
                    //{=nth.swapzarez.text}
                    result = tag.Tags.Value.Replace(",", "<;>");
                }
                else if (tag.Tags.Name == "max160")
                {
                    //{=nth.max160.text}
                    if (tag.Tags.Value.Length > 160)
                    {
                        result = "- - - W A R N I N G (text length " + tag.Tags.Value.Length + " )  - - -";
                        ModuleLog.Write(result, this, "NTHObject", ModuleLog.LogType.WARNING);
                        ModuleLog.Write(tag.Tags.Value, this, "NTHObject", ModuleLog.LogType.DEBUG);
                    }
                    else
                    {
                        result = tag.Tags.Value;
                    }
                }
                else
                {
                    ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "NTHObject", ModuleLog.LogType.ERROR);
                    result = constError_SyntaxError;
                }
            }
            catch
            {
                ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "NTHObject", ModuleLog.LogType.ERROR);
                result = constError_SyntaxError;
            }
            return result;
        }
        private string MD5Object(object obj, string objectValue)
        {
            string result = null;
            Tag tag = new Tag("md5", objectValue);
            try
            {
                if (tag.Tags.Name == "text")
                {
                    result = MD5.MD5FromText(tag.Tags.Value);
                }
                else if (tag.Tags.Name == "file")
                {
                    result = MD5.MD5FromFile(tag.Tags.Value);
                }
                else
                {
                    ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "MD5Object", ModuleLog.LogType.ERROR);
                    result = constError_SyntaxError;
                }

            }
            catch (Exception ex)
            {
                ModuleLog.Write(ex, this, "MD5Object", ModuleLog.LogType.ERROR);
                ModuleLog.Write(string.Concat(constError_SyntaxError, " (", objectValue, ")"), this, "MD5Object", ModuleLog.LogType.DEBUG);
                result = constError_SyntaxError;
            }
            return result;
        }
        public TagsStorage GetTagsStorage(Tag tag)
        {
            TagsStorage result = null;
            foreach (TagsStorage tagsStorage in this)
            {
                if (tagsStorage.name == tag.Name || (tagsStorage.tagType != TagType.Object) && tag.Name != ""  )
                {
                    if (tag.Tags == null)
                    {
                        result = tagsStorage;
                    }
                    else
                    {
                        result = tagsStorage.GetTagsStorage(tag.Tags);
                    }
                }
            }
            if (result == null)
            {
                result = this;
            }

            return result;
        }
        private void UpdateHoveringWindowList(string text)
        {
            TagsStorage activeTagStorage = null;
            TreeNode treeNode;

            if (text.Length > 2)
            {
                text = text.Substring(2, text.Length - 2);
                Tag tag = new Tag("Root", text);
                activeTagStorage = tagsStorage.GetTagsStorage(tag.Tags);
            }
            else
            {
                activeTagStorage = tagsStorage;
            }
            if (activeTagStorage != null)
            {
                tvList.Nodes.Clear();
                foreach (TagsStorage tags in activeTagStorage)
                {
                    treeNode = new TreeNode(tags.Name, 0, 0);
                    treeNode.Tag = tags.Type == TagsStorage.TagType.Object ? tags.Name : "\"\"";
                    tvList.Nodes.Add(treeNode);
                }
            }
            // ovo je tmp rjesenje jer " . " bug, raditi preko tagova orginalno
            int lastIndexOfDot = text.LastIndexOf('.');
            string lastText;
            if (lastIndexOfDot != -1)
            {
                lastText = text.Substring(lastIndexOfDot + 1, (text.Length - lastIndexOfDot) - 1);
            }
            else
            {
                lastText = text;
            }

            // select active node base on user input
            foreach (TreeNode node in tvList.Nodes)
            {
                if (node.Text.StartsWith(lastText))
                {
                    tvList.SelectedNode = node;
                    break;
                }
            }
        }