Example #1
0
        /// <summary>
        /// Main call
        /// </summary>
        /// <param name="args">Additional method call parameters</param>
        static void Main(string[] args)
        {
            TestBedAdapter.GetInstance().AddLogCallback(Adapter_Log);
            TestBedAdapter.GetInstance().Log(Level.Debug, "adapter started, listening to input...");

            // Test the large file system access
            //TestLargeFileService();

            Console.WriteLine($"Please type in any text to be send over topic '{CustomTopicName}'; q to exit");
            string text;

            // Whenever a new text has been entered by the user, create a new test message, or quit the application if the text is 'q'
            while ((text = Console.ReadLine()) != "q")
            {
                Test newMsg = new Test()
                {
                    sender  = SenderName,
                    message = text,
                };

                try
                {
                    // Send the message over our custom topic
                    TestBedAdapter.GetInstance().SendMessage <Test>(newMsg, CustomTopicName);
                    Console.WriteLine(TestBedAdapter.GetInstance().GetTimeInfo());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Method for testing the large file service upload functionality
        /// </summary>
        private static async void TestLargeFileService()
        {
            string filePath = @".\test.jpg";

            if (System.IO.File.Exists(filePath))
            {
                // Retrieve the large file service client for a manual upload
                System.Net.Http.HttpClient client = TestBedAdapter.GetInstance().GetLargeFileServiceClient();

                // Create and enter the POST parameters
                MultipartFormDataContent content = new MultipartFormDataContent();
                // the file to upload
                StreamContent file = new StreamContent(System.IO.File.OpenRead(filePath));
                file.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
                {
                    Name     = "uploadFile",
                    FileName = System.IO.Path.GetFileName(filePath),
                };
                content.Add(file);
                // the indication if this upload needs to be obfuscated or not
                content.Add(new StringContent("false"), "private");

                // Send the POST
                HttpResponseMessage response = await client.PostAsync("/upload", content);

                // Check for the response of the large file service
                if (response.IsSuccessStatusCode)
                {
                    string resContent = await response.Content.ReadAsStringAsync();

                    if (!string.IsNullOrEmpty(resContent))
                    {
                        Console.WriteLine("Large File Service response: " + resContent);
                    }
                    else
                    {
                        Console.WriteLine("Large File Service response: Service up but no response");
                    }
                }
                else
                {
                    Console.WriteLine("Large File Service response: Service down or bad request");
                }

                //// Or do this all automatically via the adapter
                //HttpResponseMessage response = await TestBedAdapter.GetInstance().Upload(filePath, eu.driver.model.core.DataType.image_jpeg, true, true);
            }
        }
Example #3
0
 /// <summary>
 /// Main call
 /// </summary>
 /// <param name="args">Additional method call parameters</param>
 static void Main(string[] args)
 {
     try
     {
         TestBedAdapter.GetInstance().AddLogCallback(Adapter_Log);
         TestBedAdapter.GetInstance().AddTimingControlCallback(Adapter_TimingControl);
         TestBedAdapter.GetInstance().AddCallback <Test>(Adapter_TestMessage, CustomTopicName);
         TestBedAdapter.GetInstance().AddCallback <Alert>(Adapter_AlertMessage, Configuration.StandardTopics[typeof(Alert)]);
         TestBedAdapter.GetInstance().Log(Level.Debug, "adapter started, listening to messages...");
         while (true)
         {
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
Example #4
0
 /// <summary>
 /// Delegate being called once the adapter has a timing control to report
 /// </summary>
 private static void Adapter_TimingControl()
 {
     Console.WriteLine($"Received a Timing control message: {TestBedAdapter.GetInstance().GetTimeInfo()}");
 }
        /// <summary>
        /// Main call
        /// </summary>
        /// <param name="args">Additional method call parameters</param>
        static void Main(string[] args)
        {
            TestBedAdapter.GetInstance().AddLogCallback(Adapter_Log);
            TestBedAdapter.GetInstance().Log(Level.Debug, "adapter started, listening to input...");

            Console.WriteLine($"Please type in any text to be send over the standard CAP topic; q to exit");
            string text;

            // Whenever a new text has been entered by the user, create a new test message, or quit the application if the text is 'q'
            while ((text = Console.ReadLine()) != "q")
            {
                // Create a new Alert message, with the given text as info[0].@event
                Alert newMsg = new Alert
                {
                    identifier  = "test",
                    sender      = "CSharpExampleProducerStandard",
                    sent        = DateTime.UtcNow.ToString("o"),
                    status      = Status.Test,
                    msgType     = MsgType.Alert,
                    source      = "null",
                    scope       = Scope.Public,
                    restriction = "null",
                    addresses   = "null",
                    code        = new string[] { "a", "b", "c" },
                    note        = "null",
                    references  = "null",
                    incidents   = "null",
                    info        = new Info[]
                    {
                        new Info {
                            language     = "en-US",
                            category     = new Category[] { Category.Env, Category.Transport },
                            @event       = text,
                            responseType = new ResponseType[] { ResponseType.Assess, ResponseType.Execute },
                            urgency      = Urgency.Unknown,
                            severity     = Severity.Minor,
                            certainty    = Certainty.Likely,
                            audience     = "null",
                            eventCode    = new ValueNamePair[]
                            {
                                new ValueNamePair {
                                    valueName = "test", value = "OK"
                                },
                            },
                            effective   = "null",
                            onset       = "null",
                            expires     = "null",
                            senderName  = "null",
                            headline    = "null",
                            description = "null",
                            instruction = "null",
                            web         = "null",
                            contact     = "null",
                            parameter   = new ValueNamePair[]
                            {
                                new ValueNamePair {
                                    valueName = "test2", value = "OK2"
                                },
                            },
                            resource = new Resource[]
                            {
                                new Resource
                                {
                                    resourceDesc = "testResource",
                                    //size = null,
                                    uri      = "null",
                                    deferUri = "null",
                                    digest   = "null",
                                    mimeType = "null",
                                },
                            },
                            area = new Area
                            {
                                areaDesc = "testArea",
                                polygon  = "null",
                                circle   = "null",
                                geocode  = null,
                                //altitude = null,
                                //ceiling = null,
                            },
                        },
                    },
                };

                try
                {
                    // Send the message over the standard topic
                    TestBedAdapter.GetInstance().SendMessage <Alert>(newMsg);
                    Console.WriteLine(TestBedAdapter.GetInstance().GetTimeInfo());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }