コード例 #1
0
        /// <summary>
        /// Search a block by name and remove it.
        /// You can specify the Block type.
        /// Output parameter is bool, which is tell you  the function is suceeded.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool RemoveBlockFromList(string name, Blocktypes type)
        {
            tfBlock tf = new tfBlock();

            if (type == Blocktypes.tf)
            {
                if (SearchTf_byName(name, out tf))
                {
                    LinkedListNode <tfBlock> mark = lists.tflist.Find(tf);
                    lists.tflist.Remove(mark);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (type == Blocktypes.sum)
            {
                sumBlock Sum = new sumBlock();
                if (SearchSum_byName(name, out Sum))
                {
                    LinkedListNode <sumBlock> mark = lists.sumlist.Find(Sum);
                    lists.sumlist.Remove(mark);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (type == Blocktypes.node)
            {
                nodeBlock Node = new nodeBlock();
                if (SearchNode_byName(name, out Node))
                {
                    LinkedListNode <nodeBlock> mark = lists.nodelist.Find(Node);
                    lists.nodelist.Remove(mark);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        public static ConsistencyResult consistency_result(bool success, string Block, Blocktypes type, PINS PINnum)
        {
            ConsistencyResult result;

            result.success        = success;
            result.ErrorBlockName = Block;
            result.type           = Convert.ToInt32(type);
            result.pinNum         = Convert.ToInt32(PINnum);
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Function for cuonting names of blocks. Search and give an unique serial number, which is never used before.
        /// </summary>
        /// <param name="basename"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string NameCounter(string basename, Blocktypes type)
        {
            int    counter     = 0;
            string newname     = "";
            int    tempcounter = 0;
            string tempstring  = "";
            bool   found       = false;

            // Parsing the names, and read their serial number and create a new unique number
            switch (type)
            {
            case Blocktypes.tf:
            {
                found = false;
                foreach (var element in lists.tflist)
                {
                    tempstring = "";
                    if ((element.name[0] == Convert.ToChar(basename[0])) && (element.name.Length >= (basename.Length + 2)))
                    {
                        for (int i = 0; i < basename.Length; i++)
                        {
                            tempstring += element.name[i];
                        }
                        found = (tempstring == basename);
                        if (found)
                        {
                            tempcounter = (Convert.ToInt32(element.name[basename.Length]) - 48) * 10 + (Convert.ToInt32(element.name[basename.Length + 1]) - 48);
                            if (tempcounter > counter)
                            {
                                counter = tempcounter;
                            }
                        }
                    }
                }
                break;
            }

            case Blocktypes.sum:
            {
                found = false;
                foreach (var element in lists.sumlist)
                {
                    tempstring = "";
                    if ((element.name[0] == Convert.ToChar(basename[0])) && (element.name.Length >= (basename.Length + 2)))
                    {
                        for (int i = 0; i < basename.Length; i++)
                        {
                            tempstring += element.name[i];
                        }
                        found = (tempstring == basename);
                        if (found)
                        {
                            tempcounter = (Convert.ToInt32(element.name[basename.Length]) - 48) * 10 + (Convert.ToInt32(element.name[basename.Length + 1]) - 48);
                            if (tempcounter > counter)
                            {
                                counter = tempcounter;
                            }
                        }
                    }
                }
                break;
            }

            case Blocktypes.node:
            {
                found = false;
                foreach (var element in lists.nodelist)
                {
                    tempstring = "";
                    if ((element.name[0] == Convert.ToChar(basename[0])) && (element.name.Length >= (basename.Length + 2)))
                    {
                        for (int i = 0; i < basename.Length; i++)
                        {
                            tempstring += element.name[i];
                        }
                        found = (tempstring == basename);
                        if (found)
                        {
                            tempcounter = (Convert.ToInt32(element.name[basename.Length]) - 48) * 10 + (Convert.ToInt32(element.name[basename.Length + 1]) - 48);
                            if (tempcounter > counter)
                            {
                                counter = tempcounter;
                            }
                        }
                    }
                }
                break;
            }
            }
            //if never defined similar name, which is given, the new serial number will be '00'
            if (found)
            {
                if (counter < 10)
                {
                    newname = basename + "0" + Convert.ToString(counter + 1);
                }
                else
                {
                    newname = basename + Convert.ToString(counter + 1);
                }
            }
            else
            {
                newname = basename + "00";
            }
            return(newname);
        }