Exemplo n.º 1
0
        internal void startReflector()
        {
            if (state != ReflectorState.DEPLOYED)
            {
                throw new InvalidOperationException("Reflector is not awaiting starting.");
            }

            reflector = new Process();
            reflector.StartInfo.FileName = reflectorDeploymentPath;

            reflectorPipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Message);
            //Console.WriteLine( "Pipe TransmissionMode: {0}.", reflectorPipe.TransmissionMode );

            reflector.StartInfo.Arguments       = pipeName;
            reflector.StartInfo.UseShellExecute = false;
            //reflector.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;   // Does nothing to stop the popup first appearing mid-screen
            // Redirect all console writes to the 1 handler
            reflector.StartInfo.CreateNoWindow         = true;
            reflector.StartInfo.RedirectStandardOutput = true;
            reflector.OutputDataReceived += outputHandler;
            reflector.StartInfo.RedirectStandardError = true;
            reflector.ErrorDataReceived += outputHandler;

            reflector.Start();
            reflector.BeginOutputReadLine();
            reflector.BeginErrorReadLine();
            //Console.WriteLine( "Reflector started." );

            reflectorWriter = new StreamWriter(reflectorPipe);
            //reflectorWriter.AutoFlush = true;
            reflectorReader = new StreamReader(reflectorPipe);

            reflectorPipe.WaitForConnection();
            state = ReflectorState.STARTED;
        }
Exemplo n.º 2
0
        internal void deployReflector(bool overwrite = true)
        {
            if (state != ReflectorState.UNDEPLOYED)
            {
                throw new InvalidOperationException("Reflector is not awaiting deployment.");
            }

            if (File.Exists(reflectorDeploymentPath) && !overwrite)
            {
                Console.WriteLine("Reflector file: " + REFLECTOR_EXE + " was already deployed, skipping.");
            }
            else
            {
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(REFLECTOR_RESOURCE_NAME))
                    using (var compressStream = new DeflateStream(stream, CompressionMode.Decompress))
                        using (var file = File.Create(reflectorDeploymentPath))
                        {
                            compressStream.CopyTo(file);
                        }
            }
            // Should checksum, whether overwriting or skipping?

            state = ReflectorState.DEPLOYED;
            //Console.WriteLine( "Reflector deployed." );
        }
Exemplo n.º 3
0
        private ReflectorState state;   // Should lock() access?


        public ReflectorManager(string TABdirectory)
        {
            if (!Directory.Exists(TABdirectory))
            {
                throw new ArgumentException("The provided TAB directory does not exist.");
            }

            reflectorDeploymentPath = Path.Combine(TABdirectory, REFLECTOR_EXE);

            resetReflector();

            outputHandler = defaultOutputHandler;

            state = ReflectorState.UNDEPLOYED;  // An assumption?
        }
Exemplo n.º 4
0
        internal void removeReflector()
        {
            if (state != ReflectorState.DEPLOYED)
            {
                throw new InvalidOperationException("Reflector is not awaiting removal.");
            }

            if (!File.Exists(reflectorDeploymentPath))
            {
                Console.WriteLine("Reflector file: " + REFLECTOR_EXE + " was not already deployed.");
            }
            else
            {
                File.Delete(reflectorDeploymentPath);
            }

            state = ReflectorState.UNDEPLOYED;
            //Console.WriteLine( "Reflector removed." );
        }
Exemplo n.º 5
0
        internal string generateChecksum(string saveFile)
        {
            if (state != ReflectorState.STARTED)
            {
                throw new InvalidOperationException("Reflector is not awaiting processing.");
            }

            state = ReflectorState.PROCESSING;

            writePipe(Char.ToString((char)PipeFlowControl.GenerateChecksum));
            writePipe(saveFile);
            string signature = readPipe();

            string checkFile = TAB.getCheckFile(saveFile);

            // Could first check if the existing contents are the same, and if so not overwrite. Unless something is expecting/needing LastModified to change?
            File.WriteAllText(checkFile, signature);

            state = ReflectorState.STARTED;
            return(signature);
        }
Exemplo n.º 6
0
        internal void stopReflector()
        {
            if (state != ReflectorState.STARTED)
            {
                throw new InvalidOperationException("Reflector is not awaiting stopping.");
            }

            state = ReflectorState.PROCESSING;

            writePipe(Char.ToString((char)PipeFlowControl.Quit));

            reflectorPipe.Close();
            //Console.WriteLine( "Pipe closed." );

            reflector.WaitForExit();
            reflector.Close();

            reflector.Dispose();
            resetReflector();

            state = ReflectorState.DEPLOYED;
            //Console.WriteLine( "Reflector stopped." );
        }
Exemplo n.º 7
0
        internal string generatePassword(string saveFile)
        {
            if (state != ReflectorState.STARTED)
            {
                throw new InvalidOperationException("Reflector is not awaiting processing.");
            }

            string checkFile = TAB.getCheckFile(saveFile);

            if (!File.Exists(checkFile))
            {
                // Generate checksum file first?
                throw new InvalidOperationException("Check file not found: " + checkFile);
            }

            state = ReflectorState.PROCESSING;

            writePipe(Char.ToString((char)PipeFlowControl.GeneratePassword));
            writePipe(saveFile);
            string password = readPipe();

            state = ReflectorState.STARTED;
            return(password);
        }