/// <summary>
        /// Writes the UserProfiles to disk
        /// </summary>
        /// <param name="hattrickManagerData">UserProfiles to write</param>
        private void WriteUserProfilesFile(HMEntities.UserProfiles.UserProfiles hattrickManagerData)
        {
            try {
                XmlDocument xmlDocument = new XmlDocument();

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

                hattrickManagerData.savedDateField = DateTime.Now;

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

                XmlElement xmlElementUserList = xmlDocument.CreateElement(Tags.UserList);

                foreach (HMEntities.UserProfiles.User currentUser in hattrickManagerData.userListField)
                {
                    XmlElement xmlElementTeamId      = xmlDocument.CreateElement(Tags.TeamID);
                    XmlElement xmlElementYouthTeamId = xmlDocument.CreateElement(Tags.YouthTeamID);
                    XmlElement xmlElementLoginname   = xmlDocument.CreateElement(Tags.Loginname);
                    XmlElement xmlElementToken       = xmlDocument.CreateElement(Tags.UserToken);
                    XmlElement xmlElementTokenSecret = xmlDocument.CreateElement(Tags.UserTokenSecret);
                    XmlElement xmlElementActivation  = xmlDocument.CreateElement(Tags.ActivationDate);
                    XmlElement xmlElementDataFolder  = xmlDocument.CreateElement(Tags.DataFolder);

                    xmlElementTeamId.InnerText      = currentUser.teamIdField.ToString();
                    xmlElementYouthTeamId.InnerText = currentUser.youthTeamIdField.ToString();
                    xmlElementLoginname.InnerText   = currentUser.username;
                    xmlElementToken.InnerText       = currentUser.accessToken;
                    xmlElementTokenSecret.InnerText = currentUser.accessTokenSecret;

                    xmlElementActivation.InnerText = currentUser.activationDateField.ToString(General.DateTimeFormat);
                    xmlElementDataFolder.InnerText = currentUser.dataFolderField;

                    XmlElement xmlElementUser = xmlDocument.CreateElement(Tags.User);

                    xmlElementUser.AppendChild(xmlElementTeamId);
                    xmlElementUser.AppendChild(xmlElementYouthTeamId);
                    xmlElementUser.AppendChild(xmlElementLoginname);
                    xmlElementUser.AppendChild(xmlElementToken);
                    xmlElementUser.AppendChild(xmlElementTokenSecret);

                    xmlElementUser.AppendChild(xmlElementActivation);
                    xmlElementUser.AppendChild(xmlElementDataFolder);

                    xmlElementUserList.AppendChild(xmlElementUser);
                }

                xmlElementRoot.AppendChild(xmlElementUserList);

                xmlDocument.AppendChild(xmlElementRoot);

                string path     = GenericFunctions.GetFolderNameByFileType(FileType.WorldDetails);
                string fileName = Path.Combine(path, FileNames.UserProfiles);

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

                xmlDocument.Save(fileName);
            } catch (Exception ex) {
                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// Reads the specified file and return it's content in a HattrickBase entity
        /// </summary>
        /// <param name="fileName">File to read</param>
        /// <param name="fileType">File type</param>
        /// <returns>HattrickBase entity load with file's content</returns>
        public HTEntities.HattrickBase ReadFile(string fileName, FileType fileType)
        {
            try {
                string folder;

                if (fileType == FileType.WorldDetails)
                {
                    folder = commonFolder;
                }
                else
                {
                    folder = Path.Combine(Path.Combine(currentUser.dataFolderField, currentUser.teamIdField.ToString()), GenericFunctions.GetFolderNameByFileType(fileType));
                }

                fileName = Path.Combine(folder, fileName);

                return(dataManager.ReadFile(GetFileStream(fileName), fileType));
            } catch (Exception ex) {
                throw ex;
            }
        }