internal string GetNameSpace(SegmentType component, Type contractType)
        {
            if (contractType.IsArray)
            {
                contractType = contractType.GetElementType();
            }
            object[] namespaceAttributes = contractType.GetCustomAttributes(typeof(PipelineHints.NamespaceAttribute), false);
            foreach (PipelineHints.NamespaceAttribute attr in namespaceAttributes)
            {
                if (ComponentsAreEquivalent(component, attr.Segment))
                {
                    return(attr.Name);
                }
            }
            String contractNamespace = contractType.FullName.Remove(contractType.FullName.LastIndexOf("."));

            if (contractNamespace.EndsWith(".Contracts") || contractNamespace.EndsWith(".Contract"))
            {
                string viewNamespace = contractNamespace.Remove(contractNamespace.LastIndexOf("."));
                if (!(component.Equals(SegmentType.AddInSideAdapter) || component.Equals(SegmentType.HostSideAdapter)))
                {
                    return(viewNamespace);
                }
                else if (component.Equals(SegmentType.AddInSideAdapter))
                {
                    return(viewNamespace + ".AddInSideAdapters");
                }
                else if (component.Equals(SegmentType.HostSideAdapter))
                {
                    return(viewNamespace + ".HostSideAdapters");
                }
            }
            else
            {
                switch (component)
                {
                case SegmentType.AddInView:
                    return(contractNamespace + ".AddInViews");

                case SegmentType.AddInSideAdapter:
                    return(contractNamespace + ".AddInSideAdapters");

                case SegmentType.HostAddInView:
                    return(contractNamespace + ".HostViews");

                case SegmentType.HostSideAdapter:
                    return(contractNamespace + ".HostSideAdapters");

                case SegmentType.View:
                    return(contractNamespace + ".Views");

                default:
                    throw new InvalidOperationException("Component is not a valid type: " + component + "/" + contractType.FullName);
                }
            }
            throw new InvalidOperationException("Component is not a valid type: " + component + "/" + contractType.FullName);
        }
 internal static bool ComponentsAreEquivalent(SegmentType component, PipelineHints.PipelineSegment pipelineHints)
 {
     if (component.Equals(SegmentType.ASA) && pipelineHints.Equals(PipelineHints.PipelineSegment.AddInSideAdapter))
     {
         return true;
     }
     if (component.Equals(SegmentType.HSA) && pipelineHints.Equals(PipelineHints.PipelineSegment.HostSideAdapter))
     {
         return true;
     }
     if (component.Equals(SegmentType.HAV) && pipelineHints.Equals(PipelineHints.PipelineSegment.HostView))
     {
         return true;
     }
     if (component.Equals(SegmentType.AIB) && pipelineHints.Equals(PipelineHints.PipelineSegment.AddInView))
     {
         return true;
     }
     if ((pipelineHints.Equals(PipelineHints.PipelineSegment.Views) &&
             (component.Equals(SegmentType.HAV) || component.Equals(SegmentType.AIB) || component.Equals(SegmentType.VIEW))))
     {
         return true;
     }
     return false;
 }
 internal static bool ComponentsAreEquivalent(SegmentType component, PipelineHints.PipelineSegment pipelineHints)
 {
     if (component.Equals(SegmentType.AddInSideAdapter) && pipelineHints.Equals(PipelineHints.PipelineSegment.AddInSideAdapter))
     {
         return(true);
     }
     if (component.Equals(SegmentType.HostSideAdapter) && pipelineHints.Equals(PipelineHints.PipelineSegment.HostSideAdapter))
     {
         return(true);
     }
     if (component.Equals(SegmentType.HostAddInView) && pipelineHints.Equals(PipelineHints.PipelineSegment.HostView))
     {
         return(true);
     }
     if (component.Equals(SegmentType.AddInView) && pipelineHints.Equals(PipelineHints.PipelineSegment.AddInView))
     {
         return(true);
     }
     if ((pipelineHints.Equals(PipelineHints.PipelineSegment.Views) &&
          (component.Equals(SegmentType.HostAddInView) || component.Equals(SegmentType.AddInView) || component.Equals(SegmentType.View))))
     {
         return(true);
     }
     return(false);
 }
        /// <summary>
        ///     Returns true if OrderChangeMessage instances are equal
        /// </summary>
        /// <param name="other">Instance of OrderChangeMessage to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(OrderChangeMessage other)
        {
            // credit: http://stackoverflow.com/a/10454552/677735
            if (other == null)
            {
                return(false);
            }

            return((Op == other.Op || Op != null && Op.Equals(other.Op)) &&
                   (Id == other.Id || Id != null && Id.Equals(other.Id)) &&
                   (Ct == other.Ct || Ct != null && Ct.Equals(other.Ct)) &&
                   (Clk == other.Clk || Clk != null && Clk.Equals(other.Clk)) &&
                   (HeartbeatMs == other.HeartbeatMs || HeartbeatMs != null && HeartbeatMs.Equals(other.HeartbeatMs)) &&
                   (Pt == other.Pt || Pt != null && Pt.Equals(other.Pt)) &&
                   (Oc == other.Oc || Oc != null && Oc.SequenceEqual(other.Oc)) &&
                   (InitialClk == other.InitialClk || InitialClk != null && InitialClk.Equals(other.InitialClk)) &&
                   (ConflateMs == other.ConflateMs || ConflateMs != null && ConflateMs.Equals(other.ConflateMs)) &&
                   (SegmentType == other.SegmentType || SegmentType != null && SegmentType.Equals(other.SegmentType)));
        }
        internal string GetNameFromType(Type type, SegmentType segmentType,SegmentDirection direction, bool prefix)
        {
            Type underlyingType;
            if (type.IsArray)
            {
                underlyingType = type.GetElementType();
            }
            else
            {
                underlyingType = type;
            }
            if (type.Equals(typeof(System.AddIn.Contract.INativeHandleContract)))
            {
                if (segmentType.Equals(SegmentType.VIEW) || segmentType.Equals(SegmentType.AIB) || segmentType.Equals(SegmentType.HAV))
                {
                    return typeof(System.Windows.FrameworkElement).FullName;
                }
                else
                {
                    return typeof(System.AddIn.Pipeline.FrameworkElementAdapters).FullName;
                }
            }
            if (!type.Assembly.Equals(this._rootAssembly))
            {
                return type.FullName;
            }

            String refPrefix = "";
            String refSuffix = "";
            if (direction == SegmentDirection.ContractToView)
            {
                refSuffix = "ContractToView";
            }
            else if (direction == SegmentDirection.ViewToContract)
            {
                refSuffix = "ViewToContract";
            }
            String typeName = NormalizeContractName(type);
            if (PipelineBuilder.IsViewInterface(type))
            {
                typeName = "I" + typeName;
            }
            if (prefix)
            {
                if (_sharedView && (segmentType.Equals(SegmentType.HAV) || segmentType.Equals(SegmentType.AIB) || segmentType.Equals(SegmentType.VIEW)))
                {
                    refPrefix = GetNameSpace(SegmentType.VIEW,underlyingType) + ".";
                }
                else
                {
                    refPrefix = GetNameSpace(segmentType, underlyingType) + ".";
                }
            }
            if (type.IsArray)
            {
                if (segmentType.Equals(SegmentType.ASA) || segmentType.Equals(SegmentType.HSA))
                {
                    typeName += "Array";
                }
                else
                {
                    typeName += "[]";
                }
            }
            switch (segmentType)
            {
                case SegmentType.HAV:
                    return refPrefix + typeName;
                case SegmentType.HSA:
                    return refPrefix + typeName + refSuffix + "HostAdapter";
                case SegmentType.ASA:
                    return refPrefix + typeName + refSuffix + "AddInAdapter";
                case SegmentType.AIB:
                    return refPrefix + typeName;
                case SegmentType.VIEW:
                    return refPrefix + typeName;
                default:
                    throw new InvalidOperationException("No segment type specified: " + segmentType);
            }
        }
 internal string GetNameSpace(SegmentType component, Type contractType)
 {
     if (contractType.IsArray)
     {
         contractType = contractType.GetElementType();
     }
     object[] namespaceAttributes = contractType.GetCustomAttributes(typeof(PipelineHints.NamespaceAttribute), false);
     foreach (PipelineHints.NamespaceAttribute attr in namespaceAttributes)
     {
         if (ComponentsAreEquivalent(component, attr.Segment))
         {
             return attr.Name;
         }
     }
     String contractNamespace = contractType.FullName.Remove(contractType.FullName.LastIndexOf("."));
     if (contractNamespace.EndsWith(".Contracts") || contractNamespace.EndsWith(".Contract"))
     {
         string viewNamespace = contractNamespace.Remove(contractNamespace.LastIndexOf("."));
         if (!(component.Equals(SegmentType.ASA) || component.Equals(SegmentType.HSA)))
         {
             return viewNamespace;
         }
         else if (component.Equals(SegmentType.ASA))
         {
             return viewNamespace + ".AddInSideAdapters";
         }
         else if (component.Equals(SegmentType.HSA))
         {
             return viewNamespace + ".HostSideAdapters";
         }
     }
     else
     {
         switch (component)
         {
             case SegmentType.AIB:
                 return contractNamespace + ".AddInViews";
             case SegmentType.ASA:
                 return contractNamespace + ".AddInSideAdapters";
             case SegmentType.HAV:
                 return contractNamespace + ".HostViews";
             case SegmentType.HSA:
                 return contractNamespace + ".HostSideAdapters";
             case SegmentType.VIEW:
                 return contractNamespace + ".Views";
             default:
                 throw new InvalidOperationException("Component is not a valid type: " + component + "/" + contractType.FullName);
         }
     }
     throw new InvalidOperationException("Component is not a valid type: " + component + "/" + contractType.FullName);
 }
        internal string GetNameFromType(Type type, SegmentType segmentType, SegmentDirection direction, bool prefix)
        {
            Type underlyingType;

            if (type.IsArray)
            {
                underlyingType = type.GetElementType();
            }
            else
            {
                underlyingType = type;
            }
            if (type.Equals(typeof(System.AddIn.Contract.INativeHandleContract)))
            {
                if (segmentType.Equals(SegmentType.View) || segmentType.Equals(SegmentType.AddInView) || segmentType.Equals(SegmentType.HostAddInView))
                {
                    return(typeof(System.Windows.FrameworkElement).FullName);
                }
                else
                {
                    return(typeof(System.AddIn.Pipeline.FrameworkElementAdapters).FullName);
                }
            }
            if (!type.Assembly.Equals(this._rootAssembly))
            {
                return(type.FullName);
            }

            String refPrefix = "";
            String refSuffix = "";

            if (direction == SegmentDirection.ContractToView)
            {
                refSuffix = "ContractToView";
            }
            else if (direction == SegmentDirection.ViewToContract)
            {
                refSuffix = "ViewToContract";
            }
            String typeName = NormalizeContractName(type);

            if (PipelineBuilder.IsViewInterface(type))
            {
                typeName = "I" + typeName;
            }
            if (prefix)
            {
                if (_sharedView && (segmentType.Equals(SegmentType.HostAddInView) || segmentType.Equals(SegmentType.AddInView) || segmentType.Equals(SegmentType.View)))
                {
                    refPrefix = GetNameSpace(SegmentType.View, underlyingType) + ".";
                }
                else
                {
                    refPrefix = GetNameSpace(segmentType, underlyingType) + ".";
                }
            }
            if (type.IsArray)
            {
                if (segmentType.Equals(SegmentType.AddInSideAdapter) || segmentType.Equals(SegmentType.HostSideAdapter))
                {
                    typeName += "Array";
                }
                else
                {
                    typeName += "[]";
                }
            }
            switch (segmentType)
            {
            case SegmentType.HostAddInView:
                return(refPrefix + typeName);

            case SegmentType.HostSideAdapter:
                return(refPrefix + typeName + refSuffix + "HostAdapter");

            case SegmentType.AddInSideAdapter:
                return(refPrefix + typeName + refSuffix + "AddInAdapter");

            case SegmentType.AddInView:
                return(refPrefix + typeName);

            case SegmentType.View:
                return(refPrefix + typeName);

            default:
                throw new InvalidOperationException("No segment type specified: " + segmentType);
            }
        }
 private SegmentType GetViewType(SegmentType adapterType)
 {
     if (ShouldShareViews())
     {
         return SegmentType.VIEW;
     }
     else
     {
         if (adapterType.Equals(SegmentType.ASA))
         {
             return SegmentType.AIB;
         }
         else if (adapterType.Equals(SegmentType.HSA))
         {
             return SegmentType.HAV;
         }
         else
         {
             throw new InvalidOperationException("Must pass in an adapter segment type");
         }
     }
 }
 private CodeMethodInvokeExpression CallStaticAdapter(SegmentType componentType, Type contractType, CodeExpression obj, SegmentDirection direction)
 {
     SegmentType viewType = SegmentType.VIEW;
     if (!ShouldShareViews())
     {
         if (componentType.Equals(SegmentType.HSA))
         {
             viewType = SegmentType.HAV;
         }
         else
         {
             viewType = SegmentType.AIB;
         }
     }
     if (IsNativeHandle(contractType))
     {
         CodeMethodInvokeExpression adapterInvoke = new CodeMethodInvokeExpression();
         if (direction == SegmentDirection.ContractToView)
         {
             adapterInvoke.Method = new CodeMethodReferenceExpression();
             adapterInvoke.Method.MethodName = "ContractToViewAdapter";
             adapterInvoke.Method.TargetObject = new CodeVariableReferenceExpression("System.AddIn.Pipeline.FrameworkElementAdapters");
             adapterInvoke.Parameters.Add(obj);
         }
         else
         {
             adapterInvoke.Method = new CodeMethodReferenceExpression();
             adapterInvoke.Method.MethodName = "ViewToContractAdapter";
             adapterInvoke.Method.TargetObject = new CodeVariableReferenceExpression("System.AddIn.Pipeline.FrameworkElementAdapters");
             adapterInvoke.Parameters.Add(obj);
         }
         return adapterInvoke;
     }
     else if (IsIListContract(contractType))
     {
         Type genericParam = GetListGenericParamterType(contractType);
         return CallListAdapter(direction, componentType, viewType, obj, genericParam);
     }
     else
     {
         CodeMethodInvokeExpression adaptExpr = new CodeMethodInvokeExpression();
         CodeTypeReferenceExpression adapterType = new CodeTypeReferenceExpression(_symbols.GetNameFromType(contractType, componentType, SegmentDirection.None, true));
         String adapterMethodName = _symbols.GetStaticAdapterMethodNameName(contractType, componentType, direction);
         CodeMethodReferenceExpression adaptMethod = new CodeMethodReferenceExpression(adapterType, adapterMethodName);
         adaptExpr.Method = adaptMethod;
         adaptExpr.Parameters.Add(obj);
         return adaptExpr;
     }
 }