private bool SaveIBlock() { try { Page.Validate("IBlockEdit"); if (!Page.IsValid) throw new Exception(); AccessEdit.State.Validate(false); if (!(iblockId > 0 ? UpdateIBlock() : CreateIBlock())) throw new Exception(); if (cbRebuildSearchIndex.Checked) { BXSchedulerAgent a = new BXSchedulerAgent(); a.SetClassNameAndAssembly(typeof(BXIBlock.IndexSynchronizer)); a.Parameters.Add("Action", BXIBlock.IndexSynchronizerAction.Rebuild.ToString("G")); a.Parameters.Add("IBlockId", iblockId); a.StartTime = DateTime.Now.AddSeconds(3D); a.Save(); } propertyEntryName = BXIBlockElement.GetCustomFieldsKey(iblockId); sectionPropertyEntryName = BXIBlockSection.GetCustomFieldsKey(iblockId); cfl.EntityId = propertyEntryName; cfls.EntityId = sectionPropertyEntryName; try { cfl.Save(); cfls.Save(); } catch (Exception ex) { errorMassage.AddErrorMessage(ex.Message); throw; } return true; } catch { return false; } }
private bool SaveForumData() { bool result = false; try { Page.Validate("ForumEdit"); if (!Page.IsValid) throw new Exception(); AccessEdit.State.Validate(false); if (forum == null) forum = new BXForum(); forum.Active = ForumActive.Checked; int categoryId; if (int.TryParse(ForumCategory.SelectedValue, out categoryId) && (categoryId == 0 || BXForumCategory.GetById(categoryId) != null)) forum.CategoryId = categoryId; forum.Sites.Clear(); foreach (ListItem item in ForumSites.Items) if (item.Selected) forum.Sites.Add(item.Value); forum.Name = ForumName.Text; forum.Description = ForumDescription.Text; int sort; if (int.TryParse(ForumSort.Text, out sort)) forum.Sort = sort; forum.AllowBBCode = ForumBBCode.Checked; forum.AllowSmiles = ForumSmiles.Checked; forum.AllowVotingForTopic = ForumVotingForTopic.Checked; forum.AllowVotingForPost = ForumVotingForPost.Checked; forum.IndexContent = ForumIndexContent.Checked; forum.Code = ForumCode.Text; forum.XmlId = ForumXmlId.Text; forum.Save(); if (IsSearchModuleInstalled && ForumRebuildSearchIndex.Checked) { BXSchedulerAgent a = new BXSchedulerAgent(); a.SetClassNameAndAssembly(typeof(Bitrix.Forum.BXForum.IndexSynchronizer)); a.Parameters.Add("Action", Bitrix.Forum.BXForum.IndexSynchronizerAction.Rebuild.ToString("G")); a.Parameters.Add("ForumId", Id); a.StartTime = DateTime.Now.AddSeconds(5D); a.Save(); } if (forum.Id > 0) { BXRoleManager.RemoveRoleFromTasks("forum", forum.Id.ToString()); BXRoleManager.RemoveRoleFromOperations("forum", forum.Id.ToString()); } SaveAccessState(); id = forum.Id; result = true; } catch (Exception ex) { errorMessage.AddErrorMessage(ex.Message); } return result; }
protected void btnCreateAgent_Click(object sender, EventArgs e) { string agentName = "BackupAgent_" + txbAgentName.Text; double hour = 0; double.TryParse(txbHour.Text, out hour); DateTime startDate = DateTime.Now.Date; BXSchedulerAgent agent = BXSchedulerAgent.GetByName(agentName); if (agent != null) { lblError.Text = string.Format("Агент с именем \"{0}\" уже существует", agentName); return; } else { lblError.Text = ""; } if (string.IsNullOrEmpty(txbAgentName.Text)) { lblError.Text = string.Format("Введите правильный имя агента", hour); return; } if (hour == 0) { lblError.Text = string.Format("Введите правильный интервал", hour); return; } try { int h = int.Parse(txbStartTime.Text.Split(':')[0].TrimStart('0')); int m = int.Parse(txbStartTime.Text.Split(':')[1].TrimStart('0')); if (h >= 0 && h < 24 && m >= 0 && m < 60) { startDate = startDate.AddHours((double)h); startDate = startDate.AddMinutes((double)m); } else { lblError.Text = string.Format("Введите правильный начало", hour); return; } } catch { lblError.Text = string.Format("Введите правильный начало", hour); return; } BuckupOptions option = GetOption(); agent = new BXSchedulerAgent(agentName); agent.Parameters["BackupOptions"] = ToBase64(option); agent.Period = TimeSpan.FromHours(hour); agent.Periodic = true; agent.StartTime = startDate; agent.SetClassNameAndAssembly(typeof(Bitrix.Modules.BackupAgentExecutor)); agent.Save(); AgentGridView.DataBind(); }