Ejemplo n.º 1
0
 public bool Equals(OptimizationLibrary other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(base.Equals(other) && Equals(other._database, _database) && Equals(other.DatabasePath, DatabasePath));
 }
Ejemplo n.º 2
0
 private OptimizationLibrary LoadLibrary(IDocumentContainer container, OptimizationLibrary lib)
 {
     // TODO: Something better than locking for the entire load
     lock (_loadedLibraries)
     {
         OptimizationLibrary libResult;
         if (!_loadedLibraries.TryGetValue(lib.Name, out libResult))
         {
             libResult = lib.Initialize(container.Document, new LoadMonitor(this, container, lib));
             if (libResult != null)
             {
                 _loadedLibraries.Add(libResult.Name, libResult);
             }
         }
         return(libResult);
     }
 }
Ejemplo n.º 3
0
 private OptimizationLibrary LoadLibrary(IDocumentContainer container, OptimizationLibrary lib)
 {
     // TODO: Something better than locking for the entire load
     lock (_loadedLibraries)
     {
         OptimizationLibrary libResult;
         if (!_loadedLibraries.TryGetValue(lib.Name, out libResult))
         {
             libResult = lib.Initialize(container.Document, new LoadMonitor(this, container, lib));
             if (libResult != null)
                 _loadedLibraries.Add(libResult.Name, libResult);
         }
         return libResult;
     }
 }
Ejemplo n.º 4
0
        private OptimizationLibrary FindOptimizationDatabase(string documentPath, OptimizationLibrary optLib)
        {
            OptimizationLibrary result;
            if (Settings.Default.OptimizationLibraryList.TryGetValue(optLib.Name, out result))
            {
                if (result.IsNone || File.Exists(result.DatabasePath))
                    return result;
            }

            // First look for the file name in the document directory
            string fileName = Path.GetFileName(optLib.DatabasePath);
            string filePath = Path.Combine(Path.GetDirectoryName(documentPath) ?? string.Empty, fileName ?? string.Empty);

            if (File.Exists(filePath))
            {
                try
                {
                    return optLib.ChangeDatabasePath(filePath);
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception)
                {
                    //Todo: should this fail silenty or report an error
                }
            }

            _out.WriteLine(Resources.CommandLine_FindOptimizationDatabase_Could_not_find_the_optimization_library__0__, Path.GetFileName(optLib.DatabasePath));
            return null;
        }
Ejemplo n.º 5
0
 public bool Equals(OptimizationLibrary other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return base.Equals(other) && Equals(other._database, _database) && Equals(other.DatabasePath, DatabasePath);
 }
Ejemplo n.º 6
0
        private OptimizationLibrary FindOptimizationDatabase(IWin32Window parent, string documentPath, OptimizationLibrary optLib)
        {
            if (optLib.IsNone)
                return optLib;

            OptimizationLibrary lib;
            if (Settings.Default.OptimizationLibraryList.TryGetValue(optLib.Name, out lib))
            {
                if (lib != null && File.Exists(lib.DatabasePath))
                    return lib;
            }
            if (documentPath == null)
                return null;

            // First look for the file name in the document directory
            string fileName = Path.GetFileName(optLib.DatabasePath);
            string filePath = Path.Combine(Path.GetDirectoryName(documentPath) ?? string.Empty, fileName ?? string.Empty);

            if (File.Exists(filePath))
            {
                try
                {
                    return optLib.ChangeDatabasePath(filePath);
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception)
                {
                    //Todo: should this fail silenty or raise another dialog box?
                }
            }

            do
            {
                using (var dlg = new MissingFileDlg
                {
                    ItemName = optLib.Name,
                    ItemType = Resources.SkylineWindow_FindOptimizationDatabase_Optimization_Library,
                    Filter = TextUtil.FileDialogFilterAll(Resources.SkylineWindow_FindOptimizationDatabase_Optimization_Library_Files, OptimizationDb.EXT),
                    FileHint = Path.GetFileName(optLib.DatabasePath),
                    FileDlgInitialPath = Path.GetDirectoryName(documentPath),
                    Title = Resources.SkylineWindow_FindOptimizationDatabase_Find_Optimization_Library
                })
                {
                    if (dlg.ShowDialog(parent) == DialogResult.OK)
                    {
                        if (dlg.FilePath == null)
                            return OptimizationLibrary.NONE;

                        try
                        {
                            return optLib.ChangeDatabasePath(dlg.FilePath);
                        }
                        catch (OptimizationsOpeningException e)
                        {
                            var message = TextUtil.SpaceSeparate(
                                Resources.SkylineWindow_FindOptimizationDatabase_The_database_file_specified_could_not_be_opened_,
                                e.Message); // Not L10N
                            MessageBox.Show(message);
                        }
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            while (true);
        }