Exemple #1
0
        public static BitmapImage ToBitmapImage(this Bitmap bitmap)
        {
            if (bitmap == null)
            {
                return(null);
            }

            BitmapImage bImg = null;

            try
            {
                ThreadDispatcher.Invoke(() =>
                {
                    MemoryStream ms = new MemoryStream();
                    bitmap.Save(ms, ImageFormat.Png);
                    bImg = new BitmapImage();

                    ms.Position = 0;

                    bImg.BeginInit();
                    bImg.StreamSource = ms;
                    bImg.EndInit();
                });
                return(bImg);
            }
            catch
            {
                return(null);
            }
        }
Exemple #2
0
 protected void NotifyPropertyChanging([CallerMemberName] string propertyName = "")
 {
     if (PropertyChanging != null)
     {
         ThreadDispatcher.Invoke(() => PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(propertyName)));
     }
 }
Exemple #3
0
 public void Dispatch(Action action)
 {
     if (IsReadyToDispatch)
     {
         ThreadDispatcher.Invoke(DispatcherPriority.Send, new TimeSpan(0, 0, 0, 0, 500), action);
     }
     else
     {
         _queuedActions.Enqueue(action);
     }
 }
Exemple #4
0
        void manager_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;

            ThreadDispatcher.Invoke(() =>
            {
                try
                {
                    MessageBox.Show(e.Exception.ToString());
                }
                catch
                { }
            });
        }
Exemple #5
0
 /// <summary>
 /// CommentString the item.
 /// </summary>
 private void CommentItem()
 {
     try
     {
         var postData = "comment_text=" + this.comment;
         this.httpContainer.InstagramPost(string.Format(CommentUri, this.imageId), this.csrfToken,
                                          this.referrer, postData, true);
     }
     catch (InstagramCommentException ex)
     {
         ThreadDispatcher.Invoke(() => this.CurrentContext.HandleException(ex));
         ThreadDispatcher.Invoke(() => this.CurrentContext.Comment = false);
         this.log.Error(ex.Message);
     }
 }
Exemple #6
0
 private void RunTask()
 {
     try
     {
         _method.Invoke(_progress);
     }
     catch (Exception e)
     {
         ThreadDispatcher.Invoke(() => MessageBox.Show(e.Message));
     }
     finally
     {
         ThreadDispatcher.Invoke(Close);
     }
 }
Exemple #7
0
        /// <summary>
        /// Unloads the loaded <see cref="GLFW" /> interface implementation.
        /// </summary>
        public static void Unload()
        {
            GLFW.Value.Terminate();
            GLFW = new Lazy <Glfw>(() =>
            {
                var glfw = Glfw.GetApi();

                ThreadDispatcher.Invoke(() =>
                {
                    glfw.Init();
                    glfw.SetErrorCallback(Glfw.ErrorCallback);
                });

                return(glfw);
            });
        }
Exemple #8
0
        /// <summary>
        /// Main strategy function. Explores instagram by keyword, likes, comments, followes
        /// based on settings coming from UI.
        /// </summary>
        public void Explore()
        {
            try
            {
                ThreadDispatcher.Invoke(() => this.CurrentContext.ProcessState = ProcessState.Running);

                if (!this.httpContainer.InstagramLogin(this.CurrentContext.UserName, this.CurrentContext.Password))
                {
                    throw new InstagramException("An error occured during login!");
                }

                this.ExploreKeywords();
            }
            catch (Exception ex)
            {
                ThreadDispatcher.Invoke(() => this.CurrentContext.HandleException(ex));
            }
        }
Exemple #9
0
        /// <summary>
        /// Creates a new instance of the GlfwProvider class.
        /// </summary>
        static GlfwProvider()
        {
            ThreadDispatcher = new Dispatcher();
            GLFW             = new Lazy <Glfw>(() =>
            {
                if (ThreadDispatcher == null)
                {
                    ThreadDispatcher = new Dispatcher();
                }

                var glfw = Glfw.GetApi();

                ThreadDispatcher.Invoke(() =>
                {
                    glfw.Init();
                    glfw.SetErrorCallback(Glfw.ErrorCallback);
                });

                return(glfw);
            });
        }
Exemple #10
0
        /// <summary>
        /// Explores the keywords.
        /// </summary>
        private void ExploreKeywords()
        {
            foreach (var keyword in this.CurrentContext.Keywords.Split('|'))
            {
                this.currentPage = 1;

                this.log.Info("Working on keyword: " + keyword);
                if (this.ProcessStopped())
                {
                    return;
                }

                var exploreResponse = this.httpContainer.InstagramGet(string.Format(ExploreUri, keyword));
                if (exploreResponse == string.Empty)
                {
                    continue;
                }

                var mediaJson =
                    Regex.Matches(exploreResponse, "<script type=\"text/javascript\">window._sharedData =(.*?);</script>")[0].Groups[1]
                    .Value;
                var keywordCsrf = Regex.Match(exploreResponse.Replace(" ", string.Empty), "\"csrf_token\":\"(\\w+)\"").Groups[1].Value;

                dynamic dyn = JsonConvert.DeserializeObject(mediaJson);

                foreach (var node in dyn.entry_data.TagPage[0].tag.media.nodes)
                {
                    this.log.Info("Working on image: " + node.code.ToString());

                    if (this.ProcessStopped())
                    {
                        return;
                    }

                    this.SetNewImage(node);

                    this.imageCode = node.code.ToString();

                    this.GetDetails();

                    Thread.Sleep(this.GetRandomTimeout());
                }

                if (this.CurrentContext.Paging && this.currentPage < this.CurrentContext.MaxPages && Convert.ToBoolean(dyn.entry_data.TagPage[0].tag.media.page_info.has_next_page))
                {
                    this.currentPage++;

                    var postData = PageQueryPostString.Replace("%0%", keyword)
                                   .Replace("%1%", dyn.entry_data.TagPage[0].tag.media.page_info.end_cursor.ToString());

                    var json = this.httpContainer.InstagramPost(QueryUri, keywordCsrf, string.Format(ExploreUri, keyword), postData);
                    if (json == string.Empty)
                    {
                        continue;
                    }

                    dyn = JsonConvert.DeserializeObject(json);

                    while (Convert.ToBoolean(dyn.media.page_info.has_next_page) == true)
                    {
                        foreach (var node in dyn.media.nodes)
                        {
                            this.log.Info("Working on image: " + node.code.ToString());

                            if (this.ProcessStopped())
                            {
                                return;
                            }

                            this.SetNewImage(node);

                            this.imageCode = node.code.ToString();

                            this.GetDetails();

                            Thread.Sleep(this.GetRandomTimeout());
                        }

                        if (this.ProcessStopped())
                        {
                            return;
                        }

                        Thread.Sleep(this.GetRandomTimeout());

                        this.currentPage++;

                        postData = PageQueryPostString.Replace("%0%", keyword)
                                   .Replace("%1%", dyn.media.page_info.end_cursor.ToString());

                        json = this.httpContainer.InstagramPost(QueryUri, keywordCsrf, string.Format(ExploreUri, keyword), postData);
                        if (json == string.Empty)
                        {
                            continue;
                        }

                        dyn = JsonConvert.DeserializeObject(json);
                    }
                }
            }

            this.log.Info("Finished.");
            ThreadDispatcher.Invoke(() => this.CurrentContext.ProcessState = ProcessState.Finished);
        }
Exemple #11
0
        /// <summary>
        /// Sets the current image in main window (thread safe).
        /// </summary>
        /// <param name="node">The node.</param>
        private void SetNewImage(dynamic node)
        {
            var imageUri = node.display_src.ToString().Replace("\\", string.Empty);

            ThreadDispatcher.Invoke(() => this.CurrentContext.UpdateCurrentImage(imageUri));
        }
Exemple #12
0
 protected override void ClearItems()
 {
     ThreadDispatcher.Invoke(() => base.ClearItems());
 }
Exemple #13
0
 protected override void SetItem(int index, T item)
 {
     ThreadDispatcher.Invoke(() => base.SetItem(index, item));
 }
Exemple #14
0
 protected override void RemoveItem(int index)
 {
     ThreadDispatcher.Invoke(() => base.RemoveItem(index));
 }
Exemple #15
0
 protected override void MoveItem(int oldIndex, int newIndex)
 {
     ThreadDispatcher.Invoke(() => base.MoveItem(oldIndex, newIndex));
 }
        public void Unfollow(bool all)
        {
            try
            {
                ThreadDispatcher.Invoke(() => this.CurrentContext.ProcessState = ProcessState.Running);

                if (!this.httpContainer.InstagramLogin(this.CurrentContext.UserName, this.CurrentContext.Password))
                {
                    throw new InstagramException("An error occured during login!");
                }

                var detailResponse = this.httpContainer.InstagramGet(string.Format(UserUri, this.CurrentContext.UserName));
                if (detailResponse == string.Empty)
                {
                    throw new InstagramException("Could not get followed users from instagram!");
                }

                this.referrer  = string.Format(UserUri, this.CurrentContext.UserName);
                this.csrfToken = Regex.Match(detailResponse.Replace(" ", string.Empty), "\"csrf_token\":\"(\\w+)\"").Groups[1].Value;

                var     profileJson = Regex.Matches(detailResponse, "<script type=\"text/javascript\">window._sharedData =(.*?);</script>")[0].Groups[1].Value;
                dynamic dyn         = JsonConvert.DeserializeObject(profileJson);
                dynamic dynPage     = JsonConvert.DeserializeObject(dyn.entry_data.ProfilePage[0].ToString());

                this.userId = dynPage.user.id.ToString();

                var postData = FollowingQueryPostString.Replace("%0%", this.userId);

                var json = this.httpContainer.InstagramPost(QueryUri, this.csrfToken, string.Format(UserUri, this.CurrentContext.UserName), postData);
                if (json == string.Empty)
                {
                    throw new InstagramException("Could not get followed users from instagram!");
                }

                dyn = JsonConvert.DeserializeObject(json);

                foreach (var node in dyn.follows.nodes)
                {
                    var pic = node.profile_pic_url.ToString();

                    ThreadDispatcher.Invoke(() => this.CurrentContext.UpdateCurrentImage(pic));

                    if (this.ProcessStopped())
                    {
                        return;
                    }

                    Thread.Sleep(this.GetRandomTimeout());

                    if (all || !this.Follows(node.username.ToString()))
                    {
                        this.log.Info("Unfollwing user: "******"%0%", this.userId).Replace("%1%", dyn.follows.page_info.end_cursor.ToString());

                    json = this.httpContainer.InstagramPost(QueryUri, this.csrfToken, string.Format(UserUri, this.CurrentContext.UserName), postData);
                    if (json == string.Empty)
                    {
                        throw new InstagramException("Could not get followed users from instagram!");
                    }

                    dyn = JsonConvert.DeserializeObject(json);

                    foreach (var node in dyn.follows.nodes)
                    {
                        var pic = node.profile_pic_url.ToString();

                        ThreadDispatcher.Invoke(() => this.CurrentContext.UpdateCurrentImage(pic));

                        if (this.ProcessStopped())
                        {
                            return;
                        }

                        Thread.Sleep(this.GetRandomTimeout());

                        if (all || !this.Follows(node.username.ToString()))
                        {
                            this.log.Info("Unfollwing user: "******"Finished.");
                ThreadDispatcher.Invoke(() => this.CurrentContext.ProcessState = ProcessState.Finished);
            }
            catch (Exception ex)
            {
                ThreadDispatcher.Invoke(() => this.CurrentContext.HandleException(ex));
            }
        }