コード例 #1
0
ファイル: PipeHandler.cs プロジェクト: radtek/frznUpload
        private static async void PipeServer(ArgumentsHandler handler, CancellationToken token)
        {
            var pipeServer = new NamedPipeServerStream("frznUploadPipe", PipeDirection.In, 1);

            var serializer = new XmlSerializer(typeof(string[]));


            while (true)
            {
                try
                {
                    await pipeServer.WaitForConnectionAsync(token);

                    var reader = new StreamReader(pipeServer, Encoding.UTF8, false, 100, true);

                    string s = reader.ReadToEnd();
                    log.Info("incoming Message:\n" + s);


                    using (var stringReader = new StringReader(s))
                    {
                        handler.HandleArguments((string[])serializer.Deserialize(stringReader));
                    }

                    reader.Dispose();
                    pipeServer.Disconnect();
                }
                catch (IOException e)
                {
                    log.Info(e);
                    pipeServer.Dispose();
                    pipeServer = new NamedPipeServerStream("frznUploadPipe", PipeDirection.In, 1);
                }
            }
        }
コード例 #2
0
ファイル: PipeHandler.cs プロジェクト: radtek/frznUpload
        /// <summary>
        /// Starts the Named pipe server, if this is the server
        /// </summary>
        /// <param name="handler">An ArgumentsHandler to handle the incoming Messages from clients</param>
        public static void Start(ArgumentsHandler handler)
        {
            if (!IsServer)
            {
                return;
            }

            new Thread(() => PipeServer(handler, tokenSource.Token)).Start();
        }
コード例 #3
0
ファイル: IconHandler.cs プロジェクト: radtek/frznUpload
        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);
        }