예제 #1
0
        // Methods
        public override void FieldAdded(SPListEventProperties properties)
        {
            string      fieldXml = properties.FieldXml;
            XmlDocument document = new XmlDocument();

            document.LoadXml(properties.FieldXml);
            XmlElement documentElement = document.DocumentElement;

            if (documentElement.Attributes["Status"] != null)
            {
                switch (documentElement.Attributes["Status"].Value)
                {
                case "Disable":
                    properties.Field.ReadOnlyField = true;
                    break;

                case "Hide":
                    properties.Field.Hidden = true;
                    break;
                }
            }
            string schemaXmlWithResourceTokens = properties.Field.SchemaXmlWithResourceTokens;
            string xPath = properties.Field.XPath;

            base.FieldAdded(properties);
        }
예제 #2
0
        public override void FieldAdded(SPListEventProperties properties)
        {
            // Если добавляется поле SPFileField, то подписываемся на удаление элементов, чтобы удалять связные файлы
            if (properties.Field.TypeDisplayName == SPFileFieldName)
            {
                // Пробуем добавить EventReceiver, если его нет
                bool eventReceiverExists = false;
                for (int i = 0; i < properties.List.EventReceivers.Count; i++)
                {
                    if (properties.List.EventReceivers[i].Class ==
                        ER_OnItemDeleting.ER_OnItemDeleting.ER_OnItemDeletingName)
                    {
                        eventReceiverExists = true;
                        break;
                    }
                }

                if (!eventReceiverExists)
                {
                    properties.List.EventReceivers.Add(SPEventReceiverType.ItemDeleting,
                                                       Assembly.GetExecutingAssembly().FullName,
                                                       ER_OnItemDeleting.ER_OnItemDeleting.ER_OnItemDeletingName);
                }
            }

            base.FieldAdded(properties);
        }
        public override void FieldAdded(SPListEventProperties properties)
        {
            // Если добавляется поле SPFileField, то подписываемся на удаление элементов, чтобы удалять связные файлы
            if (properties.Field.TypeDisplayName == SPFileFieldName)
            {
                // Пробуем добавить EventReceiver, если его нет
                bool eventReceiverExists = false;
                for (int i = 0; i < properties.List.EventReceivers.Count;i++)
                {
                    if (properties.List.EventReceivers[i].Class ==
                        ER_OnItemDeleting.ER_OnItemDeleting.ER_OnItemDeletingName)
                    {
                        eventReceiverExists = true;
                        break;
                    }
                }

                if (!eventReceiverExists)
                {
                    properties.List.EventReceivers.Add(SPEventReceiverType.ItemDeleting, 
                                                       Assembly.GetExecutingAssembly().FullName, 
                                                       ER_OnItemDeleting.ER_OnItemDeleting.ER_OnItemDeletingName);
                }
            }

            base.FieldAdded(properties);
        }
        // Public Methods (2) 

        /// <summary>
        ///     A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            //try
            //{
            //    if (properties.Web.CurrentUser.ID != properties.Web.Site.SystemAccount.ID)
            //    {
            //        try
            //        {
            //            ListCommands.MapListToReporting(properties.List);
            //        }
            //        catch { }

            //        try
            //        {
            //            ListCommands.SaveIconToReporting(properties.List);
            //        }
            //        catch { }

            //        if (properties.List.BaseType != SPBaseType.DocumentLibrary)
            //        {
            //            try
            //            {
            //                ListCommands.InstallListsViewsWebparts(properties.List);
            //            }
            //            catch { }
            //        }
            //    }
            //}
            //catch { }

            ClearCache(properties);
        }
 public override void FieldDeleting(SPListEventProperties properties)
 {
     if (this.UpdateCacheDataTable(properties, true))
     {
         base.FieldDeleting(properties);
     }
 }
예제 #6
0
        private bool AddField(SPListEventProperties properties)
        {
            bool   isSuccessful = true;
            string tableName    = string.Empty;
            string ssTableName  = string.Empty;
            var    rb           = new ReportBiz(properties.SiteId);

            try
            {
                var rd   = new ReportData(properties.SiteId);
                var cols = new ColumnDefCollection();
                tableName   = rd.GetTableName(properties.ListId);
                ssTableName = rd.GetTableNameSnapshot(properties.ListId);

                if (!rd.ColumnExists(tableName, properties.Field.InternalName))
                {
                    cols.AddColumn(properties.Field);
                    rd.AddColumns(tableName, cols);
                    rd.AddColumns(ssTableName, cols);
                    rd.InsertListColumns(properties.ListId, cols);
                }
                rd.Dispose();
            }
            catch (Exception ex)
            {
                var DAO = new EPMData(properties.SiteId);
                DAO.LogStatus(properties.ListId.ToString(), properties.FieldName,
                              "Database column add attempt: Unable to add column " + properties.FieldName + ". " + ex.Message,
                              ex.StackTrace, 2, 5, Guid.NewGuid().ToString()); //Logged in the RefreshAll event log.
                DAO.Dispose();
            }

            if (properties.Field is SPFieldLookup)
            {
                try
                {
                    //FOREIGN IMPLEMENTATION -- START
                    var DAO = new EPMData(properties.SiteId);
                    rb.UpdateForeignKeys(DAO);
                    DAO.Dispose();
                    // -- END
                }
                catch (Exception ex)
                {
                    isSuccessful = false;
                    SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        if (!EventLog.SourceExists("EPMLive Reporting - UpdateForeignKeys"))
                        {
                            EventLog.CreateEventSource("EPMLive Reporting - UpdateForeignKeys", "EPM Live");
                        }

                        LogEntry(ex, "EPMLive Reporting - UpdateForeignKeys");
                    });
                }
            }

            return(isSuccessful);
        }
        // Private Methods (1) 

        private void ClearCache(SPListEventProperties properties)
        {
            try
            {
                CacheStore.Current.RemoveSafely(properties.WebUrl, new CacheStoreCategory(properties.Web).Navigation);
            }
            catch { }
        }
예제 #8
0
        public override void FieldUpdated(SPListEventProperties properties)
        {
            if (properties.Field.InternalName.ToLower() == "today")
            {
                return;
            }

            UpdateField(properties);
        }
예제 #9
0
        // Methods
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdded(properties);
            SPList        list  = properties.List;
            SPList        list2 = properties.Web.GetList("/Lists/Contracts");
            SPContentType type  = list.ContentTypes[0];

            type.NewFormUrl     = "/_Layouts/15/FrameWork/Pages/NewForm/index.html";
            type.EditFormUrl    = "/_Layouts/15/FrameWork/Pages/EditForm/index.html";
            type.DisplayFormUrl = "/_Layouts/15/FrameWork/Pages/DisplayForm/index.html";
            type.Update();
            list.Update();
        }
예제 #10
0
        public override void FieldDeleting(SPListEventProperties properties)
        {
            if (properties.Field.TypeDisplayName == SPFileFieldName)
            {
                // Если удаляется столбец SPFileField, то
                // 1) Удаляем все связные файлы, если они есть
                for (int i = 0; i < properties.List.Items.Count; i++)
                {
                    SPListItem splistItem = properties.List.Items[i];
                    FileValue  fileValue  = splistItem[properties.Field.StaticName] as FileValue;

                    if (fileValue == null)
                    {
                        continue;
                    }

                    SPFile spFile = properties.Web.GetFile(fileValue.UniqueID);
                    spFile.Delete();
                }

                // Проверяем, останутся ли после удаления столбцы типа SPFileField
                bool anyFileFieldExist = false;
                for (int i = 0; i < properties.List.Fields.Count; i++)
                {
                    if (properties.List.Fields[i].TypeAsString == SPFileFieldName &&
                        properties.List.Fields[i].StaticName != properties.Field.StaticName)
                    {
                        anyFileFieldExist = true;
                        break;
                    }
                }

                // 2) Отписываемся от триггера, если больше нет колонок типа SPFileField
                if (!anyFileFieldExist)
                {
                    for (int i = 0; i < properties.List.EventReceivers.Count;)
                    {
                        if (properties.List.EventReceivers[i].Class == ER_OnItemDeleting.ER_OnItemDeleting.ER_OnItemDeletingName)
                        {
                            properties.List.EventReceivers[i].Delete();
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
            }

            base.FieldDeleting(properties);
        }
        public override void FieldDeleting(SPListEventProperties properties)
        {
            if (properties.Field.TypeDisplayName == SPFileFieldName)
            {
                // Если удаляется столбец SPFileField, то
                // 1) Удаляем все связные файлы, если они есть
                for (int i = 0; i < properties.List.Items.Count; i++)
                {
                    SPListItem splistItem = properties.List.Items[i];
                    FileValue fileValue = splistItem[properties.Field.StaticName] as FileValue;

                    if (fileValue == null)
                        continue;

                    SPFile spFile = properties.Web.GetFile(fileValue.UniqueID);
                    spFile.Delete();
                }

                // Проверяем, останутся ли после удаления столбцы типа SPFileField
                bool anyFileFieldExist = false;
                for (int i = 0; i < properties.List.Fields.Count; i++)
                {
                    if (properties.List.Fields[i].TypeAsString == SPFileFieldName
                        && properties.List.Fields[i].StaticName != properties.Field.StaticName)
                    {
                        anyFileFieldExist = true;
                        break;
                    }
                }

                // 2) Отписываемся от триггера, если больше нет колонок типа SPFileField
                if (!anyFileFieldExist)
                {
                    for (int i = 0; i < properties.List.EventReceivers.Count; )
                    {
                        if (properties.List.EventReceivers[i].Class == ER_OnItemDeleting.ER_OnItemDeleting.ER_OnItemDeletingName)
                        {
                            properties.List.EventReceivers[i].Delete();
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
            }

            base.FieldDeleting(properties);
        }
        /// <summary>
        /// A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdded(properties);

            XmlDocument doc;
            string _path;

            SPContentTypeCollection contentTypeColl = properties.List.ContentTypes;

            if (contentTypeColl.Count > 0)
            {
                foreach (SPContentType contentType in contentTypeColl)
                {
                    if (contentType.Name == "BrickRed.Facebook.ContentType")
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            try
                            {
                                doc = GetXMLFIle(out _path);
                                if (doc != null)
                                {

                                    XmlNode Node = doc.CreateElement("Content");

                                    XmlNode listName = doc.CreateElement("ListName");
                                    XmlNode siteURL = doc.CreateElement("SiteURL");

                                    listName.InnerText = properties.ListTitle;
                                    siteURL.InnerText = properties.WebUrl;

                                    Node.AppendChild(listName);
                                    Node.AppendChild(siteURL);

                                    doc.SelectSingleNode("Facebook/Contents").AppendChild(Node);
                                    doc.Save(_path);

                                }
                            }
                            catch (Exception ex)
                            {
                                throw (new SPException("List Added Event Reciever: " + ex.Message));
                            }
                        });
                    }
                }
            }
        }
        /// <summary>
        /// A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdded(properties);

            XmlDocument doc;
            string      _path;

            SPContentTypeCollection contentTypeColl = properties.List.ContentTypes;

            if (contentTypeColl.Count > 0)
            {
                foreach (SPContentType contentType in contentTypeColl)
                {
                    if (contentType.Name == "BrickRed.Facebook.ContentType")
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            try
                            {
                                doc = GetXMLFIle(out _path);
                                if (doc != null)
                                {
                                    XmlNode Node = doc.CreateElement("Content");

                                    XmlNode listName = doc.CreateElement("ListName");
                                    XmlNode siteURL  = doc.CreateElement("SiteURL");

                                    listName.InnerText = properties.ListTitle;
                                    siteURL.InnerText  = properties.WebUrl;

                                    Node.AppendChild(listName);
                                    Node.AppendChild(siteURL);

                                    doc.SelectSingleNode("Facebook/Contents").AppendChild(Node);
                                    doc.Save(_path);
                                }
                            }
                            catch (Exception ex)
                            {
                                throw (new SPException("List Added Event Reciever: " + ex.Message));
                            }
                        });
                    }
                }
            }
        }
예제 #14
0
        public override void FieldAdded(SPListEventProperties properties)
        {
            try
            {
                _stCurrentContext.Session["ViewSession"] = null;
            }
            catch
            {
            }

            if (properties.Field.InternalName.ToLower() == "today")
            {
                return;
            }

            AddField(properties);
        }
        private bool UpdateCacheDataTable(SPListEventProperties properties, bool isDeleted = false)
        {
            const string errorMessage = "Произошла ошибка при изменении кеша.";

            try
            {
                bool            result    = false;
                List <SyncType> syncTypes = SettingsProvider.Instance(properties.Web).CacheType(properties.List);

                ISpSyncProvider syncProvider;
                switch (syncTypes.Count)
                {
                case 0:
                    return(false);

                case 1:
                    syncProvider = new SpSyncProvider(syncTypes.FirstOrDefault());
                    result       = syncProvider.UpdateDataTableColumns(properties.List, properties.FieldXml, isDeleted);
                    break;

                default:
                    foreach (SyncType syncType in syncTypes)
                    {
                        syncProvider = new SpSyncProvider(syncType);
                        result       = syncProvider.UpdateDataTableColumns(properties.List, properties.FieldXml, isDeleted);
                    }
                    break;
                }

                if (result)
                {
                    return(true);
                }

                throw new Exception(errorMessage);
            }
            catch (Exception ex)
            {
                Logger.WriteError(ex.Message, "ListChangeReceiver.UpdateCacheDataTable()");

                properties.Status       = SPEventReceiverStatus.CancelWithError;
                properties.ErrorMessage = errorMessage;
                return(false);
            }
        }
        /// <summary>
        /// Log list event properties
        /// </summary>
        /// <param name="properties"></param>
        private void LogListEventProperties(SPListEventProperties properties)
        {
            //  Specify log list name
            string listName = "ListEventLogger";

            //  Create the string builder object
            StringBuilder sb = new StringBuilder();

            //  Add properties the don't throw exceptions
            sb.AppendFormat("Cancel: {0}\n", properties.Cancel);
            sb.AppendFormat("ErrorMessage: {0}\n", properties.ErrorMessage);
            sb.AppendFormat("EventType: {0}\n", properties.EventType);
            sb.AppendFormat("FeatureId: {0}\n", properties.FeatureId);
            sb.AppendFormat("FieldName: {0}\n", properties.FieldName);
            sb.AppendFormat("FieldXml: {0}\n", properties.FieldXml);
            sb.AppendFormat("ListId: {0}\n", properties.ListId);
            sb.AppendFormat("ListTitle: {0}\n", properties.ListTitle);
            sb.AppendFormat("ReceiverData: {0}\n", properties.ReceiverData);
            sb.AppendFormat("RedirectUrl: {0}\n", properties.RedirectUrl);
            sb.AppendFormat("SiteId: {0}\n", properties.SiteId);
            sb.AppendFormat("Status: {0}\n", properties.Status);
            sb.AppendFormat("TemplateId: {0}\n", properties.TemplateId);
            sb.AppendFormat("UserDisplayName: {0}\n", properties.UserDisplayName);
            sb.AppendFormat("UserLoginName: {0}\n", properties.UserLoginName);
            sb.AppendFormat("WebId: {0}\n", properties.WebId);
            sb.AppendFormat("WebUrl: {0}\n", properties.WebUrl);
            sb.AppendFormat("Web: {0}\n", properties.Web);
            sb.AppendFormat("List: {0}\n", properties.List);

            //  Add properties that might throw an exception
            try
            {
                sb.AppendFormat("Field: {0}\n", properties.Field);
            }
            catch (Exception e)
            {
                sb.AppendFormat("\nError accessing properties.Field:\n\n {0}", e);
            }

            //  Log the event to the list
            this.EventFiringEnabled = false;
            Common.LogEvent(properties.Web, listName, properties.EventType, sb.ToString());
            this.EventFiringEnabled = true;
        }
예제 #17
0
        /// <summary>
        /// A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdded(properties);

            if (properties.TemplateId.ToString() == ListTemplateIds.NEWS_TEMPLATE_ID)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(properties.SiteId))
                    {
                        using (SPWeb web = site.OpenWeb(properties.Web.ID))
                        {
                            try
                            {
                                EventFiringEnabled     = false;
                                web.AllowUnsafeUpdates = true;

                                var list = web.Lists[properties.ListId];

                                // create new view with custom webpart
                                CreateNewsListView(web, list);

                                // create new Display form with custom webpart
                                CreateDisplayForm(web, list);

                                // add webpart to News's homepage
                                CreateWebpartInNewsHomepage(web, list);
                            }
                            catch (Exception ex)
                            {
                                Utility.LogError(ex.Message + ex.StackTrace, "News Event Receiver");
                            }
                            finally
                            {
                                web.AllowUnsafeUpdates = false;
                                EventFiringEnabled     = true;
                            }
                        }
                    }
                });
            }
        }
예제 #18
0
        /// <summary>
        /// A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdded(properties);

               if (properties.TemplateId.ToString() == ListTemplateIds.NEWS_TEMPLATE_ID)
               {
               SPSecurity.RunWithElevatedPrivileges(delegate()
               {
                   using (SPSite site = new SPSite(properties.SiteId))
                   {
                       using (SPWeb web = site.OpenWeb(properties.Web.ID))
                       {
                           try
                           {
                               EventFiringEnabled = false;
                               web.AllowUnsafeUpdates = true;

                               var list = web.Lists[properties.ListId];

                               // create new view with custom webpart
                               CreateNewsListView(web, list);

                               // create new Display form with custom webpart
                               CreateDisplayForm(web, list);

                               // add webpart to News's homepage
                               CreateWebpartInNewsHomepage(web, list);
                           }
                           catch (Exception ex)
                           {
                               Utility.LogError(ex.Message + ex.StackTrace, "News Event Receiver");
                           }
                           finally
                           {
                               web.AllowUnsafeUpdates = false;
                               EventFiringEnabled = true;
                           }
                       }
                   }
               });
               }
        }
예제 #19
0
        /// <summary>
        /// A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdded(properties);
            this.EventFiringEnabled = false;
            try
            {
                var fields = properties.List.Fields.Cast <SPField>().ToList();

                var imageFields = fields.Where(p => p.TypeAsString == Constants.IMAGE_FIELD_TYPE_NAME).ToList();
                //var lkwithPickerFields = fields.Where(p => p.TypeAsString == Constants.LOOKUP_WITH_PICKER_TYPE_NAME).ToList();

                foreach (var item in imageFields)
                {
                    var currentWeb = item.ParentList.ParentWeb;
                    var list       = currentWeb.Lists[currentWeb.Folders["NewsImages"].ParentListId];

                    item.UpdateImageField(item.ParentList.ParentWeb, list);
                }

                /*
                 * foreach (LookupFieldWithPicker item in lkwithPickerFields)
                 * {
                 *  if (!item.LookupList.IsGuid())
                 *  {
                 *      var root = properties.List.ParentWeb.Site.RootWeb;
                 *      var list = root.GetList(item.LookupList);
                 *      System.Collections.Generic.Dictionary<string, object> props = new System.Collections.Generic.Dictionary<string, object>();
                 *      props.Add("WebId", root.ID);
                 *      props.Add("ListId", list.ID);
                 *      item.UpdateProperties(props);
                 *  }
                 * }
                 */
            }
            catch (Exception ex)
            {
            }
            finally
            {
                this.EventFiringEnabled = false;
            }
        }
        /// <summary>
        /// A list was added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdded(properties);
               this.EventFiringEnabled = false;
               try
               {
               var fields = properties.List.Fields.Cast<SPField>().ToList();

               var imageFields = fields.Where(p => p.TypeAsString == Constants.IMAGE_FIELD_TYPE_NAME).ToList();
               //var lkwithPickerFields = fields.Where(p => p.TypeAsString == Constants.LOOKUP_WITH_PICKER_TYPE_NAME).ToList();

               foreach (var item in imageFields)
               {
                   var currentWeb = item.ParentList.ParentWeb;
                   var list = currentWeb.Lists[currentWeb.Folders["NewsImages"].ParentListId];

                   item.UpdateImageField(item.ParentList.ParentWeb, list);
               }

               /*
               foreach (LookupFieldWithPicker item in lkwithPickerFields)
               {
                   if (!item.LookupList.IsGuid())
                   {
                       var root = properties.List.ParentWeb.Site.RootWeb;
                       var list = root.GetList(item.LookupList);
                       System.Collections.Generic.Dictionary<string, object> props = new System.Collections.Generic.Dictionary<string, object>();
                       props.Add("WebId", root.ID);
                       props.Add("ListId", list.ID);
                       item.UpdateProperties(props);
                   }
               }
               */
               }
               catch (Exception ex)
               {
               }
               finally
               {
               this.EventFiringEnabled = false;
               }
        }
예제 #21
0
 /// <summary>
 ///     A list was deleted.
 /// </summary>
 public override void ListDeleting(SPListEventProperties properties)
 {
     try
     {
         if (!properties.List.Hidden)
         {
             SocialEngine.Current.ProcessActivity(ObjectKind.List, ActivityKind.Deleted,
                                                  new Dictionary <string, object>
             {
                 { "Id", properties.ListId },
                 { "Title", properties.ListTitle },
                 { "URL", properties.List.DefaultViewUrl },
                 { "WebId", properties.WebId },
                 { "UserId", properties.Web.CurrentUser.ID },
                 { "ActivityTime", DateTime.Now }
             }, properties.Web);
         }
     }
     catch { }
 }
예제 #22
0
        /// <summary>
        /// A list has been added.
        /// </summary>
        public override void ListAdded(SPListEventProperties properties)
        {
            base.ListAdding(properties);

            if (properties.FeatureId != new Guid("1e084611-a8c5-449c-a1f0-841a56ee2712") || properties.TemplateId != 10001)
            {
                return;
            }

            //Make the entity part content types not visible on the new button.
            var documentStoreEntityPartContentTypeId = new SPContentTypeId(Constants.DocumentStoreEntityPartContentTypeId);
            var attachmentContentTypeId = new SPContentTypeId(Constants.DocumentStoreEntityAttachmentContentTypeId);

            var contentTypes = properties.List.RootFolder.ContentTypeOrder.ToList();

            foreach (var ct in contentTypes.ToList())
            {
                var shouldHide = false;
                if (ct.Id.IsChildOf(documentStoreEntityPartContentTypeId))
                {
                    shouldHide = true;
                }
                else if (ct.Id.IsChildOf(attachmentContentTypeId))
                {
                    shouldHide = true;
                }
                else if (ct.Id.IsChildOf(SPBuiltInContentTypeId.LinkToDocument))
                {
                    shouldHide = true;
                }

                if (!shouldHide)
                {
                    continue;
                }

                contentTypes.Remove(ct);
            }
            properties.List.RootFolder.UniqueContentTypeOrder = contentTypes;
            properties.List.RootFolder.Update();
        }
예제 #23
0
 public override void FieldAdding(SPListEventProperties properties)
 {
     _stCurrentContext = currentContext;
     if (properties != null)
     {
         XmlDocument doc = new XmlDocument();
         doc.LoadXml(properties.FieldXml);
         if (doc != null)
         {
             bool isHidden = doc.FirstChild.Attributes["Hidden"] == null ? false: Convert.ToBoolean(doc.FirstChild.Attributes["Hidden"].Value);
             if (!isHidden)
             {
                 if (properties.FieldName.ToLower().EndsWith("id") || properties.FieldName.ToLower().EndsWith("text"))
                 {
                     properties.Status       = SPEventReceiverStatus.CancelWithError;
                     properties.ErrorMessage = "Field ending with ID or Text is not allowed.";
                 }
             }
         }
     }
 }
예제 #24
0
        private bool DeleteList(SPListEventProperties properties)
        {
            bool isSuccessful = true;
            var  reportBiz    = new ReportBiz(properties.SiteId);
            Guid listId       = properties.ListId;
            var  DAO          = new EPMData(properties.SiteId);

            DAO.Command = "SELECT TableName FROM RPTList WHERE RPTListID=@RPTListID";
            DAO.AddParam("@RPTListID", listId);
            string sTableName = string.Empty;

            try
            {
                sTableName = DAO.ExecuteScalar(DAO.GetClientReportingConnection).ToString();
                DataTable refTables = reportBiz.GetReferencingTables(DAO, sTableName);
                if (refTables.Rows.Count == 0)
                {
                    reportBiz.GetListBiz(listId).Delete();
                }
                else
                {
                    isSuccessful = false;
                    DAO.LogStatus(listId.ToString(), sTableName,
                                  "Database table delete attempt: Unable to delete " + sTableName + ".",
                                  sTableName + " is referenced by other tables.", 2, 5, Guid.NewGuid().ToString());
                    //Logged in the RefreshAll event log.
                }
            }
            catch (Exception ex)
            {
                DAO.LogStatus(listId.ToString(), sTableName,
                              "Database table delete attempt: Unable to delete " + sTableName + ". " + ex.Message, ex.StackTrace,
                              2, 5, Guid.NewGuid().ToString()); //Logged in the RefreshAll event log.
            }
            reportBiz = null;
            DAO.Dispose();
            return(isSuccessful);
        }
예제 #25
0
        public override void FieldUpdated(SPListEventProperties properties)
        {
            string      fieldXml = properties.FieldXml;
            XmlDocument document = new XmlDocument();

            document.LoadXml(properties.FieldXml);
            XmlElement documentElement = document.DocumentElement;

            if (documentElement.Attributes["Status"] != null)
            {
                switch (documentElement.Attributes["Status"].Value)
                {
                case "Disable":
                    properties.Field.ReadOnlyField = true;
                    break;

                case "Hide":
                    properties.Field.Hidden = true;
                    break;
                }
            }
            base.FieldUpdated(properties);
        }
예제 #26
0
        private bool IsUpdateRequire(EPMData DAO, SPListEventProperties properties, string tableName, string columnName)
        {
            if (properties.Field.Type.Equals(SPFieldType.Lookup))
            {
                string fieldType = properties.Field.TypeAsString;
                try
                {
                    DAO.Command = "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "' AND COLUMN_NAME = '" + columnName + "'";
                    string result = Convert.ToString(DAO.ExecuteScalar(DAO.GetClientReportingConnection));

                    if ((result.Equals("ntext", StringComparison.InvariantCultureIgnoreCase) && fieldType.Equals("Lookup", StringComparison.InvariantCultureIgnoreCase)) ||
                        result.Equals("int", StringComparison.InvariantCultureIgnoreCase) && fieldType.Equals("LookupMulti", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
        /// <summary>
        /// A list is being deleted.
        /// </summary>
        public override void ListDeleting(SPListEventProperties properties)
        {
            base.ListDeleting(properties);
            XmlDocument doc;
            string _path;

            SPContentTypeCollection contentTypeColl = properties.List.ContentTypes;

            if (contentTypeColl.Count > 0)
            {
                foreach (SPContentType contentType in contentTypeColl)
                {
                    if (contentType.Name == "BrickRed.Facebook.ContentType")
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            doc = GetXMLFIle(out _path);
                            if (doc != null)
                            {
                                try
                                {
                                    XmlNode node = doc.SelectSingleNode("Facebook/Contents/Content[ListName='" + properties.ListTitle + "' and SiteURL='" + properties.WebUrl + "']");

                                    if (node != null)
                                    {
                                        node.ParentNode.RemoveChild(node);
                                        doc.Save(_path);
                                    }
                                }
                                catch { };
                            }
                        });
                    }
                }
            }
        }
        /// <summary>
        /// A list is being deleted.
        /// </summary>
        public override void ListDeleting(SPListEventProperties properties)
        {
            base.ListDeleting(properties);
            XmlDocument doc;
            string      _path;

            SPContentTypeCollection contentTypeColl = properties.List.ContentTypes;

            if (contentTypeColl.Count > 0)
            {
                foreach (SPContentType contentType in contentTypeColl)
                {
                    if (contentType.Name == "BrickRed.Facebook.ContentType")
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            doc = GetXMLFIle(out _path);
                            if (doc != null)
                            {
                                try
                                {
                                    XmlNode node = doc.SelectSingleNode("Facebook/Contents/Content[ListName='" + properties.ListTitle + "' and SiteURL='" + properties.WebUrl + "']");

                                    if (node != null)
                                    {
                                        node.ParentNode.RemoveChild(node);
                                        doc.Save(_path);
                                    }
                                }
                                catch { };
                            }
                        });
                    }
                }
            }
        }
 public override void ListAdding(SPListEventProperties properties)
 {
     InvokeScript("ListAdding", properties);
 }
예제 #30
0
 public override void FieldUpdating(SPListEventProperties properties)
 {
 }
예제 #31
0
 /// <summary>
 /// A field was removed.
 /// </summary>
 public override void FieldDeleted(SPListEventProperties properties)
 {
     base.FieldDeleted(properties);
 }
예제 #32
0
 /// <summary>
 /// A field is being updated.
 /// </summary>
 public override void FieldUpdating(SPListEventProperties properties)
 {
     base.FieldUpdating(properties);
 }
예제 #33
0
 /// <summary>
 /// A list is being deleted.
 /// </summary>
 public override void ListDeleting(SPListEventProperties properties)
 {
     base.ListDeleting(properties);
 }
예제 #34
0
 /// <summary>
 /// A list is being added. Chumma added  commengt
 /// </summary>
 public override void ListAdding(SPListEventProperties properties)
 {
     // Praveen Added comment
        base.ListAdding(properties);
        //added comment Shiva
 }
예제 #35
0
 /// <summary>
 /// A list is being added.
 /// </summary>
 public override void ListAdding(SPListEventProperties properties)
 {
     base.ListAdding(properties);
 }
        protected void InvokeScript(string eventName, SPListEventProperties properties)
        {
            using (SPSite site = new SPSite(properties.WebUrl))
            {
                using (SPWeb web = site.OpenWeb(properties.WebId))
                {
                    SPList  list  = web.Lists[properties.ListId];
                    SPField field = properties.Field;;

                    SPFeature feature = web.Features[PowerEventReceiversConstants.FeatureId];

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        Runspace runspace = RunspaceFactory.CreateRunspace();

                        runspace.Open();

                        runspace.SessionStateProxy.SetVariable("httpContext", httpContext);
                        runspace.SessionStateProxy.SetVariable("spContext", spContext);
                        runspace.SessionStateProxy.SetVariable("this", this);
                        runspace.SessionStateProxy.SetVariable("properties", properties);
                        runspace.SessionStateProxy.SetVariable("site", site);
                        runspace.SessionStateProxy.SetVariable("web", web);
                        runspace.SessionStateProxy.SetVariable("list", list);
                        runspace.SessionStateProxy.SetVariable("field", field);
                        runspace.SessionStateProxy.SetVariable("user", web.SiteUsers[properties.UserLoginName]);

                        string script = feature.Properties[PowerEventReceiversConstants.PowerListEventReceiverPropNamePrefixScript + list.RootFolder.Url].Value;

                        try
                        {
                            Pipeline pipe = runspace.CreatePipeline(PowerEventReceiversConstants.PowerEventReceiversPredefinedFunctions);
                            pipe.Invoke();

                            pipe = runspace.CreatePipeline(script);
                            pipe.Invoke();

                            //check if the event's function is defined
                            List <string> functions = PowerEventReceiversHelper.GetFunctions(runspace);
                            if (functions.Contains(eventName.ToLower()) == false)
                            {
                                return;
                            }

                            pipe = runspace.CreatePipeline(eventName);
                            pipe.Invoke();
                            object objProperties = runspace.SessionStateProxy.GetVariable("properties");
                            if (objProperties != null)
                            {
                                if (objProperties is PSObject)
                                {
                                    properties = (SPListEventProperties)((PSObject)objProperties).BaseObject;
                                }
                                else
                                {
                                    properties = (SPListEventProperties)objProperties;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                EventLog.WriteEntry(this.GetType().FullName, ex.Message + "\n" + ex.StackTrace, EventLogEntryType.Error);
                            }
                            catch { }

                            properties.Cancel       = true;
                            properties.ErrorMessage = ex.Message;
                        }
                        finally
                        {
                            if (runspace != null && runspace.RunspaceStateInfo.State != RunspaceState.Closed)
                            {
                                runspace.Close();
                                runspace = null;
                            }
                        }
                    });
                }
            }
        }
 /// <summary>
 ///     A list was deleted.
 /// </summary>
 public override void ListDeleted(SPListEventProperties properties)
 {
     ClearCache(properties);
 }
 public override void FieldUpdating(SPListEventProperties properties)
 {
     InvokeScript("FieldUpdating", properties);
 }
 public override void FieldAdded(SPListEventProperties properties)
 {
     InvokeScript("FieldAdded", properties);
 }
예제 #40
0
 /// <summary>
 /// A list was deleted.
 /// </summary>
 public override void ListDeleted(SPListEventProperties properties)
 {
     base.ListDeleted(properties);
 }
 public override void ListDeleted(SPListEventProperties properties)
 {
     InvokeScript("ListDeleted", properties);
 }