public static DialogResult ShowExceptionDialog(Exception e, bool resumable)
 {
     ExceptionManager.Publish(e);
     try
     {
         StringBuilder errorMsg =
             new StringBuilder(String.Format(SR.ExceptionGeneralCritical, RssBanditApplication.GetLogFileName()));
         errorMsg.Append("\n" + e.Message);
         if (Application.MessageLoop && e.Source != null)
         {
             errorMsg.Append("\n@:" + e.Source);
         }
         return
             (MessageBox.Show(errorMsg.ToString(),
                              SR.GUIErrorMessageBoxCaption,
                              (resumable ? MessageBoxButtons.AbortRetryIgnore : MessageBoxButtons.OK),
                              MessageBoxIcon.Stop));
     }
     catch (Exception ex)
     {
         _log.Error("Critical exception in ShowExceptionDialog() ", ex);
         /* */
     }
     return(DialogResult.Abort);
 }
Example #2
0
        public ThreadResultManager(RssBanditApplication owner, System.Windows.Forms.Timer uiDispatcher)
        {
            this.owner         = owner;
            this.processResult = uiDispatcher;
            resultInfos        = PriorityQueue.Synchronize(new PriorityQueue());

            this.owner.FeedSources.ForEach(delegate(FeedSource f) { ConnectFeedSourceEvents(f); });

            //processResult = new System.Timers.Timer(250);
            processResult.Tick    += new EventHandler(OnProcessResultTick);          //new System.Timers.ElapsedEventHandler(OnProcessResultElapsed);
            processResult.Interval = 250;
            processResult.Start();
        }
Example #3
0
        private static int Main(string[] args)
        {
            bool running = true;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            // This might fix the SEHException raised sometimes. See issue:
            // https://sourceforge.net/tracker/?func=detail&aid=2335753&group_id=96589&atid=615248
            Application.DoEvents();

            // child threads should impersonate the current windows user
            AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);

            /* setup handler for unhandled exceptions in non-debug modes */
            // Allow exceptions to be unhandled so they break in the debugger
#if !DEBUG
            ApplicationExceptionHandler eh = new ApplicationExceptionHandler();

            AppDomain.CurrentDomain.UnhandledException += eh.OnAppDomainException;
#endif

#if DEBUG && TEST_I18N_THISCULTURE
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(new I18NTestCulture().Culture);
            Thread.CurrentThread.CurrentCulture   = Thread.CurrentThread.CurrentUICulture;
#endif

            FormWindowState initialStartupState = Win32.GetStartupWindowState();
            // if you want to debug the minimzed startup (cannot be configured in VS.IDE),
            // comment out the line above and uncomment the next one:
            //FormWindowState initialStartupState =  FormWindowState.Minimized;

            RssBanditApplication  appInstance = new RssBanditApplication();
            OtherInstanceCallback callback    = appInstance.OnOtherInstance;
            try
            {
                running = InitialInstanceActivator.Activate(appInstance, callback, args);
            }
            catch (Exception /* ex */)
            {
                //_log.Error(ex); /* other instance is probably still running */
            }
            //_log.Info("Application v" + RssBanditApplication.VersionLong + " started, running instance is " + running);

            RssBanditApplication.StaticInit(appInstance);
            if (!running)
            {
                // init to system default:
                RssBanditApplication.SharedCulture   = CultureInfo.CurrentCulture;
                RssBanditApplication.SharedUICulture = CultureInfo.CurrentUICulture;

                if (appInstance.HandleCommandLineArgs(args))
                {
                    if (!string.IsNullOrEmpty(appInstance.CommandLineArgs.LocalCulture))
                    {
                        try
                        {
                            RssBanditApplication.SharedUICulture =
                                CultureInfo.CreateSpecificCulture(appInstance.CommandLineArgs.LocalCulture);
                            RssBanditApplication.SharedCulture = RssBanditApplication.SharedUICulture;
                        }
                        catch (Exception ex)
                        {
                            appInstance.MessageError(String.Format(
                                                         SR.ExceptionProcessCommandlineCulture,
                                                         appInstance.CommandLineArgs.LocalCulture,
                                                         ex.Message));
                        }
                    }

                    // take over customized cultures to current main thread:
                    Thread.CurrentThread.CurrentCulture   = RssBanditApplication.SharedCulture;
                    Thread.CurrentThread.CurrentUICulture = RssBanditApplication.SharedUICulture;

                    if (!appInstance.CommandLineArgs.StartInTaskbarNotificationAreaOnly &&
                        initialStartupState != FormWindowState.Minimized)
                    {
                        // no splash, if start option is tray only or minimized
                        Splash.Show(SR.AppLoadStateLoading,
                                    String.Format(String.IsNullOrEmpty(RssBanditApplication.versionPostfix) ? "v{0}": "v{0} {1}",
                                                  RssBanditApplication.Version, RssBanditApplication.versionPostfix)
                                    );
                    }

                    if (appInstance.Init())
                    {
                        // does also run the windows event loop:
                        appInstance.StartMainGui(initialStartupState);
                        Splash.Close();
                    }
                    else
                    {
                        return(3); // init error
                    }
                    return(0);     // OK
                }
                return(2);         // CommandLine error
            }
            return(1);             // other running instance
        }
Example #4
0
 internal IdentityNewsServerManager(RssBanditApplication app)
 {
     this.app       = app;
     this.cachePath = RssBanditApplication.GetFeedFileCachePath();
 }
Example #5
0
 public FetchNewsgroupsThreadHandler(RssBanditApplication app, INntpServerDefinition sd)
 {
     this.app        = app;
     this.serverDef  = sd;
     this.Newsgroups = new List <string>(0);
 }
Example #6
0
        /// <summary>
        /// The worker method.
        /// </summary>
        /// <param name="task"></param>
        protected override Exception DoTaskWork(ThreadWorkerTaskBase task)
        {
            //if ((Task)task.TaskID == Task.AnonymousDelegate)
            //{
            //    Action action = (Action)task.Arguments[0];
            //    if (action == null)
            //        throw new InvalidOperationException("no Action delegate specified");

            //    action();
            //    // default event if no result(s) from processing:
            //    RaiseBackgroundTaskFinished(task, 1, 1, null, null);
            //    return null;
            //}

            RssBanditApplication app = ((ThreadWorkerTask)task).Application;
            int maxTasks = 0, currentTask = 0;

            bool          force;
            UltraTreeNode feedNode;
            string        stylesheet, html;

            switch ((Task)task.TaskID)
            {
            case Task.LoadAllFeedSourcesSubscriptions:
                List <FeedSourceEntry> entries = (List <FeedSourceEntry>)task.Arguments[0];
                var finished = new ManualResetEvent(false);
                int max      = entries.Count;
                int current  = 0;

                for (int i = 0; i < max; i++)
                {
                    IndexedFeedSourceEntry e = new IndexedFeedSourceEntry(entries[i], i);

                    PriorityThreadPool.QueueUserWorkItem(
                        delegate(object state)
                    {
                        IndexedFeedSourceEntry fs = (IndexedFeedSourceEntry)state;
                        int threadCurrent         = fs.Index + 1;

                        try
                        {
                            app.LoadFeedSourceSubscriptions(fs.Entry, true);
                            this.RaiseBackroundTaskProgress(task, max, threadCurrent, null, fs.Entry);
                        }
                        catch (Exception loadEx)
                        {
                            this.RaiseBackroundTaskProgress(task, max, threadCurrent, loadEx, fs.Entry);
                        }
                        finally
                        {
                            if (Interlocked.Increment(ref current) >= max)
                            {
                                if (finished != null)
                                {
                                    finished.Set();
                                }
                            }
                        }
                    }, e, 1);
                }

                if (max > 0)
                {
                    finished.WaitOne(Timeout.Infinite, true);
                }

                break;

            case Task.LoadFeedSourceSubscriptions:
                app.LoadFeedSourceSubscriptions((FeedSourceEntry)task.Arguments[0], true);
                break;

            // code mocved to FlaggedItemsFeed migrate method:
            //case Task.LoadSpecialFeeds:
            //    app.InitializeFlaggedItems();
            //    break;

            case Task.RefreshFeeds:
                force = (bool)task.Arguments[0];
                app.FeedSources.ForEach(s => s.RefreshFeeds(force));
                break;

            case Task.RefreshCommentFeeds:
                force = (bool)task.Arguments[0];
                app.CommentFeedsHandler.RefreshFeeds(force);
                break;

            case Task.RefreshCategoryFeeds:
                FeedSourceEntry entry    = (FeedSourceEntry)task.Arguments[0];
                string          category = (string)task.Arguments[1];
                force = (bool)task.Arguments[2];
                entry.Source.RefreshFeeds(category, force);
                break;

            case Task.LoadCommentFeed:
                INewsItem item = (INewsItem)task.Arguments[0];
                if (item == null)
                {
                    throw new InvalidOperationException("Non-Null task argument 'item' expected.");
                }

                object result = null;

                if ((item.Feed != null) && (item.Feed.owner is IFacebookFeedSource))
                {
                    IFacebookFeedSource fbSource = item.Feed.owner as IFacebookFeedSource;
                    result = fbSource.GetCommentsForItem(item);
                }
                else
                {
                    NewsFeed cmtFeed = new NewsFeed();
                    cmtFeed.link  = item.CommentRssUrl;
                    cmtFeed.title = item.Feed.title;

                    if (!string.IsNullOrEmpty(item.Feed.authUser))
                    {           // take over credential settings
                        string u = null, p = null;
                        FeedSource.GetFeedCredentials(item.Feed, ref u, ref p);
                        FeedSource.SetFeedCredentials(cmtFeed, u, p);
                    }

                    result = RssParser.DownloadItemsFromFeed(cmtFeed, app.Proxy, FeedSource.Offline);
                }
                RaiseBackgroundTaskFinished(task, maxTasks, currentTask, null, new object[] { result, item, task.Arguments[1], task.Arguments[2] });
                return(null);

            case Task.TransformFeed:
                IFeedDetails feed = (IFeedDetails)task.Arguments[0];
                feedNode   = (UltraTreeNode)task.Arguments[1];
                stylesheet = (string)task.Arguments[2];
                html       = app.FormatFeed(stylesheet, feed);

                RaiseBackgroundTaskFinished(task, maxTasks, currentTask, null,
                                            new object[] { feedNode, html });
                return(null);

            case Task.TransformCategory:
                FeedInfoList feeds = (FeedInfoList)task.Arguments[0];
                feedNode   = (UltraTreeNode)task.Arguments[1];
                stylesheet = (string)task.Arguments[2];

                html = app.FormatFeeds(stylesheet, feeds);

                RaiseBackgroundTaskFinished(task, maxTasks, currentTask, null,
                                            new object[] { feedNode, html });
                return(null);

            default:
                throw new InvalidOperationException("Unhandled ThreadWorker Task: " + task.TaskID);
            }

            // default event if no result(s) from processing:
            RaiseBackgroundTaskFinished(task, maxTasks, currentTask, null, null);
            return(null);
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ThreadWorkerTask"/> class.
 /// </summary>
 /// <param name="task">The task.</param>
 /// <param name="progressHandler">The progress handler.</param>
 /// <param name="application">The RssBanditApplication.</param>
 /// <param name="args">The ask args.</param>
 public ThreadWorkerTask(ThreadWorker.Task task, ThreadWorkerProgressHandler progressHandler, RssBanditApplication application, params object[] args) :
     base(task, progressHandler, args)
 {
     this.app = application;
 }
Example #8
0
 public static string GetChannelName()
 {
     return(GetChannelName(RssBanditApplication.GetUserPath()));
 }