Beispiel #1
0
        internal ProxyEditor(ModuleManager manager, EnumerableReader reader)
            : base(manager, reader, new ModuleEditorAttribute())
        {
            Attribute.Mask = (string)reader.Read();

            Init();
        }
Beispiel #2
0
        internal ProxyCommand(ModuleManager manager, EnumerableReader reader)
            : base(manager, reader, new ModuleCommandAttribute())
        {
            Attribute.Prefix = (string)reader.Read();

            Init();
        }
Beispiel #3
0
        internal ProxyCommand(ModuleManager manager, EnumerableReader reader)
            : base(manager, reader, new ModuleCommandAttribute())
        {
            Attribute.Prefix = (string)reader.Read();

            Init();
        }
Beispiel #4
0
        internal ProxyEditor(ModuleManager manager, EnumerableReader reader)
            : base(manager, reader, new ModuleEditorAttribute())
        {
            Attribute.Mask = (string)reader.Read();

            Init();
        }
Beispiel #5
0
        internal ProxyDrawer(ModuleManager manager, EnumerableReader reader)
            : base(manager, reader, new ModuleDrawerAttribute())
        {
            Attribute.Mask     = (string)reader.Read();
            Attribute.Priority = (int)reader.Read();

            Init();
        }
Beispiel #6
0
        internal ProxyDrawer(ModuleManager manager, EnumerableReader reader)
            : base(manager, reader, new ModuleDrawerAttribute())
        {
            Attribute.Mask = (string)reader.Read();
            Attribute.Priority = (int)reader.Read();

            Init();
        }
Beispiel #7
0
        protected ProxyAction(ModuleManager manager, EnumerableReader reader, ModuleActionAttribute attribute)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            _Manager = manager;
            _Attribute = attribute;

            _ClassName = (string)reader.Read();
            _Attribute.Name = (string)reader.Read();
            _Id = (Guid)reader.Read();
        }
Beispiel #8
0
        protected ProxyAction(ModuleManager manager, EnumerableReader reader, ModuleActionAttribute attribute)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            _Manager  = manager;
            Attribute = attribute;

            _ClassName     = (string)reader.Read();
            Attribute.Name = (string)reader.Read();
            _Id            = (Guid)reader.Read();
        }
Beispiel #9
0
        /// <summary>
        /// Reads the module from the cache.
        /// </summary>
        /// <param name="fileInfo">Module file information.</param>
        /// <returns>True if the module has been loaded from the cache.</returns>
        bool ReadCache(FileInfo fileInfo)
        {
            Log.Source.TraceInformation("Read cache {0}", fileInfo);

            string path = fileInfo.FullName;
            var    data = _Cache.Get(path);

            if (data == null)
            {
                return(false);
            }

            ++_Cache.CountLoaded;
            bool          done    = false;
            ModuleManager manager = null;

            try
            {
                // read data
                EnumerableReader reader = new EnumerableReader((IEnumerable)data);

                // >> Stamp
                var assemblyStamp = (long)reader.Read();
                if (assemblyStamp != fileInfo.LastWriteTime.Ticks)
                {
                    return(false);
                }

                // new manager, add it now, remove later on errors
                manager = new ModuleManager(path);
                _Managers.Add(manager.ModuleName, manager);

                // read and load data
                var settings = manager.ReadSettings();
                manager.LoadData(settings);

                // >> Culture of cached resources
                var savedCulture = (string)reader.Read();

                // check the culture
                if (savedCulture.Length > 0)
                {
                    // the culture changed, ignore the cache
                    if (savedCulture != manager.CurrentUICulture.Name)
                    {
                        return(false);
                    }

                    // restore the flag
                    manager.CachedResources = true;
                }

                // >> Settings
                manager.HasSettings = (bool)reader.Read();

                object kind;
                while (null != (kind = reader.TryRead()))
                {
                    ProxyAction action = null;
                    switch ((ModuleItemKind)kind)
                    {
                    case ModuleItemKind.Host:
                    {
                        manager.SetModuleHost((string)reader.Read());
                    }
                    break;

                    case ModuleItemKind.Command:
                    {
                        var it = new ProxyCommand(manager, reader);
                        Host.Instance.RegisterProxyCommand(it);
                        action = it;
                    }
                    break;

                    case ModuleItemKind.Editor:
                    {
                        var it = new ProxyEditor(manager, reader);
                        Host.Instance.RegisterProxyEditor(it);
                        action = it;
                    }
                    break;

                    case ModuleItemKind.Drawer:
                    {
                        var it = new ProxyDrawer(manager, reader);
                        Host.Instance.RegisterProxyDrawer(it);
                        action = it;
                    }
                    break;

                    case ModuleItemKind.Tool:
                    {
                        var it = new ProxyTool(manager, reader);
                        Host.Instance.RegisterProxyTool(it);
                        action = it;
                    }
                    break;

                    default:
                        throw new ModuleException();
                    }

                    if (action != null)
                    {
                        action.LoadData((Hashtable)settings[action.Id]);
                    }
                }

                done = true;
            }
            catch (ModuleException)
            {
                // ignore known
            }
            catch (Exception ex)
            {
                throw new ModuleException(string.Format(null, "Error on reading the cache for '{0}'.", path), ex);
            }
            finally
            {
                if (!done)
                {
                    // remove cached data
                    _Cache.Remove(path);

                    // remove the manager
                    if (manager != null)
                    {
                        RemoveModuleManager(manager);
                    }
                }
            }

            return(done);
        }
Beispiel #10
0
 internal ProxyTool(ModuleManager manager, EnumerableReader reader)
     : base(manager, reader, new ModuleToolAttribute())
 {
     Attribute.Options = (ModuleToolOptions)reader.Read();
 }
Beispiel #11
0
        /// <summary>
        /// Reads the module from the cache.
        /// </summary>
        /// <param name="fileInfo">Module file information.</param>
        /// <returns>True if the module has been loaded from the cache.</returns>
        bool ReadCache(FileInfo fileInfo)
        {
            Log.Source.TraceInformation("Read cache {0}", fileInfo);

            string path = fileInfo.FullName;
            var data = _Cache.Get(path);
            if (data == null)
                return false;

            ++_Cache.CountLoaded;
            bool done = false;
            ModuleManager manager = null;
            try
            {
                // read data
                EnumerableReader reader = new EnumerableReader((IEnumerable)data);

                // >> Stamp
                var assemblyStamp = (long)reader.Read();
                if (assemblyStamp != fileInfo.LastWriteTime.Ticks)
                    return false;

                // new manager, add it now, remove later on errors
                manager = new ModuleManager(path);
                _Managers.Add(manager.ModuleName, manager);

                // read and load data
                var settings = manager.ReadSettings();
                manager.LoadData(settings);

                // >> Culture of cached resources
                var savedCulture = (string)reader.Read();

                // check the culture
                if (savedCulture.Length > 0)
                {
                    // the culture changed, ignore the cache
                    if (savedCulture != manager.CurrentUICulture.Name)
                        return false;

                    // restore the flag
                    manager.CachedResources = true;
                }

                // >> Settings
                manager.HasSettings = (bool)reader.Read();

                object kind;
                while (null != (kind = reader.TryRead()))
                {
                    ProxyAction action = null;
                    switch ((ModuleItemKind)kind)
                    {
                        case ModuleItemKind.Host:
                            {
                                manager.SetModuleHost((string)reader.Read());
                            }
                            break;
                        case ModuleItemKind.Command:
                            {
                                var it = new ProxyCommand(manager, reader);
                                Host.Instance.RegisterProxyCommand(it);
                                action = it;
                            }
                            break;
                        case ModuleItemKind.Editor:
                            {
                                var it = new ProxyEditor(manager, reader);
                                Host.Instance.RegisterProxyEditor(it);
                                action = it;
                            }
                            break;
                        case ModuleItemKind.Drawer:
                            {
                                var it = new ProxyDrawer(manager, reader);
                                Host.Instance.RegisterProxyDrawer(it);
                                action = it;
                            }
                            break;
                        case ModuleItemKind.Tool:
                            {
                                var it = new ProxyTool(manager, reader);
                                Host.Instance.RegisterProxyTool(it);
                                action = it;
                            }
                            break;
                        default:
                            throw new ModuleException();
                    }

                    if (action != null)
                        action.LoadData((Hashtable)settings[action.Id]);
                }

                done = true;
            }
            catch (ModuleException)
            {
                // ignore known
            }
            catch (Exception ex)
            {
                throw new ModuleException(string.Format(null, "Error on reading the cache for '{0}'.", path), ex);
            }
            finally
            {
                if (!done)
                {
                    // remove cached data
                    _Cache.Remove(path);

                    // remove the manager
                    if (manager != null)
                        RemoveModuleManager(manager);
                }
            }

            return done;
        }
Beispiel #12
0
 internal ProxyTool(ModuleManager manager, EnumerableReader reader)
     : base(manager, reader, new ModuleToolAttribute())
 {
     Attribute.Options = (ModuleToolOptions)reader.Read();
 }