Exemple #1
0
        /// <summary>
        /// Correctly sets the CSLA principal/Identity
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected async Task Application_AuthenticateRequest(object sender, EventArgs e)
        {
            var formsCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (formsCookie != null)
            {
                var authenticationToken = FormsAuthentication.Decrypt(formsCookie.Value);
                if (authenticationToken != null)
                {
                    var customPrincipal = await CustomPrincipal.LoadAsync(authenticationToken.Name);

                    ApplicationContext.User = customPrincipal;
                }
            }
        }
Exemple #2
0
        public async Task StartAsync()
        {
            while (true)
            {
                try
                {
                    var fileName = FileLocation;
                    if (System.IO.File.Exists(fileName))
                    {
                        var connectionString =
                            string.Format(
                                "Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;",
                                fileName);

                        var administrator = await CustomPrincipal.LoadAsync("JustinW");

                        ApplicationContext.User = administrator;
                        using (var adapter = new OleDbDataAdapter("SELECT * FROM [Data$]", connectionString))
                        {
                            var ds = new DataSet();

                            adapter.Fill(ds, "ActivityData");

                            DataTable data = ds.Tables["ActivityData"];
                            foreach (DataRow row in data.Rows)
                            {
                                var activityId   = row.Field <Double>("Activity Id");
                                var adName       = row.Field <string>("Magenic Username");
                                var dateOccurred = row.Field <DateTime>("Date Occurred");
                                var comments     = row.Field <string>("Comments");

                                ICslaPrincipal employee = null;
                                try
                                {
                                    employee = await CustomPrincipal.LoadAsync(adName);
                                }
                                catch (Exception ex)
                                {
                                    Logger.Error <ADProcessor>(ex.Message, ex);
                                }

                                if (employee != null)
                                {
                                    var activitySubmission = SubmitActivity.CreateActivitySubmission(((ICustomIdentity)administrator.Identity).EmployeeId);
                                    activitySubmission.ActivityId             = (int)activityId;
                                    activitySubmission.EmployeeId             = ((ICustomIdentity)employee.Identity).EmployeeId;
                                    activitySubmission.ActivitySubmissionDate = dateOccurred;
                                    activitySubmission.Notes = comments;
                                    await activitySubmission.SaveAsync();
                                }
                            }
                        }
                        System.IO.File.Delete(fileName);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error <ADProcessor>(ex.Message, ex);
                }
                finally
                {
                    Thread.Sleep(SleepInterval);
                }
            }
        }