Exemple #1
0
        public async Task <bool> Initialize()
        {
            bool result = false;

            try
            {
                if (_pluginDataFolderSelected)
                {
                    List <Framework.Interfaces.IPlugin> pins = new List <Framework.Interfaces.IPlugin>();
                    result = LoadAssemblyFolder(pins, Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins"));
                    if (result)
                    {
                        //first the Prerequisites
                        foreach (Framework.Interfaces.IPlugin plugin in pins)
                        {
                            if (plugin.Prerequisite)
                            {
                                try
                                {
                                    if (InitializingPlugin != null)
                                    {
                                        InitializingPlugin(this, plugin.FriendlyName);
                                    }
                                    result = await plugin.InitializeAsync(this);

                                    if (result)
                                    {
                                        _plugins.Add(plugin);
                                        plugin.Closing += new Framework.EventArguments.PluginEventHandler(plugin_Closing);
                                        OnPluginAdded(plugin);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                catch
                                {
                                    //plugin failed to load
                                    result = false;
                                    break;
                                }
                            }
                        }
                        //then the non-prerequisites
                        if (result)
                        {
                            foreach (Framework.Interfaces.IPlugin plugin in pins)
                            {
                                if (!plugin.Prerequisite)
                                {
                                    try
                                    {
                                        if (InitializingPlugin != null)
                                        {
                                            InitializingPlugin(this, plugin.FriendlyName);
                                        }
                                        result = await plugin.InitializeAsync(this);

                                        if (result)
                                        {
                                            _plugins.Add(plugin);
                                            plugin.Closing += new Framework.EventArguments.PluginEventHandler(plugin_Closing);
                                            OnPluginAdded(plugin);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    catch// (Exception e)
                                    {
                                        //plugin failed to load
                                        //result = false;
                                        //break;
                                    }
                                }
                            }
                        }
                    }
                    if (_settingsProvider.GetSettingsValueInt("Core.CultureID", 0) != 0)
                    {
                        _selectedLanguage = new CultureInfo(_settingsProvider.GetSettingsValueInt("Core.CultureID", 0));
                    }
                    if (_settingsProvider.GetSettingsValueInt("Core.CultureID", 0) != 127)
                    {
                        //check if culture exists and if not, try match
                        List <Framework.Interfaces.IPlugin> lpins = (from p in pins where p.PluginType == Framework.PluginType.LanguageSupport select p).ToList();
                        foreach (Framework.Interfaces.ILanguageSupport p in lpins)
                        {
                            if ((from w in p.GetSupportedCultures() where w.LCID == _selectedLanguage.LCID select w).FirstOrDefault() == null)
                            {
                                //ok, no match
                                CultureInfo tmp = (from w in p.GetSupportedCultures() where w.Name.Substring(0, 2) == _selectedLanguage.Name.Substring(0, 2) select w).FirstOrDefault();
                                if (tmp != null)
                                {
                                    //ok, base matches
                                    _selectedLanguage = tmp;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    try
                    {
                        OnSelectedLanguage();
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
                RestoreDefaultSettings();
            }
            return(result);
        }
Exemple #2
0
        public Engine()
        {
            try
            {
                _settingsProvider = new SettingsProvider(null);

                string[] args = Environment.GetCommandLineArgs();
                if (EnablePluginDataPathAtStartup || (args != null && args.Contains("/f")))
                {
                    using (SelectSettingsForm dlg = new SelectSettingsForm(this))
                    {
                        _pluginDataFolderSelected = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                    }
                }
                else
                {
                    _pluginDataFolderSelected = true;
                }

                if (_pluginDataFolderSelected)
                {
                    _geocachingAccountNames = new Framework.Data.GeocachingAccountNames();
                    var p = _settingsProvider.GetSettingsValueStringCollection("Core.GeocachingAccountNames", null);
                    if (p != null)
                    {
                        foreach (string s in p)
                        {
                            string[] parts = s.Split("|".ToArray(), 2);
                            if (parts.Length == 2)
                            {
                                _geocachingAccountNames.SetAccountName(parts[0], parts[1]);
                            }
                        }
                    }
                    _geocachingAccountNames.Changed += new Framework.EventArguments.GeocachingAccountNamesEventHandler(_geocachingAccountNames_Changed);

                    _geocachingComAccount = new Framework.Data.GeocachingComAccountInfo();
                    _geocachingComAccount.AccountName = _settingsProvider.GetSettingsValue("Core.GCComAccountName", null);
                    _geocachingComAccount.APIToken = _settingsProvider.GetSettingsValue("Core.GCComAccountToken", null);
                    _geocachingComAccount.APITokenStaging = _settingsProvider.GetSettingsValue("Core.GCComAccountTokenStaging", null);
                    _geocachingComAccount.MemberType = _settingsProvider.GetSettingsValue("Core.GCComAccountMemberType", null);
                    _geocachingComAccount.MemberTypeId = _settingsProvider.GetSettingsValueInt("Core.GCComAccountMemberTypeId", 0);
                    _geocachingComAccount.Changed += new Framework.EventArguments.GeocacheComAccountEventHandler(_geocachingComAccount_Changed);
                    GeocachingAccountNames.SetAccountName("GC", _settingsProvider.GetSettingsValue("Core.GCComAccountName", null) ?? "");

                    _logs = new Framework.Data.LogCollection();
                    _userWaypoints = new Framework.Data.UserWaypointCollection();
                    _waypoints = new Framework.Data.WaypointCollection();
                    _geocaches = new Framework.Data.GeocacheCollection(this);
                    _logImages = new Framework.Data.LogImageCollection();
                    _geocacheImages = new Framework.Data.GeocacheImageCollection();
                    _geocacheAttributes = new Framework.Data.GeocacheAttributeCollection();
                    _geocacheTypes = new Framework.Data.GeocacheTypeCollection();
                    _geocacheContainers = new Framework.Data.GeocacheContainerCollection();
                    _logTypes = new Framework.Data.LogTypeCollection();
                    _waypointTypes = new Framework.Data.WaypointTypeCollection();
                    _homeLocation = new Framework.Data.Location();
                    _centerLocation = new Framework.Data.Location();
                    _gpsLocation = new Framework.Data.GPSLocation();
                    _languageItems = new Framework.Data.LanguageItemCollection();

                    _detectedPlugins = new List<string>();
                    _internalStoragePlugins = new List<string>();
                    _selectedLanguage = System.Globalization.CultureInfo.CurrentCulture;
                    _plugins = new List<Framework.Interfaces.IPlugin>();
                    _currentDomain = AppDomain.CurrentDomain;
                    _currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);

                    //set initial data
                    //default location settings
                    _centerLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.CenterLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.CenterLon", 5.5));
                    _centerLocation.Changed += new Framework.EventArguments.LocationEventHandler(_centerLocation_Changed);
                    _homeLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.HomeLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.HomeLon", 5.5));
                    _homeLocation.Changed += new Framework.EventArguments.LocationEventHandler(_homeLocation_Changed);

                    //default (unknown) cache- ,container etc. types. Position 0 means unknown
                    Framework.Data.GeocacheType ct = new Framework.Data.GeocacheType();
                    ct.ID = 0;
                    ct.Name = "Not present";
                    _geocacheTypes.Add(ct);
                    Framework.Data.GeocacheAttribute attr = new Framework.Data.GeocacheAttribute();
                    attr.ID = 0;
                    attr.Name = "Unknown";
                    _geocacheAttributes.Add(attr);
                    Framework.Data.GeocacheContainer cont = new Framework.Data.GeocacheContainer();
                    cont.ID = 0;
                    cont.Name = "Unknown";
                    _geocacheContainers.Add(cont);
                    Framework.Data.LogType lt = new Framework.Data.LogType();
                    lt.ID = 0;
                    lt.Name = "Unknown";
                    lt.AsFound = false;
                    _logTypes.Add(lt);
                    Framework.Data.WaypointType wpt = new Framework.Data.WaypointType();
                    wpt.ID = 0;
                    wpt.Name = "Unknown";
                    _waypointTypes.Add(wpt);

                    _shortcuts = new List<Framework.Data.ShortcutInfo>();
                }
            }
            catch
            {
                RestoreDefaultSettings();
            }
        }
Exemple #3
0
        public Engine()
        {
            try
            {
                _settingsProvider = new SettingsProvider(null);

                string[] args = Environment.GetCommandLineArgs();
                if (EnablePluginDataPathAtStartup || (args != null && args.Contains("/f")))
                {
                    using (SelectSettingsForm dlg = new SelectSettingsForm(this))
                    {
                        _pluginDataFolderSelected = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                    }
                }
                else
                {
                    _pluginDataFolderSelected = true;
                }

                if (_pluginDataFolderSelected)
                {
                    _geocachingAccountNames = new Framework.Data.GeocachingAccountNames();
                    var p = _settingsProvider.GetSettingsValueStringCollection("Core.GeocachingAccountNames", null);
                    if (p != null)
                    {
                        foreach (string s in p)
                        {
                            string[] parts = s.Split("|".ToArray(), 2);
                            if (parts.Length == 2)
                            {
                                _geocachingAccountNames.SetAccountName(parts[0], parts[1]);
                            }
                        }
                    }
                    _geocachingAccountNames.Changed += new Framework.EventArguments.GeocachingAccountNamesEventHandler(_geocachingAccountNames_Changed);

                    _geocachingComAccount                 = new Framework.Data.GeocachingComAccountInfo();
                    _geocachingComAccount.AccountName     = _settingsProvider.GetSettingsValue("Core.GCComAccountName", null);
                    _geocachingComAccount.APIToken        = _settingsProvider.GetSettingsValue("Core.GCComAccountToken", null);
                    _geocachingComAccount.APITokenStaging = _settingsProvider.GetSettingsValue("Core.GCComAccountTokenStaging", null);
                    _geocachingComAccount.MemberType      = _settingsProvider.GetSettingsValue("Core.GCComAccountMemberType", null);
                    _geocachingComAccount.MemberTypeId    = _settingsProvider.GetSettingsValueInt("Core.GCComAccountMemberTypeId", 0);
                    _geocachingComAccount.Changed        += new Framework.EventArguments.GeocacheComAccountEventHandler(_geocachingComAccount_Changed);
                    GeocachingAccountNames.SetAccountName("GC", _settingsProvider.GetSettingsValue("Core.GCComAccountName", null) ?? "");

                    _logs               = new Framework.Data.LogCollection();
                    _userWaypoints      = new Framework.Data.UserWaypointCollection();
                    _waypoints          = new Framework.Data.WaypointCollection();
                    _geocaches          = new Framework.Data.GeocacheCollection(this);
                    _logImages          = new Framework.Data.LogImageCollection();
                    _geocacheImages     = new Framework.Data.GeocacheImageCollection();
                    _geocacheAttributes = new Framework.Data.GeocacheAttributeCollection();
                    _geocacheTypes      = new Framework.Data.GeocacheTypeCollection();
                    _geocacheContainers = new Framework.Data.GeocacheContainerCollection();
                    _logTypes           = new Framework.Data.LogTypeCollection();
                    _waypointTypes      = new Framework.Data.WaypointTypeCollection();
                    _homeLocation       = new Framework.Data.Location();
                    _centerLocation     = new Framework.Data.Location();
                    _gpsLocation        = new Framework.Data.GPSLocation();
                    _languageItems      = new Framework.Data.LanguageItemCollection();

                    _detectedPlugins        = new List <string>();
                    _internalStoragePlugins = new List <string>();
                    _selectedLanguage       = System.Globalization.CultureInfo.CurrentCulture;
                    _plugins       = new List <Framework.Interfaces.IPlugin>();
                    _currentDomain = AppDomain.CurrentDomain;
                    _currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);

                    //set initial data
                    //default location settings
                    _centerLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.CenterLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.CenterLon", 5.5));
                    _centerLocation.Changed += new Framework.EventArguments.LocationEventHandler(_centerLocation_Changed);
                    _homeLocation.SetLocation(_settingsProvider.GetSettingsValueDouble("Core.HomeLat", 51.5), _settingsProvider.GetSettingsValueDouble("Core.HomeLon", 5.5));
                    _homeLocation.Changed += new Framework.EventArguments.LocationEventHandler(_homeLocation_Changed);

                    //default (unknown) cache- ,container etc. types. Position 0 means unknown
                    Framework.Data.GeocacheType ct = new Framework.Data.GeocacheType();
                    ct.ID   = 0;
                    ct.Name = "Not present";
                    _geocacheTypes.Add(ct);
                    Framework.Data.GeocacheAttribute attr = new Framework.Data.GeocacheAttribute();
                    attr.ID   = 0;
                    attr.Name = "Unknown";
                    _geocacheAttributes.Add(attr);
                    Framework.Data.GeocacheContainer cont = new Framework.Data.GeocacheContainer();
                    cont.ID   = 0;
                    cont.Name = "Unknown";
                    _geocacheContainers.Add(cont);
                    Framework.Data.LogType lt = new Framework.Data.LogType();
                    lt.ID      = 0;
                    lt.Name    = "Unknown";
                    lt.AsFound = false;
                    _logTypes.Add(lt);
                    Framework.Data.WaypointType wpt = new Framework.Data.WaypointType();
                    wpt.ID   = 0;
                    wpt.Name = "Unknown";
                    _waypointTypes.Add(wpt);

                    _shortcuts = new List <Framework.Data.ShortcutInfo>();
                }
            }
            catch
            {
                RestoreDefaultSettings();
            }
        }