Exemplo n.º 1
0
        private List <Photo> Photos(List <IFormFile> files)
        {
            DirectoryManagement dm     = new DirectoryManagement();
            List <Photo>        photos = new List <Photo>();

            foreach (var file in files)
            {
                if (file.Length > 0 && file != null)
                {
                    var path = dm.GetFolderPath();

                    var fileName = FileNameManipulator.GenerateName();
                    var fullPath = Path.Combine(path, fileName);
                    var fileType = Path.GetExtension(file.FileName);

                    photos.Add(new Photo()
                    {
                        ImageType = fileType, PhotoDir = fullPath
                    });

                    using (var str = new FileStream(fullPath + fileType, FileMode.Create))
                    {
                        file.CopyTo(str);
                    }
                }
            }
            return(photos);
        }
Exemplo n.º 2
0
        private void AddDirectoryButton_Click(object sender, EventArgs e)
        {
            //_directoryPicker = new DirectoryPicker();
            _directoryPicker = new FolderBrowserDialog();
            _directoryPicker.ShowNewFolderButton = false;
            _directoryPicker.Description         = "Please select a directory:";

            ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
            string actual_path = UserContext.Instance.GetExplorerPath(true);

            if (data.FileList != null && data.FileList.Length > 0 && Directory.Exists(data.FileList[0]))
            {
                _directoryPicker.SelectedPath = data.FileList[0];
            }
            else if (actual_path != CommonInfo.UserDesktop)
            {
                _directoryPicker.SelectedPath = actual_path;
            }
            else if (data.Text != null && Directory.Exists(data.Text))
            {
                _directoryPicker.SelectedPath = data.Text;
            }

            if (_directoryPicker.ShowDialog() == DialogResult.OK)
            {
                //string dir = _directoryPicker.directoryInput.Text;
                string dir = (CommonInfo.IsPortable ? FileNameManipulator.RelativePath(_directoryPicker.SelectedPath, Environment.CurrentDirectory) : _directoryPicker.SelectedPath);
                if (dir[dir.Length - 1] != '\\')
                {
                    dir += "\\";
                }
                if (_directories.Contains(dir))
                {
                    DialogResult res = MessageBox.Show("This directory has already been added. Do you want to pick a different one?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (res == DialogResult.Yes)
                    {
                        AddDirectoryButton_Click(sender, e);
                    }
                    return;
                }
                _directories.Add(dir);
                _extensions.Add(dir, new List <string>());
                _indexSubdirectories.Add(dir, false);
                _includeDirectories.Add(dir, false);
                _dirPlugins.Add(dir, new List <string>());
                DirectoriesListBox.Items.Clear();
                DirectoriesListBox.Items.AddRange(_directories.ToArray());
                FileTypesListBox.Items.Clear();
                FileTypesListBox.Items.AddRange(_extensions[dir].ToArray());
                //IncludeSubDirCheckBox.Checked = _indexSubdirectories[dir];
                OptionsListBox.SetItemChecked(1, _indexSubdirectories[dir]);
                OptionsListBox.SetItemChecked(0, _includeDirectories[dir]);
            }
            _directoryPicker.Dispose();
            _directoryPicker = null;
        }
Exemplo n.º 3
0
 private void EnginePicker_Load(object sender, EventArgs e)
 {
     _tooltip           = new ToolTip();
     _tooltip.IsBalloon = true;
     //_tooltip.ShowAlways = true;
     _tooltip.Active       = true;
     _tooltip.ToolTipIcon  = ToolTipIcon.Error;
     _tooltip.ToolTipTitle = "Error";
     //_tooltip.AutoPopDelay = 3000;
     _tooltip.InitialDelay = 0;
     //_tooltip.ReshowDelay = 500;
     ContextLib.DataContainers.Multimedia.MultiLevelData data = UserContext.Instance.GetSelectedContent();
     if (data.FileList != null && data.FileList.Length > 0)
     {
         string path = data.FileList[data.FileList.Length - 1];
         if (File.Exists(path))
         {
             FileInfo info = new FileInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFileName(info.Name);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
         else if (Directory.Exists(path))
         {
             DirectoryInfo info = new DirectoryInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFolderName(path);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
     }
     if (data.Text != null && data.Text.Trim() != string.Empty)
     {
         string path = data.Text.Trim();
         if (File.Exists(path))
         {
             FileInfo info = new FileInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFileName(info.Name);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
         else if (Directory.Exists(path))
         {
             DirectoryInfo info = new DirectoryInfo(path);
             nameTextBox.Text = FileNameManipulator.GetFolderName(path);
             pathTextBox.Text = path;
             data.Dispose();
             return;
         }
     }
     data.Dispose();
 }
Exemplo n.º 4
0
        private void browseButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();

            if (File.Exists(pathTextBox.Text))
            {
                FileInfo info = new FileInfo(pathTextBox.Text);
                fd.InitialDirectory = info.DirectoryName;
            }
            else
            {
                fd.InitialDirectory = CommonInfo.UserHomeDrive;
            }
            //fd.Filter = "exe files (*.exe)|*.exe|All files (*.*)|*.*";
            fd.Filter           = "All files (*.*)|*.*";
            fd.Multiselect      = false;
            fd.RestoreDirectory = true;
            if (fd.ShowDialog() == DialogResult.OK)
            {
                nameTextBox.Text = FileNameManipulator.GetFileName(fd.SafeFileName);
                pathTextBox.Text = fd.FileName;
            }
        }
Exemplo n.º 5
0
        public List <string> RetrieveItems(string input)
        {
            best_paths = new List <string>();
            if (_regex.IsMatch(input))
            {
                // Get all directories
                string dir = input;
                // Ad a '\' do the drive letter if needed
                if (dir.Length == 2)
                {
                    dir += '\\';
                }
                // Solve incomplete paths
                while (!Directory.Exists(dir) || dir[dir.Length - 1] != '\\')
                {
                    int i = dir.IndexOf('\\');
                    int f = dir.LastIndexOf('\\');
                    // If there is no '\' in the path or there is only one '\', which means an invalid drive letter, return empy index
                    if (f == -1 || (f == i && f == dir.Length - 1))
                    {
                        return(best_paths);
                    }
                    else if (f == dir.Length - 1) // If it is and invalid path, trim the string (of '\') and validade it again
                    {
                        dir = dir.Substring(0, f);
                    }
                    else
                    {
                        dir = dir.Substring(0, f + 1);
                    }
                }
                // Add root to index
                if (input.Length <= dir.Length)
                {
                    best_paths.Add(dir);
                }

                string[]         available_directories;
                string[]         available_files;
                HashSet <string> accepted_directories = new HashSet <string>();
                HashSet <string> accepted_files       = new HashSet <string>();
                try
                {
                    // Get all directories
                    available_directories = Directory.GetDirectories(FileNameManipulator.GetPath(dir));
                    // Get all files
                    available_files = FileSearcher.SearchFullNames(dir, false, false, false);
                }
                catch /*(Exception e)*/
                {
                    //MessageBox.Show(e.Message);
                    return(best_paths);
                }

                // For each directory
                for (int i = 0; i < available_directories.Length; i++)
                {
                    string directory = available_directories[i];
                    directory += "\\";
                    if (!string.IsNullOrEmpty(directory) &&
                        !accepted_directories.Contains(directory) &&
                        SystemCore.SystemAbstraction.StringUtilities.StringUtility.WordContainsStr(directory, input))
                    {
                        // Add directory path
                        accepted_directories.Add(directory);
                    }
                }
                // For each file
                for (int i = 0; i < available_files.Length; i++)
                {
                    string file = available_files[i];
                    if (!string.IsNullOrEmpty(file) &&
                        !accepted_files.Contains(file) &&
                        SystemCore.SystemAbstraction.StringUtilities.StringUtility.WordContainsStr(file, input))
                    {
                        // Add file path
                        accepted_files.Add(file);
                    }
                }
                List <string> acc_dir_lst = accepted_directories.ToList();
                List <string> acc_fil_lst = accepted_files.ToList();

                acc_dir_lst.Sort();
                acc_fil_lst.Sort();

                best_paths.AddRange(acc_dir_lst.Union(acc_fil_lst));

                available_directories = null;
                available_files       = null;
                acc_dir_lst           = null;
                acc_fil_lst           = null;
            }
            return(best_paths);
        }
Exemplo n.º 6
0
        public List <InterpreterItem> RetrieveTopItems(string text)
        {
            List <InterpreterItem> ret                  = new List <InterpreterItem>();
            string                   user_text          = text.Trim().ToLower();
            List <string>            assisting_commands = new List <string>();
            List <string>            assisting_plugins  = new List <string>();
            List <InterpreterPlugin> plugins            = new List <InterpreterPlugin>(_plugins);

            plugins.Add(_menuEngine);
            bool filesystem_assisted = false;

            // take care of high priority commands
            foreach (InterpreterPlugin plugin in plugins)
            {
                Command command = plugin.GetAssistingCommand(Command.PriorityType.High, text);
                if (command != null)
                {
                    InterpreterItem item = new InterpreterItem(plugin.GetItemName(command.Name, text, null),
                                                               plugin.GetItemDescription(command.Name, text, null),
                                                               plugin.GetItemAutoComplete(command.Name, text, null),
                                                               plugin.GetItemIcon(command.Name, text, null),
                                                               InterpreterItem.OwnerType.Plugin,
                                                               user_text);
                    item.CommandName   = command.Name;
                    item.CommandTokens = null;
                    item.CommandUsage  = plugin.GetUsage(command.Name, text, null);
                    item.PluginId      = plugin.Name;
                    assisting_commands.Add(plugin.Name);
                    ret.Add(item);
                }
            }

            if (_systemBrowser.IsOwner(user_text))
            {
                //List<string> user_tokens = new List<string>();
                //user_tokens.Add(user_text.ToLower());

                //Dictionary<string, double> distances = new Dictionary<string, double>();
                //Dictionary<string, string[]> displacements = new Dictionary<string, string[]>();
                //List<string> suited_names = new List<string>();
                //List<string> min_names = new List<string>();

                List <string> paths = _systemBrowser.RetrieveItems(user_text);
                //paths.Sort();

                //Dictionary<string, List<string>> keywords = new Dictionary<string, List<string>>();
                //foreach (string s in paths)
                //    keywords.Add(s, new List<string>(new string[] { s.ToLower() }));

                //TextPredictor.Instance.PredictNamesAndDistance(user_text, user_tokens, paths, keywords, ref suited_names, ref distances, ref displacements, false);

                //while (suited_names.Count > 0)
                //{
                //    string min_name = string.Empty;
                //    for (int i = 0; i < suited_names.Count; i++)
                //    {
                //        if (min_name == string.Empty)
                //        {
                //            min_name = suited_names[i];
                //        }
                //        else if (distances[min_name] > distances[suited_names[i]])
                //        {
                //            min_name = suited_names[i];
                //        }
                //    }
                //    if (min_name != string.Empty)
                //    {
                //        min_names.Add(min_name);
                //        suited_names.Remove(min_name);
                //    }
                //}

                foreach (string s in paths)
                {
                    ret.Add(new InterpreterItem(FileNameManipulator.GetFolderName(s),
                                                s,
                                                s,
                                                _systemBrowser.GetItemIcon(s),
                                                InterpreterItem.OwnerType.FileSystem,
                                                user_text));
                }

                // clean up
                //user_tokens = null;
                //distances = null;
                //suited_names = null;
                //min_names = null;
                paths = null;
                //keywords = null;

                filesystem_assisted = true;
            }
            if (!filesystem_assisted)
            {
                List <string> user_tokens      = new List <string>(StringUtility.GenerateKeywords(user_text, true, true));
                int           user_tokens_size = user_tokens.Count;

                Index index = _fileIndexer.RetrieveItems();
                //_commandCache.Update(plugins);
                //index.Merge(_commandCache.Index);
                if (!_fileIndexer.IsCacheMerged)
                {
                    Predictor.Instance.InvalidateCache();
                }
                if (_commandCache.NeedsUpdate() || !_fileIndexer.IsCacheMerged)
                {
                    _commandCache.Update(plugins);
                    index.Merge(_commandCache.Index);
                    _fileIndexer.IsCacheMerged = true;
                }

                Dictionary <IndexItem, List <string> > tokens = null;
                LearnedContent learned_commands = SettingsManager.Instance.GetLearnedContents();
                IndexItem[]    items            = Predictor.Instance.GetBestItems(index, user_text, user_tokens, ref tokens, learned_commands);
                // TODO
                foreach (IndexItem i in items)
                {
                    // take care of medium priority commands
                    string   command_name       = i.Name;
                    string[] item_tokens        = tokens[i].ToArray();
                    bool     assisted_by_plugin = false;
                    foreach (InterpreterPlugin plugin in _plugins)
                    {
                        if (command_name == string.Empty)
                        {
                            continue;
                        }
                        Command command = plugin.GetCommandByName(command_name);
                        if (command != null && command.FitsPriority(Command.PriorityType.Medium) /*&& !assisting_plugins.Contains(plugin.Name)*/ && !assisting_commands.Contains(command_name))
                        {
                            InterpreterItem item = new InterpreterItem(plugin.GetItemName(command_name, text, item_tokens),
                                                                       plugin.GetItemDescription(command_name, text, item_tokens),
                                                                       plugin.GetItemAutoComplete(command_name, text, item_tokens),
                                                                       plugin.GetItemIcon(command_name, text, item_tokens),
                                                                       InterpreterItem.OwnerType.Plugin,
                                                                       user_text);
                            item.CommandName   = command_name;
                            item.CommandTokens = item_tokens;
                            item.CommandUsage  = plugin.GetUsage(command.Name, text, item_tokens);
                            item.PluginId      = plugin.Name;
                            assisting_commands.Add(command_name);
                            ret.Add(item);
                            assisted_by_plugin = true;
                        }
                    }
                    if (!assisted_by_plugin)
                    {
                        if (_menuEngine.IsOwner(i.Name))
                        {
                            InterpreterItem item = new InterpreterItem(command_name,
                                                                       _menuEngine.GetItemDescription(command_name, user_text, item_tokens),
                                                                       command_name,
                                                                       _menuEngine.GetItemIcon(command_name, text, item_tokens),
                                                                       InterpreterItem.OwnerType.Menu,
                                                                       user_text);
                            item.CommandName   = command_name;
                            item.CommandTokens = item_tokens;
                            item.CommandUsage  = _menuEngine.GetUsage(command_name, text, item_tokens);
                            ret.Add(item);
                            item = null;
                        }
                        else
                        {
                            ret.Add(new InterpreterItem(i.Name, i.Path, i.Name, i.GetIcon(), InterpreterItem.OwnerType.Indexer, user_text));
                        }
                    }
                }
            }

            // take care of low priority commands
            foreach (InterpreterPlugin plugin in _plugins)
            {
                Command command = plugin.GetAssistingCommand(Command.PriorityType.Low, text);
                if (command != null /*&& !assisting_plugins.Contains(plugin.Name)*/ && !assisting_commands.Contains(command.Name))
                {
                    InterpreterItem item = new InterpreterItem(plugin.GetItemName(command.Name, text, null),
                                                               plugin.GetItemDescription(command.Name, text, null),
                                                               plugin.GetItemAutoComplete(command.Name, text, null),
                                                               plugin.GetItemIcon(command.Name, text, null),
                                                               InterpreterItem.OwnerType.Plugin,
                                                               user_text);
                    item.CommandName   = command.Name;
                    item.CommandTokens = null;
                    item.CommandUsage  = plugin.GetUsage(command.Name, text, null);
                    item.PluginId      = plugin.Name;
                    assisting_commands.Add(command.Name);
                    ret.Add(item);
                    item = null;
                }
            }

            //LearnedContent lc = SettingsManager.Instance.GetLearnedContents();
            //int pos = 0;
            //foreach (string token in lc.GetSortedKeywords(user_text))
            //{
            //    int curr_pos = -1;
            //    string distinguisher = lc.Distinguishers[token];
            //    switch (lc.Types[token])
            //    {
            //        case InterpreterItem.OwnerType.Indexer:
            //            curr_pos = ret.FindIndex(delegate(InterpreterItem a)
            //            {
            //                return a.Desciption == distinguisher;
            //            });
            //            break;
            //        default:
            //            curr_pos = ret.FindIndex(delegate(InterpreterItem a)
            //            {
            //                return a.Name == distinguisher;
            //            });
            //            break;
            //    }
            //    if (curr_pos != -1)
            //    {
            //        InterpreterItem to_insert = ret[curr_pos];
            //        ret.RemoveAt(curr_pos);
            //        ret.Insert(0, to_insert);
            //        pos++;
            //    }
            //}

            user_text          = null;
            assisting_commands = null;
            return(ret);
        }
Exemplo n.º 7
0
        public void BuildIndex()
        {
            DirInfo       info        = SettingsManager.Instance.GetDirectories();
            List <string> directories = info.Directories;
            Dictionary <string, List <string> > extensions          = info.Extensions;
            Dictionary <string, bool>           includeDirectories  = info.IncludeDirectories;
            Dictionary <string, bool>           indexSubdirectories = info.IndexSubdirectories;

            _index.StartBuilding();
            for (int i = 0; i < directories.Count; i++)
            {
                string               directory = directories[i];
                List <string>        ext       = new List <string>(extensions[directory]);
                List <string>        fullpathes;
                List <IndexerPlugin> assistingPlugins = new List <IndexerPlugin>();

                foreach (IndexerPlugin plugin in _plugins)
                {
                    if (SettingsManager.Instance.GetDirectories().Plugins[directory].Contains(plugin.Name))
                    {
                        assistingPlugins.Add(plugin);
                        ext.AddRange(plugin.Extensions);
                    }
                }

                try
                {
                    fullpathes = new List <string>(FileSearcher.SearchFullNames(Environment.ExpandEnvironmentVariables(directory), ext, indexSubdirectories[directory], includeDirectories[directory], (CommonInfo.IsPortable ? true : false)));
                }
                catch (Exception)
                {
                    fullpathes = new List <string>();
                }

                for (int j = 0; j < fullpathes.Count; j++)
                {
                    string path = fullpathes[j];
                    string name = FileNameManipulator.GetFileName(Directory.Exists(path)
                                       ? Path.GetDirectoryName(path)
                                       : path);
                    Bitmap icon = null;
                    try
                    {
                        icon = IconManager.RetrieveIcon(path).ToBitmap();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    if (icon == null)
                    {
                        continue;
                    }

                    List <string> list_keywords = new List <string>(StringUtility.GenerateKeywords(name, true, true));
                    foreach (string key in list_keywords)
                    {
                        _index.AddEntry(key, name, list_keywords.Count, path, icon, false);
                    }
                    list_keywords.Clear();
                    foreach (IndexerPlugin plugin in assistingPlugins)
                    {
                        string[] tmp_keywords = plugin.GetFileKeywords(path);
                        foreach (string key in tmp_keywords)
                        {
                            list_keywords.AddRange(StringUtility.GenerateKeywords(key, true, true));
                        }
                    }
                    foreach (string key in list_keywords)
                    {
                        _index.AddEntry(key, name, list_keywords.Count, path, icon, false);
                    }
                }
            }

            _index.FinishBuilding();

            // clean up
            directories         = null;
            extensions          = null;
            indexSubdirectories = null;
            GC.Collect();
        }