Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        private void InitializeContext()
        {
            _context = new EditorContext()
            {
                View = this,
                Renderers = new IRenderer[] { new PerspexRenderer() },
                ProjectFactory = new ProjectFactory(),
                TextClipboard = new TextClipboard(),
                Serializer = new NewtonsoftSerializer(),
                PdfWriter = new PdfWriter(),
                DxfWriter = new DxfWriter(),
                CsvReader = new CsvHelperReader(),
                CsvWriter = new CsvHelperWriter()
            };

            _context.Renderers[0].State.EnableAutofit = true;
            _context.InitializeEditor(new TraceLog(), System.IO.Path.Combine(GetAssemblyPath(), _logFileName));
            _context.Editor.Renderers[0].State.DrawShapeState.Flags = ShapeStateFlags.Visible;
            _context.Editor.GetImageKey = async () => await OnGetImageKey();

            _context.Commands.OpenCommand =
                Command<object>.Create(
                    async (parameter) => await OnOpen(parameter),
                    (parameter) => _context.IsEditMode());

            _context.Commands.SaveCommand =
                Command.Create(
                    async () => await OnSave(),
                    () => _context.IsEditMode());

            _context.Commands.SaveAsCommand =
                Command.Create(
                    async () => await OnSaveAs(),
                    () => _context.IsEditMode());

            _context.Commands.ExportCommand =
                Command<object>.Create(
                    async (item) => await OnExport(),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportDataCommand =
                Command<object>.Create(
                    async (item) => await OnImportData(),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportDataCommand =
                Command<object>.Create(
                    async (item) => await OnExportData(),
                    (item) => _context.IsEditMode());

            _context.Commands.UpdateDataCommand =
                Command<object>.Create(
                    async (item) => await OnUpdateData(),
                    (item) => _context.IsEditMode());
            
            _context.Commands.ImportStyleCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Style),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportStylesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Styles),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportStyleLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.StyleLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportStyleLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.StyleLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Group),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupsCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Groups),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.GroupLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportGroupLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.GroupLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportTemplateCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Template),
                    (item) => _context.IsEditMode());

            _context.Commands.ImportTemplatesCommand =
                Command<object>.Create(
                    async (item) => await OnImportObject(item, ImportType.Templates),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStyleCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Style),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStylesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Styles),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStyleLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.StyleLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportStyleLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.StyleLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Group),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupsCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Groups),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupLibraryCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.GroupLibrary),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportGroupLibrariesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.GroupLibraries),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportTemplateCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Template),
                    (item) => _context.IsEditMode());

            _context.Commands.ExportTemplatesCommand =
                Command<object>.Create(
                    async (item) => await OnExportObject(item, ExportType.Templates),
                    (item) => _context.IsEditMode());

            // TODO: Initialize other commands.

            if (_enableRecent)
            {
                try
                {
                    var path = System.IO.Path.Combine(GetAssemblyPath(), _recentFileName);
                    if (System.IO.File.Exists(path))
                    {
                        _context.LoadRecent(path);
                    }
                }
                catch (Exception ex)
                {
                    if (_context.Editor.Log != null)
                    {
                        _context.Editor.Log.LogError("{0}{1}{2}",
                            ex.Message,
                            Environment.NewLine,
                            ex.StackTrace);
                    }
                }
            }
            
            DataContext = _context;
        }