Ejemplo n.º 1
0
        private bool ProcessRequest(HttpListenerContext context, string root,
                                    Dictionary <string, Func <dynamic, dynamic> > method, dynamic param)
        {
            var full = GetFullUrl(context);

            foreach (var m in method)
            {
                //get the complete service url
                var service = RemoveEndingSlash(root + m.Key);

                //parameters from the query string, will be loaded from the matches method
                Dictionary <string, object> paramList;

                //check if the service url matches the full url of the request
                if (!Matches(service, full, out paramList))
                {
                    continue;
                }

                //merge the post or get objects with the parameter list
                var data = WebServerHelper.Merge(param, paramList);

                //execute the specific method
                var result = m.Value(data);

                //convert the result to json and set the response
                var json = JsonConvert.SerializeObject(new ApiResponse(result));
                context.SetResponse(json);
                context.Response.ContentType = "application/json";
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        private bool ProcessGet(HttpListenerContext context, string root, BaseController controller)
        {
            //pass in the query string data
            var get = WebServerHelper.GetQueryString(context);

            return(ProcessRequest(context, root, controller.Get, get));
        }
 public void SetupTestSuite()
 {
     Debug.WriteLine("Setting up Test Assembly Fixture");
     // Kill all web server instances and then restart them
     WebServerHelper.StopAll();
     WebServerHelper.StartAll();
     DatabaseHelper.RestoreDefaultDatabases();
 }
Ejemplo n.º 4
0
        public override bool Process(HttpListenerContext context)
        {
            try
            {
                //get the file name instead of the url


                var file = context.GetUrl().AbsolutePath.Substring(1);

                if (file.IsNullOrEmpty())
                {
                    file = "index.html";
                }

                if (!Path.HasExtension(file))
                {
                    return(false);
                }

                string result = "";

                var controller = GetController <WebController>(file);

                if (controller != null)
                {
                    controller.CheckAuth(context);
                }

                var data = File.ReadAllText(file);

                //when a controller and model is found, use the view engine to render the html
                if (controller != null && controller.Get.Count > 0)
                {
                    foreach (var get in controller.Get)
                    {
                        var parameters = WebServerHelper.GetQueryString(context);
                        result = ViewEngine.Instance.Render(data, get.Value(parameters));
                        break;
                    }
                }
                //otherwise just return the data that was found
                else
                {
                    result = data;
                }

                context.SetResponse(new Controller.WebResponse(result).ToString());
            }
            catch (Exception ex)
            {
                context.Response.StatusCode = 500;
                context.SetResponse(new Controller.WebResponse(ex).ToString());
            }

            return(true);
        }
Ejemplo n.º 5
0
        public async Task SelectorTest()
        {
            var testCases = new List <TestCase>
            {
                new TestCase(
                    p => p.AddJQueryDomSelector(),
                    "#outer:first",
                    ".inner:first"),
                new TestCase(
                    p => p.AddCssDomSelector(),
                    "#outer",
                    ".inner")
            };

            using (var server = WebServerHelper.CreateWebServer())
            {
                foreach (var testCase in testCases)
                {
                    var serviceCollection = new ServiceCollection();
                    testCase.SelectorConfiguration(serviceCollection);

                    serviceCollection.AddPuppeteerWebAutomationFrameworkInstance(AutomationEngineFactory.GetPuppeteerDriverAsync);

                    var serviceProvider = serviceCollection.BuildServiceProvider();
                    using (var automationEngine = serviceProvider.GetRequiredService <IWebAutomationEngine>())
                    {
                        await automationEngine.InitializeAsync();

                        await automationEngine.OpenTest(server, "selector/index.html");

                        var outerElements = await automationEngine.Find(testCase.OuterElementSelector);

                        Assert.IsNotNull(outerElements);

                        var outerElement = outerElements.SingleOrDefault();
                        Assert.IsNotNull(outerElement);
                        Assert.AreEqual("hello world", outerElement.TextContent);

                        var innerElements = await automationEngine.Find(testCase.InnerElementSelector);

                        Assert.IsNotNull(innerElements);

                        var innerElement = innerElements.SingleOrDefault();
                        Assert.IsNotNull(innerElement);
                        Assert.AreEqual("world", innerElement.TextContent?.Trim());
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected T GetController <T>(string url) where T : IController
        {
            var cache = Cache.FirstOrDefault(i => i != null && i.Path == url);

            if (cache != null)
            {
                return((T)cache);
            }

            var ctrl = WebServerHelper.FindController <T>(url);

            if (ctrl != null)
            {
                Cache.Add(ctrl);
            }

            return(ctrl);
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting APP");

            #region DI Container Builder
            var builder = new ContainerBuilder();

            builder.RegisterType <RedisHelper>().As <ICacheHelper>();
            builder.RegisterType <ApplicationConfig>().As <IApplicationConfig>();
            builder.RegisterType <RabbitMQHelper>().As <IMessageQueueHelper>();
            builder.RegisterType <FileDataModel>().As <IFileDataModel>();
            builder.RegisterType <Log4NetHelper>().As <ILogger>();
            builder.RegisterType <AzureBlobStorageHelper>().As <IFileUploadHelper>();
            builder.RegisterType <FileUploadHub>().As <IFileUploadHub>();

            var container = builder.Build();
            #endregion

            using (var scope = container.BeginLifetimeScope())
            {
                #region DI Resolver
                _logger             = scope.Resolve <ILogger>();
                _cacheHelper        = scope.Resolve <ICacheHelper>();
                _messageQueueHelper = scope.Resolve <IMessageQueueHelper>();
                _applicationConfig  = scope.Resolve <IApplicationConfig>();
                _fileDataModel      = scope.Resolve <IFileDataModel>();
                _fileUploadHelper   = scope.Resolve <IFileUploadHelper>();
                _fileUploadHub      = scope.Resolve <IFileUploadHub>();
                #endregion

                var fileProcessor   = new FileProcessor(_fileDataModel, _fileUploadHelper, _applicationConfig, _fileUploadHub);
                var webserverHelper = new WebServerHelper(_applicationConfig);

                #region Processors
                Task.Run(() => _messageQueueHelper.ReadMessages <QueueFileMetaDataModel>(_applicationConfig, fileProcessor.FilePushed, _applicationConfig.FileDataCreateQueue));
                Task.Run(() => _messageQueueHelper.ReadMessages <QueueFileMetaDataModel>(_applicationConfig, fileProcessor.FileDelete, _applicationConfig.FileMetaDeleteQueue));
                Task.Run(() => _messageQueueHelper.ReadMessages <QueueFileMetaDataModel>(_applicationConfig, fileProcessor.FileOpened, _applicationConfig.FileOpenedQueue));
                #endregion

                Task.Run(() => webserverHelper.StartWebServer());
            }

            Console.ReadLine();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            #region DI Container Builder
            var builder = new ContainerBuilder();

            builder.RegisterType <RedisHelper>().As <ICacheHelper>();
            builder.RegisterType <ApplicationConfig>().As <IApplicationConfig>();
            builder.RegisterType <RabbitMQHelper>().As <IMessageQueueHelper>();
            builder.RegisterType <QueueDataModel>().As <IQueueDataModel>();
            builder.RegisterType <AgentDataModel>().As <IAgentDataModel>();
            builder.RegisterType <ChatHub>().As <IChatHub>();

            builder.RegisterType <QueueDataModel>().As <IQueueDataModel>().SingleInstance();
            var container = builder.Build();
            #endregion

            using (var scope = container.BeginLifetimeScope())
            {
                #region DI Resolver
                _cacheHelper        = scope.Resolve <ICacheHelper>();
                _messageQueueHelper = scope.Resolve <IMessageQueueHelper>();
                _applicationConfig  = scope.Resolve <IApplicationConfig>();
                _queueDataModel     = scope.Resolve <IQueueDataModel>();
                _agentDataModel     = scope.Resolve <IAgentDataModel>();
                _chatHub            = scope.Resolve <IChatHub>();

                var chatMonitorHelper = new ChatMonitorHelper(_queueDataModel, _agentDataModel, _chatHub);
                var webserverHelper   = new WebServerHelper(_applicationConfig);
                #endregion

                #region Processors
                //Start Message Queue Listener
                Task.Run(() => _messageQueueHelper.ReadMessages <QueueMetaData>(_applicationConfig, chatMonitorHelper.ProcessQueue));
                //Start Message Queue Processor
                Task.Run(() => chatMonitorHelper.MonitorQueue());
                //Start WebSocket Server
                Task.Run(() => webserverHelper.StartWebServer());
                #endregion
            }

            Console.ReadLine();
        }
Ejemplo n.º 9
0
        private void downloadForms()
        {
            bw = new BackgroundWorker();

            progress.Show();
            bw.DoWork += delegate
            {
                try
                {
                    WebServerHelper.WebServiceResponse resp = JsonConvert.DeserializeObject <WebServerHelper.WebServiceResponse>(WebServerHelper.WebCall("https://macarthur.goget.co.nz:9725/apps/?formlist=1"));
                    forms = resp.data.Split('|').ToList();
                    forms = forms.Select(s => Path.GetFileName(s)).ToList();

                    RunOnUiThread(() =>
                    {
                        lv         = FindViewById <ListView>(Resource.Id.mainMenu);
                        fla        = new FormListAdapter(forms, this);
                        lv.Adapter = fla;

                        lv.ItemClick += Lv_ItemClick;
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            };

            bw.RunWorkerCompleted += delegate
            {
                progress.Dismiss();
            };

            bw.RunWorkerAsync();
        }
Ejemplo n.º 10
0
 public void TearDownTestSuite()
 {
     Debug.WriteLine("Tearing down Assembly Fixture");
     WebServerHelper.StopAll();
 }
Ejemplo n.º 11
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //this disables orientation changes while form loads, effectively ignoring the sensors
            RequestedOrientation = Android.Content.PM.ScreenOrientation.Locked;

            SetContentView(Resource.Layout.Form2);
            inflater = LayoutInflater.From(this);

            MainFormLayout = FindViewById <LinearLayout>(Resource.Id.mainFormView);
            MainScrollView = FindViewById <ScrollView>(Resource.Id.mainScrollView);

            progress = new ProgressDialog(this);
            progress.SetCanceledOnTouchOutside(false);
            progress.SetCancelable(false);
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            progress.SetProgressNumberFormat(null);
            progress.SetProgressPercentFormat(null);
            progress.Indeterminate = true;


            //grab the form name from previous
            string item = Intent.GetStringExtra("form_name");

            //if we came from a page button, these values will have something in them
            int  groupId = Intent.GetIntExtra("groupId", -1);
            bool newForm = Intent.GetBooleanExtra("newForm", true);



            //get the form from the WS
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                if (newForm)
                {
                    RunOnUiThread(() =>
                    {
                        progress.SetMessage("Disposing tables...");
                        progress.Show();
                    });

                    if (XForm.instance == null)
                    {
                        DLL.DisposeTables();
                    }



                    RunOnUiThread(() => { progress.SetMessage("Downloading form..."); });

                    WebServerHelper.WebServiceResponse response =
                        JsonConvert.DeserializeObject <WebServerHelper.WebServiceResponse>(WebServerHelper.WebCall("https://macarthur.goget.co.nz:9725/apps/?getform=1", item));

                    string xform = response.data;

                    //puts it into the sqlite db
                    try
                    {
                        RunOnUiThread(() => { progress.SetMessage("Parsing form..."); });
                        Parser.Parse(xform, "Test Form");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }

                    form = DLL.GetForm(1);

                    isAssetForm = item.ToLower().Contains("asset") ? true : false;
                    if (XForm.instance == null)
                    {
                        XForm.instance = new Instance()
                        {
                            formid   = form.id,
                            instance = XForm.LoadInstance(form.instancexml),
                        };
                        DLL.InsertRow(XForm.instance);
                    }
                }


                try
                {
                    RunOnUiThread(() => { progress.SetMessage("Loading controls..."); });
                    //if we have a group id passed, this is a sub page
                    OrderLayouts = new List <LinearLayout>();

                    WidgetHelper.activity = this;
                    if (newForm)
                    {
                        XForm.LoadForm(null, this);
                    }
                    else
                    {
                        RunOnUiThread(() => {
                            progress.SetMessage($"Loading {item}...");
                            progress.Show();
                        });
                        XForm.LoadForm(groupId, this);
                        RunOnUiThread(() => { progress.Dismiss(); });
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    progress.Dismiss();

                    AlertDialog alert = new AlertDialog.Builder(this).Create();
                    alert.SetTitle("Error");
                    alert.SetMessage($"An error occured while loading the form. If the issue persists, check your form is valid XML. \n\nError:\n {ex.ToString()}");
                    alert.SetButton("OK", delegate { Finish(); });
                }
            };


            bw.RunWorkerCompleted += delegate { RunOnUiThread(() => {
                    PageLoaded = true;
                    //this reenables the app listening to orientation sensors
                    RequestedOrientation = Android.Content.PM.ScreenOrientation.Sensor;

                    foreach (LinearLayout ol in OrderLayouts)
                    {
                        TextView label = ol.FindViewById <TextView>(Resource.Id.textLabel);
                        EditText edit  = ol.FindViewById <EditText>(Resource.Id.textEdit);

                        ol.Measure(0, 0);
                        int spec = MeasureSpec.MakeMeasureSpec(ol.MeasuredWidth, MeasureSpecMode.AtMost);

                        label.Measure(spec, spec);
                        edit.Measure(spec, spec);

                        Console.WriteLine(label.Text);

                        // if (label.MeasuredWidth > edit.MeasuredWidth)
                        //  ol.Orientation = Orientation.Vertical;
                    }

                    FireFormChangeEvent(null);
                    progress.Dismiss();
                }); };

            bw.RunWorkerAsync();

            MainFormLayout.ChildViewAdded += delegate
            {
                RunOnUiThread(() => {
                    progress.SecondaryProgress += 1;
                    progress.Progress++;
                });
            };
        }
Ejemplo n.º 12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            progress = new ProgressDialog(this);
            progress.SetMessage("Loading...");
            progress.SetCanceledOnTouchOutside(false);
            progress.SetCancelable(false);
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            progress.SetProgressNumberFormat(null);
            progress.SetProgressPercentFormat(null);
            progress.Indeterminate = true;

            SetContentView(Resource.Layout.Form);
            listView = FindViewById <ListView>(Resource.Id.controlList);



            //get the form from the WS
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                DLL.DisposeTables();

                RunOnUiThread(() =>
                {
                    progress.Show();
                });

                WebServerHelper.WebServiceResponse response =
                    JsonConvert.DeserializeObject <WebServerHelper.WebServiceResponse>(WebServerHelper.WebCall("https://macarthur.goget.co.nz:9725/apps/?getform=1"));

                string xform = response.data;

                //puts it into the sqlite db
                try
                {
                    Parser.Parse(xform, "Test Form");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Forms form = DLL.GetForm(1);
                //this is where we put our filled out values back into
                instance = XForm.LoadInstance(form.instancexml);

                //the controls we put onto the UI
                FormControls = DLL.GetControls(1);

                foreach (Controls c in FormControls)
                {
                    Console.WriteLine(c.type);
                }

                RunOnUiThread(() => {
                    Title            = "Test Form";
                    listView.Adapter = new FormAdapter(FormControls, this);
                });
            };


            //setup ui now we are done
            bw.RunWorkerCompleted += delegate {
                RunOnUiThread(() => {
                    //trigger any show/hide stuff :D
                    FireFormChangeEvent(null);
                    progress.Dismiss();
                });
            };


            bw.RunWorkerAsync();
        }