Ejemplo n.º 1
0
        public WebHookEngine(RoomieEngine roomieController, string computerName, string communicationUrl, string accessKey, string encryptionKey)
        {
            this.roomieController = roomieController;
            this.computerName = computerName;
            this.communicationUrl = communicationUrl;
            this.accessKey = accessKey;
            this.encryptionKey = encryptionKey;

            //TODO: reintroduce multiple webhook engines?
            string threadPoolName = "Web Hook (to " + communicationUrl + ")";
            //int engineCount = Common.GetWebHookEngines(this.roomieController).Count;
            //if (engineCount > 0)
            //    threadPoolName += "(" + engineCount + ")";

            this.threadPool = roomieController.CreateThreadPool(threadPoolName);

            this.running = false;
            communicator = new WebCommunicator.CommunicatorClient(communicationUrl, accessKey, encryptionKey);

            bool serverFound = false;

            while (!serverFound)
            {
                try
                {
                    print("pinging Webhook server at " + communicationUrl + "...");
                    Message pingResponse = communicator.PingServer();
                    //TODO: should we look at the result?
                    print("Webhook server found!");
                    serverFound = true;

                }
                catch (CommunicationException exception)
                {
                    print("Error contacting server: " + exception.Message);
                    System.Threading.Thread.Sleep(new TimeSpan(0, 0, 10));
                }
            }
            ////initialize connection
            //Dictionary<string, string> sendValues = new Dictionary<string, string>(1);
            //sendValues.Add("action", "start session");
            //sendValues.Add("ComputerName", computerName);
            //SecureHttpCommunication.RecievedPackage package = SendMessage(sendValues, null);
            //if (package.HasErrorMessage)
            //    throw new ScriptException("Error starting webhook session");
            //foreach (SecureHttpCommunication.Message message in package)
            //{
            //    if (message.ContainsParameter("NewSessionToken"))
            //        sessionToken = message.GetValue("NewSessionToken");
            //    break;
            //}
            //if (String.IsNullOrEmpty(sessionToken))
            //    throw new ScriptException("Did not recieve a new SessionID");

            //print("Webhook Session Token: " + sessionToken);

            events = new Queue<OutputEvent>();
            //TODO: make this work!
            //this.roomieController.ScriptMessageSent += new Scope scopeScriptMessageEventHandler(roomieController_ScriptMessageSent);
        }
Ejemplo n.º 2
0
 public RoomieThread(RoomieEngine engine, string name, HierarchicalVariableScope parentScope)
 {
     Engine       = engine;
     Id           = Guid.NewGuid().ToString();
     Name         = name;
     _interpreter = new RoomieCommandInterpreter(this, parentScope ?? Engine.GlobalScope);
     _workQueue   = new ParallelWorkQueue();
 }
Ejemplo n.º 3
0
 public HomeAutomationNetworkContext(RoomieEngine engine, ThreadPool threadPool, IDeviceHistory deviceHistory, INetworkHistory networkHistory)
 {
     _engine = engine;
     ThreadPool = threadPool;
     //TODO: ninject?
     History = new MasterHistory(deviceHistory, networkHistory);
     Triggers = new TriggerCollection();
 }
Ejemplo n.º 4
0
 public RoomieThread(RoomieEngine engine, string name, HierarchicalVariableScope parentScope)
 {
     Engine = engine;
     Id = Guid.NewGuid().ToString();
     Name = name;
     _interpreter = new RoomieCommandInterpreter(this, parentScope ?? Engine.GlobalScope);
     _workQueue = new ParallelWorkQueue();
 }
Ejemplo n.º 5
0
        public RoomieEventTextStream(RoomieEngine engine, TextWriter output, TimeSpan timeStampInterval)
        {
            this.output            = output;
            this.timeStampInterval = timeStampInterval;

            _lastTimestamp = DateTime.MinValue;
            _lastThread    = null;

            engine.ScriptMessageSent += new RoomieThreadEventHandler(engine_ScriptMessageSent);
        }
Ejemplo n.º 6
0
        public RoomieEventTextStream(RoomieEngine engine, TextWriter output,  TimeSpan timeStampInterval)
        {
            this.output = output;
            this.timeStampInterval = timeStampInterval;

            _lastTimestamp = DateTime.MinValue;
            _lastThread = null;

            engine.ScriptMessageSent += new RoomieThreadEventHandler(engine_ScriptMessageSent);
        }
Ejemplo n.º 7
0
        public MainWindow()
        {
            InitializeComponent();
            _engine = new RoomieEngine();
            Events = new ObservableCollection<RoomieEvent>();
            _engine.ScriptMessageSent += engine_ScriptMessageSent;
            _engine.EngineStateChanged += _engine_EngineStateChanged;
            EventListing.ItemsSource = Events;

            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var engine = new RoomieEngine();
            setOutput(engine);
            //engine.TerminalMessageSent += new TerminalOutputEventHandler(controller_TerminalMessageSent);
            engine.Start();

            var line = "";
            var input = "";
            var xmlInput = new XmlDocument();
            //TODO: improve this.  Make the while loop directly depend on the engine's internal state.
            while (!input.Contains("Core.ShutDown"))
            {
                //TODO: pull reading from a text stream into Roomie.Desktop.Engine.RoomieEngine
                line = Console.ReadLine().Trim();
                if (!String.IsNullOrEmpty(line))
                {
                    if (input.Length > 0)
                    {
                        input += "\n";
                    }
                    input += line.TrimEnd('_');
                    //TODO: read multiple lines
                    if (!line.EndsWith("_"))
                    {
                        try
                        {
                            var script = ScriptCommandList.FromText(input);
                            engine.Threads.AddCommands(script);
                            Console.WriteLine("Command accepted.");
                            input = "";
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine("Error. " + exception.Message);
                        }
                    }

                }
                else
                {
                    if (input != "")
                    {
                        input = "";
                        Console.WriteLine("Input cleared.");
                    }

                }
            }
        }
Ejemplo n.º 9
0
 public EngineStartup(RoomieEngine engine)
 {
     _engine = engine;
     _threadpool = engine.CreateThreadPool("Startup Threads");
 }
Ejemplo n.º 10
0
 internal ThreadPool(RoomieEngine engine, string name)
 {
     _engine  = engine;
     _name    = name;
     _threads = new List <RoomieThread>();
 }
Ejemplo n.º 11
0
 protected override void OnStart(string[] args)
 {
     engine = new RoomieEngine();
     engine.Start();
 }
Ejemplo n.º 12
0
 public EngineShutdown(RoomieEngine engine)
 {
     _engine = engine;
     _threadpool = _engine.CreateThreadPool("Shutdown Tasks");
 }
Ejemplo n.º 13
0
 static void setOutput(RoomieEngine engine)
 {
     var streamWriter = new RoomieEventTextStream(engine, Console.Out, new TimeSpan(hours: 0, minutes: 0, seconds: 30));
 }
Ejemplo n.º 14
0
 public HomeAutomationNetworkContext(RoomieEngine engine, ThreadPool threadPool)
     : this(engine, threadPool, new DeviceHistory(), new NetworkHistory())
 {
 }
Ejemplo n.º 15
0
 public SpeechResponder(RoomieEngine engine)
 {
     RegisteredCommands = new Dictionary<string, ScriptCommandList>();
     _speechRecognizer = new NamedSpeechRecognizer(TimeSpan.FromSeconds(10), "Roomie");
     ThreadPool = engine.CreateThreadPool("Speech Recognizer");
 }
Ejemplo n.º 16
0
 public EngineShutdown(RoomieEngine engine)
 {
     _engine     = engine;
     _threadpool = _engine.CreateThreadPool("Shutdown Tasks");
 }
Ejemplo n.º 17
0
 public EngineStartup(RoomieEngine engine)
 {
     _engine     = engine;
     _threadpool = engine.CreateThreadPool("Startup Threads");
 }