コード例 #1
0
        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            // Map the Custom routes
            DialogueRoutes.MapRoutes(RouteTable.Routes, UmbracoContext.Current.ContentCache);

            //list to the init event of the application base, this allows us to bind to the actual HttpApplication events
            UmbracoApplicationBase.ApplicationInit += UmbracoApplicationBase_ApplicationInit;

            MemberService.Saved += MemberServiceSaved;
            MemberService.Deleting += MemberServiceOnDeleting;
            ContentService.Trashing +=ContentService_Trashing;

            PageCacheRefresher.CacheUpdated += PageCacheRefresher_CacheUpdated;

            // Sync the badges
            // Do the badge processing
            var unitOfWorkManager = new UnitOfWorkManager(ContextPerRequest.Db);
            using (var unitOfWork = unitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    ServiceFactory.BadgeService.SyncBadges();
                    unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    AppHelpers.LogError(string.Format("Error processing badge classes: {0}", ex.Message));
                }
            }

        }
コード例 #2
0
        private static void MemberServiceOnDeleting(IMemberService sender, DeleteEventArgs<IMember> deleteEventArgs)
        {

            var memberService = new Services.MemberService();
            var unitOfWorkManager = new UnitOfWorkManager(ContextPerRequest.Db);
            using (var unitOfWork = unitOfWorkManager.NewUnitOfWork())
            {
                try
                {
                    foreach (var member in deleteEventArgs.DeletedEntities)
                    {
                        var canDelete = memberService.DeleteAllAssociatedMemberInfo(member.Id, unitOfWork);
                        if (!canDelete)
                        {
                            deleteEventArgs.Cancel = true;
                            //TODO - THIS DOESN'T WORK - JUST LOG IT
                            //var clientTool = new ClientTools((Page)HttpContext.Current.CurrentHandler);
                            //clientTool.ShowSpeechBubble(SpeechBubbleIcon.Error, "Error", "Unable to delete member. Check logfile for further information");
                            AppHelpers.LogError(string.Format("There was an error attemping to delete member {0} and all of their associated data (Posts, Topics etc...)", member.Name));

                            break;

                        }
                    }

                }
                catch (Exception ex)
                {
                    AppHelpers.LogError("Error attempting to delete members", ex);
                }
            }

        }
コード例 #3
0
        protected void UploadMembers(object sender, EventArgs e)
        {
            
            if (fuXml.HasFile)
            {
                // Upload file to App_Data temp folder
                var xmlFilepath = Server.MapPath("~/App_Data/TEMP/memberimport.xml");
                fuXml.SaveAs(xmlFilepath);

                // Once saved load xml
                var xml = new XmlDocument();
                xml.Load(xmlFilepath);

                // Now loop through the members
                var allMembers = xml.SelectNodes("//member");

                // Do we have any members
                if (allMembers != null && allMembers.Count > 0)
                {
                    // Store all mapped members
                    var members = new List<MemberImport>();

                    // Yes, we have members - So map them
                    foreach (XmlNode mem in allMembers)
                    {
                        var import = MapImport(mem);
                        if (import != null)
                        {
                            members.Add(import);   
                        }
                    }

                    //TODO - Refactor - Must be a more performant way of mass creating members

                    var memService = AppHelpers.UmbServices().MemberService;
                    var memHelper = AppHelpers.UmbMemberHelper();

                    var memberGroupService = AppHelpers.UmbServices().MemberGroupService;
                    var startingGroup = memberGroupService.GetByName(AppConstants.MemberGroupDefault);
                    var adminGroup = memberGroupService.GetByName(AppConstants.AdminRoleName);

                    var unitOfWorkManager = new UnitOfWorkManager(ContextPerRequest.Db);
                    var pointService = ServiceFactory.MemberPointsService;
                    using (var unitOfWork = unitOfWorkManager.NewUnitOfWork())
                    {
                        try
                        {
                            foreach (var newmem in members)
                            {
                                //var m = memService.CreateMemberWithIdentity("username", "email", "name", AppConstants.MemberTypeAlias);

                                var userToSave = memHelper.CreateRegistrationModel(AppConstants.MemberTypeAlias);
                                userToSave.Username = ServiceFactory.BannedWordService.SanitiseBannedWords(newmem.Username);
                                userToSave.Name = userToSave.Username;
                                userToSave.UsernameIsEmail = false;
                                userToSave.Email = newmem.Email;
                                userToSave.Password = Membership.GeneratePassword(10, 1);

                                MembershipCreateStatus createStatus;
                                memHelper.RegisterMember(userToSave, out createStatus, false);

                                if (createStatus == MembershipCreateStatus.Success)
                                {
                                    // Get the umbraco member
                                    var umbracoMember = memService.GetByUsername(userToSave.Username);

                                    // Set the role/group they should be in
                                    if (newmem.IsAdmin)
                                    {
                                        // Add to admin role
                                        memService.AssignRole(umbracoMember.Id, adminGroup.Name);

                                        // Add can edit member property
                                        umbracoMember.Properties[AppConstants.PropMemberCanEditOtherUsers].Value = newmem.IsAdmin;
                                    }
                                    else
                                    {
                                        // Standard role
                                        memService.AssignRole(umbracoMember.Id, startingGroup.Name);
                                    }

                                    // Add points
                                    if (newmem.Points > 0)
                                    {
                                        // Create the DB points
                                        var points = new MemberPoints
                                        {
                                            DateAdded = DateTime.Now,
                                            MemberId = umbracoMember.Id,
                                            Points = newmem.Points
                                        };
                                        pointService.Add(points);
                                    }

                                    // Do a save on the member
                                    memService.Save(umbracoMember);
                                }
                                else
                                {
                                    //TODO- Show errors to the user
                                }

                                Server.ScriptTimeout = 600;
                            }

                            // Commit the transaction
                            unitOfWork.Commit();

                            // Yes
                            pnlResults.Controls.Add(new LiteralControl("Success - Members Imported"));
                            pnlResults.Visible = true;   
                        }
                        catch (Exception ex)
                        {
                            // Roll back database changes 
                            unitOfWork.Rollback();

                            // No
                            pnlResults.Controls.Add(new LiteralControl("There was an error during import"));
                            pnlResults.Visible = true;   
                        }
                    }
                }
                else
                {
                    // No
                    pnlResults.Controls.Add(new LiteralControl("No members found in the XML"));
                    pnlResults.Visible = true;                    
                }
            }
            else
            {
                pnlResults.Controls.Add(new LiteralControl("No file selected"));
                pnlResults.Visible = true;
            }
        }