예제 #1
0
        public BroadcastViewModel(PeerCast peerCast)
        {
            this.peerCast   = peerCast;
            this.uiSettings = new UISettingsViewModel(PeerCastApplication.Current.Settings);
            start           = new Command(OnBroadcast, () => CanBroadcast(StreamSource, ContentType, channelName));
            contentTypes    = peerCast.ContentReaderFactories.ToArray();

            yellowPages = Enumerable.Repeat(new KeyValuePair <string, IYellowPageClient>("掲載なし", null), 1)
                          .Concat(peerCast.YellowPages.Select(yp => new KeyValuePair <string, IYellowPageClient>(yp.Name, yp)));
            if (contentTypes.Length > 0)
            {
                contentType = contentTypes[0];
            }

            this.SelectedSourceStream = SourceStreams.FirstOrDefault();
        }
예제 #2
0
        public override void Run()
        {
            var streams = SourceStreams.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
            var rawSize = 1024 * 1024 * ChunkSize;


            var key = Convert.FromBase64String(EncryptionKey);

            using (var output = CellarWriter.Create(OutputStream, rawSize, key)) {
                foreach (var stream in streams)
                {
                    var fetcher = GetFetcher(stream);


                    var inputPos = output.GetCheckpoint(stream + "-pos");


                    using (var cts = new CancellationTokenSource()) {
                        // launch reading
                        var task = fetcher.ReadAll(cts.Token, inputPos, int.MaxValue);


                        while (!cts.IsCancellationRequested)
                        {
                            var start  = Stopwatch.StartNew();
                            var result = task.Result;

                            if (result.ReadRecords <= 0)
                            {
                                break;
                            }
                            inputPos = result.CurrentPosition;
                            // launch next task in advance
                            task = fetcher.ReadAll(cts.Token, inputPos, int.MaxValue);

                            foreach (var message in result.Messages)
                            {
                                SaveMessage(message, output);
                            }

                            output.Checkpoint(stream + "-pos", inputPos);

                            var stats = output.EstimateSize();

                            var totalSize = streams.Sum(s => output.GetCheckpoint(s + "-pos"));

                            var compression = totalSize * 1D / stats.DiskSize;

                            var streamCompletion = 100F * result.CurrentPosition / result.MaxPosition;
                            start.Stop();

                            var bytes    = result.CurrentPosition - result.StartingPosition;
                            var mbpersec = 1D * bytes / 1024 / 1024 / start.Elapsed.TotalSeconds;

                            Console.WriteLine(
                                "{4}: {0:##0.0}% at {1:###.0}Mb/s. {2:000} chunks with {3:##.0}x compression",
                                streamCompletion, mbpersec,
                                stats.ChunkCount,
                                compression, stream);
                        }
                    }
                    var size = output.EstimateSize();
                    Console.WriteLine("Total records: {0} and {1} of data", size.Records,
                                      Print.Bytes(size.ByteSize));

                    output.Checkpoint("stream-pos", inputPos);
                    output.Checkpoint("raw-records", size.Records);
                    output.Checkpoint("raw-bytes", size.ByteSize);
                    output.Checkpoint("timestamp-secs", DateTimeOffset.UtcNow.ToUnixTimeSeconds());
                }

                Console.WriteLine("Done");
            }
        }