예제 #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);
        }
예제 #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();
 }
예제 #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();
 }
예제 #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();
 }
예제 #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);
        }
예제 #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);
        }
예제 #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;
        }
예제 #8
0
파일: Program.cs 프로젝트: Mavtak/roomie
        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.");
                    }

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