Пример #1
0
        public UIElement GetAddElement()
        {
            UIElement element = null;

            using (ISportService service = factory.CreateSportService())
            {
                DataServiceMessage <IEnumerable <string> > serviceMessage = service.GetAll();
                RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message);

                if (serviceMessage.IsSuccessful)
                {
                    IEnumerable <string> sports = serviceMessage.Data;
                    element = Add(sports);
                }
                else
                {
                    List <ServiceMessage> messages = new List <ServiceMessage>()
                    {
                        serviceMessage
                    };

                    ErrorViewModel viewModel = new ErrorViewModel(messages);
                    ErrorControl   control   = new ErrorControl(viewModel);

                    element = control;
                }
            }

            return(element);
        }
Пример #2
0
        public UIElement GetClientAnalysisElement()
        {
            UIElement element = null;

            using (IAnalysisService service = factory.CreateAnalysisService())
            {
                DataServiceMessage <IEnumerable <ClientAnalysisDTO> > serviceMessage = service.GetClientAnalysis();
                RaiseReceivedMessageEvent(serviceMessage);

                if (serviceMessage.IsSuccessful)
                {
                    ClientAnalysisViewModel viewModel = new ClientAnalysisViewModel(serviceMessage.Data);
                    ClientAnalysisControl   control   = new ClientAnalysisControl(viewModel);

                    element = control;
                }
                else
                {
                    List <ServiceMessage> messages = new List <ServiceMessage>()
                    {
                        serviceMessage
                    };

                    ErrorViewModel viewModel = new ErrorViewModel(messages);
                    ErrorControl   control   = new ErrorControl(viewModel);

                    element = control;
                }
            }

            return(element);
        }
Пример #3
0
        public Service(ServiceInfo serviceInfo)
        {
            logger = LogManager.GetCurrentClassLogger();

            svcMain        = InitializeService;
            svcCtrlHandler = SvcControlHandler;

            serviceName   = serviceInfo.ServiceName;
            displayName   = serviceInfo.DisplayName;
            binaryPath    = serviceInfo.BinaryPath;
            serviceArgs   = serviceInfo.ServiceArgs;
            username      = serviceInfo.Username;
            password      = serviceInfo.Password;
            serviceType   = serviceInfo.ServiceType;
            startType     = serviceInfo.StartType;
            errorSeverity = serviceInfo.ErrorSeverity;
            startHandler  = serviceInfo.StartHandler;
            stopHandler   = serviceInfo.StopHandler;

            serviceCheckPoint                   = 1;
            svcStatus                           = new ServiceStatus();
            svcStatus.dwServiceType             = (uint)serviceType;
            svcStatus.dwServiceSpecificExitCode = 0;
            hSvcStatus                          = IntPtr.Zero;
        }
Пример #4
0
        public static void ShowError(this Window window, string header, string message, Action <ErrorControl> callback, Brush headerBackground = null)
        {
            window.Dispatcher.Invoke(() =>
            {
                var panel = window.Content as Panel;
                if (panel == null)
                {
                    return;
                }
                var errorControl = new ErrorControl
                {
                    ErrorHeader  = header,
                    ErrorMessage = message,
                };

                Grid.SetColumnSpan(errorControl, 99);
                Grid.SetRowSpan(errorControl, 99);

                if (callback != null)
                {
                    errorControl.CloseClick += callback;
                }
                if (headerBackground != null)
                {
                    errorControl.ErrorHeaderBackground = headerBackground;
                }

                panel.Children.Add(errorControl);
            });
        }
Пример #5
0
        protected void mvConference_ActiveViewChanged(object sender, EventArgs e)
        {
            MultiView mv = (MultiView)sender;

            switch (mv.ActiveViewIndex)
            {
            case 0:    //Start

                break;

            case 1:    //Wait
                WaitScreen.IncidentId = incidentId;
                WaitScreen.Start();
                break;

            case 2:    //Connect
                LiveConnect.IncidentId = incidentId;
                LiveConnect.Start();
                break;

            case 3:    //Survey
                Survey.IncidentId = incidentId;
                Survey.Start();
                break;

            case 4:    //Error
                ErrorControl.Start();
                break;

            default:
                break;
            }

            upPage.Update();
        }
Пример #6
0
        public UIElement GetAddElement()
        {
            UIElement element = null;

            DataServiceMessage <IEnumerable <string> > sportServiceMessage;
            DataServiceMessage <IEnumerable <TournamentDisplayDTO> >     tournamentServiceMessage;
            DataServiceMessage <IEnumerable <ParticipantTournamentDTO> > participantServiceMessage;

            using (ITournamentService service = factory.CreateTournamentService())
            {
                tournamentServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(tournamentServiceMessage.IsSuccessful, tournamentServiceMessage.Message);
            }
            using (ISportService service = factory.CreateSportService())
            {
                sportServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(sportServiceMessage.IsSuccessful, sportServiceMessage.Message);
            }
            using (IParticipantService service = factory.CreateParticipantService())
            {
                participantServiceMessage = service.GetAllWithTournaments();
                RaiseReceivedMessageEvent(sportServiceMessage.IsSuccessful, sportServiceMessage.Message);
            }

            if (tournamentServiceMessage.IsSuccessful && sportServiceMessage.IsSuccessful && participantServiceMessage.IsSuccessful)
            {
                IEnumerable <string> sports = sportServiceMessage.Data;
                IEnumerable <TournamentDisplayDTO>     tournamentDisplayDTOs     = tournamentServiceMessage.Data;
                IEnumerable <ParticipantTournamentDTO> participantTournamentDTOs = participantServiceMessage.Data;

                IEnumerable <TournamentBaseModel> tournamentBaseModels = tournamentDisplayDTOs
                                                                         .Select(t => Mapper.Map <TournamentDisplayDTO, TournamentBaseModel>(t))
                                                                         .ToList();
                IEnumerable <ParticipantTournamentModel> participantTournamentModels = participantTournamentDTOs
                                                                                       .Select(p => Mapper.Map <ParticipantTournamentDTO, ParticipantTournamentModel>(p))
                                                                                       .ToList();

                element = Add(sports, tournamentBaseModels, participantTournamentModels);
            }
            else
            {
                List <ServiceMessage> messages = new List <ServiceMessage>()
                {
                    sportServiceMessage,
                    tournamentServiceMessage,
                    participantServiceMessage
                };

                ErrorViewModel viewModel = new ErrorViewModel(messages);
                ErrorControl   control   = new ErrorControl(viewModel);

                element = control;
            }

            return(element);
        }
Пример #7
0
        protected void ControlDeError(Exception ex)
        {
            ErrorControl eC = new ErrorControl();

            eC.ErrorUsuario         = usuario;
            eC.ErrorDateTime        = DateTime.Now;
            eC.ErrorException       = ex;
            Session["ErrorControl"] = eC;
            RadAjaxManager1.ResponseScripts.Add("openOutSide('ErrorForm.aspx','ErrorForm');");
        }
Пример #8
0
        void ShowError(string message)
        {
            ShowMessage("Your fingerprint cannot be verified.");

            ErrorControl FailedVerificationControl = new ErrorControl(message);

            FailedVerificationControl.StateNotifyer   = _ApplicationStateChangeNotifyer;
            FailedVerificationControl.MessageNotifyer = _ApplicationMessageNotifyer;

            AddControl(FailedVerificationControl);
        }
Пример #9
0
        public UIElement GetAddElement()
        {
            UIElement element = null;

            DataServiceMessage <IEnumerable <string> > sportServiceMessage;
            DataServiceMessage <IEnumerable <TournamentDisplayDTO> > tournamentServiceMessage;
            DataServiceMessage <IEnumerable <EventDisplayDTO> >      eventServiceMessage;

            using (ISportService service = factory.CreateSportService())
            {
                sportServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(sportServiceMessage.IsSuccessful, sportServiceMessage.Message);
            }
            using (ITournamentService service = factory.CreateTournamentService())
            {
                tournamentServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(sportServiceMessage.IsSuccessful, sportServiceMessage.Message);
            }
            using (IEventService service = factory.CreateEventService())
            {
                eventServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(sportServiceMessage.IsSuccessful, sportServiceMessage.Message);
            }

            if (sportServiceMessage.IsSuccessful && tournamentServiceMessage.IsSuccessful && eventServiceMessage.IsSuccessful)
            {
                IEnumerable <TournamentBaseDTO> tournamentDTOs = tournamentServiceMessage.Data.AsEnumerable <TournamentBaseDTO>();
                IEnumerable <EventBaseDTO>      eventDTOs      = eventServiceMessage.Data.AsEnumerable <EventBaseDTO>();

                IEnumerable <string> sports = sportServiceMessage.Data;
                IEnumerable <TournamentBaseModel> tournaments = tournamentDTOs
                                                                .Select(t => Mapper.Map <TournamentBaseDTO, TournamentBaseModel>(t));
                IEnumerable <EventBaseModel> events = eventDTOs
                                                      .Select(e => Mapper.Map <EventBaseDTO, EventBaseModel>(e));

                element = Add(sports, tournaments, events);
            }
            else
            {
                List <ServiceMessage> messages = new List <ServiceMessage>()
                {
                    sportServiceMessage,
                    tournamentServiceMessage,
                    eventServiceMessage
                };

                ErrorViewModel viewModel = new ErrorViewModel(messages);
                ErrorControl   control   = new ErrorControl(viewModel);

                element = control;
            }

            return(element);
        }
Пример #10
0
 public static extern bool ChangeServiceConfig
 (
     ServiceHandle serviceHandle,
     ServiceType serviceType,
     ServiceStartType startType,
     ErrorControl errorControl,
     string binaryPathName,
     string loadOrderGroup,
     uint tagId,
     StringBuilder dependencies,
     string serviceUsername,
     IntPtr serviceassword,
     string displayName
 );
Пример #11
0
 internal static extern IntPtr CreateServiceW(
     IntPtr serviceControlManager,
     string serviceName,
     string displayName,
     uint desiredControlAccess,
     ServiceType serviceType,
     StartType startType,
     ErrorControl errorSeverity,
     string binaryPath,
     string loadOrderGroup,
     IntPtr outUIntTagId,
     string dependencies,
     string serviceUserName,
     string servicePassword);
Пример #12
0
    protected void ControlDeError(Exception ex)
    {
        ErrorControl eC = new ErrorControl();

        eC.ErrorUsuario = Usuario;
        eC.ErrorProcess = new Proceso()
        {
            Nombre = "DIR", Descripcion = "Direccion"
        };
        eC.ErrorDateTime        = DateTime.Now;
        eC.ErrorException       = ex;
        Session["ErrorControl"] = eC;
        RadAjaxManager1.ResponseScripts.Add("openOutSide('ErrorForm.aspx','ErrorForm');");
    }
Пример #13
0
        internal static ContentView RegisterControl(ViewControlBase control)
        {
            //-- #1: cast
            ErrorControl errorControl = null;
            FieldControl fieldControl = control as FieldControl;

            if (fieldControl == null)
            {
                errorControl = control as ErrorControl;
            }

            //-- #2: get ContentView
            Control parent = control.Parent;

            while (parent != null && !(parent is ContentView))
            {
                parent = parent.Parent;
            }
            ContentView view = (parent as ContentView);

            //-- #3: there is not a ContentView in the parent axis: exception
            if (view == null)
            {
                if (fieldControl != null)
                {
                    throw new ApplicationException(String.Concat("Control did not find the ContentView. Control type: ", control.GetType().FullName, ", Id: '", control.ID, "', FieldName: '", fieldControl.FieldName, "'"));
                }
                throw new ApplicationException(String.Concat("Control did not find the ContentView. Control type: ", control.GetType().FullName, ", Id: '", control.ID));
            }

            //-- #4 finish if GenericFieldControl or others
            if (fieldControl == null && errorControl == null)
            {
                return(view);
            }

            //-- #5 register by type
            if (errorControl != null)
            {
                view.RegisterErrorControl(errorControl);
            }
            else
            {
                view.RegisterFieldControl(fieldControl);
            }

            //-- #6 introduce the view to caller
            return(view);
        }
Пример #14
0
 public static extern ServiceHandle CreateService
 (
     ServiceControlManager serviceControlManager,
     string serviceName,
     string displayName,
     ServiceAccessRights desiredAccess,
     ServiceType serviceType,
     ServiceStartType startType,
     ErrorControl errorControl,
     string binaryPathName,
     string loadOrderGroup,
     uint tagId,
     StringBuilder dependencies,
     string serviceUsername,
     IntPtr servicePassword
 );
Пример #15
0
 protected void LoadData()
 {
     if (Session["ErrorControl"] != null)
     {
         ErrorControl errorControl = (ErrorControl)Session["ErrorControl"];
         txtFechaHora.Text = String.Format("{0:dd/MM/yyyy hh:mm:sss}", errorControl.ErrorDateTime);
         txtProceso.Text   = errorControl.ErrorProcess.Descripcion;
         txtUsuario.Text   = errorControl.ErrorUsuario.Nombre;
         txtError.Text     = errorControl.ErrorException.Message;
         RadAjaxManager1.ResponseScripts.Add("resizeWindow();");
     }
     else
     {
         txtError.Text = "NO ERROR TO CONTROL";
     }
 }
Пример #16
0
        private void TimerOnTick(object sender, EventArgs eventArgs)
        {
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                if (control == null)
                {
                    control = new ErrorControl();
                }

                popup.Child  = control;
                popup.IsOpen = true;

                control.ErrorText       = AppResources.ErrorPopupText;
                control.buttonOk.Click += (s, args) =>
                {
                    popup.IsOpen = false;
                    popup.Child  = null;
                };
            }
        }
Пример #17
0
        public UIElement GetAddElement()
        {
            UIElement element = null;

            DataServiceMessage <IEnumerable <string> > countryServiceMessage;
            DataServiceMessage <IEnumerable <string> > sportServiceMessage;

            using (ICountryService service = factory.CreateCountryService())
            {
                countryServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(countryServiceMessage.IsSuccessful, countryServiceMessage.Message);
            }
            using (ISportService service = factory.CreateSportService())
            {
                sportServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(sportServiceMessage.IsSuccessful, sportServiceMessage.Message);
            }

            if (countryServiceMessage.IsSuccessful && sportServiceMessage.IsSuccessful)
            {
                IEnumerable <string> countries = countryServiceMessage.Data;
                IEnumerable <string> sports    = sportServiceMessage.Data;

                element = Create(countries, sports);
            }
            else
            {
                List <ServiceMessage> messages = new List <ServiceMessage>()
                {
                    countryServiceMessage,
                    sportServiceMessage
                };

                ErrorViewModel viewModel = new ErrorViewModel(messages);
                ErrorControl   control   = new ErrorControl(viewModel);

                element = control;
            }

            return(element);
        }
Пример #18
0
        public UIElement GetAccountElement()
        {
            DataServiceMessage <ClientEditDTO> serviceMessage;

            using (IClientService service = factory.CreateClientService())
            {
                serviceMessage = service.GetClientInfo(login);
                RaiseReceivedMessageEvent(serviceMessage);
            }

            UIElement element = null;

            if (serviceMessage.IsSuccessful)
            {
                ClientEditModel     client    = Mapper.Map <ClientEditDTO, ClientEditModel>(serviceMessage.Data);
                ClientInfoViewModel viewModel = GetClientInfoViewModel(client);
                ClientInfoControl   control   = new ClientInfoControl(viewModel);

                viewModel.ClientEdited += (s, e) => Edit(e.Client);

                element = control;
            }
            else
            {
                List <ServiceMessage> messages = new List <ServiceMessage>()
                {
                    serviceMessage
                };

                ErrorViewModel viewModel = new ErrorViewModel(messages);
                ErrorControl   control   = new ErrorControl(viewModel);

                element = control;
            }

            return(element);
        }
Пример #19
0
 public static extern IntPtr CreateService(IntPtr hSCManager,
                                           string lpServiceName, string lpDisplayName,
                                           ServiceAccessRights dwDesiredAccess, ServiceType dwServiceType,
                                           StartType dwStartType, ErrorControl dwErrorControl,
                                           string lpBinaryPathName, string lpLoadOrderGroup, string lpdwTagId,
                                           string lpDependencies, string lpServiceStartName, string lpPassword);
Пример #20
0
        public bool RecordContextInStringTable(Dictionary <Type, Dictionary <string, ParsingContext> > objectTable, object?key, ErrorControl errorControl)
        {
            if (key is not string KeyString)
            {
                return(Program.ReportFailure($"Key '{key}' was expected to be a string"));
            }

            if (!objectTable.ContainsKey(ObjectType))
            {
                objectTable.Add(ObjectType, new Dictionary <string, ParsingContext>());
            }

            Dictionary <string, ParsingContext> KeyTable = objectTable[ObjectType];

            if (KeyTable.ContainsKey(KeyString))
            {
                if (errorControl == ErrorControl.IgnoreIfFound)
                {
                    return(true);
                }

                if (KeyString == "CorpseActionSkillExt")
                {
                    KeyTable[KeyString] = this;
                    return(true);
                }

                return(Program.ReportFailure($"Key '{KeyString}' already used for type '{ObjectType}'"));
            }

            KeyTable.Add(KeyString, this);

            return(true);
        }
Пример #21
0
        public UIElement GetAddElement()
        {
            DataServiceMessage <string> bookmakerServiceMessage;
            DataServiceMessage <IEnumerable <ClientDisplayDTO> >      clientServiceMessage;
            DataServiceMessage <IEnumerable <string> >                sportServiceMessage;
            DataServiceMessage <IEnumerable <TournamentDisplayDTO> >  tournamentServiceMessage;
            DataServiceMessage <IEnumerable <EventDisplayDTO> >       eventServiceMessage;
            DataServiceMessage <IEnumerable <CoefficientDisplayDTO> > coefficientServiceMessage;

            using (IBookmakerService service = factory.CreateBookmakerService())
            {
                bookmakerServiceMessage = service.GetLoggedInBookmakersPhoneNumber();
                RaiseReceivedMessageEvent(bookmakerServiceMessage);
            }
            using (IClientService service = factory.CreateClientService())
            {
                clientServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(clientServiceMessage);
            }
            using (ISportService service = factory.CreateSportService())
            {
                sportServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(sportServiceMessage);
            }
            using (ITournamentService service = factory.CreateTournamentService())
            {
                tournamentServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(tournamentServiceMessage);
            }
            using (IEventService service = factory.CreateEventService())
            {
                eventServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(eventServiceMessage);
            }
            using (ICoefficientService service = factory.CreateCoefficientService())
            {
                coefficientServiceMessage = service.GetAll();
                RaiseReceivedMessageEvent(coefficientServiceMessage);
            }

            bool success =
                bookmakerServiceMessage.IsSuccessful &&
                clientServiceMessage.IsSuccessful &&
                sportServiceMessage.IsSuccessful &&
                tournamentServiceMessage.IsSuccessful &&
                eventServiceMessage.IsSuccessful &&
                coefficientServiceMessage.IsSuccessful;

            UIElement element;

            if (success)
            {
                string bookmakerPhoneNumber = bookmakerServiceMessage.Data;
                IEnumerable <ClientDisplayModel> clients = clientServiceMessage
                                                           .Data
                                                           .Select(client => Mapper.Map <ClientDisplayDTO, ClientDisplayModel>(client));
                IEnumerable <string> sports = sportServiceMessage.Data;
                IEnumerable <TournamentDisplayModel> tournaments = tournamentServiceMessage
                                                                   .Data
                                                                   .Select(tournament => Mapper.Map <TournamentDisplayDTO, TournamentDisplayModel>(tournament));
                IEnumerable <EventDisplayModel> events = eventServiceMessage
                                                         .Data
                                                         .Select(_event => Mapper.Map <EventDisplayDTO, EventDisplayModel>(_event));
                IEnumerable <CoefficientDisplayModel> coefficients = coefficientServiceMessage
                                                                     .Data
                                                                     .Select(coefficient => Mapper.Map <CoefficientDisplayDTO, CoefficientDisplayModel>(coefficient));

                element = Add(bookmakerPhoneNumber, clients, sports, tournaments, events, coefficients);
            }
            else
            {
                List <ServiceMessage> messages = new List <ServiceMessage>()
                {
                    bookmakerServiceMessage,
                    clientServiceMessage,
                    sportServiceMessage,
                    tournamentServiceMessage,
                    eventServiceMessage,
                    coefficientServiceMessage
                };

                ErrorViewModel viewModel = new ErrorViewModel(messages);
                ErrorControl   control   = new ErrorControl(viewModel);

                element = control;
            }

            return(element);
        }
Пример #22
0
 private System.Web.UI.Control ParseControl(out bool parseError)
 {
     string outerHTML = this._element.GetOuterHTML();
     System.Web.UI.Control control = null;
     parseError = false;
     try
     {
         object[] pvars = new object[1];
         this._element.GetAttribute("runat", 0, pvars);
         if (string.Compare(pvars[0].ToString(), 0, "server", 0, 6, true, CultureInfo.InvariantCulture) != 0)
         {
             throw new Exception(string.Format("{0} is missing the runat=\"server\" attribute.", this._element.GetTagName()));
         }
         control = ControlParser.ParseControl(this._designerHost, outerHTML);
     }
     catch (Exception exception)
     {
         control = new ErrorControl(((Interop.IHTMLElement2) this._element).GetScopeName() + ":" + this._element.GetTagName(), exception);
         parseError = true;
     }
     return control;
 }
Пример #23
0
 private void HandleError(Exception exception)
 {
     ErrorControl.Report(exception);
     EventLogProvider.LogException("Facebook integration", "MappingEditorPage", exception);
 }
        private static bool TryParse(string stringValue, Dictionary <T, string>?stringMap, T defaultValue, T emptyValue, out T enumValue, ErrorControl errorControl)
        {
            enumValue = defaultValue;

            bool[] ParsedEnums;
            if (!StringToEnumConversion.KnownParsedEnumtable.ContainsKey(typeof(T)))
            {
                string[] EnumNames = Enum.GetNames(typeof(T));
                ParsedEnums = new bool[EnumNames.Length];
                StringToEnumConversion.KnownParsedEnumtable.Add(typeof(T), ParsedEnums);
            }
            else
            {
                ParsedEnums = StringToEnumConversion.KnownParsedEnumtable[typeof(T)];
            }

            int EnumIndex;

            if (stringValue.Length == 0 && emptyValue != null && !emptyValue.Equals(defaultValue) && TryFindIndex(emptyValue, out EnumIndex))
            {
                ParsedEnums[EnumIndex] = true;
                enumValue = emptyValue;
                return(true);
            }

            if (TryParseEnum(stringValue, out enumValue, out EnumIndex))
            {
                ParsedEnums[EnumIndex] = true;
                return(true);
            }

            if (stringMap != null)
            {
                foreach (KeyValuePair <T, string> Entry in stringMap)
                {
                    if (stringValue == Entry.Value)
                    {
                        enumValue = Entry.Key;
                        if (TryFindIndex(enumValue, out EnumIndex))
                        {
                            ParsedEnums[EnumIndex] = true;
                        }

                        return(true);
                    }
                }
            }

            if (errorControl == ErrorControl.Normal)
            {
                if (!StringToEnumConversion.MissingEnumTable.ContainsKey(typeof(T)))
                {
                    StringToEnumConversion.MissingEnumTable.Add(typeof(T), new List <string>());
                }

                List <string> MissingEnumList = StringToEnumConversion.MissingEnumTable[typeof(T)];
                if (!MissingEnumList.Contains(stringValue))
                {
                    MissingEnumList.Add(stringValue);
                }

                return(true);
            }

            string Warning = $"Enum '{stringValue}' not found for {typeof(T)}";

            return(Program.ReportFailure(Warning, errorControl));
        }
Пример #25
0
        private static bool SetItemByIntKey(Dictionary <Type, Dictionary <int, ParsingContext> > table, Action <T> setter, object value, ErrorControl errorControl)
        {
            if (!(value is int ValueId))
            {
                return(Program.ReportFailure($"Value '{value}' was expected to be an Id"));
            }

            Type LinkType = typeof(T);

            if (!table.ContainsKey(LinkType))
            {
                return(Program.ReportFailure($"Type {LinkType} does not have items with keys"));
            }

            Dictionary <int, ParsingContext> KeyTable = table[LinkType];

            if (!KeyTable.ContainsKey(ValueId))
            {
                return(Program.ReportFailure($"Key '{ValueId}' is not a known key", errorControl));
            }

            if (!(KeyTable[ValueId].Item is T AsLink))
            {
                return(Program.ReportFailure($"Key '{ValueId}' was found but for the wrong object type"));
            }

            setter(AsLink);
            return(true);
        }
Пример #26
0
 public static bool SetItemByKey(Action <T> setter, object value, ErrorControl errorControl = ErrorControl.Normal)
 {
     return(SetItemByStringKey(ParsingContext.ObjectKeyTable, setter, value, errorControl));
 }
Пример #27
0
        public static bool SetNpcNoZone(Action <PgNpcLocation> setter, MapAreaName areaName, string npcId, string parsedFile, string parsedKey, ErrorControl errorControl)
        {
            PgNpc      ParsedNpc = null !;
            SpecialNpc NpcEnum   = SpecialNpc.Internal_None;
            string     NpcName   = string.Empty;

            PgNpcLocation NpcLocation = new PgNpcLocation();

            NpcLocation.NpcId = npcId;

            if (Inserter <PgNpc> .SetItemByKey((PgNpc valueNpc) => ParsedNpc = valueNpc, npcId, ErrorControl.IgnoreIfNotFound))
            {
                NpcLocation.Npc_Key = ParsedNpc.Key;
            }
            else if (StringToEnumConversion <SpecialNpc> .TryParse(npcId, out NpcEnum, ErrorControl.IgnoreIfNotFound))
            {
                NpcLocation.NpcEnum = NpcEnum;
            }
            else if (npcId.ToUpper().StartsWith("NPC_"))
            {
                NpcLocation.NpcName = npcId.Substring(4);
            }
            else
            {
                return(Program.ReportFailure(parsedFile, parsedKey, $"'{npcId}' unknown NPC name", errorControl));
            }

            ParsingContext.AddSuplementaryObject(NpcLocation);

            Debug.Assert(!string.IsNullOrEmpty(NpcLocation.NpcId));
            Debug.Assert(NpcLocation.Npc_Key != null || NpcLocation.NpcEnum != SpecialNpc.Internal_None || NpcLocation.NpcName.Length > 0);

            setter(NpcLocation);
            return(true);
        }
Пример #28
0
        public static bool SetNpcWithZone(Action <PgNpcLocation> setter, string rawMapName, string npcId, string parsedFile, string parsedKey, ErrorControl errorControl)
        {
            Debug.Assert(!string.IsNullOrEmpty(npcId));

            if (!rawMapName.StartsWith("Area"))
            {
                return(Program.ReportFailure(parsedFile, parsedKey, $"'{rawMapName}' does not contain an area name", errorControl));
            }

            string AreaName = rawMapName.Substring(4);

            if (!StringToEnumConversion <MapAreaName> .TryParse(AreaName, out MapAreaName ParsedAreaName))
            {
                return(false);
            }

            return(SetNpcNoZone(setter, ParsedAreaName, npcId, parsedFile, parsedKey, errorControl));
        }
Пример #29
0
        public static bool SetNpc(Action <PgNpcLocation> setter, object value, string parsedFile, string parsedKey, ErrorControl errorControl = ErrorControl.Normal)
        {
            if (!(value is string ValueName))
            {
                return(Program.ReportFailure(parsedFile, parsedKey, $"Value '{value}' was expected to be a string"));
            }

            if (ValueName.Length == 0)
            {
                return(true);
            }

            string[] AreaNpc = ValueName.Split('/');
            switch (AreaNpc.Length)
            {
            case 1:
                return(SetNpcNoZone(setter, MapAreaName.Internal_None, ValueName, parsedFile, parsedKey, errorControl));

            case 2:
                return(SetNpcWithZone(setter, AreaNpc[0], AreaNpc[1], parsedFile, parsedKey, errorControl));

            default:
                return(Program.ReportFailure(parsedFile, parsedKey, $"'{value}' is not a NPC name", errorControl));
            }
        }
        public static bool TryParse(string stringValue, out T enumValue, ErrorControl errorControl = ErrorControl.Normal)
        {
            Dictionary <T, string>?stringMap = EnumStringMap.Tables.ContainsKey(typeof(T)) ? (Dictionary <T, string>)EnumStringMap.Tables[typeof(T)] : null;

            return(TryParse(stringValue, stringMap, default(T) !, default(T) !, out enumValue, errorControl));
        }
Пример #31
0
 internal void RegisterErrorControl(ErrorControl errorControl)
 {
     _errorControls.Add(errorControl);
 }