Ejemplo n.º 1
0
        public void ParseNewSigFile()
        {
            Log("---------------");
            Log("Parsing new SIG file");

            string sigFileName = System.IO.Path.ChangeExtension(this.SPZFileLocation, ".sig");

            byte[] sigFile = System.IO.File.ReadAllBytes(sigFileName);

            signalListAfterDeployment.Clear();

            string signalFileType = "";
            int    index          = 0;

            while (true)
            {
                signalFileType += (char)(sigFile[index]);
                index++;
                if (signalFileType.EndsWith("]"))
                {
                    break;
                }
            }

            if (signalFileType != "[RLSIG0001]" && signalFileType != "[LOGOSSIG001.000]")
            {
                Log("Unknown sig file type");
            }

            Log("Signal file type: " + signalFileType);

            while (index < sigFile.Length)
            {
                var length = BitConverter.ToUInt16(sigFile, index) - 8;
                index = index + 2;
                string signalName  = "";
                uint   signalIndex = 0;
                byte   signalType  = 0;
                byte   signalFlags = 0;

                if (signalFileType == "[RLSIG0001]")
                {
                    signalName = ASCIIEncoding.ASCII.GetString(sigFile, index, length);
                }
                else if (signalFileType == "[LOGOSSIG001.000]")
                {
                    signalName = Encoding.Unicode.GetString(sigFile, index, length);
                }

                index += length;

                if (!string.IsNullOrEmpty(signalName))
                {
                    signalIndex = BitConverter.ToUInt32(sigFile, index);
                    index      += 4;
                }

                signalType = sigFile[index];
                index++;
                signalFlags = sigFile[index];
                index++;

                var x = new CrestronSignal()
                {
                    SignalName = signalName, SignalIndex = signalIndex, SignalFlags = signalFlags, SignalType = signalType
                };
                //Log("\t" + x.ToString());
                signalListAfterDeployment.Add(x);

                if (signalListAfterDeployment.Count % 25 == 0)
                {
                    Log("\t" + signalListAfterDeployment.Count.ToString() + " signals parsed");
                }
            }

            //save it
            var signalListJson = Newtonsoft.Json.JsonConvert.SerializeObject(signalListAfterDeployment.ToArray());

            if (System.IO.File.Exists(TempDirectory + "NewSignals.json"))
            {
                System.IO.File.Delete(TempDirectory + "NewSignals.json");
            }

            System.IO.File.WriteAllText(TempDirectory + "NewSignals.json", signalListJson);
        }
Ejemplo n.º 2
0
        private void UnzipAndParseSig()
        {
            Log("---------------");
            Log("Unzipping and parsing SIG file");

            if (System.IO.Directory.Exists(TempDirectory + @"TEC HD\"))
            {
                System.IO.Directory.Delete(TempDirectory + @"TEC HD\", true);
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(TempDirectory + @"TEC HD.zig", TempDirectory + @"TEC HD\");

            byte[] sigFile = System.IO.File.ReadAllBytes(TempDirectory + @"TEC HD\TEC HD.sig");

            signalList.Clear();

            string signalFileType = "";
            int    index          = 0;

            while (true)
            {
                signalFileType += (char)(sigFile[index]);
                index++;
                if (signalFileType.EndsWith("]"))
                {
                    break;
                }
            }

            if (signalFileType != "[RLSIG0001]" && signalFileType != "[LOGOSSIG001.000]")
            {
                Log("Unknown sig file type");
            }

            Log("Signal file type: " + signalFileType);

            while (index < sigFile.Length)
            {
                var length = BitConverter.ToUInt16(sigFile, index) - 8;
                index = index + 2;
                string signalName  = "";
                uint   signalIndex = 0;
                byte   signalType  = 0;
                byte   signalFlags = 0;

                if (signalFileType == "[RLSIG0001]")
                {
                    signalName = ASCIIEncoding.ASCII.GetString(sigFile, index, length);
                }
                else if (signalFileType == "[LOGOSSIG001.000]")
                {
                    signalName = Encoding.Unicode.GetString(sigFile, index, length);
                }

                index += length;

                if (!string.IsNullOrEmpty(signalName))
                {
                    signalIndex = BitConverter.ToUInt32(sigFile, index);
                    index      += 4;
                }

                signalType = sigFile[index];
                index++;
                signalFlags = sigFile[index];
                index++;

                var x = new CrestronSignal()
                {
                    SignalName = signalName, SignalIndex = signalIndex, SignalFlags = signalFlags, SignalType = signalType
                };
                //Log("\t" + x.ToString());
                signalList.Add(x);

                if (signalList.Count % 25 == 0)
                {
                    Log("\t" + signalList.Count.ToString() + " signals parsed");
                }
            }

            //save it
            var signalListJson = Newtonsoft.Json.JsonConvert.SerializeObject(signalList.ToArray());

            if (System.IO.File.Exists(TempDirectory + "OldSignals.json"))
            {
                System.IO.File.Delete(TempDirectory + "OldSignals.json");
            }

            System.IO.File.WriteAllText(TempDirectory + "OldSignals.json", signalListJson);
        }