Esempio n. 1
0
        public void Login(string emailAddress, string Password)
        {
            if (LogEvent != null)
            {
                LogEvent(emailAddress + " Is Logging in");
            }
            // Does the User Exist in the Database?
            using (var db = new DamoclesEntities())
            {
                AddClient(emailAddress);   // Add the User's Client for this logon
                var uid  = User.GetUserID(emailAddress);
                var user = db.Users.First(u => u.UserId == uid);
                user.IsOnline = true;   // Set the User to Online

                int rows = db.SaveChanges();
                UpdateLoginHistory(emailAddress); // Add the User's Logon History

                if (rows == 1)
                {
                    LogEvent(emailAddress + " is Logged In");
                    LoginResultEvent(true);
                }
                else
                {
                    LogEvent(emailAddress + " Failed to Log In");
                    LoginResultEvent(false);
                }
            }
        }
Esempio n. 2
0
        private bool Register(string ClientID, string emailAddress, string Password)
        {
            if (LogEvent != null)
            {
                LogEvent("Registering User");
            }
            using (var db = new DamoclesEntities())
            {
                System.Data.Entity.DbSet <User> users = db.Users;

                var eu = Users.CreateUser(ClientID, emailAddress, Password);

                users.Add(eu);

                int rows = db.SaveChanges();
                if (rows < 1)
                {
                    if (LogEvent != null)
                    {
                        LogEvent("Failed to Add user: " + emailAddress);
                    }
                    return(false);
                }
                else
                {
                    login.UpdateLoginHistory(emailAddress);
                    return(true);
                }
            }
        }
Esempio n. 3
0
        internal void SaveUrl(string URL)
        {
            using (var db = new DamoclesEntities())
            {
                var    urls   = db.URLS;
                string newurl = Utils.DecodeUrlString(URL);

                //TODO: ADD NEW EVENT ADD URL
                AddUrl(URL);
                int row = db.SaveChanges();
                if (row > 1)
                {
                    if (LogEvent != null)
                    {
                        LogEvent("Saved URL To Database " + URL);
                    }
                }
                else
                {
                    if (LogEvent != null)
                    {
                        LogEvent("Failed to Save URL To Database " + URL);
                    }
                }
            }
        }
Esempio n. 4
0
        public void LogOffUser(string Cid)
        {
            if (LogEvent != null)
            {
                LogEvent(Cid + " Is Being Logged Off");
            }
            //TODO: We need to store the User Clients IDs when they Utils.Log on so we can Utils.Log them off properly at the end!
            if (Cid.Contains("-")) // Internally generated IDs do not contains hyphens.
            {
                using (var db = new DamoclesEntities())
                {
                    var user = db.Users.First(u => u.CurrentClientID == Cid);
                    user.IsOnline = false;
                    int    rows         = db.SaveChanges();
                    string emailAddress = User.GetUserEmailAddressByID(Cid);

                    UpdateLogOffHistory(emailAddress);
                    if (rows == 1)
                    {
                        LogEvent(emailAddress + " is Logged Out");
                    }
                    else
                    {
                        LogEvent(emailAddress + " Failed to Log Out");
                    }
                }
            }
        }
Esempio n. 5
0
 private string GetLicenseNumberCount()
 {
     using (var db = new DamoclesEntities())
     {
         int licenses = db.LicenseNumbers.Count();
         return((licenses + 1).ToString());
     }
 }
Esempio n. 6
0
        internal void DeleteAllURLS(DamoclesEntities db)
        {
            if (LogEvent != null)
            {
                LogEvent("Deleting All URLS");
            }
            var all = from c in db.URLS select c;

            db.URLS.RemoveRange(all);
            db.SaveChanges();
        }
Esempio n. 7
0
        public void DeleteAllUsers(DamoclesEntities db)
        {
            if (LogEvent != null)
            {
                LogEvent("Deleting All Users.");
            }
            var all = from c in db.Users select c;

            db.Users.RemoveRange(all);
            db.SaveChanges();
        }
Esempio n. 8
0
 public int GetUserID(string emailAddress)
 {
     if (LogEvent != null)
     {
         LogEvent("Getting User ID from Email");
     }
     using (var db = new DamoclesEntities())
     {
         var user = db.Users.First(u => u.emailAddress == emailAddress);
         return(user.UserId);
     }
 }
Esempio n. 9
0
 public string GetUserEmailAddressByID(string Cid)
 {
     if (LogEvent != null)
     {
         LogEvent("Getting User Email from ID");
     }
     using (var db = new DamoclesEntities())
     {
         var user = db.Users.First(u => u.CurrentClientID == Cid && u.IsOnline == true);
         return(user.emailAddress);
     }
 }
Esempio n. 10
0
        private void SaveUrls(ArrayList alUrls)
        {
            using (var db = new DamoclesEntities())
            {
                DeleteAllUrlsEvent(db);
            }
            foreach (string url in alUrls)
            {

                string newurl = Utils.DecodeUrlString(url);

                AddUrlEvent(newurl);
            }


        }
Esempio n. 11
0
 private void saveLicenseNumber(string ln, string emailAddress)
 {
     using (var db = new DamoclesEntities())
     {
         var lnumber    = db.LicenseNumbers;
         var newlicense = new LicenseNumber();
         newlicense.emailAddress   = emailAddress;
         newlicense.LicenseNumber1 = ln;
         lnumber.Add(newlicense);
         db.SaveChanges();
         if (LogEvent != null)
         {
             LogEvent("Saved License Number");
         }
     }
 }
Esempio n. 12
0
 internal void UpdateUrlInQueueStatus(string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         using (var db = new DamoclesEntities())
         {
             var urls   = db.URLS;
             var result = urls.FirstOrDefault(u => u.URLPath == url);
             result.IsInProcessingQueue = true;
             int rows = db.SaveChanges();
             if (rows < 1)
             {
                 LogEvent("Failed to Set Url to IsInProcessingQueue = True " + url);
             }
         }
     }
 }
Esempio n. 13
0
        internal void URLSCount()
        {
            if (LogEvent != null)
            {
                LogEvent("Counting URLS");
            }

            using (var db = new DamoclesEntities())
            {
                var  urls   = db.URLS;
                long result = urls.LongCount();
                if (LogEvent != null)
                {
                    LogEvent("Number of URLS in Database: " + result.ToString("N0"));
                }
                UrlsCountResultEvent(result);
            }
        }
Esempio n. 14
0
        internal void SeedUsers()
        {
            if (LogEvent != null) LogEvent("Seeding Users");
            using (var db = new DamoclesEntities())
            {
                //  Users.DeleteAllUsers(db);

                var usrs = db.Users;
                var su = new User();
                var em = "*****@*****.**";
                SeedAdminUser(db, usrs, su, em);

                su = new User();
                em = "*****@*****.**";
                SeedSystemUser(db, usrs, su, em);

            }
        }
Esempio n. 15
0
 private void SeedAdminUser(DamoclesEntities db, System.Data.Entity.DbSet<User> usrs, User su, string em)
 {
     if (LogEvent != null) LogEvent("Seeding Admin User");
     su.emailAddress = em;
     su.UserPasswordHash = "097dfd905dfa0e078883b7afcf7e653dde569bb1ed2ce3384d9c9ed7b85741d6e8d1b1a356318805d3c8b31b36a9916936d005d8134fb015d0392cf75cd7fa24";
     su.RegisteredDate = DateTime.UtcNow;
     su.CountryId = 3;
     su.StateId = 2;
     su.JurisidictionId = 4;
     su.LanguagesId = 1;
     su.IsOnline = false;
     su.AccountStatusId = 3;
     //   su.LicenseNumber = license.GenerateTemporaryLicenseNumber(em);
     su.emailAddress = em;
     su.UserClientID = null;
     su.CurrentClientID = null;
     usrs.Add(su);
     db.SaveChanges();
 }
Esempio n. 16
0
        private void UpdateLogOffHistory(string emailAddress)
        {
            if (LogEvent != null)
            {
                LogEvent("Updating Users LogOff History");
            }
            using (var db = new DamoclesEntities())
            {
                var uid = User.GetUserID(emailAddress);
                var loh = db.LogonHistories.First(lh => lh.LoggedOffDate == null && lh.UserId == uid);
                loh.LoggedOffDate = DateTime.UtcNow;
                db.SaveChanges();


                var us = db.Users.First(u => u.UserId == uid);
                us.IsOnline        = false;
                us.CurrentClientID = null;
                db.SaveChanges();
            }
        }
Esempio n. 17
0
 public void UpdateLoginHistory(string emailAddress)
 {
     if (LogEvent != null)
     {
         LogEvent("User's Logon History is being Created.");
     }
     using (var db = new DamoclesEntities())
     {
         var loh  = db.LogonHistories;
         var lohe = new LogonHistory();
         lohe.LoggedOnDate = DateTime.UtcNow;
         lohe.UserId       = User.GetUserID(emailAddress);
         loh.Add(lohe);
         int rows = db.SaveChanges();
         if (rows < 1)
         {
             LogEvent(emailAddress + " Failed to Add User's Logon History Record ");
         }
     }
 }
Esempio n. 18
0
        private int AddClient(string emailAddress)
        {
            if (LogEvent != null)
            {
                LogEvent(emailAddress + " Is Being Added in");
            }
            int rid = 0;

            using (var db = new DamoclesEntities())
            {
                var c       = db.Clients;
                var nclient = new Client();
                nclient.RaptorClientID = emailAddress;
                nclient.UserId         = User.GetUserID(emailAddress);
                c.Add(nclient);
                db.SaveChanges();
                rid = nclient.ClientsID;

                return(rid);
            }
        }
Esempio n. 19
0
        internal long UrlsToProcessCount()
        {
            if (LogEvent != null)
            {
                LogEvent("Counting URLS that still need to be processed");
            }
            long result = -1;

            using (var db = new DamoclesEntities())
            {
                var urls = db.URLS;
                result = urls.Where(u => u.IsInProcessingQueue == false).LongCount();
                if (result > 0)
                {
                    if (MoreUrlsLeftToProcessEvent != null)
                    {
                        MoreUrlsLeftToProcessEvent();
                    }
                    if (LogEvent != null)
                    {
                        LogEvent("Number of URLS To Process in Database: " + result.ToString("N0"));
                    }
                    StopURLMonitor();
                }
                else
                {
                    if (LogEvent != null)
                    {
                        LogEvent("NO URLS Left to be processed");
                    }
                    if (NoUrlsLeftToProcessEvent != null)
                    {
                        NoUrlsLeftToProcessEvent();
                    }
                    StartURLMonitor();
                }

                return(result);
            }
        }
Esempio n. 20
0
        internal void PopulateURLQueue(long numberOfUrlsToGet)
        {
            StopURLMonitor();
            long toprocess = UrlsToProcessCount();

            if (toprocess > 0)
            {
                if (toprocess < numberOfUrlsToGet)
                {
                    numberOfUrlsToGet = toprocess;
                }
                if (LogEvent != null)
                {
                    LogEvent("Populating URL Queue, Adding " + numberOfUrlsToGet);
                }
                if (ProgressMaximumChangedEvent != null)
                {
                    ProgressMaximumChangedEvent(int.Parse(numberOfUrlsToGet.ToString()));
                }

                using (var db = new DamoclesEntities())
                {
                    var urls = db.URLS;
                    for (int idx = 0; idx < numberOfUrlsToGet; idx++)
                    {
                        var result = urls.FirstOrDefault(u => u.IsInProcessingQueue == false);
                        var urlp   = result.URLPath;
                        result.JoinedProcessingQueueDate = DateTime.UtcNow;
                        urlQueue.Enqueue(urlp);
                        if (ProgressMaximumChangedEvent != null && ProgressChangedEvent != null)
                        {
                            ProgressChangedEvent(idx);
                        }
                        SetUrlToInProcessingQueue(urlp);
                        db.SaveChanges();
                    }
                }
                if (ProgressMaximumChangedEvent != null && ProgressChangedEvent != null)
                {
                    ProgressChangedEvent(0);
                }
                if (LogEvent != null)
                {
                    LogEvent("Populating URL Queue Completed ");
                }
                if (MoreUrlsLeftToProcessEvent != null)
                {
                    MoreUrlsLeftToProcessEvent();                                     // Tell the main program it can start sending URLS again
                }
            }
            else
            {
                // This is a FATAL Problem, It may require
                // Manually Adding more URLS
                // Returning URLS that have been in the processing queue for a shorter than normal period of time to be returned to the processing queue
                // This event should not be fired in normal operations but can occur during debugging.
                if (LogEvent != null)
                {
                    LogEvent("Failed to Populate URL Queue - there are no URLS left to Process");
                }
                if (NoUrlsLeftToProcessEvent != null)
                {
                    NoUrlsLeftToProcessEvent();
                }
                StartURLMonitor();
            }
        }