예제 #1
0
    public void Import(DsonTypes.Channel channel, string expectedId, string name, string pathPrefix)
    {
        if (channel.id != expectedId)
        {
            throw new InvalidOperationException("channel has unexpected id");
        }

        if (channel.target_channel != null)
        {
            //Skip alias channels
            return;
        }

        string label = channel.label ?? channel.name;
        string path  = pathPrefix + "/" + label;

        ChannelRecipe recipe = new ChannelRecipe {
            Name         = name,
            InitialValue = channel.value,
            Min          = channel.min,
            Max          = channel.max,
            Clamped      = channel.clamped,
            Visible      = channel.visible,
            Path         = path
        };

        channelRecipes.Add(recipe);
    }
    private List <ChannelRecipe> MergeChannels()
    {
        List <ChannelRecipe> mergedChannels = new List <ChannelRecipe>(parent.Channels);

        Dictionary <string, ChannelRecipe> parentChannelsByName = parent.Channels
                                                                  .ToDictionary(channel => channel.Name, channel => channel);

        foreach (var child in children)
        {
            foreach (var childChannel in child.Channels)
            {
                if (parentChannelsByName.TryGetValue(childChannel.Name, out var parentChannel))
                {
                    ChannelRecipe.VerifySimpleChild(parentChannel, childChannel);
                }
                else
                {
                    mergedChannels.Add(childChannel);
                }
            }
        }

        mergedChannels.AddRange(childControlChannels);

        return(mergedChannels);
    }
예제 #3
0
 /*
  * Verify a child channel will always have the same value as the parent
  */
 public static void VerifySimpleChild(ChannelRecipe parentChannel, ChannelRecipe childChannel)
 {
     if (childChannel.Name != parentChannel.Name)
     {
         throw new InvalidOperationException("parent and child channels differ");
     }
     if (childChannel.Min > parentChannel.Min)
     {
         throw new InvalidOperationException("parent and child channels differ");
     }
     if (childChannel.Max < parentChannel.Max)
     {
         throw new InvalidOperationException("parent and child channels differ");
     }
 }