Esempio n. 1
0
 public void FromRouteRow(Routes.RouteRow routeRow)
 {
     if (!routeRow.IsTeamNull()) Team = Convert.ToInt32(routeRow.Team);
     if (!routeRow.IsRadiusNull()) Radius = Convert.ToInt32(routeRow.Radius);
     if (!routeRow.IsActionsNull()) Actions = routeRow.Actions;
     if (!routeRow.IsPathActionsNull()) PathActions = routeRow.PathActions;
 }
Esempio n. 2
0
        private bool IsRouteValid(Routes.RouteRow route)
        {
            try
            {
                bool isValid = true;
                StringBuilder buff = new StringBuilder();

                // validate actions
                if (route.IsActionsNull() || route.Actions.Trim().Length == 0)
                {
                    // do we need actions?
                    isValid = false;
                    buff.Append("Route " + route.ID + " has no actions defined.\r\n");
                }
                else
                {
                    // check that the actions exist
                    string[] ids = route.Actions.Split(new char[] { ' ' });

                    for (int x = 0; x < ids.Length; x++)
                    {
                        int actionID = Int32.MinValue;

                        try
                        {
                            actionID = Convert.ToInt32(ids[x]);
                        }
                        catch
                        {
                            isValid = false;
                            buff.Append("Route " + route.ID + " has an action link that is non-numeric.\r\n");
                        }

                        if (actionID != Int32.MinValue)
                        {
                            if (actionID < 0 || actionID > _actions.Action.Count - 1)
                            {
                                isValid = false;
                                buff.Append("Route " + route.ID + " is linked to action " + actionID + " which does not exist in the navigation file.\r\n");
                            }
                        }
                    }
                }

                // validate path actions
                if (route.IsPathActionsNull() || route.PathActions.Trim().Length == 0)
                {
                    // do we need path actions?
                    isValid = false;
                    buff.Append("Route " + route.ID + " has no path actions defined.\r\n");
                }
                else
                {
                    // check that the actions exist
                    string[] ids = route.PathActions.Split(new char[] { ' ' });

                    for (int x = 0; x < ids.Length; x++)
                    {
                        int actionID = Int32.MinValue;

                        try
                        {
                            actionID = Convert.ToInt32(ids[x]);
                        }
                        catch
                        {
                            isValid = false;
                            buff.Append("Route " + route.ID + " has a path action link that is non-numeric.\r\n");
                        }

                        if (actionID != Int32.MinValue)
                        {
                            if (actionID < 0 || actionID > _actions.Action.Count - 1)
                            {
                                isValid = false;
                                buff.Append("Route " + route.ID + " is linked to path action " + actionID + " which does not exist in the navigation file.\r\n");
                            }
                            else
                            {
                                Actions.ActionRow actionRow = _actions.Action[actionID];

                                // these need to be 17, alt-roams
                                switch (route.Team)
                                {
                                    case "0":
                                        if (actionRow.IsAllyActionNull() || actionRow.IsAxisActionNull())
                                        {
                                            isValid = false;
                                            buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Alternate Roam for both teams.\r\n");
                                        }
                                        else
                                        {
                                            if (actionRow.AllyAction != "17" || actionRow.AxisAction != "17")
                                            {
                                                isValid = false;
                                                buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Alternate Roam for both teams.\r\n");
                                            }
                                        }
                                        break;
                                    case "1":
                                        if (actionRow.IsAxisActionNull())
                                        {
                                            isValid = false;
                                            buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Axis Alternate Roam action.\r\n");
                                        }
                                        else
                                        {
                                            if (actionRow.AxisAction != "17")
                                            {
                                                isValid = false;
                                                buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Axis Alternate Roam action.\r\n");
                                            }
                                        }
                                        break;
                                    case "2":
                                        if (actionRow.IsAllyActionNull())
                                        {
                                            isValid = false;
                                            buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Ally Alternate Roam action.\r\n");
                                        }
                                        else
                                        {
                                            if (actionRow.AllyAction != "17")
                                            {
                                                isValid = false;
                                                buff.Append("Route " + route.ID + " is linked to a path action [" + actionID + "] that is not an Ally Alternate Roam action.\r\n");
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }

                if (!isValid)
                {
                    MessageBox.Show(this.ParentForm, buff.ToString(), "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                return isValid;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ParentForm, "Error validation route " + route.ID + ". " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }