Beispiel #1
0
        // pridani noveho zdroje (otevre dialog pro vyber zdroje, pote ho otevre a vrati handle (index) )
        /// <summary>
        /// Creating new data source.
        /// Creates and openes source and returns handle on it.
        /// <b>notice: </b>when IceGridNode is not set as system service and some other FEplugin data source is already opened,
        /// then new data source can not be created.
        /// </summary>
        /// <param name="PersistID">Perzist ID of new source (path to Ferda project (.xfp) file)</param>
        /// <returns>Handle to newly created and opened data source.</returns>
        public static Int32 NewSource(string PersistID)
        {
            DirManager.SetHomeLMRA_dir(); // due to relative paths of pesist IDs

            // tries to create an instance of CFEsource class
            CFEsource NS;

            try
            {
                // controll if the file with FE project exists
                if (!File.Exists(PersistID))
                {
//#if (DEBUG)
//                    MessageBox.Show("aktualni adresar" + Directory.GetCurrentDirectory());
//#endif
                    throw new FE_error("FEP005", "Perzist ID: " + PersistID + "\n\nReason: project can't be loaded, file can't be found on given path");
                }

                // test, if IceGridNode is set as system service. If not and some other source is opened, new source can not be created.
                if (FEplugin_globals.IceConfig_initialized)
                {
                    if (FEplugin_globals.IceConfig.ProjectManagerOptions.IceGridAsService == false && OpenSrcCount >= 1)
                    {
                        throw new FE_error("FEP006");
                    }
                }

                NS = new CFEsource(PersistID);
                int index = sources.Add(NS);
                SrcCount++;
                OpenSrcCount++;
                return(index);
            }
            catch (FE_error e)
            {
                FE_err_msg.show_err_msg(e);
                return(-1);
            }
            catch (System.Exception e)
            {
                FE_error err = new FE_error("FEP005", "Reason: " + e.Message);
                FE_err_msg.show_err_msg(err);
                return(-1);
            }
            finally
            {
                DirManager.SetHomePrevious_dir();
            }
        }
Beispiel #2
0
        ///////// METHODS ///////

        /// <summary>
        /// Construction of one FEplugin data source.
        /// </summary>
        /// <param name="path">Path to file with Ferda project</param>
        public CFEsource(string path)
        {
            // initialization of SourcePath
            SourcePath = path;

            // initialization of PM
            try
            {
                // changing current directory to Ferda FrontEnd directory
                DirManager.SetHomeFerdaFrontEnd_dir();

                // initialization of PM
                PM = new ProjectManager(new string[0], FEplugin_globals.IceConfig.ProjectManagerOptions);
                DirManager.SetHomePrevious_dir();


                // loading the project
                DirManager.SetHomeLMRA_dir();
                if (LoadProject() == false)
                {
                    throw new FE_error("FEP005", "Perzist ID: " + SourcePath + "\n\nReason: project can't be loaded");
                }
            }
            catch (FE_error)
            {
                throw;
            }
            catch (System.Exception e)
            {
                DestroyPM();
                FE_error err = new FE_error("FEP005", "Perzist ID: " + SourcePath + "\n\nReason: " + e.Message);
                throw (err);
            }
            finally
            {
                // changing actual directory to previous
                DirManager.SetHomePrevious_dir();
            }
        }
        /// <summary>
        /// Static constructor - performs the initialization (global objects).
        /// Presence of Ferda libraries is checked and missing libraries are found in Ferda install directory and copied
        /// into LM-RA directory.
        /// Here is a list of required Ferda libraries:
        /// <ul>
        ///     <li>FerdaProjectManager.dll</li>
        ///     <li>FerdaBoxInterfaces.dll</li>
        ///     <li>FerdaBoxInterfaces.dll</li>
        ///     <li>FerdaBase.dll</li>
        ///     <li>FerdaHelpers.dll</li>
        /// </ul>
        /// </summary>
        static FEplugin_init()
        {
            success = true;

            try
            {
                #region Controling of presence of required Ferda DataMiner libraries and copying them if they are missing

                string app_file = Assembly.GetExecutingAssembly().FullName;
                string app_dir  = Assembly.GetExecutingAssembly().Location; // directory where libraries are copied to
                app_dir = app_dir.Replace(@"\FEplugin_cs.dll", "");

                string lib_dir = DirManager.get_FerdaFrontEnd_dir(); // directory, where the libraries are placed (Ferda FrontEnd dir)

                if (String.IsNullOrEmpty(lib_dir))
                {
                    throw new FE_error("FEP001");
                }



                // libraries required for FEplugin FE Plugin
                string[] Libraries = new string[] { //"FerdaProjectManager.dll",
                    "FerdaModulesManager.dll",
                    "FerdaBoxInterfaces.dll",
                    "FerdaBase.dll",
                    "FerdaHelpers.dll"
                };

                foreach (string lib in Libraries)
                {
                    string source_name = lib_dir + @"\" + lib;
                    string target_name = app_dir + @"\" + lib;


                    if (File.Exists(source_name))
                    {
                        DateTime source_time = File.GetLastWriteTime(source_name);
                        DateTime target_time;
                        if (File.Exists(target_name))
                        {
                            target_time = File.GetLastWriteTime(target_name);
                            if (target_time.CompareTo(source_time) < 0)  // copying the file
                            {
                                File.Copy(source_name, target_name);
                            }
                        }
                        else
                        {
                            File.Copy(source_name, target_name);
                        }
                    }
                    else  // file with name "source_name" wasn't found
                    {
                        throw new FE_error("FEP003", source_name);
                    }

                    // initialization of global objects
                    FEplugin_globals.init();
                    if (FEplugin_globals.IceConfig_initialized == false)
                    {
                        throw new FE_error("FEP002");
                    }
                }
                #endregion
            }
            catch (FE_error e)
            {
                FE_err_msg.show_err_msg(e);
                success = false;
            }
            catch (Exception)
            {
                success = false;
            }
        }