Example #1
0
 private Image GetEntityImage(BaseAsset entity)
 {
     return(iconList.Images[entity.GetType().Name]);
 }
Example #2
0
        /// <summary>
        /// Executes.
        /// </summary>
        ///
        /// <param name="job"> The parameter. </param>
        ///
        /// <returns>
        /// A Dictionary&lt;string,bool&gt;
        /// </returns>
        public Boolean Execute(IJob job)
        {
            host.AddResult(Severity.Debug, true, $"{job.GetType().Name}.Execute('{job.Parm}')");

            host.AddResult(Severity.Info, true, $"[Decompiling '{Path.GetFileNameWithoutExtension(job.Parm)}' Assembly]");

            if (File.Exists(job.Parm))
            {
                //! See https://stackoverflow.com/questions/658498/how-to-load-an-assembly-to-appdomain-with-all-references-recursively
                //! See https://github.com/jduv/AppDomainToolkit
                //
                //! See https://msdn.microsoft.com/en-us/library/7hcs6az6(v=vs.110).aspx (this actually works as it does not lock Assemblies).
                //
                String dir = Path.GetDirectoryName(job.Parm);

                if (AppDomain.CurrentDomain.IsDefaultAppDomain())
                {
                    //Utils.SetDllDirectory(Path.GetDirectoryName(dir));

                    //ads = AppDomain.CurrentDomain.SetupInformation;
                    //ads.PrivateBinPath = dir;

                    //ad = AppDomain.CreateDomain("Mine", AppDomain.CurrentDomain.Evidence, ads);
                    //ad.Load(GetType().Assembly.FullName);
                    //ad.AssemblyLoad += Ad_AssemblyLoad;
                    //AppDomain.CurrentDomain.SetupInformation.SetPrivateBinPath(dir);

                    ad = AppDomain.CurrentDomain;

                    //if (parm.Contains("_Portable"))
                    //{
                    //    asm1 = AppDomain.CurrentDomain.Load(Utils.LoadFile(
                    //        Path.Combine(Path.GetDirectoryName(parm), "RageAssetManager_Portable.dll")
                    //        ));
                    //}
                    //

                    //! Fails 2nd time.
                    //Assembly x = Assembly.ReflectionOnlyLoad(Utils.LoadFile(parm));
                    //
                    //var asm = ad.CreateInstanceFrom(parm, "BaseAsset");

                    ad.Load(Utils.LoadFile(@"C:\Temp\NuGet\ClientSideGameStorageAsset\GameStorageClientAsset\bin\Debug\RageAssetManager.dll"));
                    ad.Load(Utils.LoadFile(@"C:\Temp\NuGet\ClientSideGameStorageAsset\GameStorageClientAsset_Portable\bin\Debug\RageAssetManager_Portable.dll"));

                    Assembly asm = ad.Load(Utils.LoadFile(job.Parm));

                    host.AddResult(Severity.Info, true, $"Loaded Assembly.");

                    host.AddResult(Severity.Info, true, $"Assembly using .Net {asm.ImageRuntimeVersion}.");

                    Debug.Print(asm.Location);

                    Type ba  = null;
                    Type bas = null;

                    //var a = AppDomain.CurrentDomain.CreateInstance(parm, "BaseAsset");

                    //! For portable assembly ExportedTypes fails with:
                    //! Could not load type 'AssetPackage.BaseAsset' from assembly 'GameStorageClientAsset_Portable
                    //! Might be that base asset is identical between the .Net 3.5 & .Net Portable assemblies.
                    //
                    //
                    foreach (Type t in asm.ExportedTypes)
                    {
                        if (t.BaseType != null && t.BaseType.Name.Equals(typeof(BaseAsset).Name))
                        {
                            ba = t;
                        }
                        if (t.BaseType != null && t.BaseType.Name.Equals(typeof(BaseSettings).Name))
                        {
                            bas = t;
                        }

                        //GameStorageClientAsset,BaseAsset
                        //GameStorageClientAssetSettings, BaseSettings

                        //Debug.Print($"{t.Name},{(t.BaseType != null ? t.BaseType.Name : "<none>")}");
                    }

                    //Utils.SetDllDirectory(Path.GetDirectoryName(null));

                    BaseAsset asset    = (BaseAsset)Activator.CreateInstance(ba);
                    ISettings Settings = asset.Settings;

                    MethodInfo mi = asset.GetType().GetRuntimeMethod("CheckHealth", new Type[] { });

                    //! Fails as AssetManager is to old (no AssetPackage.RequestSetttings.hasBinaryResponse field).
                    //
                    //Debug.Print($"CheckHealth: {mi.Invoke(asset, new object[] { })})");
                }
            }
            else
            {
                host.AddResult(Severity.Warning, false, $"Failed to Locate Assembly.");

                return(false);
            }

            return(true);
        }