Exemplo n.º 1
0
        public FormMain()
        {
            InitializeComponent();

            using (FormUserSelection formUserSelection = new FormUserSelection()) {
                formUserSelection.ShowDialog(this);

                if (formUserSelection.DialogResult == DialogResult.OK) {
                    this.userProfiles = formUserSelection.userProfiles;
                    this.currentUser = formUserSelection.selectedUser;
                    this.selectedUser = true;

                    this.dataManager = new DataManager(currentUser);
                    this.entityManager = new EntityManager(currentUser);

                    this.currentUser.applicationSettingsField = dataManager.ReadUserSettingsFile(this.currentUser);

                    if (this.currentUser.applicationSettingsField.DefaultsRestored) {
                        dataManager.SaveUserSettings();

                        this.currentUser.applicationSettingsField.DefaultsRestored = false;
                    }
                }
            }
        }
 public FormEconomy(HTEntities.Economy.Economy economy, HTEntities.WorldDetails.League league, User user)
 {
     InitializeComponent();
     this.economy = economy;
     this.user = user;
     LoadControls();
 }
Exemplo n.º 3
0
 public FormClub(Club club, User user)
 {
     InitializeComponent();
     this.club = club;
     this.user = user;
     LoadClubData();
 }
Exemplo n.º 4
0
 public FormArena(HTEntities.ArenaDetails arenaDetails, HMEntities.User user)
 {
     this.arenaDetails = arenaDetails;
     this.user = user;
     InitializeComponent();
     LoadControls();
 }
Exemplo n.º 5
0
 public FormArena(HTEntities.ArenaDetails arenaDetails, HMEntities.User user)
 {
     this.arenaDetails = arenaDetails;
     this.user         = user;
     InitializeComponent();
     LoadControls();
 }
Exemplo n.º 6
0
        public FormMain()
        {
            InitializeComponent();

            using (FormUserSelection formUserSelection = new FormUserSelection()) {
                formUserSelection.ShowDialog(this);

                if (formUserSelection.DialogResult == DialogResult.OK)
                {
                    this.userProfiles = formUserSelection.userProfiles;
                    this.currentUser  = formUserSelection.selectedUser;
                    this.selectedUser = true;

                    this.dataManager   = new DataManager(currentUser);
                    this.entityManager = new EntityManager(currentUser);

                    this.currentUser.applicationSettingsField = dataManager.ReadUserSettingsFile(this.currentUser);

                    if (this.currentUser.applicationSettingsField.DefaultsRestored)
                    {
                        dataManager.SaveUserSettings();

                        this.currentUser.applicationSettingsField.DefaultsRestored = false;
                    }
                }
            }
        }
        /// <summary>
        /// Gets the user's league
        /// </summary>
        /// <param name="user">User</param>
        /// <returns>League object</returns>
        private static HTEntities.WorldDetails.League GetLeague(User user)
        {
            EntityManager entityManager = new EntityManager(user);

            HTEntities.WorldDetails.WorldDetails worldDetails = entityManager.GetWorldDetails();
            HTEntities.TeamDetails.TeamDetails teamDetails = entityManager.GetTeamDetails();
            uint leagueId = teamDetails.teamField.leagueField.leagueIdField;
            return worldDetails.leagueListField.Single(l => l.leagueIdField == leagueId);
        }
Exemplo n.º 8
0
 public void CopyData(User source)
 {
     this.accessToken = source.accessToken;
     this.accessTokenSecret = source.accessTokenSecret;
     this.dataFolderField = source.dataFolderField;
     this.youthTeamIdField = source.youthTeamIdField;
     this.username = source.username;
     this.applicationSettingsField = source.applicationSettingsField;
 }
        public PlayerList(User user)
        {
            InitializeComponent();

            this.user = user;

            if (user != null) {
                this.entityManager = new EntityManager(user);
                this.dataManager = new DataManager(user);
                this.entityInterface = new Entities.EntityInterface(user);
                this.players = entityManager.GetPlayersDetails();
            }
        }
        public static void SaveUser(HMEntities.UserProfiles.User user)
        {
            HMDal.DataManager dataManager = new HMDal.DataManager();

            HMEntities.UserProfiles.UserProfiles userProfiles = dataManager.LoadUserProfiles();
            List <HMEntities.UserProfiles.User>  userList     = userProfiles.userListField;

            int index = userList.FindIndex(p => p.teamIdField == user.teamIdField);

            if (index == -1)
            {
                // If profile with this TeamId does not exist, add it...
                userList.Add(user);
            }
            else
            {
                // ... otherwise, update its data
                userList[index].CopyData(user);
            }

            dataManager.SaveUserProfiles(userProfiles);
        }
 /// <summary>
 /// Creates EntityManager for given user.
 /// </summary>
 /// <param name="user">User profile</param>
 public EntityManager(User user)
 {
     this.user = user;
     dataManager = new DataManager(user);
 }
        /// <summary>
        /// Converts given amount to user's local currency.
        /// </summary>
        /// <param name="club">User</param>
        /// <param name="amount">Amount to convert</param>
        /// <returns>Amount in user's local currency</returns>
        public static string Convert(User user, int amount)
        {
            HTEntities.WorldDetails.League userLeague = GetLeague(user);

            return string.Format(General.Money, (amount / userLeague.countryField.currencyRateField).ToString(General.NoDecimalFormat), userLeague.countryField.currencyNameField);
        }
 /// <summary>
 /// Creates EntityInterface for given user.
 /// </summary>
 /// <param name="user">User profile</param>
 public EntityInterface(User user)
 {
     this.user = user;
 }
Exemplo n.º 14
0
        private void WriteInternalPlayerFile(HTEntities.Players.Internal.PlayersInternal players, HMEntities.UserProfiles.User hattrickUser)
        {
            try {
                XmlDocument xmlDocument = new XmlDocument();

                XmlElement xmlElementRoot = xmlDocument.CreateElement(Tags.PlayerData);

                xmlElementRoot.AppendChild(xmlDocument.CreateElement(Tags.SavedDate)).InnerText = DateTime.Now.ToString(General.DateTimeFormat);

                // Categories
                XmlElement xmlElementCategoryList = xmlDocument.CreateElement(Tags.PlayerCategories);

                foreach (HTEntities.Players.Internal.PlayerCategories playerCategory in players.playerCategories)
                {
                    XmlElement xmlElementPlayer = xmlDocument.CreateElement(Tags.Player);

                    XmlElement xmlElementPlayerID = xmlDocument.CreateElement(Tags.PlayerID);
                    xmlElementPlayerID.InnerText = playerCategory.PlayerIDField.ToString();

                    XmlElement xmlElementPlayerCategory = xmlDocument.CreateElement(Tags.PlayerCategoryId);
                    xmlElementPlayerCategory.InnerText = playerCategory.PlayerCategoryField.ToString();

                    xmlElementPlayer.AppendChild(xmlElementPlayerID);
                    xmlElementPlayer.AppendChild(xmlElementPlayerCategory);

                    xmlElementCategoryList.AppendChild(xmlElementPlayer);
                }

                xmlElementRoot.AppendChild(xmlElementCategoryList);

                xmlDocument.AppendChild(xmlElementRoot);

                string path = System.IO.Path.Combine(hattrickUser.dataFolderField, hattrickUser.teamIdField.ToString());
                path = System.IO.Path.Combine(path, FolderNames.PlayerInternals);

                string fileName = Path.Combine(path, FileNames.PlayerData);

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                xmlDocument.Save(fileName);
            } catch (Exception ex) {
                throw ex;
            }
        }
Exemplo n.º 15
0
        private void WriteUserSettingsFile(HMEntities.UserProfiles.User hattrickUser)
        {
            try {
                HMEntities.Settings.HattrickSettings hattrickManagerSettings = hattrickUser.applicationSettingsField;
                XmlDocument xmlDocument = new XmlDocument();

                XmlElement xmlElementRoot = xmlDocument.CreateElement(Tags.HattrickManagerSettings);

                hattrickManagerSettings.savedDateField = DateTime.Now;

                xmlElementRoot.AppendChild(xmlDocument.CreateElement(Tags.SavedDate)).InnerText = hattrickManagerSettings.savedDateField.ToString(General.DateTimeFormat);


                // Categories
                XmlElement xmlElementCategoryList = xmlDocument.CreateElement(Tags.CategoryList);
                xmlElementCategoryList.SetAttribute(Tags.Version, hattrickManagerSettings.categoryVersionIDField.ToString());

                foreach (HMEntities.Settings.Category currentCategory in hattrickManagerSettings.playerCategoryListField)
                {
                    XmlElement xmlElementCategoryName      = xmlDocument.CreateElement(Tags.CategoryName);
                    XmlElement xmlElementCategoryColour    = xmlDocument.CreateElement(Tags.CategoryColour);
                    XmlElement xmlElementCategoryChecked   = xmlDocument.CreateElement(Tags.CategoryChecked);
                    XmlElement xmlElementCategoryProtected = xmlDocument.CreateElement(Tags.CategoryProtected);

                    xmlElementCategoryName.InnerText      = currentCategory.categoryNameField;
                    xmlElementCategoryColour.InnerText    = currentCategory.categoryColourField.ToString();
                    xmlElementCategoryChecked.InnerText   = currentCategory.categoryCheckedField.ToString();
                    xmlElementCategoryProtected.InnerText = currentCategory.categoryProtectedField.ToString();

                    XmlElement xmlCategory = xmlDocument.CreateElement(Tags.Category);

                    xmlCategory.SetAttribute(Tags.CategoryID, currentCategory.categoryIdField.ToString());

                    xmlCategory.AppendChild(xmlElementCategoryName);
                    xmlCategory.AppendChild(xmlElementCategoryColour);
                    xmlCategory.AppendChild(xmlElementCategoryChecked);
                    xmlCategory.AppendChild(xmlElementCategoryProtected);

                    xmlElementCategoryList.AppendChild(xmlCategory);
                }

                xmlElementRoot.AppendChild(xmlElementCategoryList);


                // Positions
                XmlElement xmlElementPositionList = xmlDocument.CreateElement(Tags.PositionList);
                xmlElementPositionList.SetAttribute(Tags.Version, hattrickManagerSettings.positionsVersionIDField.ToString());

                foreach (HMEntities.Settings.Position currentPosition in hattrickManagerSettings.playerPositionsListField)
                {
                    XmlElement xmlElementPositionWeights = xmlDocument.CreateElement(Tags.PositionWeightList);

                    xmlElementPositionWeights.SetAttribute(Tags.PositionID, ((int)currentPosition.positionID).ToString());

                    foreach (HM.Resources.PlayerSkillTypes skill in currentPosition.positionWeights.Keys)
                    {
                        XmlElement xmlElementWeight = xmlDocument.CreateElement(Tags.PositionWeight);

                        xmlElementWeight.SetAttribute(Tags.PositionWeightName, ((int)skill).ToString());
                        xmlElementWeight.InnerText = currentPosition.positionWeights[skill].ToString();

                        xmlElementPositionWeights.AppendChild(xmlElementWeight);
                    }

                    xmlElementPositionList.AppendChild(xmlElementPositionWeights);
                }

                xmlElementRoot.AppendChild(xmlElementPositionList);


                // Columns
                XmlElement xmlElementColumnTables = xmlDocument.CreateElement(Tags.ColumnTables);
                xmlElementColumnTables.SetAttribute(Tags.Version, hattrickManagerSettings.tableColumsVersionIDField.ToString());

                foreach (HM.Resources.ColumnTables tblKey in hattrickManagerSettings.tableColumsListField.Keys)
                {
                    List <HM.Entities.HattrickManager.Settings.Column> tablesColumns = hattrickManagerSettings.tableColumsListField[tblKey];
                    XmlElement xmlElementColumnList = xmlDocument.CreateElement(Tags.ColumnList);

                    xmlElementColumnList.SetAttribute(Tags.ColumnTableID, ((int)tblKey).ToString());

                    foreach (HMEntities.Settings.Column currentColumn in tablesColumns)
                    {
                        XmlElement xmlElementColumnID           = xmlDocument.CreateElement(Tags.ColumnID);
                        XmlElement xmlElementColumnTitle        = xmlDocument.CreateElement(Tags.ColumnTitle);
                        XmlElement xmlElementColumnWidth        = xmlDocument.CreateElement(Tags.ColumnWidth);
                        XmlElement xmlElementColumnType         = xmlDocument.CreateElement(Tags.ColumnDisplayType);
                        XmlElement xmlElementColumnAlignment    = xmlDocument.CreateElement(Tags.ColumnAlignment);
                        XmlElement xmlElementColumnDisplay      = xmlDocument.CreateElement(Tags.ColumnDisplay);
                        XmlElement xmlElementColumnDisplayIndex = xmlDocument.CreateElement(Tags.ColumnDisplayIndex);
                        XmlElement xmlElementColumnSorted       = xmlDocument.CreateElement(Tags.ColumnSortColumn);

                        xmlElementColumnID.InnerText           = currentColumn.columnIDField.ToString();
                        xmlElementColumnTitle.InnerText        = currentColumn.titleField;
                        xmlElementColumnWidth.InnerText        = currentColumn.widthField.ToString();
                        xmlElementColumnType.InnerText         = ((int)currentColumn.displayTypeField).ToString();
                        xmlElementColumnAlignment.InnerText    = ((int)currentColumn.alignmentField).ToString();
                        xmlElementColumnDisplay.InnerText      = currentColumn.displayColumnField.ToString();
                        xmlElementColumnDisplayIndex.InnerText = currentColumn.displayIndex.ToString();
                        xmlElementColumnSorted.InnerText       = currentColumn.sortedColumnField.ToString();

                        XmlElement xmlColumn = xmlDocument.CreateElement(Tags.Column);

                        xmlColumn.AppendChild(xmlElementColumnID);
                        xmlColumn.AppendChild(xmlElementColumnTitle);
                        xmlColumn.AppendChild(xmlElementColumnWidth);
                        xmlColumn.AppendChild(xmlElementColumnType);
                        xmlColumn.AppendChild(xmlElementColumnAlignment);
                        xmlColumn.AppendChild(xmlElementColumnDisplay);
                        xmlColumn.AppendChild(xmlElementColumnDisplayIndex);
                        xmlColumn.AppendChild(xmlElementColumnSorted);

                        xmlElementColumnList.AppendChild(xmlColumn);
                    }

                    xmlElementColumnTables.AppendChild(xmlElementColumnList);
                }

                xmlElementRoot.AppendChild(xmlElementColumnTables);


                // Last Files
                XmlElement xmlElementLastFilesList = xmlDocument.CreateElement(Tags.LastFileList);

                foreach (HMEntities.Settings.LastFiles currentFile in hattrickManagerSettings.lastFileListField)
                {
                    XmlElement xmlElementFileName = xmlDocument.CreateElement(Tags.LastFileName);
                    XmlElement xmlElementFileType = xmlDocument.CreateElement(Tags.LastFileType);
                    XmlElement xmlElementFileDate = xmlDocument.CreateElement(Tags.LastFileDate);

                    xmlElementFileName.InnerText = currentFile.fileNameField;
                    xmlElementFileType.InnerText = ((int)currentFile.fileTypeField).ToString();
                    xmlElementFileDate.InnerText = currentFile.dateField;

                    XmlElement xmlFile = xmlDocument.CreateElement(Tags.File);

                    xmlFile.AppendChild(xmlElementFileName);
                    xmlFile.AppendChild(xmlElementFileType);
                    xmlFile.AppendChild(xmlElementFileDate);

                    xmlElementLastFilesList.AppendChild(xmlFile);
                }

                xmlElementRoot.AppendChild(xmlElementLastFilesList);

                xmlDocument.AppendChild(xmlElementRoot);

                string path = System.IO.Path.Combine(hattrickUser.dataFolderField, hattrickUser.teamIdField.ToString());
                path = System.IO.Path.Combine(path, FolderNames.UserSettings);

                string fileName = Path.Combine(path, FileNames.UserSettings);

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                xmlDocument.Save(fileName);
            } catch (Exception ex) {
                throw ex;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Reads UserProfile xml file
        /// </summary>
        /// <param name="xmlStream">Xml file content</param>
        /// <returns>UserProfiles object loaded with readed data</returns>
        public HMEntities.UserProfiles.UserProfiles ReadUserProfilesFile(Stream xmlStream)
        {
            try {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(xmlStream);

                HMEntities.UserProfiles.UserProfiles hattrickManagerData = new HM.Entities.HattrickManager.UserProfiles.UserProfiles();

                if (xmlDocument.DocumentElement.ChildNodes != null)
                {
                    foreach (XmlNode xmlNodeRoot in xmlDocument.DocumentElement.ChildNodes)
                    {
                        switch (xmlNodeRoot.Name)
                        {
                        case Tags.SavedDate: {
                            hattrickManagerData.savedDateField = GenericFunctions.ConvertStringToDateTime(xmlNodeRoot.InnerText);
                            break;
                        }

                        case Tags.UserList: {
                            if (xmlNodeRoot.ChildNodes != null)
                            {
                                foreach (XmlNode xmlNodeUserList in xmlNodeRoot.ChildNodes)
                                {
                                    if (xmlNodeUserList.ChildNodes != null)
                                    {
                                        HMEntities.UserProfiles.User hattrickManagerDataUser = new HM.Entities.HattrickManager.UserProfiles.User();

                                        foreach (XmlNode xmlNodeUser in xmlNodeUserList)
                                        {
                                            switch (xmlNodeUser.Name)
                                            {
                                            case Tags.TeamID: {
                                                hattrickManagerDataUser.teamIdField = GenericFunctions.ConvertStringToUInt(xmlNodeUser.InnerText);
                                                break;
                                            }

                                            case Tags.YouthTeamID: {
                                                hattrickManagerDataUser.youthTeamIdField = GenericFunctions.ConvertStringToUInt(xmlNodeUser.InnerText);
                                                break;
                                            }

                                            case Tags.Loginname: {
                                                hattrickManagerDataUser.username = xmlNodeUser.InnerText;
                                                break;
                                            }

                                            case Tags.UserToken: {
                                                hattrickManagerDataUser.accessToken = xmlNodeUser.InnerText;
                                                break;
                                            }

                                            case Tags.UserTokenSecret: {
                                                hattrickManagerDataUser.accessTokenSecret = xmlNodeUser.InnerText;
                                                break;
                                            }

                                            case Tags.ActivationDate: {
                                                hattrickManagerDataUser.activationDateField = GenericFunctions.ConvertStringToDateTime(xmlNodeUser.InnerText);
                                                break;
                                            }

                                            case Tags.DataFolder: {
                                                hattrickManagerDataUser.dataFolderField = xmlNodeUser.InnerText;
                                                break;
                                            }
                                            }
                                        }

                                        hattrickManagerData.userListField.Add(hattrickManagerDataUser);
                                    }
                                }
                            }
                            break;
                        }
                        }
                    }
                }
                xmlStream.Close();
                return(hattrickManagerData);
            } catch (Exception ex) {
                throw ex;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Reads UserProfile xml file
        /// </summary>
        /// <param name="xmlStream">Xml file content</param>
        /// <returns>UserProfiles object loaded with readed data</returns>
        public HMEntities.UserProfiles.UserProfiles ReadUserProfilesFile(Stream xmlStream)
        {
            try {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(xmlStream);

                HMEntities.UserProfiles.UserProfiles hattrickManagerData = new HM.Entities.HattrickManager.UserProfiles.UserProfiles();

                if (xmlDocument.DocumentElement.ChildNodes != null) {
                    foreach (XmlNode xmlNodeRoot in xmlDocument.DocumentElement.ChildNodes) {
                        switch (xmlNodeRoot.Name) {
                            case Tags.SavedDate: {
                                    hattrickManagerData.savedDateField = GenericFunctions.ConvertStringToDateTime(xmlNodeRoot.InnerText);
                                    break;
                                }
                            case Tags.UserList: {
                                    if (xmlNodeRoot.ChildNodes != null) {
                                        foreach (XmlNode xmlNodeUserList in xmlNodeRoot.ChildNodes) {
                                            if (xmlNodeUserList.ChildNodes != null) {
                                                HMEntities.UserProfiles.User hattrickManagerDataUser = new HM.Entities.HattrickManager.UserProfiles.User();

                                                foreach (XmlNode xmlNodeUser in xmlNodeUserList) {
                                                    switch (xmlNodeUser.Name) {
                                                        case Tags.TeamID: {
                                                                hattrickManagerDataUser.teamIdField = GenericFunctions.ConvertStringToUInt(xmlNodeUser.InnerText);
                                                                break;
                                                            }
                                                        case Tags.YouthTeamID: {
                                                                hattrickManagerDataUser.youthTeamIdField = GenericFunctions.ConvertStringToUInt(xmlNodeUser.InnerText);
                                                                break;
                                                            }
                                                        case Tags.Loginname: {
                                                                hattrickManagerDataUser.username = xmlNodeUser.InnerText;
                                                                break;
                                                            }
                                                        case Tags.UserToken: {
                                                                hattrickManagerDataUser.accessToken = xmlNodeUser.InnerText;
                                                                break;
                                                            }
                                                        case Tags.UserTokenSecret: {
                                                                hattrickManagerDataUser.accessTokenSecret = xmlNodeUser.InnerText;
                                                                break;
                                                            }
                                                        case Tags.ActivationDate: {
                                                                hattrickManagerDataUser.activationDateField = GenericFunctions.ConvertStringToDateTime(xmlNodeUser.InnerText);
                                                                break;
                                                            }
                                                        case Tags.DataFolder: {
                                                                hattrickManagerDataUser.dataFolderField = xmlNodeUser.InnerText;
                                                                break;
                                                            }
                                                    }
                                                }

                                                hattrickManagerData.userListField.Add(hattrickManagerDataUser);
                                            }
                                        }
                                    }
                                    break;
                                }
                        }
                    }
                }
                xmlStream.Close();
                return hattrickManagerData;
            } catch (Exception ex) {
                throw ex;
            }
        }
Exemplo n.º 18
0
 public void SaveUserSettings(User currentUser)
 {
     WriteUserSettingsFile(currentUser);
 }
Exemplo n.º 19
0
        /// <summary>
        /// Saves Matches XML from stream to disk.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="xmlData"></param>
        public void SaveMatches(User user, string xmlData)
        {
            string folderPath = System.IO.Path.Combine(System.IO.Path.Combine(user.dataFolderField, user.teamIdField.ToString()), FolderNames.Matches);
            string fileName = FileNames.Matches;

            SaveXml(xmlData, folderPath, fileName);
        }
Exemplo n.º 20
0
 public void SaveInternalPlayers(HTEntities.Players.Internal.PlayersInternal players, User currentUser)
 {
     WriteInternalPlayerFile(players, currentUser);
 }