Example #1
0
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private BitmapSource GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();

                desc.QRVersion = QR_VERSION;
                desc.GeneratorApp = GENERATOR_APP;

                desc.HardwareAddresses = String.Join(";", NetworkInformation.GetMACAddresses());
                desc.Addresses = String.Join(";", NetworkInformation.GetIPAddresses());
                desc.Name = Configuration.Services.GetServiceName();

                desc.Services = new List<ServiceDescription>();
                User wifiRemoteAuth = WifiRemote.IsInstalled ? WifiRemote.GetAuthentication() : null;
                foreach (var srv in Installation.GetInstalledServices())
                {
                    var srvdesc = new ServiceDescription()
                    {
                        Name = srv.Service.ToString(),
                        Port = srv.Port
                    };

                    if (auth != null)
                    {
                        srvdesc.User = (srv.Service == MPExtendedService.WifiRemote ? wifiRemoteAuth : auth).Username;
                        srvdesc.Password = (srv.Service == MPExtendedService.WifiRemote ? wifiRemoteAuth : auth).GetPassword();
                    }

                    desc.Services.Add(srvdesc);
                }

                Bitmap bm = QRCodeGenerator.Generate(desc.ToJSON());
                return bm.ToWpfBitmap();
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
                return null;
            }
        }
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private void GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();
                desc.GeneratorApp = "ServiceConfigurator";
                desc.ServiceType = "Client";

                desc.Port = Configuration.Services.Port;
                desc.Name = Configuration.Services.BonjourName;
                desc.HardwareAddresses = GetHardwareAddresses();
                desc.Hostname = GetServiceName();

                IPHostEntry host;
                String localIP = "?";
                StringBuilder localIPs = new StringBuilder();
                host = Dns.GetHostEntry(Dns.GetHostName());
                foreach (IPAddress ip in host.AddressList)
                {
                    if (ip.AddressFamily == AddressFamily.InterNetwork)
                    {
                        // Single address field
                        localIP = ip.ToString();

                        // Multiple addresses field
                        if (localIPs.Length > 0)
                        {
                            localIPs.Append(";");
                        }

                        localIPs.Append(ip.ToString());
                    }
                }

                desc.Addresses = (localIPs.Length > 0) ? localIPs.ToString() : "?";

                if (auth != null)
                {
                    desc.User = auth.Username;
                    desc.Password = auth.Password;
                    desc.AuthOptions = 1;
                }

                Bitmap bm = QRCodeGenerator.Generate(desc.ToJSON());
                imgQRCode.Source = bm.ToWpfBitmap();
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
            }
        }
Example #3
0
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private void GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();
                desc.HardwareAddresses = String.Join(";", NetworkInformation.GetMACAddresses());
                desc.Addresses = String.Join(";", NetworkInformation.GetIPAddresses());
                desc.Name = GetServiceName();
                desc.QRVersion = 1;

                desc.Services = new List<ServiceDescription>();
                foreach (var srv in Installation.GetInstalledServices())
                {
                    var srvdesc = new ServiceDescription()
                    {
                        Name = srv.ServiceName.ToString(),
                        Port = srv.Port
                    };

                    if (auth != null)
                    {
                        string usernameOut, passwordOut;
                        srv.GetUsernameAndPassword(auth, out usernameOut, out passwordOut);
                        srvdesc.User = usernameOut;
                        srvdesc.Password = passwordOut;
                    }

                    desc.Services.Add(srvdesc);
                }

                Bitmap bm = QRCodeGenerator.Generate(desc.ToJSON());
                imgQRCode.Source = bm.ToWpfBitmap();
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
            }
        }
Example #4
0
        /// <summary>
        /// Generate a QR Barcode with the server information
        /// </summary>
        private BitmapSource GenerateBarcode(User auth)
        {
            try
            {
                ServerDescription desc = new ServerDescription();

                desc.QRVersion = QR_VERSION;
                desc.GeneratorApp = GENERATOR_APP;

                desc.HardwareAddresses = String.Join(";", NetworkInformation.GetMACAddresses());
                desc.Addresses = String.Join(";", NetworkInformation.GetIPAddresses());
                desc.Name = Configuration.Services.GetServiceName();
                desc.NetbiosName = System.Environment.MachineName;
                desc.ExternalIp = ExternalAddress.GetAddress();

                desc.Services = new List<ServiceDescription>();
                User wifiRemoteAuth = WifiRemote.IsInstalled ? WifiRemote.GetAuthentication() : null;
                foreach (var srv in Installation.GetInstalledServices())
                {
                    var srvdesc = new ServiceDescription()
                    {
                        Name = srv.Service,
                        Port = srv.Port
                    };

                    if (auth != null)
                    {
                        srvdesc.User = (srv.Service == "WifiRemote" ? wifiRemoteAuth : auth).Username;
                        srvdesc.Password = (srv.Service == "WifiRemote" ? wifiRemoteAuth : auth).GetPassword();
                    }

                    desc.Services.Add(srvdesc);
                }

                var writer = new BarcodeWriter()
                {
                    Format = BarcodeFormat.QR_CODE,
                    Options = new EncodingOptions()
                    {
                        Height = 400,
                        Width = 400
                    }
                };

                var bitmap = writer.Write(desc.ToJSON());
                return bitmap.ToWpfBitmap();
            }
            catch (Exception ex)
            {
                Log.Error("Error generating barcode", ex);
                return null;
            }
        }