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); }
private bool search(PartManager partManager, SoegInputType1 soegObject, BatchLine batchLine, SourceUsageOrder SourceUsageOrder) { var searchResult = partManager.SearchList( BrokerContext.Current.UserToken, BrokerContext.Current.ApplicationToken, soegObject, SourceUsageOrder); if (StandardReturType.IsSucceeded(searchResult.StandardRetur)) { if (batchLine.FillFrom(searchResult)) { return(true); } else { batchLine.Error = "Person not found"; return(false); } } else { batchLine.Error = string.Format("{0}-{1}", searchResult.StandardRetur.StatusKode, searchResult.StandardRetur.FejlbeskedTekst); return(false); } }
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 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()); }
private IBasicOutput CreateReturnValue(SoapMessage message) { Exception ex = Misc.GetDeepestInnerException(message.Exception); var ret = Utilities.Reflection.CreateInstance(message.MethodInfo.ReturnType); var output = ret as Schemas.Part.IBasicOutput; if (ex is XmlException) { output.StandardRetur = StandardReturType.MalformedXml(); } else if (ex is HeaderException) { output.StandardRetur = StandardReturType.NullInput("applicationHeader"); } else if (ex is MissingRequestException) { output.StandardRetur = StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, string.Format("Missing request element: {0}", message.MethodInfo.Name)); } else if (ex is InvalidOperationException && Misc.ExceptionTreeContainsText(message.Exception, "XML")) { output.StandardRetur = StandardReturType.RequestUnreadable(ex.Message); } else { output.StandardRetur = StandardReturType.UnspecifiedError(); } return(output); }
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 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 virtual StandardReturType BaseValidate <TOutput>(MethodHeader header, TInputElement[] input) { // Initialize context try { BrokerContext.Initialize(header.ApplicationToken, header.UserToken); } catch (Exception ex) { return(StandardReturType.InvalidApplicationToken(header.ApplicationToken)); } // Validate input if (input == null || input.Length == 0) { return(StandardReturType.NullInput()); } var ret = Validate(input); if (ret == null) { ret = StandardReturType.UnspecifiedError("Validation failed"); } return(ret); }
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 Guid CprToUuid(string cprNumber) { var uuid = PartManager.GetUuid(BrokerContext.Current.UserToken, BrokerContext.Current.ApplicationToken, cprNumber); if (StandardReturType.IsSucceeded(uuid.StandardRetur)) { return(new Guid(uuid.UUID)); } else { throw new Exception(string.Format("Could not find UUID of person <{0}>", cprNumber)); } }
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()); }
/// <summary> /// Gets the result for an array of input items /// </summary> /// <typeparam name="TOutput"></typeparam> /// <param name="header">Header tokens</param> /// <param name="input">Array of input items</param> /// <returns>Composite result for the operation</returns> public TOutput GetBatch <TOutput>(MethodHeader header, TInputElement[] input) where TOutput : IBasicOutput <TOutputElement[]>, new() { try { // Validate var ret = BaseValidate <TOutput>(header, input); if (!StandardReturType.IsSucceeded(ret)) { return new TOutput() { StandardRetur = ret } } ; // Data providers IEnumerable <TInterface> dataProviders; // TODO: Create an execution plan here var providerMethod = new ProviderMethod <TInputElement, TOutputElement, Element, object, TInterface>(); ret = CreateDataProviders(providerMethod, out dataProviders); if (!StandardReturType.IsSucceeded(ret)) { return new TOutput() { StandardRetur = ret } } ; // Call data providers var allElements = providerMethod.CallDataProviders(dataProviders, input); // Aggregate return(Aggregate <TOutput>(allElements)); } catch (Exception ex) { Local.Admin.LogException(ex); return(new TOutput() { StandardRetur = StandardReturType.UnspecifiedError() }); } }
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 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()); }
protected void applicationsLinqDataSource_Inserting(object sender, LinqDataSourceInsertEventArgs e) { e.Cancel = true; CprBroker.Data.Applications.Application newApp = e.NewObject as CprBroker.Data.Applications.Application; var result = Manager.Admin.RequestAppRegistration(Constants.UserToken, Constants.BaseApplicationToken.ToString(), newApp.Name); Master.AppendErrorIfPossible(result); if (StandardReturType.IsSucceeded(result.StandardRetur)) { if (newApp.IsApproved) { var approveResult = Manager.Admin.ApproveAppRegistration(Constants.UserToken, Constants.BaseApplicationToken.ToString(), result.Item.Token); Master.AppendErrorIfPossible(approveResult); } } applicationsGridView.DataBind(); newApplicationDetailsView.DataBind(); }
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 static TOutput GetMethodOutput <TOutput, TItem>(FacadeMethodInfo <TOutput, TItem> facade) where TOutput : class, IBasicOutput <TItem>, new() { try { StandardReturType standardRetur; SubMethodRunState[] subMethodRunStates; standardRetur = Validate <TOutput, TItem>(facade); if (!StandardReturType.IsSucceeded(standardRetur)) { return(new TOutput() { StandardRetur = standardRetur }); } standardRetur = Initialize <TOutput, TItem>(facade, out subMethodRunStates); if (!StandardReturType.IsSucceeded(standardRetur)) { return(new TOutput() { StandardRetur = standardRetur }); } RunThreads <TOutput, TItem>(facade, subMethodRunStates); return(AggregateResults <TOutput, TItem>(facade, subMethodRunStates)); } catch (Exception ex) { Local.Admin.LogException(ex); return(new TOutput() { StandardRetur = StandardReturType.UnspecifiedError() }); } }
public static TOutput GetBatchMethodOutput <TInterface, TOutput, TSingleInputItem, TSingleOutputItem>(BatchFacadeMethodInfo <TInterface, TOutput, TSingleInputItem, TSingleOutputItem> facade) where TInterface : class, IDataProvider where TOutput : class, IBasicOutput <TSingleOutputItem[]>, new() { try { StandardReturType standardRetur; SubMethodRunState[] subMethodRunStates; standardRetur = Validate <TOutput, TSingleOutputItem[]>(facade); if (!StandardReturType.IsSucceeded(standardRetur)) { return(new TOutput() { StandardRetur = standardRetur }); } standardRetur = Initialize <TOutput, TSingleOutputItem[]>(facade, out subMethodRunStates); if (!StandardReturType.IsSucceeded(standardRetur)) { return(new TOutput() { StandardRetur = standardRetur }); } return(facade.Run(subMethodRunStates)); } catch (Exception ex) { Local.Admin.LogException(ex); return(new TOutput() { StandardRetur = StandardReturType.UnspecifiedError() }); } }
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.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()); }