public ActionResult DoSearch(SearchCriminalProfileViewModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            string message;

            try
            {
                //call WCF service
                SearchCriminalServiceClient wcf = new SearchCriminalServiceClient();
                var result = wcf.SearchCriminal(User.Identity.Name, model.Name, model.fromAge, model.toAge, model.fromHeight, model.toHeight, model.fromWeight, model.toWeight, model.NationalityId);
                //check if there is an error in the input or on calling the serivce
                if (result.ErrorCode == null)
                {
                    message = Constant.SuccessfulMessage;
                }
                else
                {
                    message = MappingError.getErrorMessage(result.ErrorCode);
                }

                //return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                message = ex.Message.Replace(".", "");
            }

            return(RedirectToAction("Index", "UserMessage", new { messageContent = message, backAction = "Index", backController = "SearchCriminalProfile" }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the FinishButtonClick event of the ucWizard control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.WizardNavigationEventArgs"/> instance containing the event data.</param>
        void ucWizard_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            _ir = (ImportRequest)ViewState["_ir"];
            if (_ir != null)
            {
                FillDefaultValues(dgMapping, null);
                _ir = (ImportRequest)ViewState["_ir"];
                ImportResponse irr = (ImportResponse)BusinessManager.Execute(_ir);
                MappingError[] mas = irr.Errors;
                if (mas.Length == 0)
                {
                    lblResult.Text = GetGlobalResourceObject("IbnFramework.Common", "tImportWasSuccessfull").ToString();
                }
                else
                {
                    ViewState["ErrorLog"] = MappingError.GetErrorLog(mas);
                    string sAction = String.Format("<a href=\"{1};\">{0}</a>",
                                                   GetGlobalResourceObject("IbnFramework.Common", "tErrorList").ToString(),
                                                   this.Page.ClientScript.GetPostBackClientHyperlink(lbErrorLog, String.Empty));

                    lblResult.Text = String.Format(
                        GetGlobalResourceObject("IbnFramework.Common", "tImportWithErrors").ToString(),
                        sAction);
                }
                string param = String.Empty;
                if (!String.IsNullOrEmpty(_commandName))
                {
                    param = (new CommandParameters(_commandName)).ToString();
                }
                Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterRefreshParentFromFrameScript(this.Page, param);
            }
        }
 public override Task <BindResult> BindModel(ModelBindingContext bindingContext)
 => Task.FromResult(
     BindResult.Create(
         GetValue(bindingContext)
         .Match(
             s => GetData().WithValue(s.Match(_ => _, () => (int?)null)),
             () => GetData().WithErrors(new[] { MappingError.Create("Not an Int", typeof(string), typeof(int)) })
             )
         )
     );
 public override Task <BindResult> BindModel(ModelBindingContext bindingContext)
 => Task.FromResult(
     BindResult.Create(
         GetValue(bindingContext)
         .Match(
             s => s.Match(i => GetData().WithUncheckedValue(i), () => GetData().WithNull()),
             () => GetData().WithErrors(new[] { MappingError.Create("Not an Int", typeof(string), typeof(int)) })
             )
         )
     );
Ejemplo n.º 5
0
        private void ErrorHandler(object sender, MappingEngineErrorEventArgs args)
        {
            MappingError error = args.Error;

            if (error.ErrorType == MappingErrorType.SourceValueError)
            {
                SouceValueErrorResolver(args);
            }
            else if (error.ErrorType == MappingErrorType.MetaObjectCreation)
            {
                MetaObjectCreationErrorResolver(args);
            }
            else
            {
                Trace.WriteLine(error.ErrorDescr);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks the keyboardState passed in and verifies if the command name has been inputted by the user.
        /// </summary>
        /// <param name="commandName">command name to check</param>
        /// <param name="keyStates">the keyboardState identifying what keys are pressed.</param>
        /// <returns>true if the command is being activated by the KeboardState</returns>
        public static bool CheckCommand(string commandName, KeyboardState keyStates)
        {
            LastError = MappingError.NO_ERROR;

            if (!_keyboardMap.Keys.Contains(commandName))
            {
                LastError |= MappingError.MAPPING_NOT_FOUND;
            }

            if (LastError != MappingError.NO_ERROR)
            {
                return false;
            }

            // returns true only if all keys associated with this command are down.
            return _keyboardMap[commandName].All(keys => keyStates.IsKeyDown(keys));
        }
        /// <summary>
        /// This method accepts both a partial and a full matching.
        /// The matching rules are: 1. Components can match only COMPLEX TypeNodes. 2. Parameters can match only SIMPLE TypeNodes.
        /// 3. GeometricRelationshipscan only match a NON_BINDABLE TypeNode with exactly one SubNode of COMPLEX type.
        /// </summary>
        public static void MatchStructure(Component _comp, TypeNode _tn, ref List <KeyValuePair <string, TypeNode> > correspondencies, out MappingError err)
        {
            if (correspondencies == null)
            {
                correspondencies = new List <KeyValuePair <string, TypeNode> >();
            }
            err = MappingError.NONE;

            if (_comp == null || _tn == null)
            {
                err = MappingError.MISSING_MAPPING_END;
                return;
            }

            if (_tn.BindingType == TypeNodeContentBindingType.NOT_BINDABLE ||
                _tn.BindingType == TypeNodeContentBindingType.SIMPLE)
            {
                err = MappingError.COMPONENT_TO_TYPE_MISMATCH;
                return;
            }
            if (_tn.BindingType == TypeNodeContentBindingType.KEY)
            {
                err = MappingError.NO_MAPPING_TO_ID_ALLOWED;
                return;
            }

            if (correspondencies.Where(x => x.Key == MappingComponent.PREFIX_COMP + _comp.ID.ToString()).Count() > 0)
            {
                err = MappingError.ID_DUPLICATION;
                return;
            }

            // at least top-level matching is possible
            List <KeyValuePair <string, TypeNode> > new_correspondencies = new List <KeyValuePair <string, TypeNode> >();

            new_correspondencies.Add(new KeyValuePair <string, TypeNode>(MappingComponent.PREFIX_COMP + _comp.ID.ToString(), _tn));
            bool transferred_id = false;

            if (_tn.SubNodes == null || _tn.SubNodes.Count == 0)
            {
                return;
            }

            // attempt matching of structure
            foreach (TypeNode sN in _tn.SubNodes)
            {
                if (sN.BindingType == TypeNodeContentBindingType.SIMPLE)
                {
                    // look for an existing mapping
                    bool found_existing = false;
                    if (sN.AllMappings != null && sN.AllMappings.Count > 0)
                    {
                        MappingObject mo = sN.AllMappings.FirstOrDefault(x => (x is MappingParameter) && _comp.ContainedParameters.ContainsKey((x as MappingParameter).MappedParameter.ID));
                        if (mo != null)
                        {
                            string p_key = MappingComponent.PREFIX_PARAM + (mo as MappingParameter).MappedParameter.ID.ToString();
                            if (!(correspondencies.Where(x => x.Key == p_key).Count() > 0) && !(new_correspondencies.Where(x => x.Key == p_key).Count() > 0))
                            {
                                new_correspondencies.Add(new KeyValuePair <string, TypeNode>(p_key, sN));
                            }
                            found_existing = true;
                        }
                    }
                    // try to match it to a parameter
                    if (!found_existing && _comp.ContainedParameters.Count() > 0)
                    {
                        Parameter p = _comp.ContainedParameters.FirstOrDefault(x => x.Value != null && MappingObject.StringsCouldMeanTheSame(x.Value.Name, sN.Label)).Value;
                        if (p != null)
                        {
                            string p_key = MappingComponent.PREFIX_PARAM + p.ID.ToString();
                            if (!(correspondencies.Where(x => x.Key == p_key).Count() > 0) && !(new_correspondencies.Where(x => x.Key == p_key).Count() > 0))
                            {
                                new_correspondencies.Add(new KeyValuePair <string, TypeNode>(p_key, sN));
                            }
                        }
                    }
                }
                else if (sN.BindingType == TypeNodeContentBindingType.NOT_BINDABLE)
                {
                    // try to match it to a geometric relationship
                    if (sN.IsEnumerable && sN.SubNodes != null && sN.SubNodes.Count == 1)
                    {
                        TypeNode sN_1 = sN.SubNodes[0];
                        if (sN_1.BindingType == TypeNodeContentBindingType.COMPLEX)
                        {
                            bool match_w_geometry_found = false;
                            foreach (GeometricRelationship gr in _comp.R2GInstances)
                            {
                                // get the path points as identifiable containers
                                List <HierarchicalContainer> geometry = gr.GeometricContent;
                                if (geometry.Count == 0)
                                {
                                    continue;
                                }

                                foreach (HierarchicalContainer hc in geometry)
                                {
                                    Point3DContainer p3dc = hc as Point3DContainer;
                                    if (p3dc == null)
                                    {
                                        continue;
                                    }

                                    // CHECK IF A MAPPING IS AT ALL POSSIBLE
                                    MappingError sN_1_test_err = MappingError.NONE;
                                    MappingSinglePoint.PreliminaryMapping(p3dc, _comp, sN_1, false, out sN_1_test_err);
                                    if (sN_1_test_err != MappingError.NONE)
                                    {
                                        break;
                                    }

                                    // look for an existing mapping
                                    bool found_existing = false;
                                    if (sN_1.AllMappings != null && sN_1.AllMappings.Count > 0)
                                    {
                                        MappingObject mo = sN_1.AllMappings.FirstOrDefault(x => (x is MappingSinglePoint) &&
                                                                                           (x as MappingSinglePoint).MappedPointC.ID_primary == p3dc.ID_primary && (x as MappingSinglePoint).MappedPointC.ID_secondary == p3dc.ID_secondary);
                                        if (mo != null)
                                        {
                                            string p_key = MappingComponent.PREFIX_P3DC + (mo as MappingSinglePoint).MappedPointC.ID_primary.ToString() +
                                                           "_" + (mo as MappingSinglePoint).MappedPointC.ID_secondary.ToString();
                                            if (!(correspondencies.Where(x => x.Key == p_key).Count() > 0) && !(new_correspondencies.Where(x => x.Key == p_key).Count() > 0))
                                            {
                                                new_correspondencies.Add(new KeyValuePair <string, TypeNode>(p_key, sN_1));
                                            }
                                            found_existing         = true;
                                            match_w_geometry_found = true;
                                        }
                                    }
                                    // try to create a new mapping
                                    if (!found_existing)
                                    {
                                        MappingError sN_1_m_err = MappingError.NONE;
                                        MappingSinglePoint.PreliminaryMapping(p3dc, _comp, sN_1, false, out sN_1_m_err);
                                        if (sN_1_m_err == MappingError.NONE)
                                        {
                                            // mapping successful
                                            string p_key = MappingComponent.PREFIX_P3DC + p3dc.ID_primary.ToString() +
                                                           "_" + p3dc.ID_secondary.ToString();
                                            if (!(correspondencies.Where(x => x.Key == p_key).Count() > 0) && !(new_correspondencies.Where(x => x.Key == p_key).Count() > 0))
                                            {
                                                new_correspondencies.Add(new KeyValuePair <string, TypeNode>(p_key, sN_1));
                                            }
                                            match_w_geometry_found = true;
                                        }
                                    }
                                }
                            }

                            if (!match_w_geometry_found)
                            {
                                // try to match it to a sub-component -> RECURSION
                                if (sN.SubNodes != null && sN.SubNodes.Count > 0)
                                {
                                    foreach (TypeNode ssN in sN.SubNodes)
                                    {
                                        int nr_current_correspondencies = correspondencies.Count;
                                        // attempt a matching
                                        foreach (var entry in _comp.ContainedComponents)
                                        {
                                            Component sC = entry.Value;
                                            if (sC == null)
                                            {
                                                continue;
                                            }

                                            MappingError sC_err = MappingError.NONE;
                                            MappingComponent.MatchStructure(sC, ssN, ref correspondencies, out sC_err);
                                            if (sC_err == MappingError.NONE && correspondencies.Count > nr_current_correspondencies)
                                            {
                                                // success
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (sN.BindingType == TypeNodeContentBindingType.KEY)
                {
                    // pass the ID of the component
                    string key_id = MappingComponent.PREFIX_ID + _comp.ID.ToString();
                    if (!(correspondencies.Where(x => x.Key == key_id).Count() > 0) && !(new_correspondencies.Where(x => x.Key == key_id).Count() > 0))
                    {
                        new_correspondencies.Add(new KeyValuePair <string, TypeNode>(key_id, sN));
                        transferred_id = true;
                    }
                }
                else if (sN.BindingType == TypeNodeContentBindingType.COMPLEX)
                {
                    // try to match it to a sub-component -> RECURSION
                    if (sN.SubNodes != null && sN.SubNodes.Count > 0)
                    {
                        foreach (TypeNode ssN in sN.SubNodes)
                        {
                            int nr_current_correspondencies = correspondencies.Count;
                            // attempt a matching
                            foreach (var entry in _comp.ContainedComponents)
                            {
                                Component sC = entry.Value;
                                if (sC == null)
                                {
                                    continue;
                                }

                                MappingError sC_err = MappingError.NONE;
                                MappingComponent.MatchStructure(sC, ssN, ref correspondencies, out sC_err);
                                if (sC_err == MappingError.NONE && correspondencies.Count > nr_current_correspondencies)
                                {
                                    // success
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if ((new_correspondencies.Count < 2) || (new_correspondencies.Count < 3 && transferred_id))
            {
                // only a match at the highest level -> not enough -> do not add
            }
            else
            {
                // the method traverses the component from BOTTOM to TOP
                // the mapping is performed TOP to BOTTOM -> insert at the start
                for (int i = 0; i < new_correspondencies.Count; i++)
                {
                    var entry = new_correspondencies[i];
                    correspondencies.Insert(i, new KeyValuePair <string, TypeNode>(entry.Key, entry.Value));
                }
            }
        }
        public static List <MappingObject> CreateMultipleFrom(Component _comp, TypeNode _tn, bool _as_example, List <KeyValuePair <string, TypeNode> > _correspondencies, out MappingError err)
        {
            err = MappingError.NONE;
            List <MappingObject> created_mappings = new List <MappingObject>();

            if (_comp == null || _tn == null || _correspondencies == null || _correspondencies.Count < 2)
            {
                err = MappingError.MISSING_MAPPING_END;
                return(created_mappings);
            }

            Component    current_comp = _comp;
            MappingError tmp_err      = MappingError.NONE;

            foreach (var entry in _correspondencies)
            {
                string[] key_comps = entry.Key.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                if (key_comps == null || key_comps.Length < 2)
                {
                    err = MappingError.MISSING_MAPPING_END;
                    return(created_mappings);
                }

                if ((key_comps[0] + "_") == MappingComponent.PREFIX_COMP)
                {
                    // -------------------------- COMPONENTS --------------------------- //
                    long comp_id = -1;
                    bool success = long.TryParse(key_comps[1], out comp_id);
                    if (!success)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }

                    if (comp_id != current_comp.ID)
                    {
                        // look for the component in the children of current_comp
                        List <Component> all_sub_comps = current_comp.GetFlatSubCompList();
                        Component        next          = all_sub_comps.FirstOrDefault(x => x.ID == comp_id);
                        if (next == null)
                        {
                            err = MappingError.MISSING_MAPPING_END;
                            return(created_mappings);
                        }
                        else
                        {
                            current_comp = next;
                        }
                    }
                }
                else if ((key_comps[0] + "_") == MappingComponent.PREFIX_ID)
                {
                    // ------------------------ COMPONENT IDS -------------------------- //
                    MappingString ms = MappingString.Create(current_comp, entry.Key, entry.Value, _as_example, out tmp_err);
                    if (tmp_err != MappingError.NONE)
                    {
                        err = tmp_err;
                        return(created_mappings);
                    }
                    else
                    {
                        created_mappings.Add(ms);
                    }
                }
                else if ((key_comps[0] + "_") == MappingComponent.PREFIX_PARAM)
                {
                    // -------------------------- PARAMETERS --------------------------- //
                    long param_id = -1;
                    bool success  = long.TryParse(key_comps[1], out param_id);
                    if (!success || !current_comp.ContainedParameters.ContainsKey(param_id))
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    Parameter        p  = current_comp.ContainedParameters[param_id];
                    MappingParameter mp = MappingParameter.Create(p, current_comp, entry.Value, _as_example, false, out tmp_err);
                    if (tmp_err != MappingError.NONE)
                    {
                        err = tmp_err;
                        return(created_mappings);
                    }
                    else
                    {
                        created_mappings.Add(mp);
                    }
                }
                else if ((key_comps[0] + "_") == MappingComponent.PREFIX_P3DC)
                {
                    // --------------------------- GEOMETRY ---------------------------- //
                    if (key_comps.Length < 3)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    long id_primary = -1;
                    int  id_second  = -1;
                    bool success_1  = long.TryParse(key_comps[1], out id_primary);
                    bool success_2  = int.TryParse(key_comps[2], out id_second);
                    if (!success_1 || !success_2)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    GeometricRelationship gr = current_comp.R2GInstances.FirstOrDefault(x => x.ID == id_primary);
                    if (gr == null)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }
                    Point3DContainer p3dc = gr.GeometricContent.FirstOrDefault(x => x.ID_primary == id_primary && x.ID_secondary == id_second) as Point3DContainer;
                    if (p3dc == null)
                    {
                        err = MappingError.MISSING_MAPPING_END;
                        return(created_mappings);
                    }

                    MappingSinglePoint msp = MappingSinglePoint.Create(p3dc, current_comp, entry.Value, _as_example, out tmp_err);
                    if (tmp_err != MappingError.NONE)
                    {
                        err = tmp_err;
                        return(created_mappings);
                    }
                    else
                    {
                        created_mappings.Add(msp);
                    }
                }
            }

            return(created_mappings);
        }
        public static Dictionary <string, TypeNode> PreliminaryMapping(Point3DContainer _point_container, Component _direct_parent, TypeNode _tn, bool _as_example, out MappingError err)
        {
            err = MappingError.NONE;
            if (_point_container == null || _direct_parent == null || _tn == null)
            {
                err = MappingError.MISSING_MAPPING_END;
                return(null);
            }

            // check if the mapping is possible...
            if (_tn.SubNodes == null)
            {
                err = MappingError.TOO_FEW_PARAMETERS_FOR_TYPE;
                return(null);
            }
            if (_tn.BindingType == TypeNodeContentBindingType.NOT_BINDABLE)
            {
                err = MappingError.COMPONENT_TO_TYPE_MISMATCH;
                return(null);
            }
            if (_tn.BindingType == TypeNodeContentBindingType.KEY)
            {
                err = MappingError.NO_MAPPING_TO_ID_ALLOWED;
                return(null);
            }

            if (_tn.SubNodes.Count != 3)
            {
                err = MappingError.INSTANTIATION_OF_TYPE_IMPOSSIBLE;
                return(null);
            }

            // attempt a preliminary mapping of coordinates
            Dictionary <string, TypeNode> coords_mapping = new Dictionary <string, TypeNode>()
            {
                { "x", null },
                { "y", null },
                { "z", null }
            };

            foreach (TypeNode stn in _tn.SubNodes)
            {
                if (stn.BindingType != TypeNodeContentBindingType.SIMPLE)
                {
                    err = MappingError.TOO_FEW_PARAMETERS_FOR_TYPE;
                    return(null);
                }
                if (coords_mapping["x"] == null && MappingObject.StringsCouldMeanTheSame("x", stn.Label))
                {
                    coords_mapping["x"] = stn;
                }
                else if (coords_mapping["y"] == null && MappingObject.StringsCouldMeanTheSame("y", stn.Label))
                {
                    coords_mapping["y"] = stn;
                }
                else if (coords_mapping["z"] == null && MappingObject.StringsCouldMeanTheSame("z", stn.Label))
                {
                    coords_mapping["z"] = stn;
                }
            }

            return(coords_mapping);
        }
        public static MappingSinglePoint Create(Point3DContainer _point_container, Component _direct_parent, TypeNode _tn, bool _as_example, out MappingError err)
        {
            // attempt a preliminary mapping of coordinates
            Dictionary <string, TypeNode> coords_mapping = MappingSinglePoint.PreliminaryMapping(_point_container, _direct_parent, _tn, _as_example, out err);

            if (err != MappingError.NONE)
            {
                return(null);
            }

            // perform actual mapping
            if (coords_mapping["x"] != null && coords_mapping["y"] != null && coords_mapping["z"] != null)
            {
                MappingSinglePoint msp = new MappingSinglePoint(_point_container, _direct_parent, _tn, _as_example);
                msp.coords_mapping    = coords_mapping;
                _tn.MostRecentMapping = msp;
                return(msp);
            }
            else
            {
                err = MappingError.INSTANTIATION_OF_TYPE_IMPOSSIBLE;
                return(null);
            }
        }
        public static bool PerliminaryMapping(Parameter _p, Component _direct_parent, TypeNode _tn, bool _as_example, bool _match_name, out MappingError err)
        {
            err = MappingError.NONE;
            if (_p == null || _direct_parent == null || _tn == null)
            {
                err = MappingError.MISSING_MAPPING_END;
                return(false);
            }
            // parameters can be mapped only to simple types (e.g. int)
            if (_tn.BindingType != TypeNodeContentBindingType.SIMPLE)
            {
                err = MappingError.PARAM_TO_TYPE_MISMATCH;
                return(false);
            }

            if (_match_name)
            {
                return(MappingObject.StringsCouldMeanTheSame(_p.Name, _tn.Label));
            }
            else
            {
                return(true);
            }
        }
        public static MappingParameter Create(Parameter _p, Component _direct_parent, TypeNode _tn, bool _as_example, bool _match_name, out MappingError err)
        {
            if (!(MappingParameter.PerliminaryMapping(_p, _direct_parent, _tn, _as_example, _match_name, out err)))
            {
                return(null);
            }

            MappingParameter mp = new MappingParameter(_p, _direct_parent, _tn, _as_example);

            _tn.MostRecentMapping = mp;
            return(mp);
        }
        public static bool PreliminaryMapping(Component _source, string _input, TypeNode _tn, bool _as_example, out MappingError err)
        {
            err = MappingError.NONE;
            if (_source == null || string.IsNullOrEmpty(_input) || _tn == null)
            {
                err = MappingError.MISSING_MAPPING_END;
                return(false);
            }
            // strings can be mapped only to ids
            if (_tn.BindingType != TypeNodeContentBindingType.KEY)
            {
                err = MappingError.PARAM_TO_TYPE_MISMATCH;
                return(false);
            }

            return(true);
        }
        public static MappingString Create(Component _source, string _input, TypeNode _tn, bool _as_example, out MappingError err)
        {
            if (!MappingString.PreliminaryMapping(_source, _input, _tn, _as_example, out err))
            {
                return(null);
            }

            MappingString ms = new MappingString(_source, _input, _tn, _as_example);

            _tn.MostRecentMapping = ms;
            return(ms);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Checks the Gamepad passed in and verifies if the command name has been inputted by the user.
        /// </summary>
        /// <param name="commandName">command name to check</param>
        /// <param name="buttonStates">the button combination identifying what buttons are pressed</param>
        /// <returns>true if the command is being activated by the GamePadButtons</returns>
        public static bool CheckCommand(string commandName, GamePadButtons buttonStates)
        {
            LastError = MappingError.NO_ERROR;

            if (!_controllerMap.Keys.Contains(commandName))
            {
                LastError |= MappingError.MAPPING_NOT_FOUND;
            }

            if (LastError != MappingError.NO_ERROR)
            {
                return false;
            }

            // this should return true if the buttons set in the controller map are the same as those in the buttonStates.
            return buttonStates.Equals(new GamePadButtons(_controllerMap[commandName]));
        }
Ejemplo n.º 16
0
        public static bool DeleteMapping(string commandName, MappingDevice device)
        {
            LastError = MappingError.NO_ERROR;

            if ((device == MappingDevice.KEYBOARD && !_keyboardMap.Keys.Contains(commandName)) ||
                (device == MappingDevice.CONTROLLER && _controllerMap.Keys.Contains(commandName)))
            {
                LastError |= MappingError.MAPPING_NOT_FOUND;
            }

            if (LastError != MappingError.NO_ERROR)
            {
                return false;
            }

            switch (device)
            {
                case MappingDevice.KEYBOARD:
                    _keyboardMap.Remove(commandName);
                    break;

                case MappingDevice.CONTROLLER:
                    _controllerMap.Remove(commandName);
                    break;
            }

            return true;
        }
Ejemplo n.º 17
0
 private Result <Guid, ValidationError[]> GetGuidValue(ModelBindingContext bindingContext)
 => Guid.TryParse(GetValue(bindingContext), out var guid)
                                     ? Result.Success <Guid, ValidationError[]>(guid)
                                     : Result.Failure <Guid, ValidationError[]>(new[] { MappingError.Create("Error mapping input to Guid.", typeof(string), typeof(Guid)) });
Ejemplo n.º 18
0
 private Result <Option <Guid>, ValidationError[]> GetOptionGuidValue(ModelBindingContext bindingContext)
 => GetValue(bindingContext).Match(
     some: value =>
     Guid.TryParse(value, out var guid)
                                                     ? Result.Success <Option <Guid>, ValidationError[]>(Option.Some(guid))
                                                     : Result.Failure <Option <Guid>, ValidationError[]>(new[] { MappingError.Create("Error mapping input to Guid.", typeof(string), typeof(Guid)) }),
     none: () => Result.Success <Option <Guid>, ValidationError[]>(Option.None <Guid>()));
Ejemplo n.º 19
0
        public static bool UpdateMapping(string commandName, Keys[] keys)
        {
            LastError = MappingError.NO_ERROR;

            if (!_keyboardMap.Keys.Contains(commandName))
            {
                LastError |= MappingError.MAPPING_NOT_FOUND;
            }

            if (LastError != MappingError.NO_ERROR)
            {
                return false;
            }

            _keyboardMap[commandName] = keys;

            return true;
        }
Ejemplo n.º 20
0
        public static bool UpdateMapping(string commandName, Buttons buttons)
        {
            LastError = MappingError.NO_ERROR;

            if (!_controllerMap.Keys.Contains(commandName))
            {
                LastError |= MappingError.MAPPING_NOT_FOUND;
            }

            if (LastError != MappingError.NO_ERROR)
            {
                return false;
            }

            _controllerMap[commandName] = buttons;

            return true;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Adds a new Key-set, Command-Name pair to the keyboard mapping.
        /// </summary>
        /// <param name="commandName">Command to be assigned to the key set</param>
        /// <param name="keys">Keyboard keys to map to this Command</param>
        /// <returns>True if the mapping was added successfully</returns>
        public static bool AddMapping(string commandName, Keys[] keys)
        {
            LastError = MappingError.NO_ERROR;

            if (_keyboardMap.Keys.Contains(commandName))
            {
                LastError |= MappingError.NAME_ALREADY_EXISTS;
            }

            if (!AllowBridgedCommands && _controllerMap.Keys.Contains(commandName))
            {
                LastError |= MappingError.KEY_ALREADY_MAPPED_ON_CONTROLLER;
            }

            if (!AllowDuplicateCommands && _keyboardMap.Values.Contains(keys))
            {
                LastError |= MappingError.DUPLICATES_NOT_ALLOWED;
            }

            if (LastError != MappingError.NO_ERROR)
            {
                return false;
            }

            _keyboardMap.Add(commandName, keys);
            return true;
        }