Esempio n. 1
0
        private void ProcessExport(IProgress <ExportProgressStatus> progress)
        {
            SequenceSessionData sessionData = new SequenceSessionData();

            if (_exporting)
            {
                if (SequenceNotify != null)
                {
                    SequenceNotify(ExportNotifyType.SAVING);
                }
                _generator.BeginGeneration();

                //IEnumerable<Guid> outIds = _generator.State.GetOutputIds();
                int periods = (int)_generator.Sequence.Length.TotalMilliseconds / _generator.Interval;    //outAggregator.GetCommandsForOutput(outIds.First()).Count() - 1;

                //Get a list of controller ids by index order
                IEnumerable <Guid> controllerIds = ControllerExportInfo.Where(x => x.IsActive).OrderBy(x => x.Index).Select(i => i.Id);

                var controllers = controllerIds.Select(controller => VixenSystem.OutputControllers.GetController(controller));

                //Now assemble a all their outputs by controller order.
                List <List <Guid> > controllerOutputs = controllers.Select(controller => controller.Outputs.Select(x => x.Id).ToList()).ToList();

                List <ICommand> commandList = new List <ICommand>(controllerOutputs.Count);
                _eventData = new List <byte>(controllerOutputs.Count);
                var progressData = new ExportProgressStatus(ExportProgressStatus.ProgressType.Task);
                if (_cancelling == false)
                {
                    sessionData.OutFileName   = OutFileName;
                    sessionData.NumPeriods    = periods;
                    sessionData.PeriodMS      = UpdateInterval;
                    sessionData.ChannelNames  = BuildChannelNames(controllers);
                    sessionData.TimeMS        = _generator.Sequence.Length.TotalMilliseconds;
                    sessionData.AudioFileName = AudioFilename;
                    try
                    {
                        _output.OpenSession(sessionData);
                        double j = 0;
                        while (_generator.HasNextInterval() && _cancelling == false)
                        {
                            if (progress != null)
                            {
                                progressData.TaskProgressValue   = (int)(j / periods * 100);
                                progressData.TaskProgressMessage = string.Format("Exporting {0}", _generator.Sequence.Name);
                                progress.Report(progressData);
                            }
                            commandList.Clear();
                            //Iterate the controller output groups.
                            foreach (var controller in controllerOutputs)
                            {
                                //Grab commands for each output
                                commandList.AddRange(controller.Select(guid => _generator.State.GetCommandForOutput(guid)));
                            }

                            UpdateState(commandList.ToArray());
                            _generator.NextInterval();
                            j++;
                        }

                        _output.CloseSession();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, @"Save Error!");
                        throw ex;
                    }
                    finally
                    {
                        _generator.EndGeneration();
                    }
                }

                if (SequenceNotify != null)
                {
                    SequenceNotify(ExportNotifyType.COMPLETE);
                }
            }
        }
Esempio n. 2
0
        void SequenceCacheEnded(object sender, Vixen.Cache.Event.CacheEventArgs e)
        {
            SequenceSessionData sessionData = new SequenceSessionData();

            if (_exporting)
            {
                List <ICommand>           commandList   = new List <ICommand>();
                OutputStateListAggregator outAggregator = _preCachingSequenceEngine.Cache.OutputStateListAggregator;
                IEnumerable <Guid>        outIds        = outAggregator.GetOutputIds();
                int periods = outAggregator.GetCommandsForOutput(outIds.First()).Count() - 1;

                //Get a list of controller ids by index order
                IEnumerable <Guid> controllers = ControllerExportInfo.OrderBy(x => x.Index).Select(i => i.Id);

                //Now assemble a all their outputs by controller order.
                List <List <Guid> > controllerOutputs = new List <List <Guid> >();
                foreach (var controller in controllers)
                {
                    controllerOutputs.Add(VixenSystem.OutputControllers.GetController(controller).Outputs.Select(x => x.Id).ToList());
                }

                if (_cancelling == false)
                {
                    SequenceNotify(ExportNotifyType.SAVING);
                    sessionData.OutFileName   = OutFileName;
                    sessionData.NumPeriods    = periods;
                    sessionData.PeriodMS      = UpdateInterval;
                    sessionData.ChannelNames  = BuildChannelNames(outIds);
                    sessionData.TimeMS        = _preCachingSequenceEngine.Sequence.Length.TotalMilliseconds;
                    sessionData.AudioFileName = AudioFilename;
                    try
                    {
                        _output.OpenSession(sessionData);
                        for (int j = 0; j < periods; j++)
                        {
                            SavePosition = Decimal.Round(((Decimal)j / (Decimal)periods) * 100, 2);
                            commandList.Clear();
                            //Iterate the controller output groups.
                            foreach (var controller in controllerOutputs)
                            {
                                //Grab commands for each output
                                foreach (Guid guid in controller)
                                {
                                    commandList.Add(outAggregator.GetCommandsForOutput(guid).ElementAt(j));
                                }
                            }

                            UpdateState(commandList.ToArray());
                        }

                        _output.CloseSession();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Save Error!");
                        throw ex;
                    }

                    _preCachingSequenceEngine.SequenceCacheEnded   -= SequenceCacheEnded;
                    _preCachingSequenceEngine.SequenceCacheStarted -= SequenceCacheStarted;
                }

                if (SequenceNotify != null)
                {
                    SequenceNotify(ExportNotifyType.COMPLETE);
                }
            }
        }