Exemplo n.º 1
0
        /// <summary>
        /// Downloads the feed asynchronously
        /// </summary>
        /// <returns>An awaitable Task</returns>
        public override async Task DownloadFeedAsync()
        {
            // Query the "database" for the home feeds
            IEnumerable <FeedItem> homeFeedItems =
                InMemorySocialCache.Instance.GetHomeFeeds(OwnerRemoteId, ItemCount);

            // Check if the platform supports the SocialInfo APIs
            if (!PlatformUtilities.IsSocialInfoApiAvailable())
            {
                return;
            }

            // Create the social feed updater
            SocialFeedUpdater feedUpdater = await SocialInfoProviderManager.CreateSocialFeedUpdaterAsync(
                SocialFeedKind.HomeFeed,
                SocialFeedUpdateMode.Replace,
                OwnerRemoteId);

            // Generate each of the feed items
            foreach (FeedItem fi in homeFeedItems)
            {
                SocialFeedItem item = new SocialFeedItem();

                item.Timestamp              = fi.Timestamp;
                item.RemoteId               = fi.Id;
                item.TargetUri              = fi.TargetUri;
                item.Author.DisplayName     = fi.AuthorDisplayName;
                item.Author.RemoteId        = fi.AuthorId;
                item.PrimaryContent.Title   = fi.Title;
                item.PrimaryContent.Message = fi.Message;

                if (fi.ImageUri != null)
                {
                    item.Thumbnails.Add(new SocialItemThumbnail()
                    {
                        TargetUri = fi.TargetUri,
                        ImageUri  = fi.ImageUri
                    });
                }

                feedUpdater.Items.Add(item);
            }

            await feedUpdater.CommitAsync();
        }
        /// <summary>
        /// Downloads the feed asynchronously
        /// </summary>
        /// <returns>An awaitable Task</returns>
        public override async Task DownloadFeedAsync()
        {
            // Get the contact feeds
            IEnumerable<FeedItem> contactFeedItems =
                InMemorySocialCache.Instance.GetContactFeeds(OwnerRemoteId, ItemCount);

            // Check if the platform supports the SocialInfo APIs
            if (!PlatformUtilities.IsSocialInfoApiAvailable())
            {
                return;
            }

            // Create the social feed updater
            SocialFeedUpdater feedUpdater = await SocialInfoProviderManager.CreateSocialFeedUpdaterAsync(
                SocialFeedKind.ContactFeed,
                SocialFeedUpdateMode.Replace,
                OwnerRemoteId);

            // Translate the sample feed into into SocialInfo feed items
            foreach (FeedItem fi in contactFeedItems)
            {
                SocialFeedItem item = new SocialFeedItem();

                item.Timestamp = fi.Timestamp;
                item.RemoteId = fi.Id;
                item.TargetUri = fi.TargetUri;
                item.Author.DisplayName = fi.AuthorDisplayName;
                item.Author.RemoteId = fi.AuthorId;
                item.PrimaryContent.Title = fi.Title;
                item.PrimaryContent.Message = fi.Message;

                if (fi.ImageUri != null)
                {
                    item.Thumbnails.Add(new SocialItemThumbnail()
                    {
                        TargetUri = fi.TargetUri,
                        ImageUri = fi.ImageUri
                    });
                }

                feedUpdater.Items.Add(item);
            }

            await feedUpdater.CommitAsync();
        }
Exemplo n.º 3
0
        private static bool ItemExists(ClientContext context, string listTitle, SocialFeedItem socialFeedItem)
        {
            var list = context.Web.Lists.GetByTitle(listTitle);
            var listItemCamlQuery = new CamlQuery()
            {
                ViewXml = string.Format(@"<View>
                                            <Query>
                                                <Where>
                                                    <And>
                                                        <Eq>
                                                            <FieldRef Name='Title' />
                                                            <Value Type='Text'>{0}</Value>
                                                        </Eq>
                                                        <And>
                                                            <Eq>
                                                                <FieldRef Name='w4vj' />
                                                                <Value Type='Text'>{1}</Value>
                                                            </Eq>
                                                            <Eq>
                                                                <FieldRef Name='Source' />
                                                                <Value Type='Choice'>{2}</Value>
                                                            </Eq>
                                                        </And>
                                                    </And>
                                                </Where>
                                            </Query>
                                            <RowLimit>1</RowLimit>
                                        </View>",
                                        socialFeedItem.Username,
                                        ReplaceIllegalChars(socialFeedItem.Text),
                                        socialFeedItem.Source)
            };
            var listItems = list.GetItems(listItemCamlQuery);

            context.Load(listItems, items => items.Include(item => item.Id));
            context.ExecuteQuery();

            return(listItems.Count > 0);
        }
Exemplo n.º 4
0
        private static void AddItem(ClientContext context, string listTitle, SocialFeedItem socialFeedItem)
        {
            var list         = context.Web.Lists.GetByTitle(listTitle);
            var listItemInfo = new ListItemCreationInformation();
            var listItem     = list.AddItem(listItemInfo);

            listItem["Title"]     = socialFeedItem.Username;
            listItem["w4vj"]      = ReplaceIllegalChars(socialFeedItem.Text);
            listItem["Source"]    = socialFeedItem.Source.ToString();
            listItem["Thumbnail"] = new FieldUrlValue()
            {
                Url         = socialFeedItem.ThumbnailUrl,
                Description = "User Image"
            };
            listItem["nnap"]        = socialFeedItem.DateCreated.ToUniversalTime();
            listItem["DetailsLink"] = new FieldUrlValue()
            {
                Url         = socialFeedItem.DetailsUrl,
                Description = "Details"
            };
            listItem.Update();
            context.ExecuteQuery();
        }