public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target)
 {
   ITimeSpaceAdaptedOutput adaptedOutput = adaptedOutputId as ITimeSpaceAdaptedOutput;
   if (adaptedOutput == null)
     throw new ArgumentException("Adapted output id does no come from this factory","adaptedOutputId");
   return (adaptedOutput);
 }
        /// <summary>
        /// Create an adapted output, assuming that the adaptee and target are matching (check must
        /// be done beforehand.
        /// </summary>
        /// <param name="adaptee">Adaptee to connect to multi input</param>
        /// <param name="target">Target of created multi input adaptor</param>
        /// <returns>Multi input adaptor, connected to adaptee</returns>
        public ITimeSpaceAdaptedOutput CreateAdaptedOutput(IBaseOutput adaptee, IBaseInput target)
        {
            MultiInputAdaptor multiInputAdaptor;

            if (!ExistingMultiInputAdaptors.TryGetValue(target, out multiInputAdaptor))
            {
                // Set up a multi input adaptor having the same properties as the target
                multiInputAdaptor = new MultiInputAdaptor("MultiInputAdaptor:" + target.Id)
                {
                    SpatialDefinition = ((ITimeSpaceInput)target).SpatialDefinition,
                    ValueDefinition   = target.ValueDefinition,
                };
                ExistingMultiInputAdaptors.Add(target, multiInputAdaptor);
            }

            // Identity adaptor, create and register with multiInput
            //adaptedOutput = multiInputAdaptor.CreateChildAdaptor(adaptee);

            // The trick here is to always return and use the same multi input adaptor.
            // for all adaptees.
            multiInputAdaptor.Adaptees.Add((ITimeSpaceOutput)adaptee);

            // Connect adaptee and adaptor - the factory must do this.
            if (!adaptee.AdaptedOutputs.Contains(multiInputAdaptor))
            {
                adaptee.AddAdaptedOutput(multiInputAdaptor);
            }
            return(multiInputAdaptor);
        }
    public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
    {
      ITimeSpaceOutput tadaptee = adaptee as ITimeSpaceOutput;
      
      // Not a time-space exchange item, no available adaptors
      if (tadaptee == null)
        return (new IIdentifiable[0]);
      
      // For each of the spatial extension classes, return its wrapper class

      // MultiPoint must come before ILineString (because ILineString is currently also an IMultiPoint)
      if (tadaptee.SpatialDefinition is IMultiPoint)
        return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new MultiPointWrapper(tadaptee.SpatialDefinition as IMultiPoint), "MultiPointWrapper") };
      
      if (tadaptee.SpatialDefinition is ILineString)
        return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new LineStringWrapper(tadaptee.SpatialDefinition as ILineString), "LineStringWrapper") };
      
      if (tadaptee.SpatialDefinition is ISpatial2DGrid)
        return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new Spatial2DGridWrapper(tadaptee.SpatialDefinition as ISpatial2DGrid), "Spatial2DGridWrapper") };
      
      if (tadaptee.SpatialDefinition is ISpatialMesh)
        return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new SpatialMeshWrapper(tadaptee.SpatialDefinition as ISpatialMesh), "SpatialMeshWrapper") };

      // Spatial definition is not known, return an empty set.
      return (new IIdentifiable[0]);

    }
Exemple #4
0
        /// <summary>
        /// Returns a List of ISpatialDefine with assumed 90deg angles.
        /// The ISpatialDefine is defined by two coordinates and a layer integer.
        /// A ISpatialDefine can represent a cuboid, rectangle or a point.
        /// </summary>
        /// <param name="elementID"></param>
        /// <returns></returns>
        private IDictionary <int, ISpatialDefine> GetModelCoordinates(string elementIDAndGrid)
        {
            char[]   delimiterChars = { ',' };
            string[] words          = elementIDAndGrid.Split(delimiterChars);
            string   elementID      = words[0].Trim();

            IBaseOutput baseOut = base._outputExchangeItems.First(vID => string.Compare(vID.Id, elementID) == 0);

            // Get the Grid Type from the elementID (delimiated by a ',');
            GeometryTypes gType = GetGridType(elementID);

            if (gType == GeometryTypes.Geometry3DSZ)
            {
                return(GetModelCoordinates3DSZ(gType, baseOut, elementID));
            }
            if (gType == GeometryTypes.Geometry3DUZ)
            {
                return(GetModelCoordinates3DUZ(gType, baseOut, elementID));
            }
            if (gType == GeometryTypes.Geometry2D)
            {
                return(GetModelCoordinates2D(gType, baseOut, elementID));
            }
            else
            {
                throw new Exception("The Rest not Implemented");
            }
        }
Exemple #5
0
        /// <summary>
        /// Returns the grid type based on the exchangeID. The exchange ID is a string delimiated by a comma.
        /// The second string after the comma contains the information of the Grid.
        /// Options include:
        /// 1) SZ3DGrid used for hydraulic head
        /// 2) BaseGrid used for land surface variabels (surface temperature, evapotranspiration, ...)
        /// 3) WMUZ3DGrid used for soil moisture content (in the UZ)
        /// </summary>
        /// <param name="exchangeItemId">string deliminated by a comma where the string after the comma contains the grid information.</param>
        /// <returns>The geometry type of the variable. This is MikeSHE specific</returns>
        GeometryTypes GetGridType(string exchangeItemId)
        {
            IBaseOutput baseOut = base._outputExchangeItems.First(vID => string.Compare(vID.Id, exchangeItemId) == 0);

            char[]   delimiterChars = { ',' };
            string[] words          = baseOut.Description.Split(delimiterChars);
            string   gridTypewords  = words[1].Trim();

            if (string.Compare(gridTypewords, "SZ3DGrid", 0) == 0)
            {
                return(GeometryTypes.Geometry3DSZ);
            }
            else if (string.Compare(gridTypewords, "BaseGrid", 0) == 0)
            {
                return(GeometryTypes.Geometry2D);
            }
            else if (string.Compare(gridTypewords, "WMUZ3DGrid", 0) == 0)
            {
                return(GeometryTypes.Geometry3DUZ);
            }
            else
            {
                throw new Exception("Other types do exisit (UZ...)");
            }
        }
        public IBaseAdaptedOutput CreateChildAdaptor(IBaseOutput adaptee)
        {
            var adaptedOutput = new ChildIdentityAdaptor(this, (ITimeSpaceOutput)adaptee);

            Adaptees.Add(adaptedOutput);
            return(adaptedOutput);
        }
Exemple #7
0
 public static OutputPort DefaultGetOutputPort(this IBaseOutput outputNode, ref OutputPort outputPort)
 {
     return(outputPort ?? (outputPort = new OutputPort()
     {
         Node = outputNode as Node
     }));
 }
Exemple #8
0
        public static IIdentifiable[] GetAvailableMethods(IBaseOutput adaptee, IBaseInput target)
        {
            ITimeSpaceOutput tsadaptee = adaptee as ITimeSpaceOutput;

            // Only works with timespace output as adaptee, and element set as spatial definition
            if (tsadaptee == null || !(tsadaptee.SpatialDefinition is IElementSet))
            {
                return(new IIdentifiable[0]);
            }

            IList <IIdentifiable> methods = new List <IIdentifiable>();

            GetAvailableOperationMethods(ref methods, tsadaptee.ElementSet().ElementType);

            // Check if the target is there and is a timespace input
            ITimeSpaceInput tstarget = target as ITimeSpaceInput;

            if (target == null || tstarget == null || !(tstarget.SpatialDefinition is IElementSet))
            {
                return(((List <IIdentifiable>)methods).ToArray());
            }

            GetAvailableMappingMethods(ref methods, tsadaptee.ElementSet().ElementType, tstarget.ElementSet().ElementType);

            return(((List <IIdentifiable>)methods).ToArray());
        }
 /// <summary>
 /// Check if a consumer can be added to an output or adapted output. If both the output and the
 /// new consumer are time space items, the element sets and the time set types are checked.
 /// </summary>
 /// <param name="provider">The output item</param>
 /// <param name="consumer">The new consumer</param>
 /// <returns>True if the consumer can be added indeed</returns>
 public static bool ProviderConsumerConnectable(IBaseOutput provider, IBaseInput consumer)
 {
     if (provider is ITimeSpaceOutput && consumer is ITimeSpaceInput)
     {
         return(ProviderConsumerConnectableForTimeAndElementSet((ITimeSpaceOutput)provider, (ITimeSpaceInput)consumer));
     }
     return(true);
 }
 /// <summary>
 /// Check if a consumer can be added to an output or adapted output. If both the output and the
 /// new consumer are time space items, the element sets and the time set types are checked.
 /// </summary>
 /// <param name="outputItem">The output item</param>
 /// <param name="newConsumer">The new consumer</param>
 /// <returns>True if the consumer can be added indeed</returns>
 public static bool ConsumersCompatible(IBaseOutput outputItem, IBaseInput newConsumer)
 {
     if (outputItem is ITimeSpaceOutput && newConsumer is ITimeSpaceInput)
     {
         return(ConsumersCompatibleForTimeAndElementSet((ITimeSpaceOutput)outputItem, (ITimeSpaceInput)newConsumer));
     }
     return(true);
 }
 public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput parentItem, IBaseInput target)
 {
   // The time methods in this factory only works on an ITimeSpaceOutput
   ITimeSpaceOutput tsoutput = parentItem as ITimeSpaceOutput;
   if (tsoutput == null)
     return (new IIdentifiable[0]);
   return new IIdentifiable[] { new TimeInterpolator(tsoutput), new TimeExtrapolator(tsoutput) };
 }
 /// <summary>
 /// Check if a new consumer is compatible with existing consumers. Throw an exception if not.
 /// </summary>
 /// <param name="outputItem">The output item</param>
 /// <param name="newConsumer">The new consumer</param>
 public static void CheckConsumersCompatible(IBaseOutput outputItem, IBaseInput newConsumer)
 {
     if (!ConsumersCompatible(outputItem, newConsumer))
     {
         throw new Exception("consumer \"" + newConsumer.Caption +
                             "\" can not be added to \"" + outputItem.Caption +
                             "\", because it is incompatible with existing consumers");
     }
 }
 /// <summary>
 /// Check if a consumer can be added to an output or adapted output. Throw an exception if not.
 /// </summary>
 /// <param name="provider">The output item</param>
 /// <param name="consumer">The new consumer</param>
 public static void CheckProviderConsumerConnectable(IBaseOutput provider, IBaseInput consumer)
 {
     if (!ProviderConsumerConnectable(provider, consumer))
     {
         throw new Exception("consumer \"" + consumer.Caption +
                             "\" and provider \"" + provider.Caption +
                             "\" are not connectable, put an adapted output in between");
     }
 }
Exemple #14
0
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput decoratedItem, IBaseInput targetItem)
        {
            ITimeSpaceOutput tsoutput = decoratedItem as ITimeSpaceOutput;

            if (tsoutput == null)
            {
                return(new IIdentifiable[0]);
            }
            return(new List <IIdentifiable>(_ids.Keys).ToArray());
        }
Exemple #15
0
        public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target)
        {
            ITimeSpaceAdaptedOutput adaptedOutput = adaptedOutputId as ITimeSpaceAdaptedOutput;

            if (adaptedOutput == null)
            {
                throw new ArgumentException("Adapted output id does no come from this factory", "adaptedOutputId");
            }
            return(adaptedOutput);
        }
Exemple #16
0
        public void RemoveProvider(IBaseOutput provider)
        {
            // TODO: Check if provider is valid (must be ITimeSpaceOutput)
            ITimeSpaceOutput timeSpaceprovider = (ITimeSpaceOutput)provider;

            _providers.Remove(timeSpaceprovider);
            if (_providers.Count == 0)
            {
                _linkableEngine.ActiveInputItems.Remove(this);
            }
        }
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
        {
            // The time methods in this factory only works on an ITimeSpaceOutput
            ITimeSpaceOutput tsoutput = adaptee as ITimeSpaceOutput;

            if (tsoutput == null)
            {
                return(new IIdentifiable[0]);
            }
            return(new IIdentifiable[] { new AdaptedOutputIdentifier(TimeInterpolatorId), new AdaptedOutputIdentifier(TimeExtrapolatorId) });
        }
Exemple #18
0
        public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target)
        {
            IBaseAdaptedOutput adaptedOutput = new ElementMapperAdaptedOutput(adaptedOutputId, (ITimeSpaceOutput)adaptee, target.ElementSet());

            // Connect adaptor and adaptee
            if (!adaptee.AdaptedOutputs.Contains(adaptedOutput))
            {
                adaptee.AddAdaptedOutput(adaptedOutput);
            }

            return(adaptedOutput);
        }
Exemple #19
0
 public static void ReplaceOutputPort(this IBaseOutput outputNode, ref OutputPort outputPort, OutputPort value)
 {
     //if (outputPort != null)
     //{
     //    //if (outputPort.Connection != null)
     //    //    outputPort.Connection.Start = value;
     //    outputPort.Node = null;
     //    outputPort = null;
     //}
     outputPort = value;
     //if (outputPort != null) outputPort.Node = outputNode as Node;
 }
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput targetItem)
        {
            List <IIdentifiable> available = new List <IIdentifiable>();

            if (adaptee.ValueDefinition.ValueType == typeof(double) ||
                adaptee.ValueDefinition.ValueType == typeof(double[]))
            {
                available.Add(Linear.Identifier);
            }

            return(available.ToArray());
        }
        public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target)
        {
            IBaseAdaptedOutput adaptedOutput = new ElementMapperAdaptedOutput(adaptedOutputId, (ITimeSpaceOutput)adaptee, target.ElementSet());

            // Connect adaptor and adaptee
            if (!adaptee.AdaptedOutputs.Contains(adaptedOutput))
            {
                adaptee.AddAdaptedOutput(adaptedOutput);
            }

            return adaptedOutput;
        }
 public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputIdentifier, IBaseOutput adaptee, IBaseInput target)
 {
   IBaseAdaptedOutput adaptor = adaptedOutputIdentifier as IBaseAdaptedOutput;
   if (adaptor == null)
   {
     throw new ArgumentException("Unknown adaptedOutput type - it does not originate from this factory");
   }
   // Connect the adaptor and the adaptee
   if (!adaptee.AdaptedOutputs.Contains(adaptor))
   {
     adaptee.AddAdaptedOutput(adaptor);
   }
   return adaptor;
 }
Exemple #23
0
        public void AddProvider(IBaseOutput provider)
        {
            // TODO: Check if provider is valid (must be ITimeSpaceOutput)
            ITimeSpaceOutput timeSpaceprovider = (ITimeSpaceOutput)provider;

            if (!_providers.Contains(timeSpaceprovider))
            {
                _providers.Add(timeSpaceprovider);
                if (_providers.Count == 1)
                {
                    _linkableEngine.ActiveInputItems.Add(this);
                }
            }
        }
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
        {
          ITimeSpaceOutput tsadaptee = adaptee as ITimeSpaceOutput;
          ITimeSpaceInput tstarget = target as ITimeSpaceInput;

          // This inly works with time space items, and target can not be null
          if (tsadaptee == null || tstarget == null)
            return new IIdentifiable[0];

          // This only works with element sets
          if (!(tsadaptee.SpatialDefinition is IElementSet && tstarget.SpatialDefinition is IElementSet))
            return new IIdentifiable[0];

          return ElementMapper.GetAvailableMethods(tsadaptee.ElementSet().ElementType, tstarget.ElementSet().ElementType);
        }
        private static bool ConsumersCompatibleForTimeAndOrElementSet(IBaseOutput outputItem, IBaseInput consumer, bool doCheckTime, bool doCheckSpace)
        {
            // Check which time/space consumers are already there
            bool canBeAdded = true;

            if (outputItem.Consumers.Count > 0)
            {
                if (doCheckSpace)
                {
                    // TODO (JG): make instead check on exchangeItem.ElementSet instead of an arbitray elementSet
                    // check if #elements are consistent
                    if (consumer.ElementSet() != null &&
                        outputItem.Consumers[0].ElementSet() != null &&
                        consumer.ElementSet().ElementCount != outputItem.Consumers[0].ElementSet().ElementCount)
                    {
                        canBeAdded = false;
                    }
                }
                if (doCheckTime)
                {
                    ITimeSpaceInput consumerAsTimeSpace = consumer as ITimeSpaceInput;
                    if (consumerAsTimeSpace != null)
                    {
                        List <ITimeSpaceInput> existingConsumers = new List <ITimeSpaceInput>();
                        foreach (IBaseInput existingConsumer in outputItem.Consumers)
                        {
                            if (existingConsumer is ITimeSpaceOutput)
                            {
                                existingConsumers.Add((ITimeSpaceInput)existingConsumer);
                            }
                        }
                        if (existingConsumers.Count > 0)
                        {
                            // TODO (JG): Is this a requirement?
                            if (consumerAsTimeSpace.TimeSet != null &&
                                existingConsumers[0].TimeSet != null &&
                                consumerAsTimeSpace.TimeSet.HasDurations != existingConsumers[0].TimeSet.HasDurations
                                )
                            {
                                canBeAdded = false;
                            }
                        }
                    }
                }
            }
            return(canBeAdded);
        }
        public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target)
        {
            MultiInputAdaptor multiInputAdaptor = null;

            if (adaptedOutputId == _identityAdaptor)
            {
                // If a MultiInputAdaptor already exists for the target, get that one, otherwise create a new.
                return(CreateAdaptedOutput(adaptee, target));
            }

            if (multiInputAdaptor == null)
            {
                throw new ArgumentException("Adapted output id could not be found", "adaptedOutputId");
            }

            return(multiInputAdaptor);
        }
        public static ITime GetEarliestConsumerTime(IBaseOutput output)
        {
            ITime earliestRequiredTime = null;

            foreach (IBaseAdaptedOutput adaptedOutput in output.AdaptedOutputs)
            {
                earliestRequiredTime = CheckTimeHorizonMinimum(earliestRequiredTime, GetEarliestConsumerTime(adaptedOutput));
            }
            foreach (IBaseInput input in output.Consumers)
            {
                ITimeSpaceInput timeSpaceInput = input as ITimeSpaceInput;
                if (timeSpaceInput != null && timeSpaceInput.TimeSet != null)
                {
                    earliestRequiredTime = CheckTimeHorizonMinimum(earliestRequiredTime, timeSpaceInput.TimeSet.TimeHorizon);
                }
            }
            return(earliestRequiredTime);
        }
Exemple #28
0
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
        {
            ITimeSpaceOutput tsadaptee = adaptee as ITimeSpaceOutput;
            ITimeSpaceInput  tstarget  = target as ITimeSpaceInput;

            // This inly works with time space items, and target can not be null
            if (tsadaptee == null || tstarget == null)
            {
                return(new IIdentifiable[0]);
            }

            // This only works with element sets
            if (!(tsadaptee.SpatialDefinition is IElementSet && tstarget.SpatialDefinition is IElementSet))
            {
                return(new IIdentifiable[0]);
            }

            return(ElementMapper.GetAvailableMethods(tsadaptee.ElementSet().ElementType, tstarget.ElementSet().ElementType));
        }
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
        {
            // Target must be this component!
            if (target == null || target.Component != _component)
            {
                return(new IIdentifiable[0]);
            }

            // Check for filter
            if (Filter != null && !Filter(adaptee, target))
            {
                return(new IIdentifiable[0]);
            }

            List <IIdentifiable> res = new List <IIdentifiable>();

            res.Add(_identityAdaptor);

            return(res.ToArray());
        }
Exemple #30
0
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
        {
            ITimeSpaceOutput tadaptee = adaptee as ITimeSpaceOutput;

            // Not a time-space exchange item, no available adaptors
            if (tadaptee == null)
            {
                return(new IIdentifiable[0]);
            }

            // For each of the spatial extension classes, return its wrapper class

            // MultiPoint must come before ILineString (because ILineString is currently also an IMultiPoint)
            if (tadaptee.SpatialDefinition is IMultiPoint)
            {
                return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new MultiPointWrapper(tadaptee.SpatialDefinition as IMultiPoint), "MultiPointWrapper") }
            }
            ;

            if (tadaptee.SpatialDefinition is ILineString)
            {
                return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new LineStringWrapper(tadaptee.SpatialDefinition as ILineString), "LineStringWrapper") }
            }
            ;

            if (tadaptee.SpatialDefinition is ISpatial2DGrid)
            {
                return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new Spatial2DGridWrapper(tadaptee.SpatialDefinition as ISpatial2DGrid), "Spatial2DGridWrapper") }
            }
            ;

            if (tadaptee.SpatialDefinition is ISpatialMesh)
            {
                return new IIdentifiable[] { new SpatialExtensionElementSetAdaptor(tadaptee, new SpatialMeshWrapper(tadaptee.SpatialDefinition as ISpatialMesh), "SpatialMeshWrapper") }
            }
            ;

            // Spatial definition is not known, return an empty set.
            return(new IIdentifiable[0]);
        }
        private static bool ProviderConsumerConnectableForTimeAndOrElementSet(IBaseOutput provider, IBaseInput consumer, bool doCheckTime, bool doCheckSpace)
        {
            // Check which time/space consumers are already there
            if (doCheckSpace)
            {
                // check if #elements and elementType are consistent
                if (consumer.ElementSet() != null &&
                    provider.ElementSet() != null
                    )
                {
                    if (consumer.ElementSet().ElementCount != provider.ElementSet().ElementCount)
                    {
                        return(false);
                    }
                    if (consumer.ElementSet().ElementType != provider.ElementSet().ElementType&&
                        consumer.ElementSet().ElementCount != 1)
                    {
                        return(false);
                    }
                }
            }
            if (doCheckTime)
            {
                ITimeSpaceInput consumerAsTimeSpace = consumer as ITimeSpaceInput;
                ITimeSpaceInput providerAsTimeSpace = provider as ITimeSpaceInput;
                if (consumerAsTimeSpace != null && providerAsTimeSpace != null)
                {
                    if (consumerAsTimeSpace.TimeSet != null &&
                        providerAsTimeSpace.TimeSet != null &&
                        consumerAsTimeSpace.TimeSet.HasDurations != providerAsTimeSpace.TimeSet.HasDurations)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
        {
            if (target.Component != _component)
            {
                return(new IIdentifiable[0]);
            }

            List <IIdentifiable> res = new List <IIdentifiable>();

            // TODO: Implement some criteria here
            //if (adaptee and target spatialDefintion equals)
            //{

            res.Add(_identityAdaptor);
            //}
            //else
            //{
            res.AddRange(_spatialAdaptorFactory.GetAvailableAdaptedOutputIds(adaptee, target));
            //}


            return(res.ToArray());
        }
Exemple #33
0
        public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
        {
            // The time methods in this factory only works on an ITimeSpaceOutput
            ITimeSpaceOutput tsAdaptee = adaptee as ITimeSpaceOutput;

            if (tsAdaptee == null)
            {
                return(new IIdentifiable[0]);
            }

            IIdentifiable[] ids = new IBaseAdaptedOutput[]
            {
                new TimeInterpolator(tsAdaptee),
                new TimeExtrapolator(tsAdaptee),
                new LinearOperationAdaptedOutput(tsAdaptee)
            };

            for (int i = 0; i < ids.Length; i++)
            {
                IBaseAdaptedOutput searchItem = ids[i] as IBaseAdaptedOutput;

                IBaseAdaptedOutput temp = (from n in outputsCreatedSoFar
                                           where searchItem.Id == n.Id && n.Adaptee == searchItem.Adaptee
                                           select n).FirstOrDefault();

                if (temp == null)
                {
                    outputsCreatedSoFar.Add(searchItem);
                }
                else
                {
                    ids[i] = temp;
                }
            }

            return(ids);
        }
        public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target)
        {
            // TODO: Some usefull criteria here
            if (true)
            {
                // If a MultiInputAdaptor already exists for the target, get that one, otherwise create a new.
                MultiInputAdaptor multiInputAdaptor;
                if (!ExistingMultiInputAdaptors.TryGetValue(target, out multiInputAdaptor))
                {
                    multiInputAdaptor = new MultiInputAdaptor("SomeId")
                    {
                        SpatialDefinition = ((ITimeSpaceInput)target).SpatialDefinition
                    };
                    multiInputAdaptor.AddConsumer(target);
                    ExistingMultiInputAdaptors.Add(target, multiInputAdaptor);
                }

                if (adaptedOutputId == _identityAdaptor)
                {
                    // Identity adaptor
                    IBaseAdaptedOutput adaptedOutput = multiInputAdaptor.CreateChildAdaptor(adaptee);
                    return(adaptedOutput);
                }
                else
                {
                    // ElementMapping adaptor
                    IBaseAdaptedOutput adaptedOutput = _spatialAdaptorFactory.CreateAdaptedOutput(adaptedOutputId, adaptee, target);
                    if (adaptedOutput != null)
                    {
                        multiInputAdaptor.Adaptees.Add((ITimeSpaceOutputAdder)adaptedOutput);
                        return(adaptedOutput);
                    }
                }
            }

            return(null);
        }
        public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputIdentifier, IBaseOutput parentOutput, IBaseInput target)
        {
            IBaseAdaptedOutput adaptedOutput = null;

            if (adaptedOutputIdentifier.Id.Equals(TimeInterpolatorId))
            {
                adaptedOutput = new MeasurementsInterpolator((ITimeSpaceOutput)parentOutput);
            }
            else if (adaptedOutputIdentifier.Id.Equals(TimeExtrapolatorId))
            {
                adaptedOutput = new TimeExtrapolator((ITimeSpaceOutput)parentOutput);
            }
            if (adaptedOutput == null)
            {
                throw new Exception("AdaptedOutput id: " + adaptedOutputIdentifier.Id);
            }

            // connect adaptor and adaptee
            if (!parentOutput.AdaptedOutputs.Contains(adaptedOutput))
            {
                parentOutput.AddAdaptedOutput(adaptedOutput);
            }
            return(adaptedOutput);
        }
        public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputIdentifier, IBaseOutput adaptee, IBaseInput target)
        {
            IBaseAdaptedOutput adaptor = adaptedOutputIdentifier as IBaseAdaptedOutput;

            if (adaptor == null)
            {
                throw new ArgumentException("Unknown adaptedOutput type - it does not originate from this factory");
            }
            // Connect the adaptor and the adaptee
            if (!adaptee.AdaptedOutputs.Contains(adaptor))
            {
                adaptee.AddAdaptedOutput(adaptor);
            }
            return(adaptor);
        }
 public ValidationSource(IBaseOutput source)
     : base(source)
 {
     _source = source;
 }
 public IBaseAdaptedOutput CreateChildAdaptor(IBaseOutput adaptee)
 {
   var adaptedOutput = new ChildIdentityAdaptor(this, (ITimeSpaceOutput)adaptee);
   Adaptees.Add(adaptedOutput);
   return (adaptedOutput);
 }
    public IBaseAdaptedOutput CreateAdaptedOutput(IIdentifiable adaptedOutputId, IBaseOutput adaptee, IBaseInput target)
    {
      // TODO: Some usefull criteria here
      if (true)
      {
        // If a MultiInputAdaptor already exists for the target, get that one, otherwise create a new.
        MultiInputAdaptor multiInputAdaptor;
        if (!ExistingMultiInputAdaptors.TryGetValue(target, out multiInputAdaptor))
        {
          multiInputAdaptor = new MultiInputAdaptor("SomeId")
                                  {
                                    SpatialDefinition = ((ITimeSpaceInput)target).SpatialDefinition
                                  };
          multiInputAdaptor.AddConsumer(target);
          ExistingMultiInputAdaptors.Add(target, multiInputAdaptor);
        }

        if (adaptedOutputId == _identityAdaptor)
        {
          // Identity adaptor
          IBaseAdaptedOutput adaptedOutput = multiInputAdaptor.CreateChildAdaptor(adaptee);
          return (adaptedOutput);
        }
        else
        {
          // ElementMapping adaptor
          IBaseAdaptedOutput adaptedOutput = _spatialAdaptorFactory.CreateAdaptedOutput(adaptedOutputId, adaptee, target);
          if (adaptedOutput != null)
          {
            multiInputAdaptor.Adaptees.Add((ITimeSpaceOutputAdder) adaptedOutput);
            return (adaptedOutput);
          }
        }
      }

      return (null);

    }
    public IIdentifiable[] GetAvailableAdaptedOutputIds(IBaseOutput adaptee, IBaseInput target)
    {
      if (target.Component != _component)
        return (new IIdentifiable[0]);

      List<IIdentifiable> res = new List<IIdentifiable>();

      // TODO: Implement some criteria here
      //if (adaptee and target spatialDefintion equals)
      //{

      res.Add(_identityAdaptor);
      //}
      //else
      //{
      res.AddRange(_spatialAdaptorFactory.GetAvailableAdaptedOutputIds(adaptee, target));
      //}


      return (res.ToArray());
    }
        List<IBaseInput> Consumers(IBaseOutput source)
        {
            List<IBaseInput> consumers = new List<IBaseInput>(source.Consumers);

            AddConsumersRecursive(source, consumers);

            return consumers;
        }
        void AddConsumersRecursive(IBaseOutput source, List<IBaseInput> consumers)
        {
            if (source == null)
                return;

            consumers.AddRange(source.Consumers);

            foreach (IBaseAdaptedOutput adapted in source.AdaptedOutputs)
                AddConsumersRecursive(adapted, consumers);
        }