示例#1
0
        public CamControl(PodLocal.UpdateTray status, PodLocal.UpdateCameraList cameras)
        {
            updateStatus  += status;
            updateCamList += cameras;

            lock (_locker)
            {
                reloadCamera();
            }
        }
示例#2
0
        //
        // TODO:: provide an event hook for providing out of turn information to all the control systems connected
        //

        public Server(PodLocal.UpdateTray function)
        {
            if (server == null) // Singleton
            {
                updateStatus += function;
                int  port    = 443;
                int  attempt = 0;
                bool success = false;


                string certPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                certPath = Path.Combine(certPath, "serverCert.cer");
                string localPath = System.Reflection.Assembly.GetEntryAssembly().Location;
                localPath = Path.GetDirectoryName(localPath);

                while (attempt < 3 && !success)
                {
                    try
                    {
                        //certPath = Path.Combine(certPath, "serverCert.cer");
                        X509Certificate serverCert = X509Certificate.CreateFromCertFile(certPath);

                        server = new SecureTcpServer(port, serverCert,
                                                     new SecureConnectionResultsCallback(OnServerConnectionAvailable));
                        lock (_locker)
                        {
                            doStatusUpdate();
                        }
                        server.StartListening();
                        success = true;
                    }
                    catch (System.Net.Sockets.SocketException e)
                    {
                        if (e.SocketErrorCode == SocketError.AddressAlreadyInUse)
                        {
                            MessageBox.Show("Application already running. Socket in use.");
                            System.Environment.Exit(-1);
                            return;
                        }
                    }
                    catch
                    {
                        try
                        {
                            System.Diagnostics.Process.Start(Path.Combine(localPath, "makecert.exe"), "-r -pe -n \"CN=MachineName_SS\" -ss my -a sha1 -sky exchange -eku 1.3.6.1.5.5.7.3.1 -sp \"Microsoft RSA SChannel Cryptographic Provider\" -sy 12 \"" + certPath + "\"");
                            Thread.Sleep(5000);
                        }
                        catch
                        {
                            DialogResult res = MessageBox.Show("Encryption Failed. Unable to generate TLS key file...", "Security Notice");
                            System.Environment.Exit(-1);
                            return;
                        }
                    }

                    attempt++;
                }

                if (!success)
                {
                    System.Environment.Exit(-1);
                    return;
                }
            }
        }