private async void Form1_Load(object sender, EventArgs e) { ControlStack = new ControlStack(); ControlStack.OnUpdated += ControlStack_OnUpdated; ControlStack.Push(new LoginControl(this)); mSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); Me = new User(mSocket); Resolver.AddHandler<UserList>(ResolverOnUpdateUserList); await Connect(); }
public async Task Send(User user, BasePackage package) { var builder = new StringBuilder(); mSerializer.Serialize(new StringWriter(builder), package ); var bytes = Encoding.UTF8.GetBytes(builder.ToString()); using (await user.Lock.LockAsync()) { await SendBytes(user.Socket, BitConverter.GetBytes(bytes.Length)); await SendBytes(user.Socket, bytes); } }
public ActionResult JoinUser(string username, string password) { var db = ContextFactory.GetContextPerRequest(); Core.User user = new Core.User(); user.Username = username; user.Password = password; user.Active = 0; db.Add(user); db.SaveChanges(); return(View("Index")); }
private void FileToList(string[] Text) { foreach (string line in Text) { var userInfo = line.Split(','); User user = new User(userInfo[0]); for (int i = 1; i <= userInfo.Length - 1; i++) { user.AddFollower(userInfo[i]); } _userList.Add(user); } }
public async Task StartListen(User user, Action<BasePackage> packageActions ) { while (true) { var countBytes = await ReadBytes(user.Socket, 4); var count = BitConverter.ToInt32(countBytes, 0); var data = await ReadBytes(user.Socket, count); var stringData = Encoding.UTF8.GetString(data); dynamic obj = JObject.Parse(stringData); var className = (string)obj.ClassName; var type = typeof(BasePackage).Assembly.GetTypes().First(t => t.FullName == className); var realObj = (BasePackage)mSerializer.Deserialize(new StringReader(stringData), type); packageActions(realObj); } }
public MessagesService(Core.User user) : base(user) { }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Index", "Manage"); } if (ModelState.IsValid) { // Получение сведений о пользователе от внешнего поставщика входа var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new User { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToLocal(returnUrl); } } AddErrors(result); } ViewBag.ReturnUrl = returnUrl; return View(model); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new User { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // Дополнительные сведения о том, как включить подтверждение учетной записи и сброс пароля, см. по адресу: http://go.microsoft.com/fwlink/?LinkID=320771 // Отправка сообщения электронной почты с этой ссылкой // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Подтверждение учетной записи", "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return View(model); }
private bool hasProductWithUser(State S, Product P, User U) { foreach (Product pr in S.Products) { if (pr.Equals(P)) { foreach (User usr in pr.Users) { if (usr.Equals(U)) return true; } } } return false; }
/// <summary> /// Массив "Продукт-время работы в нём" для конкретного пользователя за конкретную дату. /// </summary> /// <param name="U">Пользователь</param> /// <param name="D">дата</param> public Dictionary<Product, double> UserTimePerDay(User U, DateTime D) { Dictionary<Product, double> result = new Dictionary<Product, double>(); List<State> dailyStates = new List<State>(); foreach (State S in this.states) { if (S.Datetime.Date == D.Date) dailyStates.Add(S); } dailyStates.Sort(); foreach (Product P in this.AllProducts) { for (int i = 0; i < dailyStates.Count - 1; i++) { if (hasProductWithUser(dailyStates[i], P, U) && hasProductWithUser(dailyStates[i + 1], P, U)) { int DeltaMinutes = new DateTime(Math.Abs(dailyStates[i].Datetime.Ticks - dailyStates[i + 1].Datetime.Ticks)).Minute; double DeltaHours = (double)DeltaMinutes / 60; if (result.ContainsKey(P)) { result[P] += DeltaHours; } else { result.Add(P, DeltaHours); } } } } return result; }