protected override void UpdateDataObject()
        {
            SPServiceContext context = null;

            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
            }

            Common.Audiences.CreateAudience.Create(context, Identity, Description, Membership, Owner, true);
        }
 /// <summary>
 /// Does sanity checking and error logging on missing data in subscriptions
 /// </summary>
 /// <param name="subscription"></param>
 private void SanityCheckSubscription(SiteSubscription subscription, XmlNode xmlNode)
 {
     if (string.IsNullOrWhiteSpace(subscription.Id))
     {
         _onlineSession.StatusLog.AddError(subscription.Subject + "/" + subscription.UserName + " is missing a subscription ID. Not returned from server! xml=" + xmlNode.OuterXml);
     }
 }
        protected override void InternalProcessRecord()
        {
            SPServiceContext context = null;

            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
            }

            Common.Audiences.AddAudienceRule.AddRules(context, Identity, Rules.OuterXml, Clear.IsPresent, Compile.IsPresent, GroupExisting.IsPresent, AppendOperator.Value);
        }
        protected override IEnumerable <AudienceManager> RetrieveDataObjects()
        {
            List <AudienceManager> audienceManagers = new List <AudienceManager>();

            SPServiceContext context = null;

            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
            }
            AudienceManager manager = new AudienceManager(context);

            audienceManagers.Add(manager);
            return(audienceManagers);
        }
        protected override void InternalProcessRecord()
        {
            SPServiceContext context = null;

            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
            }

            string xml = File.ReadAllText(InputFile);

            Common.Audiences.ImportAudiences.Import(xml, context, DeleteExisting.IsPresent, Compile.IsPresent, MapFile);
        }
예제 #6
0
        protected override void UpdateDataObject()
        {
            SPServiceContext   context     = null;
            UserProfileManager profManager = null;

            switch (ParameterSetName)
            {
            case "Username_UPA":
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context     = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
                profManager = new UserProfileManager(context);

                if (string.IsNullOrEmpty(Username))
                {
                    Common.UserProfiles.SetPictureUrl.SetPictures(profManager, Path, Overwrite, IgnoreMissingData, ValidateUrl);
                }
                else
                {
                    Common.UserProfiles.SetPictureUrl.SetPicture(profManager, Username, Path, Overwrite, IgnoreMissingData, ValidateUrl);
                }

                break;

            case "Username_SPSite":
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
                profManager = new UserProfileManager(context);

                if (string.IsNullOrEmpty(Username))
                {
                    Common.UserProfiles.SetPictureUrl.SetPictures(profManager, Path, Overwrite, IgnoreMissingData, ValidateUrl);
                }
                else
                {
                    Common.UserProfiles.SetPictureUrl.SetPicture(profManager, Username, Path, Overwrite, IgnoreMissingData, ValidateUrl);
                }

                break;

            case "UserProfile":
                Common.UserProfiles.SetPictureUrl.SetPicture(UserProfile, Path, Overwrite, IgnoreMissingData, ValidateUrl);
                break;
            }
        }
        protected override IEnumerable <UserProfileChange> RetrieveDataObjects()
        {
            SPServiceContext context = null;

            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
            }
            UserProfileManager profileManager = new UserProfileManager(context);

            DateTime tokenStart = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(Interval));
            UserProfileChangeToken changeToken = new UserProfileChangeToken(tokenStart);

            UserProfileChangeQuery changeQuery = new UserProfileChangeQuery(false, true);

            changeQuery.ChangeTokenStart           = changeToken;
            changeQuery.UserProfile                = true;
            changeQuery.SingleValueProperty        = IncludeSingleValuePropertyChanges;
            changeQuery.MultiValueProperty         = IncludeMultiValuePropertyChanges;
            changeQuery.Anniversary                = IncludeAnniversaryChanges;
            changeQuery.Colleague                  = IncludeColleagueChanges;
            changeQuery.OrganizationMembership     = IncludeOrganizationMembershipChanges;
            changeQuery.DistributionListMembership = IncludeDistributionListMembershipChanges;
            changeQuery.PersonalizationSite        = IncludePersonalizationSiteChanges;
            changeQuery.SiteMembership             = IncludeSiteMembershipChanges;

            UserProfileChangeCollection changes = profileManager.GetChanges(changeQuery);

            foreach (UserProfileChange change in changes)
            {
                WriteResult(change);
            }
            return(null);
        }
        protected override IEnumerable <Audience> RetrieveDataObjects()
        {
            List <Audience> audiences = new List <Audience>();

            SPServiceContext context = null;

            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
            }
            AudienceManager manager = new AudienceManager(context);

            if (!string.IsNullOrEmpty(Identity) && !manager.Audiences.AudienceExist(Identity))
            {
                throw new SPException("Audience name does not exist");
            }
            if (!string.IsNullOrEmpty(Identity))
            {
                audiences.Add(manager.Audiences[Identity]);
                return(audiences);
            }

            foreach (Audience audience in manager.Audiences)
            {
                audiences.Add(audience);
            }
            return(audiences);
        }
    /// <summary>
    /// Get a page's worth of Subscriptions listing
    /// </summary>
    /// <param name="onlineSubscriptions"></param>
    /// <param name="pageToRequest">Page # we are requesting (1 based)</param>
    /// <param name="totalNumberPages">Total # of pages of data that Server can return us</param>
    private void ExecuteRequest_ForPage(List <SiteSubscription> onlineSubscriptions, int pageToRequest, out int totalNumberPages)
    {
        int pageSize = _onlineUrls.PageSize;
        //Create a web request, in including the users logged-in auth information in the request headers
        var urlQuery = _onlineUrls.Url_SubscriptionsList(_onlineSession, pageSize, pageToRequest);

        _onlineSession.StatusLog.AddStatus("Web request: " + urlQuery, -10);
        XmlDocument xmlDoc = ResourceSafe_PerformWebRequest_GetXmlDocument(urlQuery, "get subscriptions list");
        //var webRequest = CreateLoggedInWebRequest(urlQuery);
        //webRequest.Method = "GET";
        //var response = GetWebReponseLogErrors(webRequest, "get subscriptions list");
        //var xmlDoc = GetWebResponseAsXml(response);

        //Get all the subscription nodes
        var nsManager     = XmlHelper.CreateTableauXmlNamespaceManager("iwsOnline");
        var subscriptions = xmlDoc.SelectNodes("//iwsOnline:subscription", nsManager);

        //Get information for each of the data sources
        foreach (XmlNode itemXml in subscriptions)
        {
            try
            {
                var thisSubscription = new SiteSubscription(itemXml);
                onlineSubscriptions.Add(thisSubscription);

                SanityCheckSubscription(thisSubscription, itemXml);
            }
            catch
            {
                AppDiagnostics.Assert(false, "Subscription parse error");
                _onlineSession.StatusLog.AddError("Error parsing subscription: " + itemXml.OuterXml);
            }
        } //end: foreach

        //-------------------------------------------------------------------
        //Get the updated page-count
        //-------------------------------------------------------------------
        totalNumberPages = DownloadPaginationHelper.GetNumberOfPagesFromPagination(
            xmlDoc.SelectSingleNode("//iwsOnline:pagination", nsManager),
            pageSize);
    }
예제 #10
0
        protected override void InternalProcessRecord()
        {
            SPServiceContext context = null;

            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    context = SPServiceContext.GetContext(site);
                }
            }


            string xml = Common.Audiences.EnumAudienceRules.EnumRules(context, Identity, Explicit.IsPresent);

            if (string.IsNullOrEmpty(xml))
            {
                return;
            }

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);
            WriteResult(xml);
        }
        protected override void InternalValidate()
        {
            if (ParameterSetName == "UPA")
            {
                SPSiteSubscriptionIdentifier subId;
                if (SiteSubscription != null)
                {
                    SPSiteSubscription siteSub = SiteSubscription.Read();
                    subId = siteSub.Id;
                }
                else
                {
                    subId = SPSiteSubscriptionIdentifier.Default;
                }

                SPServiceApplication svcApp = UserProfileServiceApplication.Read();
                _context = SPServiceContext.GetContext(svcApp.ServiceApplicationProxyGroup, subId);
            }
            else
            {
                using (SPSite site = ContextSite.Read())
                {
                    _context = SPServiceContext.GetContext(site);
                }
            }

            if (!string.IsNullOrEmpty(Identity))
            {
                base.DataObject = Identity;
            }
            if (base.DataObject == null)
            {
                base.WriteError(new PSArgumentException("A valid audience name and service application must be provided."), ErrorCategory.InvalidArgument, null);
                base.SkipProcessCurrentRecord();
            }
        }
 /// <summary>
 /// Adds a subscription to the list
 /// </summary>
 /// <param name="newSubscription"></param>
 internal void AddSubscription(SiteSubscription newSubscription)
 {
     _subscriptions.Add(newSubscription);
 }