private void UpdateProgress()
        {
            Int32 oldPercentRead = percentRead;

            percentRead = (Int32)(parser.Position / (Single)parser.FileLength * 100.0f);

            if (percentRead != oldPercentRead)
            {
                progressWindowInterface.UpdateProgress(percentRead);
            }
        }
Exemple #2
0
        public void RegisterViewsFirstRun()
        {
            int             count = 0, illegallyNamedCount = 0;
            IResourceList   contacts = Core.ResourceStore.GetAllResources("Contact");
            IProgressWindow wnd      = Core.ProgressWindow;

            if (wnd != null)
            {
                wnd.UpdateProgress(0, "Upgrading Contact Names information.", null);
            }
            ContactManager.UnlinkIdenticalContactNames(contacts, wnd, ref count, ref illegallyNamedCount);
            Trace.WriteLine("ContactsUpgrade3ViewsConstructor (RegisterViewsFirstRun) -- " + count + " completely unnecessary contact names removed, of that - " +
                            illegallyNamedCount + " illegally named Conact Names");
        }
Exemple #3
0
        /// <summary>
        /// Invokes <see cref="IPlugin.Startup"/> for each of the loaded plugins, on the Resource thread, sync.
        /// </summary>
        public void StartupPlugins()
        {
            IProgressWindow window = Core.ProgressWindow;

            for (int a = 0; a < _plugins.Count; a++)
            {
                IPlugin plugin = _plugins[a];
                Trace.WriteLine("Starting plugin " + plugin.GetType().Name);

                if (window != null)
                {
                    window.UpdateProgress((a + 1) * 100 / _plugins.Count, Stringtable.StartingPluginsProgressMessage, null);
                }

                // Run on another thread
                string  sStartupError  = null;
                bool    bCancelStartup = false;
                IPlugin pluginConst    = plugin;              // Precaution: don't access modified closure
                Core.ResourceAP.RunJob(string.Format(Stringtable.JobStartingPlugin, plugin.GetType().Name), delegate
                {
                    try
                    {
                        pluginConst.Startup();
                    }
                    catch (CancelStartupException)
                    {
                        Trace.WriteLine(string.Format("Starting Plugin “{0}”: CancelStartupException.", pluginConst.GetType().AssemblyQualifiedName), "Plugin.Loader");
                        bCancelStartup = true;
                    }
                    catch (Exception ex)
                    {
                        sStartupError = ex.Message;
                    }
                });

                // Process results on home thread
                if (bCancelStartup)
                {
                    throw new CancelStartupException();
                }

                if (sStartupError != null)
                {
                    Trace.WriteLine(string.Format("Error Starting Plugin “{0}”. {1}", plugin.GetType().AssemblyQualifiedName, sStartupError));
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Calls <see cref="IPlugin.Shutdown"/> on each of the plugins, on the calling thread.
        /// </summary>
        /// <param name="bShowProgress">Whether to report to the progress window.</param>
        public void ShutdownPlugins(bool bShowProgress)
        {
            IProgressWindow window = Core.ProgressWindow;

            foreach (IPlugin plugin in _plugins)
            {
                if ((bShowProgress) && (window != null))
                {
                    window.UpdateProgress(0, string.Format(Stringtable.StoppingPluginProgressMessage, plugin.GetType().Name), null);
                }
                try
                {
                    plugin.Shutdown();
                }
                catch (Exception ex)
                {
                    Core.ReportException(ex, false);
                }
            }
        }
Exemple #5
0
        private static void UpdateResources()
        {
            string[] lastTypes = ObjectStore.ReadString("UnknownFiles", "LastConf").Split(';');
            string[] types     = (Core.FileResourceManager as FileResourceManager).GetResourceTypes();
            if (types.Length == lastTypes.Length)
            {
                bool needUpdate = false;
                Array.Sort(types);
                Array.Sort(lastTypes);
                for (int i = 0; i < types.Length; ++i)
                {
                    if (types[i] != lastTypes[i])
                    {
                        needUpdate = true;
                        break;
                    }
                }
                // plugin configuration not changed
                if (!needUpdate)
                {
                    return;
                }
            }
            IResourceList   unknownRcs     = Core.ResourceStore.GetAllResources(_unknowFileResourceType);
            IProgressWindow progressWindow = Core.ProgressWindow;

            for (int i = 0, percents = 0; i < unknownRcs.Count && Core.State != CoreState.ShuttingDown; ++i)
            {
                if (progressWindow != null)
                {
                    progressWindow.UpdateProgress(percents / unknownRcs.Count, "Updating unknown resources", null);
                    percents += 100;
                }
                IResource unknown = unknownRcs[i];
                IResource source  = FileResourceManager.GetSource(unknown);
                if (source != null)
                {
                    string resourceType = Core.FileResourceManager.GetResourceTypeByExtension(
                        IOTools.GetExtension(unknown.GetPropText(Core.Props.Name)));
                    if (resourceType != null)
                    {
                        unknown.ChangeType(resourceType);
                    }
                }
            }
            foreach (IResourceType resType in Core.ResourceStore.ResourceTypes)
            {
                if (resType.HasFlag(ResourceTypeFlags.FileFormat) && !resType.OwnerPluginLoaded)
                {
                    IResourceList formatFiles = Core.ResourceStore.GetAllResources(resType.Name);
                    foreach (IResource formatFile in formatFiles)
                    {
                        formatFile.ChangeType(_unknowFileResourceType);
                    }
                }
            }
            StringBuilder confString = new StringBuilder();

            foreach (string restype in types)
            {
                confString.Append(restype);
                confString.Append(";");
            }
            ObjectStore.WriteString("UnknownFiles", "LastConf", confString.ToString().TrimEnd(';'));
        }