diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 3d9983a..9d239ff 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -295 \ No newline at end of file +321 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index a5c750f..8783e30 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -27 \ No newline at end of file +53 \ No newline at end of file diff --git a/Common/actions/UpdateChange.cs b/Common/actions/UpdateChange.cs index 83c6d29..079b51a 100644 --- a/Common/actions/UpdateChange.cs +++ b/Common/actions/UpdateChange.cs @@ -5,7 +5,7 @@ using System.Text; using FLocal.Core.DB; namespace FLocal.Common.actions { - class UpdateChange : AbstractChange { + public class UpdateChange : AbstractChange { private readonly int id; diff --git a/Common/dataobjects/Upload.cs b/Common/dataobjects/Upload.cs index fa857e5..eee7842 100644 --- a/Common/dataobjects/Upload.cs +++ b/Common/dataobjects/Upload.cs @@ -67,8 +67,8 @@ namespace FLocal.Common.dataobjects { } } - private int? _userId; - public int? userId { + private int _userId; + public int userId { get { this.LoadIfNotLoaded(); return this._userId; @@ -76,7 +76,7 @@ namespace FLocal.Common.dataobjects { } public User user { get { - return User.LoadById(this.userId.Value); + return User.LoadById(this.userId); } } @@ -86,7 +86,7 @@ namespace FLocal.Common.dataobjects { this._size = int.Parse(data[TableSpec.FIELD_SIZE]); this._filename = data[TableSpec.FIELD_FILENAME]; this._uploadDate = Util.ParseDateTimeFromTimestamp(data[TableSpec.FIELD_UPLOADDATE]).Value; - this._userId = Util.ParseInt(data[TableSpec.FIELD_USERID]); + this._userId = int.Parse(data[TableSpec.FIELD_USERID]); } public XElement exportToXml(UserContext context) { diff --git a/Common/dataobjects/User.cs b/Common/dataobjects/User.cs index e87fdf2..c2d0ed9 100644 --- a/Common/dataobjects/User.cs +++ b/Common/dataobjects/User.cs @@ -22,6 +22,7 @@ namespace FLocal.Common.dataobjects { public const string FIELD_USERGROUPID = "UserGroupId"; public const string FIELD_SHOWPOSTSTOUSERS = "ShowPostsToUsers"; public const string FIELD_BIOGRAPHY = "Biography"; + public const string FIELD_AVATARID = "AvatarId"; public static readonly TableSpec instance = new TableSpec(); public string name { get { return TABLE; } } public string idName { get { return FIELD_ID; } } @@ -102,6 +103,19 @@ namespace FLocal.Common.dataobjects { } } + private int? _avatarId; + public int? avatarId { + get { + this.LoadIfNotLoaded(); + return this._avatarId; + } + } + public Upload avatar { + get { + return Upload.LoadById(this.avatarId.Value); + } + } + private static Dictionary id2user = new Dictionary(); public static User LoadByName(string name) { if(!id2user.ContainsKey(name)) { @@ -140,10 +154,11 @@ namespace FLocal.Common.dataobjects { this._userGroupId = int.Parse(data[TableSpec.FIELD_USERGROUPID]); this._showPostsToUsers = data[TableSpec.FIELD_SHOWPOSTSTOUSERS]; this._biography = data[TableSpec.FIELD_BIOGRAPHY]; + this._avatarId = Util.ParseInt(data[TableSpec.FIELD_AVATARID]); } public XElement exportToXmlForViewing(UserContext context) { - return new XElement("user", + XElement result = new XElement("user", new XElement("id", this.id), new XElement("regDate", this.regDate.ToXml()), new XElement("totalPosts", this.totalPosts), @@ -154,6 +169,10 @@ namespace FLocal.Common.dataobjects { new XElement("userGroupId", this.userGroupId), new XElement("showPostsToUsers", this.showPostsToUsers) ); + if(this.avatarId.HasValue) { + result.Add(new XElement("avatar", this.avatarId)); + } + return result; } public static IEnumerable getUsers(Diapasone diapasone, UserContext context) { diff --git a/ImportConsole/Program.cs b/ImportConsole/Program.cs index 418adad..5c1aa1e 100644 --- a/ImportConsole/Program.cs +++ b/ImportConsole/Program.cs @@ -22,7 +22,12 @@ namespace FLocal.ImportConsole { [Action] public static void ImportUsers() { - UsersImporter.ImportUsers(); + try { + UsersImporter.ImportUsers(); + } catch(Exception e) { + Console.WriteLine(e.GetType().FullName + ": " + e.Message); + Console.WriteLine(e.StackTrace); + } } [Action] diff --git a/ImportConsole/UsersImporter.cs b/ImportConsole/UsersImporter.cs index 634dd93..f69c66b 100644 --- a/ImportConsole/UsersImporter.cs +++ b/ImportConsole/UsersImporter.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using FLocal.Core; using FLocal.Importer; +using FLocal.Common; using FLocal.Common.dataobjects; using FLocal.Common.actions; @@ -15,11 +16,12 @@ namespace FLocal.ImportConsole { for(int i=1; i<800; i++) { Console.Write("[" + i + "]"); foreach(string userName in ShallerGateway.getUserNames(i)) { + Dictionary userData = ShallerGateway.getUserInfo(userName); + User user; try { - User.LoadByName(userName); + user = User.LoadByName(userName); Console.Write("-"); } catch(NotFoundInDBException) { - Dictionary userData = ShallerGateway.getUserInfo(userName); AbstractChange addUser = new InsertChange( User.TableSpec.instance, new Dictionary() { @@ -44,11 +46,40 @@ namespace FLocal.ImportConsole { } ); ChangeSetUtil.ApplyChanges(addUser, addAccount); + user = User.LoadById(addUser.getId().Value); Console.Write("."); } + + if(!user.avatarId.HasValue && userData["avatar"] != null && userData["avatar"] != "") { + try { + Upload avatar; + string[] nameParts = userData["avatar"].Split('.'); + if(nameParts.Length != 2) throw new FLocalException("wrong avatar filename '" + userData["avatar"] + "'"); + int oldAvatarId = int.Parse(nameParts[0]); + FileInfo avatarInfo = ShallerGateway.getFileInfo("user/" + userData["avatar"]); + try { + avatar = UploadManager.UploadFile(avatarInfo.dataStream, avatarInfo.fileName, avatarInfo.lastModified, user, 900000 + oldAvatarId); + } catch(UploadManager.AlreadyUploadedException e) { + avatar = Upload.LoadById(e.uploadId); + } + ChangeSetUtil.ApplyChanges( + new UpdateChange( + User.TableSpec.instance, + new Dictionary { + { User.TableSpec.FIELD_AVATARID, new ScalarFieldValue(avatar.id.ToString()) } + }, + user.id + ) + ); + Console.Write("a"); + } catch(Exception e) { + Console.Write("!{" + user.id + "}{" + e.Message + "}!"); + } + } + } } } } -} +} \ No newline at end of file diff --git a/Importer/FileInfo.cs b/Importer/FileInfo.cs new file mode 100644 index 0000000..521bc22 --- /dev/null +++ b/Importer/FileInfo.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +namespace FLocal.Importer { + public struct FileInfo { + + public Stream dataStream; + public string filePath; + public string fileName; + public long fileSize; + public DateTime lastModified; + + } +} diff --git a/Importer/Importer.csproj b/Importer/Importer.csproj index da0f0f2..b24a90c 100644 --- a/Importer/Importer.csproj +++ b/Importer/Importer.csproj @@ -50,6 +50,7 @@ +