Example #1
0
 /// <summary>
 /// Creates a new <see cref="StreamCommand{T}"/>.
 /// </summary>
 /// <param name="info">A <see cref="CommandInfo"/> object which contains documentation and identifying info for the action this <see cref="ICommand{T}"/> provides.</param>
 /// <param name="enableStream">An <see cref="IStream{T}"/> that emits <see cref="bool"/> values indicating whether this <see cref="StreamCommand{T}"/> should be enabled or not.</param>
 public StreamCommand(CommandInfo info, IStream <bool> enableStream = null)
 {
     Info          = info;
     TriggerStream = new SourceStream <bool>();
     ValueEmitted  = TriggerStream.ValueEmitted;
     EnabledStream = enableStream ?? true.AsStream();
 }
        /// <inheritdoc />
        protected override void OnConfigurationPropertyChanged(string propertyName)
        {
            base.OnConfigurationPropertyChanged(propertyName);
            if (propertyName == nameof(AudioVisualizationObjectConfiguration.Channel))
            {
                if (this.Panel != null)
                {
                    // NOTE: Only open a stream when this visualization object is connected to it's parent

                    // Create a new binding with a different channel argument and re-open the stream
                    var newBinding = new StreamBinding(this.Configuration.StreamBinding, typeof(AudioSummarizer), new object[] { this.Configuration.Channel });
                    this.OpenStream(newBinding);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Shows the specified stream in an appropriate visualization panel, creating a new one if needed.
        /// </summary>
        /// <typeparam name="TObject">The type of client stream visualization object (proxy) to create.</typeparam>
        /// <typeparam name="TData">The type of underlying data of the stream visualization object.</typeparam>
        /// <typeparam name="TConfig">The type of configuration of the stream visualization object</typeparam>
        /// <typeparam name="TPanel">The type of visauzalition panel required to show the stream.</typeparam>
        /// <param name="streamBinding">Stream binding inidicting which stream to open.</param>
        /// <returns>The newly created <see cref="StreamVisualizationObject{TData, TConfig}"/> used to show the stream.</returns>
        public TObject Show <TObject, TData, TConfig, TPanel>(StreamBinding streamBinding)
            where TObject : StreamVisualizationObject <TData, TConfig>, new()
            where TConfig : StreamVisualizationObjectConfiguration, new()
            where TPanel : VisualizationPanel, new()
        {
            this.EnsureCurrentPanel <TPanel>();
            this.EnsureBinding(streamBinding);

            TObject visObj = this.CurrentPanel.AddVisualizationObject <TObject, TConfig>();

            visObj.Configuration.Name = streamBinding.StreamName;
            visObj.OpenStream(streamBinding);

            return(visObj);
        }
        /// <summary>
        /// Shows the specified stream in an appropriate visualization panel, creating a new one if needed.
        /// </summary>
        /// <typeparam name="TObject">The type of client stream visualization object (proxy) to create.</typeparam>
        /// <typeparam name="TData">The type of underlying data of the stream visualization object.</typeparam>
        /// <typeparam name="TConfig">The type of configuration of the stream visualization object</typeparam>
        /// <typeparam name="TPanel">The type of visauzalition panel required to show the stream.</typeparam>
        /// <param name="vc">The visualization client.</param>
        /// <param name="stream">Stream to show.</param>
        /// <returns>The newly created <see cref="StreamVisualizationObject{TData, TConfig}"/> used to show the stream.</returns>
        public static TObject Show <TObject, TData, TConfig, TPanel>(this VisualizationClient vc, IProducer <TData> stream)
            where TObject : StreamVisualizationObject <TData, TConfig>, new()
            where TConfig : StreamVisualizationObjectConfiguration, new()
            where TPanel : VisualizationPanel, new()
        {
            PsiStreamMetadata streamMetadata;

            if (!Store.TryGetMetadata(stream, out streamMetadata))
            {
                throw new ApplicationException("Stream not found.");
            }

            var streamBinding = new StreamBinding(streamMetadata.Name, streamMetadata.PartitionName, streamMetadata.PartitionName, streamMetadata.PartitionPath, typeof(SimpleReader));

            return(vc.Show <TObject, TData, TConfig, TPanel>(streamBinding));
        }
        /// <summary>
        /// Shows a stream of doubles.
        /// </summary>
        /// <param name="stream">A stream of doubles to show.</param>
        /// <param name="vc">The visualization client.</param>
        /// <returns>The newly created <see cref="StreamVisualizationObject{TData, TConfig}"/> used to show the stream.</returns>
        public static PlotVisualizationObject Show(this IProducer <double> stream, VisualizationClient vc)
        {
            PsiStreamMetadata streamMetadata;

            if (!Store.TryGetMetadata(stream, out streamMetadata))
            {
                throw new ApplicationException("Stream not found.");
            }

            var streamBinding = new StreamBinding(
                streamMetadata.Name,
                streamMetadata.PartitionName,
                streamMetadata.PartitionName,
                streamMetadata.PartitionPath,
                typeof(SimpleReader),
                null,
                "Microsoft.Psi.Visualization.Summarizers.RangeSummarizer");

            return(vc.Show <PlotVisualizationObject, double, PlotVisualizationObjectConfiguration, TimelineVisualizationPanel>(streamBinding));
        }
        /// <summary>
        /// Shows an audio stream.
        /// </summary>
        /// <param name="stream">Aduio stream to show.</param>
        /// <param name="vc">The visualization client.</param>
        /// <param name="channel">The audio channel to show. Default is 0.</param>
        /// <returns>The newly created <see cref="StreamVisualizationObject{TData, TConfig}"/> used to show the stream.</returns>
        public static AudioVisualizationObject Show(this IProducer <AudioBuffer> stream, VisualizationClient vc, int channel = 0)
        {
            PsiStreamMetadata streamMetadata;

            if (!Store.TryGetMetadata(stream, out streamMetadata))
            {
                throw new ApplicationException("Stream not found.");
            }

            var streamBinding = new StreamBinding(
                streamMetadata.Name,
                streamMetadata.PartitionName,
                streamMetadata.PartitionName,
                streamMetadata.PartitionPath,
                typeof(SimpleReader),
                null,
                "Microsoft.Psi.Visualization.Summarizers.AudioSummarizer",
                new object[] { channel });

            return(vc.Show <AudioVisualizationObject, double, AudioVisualizationObjectConfiguration, TimelineVisualizationPanel>(streamBinding));
        }
Example #7
0
        /// <inheritdoc/>
        public override void EnsureDerivedStreamExists(StreamBinding streamBinding)
        {
            var memberPath = streamBinding.StreamAdapterArguments[0] as string;

            if (memberPath.StartsWith($"{this.MemberPath}."))
            {
                var remainingPath = memberPath.Substring(this.MemberPath.Length + 1);

                if (this.FindStreamTreeNode(remainingPath) == null)
                {
                    this.AddDerivedMemberStreamChildren();
                    this.ExpandAll();
                }

                if (remainingPath.Contains('.'))
                {
                    var pathItems = remainingPath.Split('.');
                    if (this.InternalChildren.FirstOrDefault(p => p.Name == pathItems.First()) is DerivedMemberStreamTreeNode memberChild)
                    {
                        memberChild.EnsureDerivedStreamExists(streamBinding);
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Opens a stream given a stream binding. Will close an open stream if needed.
        /// </summary>
        /// <param name="streamBinding">Stream binding inidicting which stream to open.</param>
        public void OpenStream(StreamBinding streamBinding)
        {
            string jsonStreamBinding = JsonConvert.SerializeObject(streamBinding);

            this.RemoteStreamVisualizationObject.OpenStream(jsonStreamBinding);
        }
        /// <inheritdoc/>
        public override void EnsureDerivedStreamExists(StreamBinding streamBinding)
        {
            var receiverId = (int)streamBinding.StreamAdapterArguments[0];

            this.AddDerivedReceiverDiagnosticsChildren(receiverId);
        }
            public static IBinding TryBuild <TUserType>(
                BindToStreamBindingProvider <TAttribute> parent,
                BindingProviderContext context)
            {
                // Allowed Param types:
                //  Stream
                //  any T with a Stream --> T conversion
                // out T, with a Out<Stream,T> --> void conversion

                var parameter     = context.Parameter;
                var parameterType = parameter.ParameterType;


                var attributeSource = TypeUtility.GetResolvedAttribute <TAttribute>(parameter);

                // Stream is either way; all other types are known.
                FileAccess?declaredAccess = GetFileAccessFromAttribute(attributeSource);

                Type argHelperType;
                bool isRead;

                IConverterManager cm     = parent._converterManager;
                INameResolver     nm     = parent._nameResolver;
                IConfiguration    config = parent._configuration;

                object converterParam = null;

                {
                    if (parameter.IsOut)
                    {
                        var outConverter = cm.GetConverter <ApplyConversion <TUserType, Stream>, object, TAttribute>();
                        if (outConverter != null)
                        {
                            converterParam = outConverter;
                            isRead         = false;
                            argHelperType  = typeof(OutArgBaseValueProvider <>).MakeGenericType(typeof(TAttribute), typeof(TUserType));
                        }
                        else
                        {
                            throw new InvalidOperationException($"No stream converter to handle {typeof(TUserType).FullName}.");
                        }
                    }
                    else
                    {
                        var converter = cm.GetConverter <Stream, TUserType, TAttribute>();
                        if (converter != null)
                        {
                            converterParam = converter;

                            if (parameterType == typeof(Stream))
                            {
                                if (!declaredAccess.HasValue)
                                {
                                    throw new InvalidOperationException("When binding to Stream, the attribute must specify a FileAccess direction.");
                                }
                                switch (declaredAccess.Value)
                                {
                                case FileAccess.Read:
                                    isRead = true;

                                    break;

                                case FileAccess.Write:
                                    isRead = false;
                                    break;

                                default:
                                    throw new NotImplementedException("ReadWrite access is not supported. Pick either Read or Write.");
                                }
                            }
                            else
                            {
                                // For backwards compat, we recognize TextWriter as write;
                                // anything else should explicitly set the FileAccess flag.
                                if (typeof(TextWriter).IsAssignableFrom(typeof(TUserType)))
                                {
                                    isRead = false;
                                }
                                else
                                {
                                    isRead = true;
                                }
                            }


                            argHelperType = typeof(ValueProvider <>).MakeGenericType(typeof(TAttribute), typeof(TUserType));
                        }
                        else
                        {
                            // This rule can't bind.
                            // Let another try.
                            context.BindingErrors.Add(String.Format(Resource.BindingAssemblyConflictMessage, typeof(Stream).AssemblyQualifiedName, typeof(TUserType).AssemblyQualifiedName));
                            return(null);
                        }
                    }
                }

                VerifyAccessOrThrow(declaredAccess, isRead);
                if (!parent.IsSupportedByRule(isRead))
                {
                    return(null);
                }

                var cloner = new AttributeCloner <TAttribute>(attributeSource, context.BindingDataContract, config, nm);

                ParameterDescriptor param;

                if (parent.BuildParameterDescriptor != null)
                {
                    param = parent.BuildParameterDescriptor(attributeSource, parameter, nm);
                }
                else
                {
                    param = new ParameterDescriptor
                    {
                        Name         = parameter.Name,
                        DisplayHints = new ParameterDisplayHints
                        {
                            Description = isRead ? "Read Stream" : "Write Stream"
                        }
                    };
                }

                var      fileAccess = isRead ? FileAccess.Read : FileAccess.Write;
                IBinding binding    = new StreamBinding(cloner, param, parent, argHelperType, parameterType, fileAccess, converterParam);

                return(binding);
            }
Example #11
0
        private void EnsurePartition(StreamBinding streamBinding)
        {
            var partition = this.currentSession.AddStorePartition(streamBinding.StoreName, streamBinding.StorePath, streamBinding.PartitionName);

            partition.Name = "Running";
        }
Example #12
0
 private void EnsurePartition(StreamBinding streamBinding)
 {
     this.currentSessionViewModel.AddStorePartition(streamBinding.StoreName, streamBinding.StorePath, streamBinding.PartitionName);
 }
Example #13
0
        /// <summary>
        /// Ensure the specified stream is currently open. If stream is not open, it will be upon retun.
        /// </summary>
        /// <param name="streamBinding">Stream binding inidicting which stream to open.</param>
        public void EnsureBinding(StreamBinding streamBinding)
        {
            string jsonStreamBinding = JsonConvert.SerializeObject(streamBinding);

            this.visualizationService.EnsureBinding(jsonStreamBinding);
        }