protected override void ProcessHTML()
        {
            if (HtmlDoc != null && HtmlDoc.HasData)
            {
                IEnumerable <ParseDataItem> htmlItems = HtmlDoc.Items.Where(x => !x.Header.ToUpper().Contains("DEFINITION"));
                List <InstagramObject>      items     = new List <InstagramObject>();
                foreach (ParseDataItem item in htmlItems)
                {
                    foreach (string value in item.Values)
                    {
                        if (!string.IsNullOrEmpty(value) && !value.StartsWith("No responsive records", StringComparison.InvariantCultureIgnoreCase))
                        {
                            InstagramObject fo = new InstagramObject(value);
                            if (fo.HasData)
                            {
                                items.Add(fo);
                            }
                        }
                    }
                }
                if (items.Count == 0)
                {
                    throw new SectionEmptyException(DisplaySectionName);
                }

                Items = items;
            }

            if (!HasData)
            {
                throw new SectionEmptyException(DisplaySectionName);
            }
        }
Example #2
0
        public DataTable getImageTag(string tag, string next)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("LargeImage");
            dt.Columns.Add("User_Name");
            dt.Columns.Add("Profile_picture");
            dt.Columns.Add("Caption");
            dt.Columns.Add("Tags");
            string fullUrl = GCLass.Next_URL;

            if (GCLass.Next_URL == null)
            {
                fullUrl = GCLass.URL;
            }
            WebResponse response = processWebRequest(fullUrl);

            using (var sr = new System.IO.StreamReader(response.GetResponseStream()))
            {
                InstagramObject _instagram = JsonConvert.DeserializeObject <InstagramObject>(sr.ReadToEnd());


                GCLass.Next_URL = _instagram.pagination.next_url;
                int count       = 0;
                int totalPhotos = _instagram.data.Count - 1;


                while (count < totalPhotos)
                {
                    string tags = "";

                    foreach (object o in _instagram.data[count].tags)
                    {
                        tags += "#" + o + ",";
                    }

                    string caption = "";
                    if (_instagram.data[count].caption == null)
                    {
                        dt.Rows.Add(_instagram.data[count].images.standard_resolution.url, _instagram.data[count].user.username, _instagram.data[count].user.profile_picture, "", tags.TrimEnd(new char[] { ',' }));
                    }
                    else
                    {
                        caption = _instagram.data[count].caption.text;
                        dt.Rows.Add(_instagram.data[count].images.standard_resolution.url, _instagram.data[count].user.username, _instagram.data[count].user.profile_picture, caption, tags.TrimEnd(new char[] { ',' }));
                    }


                    if (_add.CheckImages(_instagram.data[count].images.standard_resolution.url))
                    {
                        _add.AddImages(_instagram.data[count].images.standard_resolution.url, _instagram.data[count].user.username, _instagram.data[count].user.profile_picture, caption, tags.TrimEnd(new char[] { ',' }));
                        _download.SaveImage(GCLass.Path, _instagram.data[count].images.standard_resolution.url);
                    }
                    count = count + 1;
                }
            }

            return(dt);
        }
        public InstagramObject GetRecentMedia()
        {
            string          result = GetData("https://api.instagram.com/v1/users/self/media/recent/");
            InstagramObject media  = JsonConvert.DeserializeObject <InstagramObject>(result);

            if (media != null)
            {
                return(media);
            }
            return(null);
        }
Example #4
0
        public DataTable getImageTag(string tag)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("LargeImage");
            dt.Columns.Add("User_Name");
            dt.Columns.Add("Profile_picture");
            dt.Columns.Add("Caption");
            dt.Columns.Add("Tags");
            string url    = "https://api.instagram.com/v1/tags/";
            string id     = tag;
            string userId = String.Format("/{0}/", id);

            string urlRequest  = "/media/recent?access_token=";
            string accessToken = this.access_token;

            string fullUrl = url + tag + urlRequest + accessToken;

            GCLass.URL = fullUrl;
            WebResponse response = processWebRequest(fullUrl);

            using (var sr = new System.IO.StreamReader(response.GetResponseStream()))
            {
                InstagramObject _instagram = JsonConvert.DeserializeObject <InstagramObject>(sr.ReadToEnd());

                GCLass.Next_URL = _instagram.pagination.next_url;
                int count       = 0;
                int totalPhotos = _instagram.data.Count - 1;


                while (count < totalPhotos)
                {
                    string tags = "";

                    foreach (object o in _instagram.data[count].tags)
                    {
                        tags += "#" + o + ",";
                    }

                    dt.Rows.Add(_instagram.data[count].images.standard_resolution.url, _instagram.data[count].user.username, _instagram.data[count].user.profile_picture, _instagram.data[count].caption.text, tags.TrimEnd(new char[] { ',' }));
                    if (_add.CheckImages(_instagram.data[count].images.standard_resolution.url))
                    {
                        _add.AddImages(_instagram.data[count].images.standard_resolution.url, _instagram.data[count].user.username, _instagram.data[count].user.profile_picture, _instagram.data[count].caption.text, tags.TrimEnd(new char[] { ',' }));
                        _download.SaveImage(GCLass.Path, _instagram.data[count].images.standard_resolution.url);
                    }
                    count = count + 1;
                }
            }
            dt_info = dt;
            return(dt_info);
        }
Example #5
0
        /// <summary>
        /// This methods returns a Data Table containing the most recent collection of large and small
        /// images from the tags(hashtags). The two columns returned are, "LargeImage" and "SmallImage".
        /// You can bind this method to an ASP.NET Repeater server control to expose the data easily.
        /// </summary>
        /// <param name="tagName">tag name for photos. Example: "picoftheday"</param>
        /// <returns>DataTable with Columns, "LargeImage" , "SmallImage" , "Caprion" , "Tags" , "Likes".</returns>
        public DataTable getTagPhotos(string tagName, int media_count)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("LargeImage");
            dt.Columns.Add("SmallImage");
            dt.Columns.Add("Likes");
            dt.Columns.Add("Caption");
            dt.Columns.Add("Tags");
            dt.Columns.Add("Link");

            string url = "https://api.instagram.com/v1/tags";
            string tag = String.Format("/{0}/", tagName);;


            string urlRequest  = "media/recent?count=" + media_count + "&access_token=";
            string accessToken = this.access_token;

            string fullUrl = url + tag + urlRequest + accessToken;

            WebResponse response = processWebRequest(fullUrl);

            using (var sr = new System.IO.StreamReader(response.GetResponseStream()))
            {
                InstagramObject _instagram = JsonConvert.DeserializeObject <InstagramObject>(sr.ReadToEnd());

                int count       = 0;
                int totalPhotos = _instagram.data.Count - 1;


                while (count < totalPhotos)
                {
                    string tags = "";

                    foreach (object o in _instagram.data[count].tags)
                    {
                        tags += "#" + o + ",";
                    }

                    dt.Rows.Add(_instagram.data[count].images.standard_resolution.url, _instagram.data[count].images.low_resolution.url, _instagram.data[count].likes.count, _instagram.data[count].caption.text, tags.TrimEnd(new char[] { ',' }), _instagram.data[count].link);

                    count = count + 1;
                }
            }

            return(dt);
        }
            internal Comment(CommandLineLogger logger, string dataSectionName, IEnumerable <ParseDataItem> dataItems)
            {
                if (dataItems != null && dataItems.Any())
                {
                    foreach (ParseDataItem dataItem in dataItems)
                    {
                        switch (dataItem.Header.Trim().ToUpper())
                        {
                        case "ID":
                            CommentId = dataItem.Value;
                            break;

                        case "DATE CREATED":
                            DateCreatedUTC = dataItem.Value;
                            break;

                        case "STATUS":
                            Status = dataItem.Value;
                            break;

                        case "TEXT":
                            Text = dataItem.Value;
                            break;

                        case "MEDIA CONTENT ID":
                            ContentId = dataItem.Value;
                            break;

                        case "MEDIA OWNER":
                            ContentOwner = new InstagramObject(dataItem.Value);
                            break;

                        default:
                            logger.LogWarning("Unexpected Html Element - \"" + dataSectionName + ": " + dataItem.Header + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
#if DEBUG
                            throw new ApplicationException(dataItem.Header);
#endif
                            break;
                        }
                    }
                }
            }
Example #7
0
                internal SubscriptionEvent(CommandLineLogger logger, string dataSectionName, IEnumerable <ParseDataItem> dataItems)
                {
                    if (dataItems != null && dataItems.Any())
                    {
                        foreach (ParseDataItem dataItem in dataItems)
                        {
                            switch (dataItem.Header.ToUpper().Trim())
                            {
                            case "TYPE":
                                Type = dataItem.Value;
                                break;

                            case "USERS":
                                List <InstagramObject> users = new List <InstagramObject>();
                                foreach (string user in dataItem.Values)
                                {
                                    InstagramObject fo = new InstagramObject(user);
                                    if (fo.HasData)
                                    {
                                        users.Add(fo);
                                    }
                                }
                                if (users != null && users.Any(x => x.HasData))
                                {
                                    Users = users;
                                }
                                break;

                            default:
                                logger.LogWarning("Unexpected Html Element - \"" + dataSectionName + " - Message - Subscription Event:" + dataItem.Header + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
#if DEBUG
                                throw new ApplicationException(dataItem.Header);
#endif
                                // break;
                            }
                        }
                    }
                }
Example #8
0
                    internal Attachment(CommandLineLogger logger, string dataSectionName, string value, IEnumerable <ParseDataItem> dataItems)
                    {
                        if (!string.IsNullOrEmpty(value))
                        {
                            InstagramObject fo = new InstagramObject(value);
                            if (fo.HasData)
                            {
                                Name = fo.Name;
                                Id   = fo.Id;
                            }
                        }

                        foreach (ParseDataItem dataItem in dataItems)
                        {
                            string header = !string.IsNullOrEmpty(dataItem.Header) ? dataItem.Header : string.Empty;
                            switch (header.Trim().ToUpper())
                            {
                            case "TYPE":
                                MIMEType = dataItem.Value;
                                break;

                            case "SIZE":
                                Size = dataItem.Value;
                                break;

                            case "URL":
                                URL = dataItem.Value;
                                break;

                            case "":
                                if (dataItem.HasChildren)
                                {
                                    foreach (ParseDataItem childDataItem in dataItem.Children)
                                    {
                                        switch (childDataItem.Header.Trim().ToUpper())
                                        {
                                        case "LINKED MEDIA FILE:":
                                            LinkedMediaFile = childDataItem.Value;
                                            break;

                                        default:
                                            logger.LogWarning("Unexpected Html Element - \"" + dataSectionName + " - Comment: " + dataItem.Header + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
#if DEBUG
                                            throw new ApplicationException(dataItem.Header);
#endif
                                            // break;
                                        }
                                    }
                                }
                                break;

                            default:
                                logger.LogWarning("Unexpected Html Element - \"" + dataSectionName + " - Message - Attachment:" + dataItem.Header + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
                                //_log.LogWarning("Unknown Section - \"Message:Attachment:" + headerNode.InnerText + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
#if DEBUG
                                throw new ApplicationException(dataItem.Header);
#endif
                                // break;
                            }
                        }
                    }
Example #9
0
                internal Message(CommandLineLogger logger, string dataSectionName, int msgNum, IEnumerable <ParseDataItem> marketplaceIdItems, IEnumerable <InstagramObject> participants, IEnumerable <ParseDataItem> messageItems)
                {
                    List <InstagramObject> recipientList = new List <InstagramObject>();

                    GUID     = Guid.NewGuid().ToString();
                    Sequence = msgNum;

                    if (marketplaceIdItems != null && marketplaceIdItems.Any())
                    {
                        foreach (ParseDataItem marketplaceIdItem in marketplaceIdItems)
                        {
                            switch (marketplaceIdItem.Header.ToUpper().Trim())
                            {
                            case "MARKETPLACE ID":
                                MarketplaceId = marketplaceIdItem.Value;
                                break;

                            default:
                                logger.LogWarning("Unexpected Html Element - \"" + dataSectionName + " - Message (Marketplace): " + marketplaceIdItem.Header + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
                                //_log.LogWarning("Unknown Section - \"Message:" + headerNode.InnerText + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
#if DEBUG
                                throw new ApplicationException(marketplaceIdItem.Header);
#endif
                                // break;
                            }
                        }
                    }

                    foreach (ParseDataItem messageItem in messageItems)
                    {
                        switch (messageItem.Header.ToUpper().Trim())
                        {
                        case "RECIPIENTS":
                            if (messageItem.HasValues)
                            {
                                foreach (string recipient in messageItem.Values)
                                {
                                    InstagramObject fo = new InstagramObject(recipient);
                                    if (fo.HasData)
                                    {
                                        recipientList.Add(fo);
                                    }
                                }
                            }
                            break;

                        case "AUTHOR":
                            Author = new InstagramObject(messageItem.Value);
                            break;

                        case "SENT":
                            Sent = messageItem.Value;
                            break;

                        case "DELETED":
                            IsDeleted = messageItem.Value;
                            break;

                        case "BODY":
                            Body = messageItem.Value;
                            break;

                        case "IP":
                            IPAddress = messageItem.Value;
                            break;

                        case "CALL RECORD":
                            CallRecord cr = new CallRecord(logger, dataSectionName, messageItem.Children);
                            if (cr.HasData)
                            {
                                CallRecords = new List <CallRecord>()
                                {
                                    cr
                                }
                            }
                            ;
                            break;

                        case "ATTACHMENTS":
                            List <Attachment> items = new List <Attachment>();
                            int startIndex          = 0;
                            foreach (ParseDataItem.ValueCount vc in messageItem.ValueCounts)
                            {
                                string value = vc.Val;
                                List <ParseDataItem> components = null;
                                for (int i = startIndex; i < startIndex + vc.AssociatedChildCount; i++)
                                {
                                    if (components == null)
                                    {
                                        components = new List <ParseDataItem>();
                                    }
                                    ParseDataItem childItem = messageItem.Children.ElementAt(i);
                                    if (childItem.HasData)
                                    {
                                        components.Add(childItem);
                                    }
                                }
                                Attachment att = new Attachment(logger, dataSectionName, value, components);
                                if (att.HasData)
                                {
                                    items.Add(att);
                                }
                                startIndex += vc.AssociatedChildCount;
                            }
                            Attachments = items;
                            break;

                        case "SHARE":
                            Share share = new Share(logger, dataSectionName, messageItem);
                            if (share.HasData)
                            {
                                Shares = new List <Share>()
                                {
                                    share
                                }
                            }
                            ;
                            break;

                        case "MARKETPLACE ID":
                            MarketplaceId = messageItem.Value;
                            break;

                        case "SUBSCRIPTION EVENT":
                            if (messageItem.HasChildren)
                            {
                                SubscriptionEvent subscriptionEvent = new SubscriptionEvent(logger, dataSectionName, messageItem.Children);
                                if (subscriptionEvent.HasData)
                                {
                                    SubscriptionEvents = new List <SubscriptionEvent>()
                                    {
                                        subscriptionEvent
                                    }
                                }
                                ;
                            }
                            break;

                        case "REMOVED BY SENDER":
                            RemoveBySender = messageItem.Value;
                            break;

                        default:
                            logger.LogWarning("Unexpected Html Element - \"" + dataSectionName + " - Message: " + messageItem.Header + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
                            //_log.LogWarning("Unknown Section - \"Message:" + headerNode.InnerText + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
#if DEBUG
                            throw new ApplicationException(messageItem.Header);
#endif
                            // break;
                        }
                    }

                    if (participants != null && participants.Any(x => x.HasData))
                    {
                        recipientList.AddRange(participants.Where(x => x.HasData));
                    }

                    if (recipientList.Count() > 0)
                    {
                        Recipients = recipientList;
                    }
                }
Example #10
0
            internal Thread(CommandLineLogger logger, string dataSectionName, string threadId, string threadDate, IEnumerable <ParseDataItem> marketplaceIdItems, IEnumerable <ParseDataItem> currentParticipants, IEnumerable <ParseDataItem> pastParticipants, IEnumerable <ParseDataItem> messages)
            {
                ID         = !string.IsNullOrEmpty(threadId) ? threadId : Guid.NewGuid().ToString();
                ThreadDate = threadDate;

                List <InstagramObject> currentPart  = new List <InstagramObject>();
                List <InstagramObject> pastPart     = new List <InstagramObject>();
                List <InstagramObject> participants = new List <InstagramObject>();

                if (currentParticipants != null && currentParticipants.Any())
                {
                    foreach (ParseDataItem cpItem in currentParticipants)
                    {
                        if (cpItem.HasValues)
                        {
                            foreach (string val in cpItem.Values)
                            {
                                if (val.Contains("UTC"))
                                {
                                    threadDate = val;
                                }
                                else
                                {
                                    InstagramObject fo = new InstagramObject(val);
                                    if (fo.HasData)
                                    {
                                        currentPart.Add(fo);
                                    }
                                }
                            }
                        }
                    }
                    if (currentPart.Any())
                    {
                        participants.AddRange(currentPart);
                    }
                }

                if (pastParticipants != null && pastParticipants.Any())
                {
                    foreach (ParseDataItem ppItem in pastParticipants)
                    {
                        if (ppItem.HasValues)
                        {
                            foreach (string val in ppItem.Values)
                            {
                                if (val.Contains("UTC"))
                                {
                                    threadDate = val;
                                }
                                else
                                {
                                    InstagramObject fo = new InstagramObject(val);
                                    if (fo.HasData)
                                    {
                                        pastPart.Add(fo);
                                    }
                                }
                            }
                        }
                    }
                    if (pastPart.Any())
                    {
                        participants.AddRange(currentPart);
                    }
                }

                List <Message>       items      = new List <Message>();
                List <ParseDataItem> components = null;
                int    messageCount             = 1;
                string firstItem = string.Empty;

                if (messages != null && messages.Any())
                {
                    foreach (ParseDataItem item in messages)
                    {
                        if (string.IsNullOrEmpty(firstItem))
                        {
                            firstItem = item.Header;
                        }

                        if (item.Header.Equals(firstItem) && components != null && components.Any())
                        {
                            Message newItem = new Message(logger, dataSectionName, messageCount, marketplaceIdItems, participants, components);
                            if (newItem.HasData)
                            {
                                items.Add(newItem);
                                messageCount++;
                            }
                            components = null;
                        }
                        if (components == null)
                        {
                            components = new List <ParseDataItem>();
                        }
                        components.Add(item);
                    }

                    if (components != null && components.Any())
                    {
                        Message newItem = new Message(logger, dataSectionName, messageCount, marketplaceIdItems, participants, components);
                        if (newItem.HasData)
                        {
                            items.Add(newItem);
                            messageCount++;
                        }
                    }
                    if (items != null && items.Any())
                    {
                        Messages = items;
                    }
                }
            }
Example #11
0
            internal DirectStory(CommandLineLogger logger, string dataSectionName, IEnumerable <ParseDataItem> dataItems)
            {
                if (dataItems != null && dataItems.Any())
                {
                    foreach (ParseDataItem dataItem in dataItems)
                    {
                        switch (dataItem.Header.Trim().ToUpper())
                        {
                        case "MEDIA ID":
                            MediaId = dataItem.Value;
                            break;

                        case "TIME":
                            Time = dataItem.Value;
                            break;

                        case "AUTHOR":
                            InstagramObject fo = new InstagramObject(dataItem.Value);
                            if (fo.HasData)
                            {
                                Author = fo;
                            }
                            break;

                        case "RECIPIENTS":
                            if (dataItem.HasValues)
                            {
                                List <InstagramObject> recipients = null;
                                foreach (string value in dataItem.Values)
                                {
                                    {
                                        InstagramObject newRecipient = new InstagramObject(value);
                                        if (newRecipient.HasData)
                                        {
                                            if (recipients == null)
                                            {
                                                recipients = new List <InstagramObject>();
                                            }
                                            recipients.Add(newRecipient);
                                        }
                                    }
                                }
                                if (recipients != null && recipients.Any())
                                {
                                    Recipients = recipients;
                                }
                            }
                            break;

                        case "LINKED MEDIA FILE:":
                            LinkedMediaFile = dataItem.Value;
                            break;

                        default:
                            logger.LogWarning("Unexpected Html Element - \"" + dataSectionName + ": " + dataItem.Header + "\".  Please contact NDCAC with section name and test data to improve parsing functionality");
#if DEBUG
                            throw new ApplicationException(dataItem.Header);
#endif
                            break;
                        }
                    }
                }
            }