Ejemplo n.º 1
0
        /// <summary>
        /// Export a scan result to the FileSystem
        /// </summary>
        /// <param name="filterIndex">The filter index that was chosen by the user in the SaveFileDialog</param>
        private void ExportData(int filterIndex)
        {
            if (LvPorts.Items.Count == 0)
            {
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog
            {
                Filter      = "Text (*.txt)|*.txt|HTML (*.html)|*.html|CSV (*.csv)|*.csv|Excel (*.csv)|*.csv",
                FilterIndex = filterIndex
            };

            if (sfd.ShowDialog() != true)
            {
                return;
            }

            ExportType type;

            switch (sfd.FilterIndex)
            {
            default:
                type = ExportType.Text;
                break;

            case 2:
                type = ExportType.Html;
                break;

            case 3:
                type = ExportType.Csv;
                break;

            case 4:
                type = ExportType.Excel;
                break;
            }

            try
            {
                ExportWriter.Export(sfd.FileName, LvPorts, type);
                MessageBox.Show("Successfully exported all items!", "Advanced PortChecker", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Advanced PortChecker", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        private void startWebServer(int port, WebSocketsHandler webSockets)
        {
#if NET46
            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
#else
            var baseDirectory = AppContext.BaseDirectory;
#endif
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(baseDirectory)
                       .UseUrls($"http://localhost:{port}")
                       .Configure(app =>
            {
                app.UseWebSockets();

                app.Use(async(http, next) =>
                {
                    if (http.WebSockets.IsWebSocketRequest)
                    {
                        await webSockets.HandleSocket(http).ConfigureAwait(false);
                    }
                    else
                    {
                        await next().ConfigureAwait(false);
                    }
                });

#if DEBUG
                configureStaticFiles(app);
#endif

                app.Run(async http =>
                {
                    if (http.Request.Path == "/favicon.ico")
                    {
                        await writeFavicon(http).ConfigureAwait(false);

                        return;
                    }

                    try
                    {
                        http.Response.ContentType = "text/html";

                        if (http.Request.Path.HasValue && http.Request.Path.Value == "/preview")
                        {
                            var html = ExportWriter.BuildPage(_application);
                            await http.Response.WriteAsync(html).ConfigureAwait(false);
                        }
                        else
                        {
                            await HomeEndpoint.BuildPage(http.Response, _application, _input).ConfigureAwait(false);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                        throw;
                    }
                });
            });

            _server = host.Start();
        }