Exemple #1
0
        public Boolean EqualsIExtension(IExtension Extension)
        {
            if (Equals(Extension, null))
            {
                return(false);
            }
            String ExtType       = "UnknownExtension";
            Type   InterfaceType = Enumerable.FirstOrDefault(Extension.GetType().GetInterfaces());

            if (!Equals(InterfaceType, null))
            {
                ExtType = InterfaceType.Name;
            }

            if (!Equals(Name, Extension.ExtensionDescriptionAttribute.Name))
            {
                return(false);
            }
            if (!Equals(Language, Extension.ExtensionDescriptionAttribute.Language))
            {
                return(false);
            }
            if (!Equals(ExtensionType, ExtType))
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        public AboutForm()
        {
            InitializeComponent();

            //  Initialize the AboutBox to display the product information from the assembly information.
            //  Change assembly information settings for your application through either:
            //  - Project->Properties->Application->Assembly Information
            //  - AssemblyInfo.cs
            this.Text = String.Format("About {0}", AssemblyTitle);


            for (int i = 0; i < AppManager.Instance.Application.Extensions.Count; i++)
            {
                IExtension ext = AppManager.Instance.Application.Extensions[i];

                ListViewItem item = new ListViewItem(ext.Name);
                item.SubItems.Add(AssemblyVersion(ext.GetType().Assembly));
                lvwPlugs.Items.Add(item);
            }

            using (Stream s = this.GetType().Assembly.GetManifestResourceStream("MyDownloader.App.UI.About.rtf"))
            {
                richTextBox1.LoadFile(s, RichTextBoxStreamType.RichText);
            }
        }
Exemple #3
0
        private GService(IExtension container, GService parent, IPEndPoint moduleServer)
        {
            _container             = container ?? this;
            _unknownDataAttributes = parent?._unknownDataAttributes ?? new List <DataCaptureAttribute>();
            _inDataAttributes      = parent?._inDataAttributes ?? new Dictionary <ushort, List <DataCaptureAttribute> >();
            _outDataAttributes     = parent?._outDataAttributes ?? new Dictionary <ushort, List <DataCaptureAttribute> >();

            _extensionEvents = new Dictionary <ushort, Action <HPacket> >
            {
                [1] = _container.OnDoubleClick,
                [2] = _container.OnInfoRequest,
                [3] = _container.OnPacketIntercept,
                [4] = _container.OnFlagsCheck,
                [5] = _container.OnConnected,
                [6] = _container.OnDisconnected,
                [7] = _container.OnInitialized
            };

            _entities = new ConcurrentDictionary <int, HEntity>();
            Entities  = new ReadOnlyDictionary <int, HEntity>(_entities);

            _wallItems = new ConcurrentDictionary <int, HWallItem>();
            WallItems  = new ReadOnlyDictionary <int, HWallItem>(_wallItems);

            _floorItems = new ConcurrentDictionary <int, HFloorItem>();
            FloorItems  = new ReadOnlyDictionary <int, HFloorItem>(_floorItems);

            if (LicenseManager.UsageMode != LicenseUsageMode.Runtime)
            {
                return;
            }
            foreach (MethodInfo method in _container.GetType().GetAllMethods())
            {
                foreach (var dataCaptureAtt in method.GetCustomAttributes <DataCaptureAttribute>())
                {
                    dataCaptureAtt.Method = method;
                    if (_unknownDataAttributes.Any(dca => dca.Equals(dataCaptureAtt)))
                    {
                        continue;
                    }

                    dataCaptureAtt.Target = _container;
                    if (dataCaptureAtt.Id != null)
                    {
                        AddCallback(dataCaptureAtt, (ushort)dataCaptureAtt.Id);
                    }
                    else
                    {
                        _unknownDataAttributes.Add(dataCaptureAtt);
                    }
                }
            }
            _installer = HNode.ConnectNewAsync(moduleServer ?? DefaultModuleServer).GetAwaiter().GetResult();
            if (_installer == null)
            {
                OnCriticalError("Connection failed"); return;
            }
            Task handleInstallerDataTask = HandleInstallerDataAsync();
        }
Exemple #4
0
        private void Add(ConcurrentDictionary <Type, List <IExtension> > extensions, IExtension extension)
        {
            Trace.Verbose($"Registering extension: {extension.GetType().FullName}");
            List <IExtension> list = extensions.GetOrAdd(extension.ExtensionType, new List <IExtension>());

            extension.Initialize(HostContext);
            list.Add(extension);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HaveConfigurationSectionName"/> class.
        /// </summary>
        /// <param name="extension">The extension.</param>
        public HaveConfigurationSectionName(IExtension extension)
        {
            Ensure.ArgumentNotNull(extension, "extension");

            var namer = extension as IHaveConfigurationSectionName;

            this.SectionName = namer != null
                ? namer.SectionName
                : extension.GetType().Name;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HaveConfigurationSectionName"/> class.
        /// </summary>
        /// <param name="extension">The extension.</param>
        public HaveConfigurationSectionName(IExtension extension)
        {
            Ensure.ArgumentNotNull(extension, "extension");

            var namer = extension as IHaveConfigurationSectionName;

            this.SectionName = namer != null
                ? namer.SectionName
                : extension.GetType().Name;
        }
        public static byte[] GetResource(this IExtension extension, string path)
        {
            var attr = extension.GetType().GetCustomAttribute <ExtensionAttribute>();
            var ns   = attr.ResourceNamespace;
            var asm  = extension.GetType().Assembly;

            path = path.Replace("/", ".");

            using (var ms = new MemoryStream())
                using (var resourceStream = asm.GetManifestResourceStream(string.Concat(ns, ".", path)))
                {
                    if (resourceStream == null)
                    {
                        return(null);
                    }

                    resourceStream.CopyTo(ms);
                    return(ms.ToArray());
                }
        }
Exemple #8
0
        private void ResolveCallbacks()
        {
            var unresolved = new Dictionary <string, IList <string> >();

            foreach (PropertyInfo property in _container.GetType().GetAllProperties())
            {
                var messageAtt = property.GetCustomAttribute <MessageAttribute>();
                if (string.IsNullOrWhiteSpace(messageAtt?.Identifier))
                {
                    continue;
                }

                HMessage message = GetMessage(messageAtt.Identifier, messageAtt.IsOutgoing);
                if (message == null)
                {
                    if (!unresolved.TryGetValue(messageAtt.Identifier, out IList <string> users))
                    {
                        users = new List <string>();
                        unresolved.Add(messageAtt.Identifier, users);
                    }
                    users.Add($"Property({property.Name})");
                }
                else
                {
                    property.SetValue(_container, message);
                }
            }
            foreach (DataCaptureAttribute dataCaptureAtt in _unknownDataAttributes)
            {
                if (string.IsNullOrWhiteSpace(dataCaptureAtt.Identifier))
                {
                    continue;
                }
                HMessage message = GetMessage(dataCaptureAtt.Identifier, dataCaptureAtt.IsOutgoing);
                if (message == null)
                {
                    if (!unresolved.TryGetValue(dataCaptureAtt.Identifier, out IList <string> users))
                    {
                        users = new List <string>();
                        unresolved.Add(dataCaptureAtt.Identifier, users);
                    }
                    users.Add($"Method({dataCaptureAtt.Method})");
                }
                else
                {
                    AddCallback(dataCaptureAtt, message.Id);
                }
            }
            if (unresolved.Count > 0)
            {
                Console.WriteLine(new MessagesResolveException(ClientVersion, unresolved));
            }
        }
Exemple #9
0
        /// <summary>
        /// Serializes the given extensions.
        /// </summary>
        /// <param name="obj">The extension</param>
        /// <returns>The serialized data</returns>
        public string Serialize(IExtension obj)
        {
            var type = obj.GetType();

            if (serializers.ContainsKey(type))
            {
                return(serializers[type].Serialize(obj));
            }
            else
            {
                return(JsonConvert.SerializeObject(obj));
            }
        }
Exemple #10
0
        public ExtensionInfo(IExtension extension)
        {
            _extensionName = extension.GetMeta("Name");

            Type extensionType = extension.GetType();
            _guid = extension.Guid;

            Assembly extensionAssembly = extensionType.Assembly;
            _version = extensionAssembly.GetName().Version.ToString(3);
            _filePath = extensionAssembly.Location;
            FileInfo fileInfo = new FileInfo(_filePath);
            _fileSize = fileInfo.Length;
            _vendor = extension.GetMeta("Vendor");
        }
        public ExtensionsFileProvider(ILoggerFactory loggerFactory, IExtension extension)
        {
            this.Extension = extension;
            this.logger    = loggerFactory.CreateLogger <ExtensionsFileProvider>();
            var assembly = Assembly.GetAssembly(extension.GetType());

            // NB: consider using root path somehow
#if TEST
            this.inner  = new InnerFileProvider(assembly, this.Extension.Name);
            this.inner2 = new InnerFileProvider(assembly, $"{this.Extension.Name}.wwwroot");
#else
            this.inner  = new EmbeddedFileProvider(assembly, this.Extension.Name);
            this.inner2 = new EmbeddedFileProvider(assembly, $"{this.Extension.Name}.wwwroot");
#endif
        }
Exemple #12
0
        public EnabledExtensionObject(IExtension Extension)
        {
            Name     = Extension.ExtensionDescriptionAttribute.Name;
            Language = Extension.ExtensionDescriptionAttribute.Language;
            Type InterfaceType = Enumerable.FirstOrDefault(Extension.GetType().GetInterfaces());

            if (!Equals(InterfaceType, null))
            {
                ExtensionType = InterfaceType.Name;
            }
            else
            {
                ExtensionType = "UnknownExtension";
            }
        }
Exemple #13
0
        public ExtensionInfo(IExtension extension)
        {
            _extensionName = extension.GetMeta("Name");

            Type extensionType = extension.GetType();

            _guid = extension.Guid;

            Assembly extensionAssembly = extensionType.Assembly;

            _version  = extensionAssembly.GetName().Version.ToString(3);
            _filePath = extensionAssembly.Location;
            FileInfo fileInfo = new FileInfo(_filePath);

            _fileSize = fileInfo.Length;
            _vendor   = extension.GetMeta("Vendor");
        }
Exemple #14
0
        /// <summary>
        ///  Adds an extension to this Env to be used whenever this Env is used
        /// </summary>
        public void AddExension(IExtension extension)
        {
            if (_extensions == null)
            {
                _extensions = new Dictionary<int, IExtension>();
            }

            int hashCode = extension.GetType().GetHashCode();

            if (_extensions.ContainsKey(hashCode))
            {
                throw new Exception("Extension type is already loaded");
            }

            _extensions.Add(hashCode, extension);
            extension.Setup(this);
        }
Exemple #15
0
        /*
         * Extensions.
         */

        public IContext AddExtension(IExtension extension)
        {
            if (IsStarted)
            {
                throw new ContextException(ContextExceptionType.ExtensionInstallationAttemptAfterContextStart, extension.GetType().FullName);
            }

            var type = extension.GetType();

            if (_extensionInstances.ContainsKey(type))
            {
                throw new ContextException(ContextExceptionType.ExtensionInstanceAlreadyExists);
            }

            _extensions.Add(type);
            _extensionInstances.Add(type, extension);
            return(this);
        }
Exemple #16
0
        /// <summary>
        ///  Adds an extension to this Env to be used whenever this Env is used
        /// </summary>
        public void AddExension(IExtension extension)
        {
            if (_extensions == null)
            {
                _extensions = new Dictionary <int, IExtension>();
            }

            int hashCode = extension.GetType().GetHashCode();

            if (_extensions.ContainsKey(hashCode))
            {
                string message = String.Format("Extension type is already loaded: {0}", extension.GetType().FullName);
                throw new InvalidOperationException(message);
            }

            _extensions.Add(hashCode, extension);
            extension.Setup(this);
        }
        /// <inheritdoc />
        public IEnumerable<PropertyInfo> Reflect(IExtension extension)
        {
            Ensure.ArgumentNotNull(extension, "extension");

            return extension.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(x => x.CanWrite);
        }
Exemple #18
0
        private static string GetExtensionPath(IExtension ext)
        {
            var assembly = Assembly.GetAssembly(ext.GetType());

            return(assembly.Location);
        }
		void GPSProxy.Extension.IApplication.LogMessage(IExtension sender, string message)
		{
			ExtensionDetails details = GetExtensionDetails(sender.GetType());
			LogMessage(details.ExtensionAttribute.ExtensionName + ": " + message);
		}
Exemple #20
0
        /// <summary>
        /// Writes the specified Markdown object.
        /// </summary>
        /// <typeparam name="T">A MarkdownObject type</typeparam>
        /// <param name="obj">The Markdown object to write to this renderer.</param>
        /// <remarks>
        /// Write{T}(T obj) cannot be overridden. Therefore, copy 'n paste the complete impl
        /// of Render and modify it slightly so that errors are rendered.
        /// </remarks>
        public void WriteInternal <T>(T obj, bool isSummary = false) where T : MarkdownObject
        {
            if (obj == null)
            {
                return;
            }
            bool isError = false;

            if (obj is IExtensionBlock block && _blockErrors.ContainsKey(block))
            {
                if (!isSummary)
                {
                    var errors = _blockErrors[block];
                    var sb     = new StringBuilder();
                    sb.AppendLine("<ul class='error-list'>");
                    foreach (var error in errors.Errors)
                    {
                        sb.AppendLine("<li class='error'>");
                        IExtension extension     = _extensionByBlock[block];
                        string     extensionName = extension.GetType().Name;
                        var        parseError    = error as IParseError;
                        if (parseError != null)
                        {
                            sb.Append($@"<span class='Range'>{parseError.Range}</span> ");
                        }
                        sb.Append($@"<span class='extension-name'>{extensionName}:</span>");
                        sb.Append($@"<span class='message'>{error.Message}</span>");
                        sb.AppendLine("</li>");
                    }
                    sb.AppendLine("</ul>");
                    WriteLine(sb.ToString());
                }
                isError = true;
            }
            if (obj is IExtensionInline inline && _inlineErrors.ContainsKey(inline))
            {
                // TODO: implement and design a nice inline error visual
                isError = true;
            }

            if (!isError)
            {
                // Calls before writing an object
                //var writeBefore = ObjectWriteBefore;
                //ObjectWriteBefore?.Invoke(this, obj);

                // Handle regular renderers
                var  objectType         = obj.GetType();
                var  extensionBlock     = obj as IExtensionBlock;
                bool isSummaryExtension = extensionBlock != null &&
                                          _extensionByBlock.ContainsKey(extensionBlock) &&
                                          _extensionByBlock[extensionBlock].IsSummary;
                bool shouldRender = obj is MarkdownDocument ||
                                    (isSummary && isSummaryExtension) ||
                                    (!isSummary && !isSummaryExtension);

                IMarkdownObjectRenderer renderer = _previousObjectType == objectType ? _previousRenderer : null;
                if (renderer == null && !_renderersPerType.TryGetValue(objectType, out renderer))
                {
                    for (int i = 0; i < ObjectRenderers.Count; i++)
                    {
                        var testRenderer = ObjectRenderers[i];
                        if (testRenderer.Accept(this, obj))
                        {
                            _renderersPerType[objectType] = renderer = testRenderer;
                            break;
                        }
                    }
                }
                if (renderer != null && shouldRender)
                {
                    renderer.Write(this, obj);
                }
                else
                {
                    var containerBlock = obj as ContainerBlock;
                    if (containerBlock != null && shouldRender)
                    {
                        WriteChildrenInternal(containerBlock, isSummary);
                    }
                    else
                    {
                        var containerInline = obj as ContainerInline;
                        if (containerInline != null && shouldRender)
                        {
                            WriteChildrenInternal(containerInline);
                        }
                    }
                }

                _previousObjectType = objectType;
                _previousRenderer   = renderer;
            }

            // Calls after writing an object
            //var writeAfter = ObjectWriteAfter;
            //writeAfter?.Invoke(this, obj);
        }
 /// <summary>
 /// Registers an extension plugin.
 /// </summary>
 /// <param name="plugIn">IExtension object to register.</param>
 public void RegisterPlugIn(IExtension plugIn)
 {
     for (int i = 0; i < _ExtensionPlugIns.Count; i++)
     {
         if (_ExtensionPlugIns[i].GetType() == plugIn.GetType())
         {
             _ExtensionPlugIns[i] = plugIn;
             return;
         }
     }
     _ExtensionPlugIns.Add(plugIn);
 }
        /// <inheritdoc />
        public IEnumerable <PropertyInfo> Reflect(IExtension extension)
        {
            Ensure.ArgumentNotNull(extension, "extension");

            return(extension.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(x => x.CanWrite));
        }
Exemple #23
0
 internal static string GetExtensionPath(IExtension ext)
 {
     var assembly = Assembly.GetAssembly(ext.GetType());
     return assembly.Location;
 }
 public static string GetId(this IExtension extension)
 {
     return(extension.GetType().GetCustomAttribute <ExtensionAttribute>().ExtensionId);
 }
Exemple #25
0
        /// <summary>
        /// Load extensions within the given assembly, from assembly files in
        /// a given directory, or from source code files in a given directory
        /// </summary>
        /// <param name="assembly">Main assembly to load extensions from</param>
        /// <param name="path">Directory to load assembly and source code
        /// extensions from</param>
        /// <param name="owner">Object that owns the extensions. A reference to
        /// this is passed to the constructor of each extension</param>
        /// <param name="referencedAssemblies">List of assemblies the
        /// extensions need references to</param>
        /// <param name="assemblySearchPattern">Search pattern for extension
        /// dlls, for example MyApp.Extension.*.dll</param>
        /// <param name="sourceSearchPattern">Search pattern for extension
        /// source code files, for example MyApp.Extension.*.cs</param>
        /// <param name="assignablesParent">The object containing the
        /// assignable interfaces</param>
        /// <param name="assignableInterfaces">A list of interface references
        /// to assign extensions to</param>
        public static void LoadAllExtensions(Assembly assembly, string path, TOwner owner,
                                             List <string> referencedAssemblies, string assemblySearchPattern, string sourceSearchPattern,
                                             object assignablesParent, List <FieldInfo> assignableInterfaces)
        {
            // Add referenced assemblies to the C# compiler
            CSCompilerParams.ReferencedAssemblies.Clear();
            if (referencedAssemblies != null)
            {
                for (int i = 0; i < referencedAssemblies.Count; i++)
                {
                    CSCompilerParams.ReferencedAssemblies.Add(referencedAssemblies[i]);
                }
            }

            // Load internal extensions
            LoadAssemblyExtensions(assembly);

            // Load extensions from external assemblies
            List <string> extensionNames = ListExtensionAssemblies(path, assemblySearchPattern);

            foreach (string name in extensionNames)
            {
                LoadAssemblyExtensions(Assembly.LoadFile(name));
            }

            // Load extensions from external code files
            extensionNames = ListExtensionSourceFiles(path, sourceSearchPattern);
            foreach (string name in extensionNames)
            {
                CompilerResults results = CSCompiler.CompileAssemblyFromFile(CSCompilerParams, name);
                if (results.Errors.Count == 0)
                {
                    LoadAssemblyExtensions(results.CompiledAssembly);
                }
                else
                {
                    throw new ExtensionException("Error(s) compiling " + name);
                }
            }

            if (assignableInterfaces != null)
            {
                // Assign extensions to interfaces
                foreach (FieldInfo assignable in assignableInterfaces)
                {
                    Type type = assignable.FieldType;

                    for (int i = 0; i < Extensions.Count; i++)
                    {
                        IExtension <TOwner> extension = Extensions[i];

                        if (extension.GetType().GetInterface(type.Name) != null)
                        {
                            assignable.SetValue(assignablesParent, extension);
                        }
                    }
                }

                // Check for unassigned interfaces
                foreach (FieldInfo assignable in assignableInterfaces)
                {
                    if (assignable.GetValue(assignablesParent) == null)
                    {
                        throw new ExtensionException("Unassigned interface " + assignable.FieldType.Name);
                    }
                }
            }
        }
        public static string[] GetScripts(this IExtension extension)
        {
            var attr = extension.GetType().GetCustomAttribute <ExtensionAttribute>();

            return(attr.Scripts ?? Enumerable.Empty <string>().ToArray());
        }