static long GetDirectoriesSize(
            String strCurDir,
            System.Collections.Generic.LinkedList <DirInfo> parentList)
        {
            String[] strFiles = Directory.GetFiles(strCurDir, "*.*");
            long     aSize    = 0;

            foreach (String s in strFiles)
            {
                FileInfo info = new FileInfo(s);
                aSize += info.Length;
            }


            DirInfo infoCur = new DirInfo();

            infoCur.dirName = strCurDir;
            infoCur.curSize = aSize;
            System.Collections.Generic.LinkedListNode <DirInfo> infoMine = parentList.AddLast(infoCur);


            String[] strDirectories = Directory.GetDirectories(strCurDir);
            foreach (String sDirs in strDirectories)
            {
                aSize += GetDirectoriesSize(sDirs, infoMine.Value.listChild);
            }

            //Console.WriteLine("{0} size({1,0:N0}) Bytes", strCurDir, aSize);
            //infoMine.Value.aSize = aSize;
            infoMine.Value.aSize = aSize;

            return(aSize);
        }
Exemple #2
0
        public ProjectElement CreateElement(ProjectElement.ElementType Type, System.Windows.Forms.TreeNode ParentNode)
        {
            ProjectElement element = new ProjectElement();

            element.DocumentInfo.Type    = Type;
            element.DocumentInfo.Project = this;
            element.DocumentInfo.UndoManager.MainForm = Core.MainForm;
            element.Node                    = new System.Windows.Forms.TreeNode();
            element.Node.Tag                = element;
            element.Node.ImageIndex         = (int)Type;
            element.Node.SelectedImageIndex = (int)Type;


            ParentNode.Nodes.Add(element.Node);
            //MainForm.m_ProjectExplorer.NodeProject.Nodes.Add( element.Node );
            element.Node.Parent.Expand();

            foreach (var configName in Settings.GetConfigurationNames())
            {
                element.Settings[configName] = new ProjectElement.PerConfigSettings();
            }

            Elements.AddLast(element);

            m_Modified = true;
            return(element);
        }
Exemple #3
0
		public static Board BuildNewBoard()
		{
			var blockLists = new System.Collections.Generic.List<System.Collections.Generic.LinkedList<Block>>();

			for (int counter = 0; counter < maxNumberOfLists; counter++)
			{
				var linkedList = new System.Collections.Generic.LinkedList<Block>();

				int numberOfBlocksInTheList = randomNumberGenerator.Next(3, 6);

				for (int listCounter = 0; listCounter < numberOfBlocksInTheList; listCounter++)
				{
					var block = GetNewRandomBlock();
					linkedList.AddFirst(block);
				}

				for (int listCounter = numberOfBlocksInTheList; listCounter < 9; listCounter++)
				{
					var block = new Block();
					linkedList.AddLast(block);
				}

					blockLists.Add(linkedList);
			}

			Board board = new Board()
			{
				BlockLists = blockLists,
				inDanger = false,
				active = true
			};

			return board;
		}
        /** Inserts a new key <Key> with value 1. Or increments an existing key by 1. */
        public void Inc(string key)
        {
            if (_dict.ContainsKey(key))
            {
                var ln = _dict[key];
                ln.Value.value++;
                if (ln.Previous != null && ln.Previous.Value.value < ln.Value.value)
                {
                    var p = ln.Previous;
                    _list.Remove(ln);
                    while (p.Previous != null && p.Previous.Value.value < ln.Value.value)
                    {
                        p = p.Previous;
                    }

                    _list.AddBefore(p, ln);
                }
            }
            else
            {
                _dict[key] = _list.AddLast(new Node()
                {
                    key = key, value = 1
                });
            }
        }
Exemple #5
0
 public static void Add(EventListener listener)
 {
     lock (_events)
     {
         _events.AddLast(listener);
     }
 }
 public void PrepareBlocks(Block block)
 {
     if (block != null)
     {
         list.AddLast(block);
     }
 }
 private void AddBackButton_Click(object sender, EventArgs e)
 {
     if (ItemTextBox.Text != "")
     {
         todoList.AddLast(ItemTextBox.Text);
     }
     DisplayList();
 }
 public OrderedSet(IEnumerable <T> source)
 {
     list = new System.Collections.Generic.LinkedList <T>();
     map  = new Dictionary <T, LinkedListNode <T> >();
     foreach (var item in source)
     {
         var node = list.AddLast(item);
         map.Add(item, node);
     }
 }
Exemple #9
0
        /// <summary>
        /// Get all the account options names
        /// </summary>
        public System.Collections.Generic.LinkedList <String> GetOptionsNames()
        {
            System.Collections.Generic.LinkedList <String> options = new System.Collections.Generic.LinkedList <String>();

            foreach (KeyValuePair <String, String> option in this._options)
            {
                options.AddLast(option.Key);
            }
            return(options);
        }
        public System.Collections.Generic.LinkedList <T> toSystemLinkedList()
        {
            var returnList = new System.Collections.Generic.LinkedList <T>();

            foreach (T element in this)
            {
                returnList.AddLast(element);
            }
            return(returnList);
        }
Exemple #11
0
        /// <summary>
        /// Get all the user accounts
        /// </summary>
        public System.Collections.Generic.LinkedList <Account> GetAccounts()
        {
            System.Collections.Generic.LinkedList <Account> accounts = new System.Collections.Generic.LinkedList <Account>();

            foreach (KeyValuePair <int, Account> account in this._accounts)
            {
                accounts.AddLast(account.Value);
            }
            return(accounts);
        }
 public void Enque(Animal2 a)
 {
     a.Timestamp = ++timestamp;
     if (a is Dog)
     {
         _dogs.AddLast((Dog)a);
     }
     else
     {
         _cats.AddLast((Cat)a);
     }
 }
        /// <summary> Creates a new <c>MultipleTermPositions</c> instance.
        ///
        /// </summary>
        /// <exception cref="System.IO.IOException">
        /// </exception>
        public MultipleTermPositions(IndexReader indexReader, Term[] terms)
        {
            var termPositions = new System.Collections.Generic.LinkedList <TermPositions>();

            for (int i = 0; i < terms.Length; i++)
            {
                termPositions.AddLast(indexReader.TermPositions(terms[i]));
            }

            _termPositionsQueue = new TermPositionsQueue(termPositions);
            _posList            = new IntQueue();
        }
Exemple #14
0
        /// <summary>
        /// Paint the triangles defined by the points
        /// </summary>
        /// <param name="points"></param>
        private LinkedList <Triangle> makeTriangles(LinkedList <Pair <double, double> > points)
        {
            if (points == null || points.Count == 0)
            {
                return(null);
            }

            CPoint2D[]            vertices  = new CPoint2D[points.Count];
            LinkedList <Triangle> triangles = new System.Collections.Generic.LinkedList <Triangle>();

            int index = 0;

            foreach (Pair <double, double> p in points)
            {
                vertices[index] = new CPoint2D(p.X, p.Y);
                index++;
            }

            CPolygonShape cutPolygon = new CPolygonShape(vertices);

            cutPolygon.CutEar();

            debugOut("Numer of polygons: " + cutPolygon.NumberOfPolygons);

            CPoint2D[] corners;

            for (int numPoly = 0; numPoly < cutPolygon.NumberOfPolygons; numPoly++)
            {
                #region find upper and lower
                corners = cutPolygon.Polygons(numPoly);

                Pair <double, double>[] corns = new Pair <double, double> [3];
                for (int cornIndex = 0; cornIndex < 3; cornIndex++)
                {
                    CPoint2D coern = corners[cornIndex];
                    corns[cornIndex] = new Pair <double, double>(coern.X, coern.Y);
                }

                Pair <Pair <double, double>, Pair <double, double> > pairResult = findUpperAndLower(new LinkedList <Pair <double, double> >(corns));

                Pair <double, double> upper = pairResult.X;
                Pair <double, double> lower = pairResult.Y;

                Triangle inside = new Triangle(corns, upper, lower);

                debugOut(inside.ToString());

                triangles.AddLast(inside);
                #endregion
            }
            return(triangles);
        }
Exemple #15
0
 public void Read(string name, ref System.Collections.Generic.LinkedList <string> list)
 {
     if (this.StartElement(name))
     {
         list = new System.Collections.Generic.LinkedList <string>();
         for (int i = 0; i < this.Count; i++)
         {
             string value = "";
             this.Read(i, ref value);
             list.AddLast(value);
         }
         this.EndElement();
     }
 }
Exemple #16
0
        /// <summary>
        /// Adds a block to be deleted to the internal candidate list
        /// </summary>
        /// <param name="Block">Block to delete - can be null</param>
        public void PrepareBlocks(Block block)
        {
            if (block == null)
            {
                return;
            }

            list.AddLast(block);

            // important: if we haven't received a parent from constructor, just get it here
            if (Parent == null && block.Parent != null)
            {
                this.Parent = block.Parent;
            }
        }
Exemple #17
0
        public ProjectElement CreateElement(ProjectElement.ElementType Type)
        {
            ProjectElement element = new ProjectElement();

            element.Type     = Type;
            element.Node     = new System.Windows.Forms.TreeNode();
            element.Node.Tag = element;
            MainForm.m_ProjectExplorer.NodeProject.Nodes.Add(element.Node);
            element.Node.Parent.Expand();

            Elements.AddLast(element);

            m_Modified = true;
            return(element);
        }
Exemple #18
0
        Transform[] GeneratePoints(Transform root)
        {
            var points = new System.Collections.Generic.LinkedList <Transform>();

            foreach (var node in root.GetComponentsInChildren <Transform>())
            {
                if (node.childCount == 0 && node != root)
                {
                    points.AddLast(node);
                }
            }
            var result = new Transform[points.Count];

            points.CopyTo(result, 0);
            return(result);
        }
Exemple #19
0
            public void Add(int n, T t)
            {
                if (n == 0)
                {
                    if (Node != null)
                    {
                        Node.Value = t;
                    }
                    return;
                }

                Enumerator itr = new Enumerator(this);

                if (!itr.Move(n - Math.Sign(n)))
                {
                    if (begin)
                    {
                        List.AddFirst(t);
                    }
                    else
                    {
                        List.AddLast(t);
                    }

                    /*if (!itr.Move(-Math.Sign(n)))
                     * {
                     *  itr.Move(Math.Sign(n));
                     *  n *= -1;
                     * }*/
                }
                else
                {
                    if (n > 0)
                    {
                        List.AddAfter(itr.Node, t);
                    }
                    else if (n < 0)
                    {
                        List.AddBefore(itr.Node, t);
                    }
                }
            }
        public void PerfTestInsert()
        {
            var       systemList = new System.Collections.Generic.LinkedList <int>();
            Stopwatch stopwatch  = new Stopwatch();

            stopwatch.Start();
            foreach (var number in BenchmarkData)
            {
                systemList.AddLast(number);
            }
            stopwatch.Stop();
            var SystemListTime = stopwatch.ElapsedMilliseconds;
            var testedList     = new SingleList <int>();

            stopwatch.Restart();
            foreach (var number in BenchmarkData)
            {
                testedList.Add(number);
            }
            stopwatch.Stop();
            output.WriteLine($"LinkedList {stopwatch.ElapsedMilliseconds}ms | System.LinkedList {SystemListTime}");
        }
Exemple #21
0
        void exportBrush(object sender, EventArgs e)
        {
            try {
                FileDialog fileDia = new SaveFileDialog();
                fileDia.Filter     = filter;
                fileDia.DefaultExt = saveFormat;

                if (fileDia.ShowDialog() == DialogResult.OK)
                {
                    getValuesFromFormControls();
                    string filename = fileDia.FileName;
                    LinkedList <textureData> textures = new System.Collections.Generic.LinkedList <textureData>();
                    foreach (textureData tex in textureList.Items)
                    {
                        textures.AddLast(tex);
                    }
                    data.exportBrushData(filename, textures, grassTextures.selectedTextures);
                }
            } catch (Exception e2) {
                Console.WriteLine(e2);
            }
        }
Exemple #22
0
        public void bw_receive_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] buffer = new byte[4];
            byte[] data   = null;
            string usernameTemp;
            bool   check_addMessage = false;

            while (socket.Connected)
            {
                try
                {
                    stream.Read(buffer, 0, 4);
                    CommandType_ cmt = (CommandType_)BitConverter.ToInt32(buffer, 0);
                    if (cmt == CommandType_.Message)
                    {
                        string cmdMetaData = "";
                        buffer = new byte[4];
                        //đọc nội dung tin nhắn
                        stream.Read(buffer, 0, 4);
                        int    lenght     = BitConverter.ToInt32(buffer, 0);
                        byte[] metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        cmdMetaData = Encoding.ASCII.GetString(metaBuffer);
                        //đọc font
                        stream.Read(buffer, 0, 4);
                        lenght     = BitConverter.ToInt32(buffer, 0);
                        metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        MemoryStream    s    = new MemoryStream(metaBuffer);
                        BinaryFormatter bf   = new BinaryFormatter();
                        Font            temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                        temp = (Font)bf.Deserialize(s);
                        Chat chatForm = null;
                        _frmMain.Invoke(new Action(delegate()
                        {
                            if ((chatForm = IsShow("Server")) == null)
                            {
                                chatForm      = new Chat(this, "Server");
                                chatForm.Text = "Server";
                                chatForm.Show();
                                listFormChat.Add(chatForm);
                            }
                        }));
                        chatForm.Receive("Server", cmdMetaData, temp);
                    }//end message

                    if (cmt == CommandType_.LoadMessage)
                    {
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int count = BitConverter.ToInt16(buffer, 0);
                        if (count > 0)
                        {
                            buffer = new byte[4];
                            stream.Read(buffer, 0, 4);
                            int lengh = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lengh];
                            stream.Read(data, 0, lengh);
                            usernameTemp = Encoding.ASCII.GetString(data);
                            LinkedList <MessageText> listmessageTemp = new System.Collections.Generic.LinkedList <MessageText>();
                            for (int i = 0; i < count; i++)
                            {
                                buffer = new byte[4];
                                stream.Read(buffer, 0, 4);
                                lengh = BitConverter.ToInt32(buffer, 0);
                                data  = new byte[lengh];
                                stream.Read(data, 0, lengh);
                                string content = Encoding.ASCII.GetString(data);


                                stream.Read(buffer, 0, 4);
                                int lenght = BitConverter.ToInt32(buffer, 0);
                                data = new byte[lenght];
                                stream.Read(data, 0, lenght);
                                MemoryStream s = new MemoryStream(data);
                                s.Position = 0;
                                BinaryFormatter bf   = new BinaryFormatter();
                                Font            temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                                temp = (Font)bf.Deserialize(s);

                                buffer = new byte[4];
                                stream.Read(buffer, 0, 4);
                                int         type = BitConverter.ToInt16(buffer, 0);
                                MessageText mst  = new MessageText(content, temp, type);

                                listmessageTemp.AddLast(mst);
                            }
                            foreach (var s in listmessageTemp)
                            {
                                IsShow(usernameTemp).listmessage.AddFirst(s);
                            }
                            IsShow(usernameTemp).update_message(true);
                        }
                    }
                    if (cmt == CommandType_.MessageFriend)
                    {
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int lengh = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lengh];
                        stream.Read(data, 0, lengh);
                        usernameTemp = Encoding.ASCII.GetString(data);

                        //đọc nội dung tin nhắn
                        string cmdMetaData = "";
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int    lenght     = BitConverter.ToInt32(buffer, 0);
                        byte[] metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        cmdMetaData = Encoding.UTF8.GetString(metaBuffer);
                        //đọc font
                        stream.Read(buffer, 0, 4);
                        lenght     = BitConverter.ToInt32(buffer, 0);
                        metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        //convert byte sang font
                        MemoryStream    s    = new MemoryStream(metaBuffer);
                        BinaryFormatter bf   = new BinaryFormatter();
                        Font            temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                        temp = (Font)bf.Deserialize(s);
                        Chat chatForm = null;
                        _frmMain.Invoke(new Action(delegate()
                        {
                            if ((chatForm = IsShow(usernameTemp)) == null)
                            {
                                chatForm      = new Chat(this, usernameTemp);
                                chatForm.Text = usernameTemp;
                                //Command cmd = new Command(CommandType_.LoadMessage, usernameTemp, 0);
                                // this.SendCommand(cmd);
                                chatForm.Show();
                                listFormChat.Add(chatForm);
                            }
                        }));
                        chatForm.Receive(usernameTemp, cmdMetaData, temp);
                    }
                    if (cmt == CommandType_.LoginSuccess)
                    {
                        stream.Read(buffer, 0, 4);
                        int stt = BitConverter.ToInt32(buffer, 0);

                        byte[] dataPicture;
                        //đọc tên username
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string username = Encoding.ASCII.GetString(data);
                        this._userName = username;


                        //nhận email
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data   = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string email = Encoding.ASCII.GetString(data);


                        //đọc avatar
                        Image image;
                        stream.Read(buffer, 0, 4);
                        lenght      = BitConverter.ToInt32(buffer, 0);
                        dataPicture = new byte[lenght];
                        ReadBigData(stream, lenght, ref dataPicture);
                        MemoryStream mem = new MemoryStream(dataPicture);
                        image = Image.FromStream(mem);

                        //đọc status
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data   = new byte[lenght];
                        ReadBigData(stream, lenght, ref data);
                        string status = Encoding.UTF8.GetString(data);

                        //Đăng nhập thành công
                        //Khởi tạo form chính
                        //dangnhapForm.KillThreard();
                        if (_frmMain == null)
                        {
                            dangnhapForm.Invoke(new Action(delegate()
                            {
                                {
                                    _frmMain      = new Form1(dangnhapForm, 1, this._userName, email, image, status, this);
                                    _frmMain.Text = "Frozen";
                                    _frmMain.Show();
                                    dangnhapForm.Hide();
                                }
                            }));
                        }
                        Command cmd = new Command(CommandType_.ListFriend, this._userName);
                        this.SendCommand(cmd);
                        //load list friend
                        //đọc thông tin list Friend
                        //Thread.Sleep(2000);
                        //--Đọc số lượng friend của user
                    }//End LoginSuccess
                    if (cmt == CommandType_.ListFriend)
                    {
                        stream.Read(buffer, 0, 4);
                        int _CountTemp;
                        _CountTemp          = BitConverter.ToInt32(buffer, 0);
                        _frmMain.listFriend = new List <FriendList>();
                        for (int i = 0; i < _CountTemp; i++)
                        {
                            //đọc useer friend
                            //int a = _abc;
                            stream.Read(buffer, 0, 4);
                            int lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string usernameFriend = Encoding.ASCII.GetString(data);



                            //đọc avatar friend
                            Image _avatarFriend;
                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            byte[] dataPicture = new byte[lenght];
                            ReadBigData(stream, lenght, ref dataPicture);
                            MemoryStream memTemp = new MemoryStream(dataPicture);
                            _avatarFriend = Image.FromStream(memTemp);


                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            ReadBigData(stream, lenght, ref data);
                            string _status = Encoding.UTF8.GetString(data);

                            //đọc trạng thái của friend này
                            stream.Read(buffer, 0, 4);
                            CommandType_ status = (CommandType_)BitConverter.ToInt32(buffer, 0);
                            FriendList   friendTemp;
                            if (status == CommandType_.Online)
                            {
                                friendTemp = new FriendList(usernameFriend, _avatarFriend, true, _status);
                            }
                            else
                            {
                                friendTemp = new FriendList(usernameFriend, _avatarFriend, false, _status);
                            }
                            _frmMain.listFriend.Add(friendTemp);
                        }
                        _frmMain.update_listFriend(true);
                    }
                    if (cmt == CommandType_.Found)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string username = Encoding.ASCII.GetString(data);


                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data   = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string email = Encoding.ASCII.GetString(data);

                        byte[] dataPicture;
                        //đọc avatar
                        Image image;
                        stream.Read(buffer, 0, 4);
                        lenght      = BitConverter.ToInt32(buffer, 0);
                        dataPicture = new byte[lenght];
                        ReadBigData(stream, lenght, ref dataPicture);
                        MemoryStream mem = new MemoryStream(dataPicture);
                        image = Image.FromStream(mem);
                        ff_Form.Found(username, email, image);
                    }
                    if (cmt == CommandType_.NotFound)
                    {
                        ff_Form.Notfound();
                    }
                    if (cmt == CommandType_.NameExists)
                    {
                        MessageCustom.Show("Tài khoản bạn đã được đang nhập bởi người khác!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        dangnhapForm.ChangePanel();
                    }
                    if (cmt == CommandType_.Failure)
                    {
                        MessageCustom.Show("Tài khoản hoặc mật khẩu không đúng!", "Error", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        dangnhapForm.ChangePanel();
                    }
                    if (cmt == CommandType_.RegisterFailure)
                    {
                        MessageCustom.Show("Tài khoản hoặc tên người dùng đã tồn tại!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.RegisterSuccess)
                    {
                        MessageCustom.Show("Đăng kí thành công!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.Online)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string usernameFriend = Encoding.ASCII.GetString(data);
                        foreach (var s in _frmMain.listFriend)
                        {
                            if (s._userFriend == usernameFriend)
                            {
                                s.Status = true;
                            }
                        }
                        _frmMain.update_listFriend(true);
                    }
                    if (cmt == CommandType_.Offline)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string usernameFriend = Encoding.ASCII.GetString(data);
                        foreach (var s in _frmMain.listFriend)
                        {
                            if (s._userFriend == usernameFriend)
                            {
                                s.Status = false;
                            }
                        }
                        _frmMain.update_listFriend(true);
                    }
                    //load toàn bộ thông báo
                    if (cmt == CommandType_.LoadNotice)
                    {
                        stream.Read(buffer, 0, 4);
                        int count = BitConverter.ToInt32(buffer, 0);
                        for (int i = 0; i < count; i++)
                        {
                            stream.Read(buffer, 0, 4);
                            int _stt = BitConverter.ToInt32(buffer, 0);

                            stream.Read(buffer, 0, 4);
                            int lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _userPrimary = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _userReference = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _type = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _content = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data   = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string      _time      = Encoding.ASCII.GetString(data);
                            Notice_List noticeTemp = new Notice_List(_stt, _userPrimary, _userReference, _type, _time);
                            Notice_frm.listNotice.Add(noticeTemp);
                        }
                        Notice_frm.update_Notice(false);
                    }
                    if (cmt == CommandType_.DeleteNoticeSuccess)
                    {
                        Notice_frm.update_Notice(true);
                    }
                    if (cmt == CommandType_.AddNoticeSuccess)
                    {
                        ff_Form.AddNoticeSuccess();
                    }
                    if (cmt == CommandType_.AddNoticeFailure)
                    {
                        ff_Form.AddNoticeFailure();
                    }
                    if (cmt == CommandType_.AddFriendFailure)
                    {
                        ff_Form.AddFriendFailure();
                    }
                }
                catch
                {
                    if (_check)
                    {
                        MessageCustom.Show("Server đang bảo trì !", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        socket.Close();
                        dangnhapForm.Client = null;
                    }
                }
            }//end while
        }
Exemple #23
0
 public void Add(HttpWebRequest req)
 {
     ++send_cnt;
     mProgress.AddLast(req);
 }
        private void Uploadfile(HttpContext context)
        {
            int i = 0;
            System.Collections.Generic.LinkedList<ViewDataUploadFilesResult> r = new System.Collections.Generic.LinkedList<ViewDataUploadFilesResult>();
            string[] files = null;
            string savedFileName = string.Empty;

            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

            try
            {

                if (context.Request.Files.Count >= 1)
                {

                    int maximumFileSize = Convert.ToInt32(ConfigurationManager.AppSettings["UploadFilesMaximumFileSize"].ToString());

                    context.Response.ContentType = "text/plain";
                    for (i = 0; i <= context.Request.Files.Count - 1; i++)
                    {
                        HttpPostedFile hpf = null;
                        string FileName = null;
                        hpf = context.Request.Files[i];

                        if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE")
                        {
                            files = hpf.FileName.Split(Convert.ToChar("\\\\"));
                            FileName = files[files.Length - 1];
                        }
                        else
                        {
                            FileName = hpf.FileName;
                        }

                        if (hpf.ContentLength >= 0 & (hpf.ContentLength <= maximumFileSize * 1000 | maximumFileSize == 0))
                        {

                            savedFileName = StorageRoot(context);

                            savedFileName = savedFileName + FileName;

                            hpf.SaveAs(savedFileName);

                            r.AddLast(new ViewDataUploadFilesResult(FileName, hpf.ContentLength, hpf.ContentType, savedFileName));

                            dynamic uploadedFiles = r.Last;
                            dynamic jsonObj = js.Serialize(uploadedFiles);
                            context.Response.Write(jsonObj.ToString());

                        }
                        else
                        {

                            // File to Big (using IE without ActiveXObject enabled
                            if (hpf.ContentLength > maximumFileSize * 1000)
                            {
                                r.AddLast(new ViewDataUploadFilesResult(FileName, hpf.ContentLength, hpf.ContentType, string.Empty, "maxFileSize"));

                            }

                            dynamic uploadedFiles = r.Last;
                            dynamic jsonObj = js.Serialize(uploadedFiles);
                            context.Response.Write(jsonObj.ToString());

                        }
                    }

                }

            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                throw;
            }
        }
Exemple #25
0
    public void Populate()
    {
        #region Types of Keywords

        FieldPublicDynamic = new { PropPublic1 = "A", PropPublic2 = 1, PropPublic3 = "B", PropPublic4 = "B", PropPublic5 = "B", PropPublic6 = "B", PropPublic7 = "B", PropPublic8 = "B", PropPublic9 = "B", PropPublic10 = "B", PropPublic11 = "B", PropPublic12 = new { PropSubPublic1 = 0, PropSubPublic2 = 1, PropSubPublic3 = 2 } };
        FieldPublicObject  = new StringBuilder("Object - StringBuilder");
        FieldPublicInt32   = int.MaxValue;
        FieldPublicInt64   = long.MaxValue;
        FieldPublicULong   = ulong.MaxValue;
        FieldPublicUInt    = uint.MaxValue;
        FieldPublicDecimal = 100000.999999m;
        FieldPublicDouble  = 100000.999999d;
        FieldPublicChar    = 'A';
        FieldPublicByte    = byte.MaxValue;
        FieldPublicBoolean = true;
        FieldPublicSByte   = sbyte.MaxValue;
        FieldPublicShort   = short.MaxValue;
        FieldPublicUShort  = ushort.MaxValue;
        FieldPublicFloat   = 100000.675555f;

        FieldPublicInt32Nullable   = int.MaxValue;
        FieldPublicInt64Nullable   = 2;
        FieldPublicULongNullable   = ulong.MaxValue;
        FieldPublicUIntNullable    = uint.MaxValue;
        FieldPublicDecimalNullable = 100000.999999m;
        FieldPublicDoubleNullable  = 100000.999999d;
        FieldPublicCharNullable    = 'A';
        FieldPublicByteNullable    = byte.MaxValue;
        FieldPublicBooleanNullable = true;
        FieldPublicSByteNullable   = sbyte.MaxValue;
        FieldPublicShortNullable   = short.MaxValue;
        FieldPublicUShortNullable  = ushort.MaxValue;
        FieldPublicFloatNullable   = 100000.675555f;

        #endregion

        #region System

        FieldPublicDateTime         = new DateTime(2000, 1, 1, 1, 1, 1);
        FieldPublicTimeSpan         = new TimeSpan(1, 10, 40);
        FieldPublicEnumDateTimeKind = DateTimeKind.Local;

        // Instantiate date and time using Persian calendar with years,
        // months, days, hours, minutes, seconds, and milliseconds
        FieldPublicDateTimeOffset = new DateTimeOffset(1387, 2, 12, 8, 6, 32, 545,
                                                       new System.Globalization.PersianCalendar(),
                                                       new TimeSpan(1, 0, 0));

        FieldPublicIntPtr         = new IntPtr(100);
        FieldPublicTimeZone       = TimeZone.CurrentTimeZone;
        FieldPublicTimeZoneInfo   = TimeZoneInfo.Utc;
        FieldPublicTuple          = Tuple.Create <string, int, decimal>("T-string\"", 1, 1.1m);
        FieldPublicType           = typeof(object);
        FieldPublicUIntPtr        = new UIntPtr(100);
        FieldPublicUri            = new Uri("http://www.site.com");
        FieldPublicVersion        = new Version(1, 0, 100, 1);
        FieldPublicGuid           = new Guid("d5010f5b-0cd1-44ca-aacb-5678b9947e6c");
        FieldPublicSingle         = Single.MaxValue;
        FieldPublicException      = new Exception("Test error", new Exception("inner exception"));
        FieldPublicEnumNonGeneric = EnumTest.ValueA;
        FieldPublicAction         = () => true.Equals(true);
        FieldPublicAction2        = (a, b) => true.Equals(true);
        FieldPublicFunc           = () => true;
        FieldPublicFunc2          = (a, b) => true;

        #endregion

        #region Arrays and Collections

        FieldPublicArrayUni    = new string[2];
        FieldPublicArrayUni[0] = "[0]";
        FieldPublicArrayUni[1] = "[1]";

        FieldPublicArrayTwo       = new string[2, 2];
        FieldPublicArrayTwo[0, 0] = "[0, 0]";
        FieldPublicArrayTwo[0, 1] = "[0, 1]";
        FieldPublicArrayTwo[1, 0] = "[1, 0]";
        FieldPublicArrayTwo[1, 1] = "[1, 1]";

        FieldPublicArrayThree          = new string[1, 1, 2];
        FieldPublicArrayThree[0, 0, 0] = "[0, 0, 0]";
        FieldPublicArrayThree[0, 0, 1] = "[0, 0, 1]";

        FieldPublicJaggedArrayTwo    = new string[2][];
        FieldPublicJaggedArrayTwo[0] = new string[5] {
            "a", "b", "c", "d", "e"
        };
        FieldPublicJaggedArrayTwo[1] = new string[4] {
            "a1", "b1", "c1", "d1"
        };

        FieldPublicJaggedArrayThree          = new string[1][][];
        FieldPublicJaggedArrayThree[0]       = new string[1][];
        FieldPublicJaggedArrayThree[0][0]    = new string[2];
        FieldPublicJaggedArrayThree[0][0][0] = "[0][0][0]";
        FieldPublicJaggedArrayThree[0][0][1] = "[0][0][1]";

        FieldPublicMixedArrayAndJagged = new int[3][, ]
        {
            new int[, ] {
                { 1, 3 }, { 5, 7 }
            },
            new int[, ] {
                { 0, 2 }, { 4, 6 }, { 8, 10 }
            },
            new int[, ] {
                { 11, 22 }, { 99, 88 }, { 0, 9 }
            }
        };

        FieldPublicDictionary = new System.Collections.Generic.Dictionary <string, string>();
        FieldPublicDictionary.Add("Key1", "Value1");
        FieldPublicDictionary.Add("Key2", "Value2");
        FieldPublicDictionary.Add("Key3", "Value3");
        FieldPublicDictionary.Add("Key4", "Value4");

        FieldPublicList = new System.Collections.Generic.List <int>();
        FieldPublicList.Add(0);
        FieldPublicList.Add(1);
        FieldPublicList.Add(2);

        FieldPublicQueue = new System.Collections.Generic.Queue <int>();
        FieldPublicQueue.Enqueue(10);
        FieldPublicQueue.Enqueue(11);
        FieldPublicQueue.Enqueue(12);

        FieldPublicHashSet = new System.Collections.Generic.HashSet <string>();
        FieldPublicHashSet.Add("HashSet1");
        FieldPublicHashSet.Add("HashSet2");

        FieldPublicSortedSet = new System.Collections.Generic.SortedSet <string>();
        FieldPublicSortedSet.Add("SortedSet1");
        FieldPublicSortedSet.Add("SortedSet2");
        FieldPublicSortedSet.Add("SortedSet3");

        FieldPublicStack = new System.Collections.Generic.Stack <string>();
        FieldPublicStack.Push("Stack1");
        FieldPublicStack.Push("Stack2");
        FieldPublicStack.Push("Stack3");

        FieldPublicLinkedList = new System.Collections.Generic.LinkedList <string>();
        FieldPublicLinkedList.AddFirst("LinkedList1");
        FieldPublicLinkedList.AddLast("LinkedList2");
        FieldPublicLinkedList.AddAfter(FieldPublicLinkedList.Find("LinkedList1"), "LinkedList1.1");

        FieldPublicObservableCollection = new System.Collections.ObjectModel.ObservableCollection <string>();
        FieldPublicObservableCollection.Add("ObservableCollection1");
        FieldPublicObservableCollection.Add("ObservableCollection2");

        FieldPublicKeyedCollection = new MyDataKeyedCollection();
        FieldPublicKeyedCollection.Add(new MyData()
        {
            Data = "data1", Id = 0
        });
        FieldPublicKeyedCollection.Add(new MyData()
        {
            Data = "data2", Id = 1
        });

        var list = new List <string>();
        list.Add("list1");
        list.Add("list2");
        list.Add("list3");

        FieldPublicReadOnlyCollection = new ReadOnlyCollection <string>(list);

        FieldPublicReadOnlyDictionary           = new ReadOnlyDictionary <string, string>(FieldPublicDictionary);
        FieldPublicReadOnlyObservableCollection = new ReadOnlyObservableCollection <string>(FieldPublicObservableCollection);
        FieldPublicCollection = new Collection <string>();
        FieldPublicCollection.Add("collection1");
        FieldPublicCollection.Add("collection2");
        FieldPublicCollection.Add("collection3");

        FieldPublicArrayListNonGeneric = new System.Collections.ArrayList();
        FieldPublicArrayListNonGeneric.Add(1);
        FieldPublicArrayListNonGeneric.Add("a");
        FieldPublicArrayListNonGeneric.Add(10.0m);
        FieldPublicArrayListNonGeneric.Add(new DateTime(2000, 01, 01));

        FieldPublicBitArray    = new System.Collections.BitArray(3);
        FieldPublicBitArray[2] = true;

        FieldPublicSortedList = new System.Collections.SortedList();
        FieldPublicSortedList.Add("key1", 1);
        FieldPublicSortedList.Add("key2", 2);
        FieldPublicSortedList.Add("key3", 3);
        FieldPublicSortedList.Add("key4", 4);

        FieldPublicHashtableNonGeneric = new System.Collections.Hashtable();
        FieldPublicHashtableNonGeneric.Add("key1", 1);
        FieldPublicHashtableNonGeneric.Add("key2", 2);
        FieldPublicHashtableNonGeneric.Add("key3", 3);
        FieldPublicHashtableNonGeneric.Add("key4", 4);

        FieldPublicQueueNonGeneric = new System.Collections.Queue();
        FieldPublicQueueNonGeneric.Enqueue("QueueNonGeneric1");
        FieldPublicQueueNonGeneric.Enqueue("QueueNonGeneric2");
        FieldPublicQueueNonGeneric.Enqueue("QueueNonGeneric3");

        FieldPublicStackNonGeneric = new System.Collections.Stack();
        FieldPublicStackNonGeneric.Push("StackNonGeneric1");
        FieldPublicStackNonGeneric.Push("StackNonGeneric2");

        FieldPublicIEnumerable = FieldPublicSortedList;

        FieldPublicBlockingCollection = new System.Collections.Concurrent.BlockingCollection <string>();
        FieldPublicBlockingCollection.Add("BlockingCollection1");
        FieldPublicBlockingCollection.Add("BlockingCollection2");

        FieldPublicConcurrentBag = new System.Collections.Concurrent.ConcurrentBag <string>();
        FieldPublicConcurrentBag.Add("ConcurrentBag1");
        FieldPublicConcurrentBag.Add("ConcurrentBag2");
        FieldPublicConcurrentBag.Add("ConcurrentBag3");

        FieldPublicConcurrentDictionary = new System.Collections.Concurrent.ConcurrentDictionary <string, int>();
        FieldPublicConcurrentDictionary.GetOrAdd("ConcurrentDictionary1", 0);
        FieldPublicConcurrentDictionary.GetOrAdd("ConcurrentDictionary2", 0);

        FieldPublicConcurrentQueue = new System.Collections.Concurrent.ConcurrentQueue <string>();
        FieldPublicConcurrentQueue.Enqueue("ConcurrentQueue1");
        FieldPublicConcurrentQueue.Enqueue("ConcurrentQueue2");

        FieldPublicConcurrentStack = new System.Collections.Concurrent.ConcurrentStack <string>();
        FieldPublicConcurrentStack.Push("ConcurrentStack1");
        FieldPublicConcurrentStack.Push("ConcurrentStack2");

        // FieldPublicOrderablePartitioner = new OrderablePartitioner();
        // FieldPublicPartitioner;
        // FieldPublicPartitionerNonGeneric;

        FieldPublicHybridDictionary = new System.Collections.Specialized.HybridDictionary();
        FieldPublicHybridDictionary.Add("HybridDictionaryKey1", "HybridDictionary1");
        FieldPublicHybridDictionary.Add("HybridDictionaryKey2", "HybridDictionary2");

        FieldPublicListDictionary = new System.Collections.Specialized.ListDictionary();
        FieldPublicListDictionary.Add("ListDictionaryKey1", "ListDictionary1");
        FieldPublicListDictionary.Add("ListDictionaryKey2", "ListDictionary2");
        FieldPublicNameValueCollection = new System.Collections.Specialized.NameValueCollection();
        FieldPublicNameValueCollection.Add("Key1", "Value1");
        FieldPublicNameValueCollection.Add("Key2", "Value2");

        FieldPublicOrderedDictionary = new System.Collections.Specialized.OrderedDictionary();
        FieldPublicOrderedDictionary.Add(1, "OrderedDictionary1");
        FieldPublicOrderedDictionary.Add(2, "OrderedDictionary1");
        FieldPublicOrderedDictionary.Add("OrderedDictionaryKey2", "OrderedDictionary2");

        FieldPublicStringCollection = new System.Collections.Specialized.StringCollection();
        FieldPublicStringCollection.Add("StringCollection1");
        FieldPublicStringCollection.Add("StringCollection2");

        #endregion

        #region Several

        PropXmlDocument = new XmlDocument();
        PropXmlDocument.LoadXml("<xml>something</xml>");

        var tr = new StringReader("<Root>Content</Root>");
        PropXDocument         = XDocument.Load(tr);
        PropStream            = GenerateStreamFromString("Stream");
        PropBigInteger        = new System.Numerics.BigInteger(100);
        PropStringBuilder     = new StringBuilder("StringBuilder");
        FieldPublicIQueryable = new List <string>()
        {
            "IQueryable"
        }.AsQueryable();

        #endregion

        #region Custom

        FieldPublicMyCollectionPublicGetEnumerator           = new MyCollectionPublicGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionInheritsPublicGetEnumerator   = new MyCollectionInheritsPublicGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionExplicitGetEnumerator         = new MyCollectionExplicitGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionInheritsExplicitGetEnumerator = new MyCollectionInheritsExplicitGetEnumerator("a b c", new char[] { ' ' });
        FieldPublicMyCollectionInheritsTooIEnumerable        = new MyCollectionInheritsTooIEnumerable("a b c", new char[] { ' ' });

        FieldPublicEnumSpecific = EnumTest.ValueB;
        MyDelegate            = MethodDelegate;
        EmptyClass            = new EmptyClass();
        StructGeneric         = new ThreeTuple <int>(0, 1, 2);
        StructGenericNullable = new ThreeTuple <int>(0, 1, 2);
        FieldPublicNullable   = new Nullable <ThreeTuple <int> >(StructGeneric);

        #endregion
    }
Exemple #26
0
        void exportBrush(object sender, EventArgs e)
        {
            try {
                FileDialog fileDia = new SaveFileDialog();
                fileDia.Filter = filter;
                fileDia.DefaultExt = saveFormat;

                if (fileDia.ShowDialog() == DialogResult.OK) {
                    getValuesFromFormControls();
                    string filename = fileDia.FileName;
                    LinkedList<textureData> textures = new System.Collections.Generic.LinkedList<textureData>();
                    foreach (textureData tex in textureList.Items) {
                        textures.AddLast(tex);
                    }
                    data.exportBrushData(filename, textures, grassTextures.selectedTextures);

                }
            } catch (Exception e2) {
                Console.WriteLine(e2);
            }
        }
Exemple #27
0
        public void bw_receive_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] buffer = new byte[4];
            byte[] data = null;
            string usernameTemp;
            bool check_addMessage = false;
            while (socket.Connected)
            {
                try
                {

                    stream.Read(buffer, 0, 4);
                    CommandType_ cmt = (CommandType_)BitConverter.ToInt32(buffer, 0);
                    if (cmt == CommandType_.Message)
                    {

                        string cmdMetaData = "";
                        buffer = new byte[4];
                        //đọc nội dung tin nhắn
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        byte[] metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        cmdMetaData = Encoding.ASCII.GetString(metaBuffer);
                        //đọc font
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        MemoryStream s = new MemoryStream(metaBuffer);
                        BinaryFormatter bf = new BinaryFormatter();
                        Font temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                        temp = (Font)bf.Deserialize(s);
                        Chat chatForm = null;
                        _frmMain.Invoke(new Action(delegate()
                        {
                            if ((chatForm = IsShow("Server")) == null)
                            {
                                chatForm = new Chat(this, "Server");
                                chatForm.Text = "Server";
                                chatForm.Show();
                                listFormChat.Add(chatForm);
                            }
                        }));
                        chatForm.Receive("Server", cmdMetaData, temp);
                    }//end message

                    if (cmt == CommandType_.LoadMessage)
                    {
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int count = BitConverter.ToInt16(buffer, 0);
                        if (count > 0)
                        {
                            buffer = new byte[4];
                            stream.Read(buffer, 0, 4);
                            int lengh = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lengh];
                            stream.Read(data, 0, lengh);
                            usernameTemp = Encoding.ASCII.GetString(data);
                            LinkedList<MessageText> listmessageTemp = new System.Collections.Generic.LinkedList<MessageText>();
                            for (int i = 0; i < count; i++)
                            {
                                buffer = new byte[4];
                                stream.Read(buffer, 0, 4);
                                lengh = BitConverter.ToInt32(buffer, 0);
                                data = new byte[lengh];
                                stream.Read(data, 0, lengh);
                                string content = Encoding.ASCII.GetString(data);

                                stream.Read(buffer, 0, 4);
                                int lenght = BitConverter.ToInt32(buffer, 0);
                                data = new byte[lenght];
                                stream.Read(data, 0, lenght);
                                MemoryStream s = new MemoryStream(data);
                                s.Position = 0;
                                BinaryFormatter bf = new BinaryFormatter();
                                Font temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                                temp = (Font)bf.Deserialize(s);

                                buffer = new byte[4];
                                stream.Read(buffer, 0, 4);
                                int type = BitConverter.ToInt16(buffer, 0);
                                MessageText mst = new MessageText(content, temp, type);

                                listmessageTemp.AddLast(mst);

                            }
                            foreach (var s in listmessageTemp)
                            {
                                IsShow(usernameTemp).listmessage.AddFirst(s);
                            }
                            IsShow(usernameTemp).update_message(true);

                        }
                    }
                    if (cmt == CommandType_.MessageFriend)
                    {
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int lengh = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lengh];
                        stream.Read(data, 0, lengh);
                        usernameTemp = Encoding.ASCII.GetString(data);

                        //đọc nội dung tin nhắn
                        string cmdMetaData = "";
                        buffer = new byte[4];
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        byte[] metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        cmdMetaData = Encoding.UTF8.GetString(metaBuffer);
                        //đọc font
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        metaBuffer = new byte[lenght];
                        stream.Read(metaBuffer, 0, lenght);
                        //convert byte sang font
                        MemoryStream s = new MemoryStream(metaBuffer);
                        BinaryFormatter bf = new BinaryFormatter();
                        Font temp = new Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular);
                        temp = (Font)bf.Deserialize(s);
                        Chat chatForm = null;
                        _frmMain.Invoke(new Action(delegate()
                        {
                            if ((chatForm = IsShow(usernameTemp)) == null)
                            {
                                chatForm = new Chat(this, usernameTemp);
                                chatForm.Text = usernameTemp;
                                //Command cmd = new Command(CommandType_.LoadMessage, usernameTemp, 0);
                                // this.SendCommand(cmd);
                                chatForm.Show();
                                listFormChat.Add(chatForm);
                            }
                        }));
                        chatForm.Receive(usernameTemp, cmdMetaData, temp);
                    }
                    if (cmt == CommandType_.LoginSuccess)
                    {
                        stream.Read(buffer, 0, 4);
                        int stt = BitConverter.ToInt32(buffer, 0);

                        byte[] dataPicture;
                        //đọc tên username
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string username = Encoding.ASCII.GetString(data);
                        this._userName = username;

                        //nhận email
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string email = Encoding.ASCII.GetString(data);

                        //đọc avatar
                        Image image;
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        dataPicture = new byte[lenght];
                        ReadBigData(stream, lenght, ref dataPicture);
                        MemoryStream mem = new MemoryStream(dataPicture);
                        image = Image.FromStream(mem);

                        //đọc status
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        ReadBigData(stream, lenght, ref data);
                        string status = Encoding.UTF8.GetString(data);

                        //Đăng nhập thành công
                        //Khởi tạo form chính
                        //dangnhapForm.KillThreard();
                        if (_frmMain == null)
                        {
                            dangnhapForm.Invoke(new Action(delegate()
                            {

                                {
                                    _frmMain = new Form1(dangnhapForm, 1, this._userName, email, image, status, this);
                                    _frmMain.Text = "Frozen";
                                    _frmMain.Show();
                                    dangnhapForm.Hide();
                                }
                            }));

                        }
                        Command cmd = new Command(CommandType_.ListFriend, this._userName);
                        this.SendCommand(cmd);
                        //load list friend
                        //đọc thông tin list Friend
                        //Thread.Sleep(2000);
                        //--Đọc số lượng friend của user

                    }//End LoginSuccess
                    if (cmt == CommandType_.ListFriend)
                    {
                        stream.Read(buffer, 0, 4);
                        int _CountTemp;
                        _CountTemp = BitConverter.ToInt32(buffer, 0);
                        _frmMain.listFriend = new List<FriendList>();
                        for (int i = 0; i < _CountTemp; i++)
                        {
                            //đọc useer friend
                            //int a = _abc;
                            stream.Read(buffer, 0, 4);
                            int lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string usernameFriend = Encoding.ASCII.GetString(data);

                            //đọc avatar friend
                            Image _avatarFriend;
                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            byte[] dataPicture = new byte[lenght];
                            ReadBigData(stream, lenght, ref dataPicture);
                            MemoryStream memTemp = new MemoryStream(dataPicture);
                            _avatarFriend = Image.FromStream(memTemp);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            ReadBigData(stream, lenght, ref data);
                            string _status = Encoding.UTF8.GetString(data);

                            //đọc trạng thái của friend này
                            stream.Read(buffer, 0, 4);
                            CommandType_ status = (CommandType_)BitConverter.ToInt32(buffer, 0);
                            FriendList friendTemp;
                            if (status == CommandType_.Online)
                            {
                                friendTemp = new FriendList(usernameFriend, _avatarFriend, true, _status);
                            }
                            else
                            {
                                friendTemp = new FriendList(usernameFriend, _avatarFriend, false, _status);
                            }
                            _frmMain.listFriend.Add(friendTemp);
                        }
                        _frmMain.update_listFriend(true);
                    }
                    if (cmt == CommandType_.Found)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string username = Encoding.ASCII.GetString(data);

                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string email = Encoding.ASCII.GetString(data);

                        byte[] dataPicture;
                        //đọc avatar
                        Image image;
                        stream.Read(buffer, 0, 4);
                        lenght = BitConverter.ToInt32(buffer, 0);
                        dataPicture = new byte[lenght];
                        ReadBigData(stream, lenght, ref dataPicture);
                        MemoryStream mem = new MemoryStream(dataPicture);
                        image = Image.FromStream(mem);
                        ff_Form.Found(username, email, image);
                    }
                    if (cmt == CommandType_.NotFound)
                    {
                        ff_Form.Notfound();
                    }
                    if (cmt == CommandType_.NameExists)
                    {
                        MessageCustom.Show("Tài khoản bạn đã được đang nhập bởi người khác!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        dangnhapForm.ChangePanel();
                    }
                    if (cmt == CommandType_.Failure)
                    {
                        MessageCustom.Show("Tài khoản hoặc mật khẩu không đúng!", "Error", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        dangnhapForm.ChangePanel();
                    }
                    if (cmt == CommandType_.RegisterFailure)
                    {
                        MessageCustom.Show("Tài khoản hoặc tên người dùng đã tồn tại!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.RegisterSuccess)
                    {
                        MessageCustom.Show("Đăng kí thành công!", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                    }
                    if (cmt == CommandType_.Online)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string usernameFriend = Encoding.ASCII.GetString(data);
                        foreach (var s in _frmMain.listFriend)
                        {
                            if (s._userFriend == usernameFriend)
                            {
                                s.Status = true;
                            }
                        }
                        _frmMain.update_listFriend(true);
                    }
                    if (cmt == CommandType_.Offline)
                    {
                        stream.Read(buffer, 0, 4);
                        int lenght = BitConverter.ToInt32(buffer, 0);
                        data = new byte[lenght];
                        stream.Read(data, 0, lenght);
                        string usernameFriend = Encoding.ASCII.GetString(data);
                        foreach (var s in _frmMain.listFriend)
                        {
                            if (s._userFriend == usernameFriend)
                            {
                                s.Status = false;
                            }
                        }
                        _frmMain.update_listFriend(true);
                    }
                    //load toàn bộ thông báo
                    if (cmt == CommandType_.LoadNotice)
                    {
                        stream.Read(buffer, 0, 4);
                        int count = BitConverter.ToInt32(buffer, 0);
                        for (int i = 0; i < count; i++)
                        {

                            stream.Read(buffer, 0, 4);
                            int _stt = BitConverter.ToInt32(buffer, 0);

                            stream.Read(buffer, 0, 4);
                            int lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _userPrimary = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _userReference = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _type = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _content = Encoding.ASCII.GetString(data);

                            stream.Read(buffer, 0, 4);
                            lenght = BitConverter.ToInt32(buffer, 0);
                            data = new byte[lenght];
                            stream.Read(data, 0, lenght);
                            string _time = Encoding.ASCII.GetString(data);
                            Notice_List noticeTemp = new Notice_List(_stt, _userPrimary, _userReference, _type, _time);
                            Notice_frm.listNotice.Add(noticeTemp);
                        }
                        Notice_frm.update_Notice(false);
                    }
                    if (cmt == CommandType_.DeleteNoticeSuccess)
                    {
                        Notice_frm.update_Notice(true);
                    }
                    if (cmt == CommandType_.AddNoticeSuccess)
                    {
                        ff_Form.AddNoticeSuccess();
                    }
                    if (cmt == CommandType_.AddNoticeFailure)
                    {
                        ff_Form.AddNoticeFailure();
                    }
                    if (cmt == CommandType_.AddFriendFailure)
                    {
                        ff_Form.AddFriendFailure();
                    }
                }
                catch
                {
                    if (_check)
                    {
                        MessageCustom.Show("Server đang bảo trì !", "Thông báo", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))));
                        socket.Close();
                        dangnhapForm.Client = null;
                    }
                }
            }//end while
        }
Exemple #28
0
        public bool Push(T item)
        {
            LinkedListNode <T> addedItem = List.AddLast(item);

            return(addedItem != null);
        }
 private void AddTemp()
 {
     linkedList.AddLast(value);
     ClearTemp();
 }
 public void Enque(Animal a)
 {
     _animals.AddLast(a);
 }
Exemple #31
0
 public Snake()
 {
     _Waits = new Queue<SnakeBody>();
     _Bodys = new LinkedList<SnakeBody>();
     _Bodys.AddLast(new SnakeBody());
 }
Exemple #32
0
 public void Add(string part)
 {
     //Add parts
     parts.AddLast(part);
 }
    /// <summary>
    /// Does a search for a path from start to finish on
    /// graph using given search type
    /// </summary>
    /// <param name="start">start value</param>
    /// <param name="finish">finish value</param>
    /// <param name="graph">graph to search</param>
    /// <returns>string for path or empty string if there is no path</returns>
    string Search(int start, int finish, Graph <int> graph, SearchType searchType)
    {
        System.Collections.Generic.LinkedList <GraphNode <int> > searchList =
            new System.Collections.Generic.LinkedList <GraphNode <int> >();

        //Special case for start and finish the same
        if (start == finish)
        {
            return(start.ToString());
        }
        else if (graph.Find(start) == null || graph.Find(finish) == null)
        {
            //Start or finish not in graph
            return("");
        }
        else
        {
            //Add start node to dictionary and search list
            GraphNode <int> startNode = graph.Find(start);
            Dictionary <GraphNode <int>, PathNodeInfo <int> > pathNodes =
                new Dictionary <GraphNode <int>, PathNodeInfo <int> >();

            pathNodes.Add(startNode, new PathNodeInfo <int>(null));
            searchList.AddFirst(startNode);

            //Loop until we exhaust all possible paths
            while (searchList.Count > 0)
            {
                //Extract front of search list
                GraphNode <int> currentNode = searchList.First.Value;
                print("Current Node: " + currentNode.Value);
                searchList.RemoveFirst();

                //Explore each neighbor of this node
                foreach (GraphNode <int> neighbor in currentNode.Neighbors)
                {
                    //Check for found finish
                    if (neighbor.Value == finish)
                    {
                        pathNodes.Add(neighbor, new PathNodeInfo <int>(currentNode));
                        return(ConvertPathToString(neighbor, pathNodes));
                    }
                    else if (pathNodes.ContainsKey(neighbor))
                    {
                        //Found a cycle, so skip this neighbor
                        continue;
                    }
                    else
                    {
                        //Link neighbor to current node in path
                        pathNodes.Add(neighbor, new PathNodeInfo <int>(currentNode));

                        //Add neighbor to front or back of search list
                        if (searchType == SearchType.DepthFirst)
                        {
                            searchList.AddFirst(neighbor);
                        }
                        else
                        {
                            searchList.AddLast(neighbor);
                        }

                        print("Just added " + neighbor.Value + " to search list");
                    }
                }
            }
            //Didn't find a path from start to finish
            return("");
        }
    }
 /// <summary>
 /// This method adds the given element to the queue.
 /// </summary>
 /// <param name="item">The value to be added to the queue.</param>
 public void Enqueue(T item)
 {
     _list.AddLast(item);
 }
 /// <summary>
 /// Adds an item to the back of the queue
 /// </summary>
 /// <param name="item">The item to place in the queue</param>
 public void Enqueue(T item)
 {
     _items.AddLast(item);
 }
Exemple #36
0
        /// <summary>
        /// Paint the triangles defined by the points
        /// </summary>
        /// <param name="points"></param>
        private LinkedList<Triangle> makeTriangles(LinkedList<Pair<double, double>> points)
        {
            if (points == null ||points.Count == 0)
                return null;

            CPoint2D[] vertices = new CPoint2D[points.Count];
            LinkedList<Triangle> triangles = new System.Collections.Generic.LinkedList<Triangle>();

            int index = 0;
            foreach (Pair<double, double> p in points) {
                vertices[index] = new CPoint2D(p.X, p.Y);
                index++;
            }

            CPolygonShape cutPolygon =  new CPolygonShape(vertices);
            cutPolygon.CutEar();

            debugOut("Numer of polygons: "  + cutPolygon.NumberOfPolygons);

            CPoint2D[] corners;

            for(int numPoly = 0; numPoly < cutPolygon.NumberOfPolygons; numPoly++) {
                #region find upper and lower
                corners = cutPolygon.Polygons(numPoly);

                Pair<double, double>[] corns = new Pair<double, double>[3];
                for(int cornIndex = 0; cornIndex < 3; cornIndex++) {
                    CPoint2D coern = corners[cornIndex];
                    corns[cornIndex] = new Pair<double, double>(coern.X, coern.Y);
                }

                Pair<Pair<double, double>, Pair<double, double>> pairResult = findUpperAndLower(new LinkedList<Pair<double, double>>(corns));

                Pair<double, double> upper = pairResult.X;
                Pair<double, double> lower = pairResult.Y;

                Triangle inside = new Triangle(corns, upper, lower);

                debugOut(inside.ToString());

                triangles.AddLast(inside);
                #endregion
            }
            return triangles;
        }
        // On error or failure, returns null.
        private static string locate_fxc_on_disk()
        {
            try
            {
                long EndTime = DateTime.Now.Ticks + MAX_LOCATE_TIME;

                // Paths to process
                System.Collections.Generic.LinkedList<string> PathQueue = new System.Collections.Generic.LinkedList<string>();
                // Path already processed in form Key=Path, Value="1"
                System.Collections.Specialized.StringDictionary Processed = new System.Collections.Specialized.StringDictionary();

                // Add default paths
                // - Program files
                PathQueue.AddLast(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
                // - Hard disks
                foreach (DriveInfo Drive in DriveInfo.GetDrives())
                    if (Drive.DriveType == DriveType.Fixed)
                        PathQueue.AddLast(Drive.RootDirectory.Name);

                // Processing loop - berform breadth first search (BFS) algorithm
                while (PathQueue.Count > 0)
                {
                    // Get directory to process
                    string Dir = PathQueue.First.Value;
                    PathQueue.RemoveFirst();
                    // Already processed
                    if (Processed.ContainsKey(Dir))
                        continue;
                    // Add to processed
                    Processed.Add(Dir, "1");

                    try
                    {
                        // Look for fxc.exe file
                        string[] FxcFiles = Directory.GetFiles(Dir, "fxc.exe");
                        if (FxcFiles.Length > 0)
                            return FxcFiles[0];

                        // Look for subdirectories
                        foreach (string SubDir in Directory.GetDirectories(Dir))
                        {
                            // Interesting directory - add at the beginning of the queue
                            if (DirectoryIsInteresting(SubDir))
                                PathQueue.AddFirst(SubDir);
                            // Not interesting - add at the end of the queue
                            else
                                PathQueue.AddLast(SubDir);
                        }
                    }
                    catch (Exception ) { }

                    // Time out
                    if (DateTime.Now.Ticks >= EndTime)
                        return null;
                }

                // Not found
                return null;
            }
            catch (Exception )
            {
                return null;
            }
        }