Пример #1
0
        public void PrepareDictionaries()
        {
            // Load plugin into lexer if we have plugin
            string jsonPluginContent;
            string pluginDir  = mediator.Config.StyleDirectoryPath;
            string pluginPath = IOTools.CombinePath(pluginDir, mediator.currentLanguage.Language);

            pluginPath = IOTools.ChangeExtension(pluginPath, Lexer.EXT);
            if (IOTools.ReadAllText(pluginPath, out jsonPluginContent))
            {
                lexer.LoadPlugin(jsonPluginContent);
            }
            // Load dictionaries
            foreach (string path in dictPathes)
            {
                Log.Logger.Debug(string.Format("Analyzing with: {0}", path));
                string content;
                if (IOTools.ReadAllText(path, out content))
                {
                    lexer.LoadDictionary(content);
                }
            }
            // Expand dictionary
            lexer.ExpandDictionary();
        }
Пример #2
0
        public static void Configure(IUIMainWindowService windowService)
        {
            MainModel model = MainModel.Instance;

            model.Storage = new Storage(windowService.AppDir);
            model.Config.CommonDictionaryName = windowService.CommonDictionaryName;
            model.Config.CorpusDir            = windowService.CorpusDir;
            model.Config.DicDir             = windowService.DicDir;
            model.Config.OutDir             = windowService.OutDir;
            model.Config.StyleDirectoryPath = IOTools.CombinePath(Directory.GetCurrentDirectory(), "plugins");
        }
Пример #3
0
        public void LoadStyle()
        {
            // Load CSS file
            string cssContent;
            string cssDir  = mediator.Config.StyleDirectoryPath;
            string cssPath = IOTools.CombinePath(cssDir, mediator.currentLanguage.Language);

            cssPath = IOTools.ChangeExtension(cssPath, HTMLPrinter.STYLEEXT);
            if (IOTools.ReadAllText(cssPath, out cssContent))
            {
                printer.LoadCSS(cssContent);
            }
        }
Пример #4
0
        /// <summary>
        /// Prepares environmental settings for app and starts.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ApplicationStartup(object sender, StartupEventArgs e)
        {
            // Get app name from config file
            string appName = Tools.ReadSetting("appName");

            if (string.IsNullOrWhiteSpace(appName))
            {
                MessageBox.Show("Error reading app settings.\nLangTools can't start.");
                return;
            }

            // Get app directory
            string appDir;

            try
            {
                appDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            }
            catch (PlatformNotSupportedException)
            {
                MessageBox.Show("Platform is not supported.\nLangTools can't start.");
                return;
            }
            appDir = IOTools.CombinePath(appDir, appName);
            // Save application directory path for later
            Current.Properties["appDir"] = appDir;

            // Create directory if not exist
            if (!IOTools.CreateDirectory(appDir))
            {
                MessageBox.Show(string.Format("Something bad happened in {0} directory.\nLangTools can't start.", appDir));
                return;
            }

            // Make sure VM is ready to start.
            if (!VMBoot.IsReadyToLoad(appDir))
            {
                MessageBox.Show(string.Format("Can't start the app."));
                return;
            }

            Log.Logger.Debug("----The new session has started.----");

            // Start the main window
            MainWindow wnd = new MainWindow();

            wnd.Title = appName;
            wnd.Show();
        }
Пример #5
0
        /// <summary>
        /// Sets new project as current.
        /// </summary>
        /// <param name="project"></param>
        public void SelectProject(string project)
        {
            // language might be null during the proccess
            // of changing language.
            if (currentLanguage == null)
            {
                return;
            }

            Log.Logger.Debug("New project is chosen.");
            currentProject = project;
            // Get custom project dictionaries
            IEnumerable <string> projectSpecificDics;

            if (IOTools.ListFiles(Config.ProjectDicPath, out projectSpecificDics))
            {
                // Add found dictionaries to dict collection.
                foreach (string fName in projectSpecificDics)
                {
                    Dictionaries.Add(new Dict
                    {
                        FileName = fName,
                        DictType = DictType.Project,
                        FilePath = IOTools.CombinePath(Config.ProjectDicPath, fName)
                    });
                }
            }

            // Get general project dictionaries.
            IEnumerable <string> generalDics;

            if (IOTools.ListFiles(Config.GenDicPath, out generalDics))
            {
                // Combine both specific and general dictionaries
                foreach (string fName in generalDics)
                {
                    Dictionaries.Add(new Dict
                    {
                        FileName = fName,
                        DictType = DictType.General,
                        FilePath = IOTools.CombinePath(Config.GenDicPath, fName)
                    });
                }
            }

            // Get file names from project dir
            IEnumerable <string> fileNames;

            if (!IOTools.ListFiles(Config.ProjectFilesPath, out fileNames))
            {
                // Can't reach the folder, no sense to proceed further.
                return;
            }

            // Create FileStats object for every file name
            IEnumerable <FileStats> inDir = fileNames.Select(fName => new FileStats(
                                                                 fName,
                                                                 IOTools.CombinePath(Config.ProjectFilesPath, fName),
                                                                 currentLanguage,
                                                                 project
                                                                 ));

            // Get list of objects from DB
            List <FileStats> inDB = Storage.GetFilesStats(currentLanguage, project);

            // NB: inDB.Intersect will return elements from inDB.
            // Need this order since they have more information.
            foreach (FileStats item in inDB.Intersect(inDir))
            {
                // Files from DB have output page already
                item.OutPath = printer.GetOutPath(item.FileName);
                Files.Add(item);
            }

            // Add files that we have in dir but no stats in DB
            foreach (FileStats item in inDir.Except(inDB))
            {
                Files.Add(item);
            }

            // Remove leftover stats from DB.
            foreach (FileStats item in inDB.Except(inDir))
            {
                Log.Logger.Debug(string.Format("Going to remove {0} from DB", item.FileName));
                Storage.RemoveFileStats(item);
            }
            // Start watching files in the project.
            watcher.ToggleOnProject(Config.ProjectDicPath, Config.GenDicPath, Config.ProjectFilesPath);
        }
Пример #6
0
        /// <summary>
        /// Provides path to an output file created for a given fileName
        /// of the current project.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public string GetOutPath(string fileName)
        {
            string outName = IOTools.ChangeExtension(fileName, HTMLPrinter.EXT);

            return(IOTools.CombinePath(mediator.Config.ProjectOutPath, outName));
        }