public static ListOutputType1 ListPeriod(ListPeriodInputType input, string appToken, string userToken, SourceUsageOrder sourceUsageOrder) { var facade = new ListPeriodLookupFacadeMethodInfo() { ApplicationToken = appToken, UserToken = userToken, Input = new PeriodLookupInput() { UUIDs = input.UUID, EffectDateFrom = input.VirkningFraDato, EffectDateTo = input.VirkningTilDato, SourceUsageOrder = sourceUsageOrder } }; ListOutputType1 result = GetMethodOutput <ListOutputType1, LaesResultatType[]>(facade); string[] emptyRecords = ValidateResults(result.LaesResultat); CprBroker.Engine.Local.Admin.LogFormattedSuccess("# of empty records: {0}", emptyRecords.Length); if (emptyRecords.Length == 0) { result.StandardRetur = StandardReturType.OK(); } else { result.StandardRetur = StandardReturType.NoContent(emptyRecords); } return(result); }
public override StandardReturType ValidateInput() { if (Input == null) { return(StandardReturType.NullInput()); } foreach (var dp in Input) { if (dp == null || string.IsNullOrEmpty(dp.TypeName) || dp.Attributes == null) { return(StandardReturType.NullInput()); } var dataProvider = Reflection.CreateInstance <IExternalDataProvider>(dp.TypeName); if (dataProvider == null) { return(StandardReturType.UnknownObject(dp.TypeName)); } var propNames = dataProvider.ConfigurationKeys; foreach (var propInfo in propNames) { var propName = propInfo.Name; var prop = dp.Attributes.FirstOrDefault(p => p.Name.ToLower() == propName.ToLower()); if (prop == null || (propInfo.Required && string.IsNullOrEmpty(prop.Value))) { return(StandardReturType.NullInput(propName)); } } } return(StandardReturType.OK()); }
public static LaesOutputType ReadPeriod(LaesPeriodInputType input, string appToken, string userToken, SourceUsageOrder sourceUsageOrder) { var facade = new ReadPeriodLookupFacadeMethodInfo() { ApplicationToken = appToken, UserToken = userToken, Input = new PeriodLookupInput() { UUIDs = new string[] { input.UUID }, EffectDateFrom = input.VirkningFraDato, EffectDateTo = input.VirkningTilDato, SourceUsageOrder = sourceUsageOrder } }; LaesOutputType result = GetMethodOutput <LaesOutputType, LaesResultatType>(facade); if (IsValidateResult(result.LaesResultat)) { result.StandardRetur = StandardReturType.OK(); } else { result.StandardRetur = StandardReturType.NoContent(new string[] { ((FiltreretOejebliksbilledeType)result.LaesResultat.Item).UUID }); } return(result); }
public static ListOutputType1 ListAtTime(ListOejebliksbilledeInputType input, string appToken, string userToken, SourceUsageOrder sourceUsageOrder) { var facade = new ListPeriodLookupFacadeMethodInfo() { ApplicationToken = appToken, UserToken = userToken, Input = new PeriodLookupInput() { UUIDs = input.UUID, EffectDateFrom = input.VirkningDato, EffectDateTo = input.VirkningDato, SourceUsageOrder = sourceUsageOrder } }; ListOutputType1 result = GetMethodOutput <ListOutputType1, LaesResultatType[]>(facade); String[] emptyRecords = ValidateResults(result.LaesResultat); if (emptyRecords.Length == 0) { result.StandardRetur = StandardReturType.OK(); } else { result.StandardRetur = StandardReturType.NoContent(emptyRecords); } return(result); }
public static StandardReturType Validate <TOutput, TItem>(FacadeMethodInfo <TOutput, TItem> facade) where TOutput : class, IBasicOutput <TItem>, new() { // Initialize context try { BrokerContext.Initialize(facade.ApplicationToken, facade.UserToken); } catch (Exception ex) { return(StandardReturType.InvalidApplicationToken(facade.ApplicationToken)); } // Validate StandardReturType validationRet = facade.ValidateInput(); if (!StandardReturType.IsSucceeded(validationRet)) { Local.Admin.AddNewLog(TraceEventType.Error, BrokerContext.Current.WebMethodMessageName, TextMessages.InvalidInput, null, null); if (validationRet == null) { validationRet = StandardReturType.UnspecifiedError("Validation failed"); } return(validationRet); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (MaxCount <= 0 || MaxCount > 10000) { return(StandardReturType.ValueOutOfRange(MaxCount)); } return(StandardReturType.OK()); }
public StandardReturType CreateDataProviders(ProviderMethod <TInputElement, TOutputElement, Element, object, TInterface> providerMethod, out IEnumerable <TInterface> dataProviders) { dataProviders = providerMethod.CreateDataProviders(this.LocalDataProviderOption); if (dataProviders == null || dataProviders.FirstOrDefault() == null) { Local.Admin.AddNewLog(TraceEventType.Warning, BrokerContext.Current.WebMethodMessageName, TextMessages.NoDataProvidersFound, null, null); return(StandardReturType.Create(HttpErrorCode.DATASOURCE_UNAVAILABLE)); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { var channelValidationResult = ValidateChannel(NotificationChannel); if (!StandardReturType.IsSucceeded(channelValidationResult)) { return(channelValidationResult); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (string.IsNullOrEmpty(string.Format("{0}", ApplicationName).Trim())) { return(StandardReturType.NullInput()); } if (Data.Applications.Application.NameExists(ApplicationName)) { return(StandardReturType.ApplicationNameExists(ApplicationName)); } return(StandardReturType.OK()); }
public static TOutput AggregateResults <TOutput, TItem>(FacadeMethodInfo <TOutput, TItem> facade, SubMethodRunState[] subMethodRunStates) where TOutput : class, IBasicOutput <TItem>, new() { #region Final aggregation var succeededCount = (from mi in subMethodRunStates where mi.Succeeded select mi).Count(); var subResults = (from mi in subMethodRunStates select mi.Result).ToArray(); bool canAggregate = facade.AggregationFailOption == AggregationFailOption.FailNever || facade.AggregationFailOption == AggregationFailOption.FailOnAll && succeededCount > 0 || facade.AggregationFailOption == AggregationFailOption.FailOnAny && succeededCount == subMethodRunStates.Length; if (canAggregate) { var outputMainItem = facade.Aggregate(subResults); if (facade.IsValidResult(outputMainItem)) { Local.Admin.AddNewLog(TraceEventType.Information, BrokerContext.Current.WebMethodMessageName, TextMessages.Succeeded, null, null); var output = new TOutput(); output.SetMainItem(outputMainItem); if (succeededCount == subMethodRunStates.Length) { output.StandardRetur = StandardReturType.OK(); } else { var failedSubMethods = subMethodRunStates.Where(smi => !smi.Succeeded).Select(smi => smi.SubMethodInfo); var failedSubMethodsByReason = failedSubMethods.GroupBy(smi => smi.PossibleErrorReason()); var failuresAndReasons = failedSubMethodsByReason.ToDictionary(grp => grp.Key, grp => grp.Select(smi => smi.InputToString())); output.StandardRetur = StandardReturType.PartialSuccess(failuresAndReasons); } return(output); } else { string xml = Strings.SerializeObject(outputMainItem); Local.Admin.AddNewLog(TraceEventType.Error, BrokerContext.Current.WebMethodMessageName, TextMessages.ResultGatheringFailed, typeof(TOutput).ToString(), xml); return(new TOutput() { StandardRetur = StandardReturType.UnspecifiedError("Aggregation failed") }); } } else { // TODO: Is it possible to put details why each item has failed? return(new TOutput() { StandardRetur = StandardReturType.Create(HttpErrorCode.DATASOURCE_UNAVAILABLE) }); } #endregion }
public static StandardReturType ValidateChannel(ChannelBaseType notificationChannel) { if (notificationChannel == null) { return(StandardReturType.NullInput("NotificationChannel")); } if (notificationChannel is WebServiceChannelType) { if (string.IsNullOrEmpty((notificationChannel as WebServiceChannelType).WebServiceUrl)) { return(StandardReturType.NullInput("WebServiceUrl")); } } else if (notificationChannel is FileShareChannelType) { if (string.IsNullOrEmpty((notificationChannel as FileShareChannelType).Path)) { return(StandardReturType.NullInput("Path")); } } else { return(StandardReturType.UnknownObject("Unknown channel type")); } var dbChannel = Data.Channel.FromXmlType(notificationChannel); if (dbChannel == null) { return(StandardReturType.UnknownObject("NotificationChannel")); } var channel = Notifications.Channel.Create(dbChannel); try { if (channel == null || !channel.IsAlive()) { // TODO: Call StandardReturType.UnreachableChannel() return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, "Unreachable channel")); } } catch (Exception ex) { Engine.Local.Admin.LogException(ex); // TODO: Call StandardReturType.UnreachableChannel() return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, "Unreachable channel")); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (string.IsNullOrEmpty(Input)) { return(StandardReturType.NullInput()); } if (!PartInterface.Strings.IsValidPersonNumber(Input)) { return(StandardReturType.InvalidCprNumber(Input)); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (Input == null) { return(StandardReturType.NullInput()); } if (!Strings.IsGuid(Input.UUID)) { return(StandardReturType.InvalidUuid(Input.UUID)); } return(StandardReturType.OK()); }
public StandardReturType CreateDataProviders(out IEnumerable <ISingleDataProvider <TInputElement, TOutputElement> > dataProviders, SourceUsageOrder sourceUsageOrder) { DataProvidersConfigurationSection section = DataProvidersConfigurationSection.GetCurrent(); DataProvider[] dbProviders = DataProviderManager.ReadDatabaseDataProviders(); dataProviders = DataProviderManager.GetDataProviderList(section, dbProviders, InterfaceType, sourceUsageOrder) .Select(p => p as ISingleDataProvider <TInputElement, TOutputElement>); if (dataProviders.FirstOrDefault() == null) { Local.Admin.AddNewLog(TraceEventType.Warning, BrokerContext.Current.WebMethodMessageName, TextMessages.NoDataProvidersFound, null, null); return(StandardReturType.Create(HttpErrorCode.DATASOURCE_UNAVAILABLE)); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (PersonUuids == null) { return(StandardReturType.NullInput()); } else { /* * I'm not entirely sure if any single element is allowed to be empty, but not the entire set or if no element may be empty. * Therefore the two different attempts. */ // Not any empty elements are allowed foreach (Guid person in PersonUuids) { if (person == Guid.Empty || person == null) { return(StandardReturType.NullInput()); } } // Random empty elements are allowed, but not the entire set int count = 0; foreach (Guid person in PersonUuids) { if (person != null && person != Guid.Empty) { count++; } } if (PersonIdentifiers.Length != count) { return(StandardReturType.NullInput()); } } PersonIdentifiers = PersonMapping.GetPersonIdentifiers(PersonUuids); foreach (PersonIdentifier pi in PersonIdentifiers) { if (pi == null) { return(StandardReturType.NullInput()); } } return(StandardReturType.OK()); }
public static StandardReturType Initialize <TOutput, TItem>(FacadeMethodInfo <TOutput, TItem> facade, out SubMethodRunState[] subMethodRunStates) where TOutput : class, IBasicOutput <TItem>, new() { // Initialize facade method facade.Initialize(); // have a list of data provider types and corresponding methods to call bool missingDataProvidersExist; subMethodRunStates = facade.CreateSubMethodRunStates(out missingDataProvidersExist); if (missingDataProvidersExist) { Local.Admin.AddNewLog(TraceEventType.Warning, BrokerContext.Current.WebMethodMessageName, TextMessages.NoDataProvidersFound, null, null); return(StandardReturType.Create(HttpErrorCode.DATASOURCE_UNAVAILABLE)); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (string.IsNullOrEmpty(string.Format("{0}", TargetApplicationToken).Trim())) { return(StandardReturType.NullInput()); } using (ApplicationDataContext context = new ApplicationDataContext()) { var application = context.Applications.SingleOrDefault(app => app.Token == TargetApplicationToken); if (application == null) { return(StandardReturType.UnknownObject("AppToken", TargetApplicationToken)); } } return(StandardReturType.OK()); }
public StandardReturType Validate() { if (UUIDs == null || UUIDs.Length == 0) { return(StandardReturType.NullInput()); } foreach (var uuid in UUIDs) { if (string.IsNullOrEmpty(uuid)) { return(StandardReturType.NullInput()); } } var invalidUuids = (from uuid in UUIDs where !Strings.IsGuid(uuid) select uuid).ToArray(); if (invalidUuids.Length > 0) { return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, String.Join(",", invalidUuids))); } // Now validate the dates if (!EffectDateFrom.HasValue && !EffectDateTo.HasValue) // both null { EffectDateFrom = EffectDateTo = DateTime.Today; } else if (!EffectDateFrom.HasValue) // null from date { return(StandardReturType.NullInput("VirkningFraDato")); } else if (!EffectDateTo.HasValue) // null to date { return(StandardReturType.NullInput("VirkningTilDato")); } else if (EffectDateTo < EffectDateFrom) // both have values { return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, string.Format("tilVirkningDato {0} must be >= fraVirkningDato {1}", EffectDateTo, EffectDateFrom))); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (SubscriptionId == Guid.Empty) { return(StandardReturType.NullInput()); } using (var dataContext = new Data.EventBrokerDataContext()) { var subscription = (from sub in dataContext.Subscriptions where sub.SubscriptionId == SubscriptionId && sub.SubscriptionTypeId == (int)this.SubscriptionType select sub ).SingleOrDefault(); if (subscription == null) { return(StandardReturType.InvalidUuid(SubscriptionId.ToString())); } } return(StandardReturType.OK()); }
public TOutput Aggregate <TOutput>(Element[] elements) where TOutput : IBasicOutput <TOutputElement[]>, new() { // Set output item - only copy succeeded elements var ret = new TOutput(); ret.Item = elements.Select( s => this.IsElementSucceeded(s) ? s.Output : default(TOutputElement) ).ToArray(); // Set standard return var failed = elements.Where(s => !IsElementSucceeded(s)).ToArray(); var succeededCount = elements.Length - failed.Length; if (succeededCount == 0) { ret.StandardRetur = StandardReturType.Create(HttpErrorCode.DATASOURCE_UNAVAILABLE); } else if (succeededCount < elements.Length) { var failuresAndReasons = failed .GroupBy(s => s.PossibleErrorReason) .ToDictionary( g => g.Key, g => g.ToArray() .Select(s => string.Format("{0}", s.Input)) ); ret.StandardRetur = StandardReturType.PartialSuccess(failuresAndReasons); } else { ret.StandardRetur = StandardReturType.OK(); } // final return return(ret); }
public override StandardReturType ValidateInput() { var channelValidationResult = SubscribeFacadeMethod.ValidateChannel(NotificationChannel); if (!StandardReturType.IsSucceeded(channelValidationResult)) { return(channelValidationResult); } if (Years.HasValue) { if (Years.Value < 0 || Years.Value > 200) { return(StandardReturType.ValueOutOfRange("Years", Years.Value)); } } if (PriorDays < 0 || PriorDays > 365) { return(StandardReturType.ValueOutOfRange("PriorDays", Years.Value)); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (input == null || input.Length == 0) { return(StandardReturType.NullInput()); } foreach (var pnr in input) { if (string.IsNullOrEmpty(pnr)) { return(StandardReturType.NullInput()); } } var invalidPnrs = (from pnr in input where !PartInterface.Strings.IsValidPersonNumber(pnr) select pnr).ToArray(); if (invalidPnrs.Length > 0) { return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, String.Join(",", invalidPnrs))); } return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { if (input == null || input.UUID == null || input.UUID.Length == 0) { return(StandardReturType.NullInput()); } foreach (var uuid in input.UUID) { if (string.IsNullOrEmpty(uuid)) { return(StandardReturType.NullInput()); } } var invalidUuids = (from uuid in input.UUID where !Strings.IsGuid(uuid) select uuid).ToArray(); if (invalidUuids.Length > 0) { return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, String.Join(",", invalidUuids))); } return(StandardReturType.OK()); }
public TOutput Run <TOutput>(IEnumerable <TInterface> providers) where TOutput : IBasicOutput <TSingleOutputItem[]>, new() { foreach (var prov in providers) { var currentStates = States .Where(s => !IsSucceededStatus(s)).ToArray(); if (currentStates.Length == 0) { break; } var currentInput = currentStates .Select(kvp => kvp.Input).ToArray(); try { var currentOutput = Run(prov, currentInput); var currentSucceededStates = new List <Status>(); for (int i = 0; i < currentStates.Length; i++) { currentStates[i].Output = currentOutput[i]; if (IsSucceededStatus(currentStates[i])) { currentSucceededStates.Add(currentStates[i]); } } if (prov is IExternalDataProvider) { InvokeUpdateMethod( currentSucceededStates.Select(s => s.Input).ToArray(), currentSucceededStates.Select(s => s.Output).ToArray() ); } } catch (Exception ex) { Local.Admin.LogException(ex); } } // Now create the result var failed = States.Where(s => !IsSucceededStatus(s)).ToArray(); var result = States.Select(s => s.Output).ToArray(); var succeededCount = States.Length - failed.Length; var ret = new TOutput(); ret.SetMainItem(result); if (succeededCount == 0) { ret.StandardRetur = StandardReturType.Create(HttpErrorCode.DATASOURCE_UNAVAILABLE); } else if (succeededCount < States.Length) { var failuresAndReasons = failed .GroupBy(s => s.PossibleErrorReason) .ToDictionary( g => g.Key, g => g.ToArray() .Select(s => string.Format("{0}", s.Input)) ); ret.StandardRetur = StandardReturType.PartialSuccess(failuresAndReasons); } else { ret.StandardRetur = StandardReturType.OK(); } return(ret); }
public override StandardReturType ValidateInput() { if (Input == null) { return(StandardReturType.NullInput()); } if (Input.SoegObjekt == null) { return(StandardReturType.NullInput("SoegObjekt")); } if (!string.IsNullOrEmpty(Input.SoegObjekt.UUID) && !Strings.IsGuid(Input.SoegObjekt.UUID)) { return(StandardReturType.InvalidUuid(Input.SoegObjekt.UUID)); } // Start index & max results if (!string.IsNullOrEmpty(Input.FoersteResultatReference)) { int startResult; if (!int.TryParse(Input.FoersteResultatReference, out startResult)) { return(StandardReturType.InvalidValue("FoersteResultatReference", Input.FoersteResultatReference)); } if (startResult < 0) { return(StandardReturType.ValueOutOfRange("FoersteResultatReference", Input.FoersteResultatReference)); } } if (!string.IsNullOrEmpty(Input.MaksimalAntalKvantitet)) { int maxResults; if (!int.TryParse(Input.MaksimalAntalKvantitet, out maxResults)) { return(StandardReturType.InvalidValue("MaksimalAntalKvantitet", Input.MaksimalAntalKvantitet)); } if (maxResults < 0) { return(StandardReturType.ValueOutOfRange("MaksimalAntalKvantitet", Input.MaksimalAntalKvantitet)); } } // Not implemented criteria if (Input.SoegObjekt.SoegRegistrering != null) { return(StandardReturType.NotImplemented("SoegRegistrering")); } if (Input.SoegObjekt.SoegRelationListe != null) { return(StandardReturType.NotImplemented("SoegRelationListe")); } if (Input.SoegObjekt.SoegTilstandListe != null) { return(StandardReturType.NotImplemented("SoegTilstandListe")); } if (Input.SoegObjekt.SoegVirkning != null) { return(StandardReturType.NotImplemented("SoegVirkning")); } // Now validate attribute lists if (Input.SoegObjekt.SoegAttributListe != null) { if (Input.SoegObjekt.SoegAttributListe.LokalUdvidelse != null) { return(StandardReturType.NotImplemented("SoegAttributListe.LokalUdvidelse")); } if (Input.SoegObjekt.SoegAttributListe.SoegRegisterOplysning != null) { return(StandardReturType.NotImplemented("SoegAttributListe.SoegRegisterOplysning")); } if (Input.SoegObjekt.SoegAttributListe.SoegSundhedOplysning != null) { return(StandardReturType.NotImplemented("SoegAttributListe.SoegSundhedOplysning")); } if (Input.SoegObjekt.SoegAttributListe.SoegEgenskab != null) { foreach (var egen in Input.SoegObjekt.SoegAttributListe.SoegEgenskab) { if (egen.AndreAdresser != null) { return(StandardReturType.NotImplemented("AndreAdresser")); } if (!string.IsNullOrEmpty(egen.FoedestedNavn)) { return(StandardReturType.NotImplemented("FoedestedNavn")); } if (!string.IsNullOrEmpty(egen.FoedselsregistreringMyndighedNavn)) { return(StandardReturType.NotImplemented("FoedselsregistreringMyndighedNavn")); } if (egen.KontaktKanal != null) { return(StandardReturType.NotImplemented("KontaktKanal")); } if (egen.NaermestePaaroerende != null) { return(StandardReturType.NotImplemented("NaermestePaaroerende")); } if (egen.SoegVirkning != null) { return(StandardReturType.NotImplemented("SoegVirkning")); } if (egen.SoegVirkning != null) { return(StandardReturType.NotImplemented("SoegVirkning")); } } } } return(StandardReturType.OK()); }
public virtual StandardReturType ValidateInput() { return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { /* * Do the validation here */ if (Criterion == null) { return(StandardReturType.NullInput("SoegObjekt")); } if (Criterion.SoegAttributListe == null) { return(StandardReturType.NullInput("SoegObjekt.SoegAttributListe")); } else { if (Criterion.SoegAttributListe.SoegRegisterOplysning == null) { return(StandardReturType.NullInput("SoegObjekt.SoegAttributListe.SoegRegisterOplysning")); } else { int index = 0; foreach (var prop in Criterion.SoegAttributListe.SoegRegisterOplysning) { if (prop == null) { return(StandardReturType.NullInput("SoegObjekt.SoegAttributListe.SoegRegisterOplysning[" + index + "]")); } else { if (prop.Item == null) { return(StandardReturType.NullInput("SoegObjekt.SoegAttributListe.SoegRegisterOplysning[" + index + "].CprBorger")); } else { CprBroker.Schemas.Part.CprBorgerType cprBorger = (CprBroker.Schemas.Part.CprBorgerType)prop.Item; CprBroker.Schemas.Part.DanskAdresseType danskAdresse = (CprBroker.Schemas.Part.DanskAdresseType)cprBorger.FolkeregisterAdresse.Item; if (danskAdresse == null) { return(StandardReturType.NullInput("SoegObjekt.SoegAttributListe.SoegRegisterOplysning[" + index + "].CprBorger.DanskAdresse")); } else { if (String.IsNullOrEmpty(danskAdresse.AddressComplete.AddressAccess.MunicipalityCode)) { return(StandardReturType.NullInput("SoegObjekt.SoegAttributListe.SoegRegisterOplysning[" + index + "].CprBorger.DanskAdresse.AddressComplete.AddressAccess.MunicipalityCode")); } } } } index++; } } } var channelValidationResult = ValidateChannel(NotificationChannel); if (!StandardReturType.IsSucceeded(channelValidationResult)) { return(channelValidationResult); } return(StandardReturType.OK()); }
public virtual StandardReturType Validate(TInputElement[] input) { return(StandardReturType.OK()); }
public override StandardReturType ValidateInput() { return(StandardReturType.OK()); }