Beispiel #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            this.RegisterManagers();
            this.SetContentView(Resource.Layout.Main);
            this.UiMetadataWebApi = new UiMetadataWebApi
            {
                FormMetadataUrl = "http://10.0.2.2:58337/api/form/metadata",
                MetadataUrl     = "http://10.0.2.2:58337/api/form/metadata",
                RunFormUrl      = "http://10.0.2.2:58337/api/form/run"
            };
            // this.FormWrapper = new CustomFormWrapper(this, this.AppLayouts, Resource.Id.main_content_frame);
            this.MyFormHandler = new MyFormHandler(this.UiMetadataWebApi, new ManagersCollection(),
                                                   this.FormWrapper);
            var appPreference = new AppSharedPreference(Application.Context);

            if (string.IsNullOrEmpty(appPreference.GetSharedKey("Cookies")))
            {
                var metadata = this.MyFormHandler.GetFormMetadata("login");
                this.FormWrapper.UpdateView(this.MyFormHandler, new FormParameter(metadata));
            }
            else
            {
                var i = new Intent(this, typeof(FormsActivity));
                this.StartActivity(i);
            }
        }
Beispiel #2
0
        public void GetAllFormsMetadata()
        {
            this.AllForms = new Dictionary <string, FormMetadata>();
            var appPreference = new AppSharedPreference(Application.Context);

            this.MenuItems = new List <MenuItem>();
            this.MyFormHandler.AllFormsMetadata = new Dictionary <string, FormMetadata>();

            try
            {
                var result = Task.Run(
                    () => UiMetadataHttpRequestHelper.GetAllFormsMetadata(this.UiMetadataWebApi.MetadataUrl,
                                                                          appPreference.GetSharedKey("Cookies")));
                var metadata     = JsonConvert.DeserializeObject <MyForms>(result.Result);
                var orderedMenu  = metadata.Menus.OrderBy(a => a.OrderIndex);
                var orderedForms = metadata.Forms
                                   .OrderBy(a => a.CustomProperties != null ? a.CustomProperties?.GetCustomProperty <long>("menuOrderIndex") : 0)
                                   .ToList();
                foreach (var menuItem in orderedMenu)
                {
                    var existingForms = false;
                    foreach (var form in orderedForms)
                    {
                        if (form.CustomProperties != null && this.MenuItems.All(a => a.FormMetadata != form))
                        {
                            var menuName = form.CustomProperties.GetCustomProperty <string>("menu");
                            if (!string.IsNullOrEmpty(menuItem.Name))
                            {
                                if (menuName != null && (menuName.Equals(menuItem.Name) || menuName == ""))
                                {
                                    if (!existingForms && menuName != "")
                                    {
                                        this.MenuItems.Add(new MenuItem(menuItem.Name));
                                    }
                                    existingForms = true;
                                    this.MenuItems.Add(new MenuItem("\t" + form.Label, form));
                                }
                            }
                        }
                        if (!this.AllForms.ContainsKey(form.Id))
                        {
                            this.AllForms.Add(form.Id, form);
                        }

                        if (!this.MyFormHandler.AllFormsMetadata.ContainsKey(form.Id))
                        {
                            this.MyFormHandler.AllFormsMetadata.Add(form.Id, form);
                        }
                    }
                }
            }
            catch (System.Exception)
            {
                this.RunOnUiThread(() => { Toast.MakeText(Application.Context, "Server is not available in this moment", ToastLength.Long).Show(); });
            }
        }