using System; using System.Web.Configuration; using Bitrix.IBlock; using Bitrix.Modules; using Bitrix.Services; namespace Bitrix.Demo
{ [BXMessageReceiver] public static class EventHandlers
{ //Создание элемента инфоблока [BXEventListener("Bitrix.IBlock.IBlockElement.OnAfterCreate")] public static void OnIBlockElementCreate(BXCommand command) { BXIBlockElement element = command.Parameters["Entity"] as BXIBlockElement; if (element == null || !String.Equals(element.IBlockId.ToString(), WebConfigurationManager.AppSettings["RssFeedsIBlockId"], StringComparison.Ordinal)) return; BXSchedulerAgent agent = new BXSchedulerAgent("Bitrix.Demo.Aggregator.Feed." + element.Id); agent.Active = element.Active; agent.Periodic = false; agent.Period = TimeSpan.FromDays(0.5); agent.StartTime = DateTime.Now.AddMinutes(0.1); agent.Parameters["ElementId"] = element.Id; agent.SetClassNameAndAssembly(typeof(AggregatorRssDownloadExecutor)); agent.Save(); } //Обновление элемента инфоблока [BXEventListener("Bitrix.IBlock.IBlockElement.OnAfterUpdate")] public static void OnIBlockElementUpdate(BXCommand command) { BXIBlockElement element = command.Parameters["Entity"] as BXIBlockElement; if (element == null || !String.Equals(element.IBlockId.ToString(), WebConfigurationManager.AppSettings["RssFeedsIBlockId"], StringComparison.Ordinal)) return; BXSchedulerAgent agent = BXSchedulerAgent.GetByName("Bitrix.Demo.Aggregator.Feed." + element.Id); if (agent != null) { agent.StartTime = DateTime.Now.AddMinutes(0.1); agent.Active = element.Active; agent.Save(); } else OnIBlockElementCreate(command); } //Создание раздела инфоблока [BXEventListener("Bitrix.IBlock.IBlockSection.OnAfterCreate")] public static void OnIBlockSectionCreate(BXCommand command) { BXIBlockSection section = command.Parameters["Entity"] as BXIBlockSection; if (section == null || !String.Equals(section.IBlockId.ToString(), WebConfigurationManager.AppSettings["TechnologyIBlockId"], StringComparison.Ordinal)) return; Aggregator.ClearTechnologyTreeCache(); BXSchedulerAgent agent = new BXSchedulerAgent("Bitrix.Demo.Aggregator.Technology." + section.Id); agent.Active = section.Active; agent.Periodic = false; agent.Period = TimeSpan.FromDays(0.6); agent.StartTime = DateTime.Now.AddMinutes(1.0); agent.Parameters["SectionId"] = section.Id; agent.SetClassNameAndAssembly(typeof(AggregatorRemoveItemsInSection)); agent.Save(); } //Обновление раздела инфоблока [BXEventListener("Bitrix.IBlock.IBlockSection.OnAfterUpdate")] public static void OnIBlockSectionUpdate(BXCommand command) { BXIBlockSection section = command.Parameters["Entity"] as BXIBlockSection; if (section == null || !String.Equals(section.IBlockId.ToString(), WebConfigurationManager.AppSettings["TechnologyIBlockId"], StringComparison.Ordinal)) return; Aggregator.ClearTechnologyTreeCache(); BXSchedulerAgent agent = BXSchedulerAgent.GetByName("Bitrix.Demo.Aggregator.Technology." + section.Id); if (agent != null) { agent.StartTime = DateTime.Now.AddMinutes(1); agent.Active = section.Active; agent.Save(); } else OnIBlockSectionCreate(command); } } }
Страница
4 - 4 из 6
Начало
|
Пред.
|
2
3
4
5
6
|
След. |
Конец