コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: ClientMethod.cs プロジェクト: magenta-aps/cprbroker
 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());
 }
コード例 #3
0
        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
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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());
        }
コード例 #8
0
ファイル: ClientMethod.cs プロジェクト: magenta-aps/cprbroker
        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);
        }
コード例 #9
0
        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());
        }
コード例 #10
0
        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());
        }
コード例 #11
0
        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);
        }