Exemplo n.º 1
0
        /// <summary>
        /// Pastes the copied project explorer items.
        /// </summary>
        private void PasteSelection()
        {
            if (this.ClipBoard == null || this.ClipBoard.Count() <= 0)
            {
                return;
            }

            ProjectExplorerViewModel.GetInstance().AddNewProjectItems(true, this.ClipBoard);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Export a project to separate files.
        /// </summary>
        public void ExportProject()
        {
            Task.Run(() =>
            {
                // Export the project items to thier own individual files
                try
                {
                    if (String.IsNullOrEmpty(this.ProjectFilePath) || !Directory.Exists(Path.GetDirectoryName(this.ProjectFilePath)))
                    {
                        OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Please save the project before exporting");
                        return;
                    }

                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Project export starting");

                    String folderPath = Path.Combine(Path.GetDirectoryName(this.ProjectFilePath), "Export");
                    Directory.CreateDirectory(folderPath);

                    Parallel.ForEach(
                        ProjectExplorerViewModel.GetInstance().ProjectItems,
                        SettingsViewModel.GetInstance().ParallelSettingsFast,
                        (projectItem) =>
                    {
                        ProjectItem targetProjectItem = projectItem;

                        if (targetProjectItem == null)
                        {
                            return;
                        }

                        String filePath = Path.Combine(folderPath, targetProjectItem.Name + ProjectItemStorage.ProjectFileExtension);

                        using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                        {
                            List <ProjectItem> newProjectRoot = new List <ProjectItem>();
                            newProjectRoot.Add(targetProjectItem);

                            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                            serializer.WriteObject(fileStream, newProjectRoot.ToArray());
                        }
                    });
                }
                catch (Exception ex)
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, "Unable to complete export project", ex);
                    AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                    return;
                }

                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Project export complete");
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Pastes the copied project explorer items.
        /// </summary>
        private void PasteSelection()
        {
            if (this.ClipBoard == null || this.ClipBoard.Count() <= 0)
            {
                return;
            }

            foreach (ProjectItem projectItem in this.ClipBoard)
            {
                // We must clone the item, such as to prevent duplicate references of the same exact object
                ProjectExplorerViewModel.GetInstance().AddNewProjectItems(true, projectItem.Clone());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Save a project to disk.
        /// </summary>
        public void SaveProject()
        {
            // Save the project file
            try
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter           = ProjectExplorerViewModel.ProjectExtensionFilter;
                saveFileDialog.Title            = "Save Project";
                saveFileDialog.FileName         = String.IsNullOrWhiteSpace(this.ProjectFilePath) ? String.Empty : Path.GetFileName(this.ProjectFilePath);
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.InitialDirectory = String.IsNullOrWhiteSpace(this.ProjectFilePath) ? String.Empty : Path.GetDirectoryName(this.ProjectFilePath);

                if (saveFileDialog.ShowDialog() == true)
                {
                    this.ProjectFilePath = saveFileDialog.FileName;

                    using (FileStream fileStream = new FileStream(this.ProjectFilePath, FileMode.Create, FileAccess.Write))
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                        serializer.WriteObject(fileStream, ProjectExplorerViewModel.GetInstance().ProjectItems.ToArray());
                    }

                    this.HasUnsavedChanges = false;
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, "Unable to save project", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }

            // Save the hotkey profile
            try
            {
                String hotkeyFilePath = this.GetHotkeyFilePathFromProjectFilePath(this.ProjectFilePath);

                using (FileStream fileStream = new FileStream(hotkeyFilePath, FileMode.Create, FileAccess.Write))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItemHotkey[]));
                    ProjectItemHotkey[]        hotkeys    = ProjectExplorerViewModel.GetInstance().ProjectItems?.Select(x => new ProjectItemHotkey(x.HotKey, x.Guid)).ToArray();
                    serializer.WriteObject(fileStream, hotkeys);
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to save hotkey profile", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Opens a project from disk.
        /// </summary>
        public void OpenProject()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = ProjectExtensionFilter;
            openFileDialog.Title  = "Open Project";

            if (openFileDialog.ShowDialog() == false)
            {
                return;
            }

            ProjectExplorerViewModel.GetInstance().ProjectItems = new FullyObservableCollection <ProjectItem>();
            this.ProjectFilePath = openFileDialog.FileName;

            // Open the project file
            try
            {
                if (!File.Exists(this.ProjectFilePath))
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to locate project.");
                    return;
                }

                using (FileStream fileStream = new FileStream(this.ProjectFilePath, FileMode.Open, FileAccess.Read))
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                    ProjectExplorerViewModel.GetInstance().ProjectItems = new FullyObservableCollection <ProjectItem>(serializer.ReadObject(fileStream) as ProjectItem[]);
                    this.HasUnsavedChanges = false;
                }
            }
            catch (Exception ex)
            {
                this.ProjectFilePath = String.Empty;
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to open project", ex.ToString());
                return;
            }

            // Open the hotkey file
            try
            {
                String hotkeyFilePath = this.GetHotkeyFilePathFromProjectFilePath(this.ProjectFilePath);

                if (File.Exists(hotkeyFilePath))
                {
                    using (FileStream fileStream = new FileStream(hotkeyFilePath, FileMode.Open, FileAccess.Read))
                    {
                        DataContractJsonSerializer serializer         = new DataContractJsonSerializer(typeof(ProjectItemHotkey[]));
                        ProjectItemHotkey[]        projectItemHotkeys = serializer.ReadObject(fileStream) as ProjectItemHotkey[];

                        this.BindHotkeys(ProjectExplorerViewModel.GetInstance().ProjectItems, projectItemHotkeys);
                    }
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Unable to open hotkey profile", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Imports a project from disk, adding the project items to the current project.
        /// </summary>
        /// <param name="filename">The file path of the project to import.</param>
        public void ImportProject(Boolean resetGuids = true, String filename = null)
        {
            // Ask for a specific file if one was not explicitly provided
            if (filename == null || filename == String.Empty)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = ProjectExtensionFilter;
                openFileDialog.Title  = "Import Project";

                if (openFileDialog.ShowDialog() == false)
                {
                    return;
                }

                filename = openFileDialog.FileName;

                // Clear the current project, such that on save the user is prompted to reselect this
                this.ProjectFilePath = null;
            }

            // Import the project file
            ProjectItem[] importedProjectRoot = null;

            try
            {
                if (!File.Exists(filename))
                {
                    OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to locate project.");
                    return;
                }

                using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(ProjectItem[]));
                    importedProjectRoot = deserializer.ReadObject(fileStream) as ProjectItem[];

                    // Add each high level child in the project root to this project
                    foreach (ProjectItem child in importedProjectRoot)
                    {
                        ProjectExplorerViewModel.GetInstance().AddNewProjectItems(false, importedProjectRoot);
                    }

                    this.HasUnsavedChanges = true;
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to import project", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }

            // Import the hotkey file
            try
            {
                String hotkeyFilePath = this.GetHotkeyFilePathFromProjectFilePath(filename);

                if (File.Exists(hotkeyFilePath))
                {
                    using (FileStream fileStream = new FileStream(hotkeyFilePath, FileMode.Open, FileAccess.Read))
                    {
                        DataContractJsonSerializer serializer         = new DataContractJsonSerializer(typeof(ProjectItemHotkey[]));
                        ProjectItemHotkey[]        projectItemHotkeys = serializer.ReadObject(fileStream) as ProjectItemHotkey[];

                        // Bind the hotkey to this project item
                        this.BindHotkeys(importedProjectRoot, projectItemHotkeys);
                    }
                }
            }
            catch (Exception ex)
            {
                OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Unable to open hotkey profile", ex);
                AnalyticsService.GetInstance().SendEvent(AnalyticsService.AnalyticsAction.General, ex);
                return;
            }

            // Randomize the guid for imported project items, preventing possible conflicts
            if (resetGuids && importedProjectRoot != null)
            {
                foreach (ProjectItem child in importedProjectRoot)
                {
                    child.ResetGuid();
                }
            }
        }