School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,54 @@
<groups>
<group groupId="c221950c-7e1d-4a17-83a7-9af616bba78d" groupName="group 1">
<members>
<user userId="d161f928-2601-4e63-be9f-c05a1399b6b3" username="username2" password="password2" email="username2@gmail.ro" confirmationPassword="password2" />
<user userId="cf9428ef-97c3-4003-9815-03942dc79da8" username="username3" password="password3" email="user3@yahoo.com" confirmationPassword="password3" />
<user userId="3b63be21-18ce-46cb-801c-0dca405c7e83" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
<user userId="db61df0b-f9ae-489e-8406-bc116ee26ebc" username="username5" password="password5" email="username4@gmail.es" confirmationPassword="password5" />
</members>
</group>
<group groupId="efa488bd-050b-442c-8ebb-5ae3a4d9b7e4" groupName="group 3">
<members>
<user userId="3b63be21-18ce-46cb-801c-0dca405c7e83" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
<user userId="55f400a6-dcdf-4763-8ab0-fd6f2d1438a3" username="username5" password="password5" email="username4@gmail.es" confirmationPassword="password5" />
<user userId="d161f928-2601-4e63-be9f-c05a1399b6b3" username="username2" password="password2" email="username2@gmail.ro" confirmationPassword="password2" />
</members>
</group>
<group groupId="487a96c4-eb2b-4eea-9ac2-ecf3458206ec" groupName="group 2">
<members>
<user userId="3b63be21-18ce-46cb-801c-0dca405c7e83" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
<user userId="55f400a6-dcdf-4763-8ab0-fd6f2d1438a3" username="username5" password="password5" email="username4@gmail.es" confirmationPassword="password5" />
<user userId="ad36cdfe-3a9f-4f6b-a2ce-d9a73fd4c405" username="username4" password="password4" email="username4@stud.ubbcluj.ro" confirmationPassword="password4" />
<user userId="5d0cd3c3-9f92-481c-9c6e-75830d3743a4" username="username3" password="password3" email="user3@yahoo.com" confirmationPassword="password3" />
</members>
</group>
<group groupId="df05a760-20bd-4b3f-920f-a5407ad0c25a" groupName="another group">
<members>
<user userId="55f400a6-dcdf-4763-8ab0-fd6f2d1438a3" username="username5" password="password5" email="username4@gmail.es" confirmationPassword="password5" />
<user userId="cf9428ef-97c3-4003-9815-03942dc79da8" username="username3" password="password3" email="user3@yahoo.com" confirmationPassword="password3" />
<user userId="ce7ad3bd-0b87-4122-8766-54be4cef5fe9" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
<user userId="ba8f4eca-daa5-4c34-af00-0ff70a022526" username="username2" password="password2" email="username2@gmail.ro" confirmationPassword="password2" />
</members>
</group>
<group groupId="4163dad5-ab81-4d26-9d02-559d04d88733" groupName="testXMLGroup">
<members>
<user userId="998e1318-0a8c-4896-9aa0-6cd64419fc78" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
</members>
</group>
<group groupId="14620abb-17a0-4dd3-9c7e-8aa1de3b8225" groupName="newGrouptestXML">
<members>
<user userId="51a31753-6359-47c9-82fa-b8468136e14f" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
</members>
</group>
<group groupId="61ffb63b-5f2d-4ef6-8a1a-d01ef83b784b" groupName="testAllXML">
<members>
<user userId="88d05d97-0cad-4ce3-a06f-be6e69d698b5" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
</members>
</group>
<group groupId="1ffeb77a-a4dd-437b-a561-d5a90ace73d7" groupName="THELAST___TEST">
<members>
<user userId="52e1cf6f-c1a9-4100-af4b-9eedc2172cb2" username="username1" password="password1" email="user1@yahoo.ro" confirmationPassword="password1" />
<user userId="2d793e4d-0dd3-43f4-b6d3-c3a415212b45" username="username4" password="password4" email="username4@stud.ubbcluj.ro" confirmationPassword="password4" />
</members>
</group>
</groups>
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using District_3_App.ExtraInfo;
namespace District_3_App.ProfileSocialNetworkInfoStuff.Entities
{
public class BlockedProfile : IComparable<BlockedProfile>
{
public User User { get; set; }
public DateTime BlockDate { get; set; }
public BlockedProfile()
{
}
public BlockedProfile(User user, DateTime date)
{
this.User = user;
this.BlockDate = date;
}
public string DateToString()
{
return BlockDate.ToString("yyyy-MM-dd HH:mm:ss");
}
public int CompareTo(BlockedProfile other)
{
return this.BlockDate.CompareTo(other.BlockDate);
}
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace District_3_App.ProfileSocialNetworkInfoStuff.Entities
{
public class CloseFriendProfile : IComparable<CloseFriendProfile>
{
public User User { get; set; }
public DateTime CloseFriendedDate { get; set; }
public CloseFriendProfile()
{
}
public CloseFriendProfile(User user, DateTime closeFriendedDate)
{
this.User = user;
this.CloseFriendedDate = closeFriendedDate;
}
public int CompareTo(CloseFriendProfile other)
{
return this.User.CompareTo(other.User);
}
}
}
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using District_3_App.ExtraInfo;
namespace District_3_App.ProfileSocialNetworkInfoStuff.Entities
{
public class Group : IComparable<Group>
{
public Guid Id { get; set; }
public string GroupName { get; set; }
public List<User> GroupMembers { get; set; }
public Group()
{
}
public Group(Guid id, string groupName, List<User> groupMembers)
{
this.Id = id;
this.GroupName = groupName;
this.GroupMembers = groupMembers;
}
public int CompareTo(Group other)
{
return this.GroupName.CompareTo(other.GroupName);
}
}
}
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace District_3_App.ProfileSocialNetworkInfoStuff.Entities
{
public class User : IComparable<User> // MODIFY UML DIAGRAM USER CLASS
{
public Guid Id { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string ConfirmationPassword { get; set; }
public DateTime RegistrationDate { get; set; }
public int FollowingCount { get; set; }
public int FollowersCount { get; set; }
public TimeSpan Usersession { get; set; }
public User()
{
}
public User(Guid id, string username, string password, string email, string confirmationPassword)
{
this.Id = id;
this.Username = username;
this.Password = password;
this.Email = email;
this.ConfirmationPassword = confirmationPassword;
}
public User(Guid id, string username, string password, string email, string confirmationPassword, int followingCount, int followersCount)
{
this.Id = id;
this.Username = username;
this.Password = password;
this.Email = email;
this.ConfirmationPassword = confirmationPassword;
this.FollowersCount = followersCount;
this.FollowingCount = followingCount;
}
public User(Guid id, string username, string password, string email, string confirmationPassword, TimeSpan usersession)
{
this.Id = id;
this.Username = username;
this.Password = password;
this.Email = email;
this.ConfirmationPassword = confirmationPassword;
this.Usersession = usersession;
}
public string RegistrationDateToString()
{
return this.RegistrationDate.ToString("yyyy-MM-dd HH:mm:ss");
}
public int CompareTo(User other)
{
return this.Username.CompareTo(other.Username);
}
}
}
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace District_3_App.ProfileSocialNetworkInfoStuff.Entities
{
public class UserProfileSocialNetworkInfo
{
public User User { get; set; }
public List<BlockedProfile> BlockedProfiles { get; set; }
public List<CloseFriendProfile> CloseFriendsProfiles { get; set; }
public List<Group> Groups { get; set; }
public List<User> RestrictedStoriesAudience { get; set; }
public List<User> RestrictedPostsAudience { get; set; }
public bool IsProfilePrivate { get; set; }
public UserProfileSocialNetworkInfo()
{
// Create mock data with default values
User = new User();
BlockedProfiles = new List<BlockedProfile>();
CloseFriendsProfiles = new List<CloseFriendProfile>();
Groups = new List<Group>();
RestrictedStoriesAudience = new List<User>();
RestrictedPostsAudience = new List<User>();
IsProfilePrivate = false; // Assuming the default profile privacy is set to public
}
public UserProfileSocialNetworkInfo(User user, List<BlockedProfile> blockedProfiles, List<CloseFriendProfile> closeFriendsProfiles, List<Group> groups, List<User> restrictedStoriesAudience, List<User> restrictedPostsAudience)
{
this.User = user;
this.BlockedProfiles = blockedProfiles;
this.CloseFriendsProfiles = closeFriendsProfiles;
this.Groups = groups;
this.RestrictedStoriesAudience = restrictedStoriesAudience;
this.RestrictedPostsAudience = restrictedPostsAudience;
this.IsProfilePrivate = false;
}
}
}
@@ -0,0 +1,213 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
namespace District_3_App.ProfileSocialNetworkInfoStuff.ProfileNetworkInfo_Repository
{
public class GroupsRepository
{
public List<Group> GroupsRepository1 { get; set; }
private string filePath;
public GroupsRepository()
{
this.filePath = "./ProfileSocialNetworkInfoStuff/Groups.xml";
this.GroupsRepository1 = LoadGroupsFromXML();
}
public GroupsRepository(List<Group> groupsRepository)
{
this.GroupsRepository1 = groupsRepository;
this.filePath = "./ProfileSocialNetworkInfoStuff/Groups.xml";
SaveGroupsInXML();
}
private List<Group> LoadGroupsFromXML()
{
List<Group> loadedGroups = new List<Group>();
XmlDocument xmlDoc = new XmlDocument();
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = baseDirectory.Substring(0, baseDirectory.IndexOf("bin\\Debug"));
string currfilePath = System.IO.Path.Combine(relativePath, "ProfileSocialNetworkInfoStuff");
filePath = System.IO.Path.Combine(currfilePath, "Groups.xml");
xmlDoc.Load(filePath);
foreach (XmlNode groupNode in xmlDoc.SelectNodes("//group"))
{
Group group = new Group();
group.Id = Guid.Parse(groupNode.Attributes["groupId"].Value);
group.GroupName = groupNode.Attributes["groupName"].Value;
group.GroupMembers = new List<User>();
foreach (XmlNode userNode in groupNode.SelectNodes("members/user"))
{
User user = new User();
user.Id = Guid.Parse(userNode.Attributes["userId"].Value);
user.Username = userNode.Attributes["username"].Value;
user.Password = userNode.Attributes["password"].Value;
user.Email = userNode.Attributes["email"].Value;
user.ConfirmationPassword = userNode.Attributes["confirmationPassword"].Value;
group.GroupMembers.Add(user);
}
loadedGroups.Add(group);
}
return loadedGroups;
}
private void SaveGroupsInXML()
{
XmlDocument xmlDocument = new XmlDocument();
XmlNode groupsNode = xmlDocument.CreateElement("groups");
xmlDocument.AppendChild(groupsNode);
foreach (Group group in GroupsRepository1)
{
XmlNode groupNode = xmlDocument.CreateElement("group");
groupsNode.AppendChild(groupNode);
XmlAttribute groupIdAttribute = xmlDocument.CreateAttribute("groupId");
groupIdAttribute.Value = group.Id.ToString();
groupNode.Attributes.Append(groupIdAttribute);
XmlAttribute groupNameAttribute = xmlDocument.CreateAttribute("groupName");
groupNameAttribute.Value = group.GroupName;
groupNode.Attributes.Append(groupNameAttribute);
XmlNode members = xmlDocument.CreateElement("members");
groupNode.AppendChild(members);
foreach (var member in group.GroupMembers)
{
XmlNode userNode = xmlDocument.CreateElement("user");
members.AppendChild(userNode);
XmlAttribute userIdAttribute = xmlDocument.CreateAttribute("userId");
userIdAttribute.Value = member.Id.ToString();
userNode.Attributes.Append(userIdAttribute);
XmlAttribute usernameAttribute = xmlDocument.CreateAttribute("username");
usernameAttribute.Value = member.Username;
userNode.Attributes.Append(usernameAttribute);
XmlAttribute passwordAttribute = xmlDocument.CreateAttribute("password");
passwordAttribute.Value = member.Password;
userNode.Attributes.Append(passwordAttribute);
XmlAttribute emailAttribute = xmlDocument.CreateAttribute("email");
emailAttribute.Value = member.Email;
userNode.Attributes.Append(emailAttribute);
XmlAttribute confirmationPasswordAttribute = xmlDocument.CreateAttribute("confirmationPassword");
confirmationPasswordAttribute.Value = member.ConfirmationPassword;
userNode.Attributes.Append(confirmationPasswordAttribute);
}
}
xmlDocument.Save(this.filePath);
}
public List<Group> GetAllGroups()
{
return this.GroupsRepository1;
}
public bool AddGroup(Group groupToAdd)
{
foreach (var group in GroupsRepository1)
{
if (group.Id == groupToAdd.Id)
{
return false;
}
}
this.GroupsRepository1.Add(groupToAdd);
SaveGroupsInXML();
return true;
}
public bool RemoveGroup(Group groupToRemove)
{
foreach (var group in GroupsRepository1)
{
if (group.Id == groupToRemove.Id)
{
GroupsRepository1.Remove(group);
SaveGroupsInXML();
return true;
}
}
return false;
}
public Group GetGroupByGroupName(string groupName)
{
foreach (var group in GroupsRepository1)
{
if (groupName == group.GroupName)
{
return group;
}
}
return null;
}
public bool AddMemberToGroup(string groupName, User memberToAdd)
{
foreach (var group in GroupsRepository1)
{
if (group.GroupName == groupName)
{
foreach (var currentMember in group.GroupMembers)
{
if (currentMember.Username == memberToAdd.Username)
{
return false;
}
}
group.GroupMembers.Add(memberToAdd);
SaveGroupsInXML();
return true;
}
}
return false;
}
public bool RemoveMemberFromGroup(string groupName, User memberToRemove)
{
foreach (var group in GroupsRepository1)
{
if (group.GroupName == groupName)
{
foreach (var currentMember in group.GroupMembers)
{
if (currentMember.Username == memberToRemove.Username)
{
group.GroupMembers.Remove(memberToRemove);
SaveGroupsInXML();
return true;
}
}
return false;
}
}
return false;
}
}
}
@@ -0,0 +1,230 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Xml;
using System.Xml.Serialization;
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
namespace District_3_App.ProfileSocialNetworkInfoStuff.ProfileNetworkInfo_Repository
{
public class ProfileNetworkInfoRepository<T>
{
private List<UserProfileSocialNetworkInfo> repositoryList;
private string filePath;
public ProfileNetworkInfoRepository(List<UserProfileSocialNetworkInfo> repositoryList)
{
this.repositoryList = repositoryList;
SaveProfilesInXML();
}
public ProfileNetworkInfoRepository()
{
this.filePath = "./ProfileSocialNetworkInfoStuff/Profiles.xml";
LoadProfilesInXML();
SaveProfilesInXML();
}
public void LoadProfilesInXML()
{
XmlSerializer serializer = new XmlSerializer(typeof(List<UserProfileSocialNetworkInfo>));
XmlDocument xmlDoc = new XmlDocument();
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = baseDirectory.Substring(0, baseDirectory.IndexOf("bin\\Debug"));
string currfilePath = System.IO.Path.Combine(relativePath, "ProfileSocialNetworkInfoStuff");
filePath = System.IO.Path.Combine(currfilePath, "Profiles.xml");
// MessageBox.Show(filePath);
using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
{
repositoryList = (List<UserProfileSocialNetworkInfo>)serializer.Deserialize(fileStream);
}
}
public void SaveProfilesInXML()
{
XmlSerializer serializer = new XmlSerializer(typeof(List<UserProfileSocialNetworkInfo>));
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string relativePath = baseDirectory.Substring(0, baseDirectory.IndexOf("bin\\Debug"));
string currfilePath = System.IO.Path.Combine(relativePath, "ProfileSocialNetworkInfoStuff");
filePath = System.IO.Path.Combine(currfilePath, "Profiles.xml");
using (TextWriter writer = new StreamWriter(filePath))
{
serializer.Serialize(writer, repositoryList);
}
// XmlDocument xmlDocument = new XmlDocument();
// XmlNode profilesNode = xmlDocument.CreateElement("profiles");
// xmlDocument.AppendChild(profilesNode);
// foreach (UserProfileSocialNetworkInfo profile in repositoryList)
// {
// XmlNode profileNode = xmlDocument.CreateElement("profile");
// profilesNode.AppendChild(profileNode);
// XmlNode userNode = xmlDocument.CreateElement("user");
// profileNode.AppendChild(userNode);
// XmlAttribute userIdAttribute = xmlDocument.CreateAttribute("id");
// userIdAttribute.Value = profile.user.id.ToString();
// userNode.Attributes.Append(userIdAttribute);
// XmlAttribute usernameAttribute = xmlDocument.CreateAttribute("username");
// usernameAttribute.Value = profile.user.username;
// userNode.Attributes.Append(usernameAttribute);
// XmlAttribute passwordAttribute = xmlDocument.CreateAttribute("password");
// passwordAttribute.Value = profile.user.password;
// userNode.Attributes.Append(passwordAttribute);
// XmlAttribute emailAttribute = xmlDocument.CreateAttribute("email");
// emailAttribute.Value = profile.user.email;
// userNode.Attributes.Append(emailAttribute);
// XmlAttribute confirmationPasswordAttribute = xmlDocument.CreateAttribute("confirmationPassword");
// confirmationPasswordAttribute.Value = profile.user.confirmationPassword;
// userNode.Attributes.Append(confirmationPasswordAttribute);
// XmlNode blockedAccountsNode = xmlDocument.CreateElement("blockedAccounts");
// profileNode.AppendChild(blockedAccountsNode);
// foreach(var blockedAccount in profile.blockedProfiles)
// {
// XmlNode blockedAccNode = xmlDocument.CreateElement("blockedAccount");
// blockedAccountsNode.AppendChild(blockedAccNode);
// XmlNode userBlockedAccountNode = xmlDocument.CreateElement("user");
// blockedAccNode.AppendChild(userBlockedAccountNode);
// XmlAttribute userIdBlockedAttribute = xmlDocument.CreateAttribute("id");
// userIdAttribute.Value = blockedAccount.user.id.ToString();
// userBlockedAccountNode.Attributes.Append(userIdBlockedAttribute);
// XmlAttribute usernameBlockedAttribute = xmlDocument.CreateAttribute("username");
// usernameAttribute.Value = blockedAccount.user.username;
// userBlockedAccountNode.Attributes.Append(usernameBlockedAttribute);
// XmlAttribute passwordBlockedAttribute = xmlDocument.CreateAttribute("password");
// passwordAttribute.Value = blockedAccount.user.password;
// userBlockedAccountNode.Attributes.Append(passwordBlockedAttribute);
// XmlAttribute emailBlockedAttribute = xmlDocument.CreateAttribute("email");
// emailAttribute.Value = blockedAccount.user.email;
// userBlockedAccountNode.Attributes.Append(emailBlockedAttribute);
// XmlAttribute confirmationPasswordBlockedAttribute = xmlDocument.CreateAttribute("confirmationPassword");
// confirmationPasswordAttribute.Value = blockedAccount.user.confirmationPassword;
// userBlockedAccountNode.Attributes.Append(confirmationPasswordBlockedAttribute);
// XmlAttribute blockDateAttribute = xmlDocument.CreateAttribute("blockDate");
// blockDateAttribute.Value = blockedAccount.blockDate.ToString();
// userBlockedAccountNode.Attributes.Append(confirmationPasswordBlockedAttribute);
// }
// foreach(var closeFriend in profile.closeFriendsProfiles)
// {
// XmlNode blockedAccNode = xmlDocument.CreateElement("blockedAccount");
// blockedAccountsNode.AppendChild(blockedAccNode);
// XmlNode userBlockedAccountNode = xmlDocument.CreateElement("user");
// blockedAccNode.AppendChild(userBlockedAccountNode);
// XmlAttribute userIdBlockedAttribute = xmlDocument.CreateAttribute("id");
// userIdAttribute.Value = profile.user.id.ToString();
// userBlockedAccountNode.Attributes.Append(userIdBlockedAttribute);
// XmlAttribute usernameBlockedAttribute = xmlDocument.CreateAttribute("username");
// usernameAttribute.Value = profile.user.username;
// userBlockedAccountNode.Attributes.Append(usernameBlockedAttribute);
// XmlAttribute passwordBlockedAttribute = xmlDocument.CreateAttribute("password");
// passwordAttribute.Value = profile.user.password;
// userBlockedAccountNode.Attributes.Append(passwordBlockedAttribute);
// XmlAttribute emailBlockedAttribute = xmlDocument.CreateAttribute("email");
// emailAttribute.Value = profile.user.email;
// userBlockedAccountNode.Attributes.Append(emailBlockedAttribute);
// XmlAttribute confirmationPasswordBlockedAttribute = xmlDocument.CreateAttribute("confirmationPassword");
// confirmationPasswordAttribute.Value = profile.user.confirmationPassword;
// userBlockedAccountNode.Attributes.Append(confirmationPasswordBlockedAttribute);
// }
// foreach (var member in group.groupMembers)
// {
// XmlNode userNode = xmlDocument.CreateElement("user");
// members.AppendChild(userNode);
// XmlAttribute userIdAttribute = xmlDocument.CreateAttribute("userId");
// userIdAttribute.Value = member.id.ToString();
// userNode.Attributes.Append(userIdAttribute);
// XmlAttribute usernameAttribute = xmlDocument.CreateAttribute("username");
// usernameAttribute.Value = member.username;
// userNode.Attributes.Append(usernameAttribute);
// XmlAttribute passwordAttribute = xmlDocument.CreateAttribute("password");
// passwordAttribute.Value = member.password;
// userNode.Attributes.Append(passwordAttribute);
// XmlAttribute emailAttribute = xmlDocument.CreateAttribute("email");
// emailAttribute.Value = member.email;
// userNode.Attributes.Append(emailAttribute);
// XmlAttribute confirmationPasswordAttribute = xmlDocument.CreateAttribute("confirmationPassword");
// confirmationPasswordAttribute.Value = member.confirmationPassword;
// userNode.Attributes.Append(confirmationPasswordAttribute);
// }
// }
// xmlDocument.Save(this.filePath);
}
public List<UserProfileSocialNetworkInfo> GetProfileRepositoryList()
{
return this.repositoryList;
}
public void SetProfileRepositoryList(List<UserProfileSocialNetworkInfo> newList)
{
this.repositoryList = newList;
}
public bool AddProfileSocialNetworkInfo(UserProfileSocialNetworkInfo profileToAdd)
{
foreach (var profile in this.GetProfileRepositoryList())
{
if ((profile?.User?.Id ?? new Guid()) == profileToAdd.User.Id)
{
return false;
}
}
this.repositoryList.Add(profileToAdd);
SaveProfilesInXML();
return true;
}
public bool RemoveProfileSocialNetworkInfo(UserProfileSocialNetworkInfo profileToRemove)
{
foreach (var profile in this.GetProfileRepositoryList())
{
if (profile.User.Id == profileToRemove.User.Id)
{
this.repositoryList.Remove(profile);
SaveProfilesInXML();
return true;
}
}
return false;
}
}
}
@@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml.Serialization;
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
namespace District_3_App.ProfileSocialNetworkInfoStuff.ProfileNetworkInfo_Repository
{
public class UsersRepository
{
public List<User> UsersRepositoryList { get; set; }
private string filePath;
public UsersRepository()
{
}
public UsersRepository(List<User> usersRepositoryList)
{
this.UsersRepositoryList = usersRepositoryList;
}
public UsersRepository(string filePath)
{
this.filePath = filePath;
LoadUsersFromXml();
}
private void LoadUsersFromXml()
{
try
{
UsersRepositoryList = new List<User>();
XDocument xDocument = XDocument.Load(filePath);
var users = xDocument.Descendants("User");
foreach (var user in users)
{
User newUser = new User
{
Id = (Guid)user.Attribute("id"),
Username = (string)user.Attribute("Username"),
Email = (string)user.Attribute("Email"),
Password = (string)user.Attribute("Password"),
ConfirmationPassword = (string)user.Attribute("ConfirmationPassword"),
FollowingCount = (int)user.Element("Following"),
FollowersCount = (int)user.Element("Followers")
};
UsersRepositoryList.Add(newUser);
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while loading users from XML: " + ex.Message);
}
}
private void SaveUsersToXml()
{
XDocument xDocument = new XDocument(
new XElement("UserAccounts",
UsersRepositoryList.Select(user =>
new XElement("User",
new XAttribute("id", user.Id),
new XAttribute("Username", user.Username),
new XAttribute("Email", user.Email),
new XAttribute("Password", user.Password),
new XAttribute("ConfirmationPassword", user.ConfirmationPassword),
new XElement("Following", user.FollowingCount),
new XElement("Followers", user.FollowersCount)))));
xDocument.Save(filePath);
}
public User GetUserByName(string username)
{
foreach (var user in UsersRepositoryList)
{
if (user.Username == username)
{
return user;
}
}
return null;
}
public List<User> GetAllUsers()
{
return UsersRepositoryList;
}
public void AddUser(User user)
{
UsersRepositoryList.Add(user);
SaveUsersToXml();
}
public int GetFollowersCount(string username)
{
User user = GetUserByName(username);
if (user != null)
{
return user.FollowersCount;
}
else
{
// Handle user not found scenario
return -1;
}
}
public int GetFollowingCount(string username)
{
User user = GetUserByName(username);
if (user != null)
{
return user.FollowingCount;
}
else
{
return -1;
}
}
public bool UpdatePassword(string email, string newPassword)
{
try
{
XElement root = XElement.Load(filePath);
IEnumerable<XElement> users = from user in root.Elements("User")
where (string)user.Attribute("Email") == email
select user;
if (users.Any())
{
foreach (XElement user in users)
{
user.SetAttributeValue("Password", newPassword);
}
root.Save(filePath);
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
Console.WriteLine("Error updating password: " + ex.Message);
return false;
}
}
public User GetUserByUsernameOrEmail(string usernameOrEmail)
{
return UsersRepositoryList.FirstOrDefault(user => user.Username == usernameOrEmail || user.Email == usernameOrEmail);
}
public bool UsernameExists(string username)
{
return UsersRepositoryList.Any(user => user.Username == username);
}
public bool EmailExists(string email)
{
return UsersRepositoryList.Any(user => user.Email == email);
}
}
}
@@ -0,0 +1,477 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
using District_3_App.ProfileSocialNetworkInfoStuff.ProfileNetworkInfo_Repository;
using District_3_App.ProfileSocialNetworkInfoStuff.Sorting_module;
namespace District_3_App.ProfileSocialNetworkInfoStuff.ProfileNetworkInfo_Service
{
public class ProfileNetworkInfoService
{
public ProfileNetworkInfoRepository<UserProfileSocialNetworkInfo> Repository { get; set; }
public GroupsRepository GroupsRepository { get; set; }
public UsersRepository UsersRepository { get; set; }
public User CurrentConnectedUser { get; set; }
public ProfileNetworkInfoService()
{
//// HARDCODED STUFF
}
public ProfileNetworkInfoService(GroupsRepository groupsRepository, ProfileNetworkInfoRepository<UserProfileSocialNetworkInfo> repository, UsersRepository usersRepository)
{
this.GroupsRepository = groupsRepository;
this.Repository = repository;
this.UsersRepository = usersRepository;
}
// delegate types: takes 2 BlockedProfile params and returns int using CompareTo function
public Func<BlockedProfile, BlockedProfile, int> CompareBlockedProfilesByDateValue = (profile1, profile2) => profile1.BlockDate.CompareTo(profile2.BlockDate);
public Func<CloseFriendProfile, CloseFriendProfile, int> CompareCloseFriendsByUsernameValue = (profile1, profile2) => profile1.User.CompareTo(profile2.User);
public Func<Group, Group, int> CompareGroupsByNameValue = (group1, group2) => group1.GroupName.CompareTo(group2.GroupName);
public Func<User, User, int> CompareUsersByUsername = (user1, user2) => user1.Username.CompareTo(user2.Username);
// public Func<LikedPost, LikedPost, int> compareLikedPostbyDate = (Post1, Post2) => Post1.date.CompareTo(Post2.date);
public Func<BlockedProfile, BlockedProfile, int> CompareBlockedProfilesByDate
{
get { return this.CompareBlockedProfilesByDateValue; }
}
public Func<CloseFriendProfile, CloseFriendProfile, int> CompareCloseFriendsByUsername
{
get { return this.CompareCloseFriendsByUsernameValue; }
}
public Func<Group, Group, int> CompareGroupsByName
{
get { return this.CompareGroupsByNameValue; }
}
public Func<User, User, int> CompareRestrictedUsersByUsername
{
get { return this.CompareUsersByUsername; }
}
// public Func<LikedPost, LikedPost, int> CompareLikedPostsByDate
// {
// get { return this.compareLikedPostbyDate; }
// }
public void QuickSortBlockedProfiles(Func<BlockedProfile, BlockedProfile, int> compareFunction)
{
if (this.Repository.GetProfileRepositoryList().Count > 0 && this.Repository.GetProfileRepositoryList() != null)
{
ISortingAlgorithms<BlockedProfile> sortingAlgorithms = new SortingAlgorithms<BlockedProfile>();
foreach (UserProfileSocialNetworkInfo profile in this.Repository.GetProfileRepositoryList())
{
sortingAlgorithms.QuickSortDescending(profile.BlockedProfiles, compareFunction);
}
}
}
public void QuickSortRestrictedPostsAudience(Func<User, User, int> compareFunction)
{
if (this.Repository.GetProfileRepositoryList().Count > 0 && this.Repository.GetProfileRepositoryList() != null)
{
ISortingAlgorithms<User> sortingAlgorithms = new SortingAlgorithms<User>();
foreach (UserProfileSocialNetworkInfo profile in this.Repository.GetProfileRepositoryList())
{
sortingAlgorithms.QuickSortAscending(profile.RestrictedPostsAudience, compareFunction);
}
}
}
public void QuickSortRestrictedStoriesAudience(Func<User, User, int> compareFunction)
{
if (this.Repository.GetProfileRepositoryList().Count > 0 && this.Repository.GetProfileRepositoryList() != null)
{
ISortingAlgorithms<User> sortingAlgorithms = new SortingAlgorithms<User>();
foreach (UserProfileSocialNetworkInfo profile in this.Repository.GetProfileRepositoryList())
{
sortingAlgorithms.QuickSortAscending(profile.RestrictedStoriesAudience, compareFunction);
}
}
}
public void QuickSortCloseFriends(Func<CloseFriendProfile, CloseFriendProfile, int> compareFunction)
{
if (this.Repository.GetProfileRepositoryList().Count > 0 && this.Repository.GetProfileRepositoryList() != null)
{
ISortingAlgorithms<CloseFriendProfile> sortingAlgorithms = new SortingAlgorithms<CloseFriendProfile>();
foreach (UserProfileSocialNetworkInfo profile in this.Repository.GetProfileRepositoryList())
{
sortingAlgorithms.QuickSortAscending(profile.CloseFriendsProfiles, compareFunction);
}
}
}
public void QuickSortGroups(Func<Group, Group, int> compareFunction)
{
if (this.Repository.GetProfileRepositoryList().Count > 0 && this.Repository.GetProfileRepositoryList() != null)
{
ISortingAlgorithms<Group> sortingAlgorithms = new SortingAlgorithms<Group>();
foreach (UserProfileSocialNetworkInfo profile in this.Repository.GetProfileRepositoryList())
{
sortingAlgorithms.QuickSortAscending(profile.Groups, compareFunction);
}
}
}
public bool CheckIfProfileExists(UserProfileSocialNetworkInfo profileToCheck)
{
foreach (var profile in this.GetAllUserProfileSocialNetworks())
{
if (profile.User.Id == profileToCheck.User.Id)
{
return true;
}
}
return false;
}
public List<UserProfileSocialNetworkInfo> GetAllUserProfileSocialNetworks()
{
return this.Repository.GetProfileRepositoryList();
}
public UserProfileSocialNetworkInfo GetProfileSocialNetworkInfoCurrentUser(User currentUser)
{
foreach (var profile in this.GetAllUserProfileSocialNetworks())
{
if (profile.User.Username == currentUser.Username)
{
return profile;
}
}
return null;
}
public bool AddProfileSocialNetworkInfo(UserProfileSocialNetworkInfo profileToAdd)
{
return this.Repository.AddProfileSocialNetworkInfo(profileToAdd);
}
public bool RemoveProfileSocialNetworkInfo(UserProfileSocialNetworkInfo profileToRemove)
{
return this.Repository.RemoveProfileSocialNetworkInfo(profileToRemove);
}
// add / remove group
public bool AddGroupToCurrentUser(UserProfileSocialNetworkInfo currentUser, Group groupToAdd)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var group in currentUser.Groups)
{
if (group == groupToAdd)
{
return false;
}
}
currentUser.Groups.Add(groupToAdd);
SaveDataIntoXML();
return true;
}
return false;
}
public bool RemoveGroupFromCurrentUser(UserProfileSocialNetworkInfo currentUser, Group groupToRemove)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var group in currentUser.Groups)
{
if (group.GroupName == groupToRemove.GroupName)
{
currentUser.Groups.Remove(group);
SaveDataIntoXML();
return true;
}
}
}
return false;
}
// add / remove close friend
public bool AddCloseFriendToCurrentUser(UserProfileSocialNetworkInfo currentUser, CloseFriendProfile closeFriendToAdd)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var closeFriend in currentUser.CloseFriendsProfiles)
{
if (closeFriend == closeFriendToAdd)
{
return false;
}
}
currentUser.CloseFriendsProfiles.Add(closeFriendToAdd);
SaveDataIntoXML();
return true;
}
return false;
}
public bool RemoveCloseFriendFromCurrentUser(UserProfileSocialNetworkInfo currentUser, CloseFriendProfile closeFriendToRemove)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var closeFriend in currentUser.CloseFriendsProfiles)
{
if (closeFriend.User.Id == closeFriendToRemove.User.Id)
{
currentUser.CloseFriendsProfiles.Remove(closeFriend);
SaveDataIntoXML();
return true;
}
}
}
return false;
}
// add / remove blocked profile
public bool AddBlockedProfileToCurrentUser(UserProfileSocialNetworkInfo currentUser, BlockedProfile blockedProfileToAdd)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var blockedProfile in currentUser.BlockedProfiles)
{
if (blockedProfile.User.Id == blockedProfileToAdd.User.Id)
{
return false;
}
}
currentUser.BlockedProfiles.Add(blockedProfileToAdd);
SaveDataIntoXML();
return true;
}
return false;
}
public bool RemoveBlockedProfileFromCurrentUser(UserProfileSocialNetworkInfo currentUser, BlockedProfile blockedProfileToRemove)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var blockedProfile in currentUser.BlockedProfiles)
{
if (blockedProfile.User.Id == blockedProfileToRemove.User.Id)
{
currentUser.BlockedProfiles.Remove(blockedProfile);
SaveDataIntoXML();
return true;
}
}
}
return false;
}
// add / remove Restricted posts
public bool AddRestrictedPostsAudienceUserToCurrentUser(UserProfileSocialNetworkInfo currentUser, User userToAdd)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var restrictedUser in currentUser.RestrictedPostsAudience)
{
if (restrictedUser == userToAdd)
{
return false;
}
}
currentUser.RestrictedPostsAudience.Add(userToAdd);
SaveDataIntoXML();
return true;
}
return false;
}
public bool RemoveRestrictedPostsAudienceUserFromCurrentUser(UserProfileSocialNetworkInfo currentUser, User userToRemove)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var restrictedUser in currentUser.RestrictedPostsAudience)
{
if (restrictedUser.Username == userToRemove.Username)
{
currentUser.RestrictedPostsAudience.Remove(restrictedUser);
SaveDataIntoXML();
return true;
}
}
}
return false;
}
// add / remove Restricted stories
public bool AddRestrictedStoriesAudienceUserToCurrentUser(UserProfileSocialNetworkInfo currentUser, User userToAdd)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var restrictedUser in currentUser.RestrictedStoriesAudience)
{
if (restrictedUser == userToAdd)
{
return false;
}
}
currentUser.RestrictedStoriesAudience.Add(userToAdd);
SaveDataIntoXML();
return true;
}
return false;
}
public bool RemoveRestrictedStoriesAudienceUserFromCurrentUser(UserProfileSocialNetworkInfo currentUser, User userToRemove)
{
if (this.CheckIfProfileExists(currentUser))
{
foreach (var restrictedUser in currentUser.RestrictedStoriesAudience)
{
if (restrictedUser.Username == userToRemove.Username)
{
currentUser.RestrictedStoriesAudience.Remove(restrictedUser);
SaveDataIntoXML();
return true;
}
}
}
return false;
}
public List<Group> GetAllGroupsService()
{
return this.GroupsRepository.GetAllGroups();
}
public Group GetGroupByName(string name)
{
return this.GroupsRepository.GetGroupByGroupName(name);
}
public bool CreateGroupToRepository(string groupName, List<User> groupMembers)
{
Group groupToAdd = new Group(Guid.NewGuid(), groupName, groupMembers);
return GroupsRepository.AddGroup(groupToAdd);
}
public bool DeleteGroupFromRepository(string groupName)
{
if (GroupsRepository.GetGroupByGroupName(groupName) == null)
{
return false;
}
GroupsRepository.RemoveGroup(GroupsRepository.GetGroupByGroupName(groupName));
return true;
}
public bool AddMemberToGroup(string groupName, User user)
{
return GroupsRepository.AddMemberToGroup(groupName, user);
}
public bool RemoveMemberFromGroup(string groupName, User user)
{
return GroupsRepository.RemoveMemberFromGroup(groupName, user);
}
public void AddMemberToGroupProfile(UserProfileSocialNetworkInfo profile, string groupName, string username)
{
foreach (var gr in profile.Groups)
{
if (gr.GroupName == groupName)
{
foreach (var user in GetAllUsers())
{
if (user.Username == username)
{
gr.GroupMembers.Add(user);
}
}
}
}
}
//// USERS REPOSITORY
///
public User GetUserByName(string username)
{
return UsersRepository.GetUserByName(username);
}
public List<User> GetAllUsers()
{
return UsersRepository.GetAllUsers();
}
public UserProfileSocialNetworkInfo GetProfileSocialNetworkInfoByUser(string username)
{
foreach (User user in UsersRepository.GetAllUsers())
{
if (user.Username == username)
{
foreach (var profile in Repository.GetProfileRepositoryList())
{
if (profile.User.Username == username)
{
return profile;
}
}
}
}
return null;
}
public BlockedProfile GetBlockedProfileByName(UserProfileSocialNetworkInfo profile, string username)
{
foreach (var blockedProfile in profile.BlockedProfiles)
{
if (blockedProfile.User.Username == username)
{
return blockedProfile;
}
}
return null;
}
public CloseFriendProfile GetCloseFriendByName(UserProfileSocialNetworkInfo profile, string username)
{
foreach (var closeFriend in profile.CloseFriendsProfiles)
{
if (closeFriend.User.Username == username)
{
return closeFriend;
}
}
return null;
}
public void SwitchAccountPrivacyPublicPrivate(User currentConnectedUser)
{
UserProfileSocialNetworkInfo profile = GetProfileSocialNetworkInfoByUser(currentConnectedUser.Username);
profile.IsProfilePrivate = !profile.IsProfilePrivate;
SaveDataIntoXML();
}
public void SaveDataIntoXML()
{
this.Repository.SaveProfilesInXML();
}
}
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace District_3_App.ProfileSocialNetworkInfoStuff.Sorting_module
{
public interface ISortingAlgorithms<T>
{
void BubbleSortAscending(List<T> list, Func<T, T, int> compare);
void BubbleSortDescending(List<T> list, Func<T, T, int> compare);
void MergeSortAscending(List<T> domainList, Func<T, T, int> compare);
void MergeSortDescending(List<T> domainList, Func<T, T, int> compare);
void GnomeSortAscending(List<T> domainList, Func<T, T, int> compare);
void GnomeSortDescending(List<T> domainList, Func<T, T, int> compare);
void QuickSortAscending(List<T> domainList, Func<T, T, int> compare);
void QuickSortDescending(List<T> domainList, Func<T, T, int> compare);
}
}
@@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace District_3_App.ProfileSocialNetworkInfoStuff.Sorting_module
{
public class SortingAlgorithms<T> : ISortingAlgorithms<T>
where T : IComparable<T>
{
public SortingAlgorithms()
{
}
public void BubbleSortAscending(List<T> list, Func<T, T, int> compare)
{
bool swapped = false;
int numberOfElements = list.Count;
while (swapped != true)
{
swapped = true;
for (int index = 0; index < numberOfElements - 1; index++)
{
if (list[index].CompareTo(list[index + 1]) > 0)
{
T temporary = list[index];
list[index] = list[index + 1];
list[index + 1] = temporary;
swapped = false;
}
}
}
}
public void BubbleSortDescending(List<T> list, Func<T, T, int> compare)
{
bool swapped = false;
int numberOfElements = list.Count;
while (swapped != true)
{
swapped = true;
for (int index = 0; index < numberOfElements - 1; index++)
{
if (list[index].CompareTo(list[index + 1]) < 0)
{
T temporary = list[index];
list[index] = list[index + 1];
list[index + 1] = temporary;
swapped = false;
}
}
}
}
private void MergeLists(List<T> domainList, int left, int middle, int right, Func<T, T, int> compare, bool sortingTypes)
{
var leftListLength = middle - left + 1;
var rightListLength = right - middle;
var leftTemporaryList = new List<T>();
var rightTemporaryList = new List<T>();
int i, j;
for (i = 0; i < leftListLength; i++)
{
leftTemporaryList.Add(domainList[left + i]);
}
for (j = 0; j < rightListLength; j++)
{
rightTemporaryList.Add(domainList[middle + 1 + j]);
}
i = 0;
j = 0;
int k = left;
while (i < leftListLength && j < rightListLength)
{
if (sortingTypes)
{
if (compare(leftTemporaryList[i], rightTemporaryList[j]) <= 0)
{
domainList[k++] = leftTemporaryList[i++];
}
else
{
domainList[k++] = rightTemporaryList[j++];
}
}
else
if (compare(leftTemporaryList[i], rightTemporaryList[j]) >= 0)
{
domainList[k++] = leftTemporaryList[i++];
}
else
{
domainList[k++] = rightTemporaryList[j++];
}
}
while (i < leftListLength)
{
domainList[k++] = leftTemporaryList[i++];
}
while (j < rightListLength)
{
domainList[k++] = rightTemporaryList[j++];
}
}
private void RecursiveMergeSort(List<T> domainList, int left, int right, Func<T, T, int> compare, bool sortingType)
{
if (left < right)
{
int middle = (left + right) / 2;
RecursiveMergeSort(domainList, left, middle, compare, sortingType);
RecursiveMergeSort(domainList, middle + 1, right, compare, sortingType);
MergeLists(domainList, left, middle, right, compare, sortingType);
}
}
public void MergeSortAscending(List<T> domainList, Func<T, T, int> compare)
{
// List<DomainObject> temporaryList = new List<DomainObject>(domainList.Count);
RecursiveMergeSort(domainList, 0, domainList.Count - 1, compare, true);
}
public void MergeSortDescending(List<T> domainList, Func<T, T, int> compare)
{
RecursiveMergeSort(domainList, 0, domainList.Count - 1, compare, false);
}
public void GnomeSortAscending(List<T> domainList, Func<T, T, int> compare)
{
int index = 0;
while (index < domainList.Count)
{
if (index == 0 || compare(domainList[index], domainList[index - 1]) >= 0)
{
index++;
}
else
{
T temporaryObject = domainList[index];
domainList[index] = domainList[index - 1];
domainList[index - 1] = temporaryObject;
index--;
}
}
}
public void GnomeSortDescending(List<T> domainList, Func<T, T, int> compare)
{
int index = 0;
while (index < domainList.Count)
{
if (index == 0 || compare(domainList[index], domainList[index - 1]) <= 0)
{
index++;
}
else
{
T temporaryObject = domainList[index];
domainList[index] = domainList[index - 1];
domainList[index - 1] = temporaryObject;
index--;
}
}
}
public void QuickSortAscending(List<T> domainList, Func<T, T, int> compare)
{
domainList = QuickSort(domainList, 0, domainList.Count - 1, compare, true); // ascending
}
public void QuickSortDescending(List<T> domainList, Func<T, T, int> compare)
{
domainList = QuickSort(domainList, 0, domainList.Count - 1, compare, false); // ascending
}
private List<T> QuickSort(List<T> domainList, int leftIndex, int rightIndex, Func<T, T, int> compare, bool sortingType)
{
int index_1 = leftIndex;
int index_2 = rightIndex;
T pivot = domainList[leftIndex];
while (index_1 <= index_2)
{
if (sortingType)
{
while (compare(domainList[index_1], pivot) < 0)
{
index_1++;
}
while (compare(domainList[index_2], pivot) > 0)
{
index_2--;
}
}
else
{
while (compare(domainList[index_1], pivot) > 0)
{
index_1++;
}
while (compare(domainList[index_2], pivot) < 0)
{
index_2--;
}
}
if (index_1 <= index_2)
{
T temp = domainList[index_1];
domainList[index_1] = domainList[index_2];
domainList[index_2] = temp;
index_1++;
index_2--;
}
}
if (leftIndex < index_2)
{
QuickSort(domainList, leftIndex, index_2, compare, sortingType);
}
if (index_1 < rightIndex)
{
QuickSort(domainList, index_1, rightIndex, compare, sortingType);
}
return domainList;
}
}
}