Exemple #1
0
        public async Task <ActionResult> CreateOrEdit(string id)
        {
            var categories = await _categoryService.GetAllAsync(new CategoryFilter());

            EffectViewModel model;

            // Get EffectViewModel according to whether is edit or create.
            if (!string.IsNullOrEmpty(id))
            {
                // Edit
                var effect = await _effectService.GetByIdAsync(id);

                if (effect == null)
                {
                    Log.Error($"An unexpected error occurred while getting id. No entity with id {id} could be found.");
                    throw new ArgumentNullException(string.Format(Resources.Resources.Error_NoEntityWithIdFound, id));
                }

                model = new EffectViewModel(effect, categories);
            }
            else
            {
                // Create
                model = new EffectViewModel(null, categories);
            }

            return(View(model));
        }
        /// <summary>
        /// Processes the specified form.
        /// </summary>
        /// <param name="effectViewModel">The effect view model.</param>
        internal void Process(EffectViewModel effectViewModel)
        {
            TraceService.WriteLine("EffectsController::Process");

            this.VisualStudioService.WriteStatusBarMessage(NinjaMessages.NinjaIsRunning);

            try
            {
                TraceService.WriteLine("EffectsController::Process GetTextTemplates");

                IEnumerable <TextTemplateInfo> textTemplates = this.effectFactory.GetTextTemplates(
                    effectViewModel.RequestedName,
                    this.SettingsService.EffectDirectory);

                IEnumerable <string> messages = this.textTemplatingService.AddTextTemplates(
                    NinjaMessages.AddingEffect,
                    textTemplates);

                //// show the readme.
                this.ShowReadMe("Add Xamarin Forms Effect", messages);
            }
            catch (Exception exception)
            {
                TraceService.WriteError("Cannot create effect exception=" + exception.Message);
            }
        }
Exemple #3
0
        public async Task <ActionResult> Index(string lastEditedEffectId)
        {
            var filter = new EffectFilter();

            // Get values from database.
            var effects = await _effectService.GetAllAsync(filter);

            var categories = await _categoryService.GetAllAsync(new CategoryFilter());

            IList <EffectViewModel> effectViewModels = new List <EffectViewModel>();

            // Create list of effects for view.
            foreach (var effect in effects)
            {
                var model = new EffectViewModel(effect, null);
                effectViewModels.Add(model);
            }

            // Create view model for Index view.
            var effectViewModelIndex = new EffectViewModelIndex(effectViewModels, categories);

            // Set value to where to scroll to.
            effectViewModelIndex.LastEditedEffectId = lastEditedEffectId;

            return(View(effectViewModelIndex));
        }
        public ActionResult EffectNew(int typeId)
        {
            EffectViewModel vm = new EffectViewModel();

            vm.EffectType = db.EffectTypes.Single(p => p.EffectTypeId == typeId);
            return(View(vm));
        }
        public ActionResult EffectDelete(int id)
        {
            EffectViewModel vm = new EffectViewModel();

            vm.Effect = db.Effects.Single(p => p.EffectId == id);
            return(View(vm));
        }
        public ActionResult EffectList(int typeId)
        {
            EffectViewModel vm = new EffectViewModel();

            vm.EffectType     = db.EffectTypes.Single(p => p.EffectTypeId == typeId);
            vm.Effects        = db.Effects.Where(p => p.EffectTypeId == typeId);
            ViewBag.CanModify = userData.IsAdmin;
            return(View(vm));
        }
 public ActionResult EffectEdit(EffectViewModel vm)
 {
     if (ModelState.IsValid)
     {
         db.Effects.Attach(vm.Effect);
         db.Entry(vm.Effect).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("EffectList", new { typeId = vm.Effect.EffectTypeId }));
     }
     return(View(vm));
 }
        public void DropEffectInSlot(Point point, EffectViewModel effect)
        {
            EffectSlotViewModel effectSlotViewModel = GetEffectSlotAtPoint(point);

            if (effectSlotViewModel != null)
            {
                effectSlotViewModel.PushEffect(effect);

                CharacterViewModel.Effects.Remove(effect);
            }
        }
Exemple #9
0
        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            EffectViewModel effectViewModel = value as EffectViewModel;

            if (effectViewModel != null)
            {
                return(effectViewModel);
            }

            return(null);
        }
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Create([Bind(properties)] EffectViewModel c)
        {
            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            c.ID = Guid.NewGuid().ToString();
            var o = EffectObjectFactory.Create(c.ID, c.Name, c.ValidFrom, c.ValidTo);
            await repository.AddObject(o);

            return(RedirectToAction("Index"));
        }
 public ActionResult EffectNew(EffectViewModel vm, int typeId)
 {
     if (ModelState.IsValid)
     {
         vm.Effect.EffectTypeId = typeId;
         db.Effects.Add(vm.Effect);
         db.SaveChanges();
         return(RedirectToAction("EffectList", new { typeId = typeId }));
     }
     vm.EffectType = db.EffectTypes.Single(p => p.EffectTypeId == typeId);
     return(View(vm));
 }
        private void Grid_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            Point point = e.Position;

            Rect?boundingRect = null;

            bool pointIsInEffectsSheet = CharacterSheetGrid.IsPointInElement(CharacterEffectsSheet, point);
            bool pointIsInEffectsList  = CharacterSheetGrid.IsPointInElement(PossibleEffectsList, point);

            if (pointIsInEffectsSheet)
            {
                Point pointInChild = CharacterSheetGrid.TranslatePointToContainer(CharacterEffectsSheet, point);

                originalSlotViewModel = CharacterEffectsSheet.GetEffectSlotAtPoint(pointInChild);

                if (originalSlotViewModel != null)
                {
                    draggedViewModel = originalSlotViewModel.ActiveEffect;

                    boundingRect = CharacterEffectsSheet.GetBoundingRectForItem(originalSlotViewModel);

                    dragStartPosition = StartPosition.EffectGrid;
                }
            }
            else if (pointIsInEffectsList)
            {
                Point pointInChild = CharacterSheetGrid.TranslatePointToContainer(PossibleEffectsList, point);

                draggedViewModel = PossibleEffectsList.GetItemAtPoint <EffectViewModel>(pointInChild);

                dragStartPosition = StartPosition.PossibleList;

                boundingRect = PossibleEffectsList.GetBoundingRectForItem(draggedViewModel, CharacterSheetGrid);
            }

            if (draggedViewModel != null)
            {
                manipulationInitialized = true;

                DraggableEffect.EffectViewModel = draggedViewModel;

                //Save the initial touch point so we can calculate deltas
                lastManipulationPosition = point;

                DraggableEffect.Width  = 300;
                DraggableEffect.Height = boundingRect.Value.Height - 20; //stupid magic number

                DraggableEffectTranslateTransform.X = boundingRect.Value.X - (CharacterSheetGrid.ActualWidth / 2) + 150;
                DraggableEffectTranslateTransform.Y = boundingRect.Value.Y - (CharacterSheetGrid.ActualHeight / 2) + (DraggableEffect.Height / 2);

                DraggableEffect.Visibility = Visibility.Visible;
            }
        }
        public async Task <IActionResult> Edit([Bind(properties)] EffectViewModel c)
        {
            if (!ModelState.IsValid)
            {
                return(View(c));
            }
            var o = await repository.GetObject(c.ID);

            o.DbRecord.Name      = c.Name;
            o.DbRecord.ValidFrom = c.ValidFrom ?? DateTime.MinValue;
            o.DbRecord.ValidTo   = c.ValidTo ?? DateTime.MaxValue;
            await repository.UpdateObject(o);

            return(RedirectToAction("Index"));
        }
Exemple #14
0
        public async Task <ActionResult> CreateOrEdit(EffectViewModel model)
        {
            var validationResult = new ValidationResultList();
            var effect           = new Effect();

            if (ModelState.IsValid)
            {
                try
                {
                    // Map view model to entity.
                    model.MapViewModelToEntity(effect);

                    // Edit or create
                    if (effect.Id != null)
                    {
                        validationResult = await _effectService.UpdateAsync(effect);
                    }
                    else
                    {
                        validationResult = await _effectService.InsertAsync(effect);
                    }
                }
                catch (Exception e)
                {
                    Log.Error($"An unexpected error occurred while inserting or editing: {e}");
                    throw new ArgumentException(Resources.Resources.Error_UnexpectedError);
                }
            }

            // Show validation result, if validation error occurred while
            // inserting or if ModelState is invalid.
            if (validationResult.HasErrors || !ModelState.IsValid)
            {
                AddValidationResultsToModelStateErrors(validationResult.Errors);

                // Set categories to display in drop down.
                var categories = await _categoryService.GetAllAsync(new CategoryFilter());

                model.Categories = categories;

                Log.Info("Show CreateOrEdit");
                return(View(nameof(CreateOrEdit), model));
            }

            // If form is valid, navigate to AssignMolecule.
            Log.Info("Redirect to AssignMolecule");
            return(RedirectToAction(nameof(AssignMolecule), new { id = effect.Id }));
        }
        private void Grid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            if (manipulationInitialized)
            {
                DraggableEffect.Visibility = Visibility.Collapsed;

                switch (dragStartPosition)
                {
                case StartPosition.EffectGrid:
                {
                    bool pointIsInEffectsList = CharacterSheetGrid.IsPointInElement(PossibleEffectsList, e.Position);

                    if (pointIsInEffectsList)
                    {
                        CharacterViewModel.Effects.Add(draggedViewModel);
                        originalSlotViewModel.PopEffect();
                    }

                    RemoveEffectListHighlight();

                    break;
                }

                case StartPosition.PossibleList:
                {
                    bool pointIsInEffectsSheet = CharacterSheetGrid.IsPointInElement(CharacterEffectsSheet, e.Position);

                    if (pointIsInEffectsSheet)
                    {
                        Point pointInEffectSheet = CharacterSheetGrid.TranslatePointToContainer(CharacterEffectsSheet, e.Position);

                        CharacterEffectsSheet.DropEffectInSlot(pointInEffectSheet, draggedViewModel);
                    }

                    CharacterEffectsSheet.ClearAllHighlights();

                    break;
                }
                }

                draggedViewModel = null;
            }

            manipulationInitialized = false;
        }
        /// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run()
        {
            TraceService.WriteHeader("EffectsController::Run");

            FrameworkType frameworkType = this.VisualStudioService.GetFrameworkType();

            if (frameworkType.IsXamarinFormsSolutionType())
            {
                this.effectFactory.RegisterWizardData();

                WizardFrameViewModel viewModel = this.ShowDialog <WizardFrameViewModel>(new WizardView());

                if (viewModel.Continue)
                {
                    EffectViewModel effectViewModel = (EffectViewModel)viewModel.GetWizardStepViewModel("EffectViewModel").ViewModel;

                    this.Process(effectViewModel);
                }
            }
            else
            {
                this.ShowNotXamarinFormsSolutionMessage();
            }
        }
Exemple #17
0
 public EffectPage()
 {
     InitializeComponent();
     BindingContext = new EffectViewModel();
 }
Exemple #18
0
        public static EffectsVM GetEffectViewModels()
        {
            var all = GetEffectTypes();
            var groupEffectsTypes = GetGroupEffectTypes();
            var groups            = GroupService.GetAll();

            Dictionary <string, List <EffectViewModel> > baseEffects = new Dictionary <string, List <EffectViewModel> >();
            List <EffectViewModel> shortEffects = new List <EffectViewModel>();
            List <EffectViewModel> groupEffects = new List <EffectViewModel>();

            foreach (var type in all)
            {
                var hueEffectAtt = type.GetCustomAttribute <HueEffectAttribute>();
                if (hueEffectAtt == null)
                {
                    continue;
                }

                var effect = new EffectViewModel();
                effect.Name           = hueEffectAtt.Name;
                effect.TypeName       = type.Name;
                effect.HasColorPicker = hueEffectAtt.HasColorPicker;

                if (!string.IsNullOrEmpty(hueEffectAtt.DefaultColor))
                {
                    effect.Color    = hueEffectAtt.DefaultColor;
                    effect.IsRandom = false;
                }

                if (hueEffectAtt.IsBaseEffect)
                {
                    if (!baseEffects.ContainsKey(hueEffectAtt.Group))
                    {
                        baseEffects.Add(hueEffectAtt.Group, new List <EffectViewModel>());
                    }

                    baseEffects[hueEffectAtt.Group].Add(effect);
                }
                else
                {
                    shortEffects.Add(effect);
                }
            }

            foreach (var type in groupEffectsTypes)
            {
                var hueEffectAtt = type.GetCustomAttribute <HueEffectAttribute>();
                if (hueEffectAtt == null)
                {
                    continue;
                }

                var effect = new EffectViewModel();
                effect.Name           = hueEffectAtt.Name;
                effect.TypeName       = type.Name;
                effect.HasColorPicker = hueEffectAtt.HasColorPicker;

                if (!string.IsNullOrEmpty(hueEffectAtt.DefaultColor))
                {
                    effect.Color    = hueEffectAtt.DefaultColor;
                    effect.IsRandom = false;
                }

                groupEffects.Add(effect);
            }

            List <string> iteratorNames = new List <string>();

            foreach (var name in Enum.GetNames(typeof(IteratorEffectMode)))
            {
                iteratorNames.Add(name);
            }

            List <string> secondaryIteratorNames = new List <string>()
            {
                IteratorEffectMode.All.ToString(),
                          IteratorEffectMode.AllIndividual.ToString(),
                          IteratorEffectMode.Bounce.ToString(),
                          IteratorEffectMode.Single.ToString(),
                          IteratorEffectMode.Random.ToString(),
            };

            var vm = new EffectsVM();

            vm.BaseEffects  = baseEffects;
            vm.ShortEffects = shortEffects;
            vm.GroupEffects = groupEffects;
            vm.Groups       = groups.Select(x => new GroupInfoViewModel()
            {
                Name = x.Name
            }).ToList();
            vm.IteratorModes          = iteratorNames;
            vm.SecondaryIteratorModes = secondaryIteratorNames;

            return(vm);
        }
        /// <summary>
        /// Processes the specified form.
        /// </summary>
        /// <param name="effectViewModel">The effect view model.</param>
        internal void Process(EffectViewModel effectViewModel)
        {
            TraceService.WriteLine("EffectsController::Process");

            this.VisualStudioService.WriteStatusBarMessage(NinjaMessages.NinjaIsRunning);

            try
            {
                TraceService.WriteLine("EffectsController::Process GetTextTemplates");

                IEnumerable<TextTemplateInfo> textTemplates = this.effectFactory.GetTextTemplates(
                    effectViewModel.RequestedName,
                    this.SettingsService.EffectDirectory);

                IEnumerable<string> messages = this.textTemplatingService.AddTextTemplates(
                    NinjaMessages.AddingEffect,
                    textTemplates);

                //// show the readme.
                this.ShowReadMe("Add Xamarin Forms Effect", messages);
            }
            catch (Exception exception)
            {
                TraceService.WriteError("Cannot create effect exception=" + exception.Message);
            }
        }