Exemple #1
0
        public void ProcessMessageTest()
        {
            var clientCert = ThaliClientToDeviceHubUtilities.GetLocalClientCertificate(tempDirectory);

            // Provision client to local Thali Hub
            var provisionXmlHttpRequest = GenerateXmlHttprequestForClientProvisioning();
            var xmlHttpResponse         =
                (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(provisionXmlHttpRequest, clientCert);

            Assert.AreEqual(xmlHttpResponse.status, 200);
            var hubUrl = xmlHttpResponse.responseText;

            // Provision local hub to 'remote' hub
            var localToRemoteHubXmlHttpRequest = this.GenerateXmlHttpRequestForLocalToRemoteHubProvisioning(hubUrl);

            xmlHttpResponse =
                (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(localToRemoteHubXmlHttpRequest, clientCert);
            Assert.AreEqual(200, xmlHttpResponse.status);
            Assert.AreEqual(hubUrl, xmlHttpResponse.responseText);

            var xmlHttpRequest = GenerateXmlHttpRequestForNonExistentDatabase(hubUrl);

            xmlHttpResponse = (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(xmlHttpRequest, clientCert);
            Assert.AreEqual(xmlHttpResponse.status, 404);
        }
Exemple #2
0
        public void Setup()
        {
            var tempDirectoryForSetupPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            tempDirectoryForSetup = Directory.CreateDirectory(tempDirectoryForSetupPath);
            var clientCert      = ThaliClientToDeviceHubUtilities.GetLocalClientCertificate(tempDirectoryForSetup);
            var serverPublicKey = ThaliClientToDeviceHubUtilities.GetServersRootPublicKey(Host, Port, clientCert);

            ThaliClientToDeviceHubUtilities.ProvisionThaliClient(serverPublicKey, Host, Port, clientCert);
            var couchClient = ThaliClientToDeviceHubUtilities.GetCouchClient(serverPublicKey, Host, Port, clientCert);

            var response = couchClient.DeleteDatabase(TestDatabaseName);

            var tempDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            tempDirectory = Directory.CreateDirectory(tempDirectoryPath);
        }
Exemple #3
0
        public static void bar()
        {
            var tempDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            var tempDirectory     = Directory.CreateDirectory(tempDirectoryPath);

            var clientCert = ThaliClientToDeviceHubUtilities.GetLocalClientCertificate(tempDirectory);

            var testGetJsonString = GenerateXmlHttpRequestJsonObjectForNonExistentDatabase();

            var xmlHttpRequest  = JsonConvert.DeserializeObject <XmlHttpRequest>(testGetJsonString);
            var xmlHttpResponse = (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(xmlHttpRequest, clientCert);

            //Assert.AreEqual(xmlHttpResponse.status, 404);


            xmlHttpResponse = (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(xmlHttpRequest, clientCert);
            xmlHttpResponse = (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(xmlHttpRequest, clientCert);
            xmlHttpResponse = (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(xmlHttpRequest, clientCert);
            xmlHttpResponse = (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(xmlHttpRequest, clientCert);
            xmlHttpResponse = (XmlHttpResponse)XmlHttpRequestProxy.ProcessMessage(xmlHttpRequest, clientCert);
        }
        public static void MainLoop(bool synchronous)
        {
            Stream outStream = null;

            // TODO: If one of the console methods throws an exception then will it be caught by the outer catch? And if
            // there is an exception inside the inner try then don't I have to assume that the using will close the streams
            // before the outter catch can send a message? I'm not sure about the answers and don't have time to explore
            // at the moment so I'm using a double wrapping of try's to take care of it.
            try
            {
                using (var inStream = Console.OpenStandardInput())
                using (outStream = Console.OpenStandardOutput())
                {
                    try
                    {
                        ServicePointManager.DefaultConnectionLimit = 100;

                        var appdataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                        var homeDirectory = string.Concat(appdataDirectory, @"\Google\Chrome\User Data\Thali");
                        if (!Directory.Exists(homeDirectory))
                        {
                            Directory.CreateDirectory(homeDirectory);
                        }

                        DirectoryInfo workingDirectory = new DirectoryInfo(homeDirectory);
                        
                        var clientCert = ThaliClientToDeviceHubUtilities.GetLocalClientCertificate(workingDirectory);
                        if (synchronous)
                        {
                            ChromeNativeHostUtilities.SynchronousRequestResponseMessageEngine<XmlHttpRequest>(
                                inStream,
                                outStream,
                                inMessage => ProcessMessage(inMessage, clientCert),
                                ProcessHostError);
                        }
                        else
                        {
                            ChromeNativeHostUtilities.AsynchronousRequestResponseMessageEngine<XmlHttpRequest>(
                                inStream,
                                outStream,
                                inMessage => ProcessMessage(inMessage, clientCert),
                                ProcessHostError);
                        }
                    }
                    catch (Exception e)
                    {
                        if (outStream != null)
                        {
                            ChromeNativeHostUtilities.ParallelSendMessage(ProcessHostError("oops! " + e.Message, null), outStream);
                        }                        
                    }
                }
            }
            catch (Exception e)
            {
                if (outStream != null)
                {
                    ChromeNativeHostUtilities.SendMessage(ProcessHostError("oops! " + e.Message, null), outStream);   
                }
            }
        }