private void WriteAudience(AudienceCollection audienceCollection) { _xmlWriter.WriteStartElement(XmlNames.Audience); if (audienceCollection.IsAll) { _xmlWriter.WriteStartElement("AllClients"); _xmlWriter.WriteEndElement(); } if (audienceCollection.IncludesServer) { _xmlWriter.WriteStartElement("Server"); _xmlWriter.WriteEndElement(); } if (!audienceCollection.IsAll) { _xmlWriter.WriteStartElement("Clients"); var targets = new CommandTargetCollection(audienceCollection); _xmlWriter.WriteAttributeString("id", targets.ToString()); _xmlWriter.WriteEndElement(); } _xmlWriter.WriteEndElement(); }
protected void gvResult_DeleteCommand(object source, DataGridCommandEventArgs e) { AudienceCollection dt = ((AudienceCollection)this.gvResult.DataSource); PubEntAdmin.BLL.Audience l_conf = dt[e.Item.ItemIndex]; int Audid = l_conf.AudID; string Audname = l_conf.AudName; string Activestatus = ((Button)e.Item.Cells[4].Controls[7]).Text; if (Activestatus == "Inactive") { Boolean audExist = LU_DAL.AudExist(Audid); if (audExist == false) { LU_DAL.DeleteAudienceLU(Audid); Response.Redirect("~/LookupMgmt.aspx?sub=audience"); } else if (audExist == true) { string confirm = "Unable to Inactivate, value associated with Publication."; ((Label)e.Item.Cells[5].Controls[1]).Text = confirm; } } if (Activestatus == "Active") { int Active = 1; LU_DAL.UpdateAudienceLU(Audid, Audname, Active); Response.Redirect("~/LookupMgmt.aspx?sub=audience"); } }
private void ExecuteCommand(IEnumerable <ClientViewModel> obj, ICommandDescription commandDescription) { var audienceCollection = new AudienceCollection(); audienceCollection.AddRange(obj.Select(x => new CommandTarget(CommandTargetType.Client, x.ClientId))); if (_windowService.ShowDialog <ExecuteCommandViewModel>(vm => vm.Initialize(commandDescription, audienceCollection), out var viewModel) == true) { var watcher = _commandExecutionManager.Execute(viewModel.MazeTask, commandDescription); _windowService.ShowDialog <TaskOverviewViewModel>(vm => vm.Initialize(watcher, commandDescription.Name)); } }
private void GetListItems(string str, MenuItem _spMenu, SPList _spListMenu, SPSite thisSite) { AudienceManager audMgr = new AudienceManager(SPServiceContext.GetContext(thisSite)); AudienceCollection audiences = audMgr.Audiences; AudienceLoader audienceLoader = AudienceLoader.GetAudienceLoader(); try { SPQuery _spQuery = new SPQuery(); string target = ""; _spQuery.Query = String.Format("<OrderBy><FieldRef Name='LinkOrder' Ascending='True' /><FieldRef Name='Title' Ascending='True' /></OrderBy><Where><And><Eq><FieldRef Name='ParentMenu' LookupId= 'TRUE' /><Value Type='Lookup'>{0}</Value></Eq><Eq><FieldRef Name='ShowMenuItem' /><Value Type='Choice'>Yes</Value></Eq></And></Where>", str); SPListItemCollection _spListItems = _spListMenu.GetItems(_spQuery); MenuItem _spMenuItem = new MenuItem(); foreach (SPListItem item in _spListItems) { target = ""; string audienceFieldValue = (string)item["CanBeSeenBy"]; if (string.IsNullOrEmpty(audienceFieldValue) || AudienceManager.IsCurrentUserInAudienceOf(audienceLoader, audienceFieldValue, false)) { if (item["Link URL"] == null) { _spMenuItem = new MenuItem(item["Title"].ToString()); } else { if (_NewWindowFieldExists && item["OpenNewWindow"] != null && (Boolean)item["OpenNewWindow"] == true) { target = "_blank"; } _spMenuItem = new MenuItem(item["Title"].ToString(), "", "", SetServerURL(item["Link URL"].ToString()), target); } GetListItems(item["ID"].ToString(), _spMenuItem, _spListMenu, thisSite); _spMenu.ChildItems.Add(_spMenuItem); } } } catch (Exception ex) { ULSLoggingService myULS = new ULSLoggingService("TopNavProvider", SPContext.Current.Site.WebApplication.Farm); if (myULS != null) { SPDiagnosticsCategory cat = new SPDiagnosticsCategory("CreateChildControls", TraceSeverity.High, EventSeverity.Verbose); cat = myULS[CategoryId.WebPart]; myULS.WriteTrace(1, cat, TraceSeverity.Verbose, String.Format("{0};{1}", ex.Message, ex.StackTrace), myULS.TypeName); } Controls.Add(new LiteralControl(String.Format("An error has occured with this web part. Please contact your system administrator and relay this error message: {0} sub:GetListItems", ex.Message))); } }
public AudienceCollection GetAudience() { var ns = Xml.Root.GetDefaultNamespace().NamespaceName; var audienceNode = Xml.Root.Elements(XName.Get(XmlNames.Audience, ns)); var result = new AudienceCollection(); foreach (var audienceElement in audienceNode.Elements()) { switch (audienceElement.Name.LocalName) { case "AllClients": result.IsAll = true; result.Clear(); break; case "Server": result.IncludesServer = true; break; case "Clients": if (result.IsAll) { continue; } var ids = GetAttributeValue(audienceElement, "id"); if (ids != null) { var targets = CommandTargetCollection.Parse(ids); result.AddRange(targets); } break; } } return(result); }
protected void gvResult_UpdateCommand(object source, DataGridCommandEventArgs e) { AudienceCollection dt = ((AudienceCollection)this.gvResult.DataSource); PubEntAdmin.BLL.Audience l_conf = dt[e.Item.ItemIndex]; int Active = 0; int Audid = l_conf.AudID; string Audname = ((TextBox)e.Item.Cells[1].Controls[1]).Text; string sActive = ((Label)e.Item.Cells[2].Controls[1]).Text; if (sActive == "Active") { Active = 1; } else { Active = 0; } Boolean valid = false; Boolean validnum = false; Boolean validlen = false; if (Audname.Length != 0) { valid = PubEntAdminManager.OtherVal(Audname); validnum = PubEntAdminManager.SpecialVal2(Audname); validlen = PubEntAdminManager.LenVal(Audname, 50); } if ((valid == false) && (validnum == false) && (validlen == true)) { LU_DAL.UpdateAudienceLU(Audid, Audname, Active); Response.Redirect("~/LookupMgmt.aspx?sub=audience"); } else { Response.Redirect("InvalidInput.aspx"); } }
private string BuildTAQuery() { string query = string.Empty; string audienceGroups = string.Empty; try { SPSite site = new SPSite(SPContext.Current.Web.Url); SPServiceContext context = SPServiceContext.GetContext(site); SPUser currentUser = SPContext.Current.Web.CurrentUser; string loginName = currentUser.ToString().Split('|')[1]; AudienceManager audMgr = new AudienceManager(context); AudienceCollection audiences = audMgr.Audiences; for (int i = 0; i < audiences.Count; i++) { if (audiences[i].AudienceName != "All site users") { if (audiences[i].IsMember(loginName)) { //audienceGroups = audienceGroups + "," + audiences[i].AudienceID; //TargetAudience is the managed property name in the search schema query += "TargetAudience:\"" + audiences[i].AudienceID + "\" OR "; } } } query = query.Substring(0, query.LastIndexOf(" OR ")); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Content Search Ext Web Part", TraceSeverity.Medium, EventSeverity.Error), TraceSeverity.Medium, "Audience Build Failed: " + ex.Message, null); } return(query); }
public AudienceFilter(AudienceCollection audienceCollection) { _audienceCollection = audienceCollection; }
/// <summary> /// Create all your controls here for rendering. /// Try to avoid using the RenderWebPart() method. /// </summary> protected override void CreateChildControls() { // Create ASPMenu control. ChromeType = PartChromeType.None; /*string MenuID = _MenuList + "CustomTopNavWebPart";*/ AspMenu _spMenu = new AspMenu { UseSimpleRendering = true, UseSeparateCSS = false, Orientation = Orientation.Horizontal, MaximumDynamicDisplayLevels = 5, CssClass = "s4-tn" }; SPWeb thisWeb = null; try { //Set some defaults if (Set_TopNavigationMenu.ToLower() != "yes" && Set_TopNavigationMenu.ToLower() != "no") { Set_TopNavigationMenu = "yes"; } if (Set_TopNavigationMenu.ToLower() == "yes") { Set_MenuName = "TopNavigationMenu"; Set_MenuOrientation = "horizontal"; } //Set the controls look and feel //For some reason the ID of the Menu matters when using this as a Top Menu, the name must be TopNavigationMenu or the dropdowns are blank. _spMenu.ID = Set_MenuName; _spMenu.EnableViewState = false; SPSite thisSite = null; try { if (string.IsNullOrEmpty(Set_ServerURL)) { //Try to get the ServerURl from the web config Set_ServerURL = ConfigurationManager.AppSettings["topNavWebAppURL"]; if (string.IsNullOrEmpty(Set_ServerURL)) { //If cannot get from web config then set to the current web application Set_ServerURL = SPContext.Current.Site.WebApplication.GetResponseUri(SPContext.Current.Site.Zone).AbsoluteUri; } thisSite = new SPSite(Set_ServerURL); } else { thisSite = new SPSite(Set_ServerURL); } if (Set_WebSite == "" || Set_WebSite == null) { thisWeb = thisSite.OpenWeb("/"); } else { thisWeb = thisSite.OpenWeb(Set_WebSite); } } finally { if (thisSite != null) { thisSite.Dispose(); } } AudienceManager audMgr = new AudienceManager(SPServiceContext.GetContext(thisSite)); AudienceCollection audiences = audMgr.Audiences; AudienceLoader audienceLoader = AudienceLoader.GetAudienceLoader(); string target = ""; SPList _spListMenu = thisWeb.Lists[Set_MenuList]; _NewWindowFieldExists = _spListMenu.Fields.ContainsField("OpenNewWindow"); SPQuery _spQuery = new SPQuery(); MenuItem _spMenuItem = new MenuItem(); _spQuery.Query = "<OrderBy><FieldRef Name='LinkOrder' Ascending='True' /><FieldRef Name='Title' Ascending='True' /></OrderBy><Where><And><IsNull><FieldRef Name='ParentMenu' /></IsNull><Eq><FieldRef Name='ShowMenuItem' /><Value Type='Choice'>Yes</Value></Eq></And></Where>"; SPListItemCollection _spListItems = _spListMenu.GetItems(_spQuery); foreach (SPListItem item in _spListItems) { string audienceFieldValue = (string)item["CanBeSeenBy"]; if (string.IsNullOrEmpty(audienceFieldValue) || AudienceManager.IsCurrentUserInAudienceOf(audienceLoader, audienceFieldValue, false)) { if (item["Link URL"] == null) { _spMenuItem = new MenuItem(item["Title"].ToString()); } else { if (_NewWindowFieldExists && item["OpenNewWindow"] != null && (Boolean)item["OpenNewWindow"] == true) { target = "_blank"; } _spMenuItem = new MenuItem(item["Title"].ToString(), "", "", SetServerURL(item["LinkURL"].ToString()), target); } GetListItems(item["ID"].ToString(), _spMenuItem, _spListMenu, thisSite); if (Page.Request.Url.AbsoluteUri == item["Link URL"].ToString()) { _spMenuItem.Selected = true; } _spMenu.Items.Add(_spMenuItem); } } Controls.Add(_spMenu); } catch (Exception ex) { ULSLoggingService myULS = new ULSLoggingService("TopNavProvider", SPContext.Current.Site.WebApplication.Farm); if (myULS != null) { SPDiagnosticsCategory cat = new SPDiagnosticsCategory("CreateChildControls", TraceSeverity.High, EventSeverity.Verbose); cat = myULS[CategoryId.WebPart]; myULS.WriteTrace(1, cat, TraceSeverity.Verbose, String.Format("{0};{1}", ex.Message, ex.StackTrace), myULS.TypeName); } Controls.Add(new LiteralControl(String.Format("An error has occured with this web part. Please contact your system administrator and relay this error message: {0} sub:CreateChildControls ", ex.Message))); } finally { if (thisWeb != null) { thisWeb.Dispose(); } } }
protected void gvResult_ItemDataBound(object sender, DataGridItemEventArgs e) { AudienceCollection dt = ((AudienceCollection)this.gvResult.DataSource); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { PubEntAdmin.BLL.Audience l_conf = dt[e.Item.ItemIndex]; ((Label)e.Item.Cells[1].Controls[1]).Text = Server.HtmlEncode(l_conf.AudName); //delete btn col Button l_able = e.Item.Cells[5].FindControl("lnkbtnDel") as Button; if (l_conf.Checked) { ((Label)e.Item.Cells[2].Controls[1]).Text = "Active"; l_able.Text = "Inactivate"; Panel l_pnl = e.Item.Cells[5].FindControl("pnlConfirmDel") as Panel; ((Label)l_pnl.Controls[1]).Text = "Are you sure you want to inactivate this Lookup Value [" + Server.HtmlEncode(l_conf.AudName) + "]?"; } else { ((Label)e.Item.Cells[2].Controls[1]).Text = "Inactive"; l_able.Text = "Activate"; Panel l_pnl = e.Item.Cells[5].FindControl("pnlConfirmDel") as Panel; ((Label)l_pnl.Controls[1]).Text = "Are you sure you want to activate this Lookup Value [" + Server.HtmlEncode(l_conf.AudName) + "]?"; } } else if (e.Item.ItemType == ListItemType.EditItem) { PubEntAdmin.BLL.Audience l_conf = dt[e.Item.ItemIndex]; String status = ""; if (l_conf.Checked == true) { status = "Active"; } else { status = "Inactive"; } ((Label)e.Item.Cells[2].Controls[1]).Text = status; if (e.Item.Cells[3].Controls[2] is Button) { Button l_btnCancel = ((Button)e.Item.Cells[3].Controls[2]); l_btnCancel.ID = "gvResult_Cancel"; Panel l_panel = new Panel(); l_panel.ID = "l_panel"; l_panel.CssClass = "modalPopup"; l_panel.Style.Add("display", "none"); l_panel.Width = Unit.Pixel(233); Label l_label = new Label(); l_label.Text = "Are you sure you want to continue?"; HtmlGenericControl l_div = new HtmlGenericControl(); Button l_ok = new Button(); Button l_cancel = new Button(); l_ok.ID = "l_ok"; l_ok.Text = "OK"; l_cancel.ID = "l_cancel"; l_cancel.Text = "Cancel"; l_div.Controls.Add(l_ok); l_div.Controls.Add(new LiteralControl(" ")); l_div.Controls.Add(l_cancel); l_div.Attributes.Add("align", "center"); l_panel.Controls.Add(l_label); l_panel.Controls.Add(new LiteralControl("<br>")); l_panel.Controls.Add(new LiteralControl("<br>")); l_panel.Controls.Add(l_div); ModalPopupExtender l_mpe = new ModalPopupExtender(); l_mpe.ID = "l_mpe"; l_mpe.TargetControlID = l_btnCancel.ID; l_mpe.PopupControlID = l_panel.ID; l_mpe.BackgroundCssClass = "modalBackground"; l_mpe.DropShadow = true; l_mpe.OkControlID = l_ok.ID; l_mpe.CancelControlID = l_cancel.ID; ConfirmButtonExtender l_cbe = new ConfirmButtonExtender(); l_cbe.TargetControlID = l_btnCancel.ID; l_cbe.ConfirmText = ""; l_cbe.DisplayModalPopupID = l_mpe.ID; e.Item.Cells[3].Controls.Add(l_panel); e.Item.Cells[3].Controls.Add(l_mpe); e.Item.Cells[3].Controls.Add(l_cbe); } //delete btn col Button l_able = e.Item.Cells[5].FindControl("lnkbtnDel") as Button; if (l_conf.Checked) { ((Label)e.Item.Cells[2].Controls[1]).Text = "Active"; l_able.Text = "Inactivate"; Panel l_pnl = e.Item.Cells[5].FindControl("pnlConfirmDel") as Panel; ((Label)l_pnl.Controls[1]).Text = "Are you sure you want to inactivate this Lookup Value [" + Server.HtmlEncode(l_conf.AudName) + "]?"; } else { ((Label)e.Item.Cells[2].Controls[1]).Text = "Inactive"; l_able.Text = "Activate"; Panel l_pnl = e.Item.Cells[5].FindControl("pnlConfirmDel") as Panel; ((Label)l_pnl.Controls[1]).Text = "Are you sure you want to activate this Lookup Value [" + Server.HtmlEncode(l_conf.AudName) + "]?"; } } }
/// <summary> /// Creates the specified audience. /// </summary> /// <param name="context">The context.</param> /// <param name="audienceName">Name of the audience.</param> /// <param name="description">The description.</param> /// <param name="rule">The rule.</param> /// <param name="owner">The owner.</param> /// <param name="update">if set to <c>true</c> [update].</param> /// <returns></returns> internal static Audience Create(SPServiceContext context, string audienceName, string description, RuleEnum?rule, string owner, bool update) { AudienceManager manager = new AudienceManager(context); AudienceCollection auds = manager.Audiences; Audience audience; if (auds.AudienceExist(audienceName)) { if (update) { audience = auds[audienceName]; audience.AudienceDescription = description ?? ""; } else { throw new SPException("Audience name already exists"); } } else { audience = auds.Create(audienceName, description ?? "");// IMPORTANT: the create method does not do a null check but the methods that load the resultant collection assume not null. } if (update && rule.HasValue && audience.GroupOperation != AudienceGroupOperation.AUDIENCE_MIX_OPERATION) { if (rule.Value == RuleEnum.Any && audience.GroupOperation != AudienceGroupOperation.AUDIENCE_OR_OPERATION) { audience.GroupOperation = AudienceGroupOperation.AUDIENCE_OR_OPERATION; } else if (rule.Value == RuleEnum.All && audience.GroupOperation != AudienceGroupOperation.AUDIENCE_AND_OPERATION) { audience.GroupOperation = AudienceGroupOperation.AUDIENCE_AND_OPERATION; } } else { if (audience.GroupOperation != AudienceGroupOperation.AUDIENCE_MIX_OPERATION) { if (rule.HasValue) { if (rule == RuleEnum.Any) { audience.GroupOperation = AudienceGroupOperation.AUDIENCE_OR_OPERATION; } else if (rule == RuleEnum.All) { audience.GroupOperation = AudienceGroupOperation.AUDIENCE_AND_OPERATION; } } else { audience.GroupOperation = AudienceGroupOperation.AUDIENCE_OR_OPERATION; } } } if (!string.IsNullOrEmpty(owner)) { audience.OwnerAccountName = owner; } else { audience.OwnerAccountName = string.Empty; } audience.Commit(); return(audience); }