Exemple #1
0
        /// <summary>
        /// Helper method to load a certificate and key from the Application directory
        /// (as determined by Directory.GetApplicationDirectory())
        /// </summary>
        /// <param name="cert_fn"> File name of the certificate to be loaded to the controller </param>
        /// <param name="key_fn"> File name of the matching private key for the controller </param>
        /// <param name="cert"> The X509Certificate, in DER format, read from cert_fn </param>
        /// <param name="key"> The byte[] for the private key, in DER format, taken from key_fn </param>
        /// <returns></returns>
        static void loadCertAndKey(string cert_fn, string key_fn, out X509Certificate cert, out byte[] key)
        {
            PrintAndLog("Loading certificate and key from " + cert_fn + " and " + key_fn + " in directory " + Directory.GetApplicationDirectory() + "...");
            byte[] bufCert; // intermediate buffer used to construct the X509Certificate
            try
            {
                using (FileStream fs = File.OpenRead(Directory.GetApplicationDirectory() + "\\" + cert_fn))
                    using (BinaryReader br = new BinaryReader(fs))
                    {
                        bufCert = br.ReadBytes((int)fs.Length);
                        br.Close();
                    }

                CrestronConsole.Print("Generating X509Certificate object... ");
                cert = new X509Certificate2(bufCert);
                CrestronConsole.PrintLine("done");

                // Extract the byte array from the key file
                using (FileStream fs = File.OpenRead(Directory.GetApplicationDirectory() + "\\" + key_fn))
                    using (BinaryReader br = new BinaryReader(fs))
                    {
                        key = br.ReadBytes((int)fs.Length);
                        br.Close();
                    }
            }
            catch (Exception e)
            {
                cert = null;
                key  = null;
                PrintAndLog("Error loading certificate and key: " + e.Message);
            }
        }
Exemple #2
0
        void clearSwitcher(uint hdmiOutput)
        {
            CrestronConsole.Print("\nClearing the route\r\n");
            DMOutput outputToClear = deskSwitcher.Outputs[hdmiOutput] as DMOutput;

            outputToClear.VideoOut = null;
        }
Exemple #3
0
        public void Load()
        {
            string          text         = GetFileContents();
            MatchCollection regexMatches = Regex.Matches(text, @"\[([\w]+)\]\s+([^\r\n]*)");

            CrestronConsole.Print("Matches = {0}\r\n", regexMatches.Count);
            foreach (Match match in regexMatches)
            {
                try
                {
                    string key   = match.Groups[1].Value;
                    string value = match.Groups[2].Value;
                    Params[key]     = value;
                    EditParams[key] = value;
                }
                catch
                {
                    CrestronConsole.Print("Error processing a config parameter... check config syntax?!\r\n");
                }
            }
            CrestronConsole.Print("Params Loaded... ({0})\r\n", Params.Count);
            foreach (KeyValuePair <string, string> param in Params)
            {
                CrestronConsole.Print("  {0}: {1}\r\n", param.Key, param.Value);
            }
            EditParams = EditParams.OrderBy(k => k.Key).ToDictionary(k => k.Key, k => k.Value);
        }
        public void Send(string str)
        {
            var bytes = new byte[str.Length + 1];

            for (int i = 0; i < str.Length; i++)
            {
                bytes[i] = unchecked ((byte)str[i]);
            }

            bytes[str.Length] = 0x0a;

            _txQueue.Enqueue(bytes);

            if (_txThread == null || _txThread.ThreadState != Thread.eThreadStates.ThreadRunning)
            {
                _txThread = new Thread(specific =>
                {
                    Thread.CurrentThread.Name = string.Format("{0} Tx Handler", GetType().Name);
                    while (_programRunning)
                    {
                        var qBytes = _txQueue.Dequeue();
                        if (qBytes != null)
                        {
#if DEBUG
                            CrestronConsole.Print("QSys Tx: ");
                            Tools.PrintBytes(qBytes, qBytes.Length, true);
#endif
                            ComPort.Send(qBytes, qBytes.Length);
                        }
                    }
                    return(null);
                }, null);
            }
        }
 private static void SendDataAsync(string dataToSend)
 {
     try
     {
         byte[] SendData = System.Text.Encoding.ASCII.GetBytes(dataToSend);
         for (uint index = 1; index <= tcpServer.NumberOfClientsConnected; index++)
         {
             if (debug > 0)
             {
                 CrestronConsole.Print("\n Catch Connect SendDataAsync attempt for index: " + index);
             }
             if (tcpServer.ClientConnected(index))
             {
                 SocketErrorCodes resultCodes = tcpServer.SendDataAsync(index, SendData, SendData.Length, OnTCPServerSendCallback);
                 if (debug > 0)
                 {
                     CrestronConsole.Print("\n Catch Connect SendDataAsync resultCodes: " + resultCodes.ToString());
                 }
             }
             else
             {
                 CrestronConsole.Print("\n Catch Connect SendDataAsync client not connected at index: " + index);
             }
         }
     }
     catch (Exception e)
     {
         ErrorLog.Error("error = " + e.Message);
     }
 }
        private static void tcpServer_SocketStatusChange(TCPServer myTCPServer, uint clientIndex, SocketStatus serverSocketStatus)
        {
            if (debug > 0)
            {
                CrestronConsole.Print("\n Catch Connect SocketStatusChange serverSocketStatus: {0} for index: {1}", serverSocketStatus.ToString(), clientIndex.ToString());
            }

            ushort online = 0;

            switch (serverSocketStatus)
            {
            case SocketStatus.SOCKET_STATUS_CONNECTED:
                online = 1;
                ProcessQueue();
                break;

            case SocketStatus.SOCKET_STATUS_NO_CONNECT:
                online = 0;
                myTCPServer.DisconnectAll();
                StartListening();
                break;

            default:
                break;
            }
            OnServiceEvent(online, (ushort)serverSocketStatus, serverSocketStatus.ToString());
        }
Exemple #7
0
 public void Init(string filePath)
 {
     RoomName   = "";
     Params     = new Dictionary <string, string>();
     EditParams = new Dictionary <string, string>();
     FilePath   = filePath;
     CrestronConsole.Print("System / Room Config... Config Path = {0}\r\n", FilePath);
 }
 private static void OnTCPServerSendCallback(TCPServer myTCPServer, uint clientIndex, int numberOfBytesSent)
 {
     ProcessQueue();
     if (debug > 0)
     {
         CrestronConsole.Print("\n Catch Connect OnTCPServerSendCallback clientIndex: {0}, numberOfBytesSent: {1}", clientIndex, numberOfBytesSent);
     }
 }
        private void WriteImpl(string message)
        {
            if (NeedIndent)
            {
                WriteIndent();
            }

            CrestronConsole.Print(message);
        }
Exemple #10
0
        public void checkPushes()
        {
            CrestronConsole.PrintLine("Getting Previous Pushes");

            HttpsClient hsc = new HttpsClient();

            hsc.PeerVerification = false;
            hsc.HostVerification = false;
            HttpsClientRequest hscr = new HttpsClientRequest();

            //HttpsClientResponse hscrs;

            hsc.KeepAlive = true;
            hscr.Url.Parse("https://api.pushbullet.com/v2/pushes?active=true&modified_after=" + lastModified);
            //hscr.Header.AddHeader(new HttpsHeader("Access-Token", token));
            hscr.RequestType = Crestron.SimplSharp.Net.Https.RequestType.Get;
            hscr.Header.AddHeader(new HttpsHeader("Content-Type", "application/json"));
            hscr.Header.AddHeader(new HttpsHeader("Authorization", "Bearer " + token));
            //hscr.ContentString = JsonConvert.SerializeObject(hscr.ToString());
            hsc.DispatchAsync(hscr, (hscrs, e) =>
            {
                try
                {
                    if (hscrs.Code >= 200 && hscrs.Code < 300)
                    {
                        // success
                        //CrestronConsole.PrintLine("Old Pushes Requst Send.");
                        //string s = hscrs.ContentString.ToString();
                        //CrestronConsole.Print("Old Push Data: " + s + "\n");
                        pushReturn pr = JsonConvert.DeserializeObject <pushReturn>(hscrs.ContentString);

                        foreach (pushData pd in pr.pushes)
                        {
                            //CrestronConsole.Print("Json Push Data: " + pr.ToString() + "\n");
                            if (pd.modified > lastModified)
                            {
                                lastModified = pd.modified;
                                CrestronConsole.Print("Json Push Data: " + pd.body + "\n");
                                if (pd.body.ToLower().StartsWith("unlock"))
                                {
                                    OnNewResponse(new SimplSharpString(pd.body.ToLower()));
                                }
                                else if (pd.body.ToLower().StartsWith("ignore"))
                                {
                                    OnNewResponse(new SimplSharpString(pd.body.ToLower()));
                                }
                            }
                        }
                    }
                }
                catch (Exception f)
                {
                    CrestronConsole.PrintLine("Old Push Connection error:" + f.ToString());
                }
            });
        }
Exemple #11
0
 public Sheet ReadCsvText(List <string> lines)
 {
     sheet   = new Sheet();
     section = null;
     CrestronConsole.Print(".");
     try {
         ParseCells(lines);
     } catch (Exception ex) { ErrorMessage.Warn("Unity.GoogleSheetsReader ParseCells(): {0}", ex.Message); }
     return(sheet);
 }