AccountIndicator implemented; legacy code removed from ImportUsers

main
Inga 🏳‍🌈 14 years ago
parent 5d7f32a3d8
commit 2b3c6a8ae9
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      Builder/IISUploadHandler/build.txt
  3. 1
      Common/Common.csproj
  4. 1
      Common/actions/ChangeSet.cs
  5. 99
      Common/dataobjects/AccountIndicator.cs
  6. 25
      ImportConsole/UsersImporter.cs

@ -58,6 +58,7 @@
<Compile Include="actions\ChangeSetUtil.cs" />
<Compile Include="Config.cs" />
<Compile Include="dataobjects\Account.cs" />
<Compile Include="dataobjects\AccountIndicator.cs" />
<Compile Include="dataobjects\Board.cs" />
<Compile Include="dataobjects\Category.cs" />
<Compile Include="dataobjects\IUserSettings.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,

@ -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<AccountIndicator> {
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<string, string> 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<int, int> accountid2id = new Dictionary<int, int>();
public static AccountIndicator LoadByAccount(Account account) {
if(!accountid2id.ContainsKey(account.id)) {
lock(accountid2id) {
if(!accountid2id.ContainsKey(account.id)) {
List<string> 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)
);
}
}
}

@ -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<string, string> userData = ShallerGateway.getUserInfo(userName);
User user;
try {
user = User.LoadByName(userName);
User.LoadByName(userName);
Console.Write("-");
} catch(NotFoundInDBException) {
Dictionary<string, string> userData = ShallerGateway.getUserInfo(userName);
AbstractChange addUser = new InsertChange(
User.TableSpec.instance,
new Dictionary<string, AbstractFieldValue>() {
new Dictionary<string, AbstractFieldValue> {
{ 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<string,AbstractFieldValue>() {
new Dictionary<string,AbstractFieldValue> {
{ 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<string,AbstractFieldValue> {
{ 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 + "}!");
}
}

Loading…
Cancel
Save