Exemple #1
0
 protected void customizeController(MvcController controller, RunCommandsAction showCommand)
 {
     if (startupAction != null)
     {
         startupAction.setupAction(this, showCommand);
     }
 }
        public void GetPropertiesShouldNotThrowExceptionForNormalController()
        {
            MyMvc.IsUsingDefaultConfiguration();

            var helper = ControllerPropertyHelper.GetProperties<MvcController>();

            var controller = new MvcController();
            var controllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    RequestServices = TestServiceProvider.Global
                }
            };

            controller.ControllerContext = controllerContext;

            Assert.NotNull(controller.ControllerContext);
            Assert.Same(controllerContext, controller.ControllerContext);

            var gotControllerContext = helper.ControllerContextGetter(controller);

            Assert.NotNull(gotControllerContext);
            Assert.Same(gotControllerContext, controller.ControllerContext);

            Test.AssertException<InvalidOperationException>(
                () =>
                {
                    var gotActionContext = helper.ActionContextGetter(controller);
                },
                "ActionContext could not be found on the provided MvcController. The property should be specified manually by providing controller instance or using the specified helper methods.");
        }
Exemple #3
0
        public void GetPropertiesShouldNotThrowExceptionForNormalController()
        {
            MyMvc.IsUsingDefaultConfiguration();

            var helper = ControllerPropertyHelper.GetProperties <MvcController>();

            var controller        = new MvcController();
            var controllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    RequestServices = TestServiceProvider.Global
                }
            };

            controller.ControllerContext = controllerContext;

            Assert.NotNull(controller.ControllerContext);
            Assert.Same(controllerContext, controller.ControllerContext);

            var gotControllerContext = helper.ControllerContextGetter(controller);

            Assert.NotNull(gotControllerContext);
            Assert.Same(gotControllerContext, controller.ControllerContext);

            Test.AssertException <InvalidOperationException>(
                () =>
            {
                var gotActionContext = helper.ActionContextGetter(controller);
            },
                "ActionContext could not be found on the provided MvcController. The property should be specified manually by providing controller instance or using the specified helper methods.");
        }
        public override void addToController(Slide slide, MvcController controller, AnomalousMvcContext context)
        {
            RunCommandsAction action = new RunCommandsAction(name);

            setupAction(slide, action);
            controller.Actions.add(action);
        }
 public ControllerContext(
     MvcController controller,
     string outputPath,
     ExtractedTypeCollection types,
     FetchFunctionResolver fetchResolver
     )
     : this(new [] { controller }, outputPath, types, fetchResolver)
 {
 }
Exemple #6
0
        public void WithResponseModelShouldNotThrowExceptionWithCorrectPassedExpectedObject()
        {
            var controller = new MvcController();

            MyController <MvcController>
            .Instance(() => controller)
            .Calling(c => c.OkResultWithInterfaceResponse())
            .ShouldReturn()
            .Ok()
            .WithModel(controller.ResponseModel);
        }
        public void WithResponseModelShouldNotThrowExceptionWithDeeplyEqualPassedExpectedObject()
        {
            var controller = new MvcController();

            MyController <MvcController>
            .Instance()
            .Calling(c => c.OkResultWithResponse())
            .ShouldReturn()
            .Ok(ok => ok
                .WithModel(controller.ResponseModel));
        }
        public void ControllerWithProvidedInstanceShouldPopulateCorrectInstanceOfControllerType()
        {
            var instance = new MvcController();

            MyController<MvcController>
                .Instance(instance)
                .ShouldPassForThe<MvcController>(controller =>
                {
                    Assert.NotNull(controller);
                    Assert.IsAssignableFrom<MvcController>(controller);
                });
        }
        public void ControllerWithProvidedInstanceShouldPopulateCorrectInstanceOfControllerType()
        {
            var instance = new MvcController();

            MyController <MvcController>
            .Instance(instance)
            .ShouldPassForThe <MvcController>(controller =>
            {
                Assert.NotNull(controller);
                Assert.IsAssignableFrom <MvcController>(controller);
            });
        }
Exemple #10
0
        public override string TryResolve(string currentRoute, MvcController controller, MvcAction action)
        {
            var apiVersionAttr = controller.NamedType.Attributes.LastOrDefault(attr => attr.AttributeType.FullName == _attrTypeFullName);

            if (apiVersionAttr == null)
            {
                return(currentRoute);
            }

            // TODO: can override on action... but eh for now

            string version = apiVersionAttr.ConstructorArguments[0].ToString();

            return(s_apiVersionToken.Replace(currentRoute, version));
        }
Exemple #11
0
 // Add Controller-Permissions to database
 private void InitializeControllerPermissions(List <ControllerPermissions> controllerPermissions, ContextDb context)
 {
     foreach (var controllerPermission in controllerPermissions)
     {
         // If controller already exsits, update it with permissions
         if (context.MvcControllers.Any(c => c.Name == controllerPermission.ControllerName))
         {
             var mvcController = context.MvcControllers.Include(p => p.Permissions).Single(c => c.Name == controllerPermission.ControllerName);
             foreach (var permission in controllerPermission.Permissions)
             {
                 // Add if permission does not already exist for controller
                 if (mvcController.Permissions?.Any(p => p.Name == permission) != true)
                 {
                     var newPermission = new Permission {
                         Name = permission, MvcController = mvcController
                     };
                     context.Permissions.Add(newPermission);
                     mvcController.Permissions.Add(newPermission);
                 }
             }
             context.MvcControllers.Update(mvcController);
         }
         // Else create a new controller and permissions
         else
         {
             var mvcController = new MvcController
             {
                 Name        = controllerPermission.ControllerName,
                 Permissions = new Collection <Permission>(),
             };
             foreach (var permission in controllerPermission.Permissions)
             {
                 if (!mvcController.Permissions.Any(p => p.Name == permission))
                 {
                     var newPermission = new Permission {
                         Name = permission, MvcController = mvcController
                     };
                     context.Permissions.Add(newPermission);
                     mvcController.Permissions.Add(newPermission);
                 }
             }
             context.MvcControllers.Add(mvcController);
         }
     }
     context.SaveChanges();
 }
Exemple #12
0
        private static void createController(AnomalousMvcContext mvcContext, String name, bool backButton)
        {
            MvcController     controller = new MvcController(name);
            RunCommandsAction show       = new RunCommandsAction("Show");

            show.addCommand(new ShowViewCommand(name));
            if (backButton)
            {
                show.addCommand(new RecordBackAction());
            }
            controller.Actions.add(show);
            RunCommandsAction close = new RunCommandsAction("Close");

            close.addCommand(new CloseViewCommand());
            controller.Actions.add(close);
            mvcContext.Controllers.add(controller);
        }
        public void Update(MvcControllerViewModel vmMVCContr, string UserName)
        {
            MvcController objMVCContr = Find(vmMVCContr.ControllerId);

            objMVCContr.ControllerName     = vmMVCContr.ControllerName;
            objMVCContr.IsActive           = vmMVCContr.IsActive;
            objMVCContr.ParentControllerId = vmMVCContr.ParentControllerId;
            objMVCContr.PubModuleName      = vmMVCContr.PubModuleName;
            objMVCContr.ModifiedBy         = UserName;
            objMVCContr.ModifiedDate       = DateTime.Now;

            objMVCContr.ObjectState = Model.ObjectState.Modified;

            _MvcControllerRepository.Update(objMVCContr);

            _unitOfWork.Save();
        }
        public List <MvcAction> GetActions(MvcController controller)
        {
            if (_types == null)
            {
                this._types = this._assembly.GetTypes();
            }

            var actions = _types
                          .SelectMany(type => type.GetMethods((BindingFlags.Instance | BindingFlags.Public)))
                          .Where(m => !m.Name.StartsWith("get_") && !m.Name.StartsWith("set_") && (m.DeclaringType.Name == controller.DeclareTypeName) &&
                                 !m.CustomAttributes.Any(c =>
                                                         c.AttributeType == typeof(System.Web.Http.AllowAnonymousAttribute) ||
                                                         c.AttributeType == typeof(System.Web.Mvc.AllowAnonymousAttribute) ||
                                                         c.AttributeType == typeof(System.Web.Http.NonActionAttribute) ||
                                                         c.AttributeType == typeof(System.Web.Mvc.NonActionAttribute))
                                 );

            if (actions.Count() > 0)
            {
                controller.Actions = actions.Select(x => new MvcAction
                {
                    ControllerName = controller.ControllerName,
                    ActionName     = x.Name,
                    Methods        = string.Join(",", x.CustomAttributes.Where(attr =>
                                                                               attr.AttributeType == typeof(System.Web.Mvc.HttpGetAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Mvc.HttpPostAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Mvc.HttpPutAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Mvc.HttpDeleteAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Mvc.HttpPatchAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Http.HttpGetAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Http.HttpPutAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Http.HttpDeleteAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Http.HttpPatchAttribute) ||
                                                                               attr.AttributeType == typeof(System.Web.Http.HttpPostAttribute)
                                                                               ).Select(attr => attr.AttributeType.Name.Remove(0, 4).Replace("Attribute", ""))),
                    Description    = x.GetCustomAttribute <DescriptionAttribute>()?.Description,
                    ReturnType     = x.ReturnType.ToString(),
                    ParameterTypes = x.GetParameters().Select(p => p.ParameterType.ToString())
                }).ToList();

                return(controller.Actions);
            }
            return(null);
        }
        public override void addToController(Slide slide, MvcController controller, AnomalousMvcContext context)
        {
            String closeCommandName = String.Format("CloseImagePopup__{0}", name);

            RunCommandsAction openAction = new RunCommandsAction(name, new ShowViewCommand(name));

            controller.Actions.add(openAction);

            RunCommandsAction closeAction = new RunCommandsAction(closeCommandName, new CloseViewCommand());

            controller.Actions.add(closeAction);

            RawRmlView popupView = new RawRmlView(name);

            popupView.ElementName = new LayoutElementName(GUILocationNames.ContentAreaPopup);
            popupView.Buttons.add(new CloseButtonDefinition(String.Format("CloseButton__{0}", name), String.Format("{0}/{1}", slide.UniqueName, closeCommandName)));
            popupView.Rml      = String.Format(ImageRml, imageName);
            popupView.FakePath = Path.Combine(slide.UniqueName, "ImagePopup.rml");
            context.Views.add(popupView);
        }
Exemple #16
0
        public void WithResponceModelShouldThrowExceptionWithDifferentPassedExpectedObject()
        {
            var controller = new MvcController();

            var another = controller.ResponseModel.ToList();

            another.Add(new ResponseModel());

            Test.AssertException <ResponseModelAssertionException>(
                () =>
            {
                MyController <MvcController>
                .Instance()
                .Calling(c => c.OkResultWithResponse())
                .ShouldReturn()
                .Ok()
                .WithModel(another);
            },
                "When calling OkResultWithResponse action in MvcController expected response model List<ResponseModel> to be the given model, but in fact it was a different one.");
        }
        public MvcControllerViewModel Create(MvcControllerViewModel pt, string UserName)
        {
            MvcController obj = new MvcController();

            obj = Mapper.Map <MvcController>(pt);

            obj.CreatedBy    = UserName;
            obj.CreatedDate  = DateTime.Now;
            obj.ModifiedBy   = UserName;
            obj.ModifiedDate = DateTime.Now;
            obj.ObjectState  = Model.ObjectState.Added;

            _MvcControllerRepository.Add(obj);

            _unitOfWork.Save();

            pt.ControllerId = obj.ControllerId;

            return(pt);
        }
        public void GetPropertiesShouldNotThrowExceptionForNormalController()
        {
            MyApplication.StartsFrom<DefaultStartup>();

            var helper = ViewDataPropertyHelper.GetViewDataProperties<MvcController>();

            var controller = new MvcController();
            var controllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    RequestServices = TestServiceProvider.Global
                }
            };

            var gotViewData = helper.ViewDataGetter(controller);

            Assert.NotNull(gotViewData);
            Assert.Same(gotViewData, controller.ViewData);
        }
        public void GetPropertiesShouldNotThrowExceptionForNormalController()
        {
            MyApplication.StartsFrom <DefaultStartup>();

            var helper = ViewDataPropertyHelper.GetViewDataProperties <MvcController>();

            var controller        = new MvcController();
            var controllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext
                {
                    RequestServices = TestServiceProvider.Global
                }
            };

            var gotViewData = helper.ViewDataGetter(controller);

            Assert.NotNull(gotViewData);
            Assert.Same(gotViewData, controller.ViewData);
        }
Exemple #20
0
        public void setupContext(AnomalousMvcContext context, String name, ResourceProvider resourceProvider, SlideDisplayManager displayManager)
        {
            MvcController     controller  = new MvcController(name);
            RunCommandsAction showCommand = new RunCommandsAction("Show");

            showCommand.addCommand(new CloseAllViewsCommand());
            String timelinePath = Path.Combine(UniqueName, "Timeline.tl");

            if (resourceProvider.exists(timelinePath))
            {
                showCommand.addCommand(new PlayTimelineCommand(timelinePath));
            }
            foreach (var action in triggerActions.Values)
            {
                action.addToController(this, controller, context);
            }
            context.Controllers.add(controller);

            layoutStrategy.createViews(name, showCommand, context, displayManager, this);

            controller.Actions.add(showCommand);
            customizeController(controller, showCommand);
        }
Exemple #21
0
        public void UpdateControllers()
        {
            string s = "";

            List <ControllerActionList> List        = new List <ControllerActionList>();
            List <ControllerActionList> Controllers = new List <ControllerActionList>();

            var controllers = Assembly.GetExecutingAssembly().GetExportedTypes().Where(t => typeof(ControllerBase).IsAssignableFrom(t)).Select(t => t);

            #region ☺ControllerUpdateCode☺

            foreach (Type controller in controllers)
            {
                if (controller.Name != "AccountController")
                {
                    Controllers.Add(new ControllerActionList {
                        ControllerName = controller.Name.Replace("Controller", "")
                    });
                }
            }

            List <ControllerActionList> DBControllers = (from p in db.MvcController
                                                         where p.PubModuleName == ProjectConstants.Customize
                                                         select new ControllerActionList {
                ControllerName = p.ControllerName, IsActive = p.IsActive
            }
                                                         ).ToList();


            var PendingToUpdate = from p in Controllers
                                  join t in DBControllers on p.ControllerName equals t.ControllerName into table
                                  from left in table.DefaultIfEmpty()
                                  where left == null
                                  select p.ControllerName;

            var PendingToDeActivate = from p in DBControllers
                                      join t in Controllers on p.ControllerName equals t.ControllerName into table
                                      from right in table.DefaultIfEmpty()
                                      where right == null
                                      select p.ControllerName;

            var PendingToActivate = from p in Controllers
                                    join t in DBControllers.Where(m => m.IsActive == false) on p.ControllerName equals t.ControllerName
                                    select p.ControllerName;


            foreach (var item in PendingToUpdate)
            {
                if (!CommonControllers.Controllers.Contains(item))
                {
                    MvcController temp = new MvcController();

                    temp.ControllerName = item;
                    temp.IsActive       = true;
                    temp.PubModuleName  = ProjectConstants.Customize;
                    temp.ObjectState    = Model.ObjectState.Added;
                    temp.CreatedBy      = User.Identity.Name;
                    temp.CreatedDate    = DateTime.Now;
                    temp.ModifiedBy     = User.Identity.Name;
                    temp.ModifiedDate   = DateTime.Now;
                    new MvcControllerService(_unitOfWork).Create(temp);
                }
            }

            foreach (var item in PendingToDeActivate)
            {
                MvcController DeactivateRecord = new MvcControllerService(_unitOfWork).Find(item);
                DeactivateRecord.IsActive     = false;
                DeactivateRecord.ModifiedBy   = User.Identity.Name;
                DeactivateRecord.ModifiedDate = DateTime.Now;
                new MvcControllerService(_unitOfWork).Update(DeactivateRecord);
            }

            foreach (var item in PendingToActivate)
            {
                MvcController ActivateRecord = new MvcControllerService(_unitOfWork).Find(item);
                ActivateRecord.IsActive     = true;
                ActivateRecord.ModifiedBy   = User.Identity.Name;
                ActivateRecord.ModifiedDate = DateTime.Now;
                new MvcControllerService(_unitOfWork).Update(ActivateRecord);
            }

            try
            {
                _unitOfWork.Save();
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ErrorMessage = message;
            }


            #endregion
        }
 /// <summary>
 /// Add the slide action to a given mvc controller.
 /// </summary>
 /// <param name="slide"></param>
 /// <param name="controller"></param>
 public abstract void addToController(Slide slide, MvcController controller, AnomalousMvcContext context);
        public void WithResponseModelShouldNotThrowExceptionWithCorrectPassedExpectedObject()
        {
            var controller = new MvcController();

            MyMvc
                .Controller(() => controller)
                .Calling(c => c.OkResultWithInterfaceResponse())
                .ShouldReturn()
                .Ok()
                .WithResponseModel(controller.ResponseModel);
        }
        public void WithResponceModelShouldThrowExceptionWithDifferentPassedExpectedObject()
        {
            var controller = new MvcController();

            var another = controller.ResponseModel.ToList();
            another.Add(new ResponseModel());

            Test.AssertException<ResponseModelAssertionException>(
                () =>
                {
                    MyMvc
                        .Controller<MvcController>()
                        .Calling(c => c.OkResultWithResponse())
                        .ShouldReturn()
                        .Ok()
                        .WithResponseModel(another);
                },
                "When calling OkResultWithResponse action in MvcController expected response model List<ResponseModel> to be the given model, but in fact it was a different one.");
        }
        public void WithResponceModelShouldNotThrowExceptionWithDeeplyEqualPassedExpectedObject()
        {
            var controller = new MvcController();

            MyMvc
                .Controller<MvcController>()
                .Calling(c => c.OkResultWithResponse())
                .ShouldReturn()
                .Ok()
                .WithResponseModel(controller.ResponseModel);
        }
 public abstract string TryResolve(string currentRoute, MvcController controller, MvcAction action);
 public override string TryResolve(string currentRoute, MvcController controller, MvcAction action) => _func(currentRoute, controller, action);
Exemple #28
0
 private bool HasAnyComplexQueryParmeter(MvcController controller)
 => controller.Actions.Any(a => HasAnyComplexQueryParmeter(a));
Exemple #29
0
 public AspNetCoreRouteGenerator(MvcController controller, string baseUrl) : base(controller, baseUrl)
 {
 }
        public void SyncControllersList(List <ControllerActionList> Controllers, string UserName)
        {
            List <ControllerActionList> List = new List <ControllerActionList>();

            #region ☺ControllerUpdateCode☺

            List <ControllerActionList> DBControllers = (from p in _MvcControllerRepository.Instance
                                                         select new ControllerActionList {
                ControllerName = p.ControllerName, IsActive = p.IsActive
            }
                                                         ).ToList();

            var PendingToUpdate = from p in Controllers
                                  join t in DBControllers on p.ControllerName equals t.ControllerName into table
                                  from left in table.DefaultIfEmpty()
                                  where left == null
                                  select p.ControllerName;

            var PendingToDeActivate = from p in DBControllers
                                      join t in Controllers on p.ControllerName equals t.ControllerName into table
                                      from right in table.DefaultIfEmpty()
                                      where right == null
                                      select p.ControllerName;

            var PendingToActivate = from p in Controllers
                                    join t in DBControllers.Where(m => m.IsActive == false) on p.ControllerName equals t.ControllerName
                                    select p.ControllerName;


            foreach (var item in PendingToUpdate)
            {
                MvcController temp = new MvcController();

                temp.ControllerName = item;
                temp.IsActive       = true;
                temp.ObjectState    = Model.ObjectState.Added;
                temp.CreatedBy      = UserName;
                temp.CreatedDate    = DateTime.Now;
                temp.ModifiedBy     = UserName;
                temp.ModifiedDate   = DateTime.Now;

                _MvcControllerRepository.Add(temp);
            }

            foreach (var item in PendingToDeActivate)
            {
                MvcController DeactivateRecord = Find(item);
                DeactivateRecord.IsActive     = false;
                DeactivateRecord.ModifiedBy   = UserName;
                DeactivateRecord.ModifiedDate = DateTime.Now;
                DeactivateRecord.ObjectState  = Model.ObjectState.Modified;

                _MvcControllerRepository.Update(DeactivateRecord);
            }

            foreach (var item in PendingToActivate)
            {
                MvcController ActivateRecord = Find(item);
                ActivateRecord.IsActive     = true;
                ActivateRecord.ModifiedBy   = UserName;
                ActivateRecord.ModifiedDate = DateTime.Now;
                ActivateRecord.ObjectState  = Model.ObjectState.Modified;
                _MvcControllerRepository.Update(ActivateRecord);
            }
            #endregion


            _unitOfWork.Save();
        }
 public MvcController Create(MvcController pt)
 {
     _unitOfWork.Repository <MvcController>().Insert(pt);
     return(pt);
 }
 public void Update(MvcController pt)
 {
     _unitOfWork.Repository <MvcController>().Update(pt);
 }
        public EditorUICallback(StandaloneController standaloneController, EditorController editorController, PropEditController propEditController)
            : base(standaloneController, editorController, propEditController)
        {
            this.addOneWayCustomQuery(AnomalousMvcContext.CustomQueries.Preview, delegate(AnomalousMvcContext context)
            {
                previewMvcContext(context);
            });

            this.addSyncCustomQuery<Browser>(ViewBrowserEditableProperty.CustomQueries.BuildBrowser, () =>
            {
                Browser browser = new Browser("Views", "Choose View");
                if (CurrentEditingMvcContext != null)
                {
                    foreach (View view in CurrentEditingMvcContext.Views)
                    {
                        browser.addNode(null, null, new BrowserNode(view.Name, view.Name));
                    }
                }
                return browser;
            });

            this.addSyncCustomQuery<Browser, Type>(ModelBrowserEditableProperty.CustomQueries.BuildBrowser, (assignableFromType) =>
            {
                Browser browser = new Browser("Models", "Choose Model");
                if (CurrentEditingMvcContext != null)
                {
                    foreach (MvcModel model in CurrentEditingMvcContext.Models)
                    {
                        if (assignableFromType.IsAssignableFrom(model.GetType()))
                        {
                            browser.addNode(null, null, new BrowserNode(model.Name, model.Name));
                        }
                    }
                }
                return browser;
            });

            this.addOneWayCustomQuery(View.CustomQueries.AddControllerForView, delegate(View view)
            {
                AnomalousMvcContext context = CurrentEditingMvcContext;
                String controllerName = view.Name;
                if (context.Controllers.hasItem(controllerName))
                {
                    MessageBox.show(String.Format("There is already a controller named {0}. Cannot create a new one.", controllerName), "Error", MessageBoxStyle.IconError | MessageBoxStyle.Ok);
                }
                else
                {
                    MvcController controller = new MvcController(controllerName);
                    RunCommandsAction showCommand = new RunCommandsAction("Show");
                    showCommand.addCommand(new ShowViewCommand(view.Name));
                    controller.Actions.add(showCommand);

                    RunCommandsAction closeCommand = new RunCommandsAction("Close");
                    closeCommand.addCommand(new CloseViewCommand());
                    controller.Actions.add(closeCommand);
                    context.Controllers.add(controller);
                }
            });

            this.addSyncCustomQuery<Browser>(ActionBrowserEditableProperty.CustomQueries.BuildBrowser, () =>
            {
                return createActionBrowser();
            });

            this.addSyncCustomQuery<Browser>(ElementAttributeEditor.CustomQueries.BuildActionBrowser, () =>
            {
                return createActionBrowser();
            });

            this.addSyncCustomQuery<Browser, IEnumerable<String>, String, String>(ElementAttributeEditor.CustomQueries.BuildFileBrowser, (searchPatterns, prompt, leadingPath) =>
            {
                return createFileBrowser(searchPatterns, prompt, leadingPath);
            });

            this.addCustomQuery<String, String>(PlaySoundAction.CustomQueries.Record, (queryResult, soundFile) =>
            {
                this.getInputString("Enter a name for the sound file.", delegate(String result, ref String errorMessage)
                {
                    String finalSoundFile = Path.ChangeExtension(result, ".ogg");
                    String error = null;
                    QuickSoundRecorder.ShowDialog(standaloneController.MedicalController, finalSoundFile, editorController.ResourceProvider.openWriteStream,
                    newSoundFile =>
                    {
                        queryResult.Invoke(newSoundFile, ref error);
                    });
                    return true;
                });
            });

            this.addSyncCustomQuery<Browser>(TimelinePreActionEditInterface.CustomQueries.BuildActionBrowser, () =>
            {
                var browser = new Browser("Pre Actions", "Choose Pre Action");
                browser.addNode(null, null, new BrowserNode("Change Scene", typeof(OpenNewSceneAction)));
                browser.addNode(null, null, new BrowserNode("Show Skip To Post Actions Prompt", typeof(SkipToPostActions)));
                browser.addNode(null, null, new BrowserNode("Run Mvc Action", typeof(RunMvcAction)));
                return browser;
            });

            this.addSyncCustomQuery<Browser>(TimelinePostActionEditInterface.CustomQueries.BuildActionBrowser, () =>
            {
                var browser = new Browser("Post Actions", "Choose Post Action");
                browser.addNode(null, null, new BrowserNode("Load Another Timeline", typeof(LoadAnotherTimeline)));
                browser.addNode(null, null, new BrowserNode("Repeat Previous", typeof(RepeatPreviousPostActions)));
                browser.addNode(null, null, new BrowserNode("Run Mvc Action", typeof(RunMvcAction)));
                return browser;
            });
        }
 public void Delete(MvcController pt)
 {
     _MvcControllerRepository.Delete(pt);
 }
Exemple #35
0
        public RmlEditorContext(String file, RmlTypeController rmlTypeController, AnomalousMvcContext editingMvcContext, EditorController editorController, EditorUICallback uiCallback)
        {
            this.rmlTypeController = rmlTypeController;
            this.currentFile       = file;
            this.uiCallback        = uiCallback;

            undoBuffer = new UndoRedoBuffer(50);

            rmlTypeController.loadText(currentFile);

            mvcContext = new AnomalousMvcContext();
            mvcContext.StartupAction = "Common/Start";
            mvcContext.FocusAction   = "Common/Focus";
            mvcContext.BlurAction    = "Common/Blur";
            mvcContext.SuspendAction = "Common/Suspended";
            mvcContext.ResumeAction  = "Common/Resumed";

            TextEditorView textEditorView = new TextEditorView("RmlEditor", () => rmlComponent.CurrentRml, wordWrap: false, textHighlighter: RmlTextHighlighter.Instance);

            textEditorView.ElementName = new MDILayoutElementName(GUILocationNames.MDI, DockLocation.Left);
            textEditorView.Buttons.add(new CloseButtonDefinition("Close", "RmlTextEditor/Close"));
            textEditorView.ComponentCreated += (view, component) =>
            {
                textEditorComponent = component;
            };
            mvcContext.Views.add(textEditorView);

            RmlWysiwygView rmlView = new RmlWysiwygView("RmlView", uiCallback, undoBuffer);

            rmlView.ElementName       = new MDILayoutElementName(GUILocationNames.MDI, DockLocation.Left);
            rmlView.RmlFile           = file;
            rmlView.ComponentCreated += (view, component) =>
            {
                rmlComponent            = component;
                rmlComponent.RmlEdited += rmlEditor =>
                {
                    if (textEditorComponent != null)
                    {
                        textEditorComponent.Text = rmlEditor.CurrentRml;
                    }
                };
            };
            mvcContext.Views.add(rmlView);

            DragAndDropView <WysiwygDragDropItem> htmlDragDrop = new DragAndDropView <WysiwygDragDropItem>("HtmlDragDrop",
                                                                                                           new WysiwygDragDropItem("Heading", "Editor/HeaderIcon", "<h1>Heading</h1>"),
                                                                                                           new WysiwygDragDropItem("Paragraph", "Editor/ParagraphsIcon", "<p>Add paragraph text here.</p>"),
                                                                                                           new WysiwygDragDropItem("Image", "Editor/ImageIcon", String.Format("<img src=\"{0}\" style=\"width:200px;\"></img>", RmlWysiwygComponent.DefaultImage)),
                                                                                                           new WysiwygDragDropItem("Link", "Editor/LinksIcon", "<a onclick=\"None\">Link</a>"),
                                                                                                           new WysiwygDragDropItem("Button", "Editor/AddButtonIcon", "<input type=\"submit\" onclick=\"None\">Button</input>"),
                                                                                                           new WysiwygDragDropItem("Separator", CommonResources.NoIcon, "<x-separator/>"),
                                                                                                           new WysiwygDragDropItem("Two Columns", CommonResources.NoIcon, "<div class=\"TwoColumn\"><div class=\"Column\"><p>Column 1 text goes here.</p></div><div class=\"Column\"><p>Column 2 text goes here.</p></div></div>"),
                                                                                                           new WysiwygDragDropItem("Heading and Paragraph", CommonResources.NoIcon, "<h1>Heading For Paragraph.</h1><p>Paragraph for heading.</p>", "div"),
                                                                                                           new WysiwygDragDropItem("Left Image and Paragraph", CommonResources.NoIcon, String.Format("<div class=\"ImageParagraphLeft\"><img src=\"{0}\" style=\"width:200px;\"/><p>Add paragraph text here.</p></div>", RmlWysiwygComponent.DefaultImage)),
                                                                                                           new WysiwygDragDropItem("Right Image and Paragraph", CommonResources.NoIcon, String.Format("<div class=\"ImageParagraphRight\"><img src=\"{0}\" style=\"width:200px;\"/><p>Add paragraph text here.</p></div>", RmlWysiwygComponent.DefaultImage))
                                                                                                           );

            htmlDragDrop.Dragging += (item, position) =>
            {
                rmlComponent.setPreviewElement(position, item.PreviewMarkup, item.PreviewTagType);
            };
            htmlDragDrop.DragEnded += (item, position) =>
            {
                if (rmlComponent.contains(position))
                {
                    rmlComponent.insertRml(item.createDocumentMarkup());
                }
                else
                {
                    rmlComponent.cancelAndHideEditor();
                    rmlComponent.clearPreviewElement(false);
                }
            };
            htmlDragDrop.ItemActivated += (item) =>
            {
                rmlComponent.insertRml(item.createDocumentMarkup());
            };
            htmlDragDrop.ElementName = new MDILayoutElementName(GUILocationNames.MDI, DockLocation.Left);
            mvcContext.Views.add(htmlDragDrop);

            EditorTaskbarView taskbar = new EditorTaskbarView("InfoBar", currentFile, "Editor/Close");

            taskbar.addTask(new CallbackTask("SaveAll", "Save All", "Editor/SaveAllIcon", "", 0, true, item =>
            {
                saveAll();
            }));
            taskbar.addTask(new RunMvcContextActionTask("Save", "Save Rml File", "CommonToolstrip/Save", "File", "Editor/Save", mvcContext));
            taskbar.addTask(new RunMvcContextActionTask("Undo", "Undo", CommonResources.NoIcon, "Edit", "Editor/Undo", mvcContext));
            taskbar.addTask(new RunMvcContextActionTask("Redo", "Redo", CommonResources.NoIcon, "Edit", "Editor/Redo", mvcContext));
            taskbar.addTask(new RunMvcContextActionTask("Cut", "Cut", "Editor/CutIcon", "Edit", "Editor/Cut", mvcContext));
            taskbar.addTask(new RunMvcContextActionTask("Copy", "Copy", "Editor/CopyIcon", "Edit", "Editor/Copy", mvcContext));
            taskbar.addTask(new RunMvcContextActionTask("Paste", "Paste", "Editor/PasteIcon", "Edit", "Editor/Paste", mvcContext));
            taskbar.addTask(new RunMvcContextActionTask("SelectAll", "Select All", "Editor/SelectAllIcon", "Edit", "Editor/SelectAll", mvcContext));
            taskbar.addTask(new RunMvcContextActionTask("RmlEditor", "Edit Rml", RmlTypeController.Icon, "Edit", "RmlTextEditor/Show", mvcContext));
            mvcContext.Views.add(taskbar);

            mvcContext.Controllers.add(new MvcController("RmlTextEditor",
                                                         new RunCommandsAction("Show",
                                                                               new ShowViewIfNotOpenCommand("RmlEditor")),
                                                         new RunCommandsAction("Close",
                                                                               new CloseViewCommand(),
                                                                               new CallbackCommand(context =>
            {
                textEditorComponent = null;
            }))
                                                         ));

            mvcContext.Controllers.add(new MvcController("HtmlDragDrop",
                                                         new RunCommandsAction("Show",
                                                                               new ShowViewIfNotOpenCommand("HtmlDragDrop")),
                                                         new RunCommandsAction("Close",
                                                                               new CloseViewCommand())
                                                         ));

            mvcContext.Controllers.add(new MvcController("Editor",
                                                         new RunCommandsAction("Show",
                                                                               new ShowViewCommand("RmlView"),
                                                                               new ShowViewCommand("InfoBar")),
                                                         new RunCommandsAction("Close", new CloseAllViewsCommand()),
                                                         new CallbackAction("Save", context =>
            {
                save();
            }),
                                                         new CallbackAction("Cut", context =>
            {
                if (textEditorComponent != null)
                {
                    textEditorComponent.cut();
                }
            }),
                                                         new CallbackAction("Copy", context =>
            {
                if (textEditorComponent != null)
                {
                    textEditorComponent.copy();
                }
            }),
                                                         new CallbackAction("Paste", context =>
            {
                if (textEditorComponent != null)
                {
                    textEditorComponent.paste();
                }
            }),
                                                         new CallbackAction("SelectAll", context =>
            {
                if (textEditorComponent != null)
                {
                    textEditorComponent.selectAll();
                }
            }),
                                                         new CallbackAction("Undo", context =>
            {
                undoBuffer.undo();
            }),
                                                         new CallbackAction("Redo", context =>
            {
                undoBuffer.execute();
            })
                                                         ));

            mvcContext.Controllers.add(new MvcController("Common",
                                                         new RunCommandsAction("Start", new RunActionCommand("HtmlDragDrop/Show"), new RunActionCommand("Editor/Show")),
                                                         new CallbackAction("Focus", context =>
            {
                GlobalContextEventHandler.setEventContext(eventContext);
                if (Focus != null)
                {
                    Focus.Invoke(this);
                }
            }),
                                                         new CallbackAction("Blur", context =>
            {
                GlobalContextEventHandler.disableEventContext(eventContext);
                if (Blur != null)
                {
                    Blur.Invoke(this);
                }
            }),
                                                         new RunCommandsAction("Suspended", new SaveViewLayoutCommand()),
                                                         new RunCommandsAction("Resumed", new RestoreViewLayoutCommand())));

            eventContext = new EventContext();
            ButtonEvent saveEvent = new ButtonEvent(EventLayers.Gui);

            saveEvent.addButton(KeyboardButtonCode.KC_LCONTROL);
            saveEvent.addButton(KeyboardButtonCode.KC_S);
            saveEvent.FirstFrameUpEvent += eventManager =>
            {
                saveAll();
            };
            eventContext.addEvent(saveEvent);

            ButtonEvent undoEvent = new ButtonEvent(EventLayers.Gui);

            undoEvent.addButton(KeyboardButtonCode.KC_LCONTROL);
            undoEvent.addButton(KeyboardButtonCode.KC_Z);
            undoEvent.FirstFrameUpEvent += eventManager =>
            {
                undoBuffer.undo();
            };
            eventContext.addEvent(undoEvent);

            ButtonEvent redoEvent = new ButtonEvent(EventLayers.Gui);

            redoEvent.addButton(KeyboardButtonCode.KC_LCONTROL);
            redoEvent.addButton(KeyboardButtonCode.KC_Y);
            redoEvent.FirstFrameUpEvent += eventManager =>
            {
                undoBuffer.execute();
            };
            eventContext.addEvent(redoEvent);

            if (editingMvcContext != null)
            {
                String controllerName = PathExtensions.RemoveExtension(file);
                if (editingMvcContext.Controllers.hasItem(controllerName))
                {
                    MvcController viewController = editingMvcContext.Controllers[controllerName];

                    GenericPropertiesFormView genericPropertiesView = new GenericPropertiesFormView("MvcContext", viewController.getEditInterface(), editorController, uiCallback, true);
                    genericPropertiesView.ElementName = new MDILayoutElementName(GUILocationNames.MDI, DockLocation.Left);
                    genericPropertiesView.Buttons.add(new CloseButtonDefinition("Close", "MvcEditor/Close"));
                    mvcContext.Views.add(genericPropertiesView);

                    taskbar.addTask(new RunMvcContextActionTask("EditActions", "Edit Actions", "MvcContextEditor/ControllerIcon", "Edit", "MvcEditor/Show", mvcContext));

                    mvcContext.Controllers.add(new MvcController("MvcEditor",
                                                                 new RunCommandsAction("Show",
                                                                                       new ShowViewIfNotOpenCommand("MvcContext")),
                                                                 new RunCommandsAction("Close",
                                                                                       new CloseViewCommand())
                                                                 ));
                }

                if (editingMvcContext.Views.hasItem(controllerName))
                {
                    RmlView view = editingMvcContext.Views[controllerName] as RmlView;
                    if (view != null && view.RmlFile == file)
                    {
                        GenericPropertiesFormView genericPropertiesView = new GenericPropertiesFormView("MvcView", view.getEditInterface(), editorController, uiCallback, true);
                        genericPropertiesView.ElementName = new MDILayoutElementName(GUILocationNames.MDI, DockLocation.Left);
                        genericPropertiesView.Buttons.add(new CloseButtonDefinition("Close", "MvcViewEditor/Close"));
                        mvcContext.Views.add(genericPropertiesView);

                        taskbar.addTask(new RunMvcContextActionTask("EditView", "Edit View", "MvcContextEditor/IndividualViewIcon", "Edit", "MvcViewEditor/Show", mvcContext));

                        mvcContext.Controllers.add(new MvcController("MvcViewEditor",
                                                                     new RunCommandsAction("Show",
                                                                                           new ShowViewIfNotOpenCommand("MvcView")),
                                                                     new RunCommandsAction("Close",
                                                                                           new CloseViewCommand())
                                                                     ));
                    }
                }

                taskbar.addTask(new CallbackTask("PreviewMvc", "Preview", "MvcContextEditor/MVCcomIcon", "", 0, true, (item) =>
                {
                    uiCallback.previewMvcContext(editingMvcContext);
                }));
            }
        }