示例#1
0
        /// <summary>
        ///     Load field data.
        /// </summary>
        /// <param name="dataTable"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <remarks>
        ///     Data sources MUST:
        ///     - ensure that bits are represented as Booleans
        ///     - ensure that XML is transformed so that entityRefs contain Upgrade ids
        ///     - or where XML contains an alias, translate it to uprgadeId|alias   (as the alias may be changed in the target)
        ///     - ensure that aliases export their namespace and direction marker.
        /// </remarks>
        public IEnumerable <DataEntry> GetFieldData(string dataTable, IProcessingContext context)
        {
            if (!FieldData.ContainsKey(dataTable))
            {
                return(Enumerable.Empty <DataEntry>( ));
            }

            Dictionary <Entity, List <FieldData> > typedValues = FieldData[dataTable];

            if (dataTable == "Alias")
            {
                Alias aliasMarkerIdField = Aliases.CoreAlias("aliasMarkerId");

                return(from pair in typedValues
                       from field in pair.Value
                       let alias = SchemaResolver.GetAliasFieldValue(pair.Key, field.Field.Alias)
                                   let intFieldValue = SchemaResolver.GetIntFieldValue(field.Field, aliasMarkerIdField)
                                                       where intFieldValue != null
                                                       where pair.Key.Members != null && pair.Key.Members.Any(m => m.MemberDefinition.Alias.Namespace == "core" && m.MemberDefinition.Alias.Value == "inSolution" && m.Value == ActiveSolution)
                                                       let markerId = intFieldValue.Value
                                                                      select new DataEntry
                {
                    AliasMarkerId = markerId,
                    Data = alias.Value,
                    EntityId = pair.Key.Guid,
                    FieldId = field.Field.Guid,
                    Namespace = alias.Namespace,
                    State = DataState.Added
                });
            }

            /////
            // Non-Alias
            /////
            return(from pair in typedValues
                   from field in pair.Value
                   where pair.Key.Members != null && pair.Key.Members.Any(m => m.MemberDefinition.Alias.Namespace == "core" && m.MemberDefinition.Alias.Value == "inSolution" && m.Value == ActiveSolution)
                   select new DataEntry
            {
                Data = FormatData(field),
                EntityId = pair.Key.Guid,
                FieldId = field.Field.Guid,
                State = DataState.Added
            });
        }
        public override void ProcessResponse(Session session, Message message, bool isPartialResponse, Action <Session, Message, Exception> onFailure)
        {
            IObserver <ReferenceDataResponse> observer;

            if (!TryGet(message.CorrelationID, out observer))
            {
                onFailure(session, message, new Exception("Unable to find handler for correlation id: " + message.CorrelationID));
                return;
            }

            if (message.HasElement(ElementNames.ResponseError))
            {
                var responseErrorElement = message.GetElement(ElementNames.ResponseError);
                var responseError        = new ResponseError(
                    responseErrorElement.GetElementAsString(ElementNames.Source),
                    responseErrorElement.GetElementAsString(ElementNames.Category),
                    responseErrorElement.GetElementAsString(ElementNames.SubCategory),
                    responseErrorElement.GetElementAsInt32(ElementNames.Code),
                    responseErrorElement.GetElementAsString(ElementNames.Message));
                observer.OnError(new ContentException <ResponseError>(responseError));

                // We assume no more messages will be delivered for this correlation id.
                Remove(message.CorrelationID);

                return;
            }

            var referenceDataResponse = new ReferenceDataResponse();

            var securities = message.GetElement(ElementNames.SecurityData);

            for (var i = 0; i < securities.NumValues; ++i)
            {
                var security = securities.GetValueAsElement(i);
                var ticker   = security.GetElementAsString(ElementNames.Security);

                if (security.HasElement(ElementNames.SecurityError))
                {
                    var securityErrorElement = security.GetElement(ElementNames.SecurityError);
                    var responseError        = new ResponseError(
                        securityErrorElement.GetElementAsString(ElementNames.Source),
                        securityErrorElement.GetElementAsString(ElementNames.Category),
                        securityErrorElement.GetElementAsString(ElementNames.SubCategory),
                        securityErrorElement.GetElementAsInt32(ElementNames.Code),
                        securityErrorElement.GetElementAsString(ElementNames.Message));

                    referenceDataResponse.Add(ticker, Either.Left <ResponseError, FieldData>(responseError));
                    continue;
                }

                var fieldData = new FieldData();

                var fields = security.GetElement(ElementNames.FieldData);
                for (var j = 0; j < fields.NumElements; ++j)
                {
                    var field = fields.GetElement(j);
                    var name  = field.Name.ToString();
                    var value = field.GetFieldValue();
                    if (fieldData.ContainsKey(name))
                    {
                        fieldData[name] = value;
                    }
                    else
                    {
                        fieldData.Add(name, value);
                    }
                }

                referenceDataResponse.Add(ticker, Either.Right <ResponseError, FieldData>(fieldData));
            }

            observer.OnNext(referenceDataResponse);

            if (!isPartialResponse)
            {
                observer.OnCompleted();
                Remove(message.CorrelationID);
            }
        }