public User(decimal ID, bool AsProxy) { if (AsProxy == false) { FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); FI.Common.Data.FIDataTable table = dacObj.ReadUser(ID); if (table == null || table.Rows.Count == 0) { throw new Exception("Cannot authenticate by id:" + ID.ToString()); } LoadData(table); this._isProxy = false; } this._id = ID; if (this.IsNew == false) { _contactSystem = new ContactSystem(this); _reportSystem = new ReportSystem(this); _distributionSystem = new DistributionSystem(this); // after Contacts and Reports } }
public void SendQueuedDistributions(string CompanyNameShort) { lock (this) { // check if already being handled if (_sendingRequests.Contains(CompanyNameShort)) { return; } _sendingRequests.Add(CompanyNameShort); } Exception lastExc = null; decimal lastExcQueueItemId = -1; try { FI.DataAccess.Distributions distrDao = DataAccessFactory.Instance.GetDistributionsDA(); FI.DataAccess.Users userDao = DataAccessFactory.Instance.GetUsersDA(); decimal companyId = userDao.GetCompanyIdByShortName(CompanyNameShort); if (companyId > 0) { while (true) { decimal queueItemId = distrDao.ReadNextQueuedDistribution(companyId); if (queueItemId <= 0) { break; } try { SendQueuedDistribution(queueItemId); } catch (Exception exc) { // throw if exception occured twice for same queue item if (lastExcQueueItemId == queueItemId) { throw exc; } lastExcQueueItemId = queueItemId; } } } } finally { _sendingRequests.Remove(CompanyNameShort); } if (lastExc != null) { throw lastExc; } }
public void AuditPageHit() { if (this.IsLoggedIn == false) { return; } FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); dacObj.InsertPageHitAudit(this.ID, this._companyId, this.IPAddress, this.SessionId, System.DateTime.Now); }
public bool CheckSessionValidity() { if (this.IsLoggedIn == false) { return(false); } FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); string sessionId = dacObj.GetUserCurrentSession(this.ID); return(sessionId == this.SessionId); }
private void TestLoadRemotingSocketsMethod() { try { FI.DataAccess.Users dac = FI.BusinessObjects.DataAccessFactory.Instance.GetUsersDA(); dac.ReadUser((decimal)1); FI.Common.LogWriter.Instance.WriteEventLogEntry("TestLoadRemotingSocketsMethod completed"); } catch (Exception exc) { FI.Common.LogWriter.Instance.WriteEventLogEntry(exc); } }
public void SendAllQueuedDistributions() { FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); DataTable table = dacObj.ReadCompanies(); if (table == null || table.Rows.Count == 0) { return; } foreach (System.Data.DataRow row in table.Rows) { string comName = row["ShortName"].ToString(); this.SendQueuedDistributions(comName); } }
public void EnqueueScheduledDistributions(System.DateTime Date, string CompanyNameShort) { FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); FI.Common.Data.FIDataTable table = dacObj.ReadUsers(); if (table.Rows.Count == 0) { return; } foreach (System.Data.DataRow row in table.Rows) { if (((string)row["CompanyNameShort"]).ToUpper() == CompanyNameShort.ToUpper()) { User user = new User((decimal)row["Id"], true); user.DistributionSystem.EnqueueDistributions(Date); } } }
public void SaveUser(User user) { if (this.IsNew || this.IsProxy) { throw new Exception("Cannot use new or proxy to save"); } if (user.IsNew == false && user.IsProxy) { throw new Exception("Cannot save proxy"); } if (this.IsAdmin == false && this.ID != user.ID) { throw new Exception("Permission denied"); } if (this.ID == user.ID) { //saving itself , must not assign itself as admin if wasn't admin if (this._isAdminAudit == false && user.IsAdmin) { throw new Exception("Premission denied : IsAdmin property"); } } FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); if (user.IsNew) { user._id = dacObj.InsertUser(user._companyId, user.Logon, user.Password, user._passwordTimestamp, user.Name, user.Email, user.IsAdmin, user.CssStyle); } else { dacObj.UpdateUser(user.ID, user.Logon, user.Password, user._passwordTimestamp, user.Name, user.Email, user.IsAdmin, user.CssStyle); } user._isProxy = false; user._isAdminAudit = user._isAdmin; if (this.ID == user.ID) { //update itself FI.Common.Data.FIDataTable table = dacObj.ReadUser(this.ID); this.LoadData(table); } }
public virtual void Login(bool Force, string IpAddress, string SessionId) { if (this.IsValidIp(IpAddress) == false) { throw new Exception("Permission denied from address " + IpAddress); } if (this.IsLoggedIn && this.SessionId != SessionId && Force == false) { this._isLoggedIn = false; throw new Exception("User is already logged in"); } // login this._isLoggedIn = true; this._ipAddress = IpAddress; this._sessionId = SessionId; FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); dacObj.UpdateUserSession(this.ID, this.IPAddress, this.SessionId, this.IsLoggedIn); }
public void DeleteUser(User user) { if (this.IsProxy) { throw new Exception("Cannot use proxy"); } if (this.IsAdmin == false) { throw new Exception("Permission denied"); } if (this.ID == user.ID) { throw new Exception("Cannot delete itself"); } user.ContactSystem.DeleteAll(); user.ReportSystem.DeleteAll(false); FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); dacObj.DeleteUser(user.ID); }
public User(string CompanyNameShort, string Logon, string Password) { FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); // read FI.Common.Data.FIDataTable table = dacObj.ReadUser(CompanyNameShort, Logon, Password); if (table.Rows.Count == 0) { throw new Exception("Incorrect login information"); } System.Data.DataRow row = table.Rows[0]; this._id = (decimal)row["id"]; LoadData(table); this._isProxy = false; _contactSystem = new ContactSystem(this); _reportSystem = new ReportSystem(this); _distributionSystem = new DistributionSystem(this); // after Contacts and Reports }
public virtual void Logout() { if (CheckSessionValidity()) { FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); dacObj.UpdateUserSession(this.ID, this.IPAddress, this.SessionId, false); } // dispose this.Dispose(); // logout this._isLoggedIn = false; this._id = 0; this._logon = ""; this._password = ""; this._name = ""; this._companyId = 0; this._companyNameShort = ""; this._companyNameLong = ""; this._oltpDatabase = ""; }
public FI.Common.Data.FIDataTable GetSystemUsers() { FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); return(dacObj.ReadUsers(this._companyId)); }
public void PingOlapSystem(string Mdx, string MailTo) { bool failure = false; System.IO.StringWriter sw = new System.IO.StringWriter(); // get all companies FI.DataAccess.Users usersDac = DataAccessFactory.Instance.GetUsersDA(); System.Data.DataTable table = usersDac.ReadCompanies(); if (table == null || table.Rows.Count == 0) { return; } sw.WriteLine("<html>"); sw.WriteLine("Failed Ping Queries (" + System.DateTime.Today.ToShortDateString() + " " + System.DateTime.Now.ToShortTimeString() + ")"); sw.WriteLine("<br><br>"); sw.WriteLine("<table border=1 width=100%>"); try { foreach (System.Data.DataRow row in table.Rows) { if ((bool)row["Ping"] == true) { string company = row["ShortName"].ToString(); string server = row["OlapServer"].ToString(); string database = row["OlapDatabase"].ToString(); try { string taskGuid = Guid.NewGuid().ToString(); string taskTag = string.Format("Ping"); FI.DataAccess.OlapSystem olapDac = DataAccessFactory.Instance.GetOlapSystemDA(); olapDac.BuildCellset(Mdx, server, database, taskGuid, taskTag); } catch (Exception exc) { failure = true; sw.Write("<tr>"); sw.Write("<td>"); sw.Write(company); sw.Write("</td><td>"); sw.Write(exc.Message); sw.Write("</td>"); sw.WriteLine("</tr>"); Common.LogWriter.Instance.WriteEventLogEntry(exc); } } } } catch (Exception exc) //more common exception { failure = true; sw.Write("<tr>"); sw.Write(exc.Message); sw.Write("</td>"); sw.WriteLine("</tr>"); Common.LogWriter.Instance.WriteEventLogEntry(exc); } sw.WriteLine("</table></html>"); //send via email if (failure) { try { // message OpenSmtp.Mail.MailMessage msg = new OpenSmtp.Mail.MailMessage(); msg.From = new OpenSmtp.Mail.EmailAddress(FI.Common.AppConfig.SmtpSender); msg.To.Add(new OpenSmtp.Mail.EmailAddress(MailTo)); msg.Subject = "Failed Ping Queries"; msg.Priority = "High"; msg.HtmlBody = sw.ToString(); // smtp host OpenSmtp.Mail.Smtp smtp = new OpenSmtp.Mail.Smtp(); smtp.Host = FI.Common.AppConfig.SmtpServer; if (FI.Common.AppConfig.SmtpUserName != null && FI.Common.AppConfig.SmtpUserName != "") { smtp.Username = FI.Common.AppConfig.SmtpUserName; smtp.Password = FI.Common.AppConfig.SmtpPassword; } smtp.SendMail(msg); } catch (Exception exc) { // because real exception is inside: while (exc.InnerException != null) { exc = exc.InnerException; } throw exc; } } }
public void ExecuteAllOlapReports(string CompanyNameShort, int millisecondsTimeout, string logPath) { if (!System.IO.Path.IsPathRooted(logPath)) { logPath = FI.Common.AppConfig.TempDir + "\\" + logPath; } FI.DataAccess.Users dacObj = DataAccessFactory.Instance.GetUsersDA(); FI.Common.Data.FIDataTable table = dacObj.ReadUsers(); if (table.Rows.Count == 0) { return; } table.DefaultView.Sort = "Id asc"; int errorCount = 0; int rptCount = 1; foreach (System.Data.DataRowView userRow in table.DefaultView) { if (((string)userRow["CompanyNameShort"]).ToUpper() == CompanyNameShort.ToUpper()) { User user = new User((decimal)userRow["Id"], false); FI.Common.Data.FIDataTable t = user.ReportSystem.GetReportHeaders(typeof(OlapReport)); t.DefaultView.Sort = "id asc"; string userLog = string.Format("***************** User id={0}, login='******', password='******'", user.ID, user.Logon, user.Password); System.IO.StreamWriter sw = System.IO.File.AppendText(logPath); sw.WriteLine(userLog); sw.Close(); foreach (DataRowView rptRow in t.DefaultView) { if ((byte)rptRow["sharing_status"] == (byte)Report.SharingEnum.InheriteSubscriber || (byte)rptRow["sharing_status"] == (byte)Report.SharingEnum.SnapshotSubscriber) { continue; } string log = string.Format("{0}\t#{1}\t", DateTime.Now.ToShortTimeString(), rptCount); try { OlapReport rpt = (OlapReport)user.ReportSystem.GetReport((decimal)rptRow["id"], typeof(OlapReport), true); log += string.Format("OlapReport id={0}, name='{1}', description='{2}'", rpt.ID, rpt.Name, rpt.Description); rpt.BeginExecute(); int milisecondCount = 0; while (milisecondCount < millisecondsTimeout && rpt.State == Report.StateEnum.Executing) { System.Threading.Thread.Sleep(500); milisecondCount += 500; } if (rpt.State == Report.StateEnum.Executing) { rpt.CancelExecute(); log += "\r\n\tcanceled on timeout"; } else { rpt.EndExecute(); log += "\r\n\tcompleted, cells=" + rpt.Cellset.Axis0PosCount * rpt.Cellset.Axis1PosCount; } } catch (Exception exc) { log += string.Format("exception \r\n\t\t{0}", exc.Message); errorCount++; } rptCount++; sw = System.IO.File.AppendText(logPath); sw.WriteLine(log); sw.Close(); } } } }