示例#1
0
        public async override Task <Result> ExportAsync(string fileName, CancellationToken cancellationToken)
        {
            var cmdCount = 0;

            using (var context = new ZvsContext(EntityContextConnection))
            {
                var existingScenes = await context.Scenes
                                     .Include(o => o.Commands)
                                     .ToListAsync(cancellationToken);

                var backupScenes = new List <SceneBackup>();
                foreach (var s in existingScenes)
                {
                    var sceneBackup = new SceneBackup {
                        Name = s.Name
                    };

                    foreach (var scmd in s.Commands)
                    {
                        var sceneCmdBackup = new SceneCMDBackup
                        {
                            Order         = scmd.SortOrder,
                            StoredCommand = await StoredCmdBackup.ConvertToBackupCommand(scmd)
                        };
                        sceneBackup.Commands.Add(sceneCmdBackup);
                        cmdCount++;
                    }
                    backupScenes.Add(sceneBackup);
                }

                var saveResult = await SaveAsXmlToDiskAsync(backupScenes, fileName);

                if (saveResult.HasError)
                {
                    return(Result.ReportError(saveResult.Message));
                }

                return(Result.ReportSuccessFormat("Exported {0} scenes with {1} scene commands to {2}",
                                                  backupScenes.Count,
                                                  cmdCount,
                                                  Path.GetFileName(fileName)));
            }
        }
        public async override Task<Result> ExportAsync(string fileName, CancellationToken cancellationToken)
        {
            var cmdCount = 0;
            using (var context = new ZvsContext(EntityContextConnection))
            {
                var existingScenes = await context.Scenes
                    .Include(o => o.Commands)
                    .ToListAsync(cancellationToken);

                var backupScenes = new List<SceneBackup>();
                foreach (var s in existingScenes)
                {
                    var sceneBackup = new SceneBackup {Name = s.Name};

                    foreach (var scmd in s.Commands)
                    {
                        var sceneCmdBackup = new SceneCMDBackup
                        {
                            Order = scmd.SortOrder,
                            StoredCommand = await StoredCmdBackup.ConvertToBackupCommand(scmd)
                        };
                        sceneBackup.Commands.Add(sceneCmdBackup);
                        cmdCount++;
                    }
                    backupScenes.Add(sceneBackup);
                }

                var saveResult = await SaveAsXmlToDiskAsync(backupScenes, fileName);

                if (saveResult.HasError)
                    return Result.ReportError(saveResult.Message);

                return Result.ReportSuccessFormat("Exported {0} scenes with {1} scene commands to {2}",
                    backupScenes.Count,
                    cmdCount,
                    Path.GetFileName(fileName));
            }
        }