private LicenseUser CreateLicense(ConnectionInfo connectionInfo, int LicenseType) { LicenseUser newLicense = new LicenseUser(); logWrite(connectionInfo.ConnectionId,"라이센스 타입 : " + LicenseType + "라이센스 생성 중.."); try { using (var db = new LicensingEntities()) { newLicense = new LicenseUser() { ID = Guid.NewGuid(), Company = connectionInfo.Company, ProjectType = connectionInfo.ProjectType, UserName = connectionInfo.UserName, LicenseType = LicenseType, StartDateTime = connectionInfo.CurrentDateTime, EndDateTime = connectionInfo.CurrentDateTime.AddMinutes(LicenseType) }; db.LicenseUser.Add(newLicense); db.SaveChanges(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); newLicense = null; } return newLicense; }
private void SetConnection(ConnectionInfo connectionInfo, LicenseUser licenseUser) { using (var db = new LicensingEntities()) { Guid ConnectionID = Guid.Parse(connectionInfo.ConnectionId); var users = db.User.Where(f => f.UserName == connectionInfo.UserName); if (users.Count() == 0) { int Isrole; if(!int.TryParse(connectionInfo.Role, out Isrole)) { Isrole = 1; } var user = new User { ID = Guid.NewGuid(), UserName = connectionInfo.UserName, Company = connectionInfo.Company, ProjectType = connectionInfo.ProjectType, Role = Isrole, LastActivity = connectionInfo.CurrentDateTime }; db.User.Add(user); } else { var user = users.First(); user.LastActivity = DateTime.UtcNow; } db.SaveChanges(); var _connections = db.Connection.Where(con => con.ConnectionID == ConnectionID); if (_connections.Count() == 0) { CreateConnection(connectionInfo); } Clients.Client(connectionInfo.ConnectionId).licenseExpired(licenseUser.EndDateTime); } }