From 2b3c6a8ae9900ef480842a5e7d5326eb79aba1cb Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Tue, 29 Jun 2010 16:18:28 +0000 Subject: [PATCH] AccountIndicator implemented; legacy code removed from ImportUsers --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/Common.csproj | 1 + Common/actions/ChangeSet.cs | 1 + Common/dataobjects/AccountIndicator.cs | 99 ++++++++++++++++++++++++++ ImportConsole/UsersImporter.cs | 25 ++++--- 6 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 Common/dataobjects/AccountIndicator.cs diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 00c22e5..bc56e76 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -429 \ No newline at end of file +431 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 59f3135..2efea51 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -165 \ No newline at end of file +167 \ No newline at end of file diff --git a/Common/Common.csproj b/Common/Common.csproj index 4e372da..47023da 100644 --- a/Common/Common.csproj +++ b/Common/Common.csproj @@ -58,6 +58,7 @@ + diff --git a/Common/actions/ChangeSet.cs b/Common/actions/ChangeSet.cs index 3622927..1cb2256 100644 --- a/Common/actions/ChangeSet.cs +++ b/Common/actions/ChangeSet.cs @@ -26,6 +26,7 @@ namespace FLocal.Common.actions { dataobjects.Account.TableSpec.TABLE, dataobjects.User.TableSpec.TABLE, dataobjects.AccountSettings.TableSpec.TABLE, + dataobjects.AccountIndicator.TableSpec.TABLE, dataobjects.Thread.ReadMarkerTableSpec.TABLE, dataobjects.Board.ReadMarkerTableSpec.TABLE, dataobjects.Session.TableSpec.TABLE, diff --git a/Common/dataobjects/AccountIndicator.cs b/Common/dataobjects/AccountIndicator.cs new file mode 100644 index 0000000..4c2c7c2 --- /dev/null +++ b/Common/dataobjects/AccountIndicator.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Xml.Linq; +using FLocal.Core; +using FLocal.Core.DB; +using FLocal.Core.DB.conditions; +using FLocal.Common.actions; + +namespace FLocal.Common.dataobjects { + public class AccountIndicator : SqlObject { + + public class TableSpec : ISqlObjectTableSpec { + public const string TABLE = "Accounts_Indicators"; + public const string FIELD_ID = "Id"; + public const string FIELD_ACCOUNTID = "AccountId"; + public const string FIELD_PRIVATEMESSAGES = "PrivateMessages"; + public const string FIELD_UNREADPRIVATEMESSAGES = "UnreadPrivateMessages"; + public static readonly TableSpec instance = new TableSpec(); + public string name { get { return TABLE; } } + public string idName { get { return FIELD_ID; } } + public void refreshSqlObject(int id) { Refresh(id); } + } + + protected override ISqlObjectTableSpec table { get { return TableSpec.instance; } } + + private int _accountId; + public int accountId { + get { + this.LoadIfNotLoaded(); + return this._accountId; + } + } + public Account account { + get { + return Account.LoadById(this._accountId); + } + } + + private int _privateMessages; + public int privateMessages { + get { + this.LoadIfNotLoaded(); + return this._privateMessages; + } + } + + private int _unreadPrivateMessages; + public int unreadPrivateMessages { + get { + this.LoadIfNotLoaded(); + return this._unreadPrivateMessages; + } + } + + protected override void doFromHash(Dictionary data) { + this._accountId = int.Parse(data[TableSpec.FIELD_ACCOUNTID]); + this._privateMessages = int.Parse(data[TableSpec.FIELD_PRIVATEMESSAGES]); + this._unreadPrivateMessages = int.Parse(data[TableSpec.FIELD_UNREADPRIVATEMESSAGES]); + } + + private static Dictionary accountid2id = new Dictionary(); + public static AccountIndicator LoadByAccount(Account account) { + if(!accountid2id.ContainsKey(account.id)) { + lock(accountid2id) { + if(!accountid2id.ContainsKey(account.id)) { + List ids = Config.instance.mainConnection.LoadIdsByConditions( + TableSpec.instance, + new ComparisonCondition( + TableSpec.instance.getColumnSpec(TableSpec.FIELD_ACCOUNTID), + ComparisonType.EQUAL, + account.id.ToString() + ), + Diapasone.unlimited, + new JoinSpec[0] + ); + if(ids.Count > 1) { + throw new CriticalException("not unique"); + } else if(ids.Count == 1) { + accountid2id[account.id] = int.Parse(ids[0]); + } else { + throw new CriticalException("not found"); + } + } + } + } + return AccountIndicator.LoadById(accountid2id[account.id]); + } + + public XElement exportToXml(UserContext context) { + return new XElement("indicators", + new XElement("privateMessages", this.privateMessages), + new XElement("unreadPrivateMessages", this.unreadPrivateMessages) + ); + } + + } +} diff --git a/ImportConsole/UsersImporter.cs b/ImportConsole/UsersImporter.cs index f69c66b..470a8ff 100644 --- a/ImportConsole/UsersImporter.cs +++ b/ImportConsole/UsersImporter.cs @@ -16,15 +16,15 @@ 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 = User.LoadByName(userName); + User.LoadByName(userName); Console.Write("-"); } catch(NotFoundInDBException) { + Dictionary userData = ShallerGateway.getUserInfo(userName); AbstractChange addUser = new InsertChange( User.TableSpec.instance, - new Dictionary() { + new Dictionary { { User.TableSpec.FIELD_NAME, new ScalarFieldValue(userName) }, { User.TableSpec.FIELD_REGDATE, new ScalarFieldValue(DateTime.Parse(userData["regDate"]).ToUTCString()) }, { User.TableSpec.FIELD_LOCATION, new ScalarFieldValue(userData["location"]) }, @@ -38,20 +38,27 @@ namespace FLocal.ImportConsole { ); AbstractChange addAccount = new InsertChange( Account.TableSpec.instance, - new Dictionary() { + new Dictionary { { Account.TableSpec.FIELD_NAME, new ScalarFieldValue(userName.ToLower()) }, { Account.TableSpec.FIELD_NEEDSMIGRATION, new ScalarFieldValue("1") }, { Account.TableSpec.FIELD_PASSWORDHASH, new ScalarFieldValue("*") }, { Account.TableSpec.FIELD_USERID, new ReferenceFieldValue(addUser) }, } ); - ChangeSetUtil.ApplyChanges(addUser, addAccount); + AbstractChange addIndicator = new InsertChange( + AccountIndicator.TableSpec.instance, + new Dictionary { + { AccountIndicator.TableSpec.FIELD_ACCOUNTID, new ReferenceFieldValue(addAccount) }, + { AccountIndicator.TableSpec.FIELD_PRIVATEMESSAGES, new ScalarFieldValue("0") }, + { AccountIndicator.TableSpec.FIELD_UNREADPRIVATEMESSAGES, new ScalarFieldValue("0") }, + } + ); + ChangeSetUtil.ApplyChanges(addUser, addAccount, addIndicator); + user = User.LoadById(addUser.getId().Value); Console.Write("."); - } - if(!user.avatarId.HasValue && userData["avatar"] != null && userData["avatar"] != "") { - try { + if(userData["avatar"] != null && userData["avatar"] != "") { Upload avatar; string[] nameParts = userData["avatar"].Split('.'); if(nameParts.Length != 2) throw new FLocalException("wrong avatar filename '" + userData["avatar"] + "'"); @@ -72,8 +79,6 @@ namespace FLocal.ImportConsole { ) ); Console.Write("a"); - } catch(Exception e) { - Console.Write("!{" + user.id + "}{" + e.Message + "}!"); } }