Пример #1
0
        /// <summary>
        /// Handle user click on button and trigger event to other control
        /// </summary>
        private void OnThumbnailClick(object sender, EventArgs e)
        {
            try
            {
                if (!(sender is Button btn))
                {
                    return;
                }
                NodeTag nodeTag = btn.Tag as NodeTag;

                if (nodeTag.IsBranch)
                {
                    ShowBranch(nodeTag);
                }
                // trigger event
                // mainform : hide branchview + show adapted viewer
                // DocumentTreeView -> show adapted
                SelectionChanged?.Invoke(this, new NodeEventArgs(nodeTag.TreeNode, nodeTag.Type), nodeTag.Name);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                _log.Debug(ex.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Handle user click on button and trigger event to other control
        /// </summary>
        private void btn_Click(object sender, EventArgs e)
        {
            try
            {
                Button btn = sender as Button;
                if (null == btn)
                {
                    return;
                }
                NodeTag nodeTag = btn.Tag as NodeTag;

                if (nodeTag.IsTreeNode)
                {
                    ShowBranch(nodeTag.TreeNode);
                }
                // trigger event
                // mainform : hide branchview + show adapted viewer
                // DocumentTreeView -> show adapted
                if (null != SelectionChanged)
                {
                    SelectionChanged(this, new NodeEventArgs(nodeTag.TreeNode, nodeTag.Type), nodeTag.Name);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                _log.Debug(ex.ToString());
            }
        }
Пример #3
0
        void CreateTree(TreeView tv)
        {
            String    NodeName;
            DataTable dt     = MyManager.GetDataSet("select ID,name,(case when FingerTmpStr is null then 0 when FingerTmpStr IS not null then 1 end) as sign  from userlist order by Name asc");
            TreeNode  p_node = tv.Nodes.Add("全体人员");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["sign"].ToString() == "0")
                {
                    NodeName = dt.Rows[i]["Name"].ToString() + "(N)";
                }
                else
                {
                    NodeName = dt.Rows[i]["Name"].ToString() + "(Y)";
                }
                NodeTag nt = new NodeTag();
                nt.UserName      = dt.Rows[i]["Name"].ToString();
                nt.UserID        = dt.Rows[i]["ID"].ToString();
                nt.HaveFingerTmp = Convert.ToInt32(dt.Rows[i]["sign"].ToString());
                TreeNode node = new TreeNode(NodeName);
                node.Tag = nt;
                if (nt.HaveFingerTmp == 0)
                {
                    node.ForeColor = Color.Red;
                }

                p_node.Nodes.Add(node);
            }
            p_node.Expand();
            //tv.Nodes.Add(p_node);
        }
Пример #4
0
        /// <summary>
        /// Parse the string value to create an object.
        /// </summary>
        /// <param name="type">The type of the created object.</param>
        /// <param name="str">The string value of the created object.</param>
        /// <param name="node">The owner node of the created object.</param>
        /// <returns>Returns the created object.</returns>
        public static object ParseStringValue(Type type, string str, NodeTag.DefaultObject node)
        {
            object obj = null;
            Plugin.InvokeTypeParser(type, str, (object value) => obj = value, node);

            return obj;
        }
Пример #5
0
        private void SetFileCount(TreeNodeCollection treenodes, ref int exportedFileCount, ref int uncheckedFilesCount, ref int errorsFilesCount)
        {
            foreach (TreeNode node in treenodes)
            {
                NodeTag nodetag = (NodeTag)node.Tag;

                if (nodetag.Type == NodeTagType.Behavior)
                {
                    if (node.Checked)
                    {
                        exportedFileCount++;
                    }
                    else
                    {
                        uncheckedFilesCount++;

                        if (node.ForeColor == SystemColors.GrayText)
                        {
                            errorsFilesCount++;
                        }
                    }
                }

                SetFileCount(node.Nodes, ref exportedFileCount, ref uncheckedFilesCount, ref errorsFilesCount);
            }
        }
Пример #6
0
        void postfix_nodes(TreeNodeCollection nodes, bool is_visible)
        {
            foreach (TreeNode t in nodes)
            {
                if (t.Tag != null && t.Tag is NodeTag)
                {
                    NodeTag   nt  = (NodeTag)t.Tag;
                    UmlObject obj = nt.n as UmlObject;
                    if (obj != null)
                    {
                        if (is_visible)
                        {
                            ArrayList l = new ArrayList();
                            get_children(obj, l);

                            if (!nt.initialized)
                            {
                                add_nodes(t.Nodes, l, -1);
                                nt.initialized = true;
                            }
                            else
                            {
                                merge_nodes(t.Nodes, l, -1);
                                postfix_nodes(t.Nodes, t.IsExpanded);
                            }
                        }
                        else
                        {
                            t.Nodes.Clear();
                            nt.initialized = false;
                        }
                    }
                }
            }
        }
Пример #7
0
        private void ShowNodes(TreeNodeCollection treenodes, bool onlyShowFaultBehaviors)
        {
            List <TreeNode> removedNodes = new List <TreeNode>();

            foreach (TreeNode node in treenodes)
            {
                NodeTag nodetag   = (NodeTag)node.Tag;
                bool    isRemoved = false;

                if (nodetag.Type == NodeTagType.Behavior)
                {
                    if (onlyShowFaultBehaviors && (node.Checked || node.ForeColor != SystemColors.GrayText))
                    {
                        removedNodes.Add(node);
                        isRemoved = true;
                    }
                }

                if (!isRemoved)
                {
                    ShowNodes(node.Nodes, onlyShowFaultBehaviors);
                }
            }

            foreach (TreeNode node in removedNodes)
            {
                node.Remove();
            }
        }
Пример #8
0
        private void RemoveEmptyNodes(TreeNodeCollection treenodes)
        {
            List <TreeNode> removedNodes = new List <TreeNode>();

            foreach (TreeNode node in treenodes)
            {
                NodeTag nodetag   = (NodeTag)node.Tag;
                bool    isRemoved = false;

                if (nodetag.Type == NodeTagType.BehaviorFolder && !hasLeaf(node))
                {
                    removedNodes.Add(node);
                    isRemoved = true;
                }

                if (!isRemoved)
                {
                    RemoveEmptyNodes(node.Nodes);
                }
            }

            foreach (TreeNode node in removedNodes)
            {
                node.Remove();
            }
        }
Пример #9
0
        public static new object ParseStringValue(Type type, string str, NodeTag.DefaultObject node)
        {
            Debug.Check(type != null && Plugin.IsArrayType(type));

            object obj = Plugin.CreateInstance(type);
            Debug.Check(obj != null);

            if (!string.IsNullOrEmpty(str))
            {
                System.Collections.IList list = (System.Collections.IList)obj;
                Type itemType = type.GetGenericArguments()[0];

                int index = str.IndexOf(':');
                if (index >= 0)
                    str = str.Substring(index + 1);

                if (!string.IsNullOrEmpty(str))
                {
                    System.Collections.IList structArray = (System.Collections.IList)Plugin.CreateInstance(type);
                    parseStringValue(node, structArray, itemType, str, 0, str.Length - 1);

                    return structArray;
                }
            }

            return obj;
        }
        public async Task UpdateTag(NodeTag newNodeTagData)
        {
            NodeTag tag = await _context.Tags.FindAsync(newNodeTagData.ID);

            tag.Name = newNodeTagData.Name;
            await _context.SaveChangesAsync();
        }
Пример #11
0
        /// <summary>
        /// Handles actions that occur after the user checked/unchecked an item.
        /// </summary>
        private void treeView_AfterCheck(object sender, TreeViewEventArgs e)
        {
            // if the code is currently updating the checking we skip any post actions.
            if (_isCheckingNodes)
            {
                return;
            }

            // check if the user check a folder
            NodeTag nodetag = (NodeTag)e.Node.Tag;

            if (nodetag.Type == NodeTagType.BehaviorFolder)
            {
                // disable the post actions
                _isCheckingNodes = true;

                // check/uncheck all the children
                CheckNodes(e.Node, e.Node.Checked);

                // enable post actions
                _isCheckingNodes = false;
            }

            if (!_isCheckingByTypeChanged)
            {
                SetFileCountLabel();
            }
        }
Пример #12
0
        private void PopulateListView(List <DatabaseFile> dirents, DatabaseFile parent)
        {
            listView1.BeginUpdate();
            listView1.Items.Clear();

            var upDir = listView1.Items.Add("");

            upDir.SubItems.Add("...");
            if (parent != null)
            {
                upDir.Tag = new NodeTag(parent, NodeType.Dirent);
            }
            else
            {
                NodeTag nodeTag = (NodeTag)currentClusterNode.Tag;
                upDir.Tag = new NodeTag(nodeTag.Tag as List <DatabaseFile>, NodeType.Cluster);
            }

            List <ListViewItem> items = new List <ListViewItem>();
            int index = 1;

            foreach (DatabaseFile databaseFile in dirents)
            {
                ListViewItem item = new ListViewItem(index.ToString());
                item.Tag = new NodeTag(databaseFile, NodeType.Dirent);

                item.SubItems.Add(databaseFile.FileName);

                DateTime creationTime   = databaseFile.CreationTime.AsDateTime();
                DateTime lastWriteTime  = databaseFile.LastWriteTime.AsDateTime();
                DateTime lastAccessTime = databaseFile.LastAccessTime.AsDateTime();

                string sizeStr = "";
                if (!databaseFile.IsDirectory())
                {
                    item.ImageIndex = 1;
                    sizeStr         = Utility.FormatBytes(databaseFile.FileSize);
                }
                else
                {
                    item.ImageIndex = 0;
                }

                item.SubItems.Add(sizeStr);
                item.SubItems.Add(creationTime.ToString());
                item.SubItems.Add(lastWriteTime.ToString());
                item.SubItems.Add(lastAccessTime.ToString());
                item.SubItems.Add("0x" + databaseFile.Offset.ToString("x"));
                item.SubItems.Add(databaseFile.Cluster.ToString());

                item.BackColor = statusColor[databaseFile.GetRanking()];

                index++;

                items.Add(item);
            }

            listView1.Items.AddRange(items.ToArray());
            listView1.EndUpdate();
        }
Пример #13
0
        /// <param name="op1">Can only be a binary op.</param>
        /// <param name="op2">Can only be a binary op.</param>
        /// <returns>neg if op1 is more important, pos if op2 is more important, 0 if tied</returns>
        public int ComparePrecident(string op1, string op2)
        {
            NodeTag firstTag  = GetNodeTag(op1);
            NodeTag secondTag = GetNodeTag(op2);

            return(Precident(secondTag) - Precident(firstTag));
        }
Пример #14
0
        static string Convert(NodeTag t)
        {
            switch (t)
            {
            case NodeTag.gt:
                return(">");

            case NodeTag.gte:
                return(">=");

            case NodeTag.eq:
                return("==");

            case NodeTag.neq:
                return("!=");

            case NodeTag.lt:
                return("<");

            case NodeTag.lte:
                return("<=");

            default: return("<ERROR>");
            }
        }
Пример #15
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type.GetGenericTypeDefinition() != typeof(List<>))
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);

            Type itemType = type.GetGenericArguments()[0];
            if (!itemType.IsEnum)
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);

            System.Collections.IList enumArray = (System.Collections.IList)Plugin.CreateInstance(type);
            if (!string.IsNullOrEmpty(str))
            {
                int index = str.IndexOf(':');
                if (index >= 0)
                    str = str.Substring(index + 1);

                string[] tokens = str.Split('|');
                foreach (string s in tokens)
                {
                    enumArray.Add(Enum.Parse(itemType, s, true));
                }
            }

            return enumArray;
        }
Пример #16
0
        static bool Check(NodeTag t, double a, double b)
        {
            switch (t)
            {
            case NodeTag.gt:
                return(a > b);

            case NodeTag.gte:
                return(a >= b);

            case NodeTag.eq:
                return(a == b);

            case NodeTag.neq:
                return(a != b);

            case NodeTag.lt:
                return(a < b);

            case NodeTag.lte:
                return(a <= b);

            default: return(true);
            }
        }
Пример #17
0
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 1)
            {
                return;
            }

            //Console.WriteLine($"Current Cluster Node: {currentClusterNode.Text}");

            NodeTag nodeTag = (NodeTag)listView1.SelectedItems[0].Tag;

            switch (nodeTag.Type)
            {
            case NodeType.Dirent:
                DatabaseFile databaseFile = nodeTag.Tag as DatabaseFile;

                if (databaseFile.IsDirectory())
                {
                    PopulateListView(databaseFile.Children, databaseFile.GetParent());
                }

                break;

            case NodeType.Cluster:
                List <DatabaseFile> dirents = nodeTag.Tag as List <DatabaseFile>;

                PopulateListView(dirents, null);

                break;
            }
        }
Пример #18
0
            public int Compare(object x, object y)
            {
                NodeTag tagX = (NodeTag)((TreeNode)x).Tag;
                NodeTag tagY = (NodeTag)((TreeNode)y).Tag;

                return(String.Compare(tagX.SortKey, tagY.SortKey));
            }
Пример #19
0
        void btn_Click(object sender, EventArgs e)
        {
            // 设置显示图标的变换
            NodeTag nodeTag = (NodeTag)((Button)sender).Tag;

            BugsBox.Pharmacy.AppClient.Menu.Instance.TriggerClick(nodeTag);
        }
Пример #20
0
        public Node MakeBinary(NodeTag tag, Node lhs, Node rhs)
        {
            Node retval = new Binary(this, tag, lhs, rhs);

            RegisterNode(retval);
            return(retval);
        }
Пример #21
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            currentClusterNode = e.Node;
            while (currentClusterNode.Parent != null)
            {
                currentClusterNode = currentClusterNode.Parent;
            }

            //Console.WriteLine($"Current Cluster Node: {currentClusterNode.Text}");

            NodeTag nodeTag = (NodeTag)e.Node.Tag;

            switch (nodeTag.Type)
            {
            case NodeType.Cluster:
                List <DatabaseFile> dirents = (List <DatabaseFile>)nodeTag.Tag;

                PopulateListView(dirents, null);

                break;

            case NodeType.Dirent:
                DatabaseFile databaseFile = (DatabaseFile)nodeTag.Tag;

                PopulateListView(databaseFile.Children, databaseFile.GetParent());

                break;
            }
        }
Пример #22
0
        private void treeRecoverAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Dictionary <string, List <DatabaseFile> > clusterList = new Dictionary <string, List <DatabaseFile> >();

                    foreach (TreeNode clusterNode in treeView1.Nodes)
                    {
                        NodeTag nodeTag = (NodeTag)clusterNode.Tag;
                        switch (nodeTag.Type)
                        {
                        case NodeType.Cluster:
                            List <DatabaseFile> dirents = nodeTag.Tag as List <DatabaseFile>;

                            clusterList[clusterNode.Text] = dirents;

                            break;
                        }
                    }

                    RunRecoverAllTaskAsync(dialog.SelectedPath, clusterList);
                }
            }
        }
Пример #23
0
 public Node(NodeTag deviceInfo)
     : this()
 {
     Id                  = deviceInfo.Id;
     EndPointId          = deviceInfo.EndPointId;
     EndPointIdSpecified = deviceInfo.EndPointId > 0;
 }
Пример #24
0
        public FunctionMap()
        {
            InitializeComponent();

            XmlDocument doc = new XmlDocument();

            doc.Load(System.Configuration.ConfigurationManager.AppSettings["Menu"].ToString());

            List <FuncMapItem> Items = new List <FuncMapItem>();

            foreach (XmlNode node in doc.SelectNodes("/MenusGroup/Menu/Menu"))
            {
                FuncMapItem item = new FuncMapItem();
                Items.Add(item);
                item.Header = NodeTag.Create(node);
                Build(node, item);
            }

            foreach (var item in Items)
            {
                var control = new BugsBox.Pharmacy.AppClient.UserControls.FuncMapItemControl(item);

                flowLayoutPanel1.Controls.Add(control);
            }

            this.SizeChanged += FunctionMap_SizeChanged;
        }
Пример #25
0
        public static object ParseStringValue(Type type, string str, NodeTag.DefaultObject node)
        {
            Debug.Check(Plugin.IsArrayType(type));

            Type itemType = type.GetGenericArguments()[0];
            if (Plugin.IsCustomClassType(itemType))
                return DesignerArrayStruct.ParseStringValue(type, str, node);

            object obj = Plugin.CreateInstance(type);
            Debug.Check(obj != null);

            if (!string.IsNullOrEmpty(str))
            {
                System.Collections.IList list = (System.Collections.IList)obj;

                int index = str.IndexOf(':');
                if (index >= 0)
                    str = str.Substring(index + 1);

                if (!string.IsNullOrEmpty(str))
                {
                    string[] tokens = str.Split('|');
                    foreach (string s in tokens)
                    {
                        Plugin.InvokeTypeParser(itemType, s, (object value) => { list.Add(value); }, node);
                    }
                }
            }

            return obj;
        }
Пример #26
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            NodeTag nodeTag = (NodeTag)e.Node.Tag;

            switch (nodeTag.Type)
            {
            case NodeType.Dirent:
                DirectoryEntry dirent = nodeTag.Tag as DirectoryEntry;

                if (dirent.IsDeleted())
                {
                    Console.WriteLine($"Cannot loads contents of a deleted directory: {dirent.FileName}");
                }
                else
                {
                    PopulateListView(dirent.Children, dirent);
                }

                break;

            case NodeType.Root:

                PopulateListView(this.volume.GetRoot(), null);

                break;
            }
        }
Пример #27
0
        private void listSaveSelectedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            FolderBrowserDialog dialog = new FolderBrowserDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                List <DirectoryEntry> selectedFiles = new List <DirectoryEntry>();

                foreach (ListViewItem selected in listView1.SelectedItems)
                {
                    NodeTag nodeTag = (NodeTag)selected.Tag;
                    switch (nodeTag.Type)
                    {
                    case NodeType.Dirent:
                        DirectoryEntry dirent = nodeTag.Tag as DirectoryEntry;

                        selectedFiles.Add(dirent);

                        break;
                    }
                }

                RunSaveAllTaskAsync(dialog.SelectedPath, selectedFiles);
            }
        }
Пример #28
0
        private void axZKFPEngX1_OnEnroll(object sender, AxZKFPEngXControl.IZKFPEngXEvents_OnEnrollEvent e)
        {
            byte[] tmpbyte;
            string tmp = "";

            tmp           = gZK.GetTemplateAsString();
            textBox1.Text = tmp;
            if (MyManager.InsertFingerTmp(((NodeTag)CurNode.Tag).UserID, tmp, (byte[])e.aTemplate, GetImageBytes(pictureBox1.Image)) == true)
            {
                MessageBox.Show("指纹登记成功!");
                textBox2.Text = "指纹登机成功!";
                NodeTag nt = (NodeTag)CurNode.Tag;
                nt.HaveFingerTmp  = 1;
                CurNode.Text      = nt.UserName + "(Y)";
                CurNode.ForeColor = Color.Black;
            }
            else
            {
                MessageBox.Show("指纹登记失败!");
                textBox2.Text = "指纹登机失败!";
            }


            button1.Enabled = true;
            button3.Enabled = false;

            //tmpbyte = Convert.FromBase64String(tmp);
            //开始检查指纹是否重复
            //DataTable dt = MyManager.GetDataSet("SELECT UserName,UserID,FingerTmp From UserList Where UserID <>" + ((NodeTag)CurNode.Tag).UserID + " AND ");
        }
Пример #29
0
        private void AddNode(TreeNode work, XmlNode node)
        {
            NodeTag nodeTag = new NodeTag()
            {
                id        = node.Attributes["id"].Value,
                Name      = node.Attributes["Name"].Value,
                Params    = node.Attributes["Params"].Value,
                Title     = node.Attributes["Title"].Value,
                ModuleKey = node.Attributes["ModuleKey"].Value
            };
            TreeNode Node = new TreeNode();

            Node.Text               = nodeTag.Title;
            Node.Name               = nodeTag.id;
            Node.Tag                = nodeTag;
            Node.ImageIndex         = 0;
            Node.SelectedImageIndex = 0;
            if (!string.IsNullOrWhiteSpace(nodeTag.ModuleKey))
            {
                if (PharmacyAuthorizeExtesions.Authorize(this, nodeTag.ModuleKey))
                {
                    work.Nodes.Add(Node);
                }
            }
        }
Пример #30
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            foreach (Plugin.InstanceName_t t in Plugin.InstanceNames)
            {
                if (str == t.agentType_.AgentTypeName
            #if BEHAVIAC_NAMESPACE_FIX
                    || t.agentType_.AgentTypeName.EndsWith(str)
            #endif
                    )
                {
                    return t.agentType_;
                }
            }

            foreach (AgentType t in Plugin.AgentTypes)
            {
                if (str == t.ToString()
            #if BEHAVIAC_NAMESPACE_FIX
                    || t.AgentTypeName.EndsWith(str)
            #endif
                    )
                {
                    return t;
                }
            }

            return null;
        }
Пример #31
0
        private void treeRecoverSelectedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var selectedNode = treeView1.SelectedNode;

                    NodeTag nodeTag = (NodeTag)selectedNode.Tag;
                    switch (nodeTag.Type)
                    {
                    case NodeType.Cluster:
                        List <DatabaseFile> dirents = nodeTag.Tag as List <DatabaseFile>;

                        string clusterDir = dialog.SelectedPath + "/" + selectedNode.Text;
                        Directory.CreateDirectory(clusterDir);
                        RunRecoverClusterTaskAsync(clusterDir, dirents);

                        break;

                    case NodeType.Dirent:
                        DatabaseFile dirent = nodeTag.Tag as DatabaseFile;

                        RunRecoverClusterTaskAsync(dialog.SelectedPath, new List <DatabaseFile> {
                            dirent
                        });

                        break;
                    }

                    Console.WriteLine("Finished recovering files.");
                }
            }
        }
 public async Task <ActionResult> UpdateTag(int tagId, [FromBody] NodeTag tag)
 {
     tag.Id = tagId;
     return(ObserveDataOperationStatus(
                await _data.UpdateTag(tag)
                ));
 }
Пример #33
0
        private void listRecoverCurrentDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    // TODO: Create `DirectoryEntry currentDirectory` for this class
                    //  so that we don't go through the list items.
                    //  Also, should we be dumping to a cluster directory?
                    List <DatabaseFile> selectedFiles = new List <DatabaseFile>();

                    foreach (ListViewItem item in listView1.Items)
                    {
                        if (item.Index == 0)
                        {
                            continue;
                        }

                        NodeTag nodeTag = (NodeTag)item.Tag;

                        switch (nodeTag.Type)
                        {
                        case NodeType.Dirent:
                            DatabaseFile databaseFile = nodeTag.Tag as DatabaseFile;

                            selectedFiles.Add(databaseFile);

                            break;
                        }
                    }

                    RunRecoverClusterTaskAsync(dialog.SelectedPath, selectedFiles);
                }
            }
        }
Пример #34
0
        /// <summary>
        /// Make a unary operation that works against other node.
        /// </summary>
        /// <param name="tag">The unary operator.</param>
        /// <param name="child">The operator to be operated upon.</param>
        public Node MakeUnary(NodeTag tag, Node child)
        {
            Node retval = new Unary(this, tag, child);

            RegisterNode(retval);
            return(retval);
        }
Пример #35
0
        private void listRecoverSelectedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            var selectedItems = listView1.SelectedItems;

            using (var dialog = new FolderBrowserDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    List <DatabaseFile> selectedFiles = new List <DatabaseFile>();

                    foreach (ListViewItem selectedItem in selectedItems)
                    {
                        NodeTag nodeTag = (NodeTag)selectedItem.Tag;

                        switch (nodeTag.Type)
                        {
                        case NodeType.Dirent:
                            DatabaseFile databaseFile = nodeTag.Tag as DatabaseFile;

                            selectedFiles.Add(databaseFile);

                            break;
                        }
                    }

                    RunRecoverClusterTaskAsync(dialog.SelectedPath, selectedFiles);
                }
            }
        }
Пример #36
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(RightValueDef))
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);

            if (str.Length == 0 ||
                str.Length == 2 && str == "\"\"")
            {
                return null;
            }

            if (!str.StartsWith("const"))
            {
                int pos = str.IndexOf('(');
                if (pos < 0)
                {
                    VariableDef var = this.parsePropertyVar(node, str);

                    return new RightValueDef(var);
                }
                else
                {
                    //Ship::Getter(100,50,50)
                    Behaviac.Design.Nodes.Behavior behavior = node.Behavior as Behaviac.Design.Nodes.Behavior;

                    string valueClass = VariableDef.kSelfMethod;
                    MethodDef method = DesignerMethodEnum.parseMethodString(node, behavior.AgentType, this.MethodType, str);
                    if (method == null)
                    {
                        string className = Plugin.GetClassName(str);
                        method = DesignerMethodEnum.parseMethodString(node, Plugin.GetInstanceAgentType(className), this.MethodType, str);
                        valueClass = className + VariableDef.kMethod;
                    }

                    //Debug.Check(method != null);

                    string instanceName = Plugin.GetInstanceName(str);
                    if (!string.IsNullOrEmpty(instanceName))
                    {
                        valueClass = instanceName + VariableDef.kMethod;
                    }

                    return new RightValueDef(method, valueClass);
                }
            }
            else
            {
                VariableDef var = this.parseConstVar(node, parentObject, str);

                if (var != null)
                {
                    return new RightValueDef(var);
                }
            }

            return null;
        }
Пример #37
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(bool))
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);

            str = str.ToLowerInvariant();
            if (str == "true")
                return true;

            if (str == "false")
                return false;

            throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalBooleanValue, str));
        }
Пример #38
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type == typeof(string))
            {
                return trimQuotes(str);
            }
            else if (Plugin.IsCharType(type))
            {
                if (str.Length >= 1)
                {
                    char r = str[0];
                    return r;
                }

                //return "";
                return 'A';
            }

            throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);
        }
Пример #39
0
 /// <summary>
 /// Sets the property's value based on a string.
 /// </summary>
 /// <param name="type">The type of the property.</param>
 /// <param name="str">The string representing the value to be set.</param>
 /// <returns>Returns the value encoded in the string in the correct type given.</returns>
 public object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
 {
     return _attribute.FromStringValue(node, parentObject, type, str);
 }
 Node mathFunc(NodeTag cop, Code opd) { 
     Node expr = (Node)opd;
     if (expr.type == NodeType.tpInt) { 
         expr = QueryImpl.int2real(expr);
     } else if (expr.type != NodeType.tpReal) { 
         throw new CodeGeneratorException("Invalid argument types");
     }
     return new UnaryOpNode(NodeType.tpReal, cop, expr);
 }
Пример #41
0
        /// <summary>
        /// Sets the value of the property for the given node from a string.
        /// </summary>
        /// <param name="obj">The object we want to set the value on.</param>
        /// <param name="valueString">The string holding the value.</param>
        public void SetValueFromString(object obj, string valueString, NodeTag.DefaultObject node = null)
        {
            if (Plugin.IsCharType(_property.PropertyType))
            {
                object v = FromStringValue(node, obj, _property.PropertyType, valueString);
                string vStr = v.ToString();

                char c = 'A';
                if (vStr.Length >= 1)
                {
                    c = vStr[0];
                }

                _property.SetValue(obj, c, null);
            }
            else
            {
                _property.SetValue(obj, FromStringValue(node, obj, _property.PropertyType, valueString), null);
            }
        }
Пример #42
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(MethodDef))
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);

            Nodes.Behavior behavior = node.Behavior as Nodes.Behavior;
            if (behavior != null && behavior.AgentType != null)
            {
                MethodDef method = parseMethodString(node, behavior.AgentType, this.MethodType, str);
                if (method == null)
                {
                    string className = Plugin.GetClassName(str);
                    method = parseMethodString(node, Plugin.GetInstanceAgentType(className), this.MethodType, str);
                }

                return method;
            }

            return null;
        }
Пример #43
0
 /// <summary>
 /// Sets the property's value based on a string.
 /// </summary>
 /// <param name="type">The type of the property.</param>
 /// <param name="str">The string representing the value to be set.</param>
 /// <returns>Returns the value encoded in the string in the correct type given.</returns>
 public abstract object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str);
Пример #44
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(VariableDef))
            {
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);
            }

            if (str.Length == 0 ||
                str.Length == 2 && str == "\"\"")
            {
                return null;
            }

            if (!str.StartsWith("const"))
            {
                return this.parsePropertyVar(node, str);
            }
            else
            {
                return this.parseConstVar(node, parentObject, str);
            }

            //return null;
        }
Пример #45
0
        protected VariableDef parsePropertyVar(NodeTag.DefaultObject node, string str)
        {
            Debug.Check(!str.StartsWith("const"));

            string[] tokens = str.Split(' ');
            if (tokens.Length < 2)
                return null;

            string propertyType = string.Empty;
            string propertyName = string.Empty;
            if (tokens[0] == "static")
            {
                Debug.Check(tokens.Length == 3);

                //e.g. static int Property;
                propertyType = tokens[1];
                propertyName = tokens[2];
            }
            else
            {
                Debug.Check(tokens.Length == 2);

                //e.g. int Property;
                propertyType = tokens[0];
                propertyName = tokens[1];
            }

            VariableDef v = null;
            int pointIndex = propertyName.IndexOf('.');

            if (pointIndex > -1)
            {
                string ownerName = propertyName.Substring(0, pointIndex);
                propertyName = propertyName.Substring(pointIndex + 1, propertyName.Length - pointIndex - 1);

                AgentType agentType = node.Behavior.AgentType;
                agentType = Plugin.GetInstanceAgentType(ownerName, agentType);
                string valueType = (agentType == node.Behavior.AgentType) ? VariableDef.kSelf : agentType.ToString();

                v = setProperty(agentType, propertyName, valueType);
            }
            else
            {
                string className = Plugin.GetClassName(propertyName);

                // Assume it was World type.
                if (className != null)
                {
                    v = setProperty(Plugin.GetInstanceAgentType(className), propertyName, className);

                    if (v == null)
                    {
                        Nodes.Behavior behavior = node.Behavior as Nodes.Behavior;
                        if (behavior != null)
                        {
                            // Assume it was Agent type.
                            v = setProperty(behavior.AgentType, propertyName, VariableDef.kSelf);
                        }
                    }
                }
            }

            if (v == null)
            {
                // It should be Par type.
                v = setParameter(node, propertyType, propertyName);
            }

            return v;
        }
Пример #46
0
 public ObjectPair(Nodes.Node root, NodeTag.DefaultObject obj)
 {
     Root = root;
     Obj = obj;
 }
Пример #47
0
        public static bool ContainObjectPair(List<ObjectPair> objects, Nodes.Node root, NodeTag.DefaultObject obj)
        {
            foreach (ObjectPair objPair in objects)
            {
                if (objPair.Root == root && objPair.Obj == obj)
                    return true;
            }

            return false;
        }
Пример #48
0
        private static void parseStringValue(NodeTag.DefaultObject node, object obj, Type type, string paramName, string str, int startIndex, int endIndex)
        {
            string propertyName = string.Empty;
            string propertyValue = string.Empty;

            try
            {
                if (startIndex >= endIndex)
                    return;

                if (!string.IsNullOrEmpty(str))
                {
                    if (startIndex < str.Length && str[startIndex] == '{')
                    {
                        startIndex++;

                        if (endIndex < str.Length && str[endIndex] == '}')
                            endIndex--;
                    }
                }

                int valueIndex = getProperty(str, startIndex, endIndex, out propertyName, out propertyValue);

                //if (propertyName == "code")
                //{
                //    Debug.Check(true);
                //}

                if (valueIndex >= 0)
                {
                    Debug.Check(!string.IsNullOrEmpty(propertyName));

                    DesignerPropertyInfo property;

                    if (getPropertyInfo(type, propertyName, out property))
                    {
                        // Primitive type
                        if (string.IsNullOrEmpty(propertyValue) || propertyValue[0] != '{')
                        {
                            MethodDef.Param parParam = null;
                            Nodes.Action action = node as Nodes.Action;
                            if (action != null)
                            {
                                MethodDef method = action.Method;
                                if (method != null)
                                {
                                    parParam = method.GetParam(paramName, type, obj, property);
                                }
                            }

                            bool bParamFromStruct = false;
                            string[] tokens = Plugin.Split(propertyValue, ' ');

                            if (tokens != null && tokens.Length > 1)
                            {
                                //par
                                if (parParam != null)
                                {
                                    int propertyNameIndex = 1;
                                    if (tokens.Length == 2)
                                    {
                                        propertyNameIndex = 1;
                                    }
                                    else if (tokens.Length == 3)
                                    {
                                        Debug.Check(tokens[0] == "static");
                                        propertyNameIndex = 2;
                                    }
                                    else
                                    {
                                        Debug.Check(false);
                                    }
                                    parParam.Value = DesignerMethodEnum.setParameter(node, tokens[propertyNameIndex]);
                                    bParamFromStruct = true;
                                }
                            }

                            if (!bParamFromStruct)
                            {
                                property.SetValueFromString(obj, propertyValue, node);

                                if (parParam != null)
                                {
                                    parParam.Value = property.GetValue(obj);
                                }
                            }
                        }
                        // Struct type
                        else
                        {
                            object member = property.GetValue(obj);
                            Debug.Check(member != null);

                            string structStr = str.Substring(valueIndex + 1, propertyValue.Length - 2);
                            parseStringValue(node, member, member.GetType(), paramName, structStr, 0, structStr.Length - 1);
                        }
                    }

                    // Parse next property
                    parseStringValue(node, obj, type, paramName, str, valueIndex + propertyValue.Length + 1, str.Length - 1);
                }
            }
            catch(Exception ex)
            {
                string msg = string.Format("{0}\n{1}:{2}", ex.Message, propertyName, propertyValue);
                MessageBox.Show(msg, Resources.LoadError, MessageBoxButtons.OK);
            }
        }
Пример #49
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (Plugin.IsCustomClassType(type))
                return ParseStringValue(type, null, str, node);

            throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);
        }
Пример #50
0
        public static object ParseStringValue(Type type, string paramName, string str, NodeTag.DefaultObject node)
        {
            Debug.Check(Plugin.IsCustomClassType(type));

            object obj = Plugin.CreateInstance(type);
            parseStringValue(node, obj, type, paramName, str, 0, str.Length - 1);

            return obj;
        }
Пример #51
0
        public static MethodDef parseMethodString(NodeTag.DefaultObject node, AgentType agentType, MethodType methodType, string str)
        {
            try
            {
                if (agentType != null)
                {
                    int pos = str.IndexOf('(');
                    if (pos < 0)
                        return null;

                    string ownerName = agentType.ToString();
                    int pointIndex = str.IndexOf('.');
                    if (pointIndex > -1 && pointIndex < pos)
                    {
                        ownerName = str.Substring(0, pointIndex);
                        str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1);
                        agentType = Plugin.GetInstanceAgentType(ownerName, agentType);
                        if (agentType == node.Behavior.AgentType)
                            ownerName = VariableDef.kSelf;
                        pos = str.IndexOf('(');
                    }

                    IList<MethodDef> actions = agentType.GetMethods(methodType);
                    string actionName = str.Substring(0, pos);
                    foreach (MethodDef actionTypeIt in actions)
                    {
                        if (actionTypeIt.Name == actionName
            #if BEHAVIAC_NAMESPACE_FIX
                        || actionTypeIt.Name.EndsWith(actionName)
            #endif
            )
                        {
                            MethodDef method = new MethodDef(actionTypeIt);
                            method.Owner = ownerName;

                            List<string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2));
                            //Debug.Check((paras.Count == actionTypeIt.Params.Count));

                            //if (paras.Count == actionTypeIt.Params.Count)
                            {
                                for (int i = 0; i < paras.Count; ++i)
                                {
                                    string param = paras[i];
                                    string[] tokens = null;
                                    if (param[0] == '\"')
                                    {
                                        param = param.Substring(1, param.Length - 2);
                                    }
                                    else if (param[0] == '{')
                                    {
                                        //struct

                                        //to set it as action.Method is used in the following parsing
                                        Nodes.Action action = node as Nodes.Action;
                                        if (action != null)
                                        {
                                            action.Method = method;
                                        }
                                    }
                                    else
                                    {
                                        tokens = param.Split(' ');
                                    }

                                    if (i < method.Params.Count)
                                    {
                                        MethodDef.Param par = method.Params[i];

                                        if (tokens != null && tokens.Length > 1)
                                        {
                                            //par
                                            VariableDef var = setParameter(node, tokens[tokens.Length - 1]);
                                            if (var != null)
                                                par.Value = var;
                                            //else
                                            //    throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str));
                                        }
                                        else
                                        {
                                            bool bOk = Plugin.InvokeTypeParser(par.Type, param, (object value) => par.Value = value, node, par.Name);
                                            if (!bOk)
                                                throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str));
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }

                            return method;
                        }
                    }
                }
            }
            catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK);
            }

            return null;
        }
Пример #52
0
        public static VariableDef setParameter(NodeTag.DefaultObject node, string propertyName)
        {
            Behaviac.Design.Nodes.Behavior behavior = node.Behavior as Behaviac.Design.Nodes.Behavior;

            string instance = Plugin.GetInstanceName(propertyName);
            if (!string.IsNullOrEmpty(instance))
            {
                propertyName = propertyName.Substring(instance.Length + 1, propertyName.Length - instance.Length - 1);
                VariableDef var = createVariable(behavior.AgentType, instance, propertyName);
                if (var != null)
                    return var;
            }

            // Try to find the Par parameter with the name.
            List<ParInfo> allPars = new List<ParInfo>();
            ((Nodes.Node)behavior).GetAllPars(ref allPars);
            if (allPars.Count > 0)
            {
                foreach (ParInfo p in allPars)
                {
                    if (p.Name == propertyName
            #if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
            #endif
                        )
                    {
                        VariableDef var = new VariableDef(p);
                        var.SetValue(p, VariableDef.kPar);
                        return var;
                    }
                }
            }

            // Try to find the Agent property with the name.
            if (behavior != null && behavior.AgentType != null)
            {
                IList<PropertyDef> properties = behavior.AgentType.GetProperties();
                foreach (PropertyDef p in properties)
                {
                    if (p.Name == propertyName
            #if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
            #endif
                        )
                        return new VariableDef(p, VariableDef.kSelf);
                }
            }

            // Try to find the World property with the name.
            string instacneName = Plugin.GetClassName(propertyName);
            if (!string.IsNullOrEmpty(instacneName) && Plugin.GetInstanceAgentType(instacneName) != null)
            {
                IList<PropertyDef> properties = Plugin.GetInstanceAgentType(instacneName).GetProperties();
                foreach (PropertyDef p in properties)
                {
                    if (p.Name == propertyName
            #if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
            #endif
                        )
                        return new VariableDef(p, instacneName);
                }
            }

            return null;
        }
Пример #53
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (!type.IsEnum)
                throw new Exception(string.Format(Resources.ExceptionDesignerAttributeExpectedEnum, type));

            string[] parts = str.Split(':');

            if (parts.Length != 2)
            {
                // keep compatibility with version 1
                //throw new Exception( string.Format(Resources.ExceptionDesignerAttributeEnumCouldNotReadValue, str) );
                parts = new string[] { str, "-1" };
            }

            string enumname = parts[0];

            int enumval;
            try
            {
                // try to get the enum value by name
                enumval = (int)Enum.Parse(type, enumname, true);
            }
            catch
            {
                // try to read the stored enum value index
                if (!int.TryParse(parts[1], NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat, out enumval))
                    throw new Exception(string.Format(Resources.ExceptionDesignerAttributeEnumCouldNotParseValue, str));

                // try to get the enum value by index
                if (Enum.ToObject(type, enumval) == null)
                    throw new Exception(string.Format(Resources.ExceptionDesignerAttributeEnumIllegalEnumIndex, enumval));

                enumval = (int)Plugin.DefaultValue(type);
            }

            return enumval;
        }
Пример #54
0
 public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
 {
     return ParseStringValue(type, str, node);
 }
Пример #55
0
 public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
 {
     Debug.Check(Plugin.IsArrayType(type));
     return ParseStringValue(type, str, node);
 }
Пример #56
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(int))
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);

            int result;
            if (int.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture.NumberFormat, out result))
                return result;

            throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalIntegerValue, str));
        }
Пример #57
0
        protected VariableDef parseConstVar(NodeTag.DefaultObject node, object parentObject, string str)
        {
            Debug.Check(str.StartsWith("const"));

            //const Int32 1
            object propertyMemberDepended = null;
            Type objType = node.GetType();
            if (this.DependedProperty != "")
            {
                System.Reflection.PropertyInfo pi = objType.GetProperty(this.DependedProperty);

                if (pi != null)
                {
                    propertyMemberDepended = pi.GetValue(node, null);
                }
                else if (pi == null && parentObject != null)
                {
                    Type parentType = parentObject.GetType();
                    pi = parentType.GetProperty(this.DependedProperty);
                    propertyMemberDepended = pi.GetValue(parentObject, null);
                }
            }

            Type valueType = null;
            VariableDef variableDepended = propertyMemberDepended as VariableDef;
            if (variableDepended != null)
            {
                valueType = variableDepended.GetValueType();
            }
            else if (propertyMemberDepended != null)
            {
                MethodDef methodDepended = propertyMemberDepended as MethodDef;
                if (methodDepended != null)
                {
                    valueType = methodDepended.ReturnType;
                }
                else
                {
                    RightValueDef varRV = propertyMemberDepended as RightValueDef;
                    if (varRV != null)
                    {
                        valueType = varRV.ValueType;
                    }
                }
            }
            else
            {
                string[] tokens = str.Split(' ');
                Debug.Check(tokens.Length == 3);

                valueType = Plugin.GetTypeFromName(tokens[1]);
            }

            if (valueType != null)
            {
                VariableDef variable = new VariableDef(null);

                string[] tokens = str.Split(' ');
                Debug.Check(tokens.Length == 3);

                Plugin.InvokeTypeParser(valueType, tokens[2],
                    (object value) => variable.Value = value,
                    node);

                return variable;
            }

            return null;
        }
Пример #58
0
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(string))
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);

            return str;
        }
Пример #59
0
        protected VariableDef setParameter(NodeTag.DefaultObject node, string propertyType, string propertyName)
        {
            List<ParInfo> allPars = new List<ParInfo>();
            ((Nodes.Node)node.Behavior).GetAllPars(ref allPars);
            if (allPars.Count > 0)
            {
                string fullname = string.Format("{0} {1}", propertyType, propertyName);
                foreach (ParInfo p in allPars)
                {
                    if (p.ToString() == fullname)
                    {
                        VariableDef v = new VariableDef(p);
                        v.SetValue(p, VariableDef.kPar);
                        return v;
                    }
                }
            }

            return null;
        }
Пример #60
0
    public static bool GetTagStatus(NodeTag tag)
    {
        string colorString;
        switch (tag)
        {
          case NodeTag.BlueColoured:
          {
        colorString="BlueColor";
        break;
          }
          case NodeTag.RedColoured:
          {
        colorString="RedColor";
        break;
          }
          case NodeTag.GreenColoured:
          {
        colorString="GreenColor";
        break;
          }
          case NodeTag.Whirlwind:
            case NodeTag.Stream:
          {
              return false;
          }
          default:
          {
        return true;
          }
        }

        return PlayerSaveData.GetColorStatus(colorString);
    }