// -------------------------------------------------------------------------------
 // -------------------------------------------------------------------------------
 /// <summary>
 /// Adds a media comment
 /// </summary>
 /// <param name="comment">Comment</param>
 // -------------------------------------------------------------------------------
 // -------------------------------------------------------------------------------
 public void AddMediaComment(string comment)
 {
     if (MediaComments == null)
     {
         MediaComments = new RssMediaComments();
     }
     MediaComments.Add(comment);
 }
示例#2
0
        public async Task <string> LikePost(string json)
        {
            dynamic item = JObject.Parse(json);
            string  GeneratedFileNameAsMediaId = item.GeneratedFileNameAsMediaId;
            string  CommentText = item.CommentText;

            if (GeneratedFileNameAsMediaId != null && CommentText != null)
            {
                MediaComments x = new MediaComments(GeneratedFileNameAsMediaId, User.Identity.Name, CommentText);
                await AWSConnectionService.getInstance().context.SaveAsync <MediaComments>(x);

                return(JsonConvert.SerializeObject(x));
            }
            return(null);
        }
示例#3
0
        /******************************************************** GETTERS **********************************************************/
        /// <summary>
        ///     <para>gets the list of recent comments on a media object</para>
        /// </summary>
        /// <param name="MediaId"></param>
        /// <returns></returns>
        public MediaComments GetMediaRecentComments(String MediaId)
        {
            MediaComments Comments = null;

            try
            {
                // SET UP REQUEST URI
                UriBuilder BaseUri = new UriBuilder(Config.GetUriScheme() + "://" + Config.GetApiUriString() + "/media/" + MediaId + "/comments");

                // SET UP QUERY STRING
                NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty);
                QueryString.Add("access_token", AuthorisedUser.AccessToken);

                // SET THE QUERY STRINGS
                BaseUri.Query = QueryString.ToString();

                // CREATE NEW FEEDS OBJECT AND FILL IN DATA
                Comments = new MediaComments();

                // SEND REQUEST
                WebClient Client = new WebClient();
                byte[] ResponseData = Client.DownloadData(BaseUri.Uri);
                String Response = Encoding.UTF8.GetString(ResponseData);

                // PARSE JSON
                dynamic ParsedJson = JsonConvert.DeserializeObject(Response);

                // CREATE META OBJECT
                MetaData Meta = new MetaData();
                Meta.Code = ParsedJson.meta.code;
                Comments.Meta = Meta;

                // SET FEED DATA
                List<Comment> Data = new List<Comment>();
                foreach (dynamic EachComment in ParsedJson.data)
                {
                    Comment Comment = new Comment();
                    Comment.CreatedTime = new DateTime(long.Parse(EachComment.created_time.ToString()));
                    Comment.Id = EachComment.id;
                    Comment.Text = EachComment.text;
                    User CommentedBy = new User();
                    CommentedBy.Id = EachComment.from.id;
                    CommentedBy.UserName = EachComment.from.username;
                    CommentedBy.ProfilePicture = EachComment.from.profile_picture;
                    CommentedBy.FullName = EachComment.from.full_name;
                    Comment.From = CommentedBy;

                    Data.Add(Comment);
                }
                Comments.Data = Data;
            }
            catch (WebException WEx)
            {
                // FETCHES ANY ERROR THROWN BY INSTAGRAM API
                Stream ResponseStream = WEx.Response.GetResponseStream();
                if (ResponseStream != null)
                {
                    StreamReader ResponseReader = new StreamReader(ResponseStream);
                    if (ResponseReader != null)
                    {
                        // PARSE JSON
                        dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd());

                        // CREATE NEW META OBJECT AND FILL IN DATA
                        MetaData Meta = new MetaData();
                        Meta.Code = ParsedJson.meta.code;
                        Meta.ErrorType = ParsedJson.meta.error_type;
                        Meta.ErrorMessage = ParsedJson.meta.error_message;
                        Comments.Meta = Meta;
                    }
                }
            }
            catch (Exception Ex)
            {
                Console.WriteLine(Ex.StackTrace);
            }

            return Comments;
        }
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Sets the parent XElement with the contents of the RssMediaExtension object
        /// properties
        /// </summary>
        /// <param name="parEl">Parent element</param>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public void SetEl(XElement parEl)
        {
            for (int i = 0; i < MediaRatings.Count; i++)
            {
                parEl.Add(MediaRatings[i].GetEl());
            }

            if (MediaTitle != null)
            {
                parEl.Add(MediaTitle.GetEl());
            }

            if (MediaDescription != null)
            {
                parEl.Add(MediaDescription.GetEl());
            }

            if (MediaKeywords != null)
            {
                parEl.Add(MediaKeywords.GetEl());
            }

            if (MediaThumbnails.Count > 0)
            {
                for (int i = 0; i < MediaThumbnails.Count; i++)
                {
                    parEl.Add(MediaThumbnails[i].GetEl());
                }
            }

            if (MediaCategories.Count > 0)
            {
                for (int i = 0; i < MediaCategories.Count; i++)
                {
                    parEl.Add(MediaCategories[i].GetEl());
                }
            }

            if (MediaHashes.Count > 0)
            {
                for (int i = 0; i < MediaHashes.Count; i++)
                {
                    parEl.Add(MediaHashes[i].GetEl());
                }
            }

            if (MediaPlayer != null)
            {
                parEl.Add(MediaPlayer.GetEl());
            }

            if (MediaCredits.Count > 0)
            {
                for (int i = 0; i < MediaCredits.Count; i++)
                {
                    parEl.Add(MediaCredits[i].GetEl());
                }
            }

            if (MediaCopyright != null)
            {
                parEl.Add(MediaCopyright.GetEl());
            }

            if (MediaTexts.Count > 0)
            {
                // sort the list
                MediaTexts.Sort(new SortMediaText());

                // now iterate
                for (int i = 0; i < MediaTexts.Count; i++)
                {
                    parEl.Add(MediaTexts[i].GetEl());
                }
            }


            if (MediaRestrictions.Count > 0)
            {
                for (int i = 0; i < MediaRestrictions.Count; i++)
                {
                    parEl.Add(MediaRestrictions[i].GetEl());
                }
            }


            if (MediaCommunity != null)
            {
                parEl.Add(MediaCommunity.GetEl());
            }

            if (MediaComments != null)
            {
                parEl.Add(MediaComments.GetEl());
            }


            if (MediaEmbed != null)
            {
                parEl.Add(MediaEmbed.GetEl());
            }

            if (MediaResponses != null)
            {
                parEl.Add(MediaResponses.GetEl());
            }

            if (MediaBacklinks != null)
            {
                parEl.Add(MediaBacklinks.GetEl());
            }

            if (MediaStatus != null)
            {
                parEl.Add(MediaStatus.GetEl());
            }

            if (MediaPrices.Count > 0)
            {
                for (int i = 0; i < MediaPrices.Count; i++)
                {
                    parEl.Add(MediaPrices[i].GetEl());
                }
            }

            if (MediaLicense != null)
            {
                parEl.Add(MediaLicense.GetEl());
            }

            if (MediaSubtitles.Count > 0)
            {
                for (int i = 0; i < MediaSubtitles.Count; i++)
                {
                    parEl.Add(MediaSubtitles[i].GetEl());
                }
            }

            if (MediaPeerLink != null)
            {
                parEl.Add(MediaPeerLink.GetEl());
            }

            if (MediaRights != null)
            {
                parEl.Add(MediaRights.GetEl());
            }

            if (MediaScenes != null)
            {
                parEl.Add(MediaScenes.GetEl());
            }

            if (MediaLocations.Count > 0)
            {
                for (int i = 0; i < MediaLocations.Count; i++)
                {
                    parEl.Add(MediaLocations[i].GetEl());
                }
            }

            if (MediaValid != null)
            {
                parEl.Add(MediaValid.GetEl());
            }
        }
示例#5
0
        /******************************************************** GETTERS **********************************************************/

        /// <summary>
        ///     <para>gets the list of recent comments on a media object</para>
        /// </summary>
        /// <param name="MediaId"></param>
        /// <returns></returns>
        public MediaComments GetMediaRecentComments(String MediaId)
        {
            MediaComments Comments = null;

            try
            {
                // SET UP REQUEST URI
                UriBuilder BaseUri = new UriBuilder(Config.GetUriScheme() + "://" + Config.GetApiUriString() + "/media/" + MediaId + "/comments");

                // SET UP QUERY STRING
                NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty);
                QueryString.Add("access_token", AuthorisedUser.AccessToken);

                // SET THE QUERY STRINGS
                BaseUri.Query = QueryString.ToString();

                // CREATE NEW FEEDS OBJECT AND FILL IN DATA
                Comments = new MediaComments();

                // SEND REQUEST
                WebClient Client       = new WebClient();
                byte[]    ResponseData = Client.DownloadData(BaseUri.Uri);
                String    Response     = Encoding.UTF8.GetString(ResponseData);

                // PARSE JSON
                dynamic ParsedJson = JsonConvert.DeserializeObject(Response);

                // CREATE META OBJECT
                MetaData Meta = new MetaData();
                Meta.Code     = ParsedJson.meta.code;
                Comments.Meta = Meta;

                // SET FEED DATA
                List <Comment> Data = new List <Comment>();
                foreach (dynamic EachComment in ParsedJson.data)
                {
                    Comment Comment = new Comment();
                    Comment.CreatedTime = new DateTime(long.Parse(EachComment.created_time.ToString()));
                    Comment.Id          = EachComment.id;
                    Comment.Text        = EachComment.text;
                    User CommentedBy = new User();
                    CommentedBy.Id             = EachComment.from.id;
                    CommentedBy.UserName       = EachComment.from.username;
                    CommentedBy.ProfilePicture = EachComment.from.profile_picture;
                    CommentedBy.FullName       = EachComment.from.full_name;
                    Comment.From = CommentedBy;

                    Data.Add(Comment);
                }
                Comments.Data = Data;
            }
            catch (WebException WEx)
            {
                // FETCHES ANY ERROR THROWN BY INSTAGRAM API
                Stream ResponseStream = WEx.Response.GetResponseStream();
                if (ResponseStream != null)
                {
                    StreamReader ResponseReader = new StreamReader(ResponseStream);
                    if (ResponseReader != null)
                    {
                        // PARSE JSON
                        dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd());

                        // CREATE NEW META OBJECT AND FILL IN DATA
                        MetaData Meta = new MetaData();
                        Meta.Code         = ParsedJson.meta.code;
                        Meta.ErrorType    = ParsedJson.meta.error_type;
                        Meta.ErrorMessage = ParsedJson.meta.error_message;
                        Comments.Meta     = Meta;
                    }
                }
            }
            catch (Exception Ex)
            {
                Console.WriteLine(Ex.StackTrace);
            }

            return(Comments);
        }