Example #1
0
            // Execute when user Log out.
            private void DeleteUserFiles(User user)
            {
                foreach (FileDetails file in user.FileList)
                {
                    if (ServerFileList.ContainsKey(file))
                    {
                        // File exsits in list.
                        if (ServerFileList[file].Contains(user))
                        {
                            // This user in owner of this file.
                            ServerFileList[file].Remove(user);

                            // Delete this file if there is no longer more owners.
                            if (ServerFileList[file].Count == 0)
                            {
                                ServerFileList.Remove(file);
                            }
                        }
                    }
                }

                // Delete user from list if is active.
                if (ActiveUsers.Contains(user))
                {
                    ActiveUsers.Remove(user);
                }

                while (bwUpdateUserList.IsBusy)
                {
                    ;
                }
                bwUpdateUserList.RunWorkerAsync();
            }
Example #2
0
            // Execute when user Log in.
            private void AddUserFiles(User user, OperationsDB DB)
            {
                lock (thisLock)
                {
                    if (!ActiveUsers.Contains(user))
                    {
                        ActiveUsers.Add(user);
                    }
                }

                foreach (FileDetails file in user.FileList)
                {
                    if (ServerFileList.ContainsKey(file))
                    {
                        // This file already exist in list.
                        // Add this user as adition peer to download.
                        lock (thisLock)
                        {
                            if (!ServerFileList[file].Contains(user))
                            {
                                ServerFileList[file].Add(user);
                                DB.AddPeerToFile(file.FileName, file.FileSize);
                            }
                        }
                    }

                    else
                    {
                        // This file new in list.
                        lock (thisLock)
                        {
                            ServerFileList.Add(file, new List <User>());
                            ServerFileList[file].Add(user);
                            DB.AddFile(file.FileName, file.FileSize);
                        }
                    }
                }

                while (bwUpdateUserList.IsBusy)
                {
                    ;
                }
                bwUpdateUserList.RunWorkerAsync();
            }