コード例 #1
0
ファイル: CoreLogger.cs プロジェクト: candyzkn/Dopamine
        private void Initialize()
        {
            // Initializing the connection also creates the database file if it doesn't exist yet.
            this.connection = new SQLiteConnection(System.IO.Path.Combine(LegacyPaths.LocalAppDataFolder(), "Logging.db"));

            // Check if the table exists. If not, create it.
            var tableExistsQuery = "SELECT name FROM sqlite_master WHERE type='table' AND name='LogEntry';";
            var result           = connection.ExecuteScalar <string>(tableExistsQuery);

            if (result == null)
            {
                this.connection.CreateTable <LogEntry>();
            }

            // Instantiate the logEntries queue
            this.logEntries = new ConcurrentQueue <LogEntry>();

            // Initialize the timers
            this.saveTimer          = new DispatcherTimer();
            this.saveTimer.Interval = new TimeSpan(0, 0, 0, 0, 10); // Every 10 milliseconds
            this.saveTimer.Tick    += SaveTimer_Tick;

            this.cleanupTimer          = new DispatcherTimer();
            this.cleanupTimer.Interval = new TimeSpan(0, 5, 0); // Every 5 minutes
            this.cleanupTimer.Tick    += CleanupTimer_Tick;
            this.cleanupTimer.Start();

            this.isInitialized = true;
        }
コード例 #2
0
        private async Task DeletePresetAsync()
        {
            if (this.dialogService.ShowConfirmation(
                    0xe11b,
                    16,
                    ResourceUtils.GetStringResource("Language_Delete_Preset"),
                    ResourceUtils.GetStringResource("Language_Delete_Preset_Confirmation").Replace("%preset%", this.SelectedPreset.Name),
                    ResourceUtils.GetStringResource("Language_Yes"),
                    ResourceUtils.GetStringResource("Language_No")))
            {
                try
                {
                    await Task.Run(() => {
                        string presetPath = System.IO.Path.Combine(LegacyPaths.AppData(), ProductInformation.ApplicationAssemblyName, ApplicationPaths.EqualizerSubDirectory, this.SelectedPreset.Name + FileFormats.EQUALIZERPRESET);
                        System.IO.File.Delete(presetPath);
                    });

                    this.ApplyManualPreset();
                    this.InitializeAsync();
                }
                catch (Exception ex)
                {
                    LogClient.Instance.Logger.Error("An error occured while deleting preset '{0}'. Exception: {1}", this.SelectedPreset, ex.Message);

                    this.dialogService.ShowNotification(
                        0xe711,
                        16,
                        ResourceUtils.GetStringResource("Language_Error"),
                        ResourceUtils.GetStringResource("Language_Error_While_Deleting_Preset"),
                        ResourceUtils.GetStringResource("Language_Ok"),
                        true,
                        ResourceUtils.GetStringResource("Language_Log_File"));
                }
            }
        }
コード例 #3
0
        private XmlSettingsClient()
        {
            this.timer          = new System.Timers.Timer(100); // a 10th of a second
            this.timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);

            // Check in BaseSettings.xml if we're using the portable application
            this.baseSettingsDoc = XDocument.Load(this.baseSettingsFile);

            if (this.applicationFolder == null)
            {
                bool isPortable = false;

                // Set the path of Settings.xml
                if (this.BaseTryGet <bool>("Application", "IsPortable", ref isPortable))
                {
                    // Sets the application folder
                    if (isPortable)
                    {
                        this.applicationFolder = System.IO.Path.Combine(ApplicationPaths.ExecutionFolder, ProductInformation.ApplicationAssemblyName);
                    }
                    else
                    {
                        this.applicationFolder = System.IO.Path.Combine(LegacyPaths.AppData(), ProductInformation.ApplicationAssemblyName);
                    }
                }
                else
                {
                    // By default, we save in the user's Roaming folder
                    this.applicationFolder = System.IO.Path.Combine(LegacyPaths.AppData(), ProductInformation.ApplicationAssemblyName);
                }

                this.TryCreateApplicationFolder();
            }

            this.settingsFile = System.IO.Path.Combine(ApplicationFolder, "Settings.xml");

            // Check if Settings.xml exists in the given path. If not,
            // create a new Settings.xml based on BaseSettings.xml
            if (!File.Exists(this.settingsFile))
            {
                File.Copy(this.baseSettingsFile, this.settingsFile);
            }

            try
            {
                // Load Settings.xml in memory
                this.settingsDoc = XDocument.Load(this.settingsFile);
            }
            catch (Exception)
            {
                // After a crash, the Settings file is sometimes empty.  If that
                // happens, copy the BaseSettings file (there is no way to restore
                // settings from a broken file anyway) and try to load the Settings
                // file again.
                File.Copy(this.baseSettingsFile, this.settingsFile, true);
                this.settingsDoc = XDocument.Load(this.settingsFile);
            }
        }
コード例 #4
0
        private async Task SavePresetToFileAsync()
        {
            var showSaveDialog = true;

            var dlg = new Microsoft.Win32.SaveFileDialog();

            dlg.FileName         = string.Empty;
            dlg.DefaultExt       = FileFormats.EQUALIZERPRESET;
            dlg.Filter           = string.Concat(ResourceUtils.GetStringResource("Language_Equalizer_Presets"), " (", FileFormats.EQUALIZERPRESET, ")|*", FileFormats.EQUALIZERPRESET);
            dlg.InitialDirectory = System.IO.Path.Combine(LegacyPaths.AppData(), ProductInformation.ApplicationAssemblyName, ApplicationPaths.EqualizerSubDirectory);

            while (showSaveDialog)
            {
                if ((bool)dlg.ShowDialog())
                {
                    int existingCount = this.presets.Select((p) => p).Where((p) => p.Name.ToLower() == System.IO.Path.GetFileNameWithoutExtension(dlg.FileName).ToLower() & !p.IsRemovable).Count();

                    if (existingCount > 0)
                    {
                        dlg.FileName = string.Empty;

                        this.dialogService.ShowNotification(
                            0xe711,
                            16,
                            ResourceUtils.GetStringResource("Language_Error"),
                            ResourceUtils.GetStringResource("Language_Preset_Already_Taken"),
                            ResourceUtils.GetStringResource("Language_Ok"),
                            false,
                            string.Empty);
                    }
                    else
                    {
                        showSaveDialog = false;

                        try
                        {
                            await Task.Run(() => {
                                System.IO.File.WriteAllLines(dlg.FileName, this.SelectedPreset.ToValueString().Split(';'));
                            });
                        }
                        catch (Exception ex)
                        {
                            LogClient.Instance.Logger.Error("An error occured while saving preset to file '{0}'. Exception: {1}", dlg.FileName, ex.Message);

                            this.dialogService.ShowNotification(
                                0xe711,
                                16,
                                ResourceUtils.GetStringResource("Language_Error"),
                                ResourceUtils.GetStringResource("Language_Error_While_Saving_Preset"),
                                ResourceUtils.GetStringResource("Language_Ok"),
                                true,
                                ResourceUtils.GetStringResource("Language_Log_File"));
                        }
                        XmlSettingsClient.Instance.Set <string>("Equalizer", "SelectedPreset", System.IO.Path.GetFileNameWithoutExtension(dlg.FileName));
                        this.InitializeAsync();
                    }
                }
                else
                {
                    showSaveDialog = false; // Makes sure the dialog doesn't re-appear when pressing cancel
                }
            }
        }
コード例 #5
0
ファイル: MigratorWorker.cs プロジェクト: one3chens/Knowte
        public void Execute()
        {
            Console.WriteLine("Migrator");
            Console.WriteLine("========");

            // First check Roaming\NoteStudio
            string noteStudioFolder = Path.Combine(LegacyPaths.AppData(), "NoteStudio");

            // If Roaming\NoteStudio doesn't exist, check Local\NoteStudio
            if (!Directory.Exists(noteStudioFolder))
            {
                noteStudioFolder = Path.Combine(LegacyPaths.LocalAppData(), "NoteStudio");
            }

            string notesSubfolder = Path.Combine(LegacyPaths.AppData(), ProductInformation.ApplicationDisplayName, "Notes");
            var    migrator       = new DbMigrator(notesSubfolder);

            if (Directory.Exists(noteStudioFolder))
            {
                if (!migrator.DatabaseExists())
                {
                    // Create the database if it doesn't exist
                    migrator.InitializeNewDatabase();
                }

                int noteCount     = 0;
                int notebookCount = 0;

                using (var conn = migrator.Factory.GetConnection())
                {
                    noteCount     = conn.Table <Note>().Count();
                    notebookCount = conn.Table <Notebook>().Count();
                }

                if (noteCount == 0 & notebookCount == 0)
                {
                    Console.WriteLine(Environment.NewLine + "NoteStudio installation found! Do you want to start importing Notes and Notebooks? [Y/N]");

                    ConsoleKeyInfo info = Console.ReadKey();

                    if (info.Key == ConsoleKey.Y)
                    {
                        // Get the Notebooks from the xml
                        String noteStudioXmlFilePath = System.IO.Path.Combine(noteStudioFolder, "NoteStudio.xml");

                        if (File.Exists(noteStudioXmlFilePath))
                        {
                            XDocument doc = XDocument.Load(noteStudioXmlFilePath);

                            List <Notebook> notebooks    = null;
                            List <Note>     notes        = null;
                            long            newNoteCount = 0;

                            Console.WriteLine(Environment.NewLine + "Importing. Please wait...");

                            try
                            {
                                // Add to database
                                newNoteCount = (from t in doc.Element("NoteStudio").Elements("Counters")
                                                select Convert.ToInt64(t.Attribute("UntitledCount").Value)).FirstOrDefault();

                                notebooks = (from t in doc.Element("NoteStudio").Element("Notebooks").Elements("Notebook")
                                             select new Notebook()
                                {
                                    Id = t.Attribute("Id").Value,
                                    Title = t.Attribute("Title").Value,
                                    CreationDate = DateTime.Parse(t.Attribute("CreationDate").Value).Ticks,
                                }).ToList();

                                notes = (from t in doc.Element("NoteStudio").Element("Notes").Elements("Note")
                                         select new Note()
                                {
                                    NotebookId = t.Attribute("NotebookId").Value,
                                    Id = t.Attribute("Id").Value,
                                    Text = t.Attribute("Text") == null ? "" : t.Attribute("Text").Value,
                                    Title = t.Attribute("Title").Value,
                                    CreationDate = t.Attribute("CreationDate") == null ? DateTime.Now.Ticks : DateTime.Parse(t.Attribute("CreationDate").Value).Ticks,
                                    OpenDate = t.Attribute("OpenDate") == null ? DateTime.Now.Ticks : DateTime.Parse(t.Attribute("OpenDate").Value).Ticks,
                                    ModificationDate = t.Attribute("ModificationDate") == null ? DateTime.Now.Ticks : DateTime.Parse(t.Attribute("ModificationDate").Value).Ticks,
                                    Flagged = t.Attribute("Flagged") == null ? 0 : Convert.ToBoolean(t.Attribute("Flagged").Value) ? 1 : 0,
                                    Maximized = t.Attribute("Maximized") == null ? 0 : Convert.ToBoolean(t.Attribute("Maximized").Value) ? 1 : 0,
                                    Width = t.Attribute("Width") == null ? Defaults.DefaultNoteWidth : Convert.ToInt32(t.Attribute("Width").Value),
                                    Height = t.Attribute("Height") == null ? Defaults.DefaultNoteHeight : Convert.ToInt32(t.Attribute("Height").Value),
                                    Top = t.Attribute("Top") == null ? Defaults.DefaultNoteTop : Convert.ToInt32(t.Attribute("Top").Value),
                                    Left = t.Attribute("Left") == null ? Defaults.DefaultNoteLeft : Convert.ToInt32(t.Attribute("Left").Value)
                                }).ToList();

                                using (var conn = migrator.Factory.GetConnection())
                                {
                                    // Notebooks
                                    foreach (Notebook notebook in notebooks)
                                    {
                                        conn.Insert(notebook);
                                    }

                                    // Notes
                                    foreach (Note note in notes)
                                    {
                                        conn.Insert(note);
                                    }
                                }

                                // Copy xaml files
                                string noteStudioNotesSubFolder = System.IO.Path.Combine(noteStudioFolder, "Notes");

                                if (Directory.Exists(noteStudioNotesSubFolder))
                                {
                                    // If the Notes subfolder doesn't exist, create it.
                                    if (!Directory.Exists(notesSubfolder))
                                    {
                                        Directory.CreateDirectory(notesSubfolder);
                                    }

                                    foreach (var file in Directory.GetFiles(noteStudioNotesSubFolder))
                                    {
                                        File.Copy(file, Path.Combine(notesSubfolder, Path.GetFileName(file)));
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine(Environment.NewLine + $"Import failed. Exception: {ex}");
                                Console.ForegroundColor = ConsoleColor.Gray;
                            }
                        }

                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine(Environment.NewLine + "Import complete!");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(Environment.NewLine + "Import not allowed as the Knowte database is not empty.");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
            }
            else
            {
                Console.WriteLine(Environment.NewLine + "NoteStudio installation not found.");
            }

            Console.WriteLine(Environment.NewLine + "Press any key to close this window...");
            Console.ReadKey();
        }