예제 #1
0
        static void Main(string[] args)
        {
            var f = new FileInfo(System.Reflection.Assembly.GetEntryAssembly().Location);

            Directory.SetCurrentDirectory(f.Directory.FullName);

            var rollingFileAppender = new RollingFileAppender()
            {
                Layout             = new PatternLayout("%date{HH:mm:ss} [%thread] %-3level %logger - %message%newline"),
                File               = "rollingLog.txt",
                AppendToFile       = true,
                MaximumFileSize    = "100KB",
                MaxSizeRollBackups = 2
            };

            rollingFileAppender.ActivateOptions();

            BasicConfigurator.Configure(
                new ConsoleAppender(),
                rollingFileAppender
                );

            if (HandleSquirrel(args))
            {
                return;
            }

            var configFileMap = new ExeConfigurationFileMap();

#if DEBUG
            configFileMap.ExeConfigFilename = "App.Release.config";
#else
            configFileMap.ExeConfigFilename = "App.Release.config";
#endif
            Config.Configuration = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);



            log.Info("Starting...");

            log.Info("Working Directory: " + Directory.GetCurrentDirectory());

            Application.ThreadException += Application_ThreadException;

            Task.Run(Update);


            if (PipeHandler.IsServer)
            {
                ExplorerIntegrationHandler.Init();
                AutostartHandler.Init();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new IconHandler(args));
            }
            else
            {
                PipeHandler.SendMessage(args);
            }
        }
예제 #2
0
        public IconHandler(string[] args)
        {
            notifyIcon.Icon             = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);;
            notifyIcon.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip();
            notifyIcon.ContextMenuStrip.Items.Add("Show", null, Show);
            notifyIcon.ContextMenuStrip.Items.Add("Configuration", null, ShowConfig);
            notifyIcon.ContextMenuStrip.Items.Add("Exit", null, Exit);

            notifyIcon.MouseClick += new MouseEventHandler(LeftClick);
            //Dont show icon untill everything is set ups
            notifyIcon.Visible = false;

            CertificateHandler.Load();

            Client = new ClientManager();

            try
            {
                Task.Run(() => Client.Connect()).Wait();
            }
            catch (AggregateException ex)
            {
                MessageBox.Show("Agg Couldn´t connect:\n" + ex.InnerException.Message);



                string text = $"AggregateException with {ex.InnerExceptions.Count} InnerExceptions:\n" + ex.ToString() + "\nInnerExceptions:";

                foreach (Exception exception in ex.InnerExceptions)
                {
                    text += "\n" + exception.ToString();
                }

                File.WriteAllText("crashLog " + DateTime.Now.ToString("dd-MM-yy HH_mm") + ".txt", text);

                Thread.Sleep(1000);

                Exit();
                return;
            }
            catch (Exception e)
            {
                MessageBox.Show("Couldn´t connect:\n" + e.Message);
                File.WriteAllText("crashLog " + DateTime.Now.ToString("dd-MM-yy HH_mm") + ".txt", e.ToString());

                Exit();
                return;
            }

            mainForm = new MainForm(Client);

            //if client is not logged in -> show a login prompt
            if (Client.LoggedIn == false)
            {
                mainForm.Show();
            }

            FileUploadHandler.Init(mainForm, Client);
            mainForm.CreateControl();

            //Everything is ready -> show icon
            notifyIcon.Visible = true;

            var argumentsHandler = new ArgumentsHandler(mainForm);

            if (args.Length != 0)
            {
                argumentsHandler.HandleArguments(args);
            }

            PipeHandler.Start(argumentsHandler);
        }