public RegisteredUserInfo GetRegisteredUserInfo(long accountId) { RegisteredUserInfo info = null; RegisteredUsers.TryGetValue(accountId, out info); return(info); }
public RegisteredUserInfo RegisterUser(LoginInfo info, OperationContext context) { if (!info.IsAccountNameValid) { return(null); } var user = new RegisteredUserInfo(NewRegisterID, info.AccountName, info.Password); RegisteredUsers[user.AccountID] = user; var suser = new ServerLoginUserInfo(user, LoginStatus.登录中, context); TaskGroups[0].AddUser(suser.LoginInfo); return(user); }
public void Load() { RegisteredUsers.Clear(); TaskGroups.Clear(); var defGroup = CreateTaskGroup(0); defGroup.Name = "未分组"; if (File.Exists(DataFile)) { XmlDocument doc = new XmlDocument(); doc.Load(DataFile); XmlElement nodeUsers = doc.DocumentElement.GetElementsByTagName("Users")[0] as XmlElement; foreach (XmlElement elm in nodeUsers.ChildNodes) { RegisteredUserInfo user = new RegisteredUserInfo(elm); RegisteredUsers[user.AccountID] = user; var group = CreateTaskGroup(user.TaskGroupID); if (group == null) { group = defGroup; } var suser = new ServerLoginUserInfo(user, LoginStatus.离线, null); group.AddUser(suser.LoginInfo); } XmlElement nodeGrps = doc.DocumentElement.GetElementsByTagName("Groups")[0] as XmlElement; foreach (XmlElement elm in nodeGrps.ChildNodes) { int groupId = int.Parse(elm.GetAttribute("ID")); var grp = CreateTaskGroup(groupId); if (grp != null) { grp.Name = elm.GetAttribute("Name"); } } } }
public void Login(LoginInfo info) { ILoginServiceCallback curGuest = OperationContext.Current.GetCallbackChannel<ILoginServiceCallback>(); if (!info.IsAccountValid) { curGuest.NotifyLoginResult(null, LoginResult.失败_帐号非法); return; } RegisteredUserInfo uinfo = null; LoginResult result = LoginResult.登录成功; if (info.IsAccountIDValid) { uinfo = Program.UserMgr.GetRegisteredUserInfo(info.AccountID); if (uinfo == null) { curGuest.NotifyLoginResult(null, LoginResult.失败_帐号不存在); return; } } else if (info.IsAccountNameValid) { uinfo = Program.UserMgr.GetRegisteredUserInfo(info.AccountName); if (uinfo == null) { uinfo = Program.UserMgr.RegisterUser(info, OperationContext.Current); result = LoginResult.登录并注册成功; } } if (info.Password != uinfo.Password) { curGuest.NotifyLoginResult(null, LoginResult.失败_密码错误); return; } if (info.AdjudicatorMode && (uinfo.Permission & UserPermission.评审) == 0) { curGuest.NotifyLoginResult(null, LoginResult.失败_评审权限未开通); return; } var suser = Program.UserMgr.GetLoginUserInfo(uinfo.AccountID); if (suser != null) { if (suser.IsOnline) Program.UserMgr.KickUser(suser.AccountID, 0, LogoutReason.异地登录, null); else { suser.LoginInfo.AdjudicatorMode = info.AdjudicatorMode; suser.LoginInfo.TransServicePort = info.TransServicePort; suser.LoginInfo.JudgementConfigFileMD5 = info.JudgementConfigFileMD5; } } suser = Program.UserMgr.GetLoginUserInfo(OperationContext.Current); if (suser != null) { if (suser.AccountID != uinfo.AccountID) Program.UserMgr.KickUser(suser.AccountID, 5, LogoutReason.更改用户, null); else curGuest.NotifyLoginResult(uinfo, result); } suser = Program.UserMgr.GetLoginUserInfo(uinfo.AccountID); if (suser.LoginInfo.AdjudicatorMode) { if (!Program.UserMgr.SetUserTaskGroup(suser.AccountID, 0)) { curGuest.NotifyLoginResult(null, LoginResult.失败_未知错误); return; } } Program.UserMgr.OnUserLoginSucceeded(uinfo.AccountID, OperationContext.Current); curGuest.NotifyLoginResult(uinfo, result); }
public void NotifyLoginResult(RegisteredUserInfo user, LoginResult result) { this.BeginInvokeEx(() => { if (result == LoginResult.登录成功 || result == LoginResult.登录并注册成功) { Program.CurUser.Info = user; Program.CurUser.AdjudicatorMode = Program.IsLoginJudgeMode && ((user.Permission & UserPermission.评审) == UserPermission.评审); ProjectDoc.Instance.CurEditUserID = user.AccountID; if (result == LoginResult.登录并注册成功 && Program.StartupArgs.Count == 0) { MessageBox.Show("注册成功,你的帐号ID是:" + user.AccountID); } UIEnabled = true; if (cmbServerIP.Text.Length > 0 && !cmbServerIP.Properties.Items.Contains(cmbServerIP.Text)) { cmbServerIP.Properties.Items.Insert(0, cmbServerIP.Text); } else if (cmbServerIP.Properties.Items.Count > 1) { string sel = cmbServerIP.SelectedItem as string; cmbServerIP.Properties.Items.RemoveAt(cmbServerIP.SelectedIndex); cmbServerIP.Properties.Items.Insert(0, sel); cmbServerIP.SelectedIndex = 0; } string ips = ""; foreach (var item in cmbServerIP.Properties.Items) { if (ips.Length > 0) { ips += ";"; } ips += item as string; } Program.SaveConfigValue("ServerIPs", ips); if (cmbAccount.Text.Length > 0 && !cmbAccount.Properties.Items.Contains(cmbAccount.Text)) { cmbAccount.Properties.Items.Insert(0, cmbAccount.Text); } else if (cmbAccount.Properties.Items.Count > 1) { string sel = cmbAccount.SelectedItem as string; cmbAccount.Properties.Items.RemoveAt(cmbAccount.SelectedIndex); cmbAccount.Properties.Items.Insert(0, sel); cmbAccount.SelectedIndex = 0; } string accs = ""; foreach (var item in cmbAccount.Properties.Items) { if (accs.Length > 0) { accs += ";"; } accs += item as string; } Program.SaveConfigValue("UserAccounts", accs); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { lblUpdateStatus.Text = result.ToString().Replace("失败_", ""); UIEnabled = true; } }); }
//static ServerLoginUserInfo() //{ // LoginUserInfo.DataContractKnownTypes.Add(typeof(ServerLoginUserInfo)); //} public ServerLoginUserInfo(RegisteredUserInfo user, LoginStatus status, OperationContext context) { LoginInfo = new LoginUserInfo(user, 0, status); LoginInfo.LocalObj = this; Context = context; }
public static string DoSynchronization(MyRemoteServices.SinchronizationObject syncObj) { string syncLog = "***************BEGIN LOG***************" + Environment.NewLine; MyRemoteServices.BonusFeature[] incomingBonusFeatures = syncObj.bonusFeaturesList; MyRemoteServices.AccomodationCategory[] incomingAccCats = syncObj.accCatsList; MyRemoteServices.AccomodationType[] incomingAccTypes = syncObj.accTypesList; MyRemoteServices.Country[] incomingCountries = syncObj.countriesList; MyRemoteServices.City[] incomingCities = syncObj.citiesList; MyRemoteServices.RegUsrMessage[] incomingMessages = syncObj.regUserMessagesList; MyRemoteServices.MainServerReservation[] incomingReservations = syncObj.reservationsList; using (var ctx = new ApplicationDbContext()) { if (incomingBonusFeatures != null) { foreach (var bf in incomingBonusFeatures) { bool actionHappened = false; var localBfData = ctx.BonusFeatures.FirstOrDefault(x => x.MainServerId == bf.mainServerId); if (localBfData == null) { BonusFeatures localBf = new BonusFeatures { MainServerId = bf.mainServerId, Name = bf.name }; ctx.BonusFeatures.Add(localBf); actionHappened = true; syncLog += string.Format("Added a new BonusFeature: {0}" + Environment.NewLine, localBf.Name); } else { if (bf.name != localBfData.Name) { syncLog += string.Format("Edited the {0} BonusFeature's name property from {1} to {2}" + Environment.NewLine, localBfData.Name, localBfData.Name, bf.name); localBfData.Name = bf.name; actionHappened = true; } } if (actionHappened) { syncLog += TrySave(ctx); } } syncLog += "=============================================================" + Environment.NewLine; } if (incomingAccCats != null) { foreach (var accCat in incomingAccCats) { bool actionHappened = false; var localAccCatData = ctx.AccomodationCategories.FirstOrDefault(x => x.MainServerId == accCat.mainServerId); if (localAccCatData == null) { AccomodationCategory localAccCat = new AccomodationCategory { MainServerId = accCat.mainServerId, Name = accCat.name }; ctx.AccomodationCategories.Add(localAccCat); actionHappened = true; syncLog += string.Format("Added a new AccomodationCategory: {0}" + Environment.NewLine, localAccCat.Name); } else { if (localAccCatData.Name != accCat.name) { syncLog += string.Format("Edited the {0} AccomodationCategory's name property from {1} to {2}" + Environment.NewLine, localAccCatData.Name, localAccCatData.Name, accCat.name); localAccCatData.Name = accCat.name; actionHappened = true; } } if (actionHappened) { syncLog += TrySave(ctx); } } syncLog += "=============================================================" + Environment.NewLine; } if (incomingAccTypes != null) { foreach (var accType in incomingAccTypes) { bool actionHappened = false; var localAccTypeData = ctx.AccomodationTypes.FirstOrDefault(x => x.MainServerId == accType.mainServerId); if (localAccTypeData == null) { AccomodationType localAccType = new AccomodationType { MainServerId = accType.mainServerId, Name = accType.name }; ctx.AccomodationTypes.Add(localAccType); actionHappened = true; syncLog += string.Format("Added a new AccomodationType: {0}" + Environment.NewLine, localAccType.Name); } else { if (localAccTypeData.Name != accType.name) { syncLog += string.Format("Edited the {0} AccomodationType's name property from {1} to {2}" + Environment.NewLine, localAccTypeData.Name, localAccTypeData.Name, accType.name); localAccTypeData.Name = accType.name; actionHappened = true; } } if (actionHappened) { syncLog += TrySave(ctx); } } syncLog += "=============================================================" + Environment.NewLine; } if (incomingCountries != null) { foreach (var cntry in incomingCountries) { bool actionHappened = false; var localCntryData = ctx.Countries.FirstOrDefault(x => x.MainServerId == cntry.mainServerId); if (localCntryData == null) { Country localCntry = new Country { MainServerId = cntry.mainServerId, Name = cntry.name }; ctx.Countries.Add(localCntry); actionHappened = true; syncLog += string.Format("Added a new Country: {0}" + Environment.NewLine, localCntry.Name); } else { if (localCntryData.Name != cntry.name) { syncLog += string.Format("Edited the {0} Country's name property from {1} to {2}" + Environment.NewLine, localCntryData.Name, localCntryData.Name, cntry.name); localCntryData.Name = cntry.name; actionHappened = true; } } if (actionHappened) { syncLog += TrySave(ctx); } } syncLog += "=============================================================" + Environment.NewLine; } if (incomingCities != null) { foreach (var city in incomingCities) { bool actionHappened = false; var localCityData = ctx.Cities.FirstOrDefault(x => x.MainServerId == city.mainServerId); if (localCityData == null) { var cntry = ctx.Countries.FirstOrDefault(x => x.MainServerId == city.country.mainServerId); City localCity = new City { MainServerId = city.mainServerId, Name = city.name, PostalCode = city.postalCode, Country = cntry }; ctx.Cities.Add(localCity); actionHappened = true; syncLog += string.Format("Added a new City: {0}" + Environment.NewLine, localCity.Name); } else { if (localCityData.Name != city.name) { syncLog += string.Format("Edited the {0} City's name property from {1} to {2}" + Environment.NewLine, localCityData.Name, localCityData.Name, city.name); localCityData.Name = city.name; actionHappened = true; } if (localCityData.PostalCode != city.postalCode) { syncLog += string.Format("Edited the {0} City's postalCode property from {1} to {2}" + Environment.NewLine, localCityData.Name, localCityData.PostalCode, city.postalCode); localCityData.PostalCode = city.postalCode; actionHappened = true; } if (localCityData.Country.MainServerId != city.country.mainServerId) { var newCountry = ctx.Countries.FirstOrDefault(x => x.MainServerId == city.country.mainServerId); if (newCountry == null) { syncLog += string.Format("Error while trying to edit the {0} City's country property: No Country with such id is found." + Environment.NewLine, localCityData.Name); } else { syncLog += string.Format("Edited the {0} City's country property from {1} to {2}" + Environment.NewLine, localCityData.Name, localCityData.Country.Name, city.country.name); localCityData.Country = newCountry; actionHappened = true; } } } if (actionHappened) { syncLog += TrySave(ctx); } } syncLog += "=============================================================" + Environment.NewLine; } if (incomingMessages != null) { foreach (var msg in incomingMessages) { bool actionHappened = false; var localMsgData = ctx.Messages.FirstOrDefault(x => x.MainServerId == msg.mainServerId); if (localMsgData == null) { var localRegUserInfo = ctx.RegisteredUsersInfo.FirstOrDefault(x => x.MainServerId == msg.regUsrInfo.mainServerId); if (localRegUserInfo == null) { localRegUserInfo = new RegisteredUserInfo { MainServerId = msg.regUsrInfo.mainServerId, UserName = msg.regUsrInfo.userName }; ctx.RegisteredUsersInfo.Add(localRegUserInfo); actionHappened = true; syncLog += string.Format("Added a new RegisteredUserInfo: {0}" + Environment.NewLine, localRegUserInfo.UserName); } var localAgent = ctx.Users.FirstOrDefault(x => x.MainServerId == msg.agentUserMainServerId); if (localAgent == null) { syncLog += string.Format("Error while trying to add a new message: agent user not found." + Environment.NewLine); } else { Message localMsg = new Message { MainServerId = msg.mainServerId, AgentUserId = localAgent.Id, Content = msg.content, RegisteredUserInfo = localRegUserInfo, IsRead = false, HasResponse = false }; ctx.Messages.Add(localMsg); actionHappened = true; syncLog += string.Format("Added a new Message" + Environment.NewLine); } } if (actionHappened) { syncLog += TrySave(ctx); } } syncLog += "=============================================================" + Environment.NewLine; } if (incomingReservations != null) { foreach (var res in incomingReservations) { bool actionHappened = false; var localReservationData = ctx.Reservations.FirstOrDefault(x => x.MainServerId == res.mainServerId); if (localReservationData == null) { var bookingUnitLocal = ctx.BookingUnits.FirstOrDefault(x => x.MainServerId == res.bookingUnitMainServerId); if (bookingUnitLocal == null) { syncLog += string.Format("Error while trying to add a new reservation: bookingUnit not found." + Environment.NewLine); } else { Reservation localReservation = new Reservation { MainServerId = res.mainServerId, From = res.from, To = res.to, ReservationStatus = (ReservationStatus)res.reservationStatus, SubjectName = res.subjectName, SubjectSurname = res.subjectSurname, TotalPrice = res.totalPrice, BookingUnit = bookingUnitLocal }; ctx.Reservations.Add(localReservation); actionHappened = true; syncLog += string.Format("Added a new Reservation of the booking unit: {0}" + Environment.NewLine, bookingUnitLocal.Name); } } else { if (localReservationData.ReservationStatus != (ReservationStatus)res.reservationStatus) { var bUnit = ctx.BookingUnits.FirstOrDefault(x => x.MainServerId == res.bookingUnitMainServerId); syncLog += string.Format("Edited the reservation status from {0} to {1} for the Booking unit: {2}" + Environment.NewLine, localReservationData.ReservationStatus.ToString(), res.reservationStatus.ToString(), bUnit.Name); localReservationData.ReservationStatus = (ReservationStatus)res.reservationStatus; actionHappened = true; } } if (actionHappened) { syncLog += TrySave(ctx); } } syncLog += "***************END LOG***************"; } } return(syncLog); }