Ejemplo n.º 1
0
        /// <summary>
        /// Closes opened data source (destructs ProjectManager)
        /// </summary>
        /// <param name="index">index of data source in data sources table</param>
        /// <returns></returns>
        public static bool CloseSource(int index)
        {
            try
            {
                if (index >= 0 && index < sources.Count)
                {
                    ((CFEsource)sources[index]).PM.DestroyProjectManager();
                }
            }
            catch (SystemException e)
            {
                FE_error err = new FE_error("FEP004", "Reason: " + e.Message);
                FE_err_msg.show_err_msg(err);
                return(false);
            }
            catch (Ice.NoEndpointException) // lost of icegridnode, source can't be closed normally
            {
                OpenSrcCount--;
                return(true);
            }
            catch (System.Exception e)
            {
                FE_error err = new FE_error("FEP004", "Reason: " + e.Message);
                FE_err_msg.show_err_msg(err);
                return(false);
            }
#if (LADICI)
            MessageBox.Show("Zdroj " + index.ToString() + " byl zavren\n", "Ladici hlaska", MessageBoxButtons.OK);
#endif
            OpenSrcCount--;
            return(true);
        }
Ejemplo n.º 2
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();
            }
        }
        /// <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;
            }
        }