/// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);

            try
            {
                if (properties.ListItem.ContentTypeId.IsChildOf(new SPContentTypeId("0x01010901"))) //pagina de webparts
                {
                    if (MemoryPersisted.Contains(properties.Web.CurrentUser.ID, "NewPageActionReferrer"))
                    {
                        string urlReferrer = MemoryPersisted.Get <string>(properties.Web.CurrentUser.ID, "NewPageActionReferrer");
                        string secao       = MemoryPersisted.Get <string>(properties.Web.CurrentUser.ID, "SecaoMenu");

                        MenuPrincipalAdapter adapter = new MenuPrincipalAdapter(properties.Site.RootWeb);

                        IEnumerable <MenuPrincipal> referrerMenus = adapter.GetByQuery(
                            string.Format("<Where><And><Eq><FieldRef Name=\"{0}\" /><Value Type=\"Text\">{1}</Value></Eq><Contains><FieldRef Name=\"{2}\" /><Value Type=\"Text\">{3}</Value></Contains></And></Where>",
                                          MenuPrincipal.FieldNameURL, urlReferrer, MenuPrincipal.FieldNameSecao, secao));

                        MenuPrincipal referrerUrlMenu = referrerMenus.FirstOrDefault();

                        //if (referrerUrlMenu != null)
                        //{
                        MenuPrincipal newChildMenu = new MenuPrincipal();
                        newChildMenu.Title              = properties.ListItem.File.Name.Remove(properties.ListItem.File.Name.LastIndexOf('.'));
                        newChildMenu.URL                = properties.ListItem.File.ServerRelativeUrl;
                        newChildMenu.Destino            = EmbratelIntranet.Home.Core.Domain.Destino._self;
                        newChildMenu.Secao              = secao;
                        newChildMenu.ParentLookup.Value = referrerUrlMenu;

                        adapter.Add(newChildMenu);
                        //}
                    }
                }
            }
            catch { }
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //try
            //{
            string typeName = Page.Request.QueryString["Executable"];

            if (MemoryPersisted.Contains(Page.Request.Url.ToString()))
            {
                return;
            }

            MemoryPersisted.Set(Page.Request.Url.ToString(), true);

            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentNullException("Executable", "O parâmetro 'Executable' não foi especificado.");
            }

            Type type = null;

            try
            {
                type = Type.GetType(typeName);
            }
            catch (Exception ex)
            {
                throw new ArgumentException(string.Format("O tipo de Executable '{0}' não pôde ser encontrado, verifique se é um tipo válido.", typeName), "Executable");
            }

            if (typeof(IExecutable).IsAssignableFrom(type))
            {
                IExecutable executable;

                try
                {
                    executable = Activator.CreateInstance(type) as IExecutable;
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("Falha ao tentar instanciar o Executable especificado.");
                }

                try
                {
                    executable.Execute(Page, SPContext.Current);
                }
                catch (Exception ex)
                {
                    MemoryPersisted.Remove(Page.Request.Url.ToString());
                    throw ex;
                }
            }
            else
            {
                throw new NotSupportedException("O tipo especificado não implementa 'IExecutable'.");
            }
            //}
            //catch (Exception ex)
            //{
            //    ExceptionManager.Log(ex);
            //}
        }