Exemplo n.º 1
0
        public static Assembly[] AssembliesFromStrings(String[] foldernames, iManagerCallback datahook)
        {
            List <Assembly> buildlist = new List <Assembly>();

            buildlist.Add(Assembly.GetExecutingAssembly());
            foreach (String loopfolder in foldernames)
            {
                if (Directory.Exists(loopfolder))
                {
                    foreach (FileInfo loopfile in new DirectoryInfo(loopfolder).GetFiles("*.dll", SearchOption.TopDirectoryOnly))
                    {
                        Assembly testassembly;
                        try
                        {
                            testassembly = Assembly.LoadFile(loopfile.FullName);
                            if (testassembly != null)
                            {
                                buildlist.Add(testassembly);
                            }
                        }
                        catch (Exception err)
                        {
                            //Debug.Print("failed to load assembly:" + loopfile.FullName + " " + err.Message);
                            datahook.ShowMessage("failed to load assembly:" + loopfile.FullName + " " + err.Message);
                        }
                    }
                }
            }



            return(buildlist.ToArray());
        }
Exemplo n.º 2
0
        public TemplateManager(IEnumerable<DirectoryInfo> Dirinfos, iManagerCallback callback)
        {
            foreach (DirectoryInfo loopdir in Dirinfos)
            {
                LoadTemplates(loopdir, callback);

            }
        }
Exemplo n.º 3
0
 public LoadedTypeManager(Assembly[] lookassemblies, Type lookfor, IEnumerable <string> ignoreassemblynames,
                          iManagerCallback pcallback, TypeManagerInspectTypeCallback pinspectioncallback)
 {
     TypeManage = lookfor;
     this.inspectioncallback = pinspectioncallback;
     LoadTypes(lookassemblies, ignoreassemblynames);
     //LoadTypeScores(ManagedTypes.ToArray(), mcallback);
 }
Exemplo n.º 4
0
        public static void GameInitialize(iManagerCallback datahook)
        {
            OrbImages = new Image[PrebuiltOrbImageCount];
            for(int i=0;i<PrebuiltOrbImageCount;i++)
            {
                OrbImages[i] = DrawOrbBlockImage();

            }
        }
Exemplo n.º 5
0
        public LoadedTypeManager(string[] slookfolders, Type lookfor, IEnumerable <string> ignoreassemblynames,
                                 iManagerCallback pcallback)
        {
            //alright, iterate through all the folders..
            mcallback  = pcallback;
            TypeManage = lookfor;


            DirectoryInfo[] lookfolders = new DirectoryInfo[slookfolders.Length];
            for (int i = 0; i < slookfolders.Length; i++)
            {
                lookfolders[i] = new DirectoryInfo(slookfolders[i]);
            }

            List <Assembly> AssemblyList = new List <Assembly>();

            foreach (DirectoryInfo loopfolder in lookfolders)
            {
                //now iterate through all the DLL files in that folder.
                if (loopfolder.Exists)
                {
                    foreach (FileInfo dllfile in loopfolder.GetFiles("*.dll", SearchOption.TopDirectoryOnly))
                    {
                        Assembly LoadAssembly = null;
                        //attempt to load this as an assembly...
                        try
                        {
                            LoadAssembly = Assembly.LoadFile(dllfile.FullName);
                            mcallback.ShowMessage("Loaded Assembly:" + dllfile.Name);
                        }
                        catch (Exception error)
                        {
                            mcallback.ShowMessage("Load of " + dllfile.Name + " failed- " + error.Message);
                        }

                        if (LoadAssembly != null)
                        {
                            if (
                                !ignoreassemblynames.Any <String>
                                (
                                    (y) => y.Equals(LoadAssembly.GetName().Name, StringComparison.OrdinalIgnoreCase)))
                            {
                                AssemblyList.Add(LoadAssembly);
                            }
                        }
                    }
                }
            }

            mcallback.ShowMessage("Found " + AssemblyList.Count.ToString() + " Assemblies.");
            AssemblyList.Add(Assembly.GetExecutingAssembly()); //add this assembly, so it can find the default builder.
            LoadTypes(AssemblyList.ToArray());
            //LoadTypeScores(ManagedTypes.ToArray(), mcallback);
        }
Exemplo n.º 6
0
        private void DoInit()
        {
            try
            {
                logfilename = Path.Combine(BCBlockGameState.AppDataFolder, "baseblock.log");


                filelogwriter = new FileLogCallback(logfilename);
            }
            catch
            {
            }
        }
Exemplo n.º 7
0
        public static bool CheckType(Type looptype, Type TypeManage, iManagerCallback mcallback)
        {
            int CountInFile = 0;

            //if (BCBlockGameState.Verbose) mcallback.ShowMessage("checking:" + looptype.Name);
            if (!looptype.IsAbstract)
            {
                //added more recently: check wether it is a class derived from the given type.
                if (looptype.IsSubclassOf(TypeManage))
                {
                    mcallback.ShowMessage("Found " + TypeManage.Name + " Derivation:" +
                                          looptype.Name);

                    //ManagedTypes.Add(looptype);
                    CountInFile++;
                    //break out of the immediate loop.
                }
                else
                {
                    foreach (var loopinterface in looptype.GetInterfaces())
                    {
                        try
                        {
                            if (loopinterface.Equals(TypeManage))
                            {
                                mcallback.ShowMessage("Found " + TypeManage.Name + " Implementor:" +
                                                      looptype.Name);

                                //ManagedTypes.Add(looptype);
                                CountInFile++;
                                //break out of the immediate loop.
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.Print("Exception:" + ex.Message);
                        }
                    }
                }
            }
            else
            {
                Debug.Print("Skipped Abstract class:" + looptype.FullName);
            }
            return(CountInFile > 0);
        }
Exemplo n.º 8
0
        public void LoadTemplates(DirectoryInfo Directory, iManagerCallback callback)
        {
            //load all .blf files from the given folder.
            DirectoryInfo di = Directory;
            callback.ShowMessage("Loading Templates from " + Directory);
            //iterate...
            foreach (FileInfo blffile in di.GetFiles("*.blf"))
            {
                try
                {
                    TemplateSetData tsd = new TemplateSetData(blffile.FullName);
                    LoadedTemplates.Add(tsd.Name, tsd);
                }
                catch (Exception exx)
                {
                    callback.ShowMessage("Failed to load template data from " + blffile.FullName + " Exception:" + exx);
                }

            }
        }
Exemplo n.º 9
0
        private List <T> RemoveDuplicates <T>(List <T> removefrom, iManagerCallback mcallback)
        {
            Dictionary <T, T> Dictcheck = new Dictionary <T, T>();


            foreach (T item in removefrom)
            {
                if (!Dictcheck.ContainsKey(item))
                {
                    Dictcheck.Add(item, item);
                }
                else
                {
                    mcallback.ShowMessage("removing duplicate entry for " + item.ToString());
                }
            }


            return(Dictcheck.Keys.ToList());
        }
Exemplo n.º 10
0
        public MultiTypeManager(IEnumerable <Assembly> lookassemblies, IEnumerable <Type> typesload,
                                iManagerCallback pcallback, AssemblyLoadTestFunction TestAssembly,
                                TypeManagerLoadProgressCallback pprog,
                                LoadedTypeManager.TypeManagerInspectTypeCallback pinspectioncallback,
                                IEnumerable <Assembly> preloadedassemblies)
        {
            lookassemblies = LoadedTypeManager.RemoveDuplicates(lookassemblies, pcallback).AsParallel();
            //each Type corresponds to a new LoadedTypeManager to load for that type.
            //LoadedTypeManager[] ltm = new LoadedTypeManager[typesload.Length];
            if (TestAssembly == null)
            {
                TestAssembly = ass => true;
            }
            //create the Dictionary first...
            inspectioncallback = pinspectioncallback;
            List <Assembly> buildcheck = new List <Assembly>();

            if (preloadedassemblies != null)
            {
                foreach (var addassembly in preloadedassemblies)
                {
                    if (!buildcheck.Contains(addassembly))
                    {
                        buildcheck.Add(addassembly);
                    }
                }
            }

            if (lookassemblies != null)
            {
                foreach (var addassembly in lookassemblies)
                {
                    if (!buildcheck.Contains(addassembly))
                    {
                        buildcheck.Add(addassembly);
                    }
                }
            }


            Assembly[] checkassemblies = buildcheck.ToArray();
            useassemblies = checkassemblies;
            loadeddata    = new Dictionary <Type, LoadedTypeManager>();
            foreach (Type looptype in typesload)
            {
                // LoadedTypeManager addtm = new LoadedTypeManager(checkassemblies,looptype, IgnoreAssemblies,pcallback);
                LoadedTypeManager addtm = new LoadedTypeManager(looptype);
                addtm.inspectioncallback = inspectioncallback;
                loadeddata.Add(looptype, addtm);
            }


            //now that we have the LoadedTypeManager objects, uninitialized- we can iterate through each assembly and the types
            //in each assembly for matches.
            //assemblyprogressincrement: the amount of progress we will go through after checking each assembly.
            float assemblyprogressincrement = 1f / (float)checkassemblies.Count();
            float currprogress = 0;

            foreach (Assembly loopassembly in checkassemblies)
            {
                if (TestAssembly(loopassembly))
                {
                    pcallback.ShowMessage("Inspecting Assembly:" + loopassembly.GetName().Name);
                    //iterate through each type...
                    currprogress += assemblyprogressincrement;
                    Type[] typesiterate;
                    try
                    {
                        typesiterate = loopassembly.GetTypes();
                    }
                    catch (ReflectionTypeLoadException rtle)
                    {
                        pcallback.ShowMessage
                            ("ReflectionTypeLoadException occured;" + rtle.StackTrace +
                            " InnerExceptions:");
                        foreach (Exception loopexception in rtle.LoaderExceptions)
                        {
                            pcallback.ShowMessage
                                ("RTLE Loader Exception:" + loopexception.Message + " Source:" +
                                loopexception.Source + "stack Trace:" + loopexception.StackTrace);
                        }

                        pcallback.ShowMessage("End of RTLE Loader Exceptions");
                        currprogress += assemblyprogressincrement;
                        pprog(currprogress);
                        typesiterate = null;
                    }

                    if (typesiterate != null)
                    {
                        //iterate through each type...

                        //get appropriate percent per type...
                        // float percentpertype = assemblyprogressincrement / typesiterate.Length;

                        foreach (Type looptype in typesiterate)
                        {
                            //currprogress+=percentpertype;

                            //if this is a class type...


                            // pcallback.ShowMessage("Checking type:" + looptype.FullName);
                            //And... for each type, iterate through all the LoadedTypeManagers in our dictionary...
                            foreach (var checkmanager in loadeddata)
                            {
                                if (LoadedTypeManager.CheckType(looptype, checkmanager.Key, pcallback))
                                {
                                    pcallback.ShowMessage
                                        ("Type:" + looptype.FullName + " is a, or implements, " +
                                        checkmanager.Key.Name);

                                    //add it to that manager...
                                    if (inspectioncallback != null)
                                    {
                                        inspectioncallback(looptype);
                                    }
                                    if (looptype != null)
                                    {
                                        checkmanager.Value.ManagedTypes.Add(looptype);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    currprogress += assemblyprogressincrement;
                    pprog(currprogress);
                    pcallback.ShowMessage("Skipped Assembly " + loopassembly.FullName);
                }
            }

            //at the conclusion of the loop, show a summary.
            if (!(pcallback is Nullcallback))
            {
                pcallback.ShowMessage
                    ("Assembly enumeration complete.(" + checkassemblies.Count().ToString() +
                    " Assemblies ");
                //^save time by not doing this for a Nullcallback...
                foreach (var loopltm in loadeddata)
                {
                    pcallback.ShowMessage
                        (" found " + loopltm.Value.ManagedTypes.Count + " instances of type " +
                        loopltm.Key.Name);
                }
            }
        }
Exemplo n.º 11
0
        private void DoInit()
        {
            try
            {
                logfilename = Path.Combine(BCBlockGameState.AppDataFolder, "baseblock.log");


                filelogwriter = new FileLogCallback(logfilename);
            }
            catch
            {
            }
        }
Exemplo n.º 12
0
        public static IEnumerable <Assembly> AssembliesFromStrings(IEnumerable <String> foldernames, iManagerCallback datahook)
        {
            yield return(Assembly.GetExecutingAssembly());

            foreach (String loopfolder in foldernames)
            {
                if (Directory.Exists(loopfolder))
                {
                    foreach (
                        FileInfo loopfile in
                        new DirectoryInfo(loopfolder).GetFiles("*.dll", SearchOption.TopDirectoryOnly))
                    {
                        Assembly testassembly = null;
                        try
                        {
                            if (loopfile.FullName.EndsWith("DragonAdapter.dll", StringComparison.OrdinalIgnoreCase))
                            {
                                Debug.Print("Dragon");
                            }

                            testassembly = Assembly.LoadFile(loopfile.FullName);
                        }
                        catch (Exception err)
                        {
                            //Debug.Print("failed to load assembly:" + loopfile.FullName + " " + err.Message);
                            datahook.ShowMessage("failed to load assembly:" + loopfile.FullName + " " + err.Message);
                        }

                        if (testassembly != null)
                        {
                            yield return(testassembly);
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Directly initializes a LoadedTypeManager instance with a specified list of managed types and the Type being managed.
 /// </summary>
 /// <param name="pTypeManage"></param>
 /// <param name="pmanagedtypes"></param>
 /// <param name="pcallback"></param>
 internal LoadedTypeManager(Type pTypeManage, IEnumerable <Type> pmanagedtypes, iManagerCallback pcallback)
 {
     TypeManage   = pTypeManage;
     ManagedTypes = pmanagedtypes.ToList();
     mcallback    = pcallback;
 }
Exemplo n.º 14
0
 public void LoadTemplates(String Directory, iManagerCallback callback)
 {
     LoadTemplates(new DirectoryInfo(Directory), callback);
 }
Exemplo n.º 15
0
        internal static IEnumerable <T> RemoveDuplicates <T>(IEnumerable <T> removefrom, iManagerCallback mcallback)
        {
            Dictionary <T, T> Dictcheck = new Dictionary <T, T>();


            foreach (T item in removefrom)
            {
                if (item != null)
                {
                    if (!Dictcheck.ContainsKey(item))
                    {
                        Dictcheck.Add(item, item);
                        yield return(item);
                    }
                    else
                    {
                        mcallback.ShowMessage("removing duplicate entry for " + item.ToString());
                    }
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Internal constructor used to create a LoadedTypeManager that has no actual state. This is used by the MultiTypeManager class
 /// to create "empty" TypeManager instances that it can then add to.
 /// </summary>
 /// <param name="ptypemanage"></param>
 /// <param name="pcallback"></param>
 internal LoadedTypeManager(Type ptypemanage, iManagerCallback pcallback)
 {
     TypeManage = ptypemanage;
     mcallback  = pcallback;
 }
Exemplo n.º 17
0
 public LoadedTypeManager(Assembly[] lookassemblies, Type lookfor, iManagerCallback pcallback)
     : this(lookassemblies, lookfor, null, pcallback)
 {
 }
Exemplo n.º 18
0
        public MultiTypeManager(Assembly[] lookassemblies, Type[] typesload, IEnumerable <String> IgnoreAssemblies, IEnumerable <String> IncludeAssemblies, iManagerCallback pcallback, TypeManagerLoadProgressCallback pprog, Assembly[] preloadedassemblies)
        {
            //each Type corresponds to a new LoadedTypeManager to load for that type.
            //LoadedTypeManager[] ltm = new LoadedTypeManager[typesload.Length];

            //create the Dictionary first...
            if (IgnoreAssemblies == null)
            {
                IgnoreAssemblies = new String[] { }
            }
            ;
            List <Assembly> buildcheck = new List <Assembly>();

            if (preloadedassemblies != null)
            {
                buildcheck.AddRange(preloadedassemblies);
            }
            buildcheck.AddRange(lookassemblies);

            Assembly[] checkassemblies = buildcheck.ToArray();

            loadeddata = new Dictionary <Type, LoadedTypeManager>();
            foreach (Type looptype in typesload)
            {
                LoadedTypeManager addtm = new LoadedTypeManager(looptype, pcallback);
                loadeddata.Add(looptype, addtm);
            }



            //now that we have the LoadedTypeManager objects, uninitialized- we can iterate through each assembly and the types
            //in each assembly for matches.
            //assemblyprogressincrement: the amount of progress we will go through after checking each assembly.
            float assemblyprogressincrement = 1f / (float)checkassemblies.Count();
            float currprogress = 0;

            foreach (Assembly loopassembly in checkassemblies)
            {
                if ((loopassembly.GetName().Name.StartsWith("script_", StringComparison.OrdinalIgnoreCase)) || (!IgnoreAssemblies.Any((w) => loopassembly.GetName().Name.TestRegex(w))))
                {
                    pcallback.ShowMessage("Inspecting Assembly:" + loopassembly.GetName().Name);
                    //iterate through each type...
                    currprogress += assemblyprogressincrement;
                    Type[] typesiterate;
                    try
                    {
                        typesiterate = loopassembly.GetTypes();
                    }
                    catch (ReflectionTypeLoadException rtle)
                    {
                        pcallback.ShowMessage("ReflectionTypeLoadException occured;" + rtle.StackTrace +
                                              " InnerExceptions:");
                        foreach (Exception loopexception in rtle.LoaderExceptions)
                        {
                            pcallback.ShowMessage("RTLE Loader Exception:" + loopexception.Message + " Source:" +
                                                  loopexception.Source + "stack Trace:" + loopexception.StackTrace);
                        }
                        pcallback.ShowMessage("End of RTLE Loader Exceptions");
                        currprogress += assemblyprogressincrement;
                        if (pprog != null)
                        {
                            pprog(currprogress);
                        }
                        typesiterate = null;
                    }
                    if (typesiterate != null)
                    {
                        //iterate through each type...

                        //get appropriate percent per type...
                        // float percentpertype = assemblyprogressincrement / typesiterate.Length;

                        foreach (Type looptype in typesiterate)
                        {
                            //currprogress+=percentpertype;



                            // pcallback.ShowMessage("Checking type:" + looptype.FullName);
                            //And... for each type, iterate through all the LoadedTypeManagers in our dictionary...
                            foreach (var checkmanager in loadeddata)
                            {
                                if (LoadedTypeManager.CheckType(looptype, checkmanager.Key, pcallback))
                                {
                                    pcallback.ShowMessage("Type:" + looptype.FullName + " is a, or implements, " +
                                                          checkmanager.Key.Name);
                                    //add it to that manager...
                                    checkmanager.Value.ManagedTypes.Add(looptype);
                                }
                            }
                        }
                    }
                }
                else
                {
                    currprogress += assemblyprogressincrement;
                    pprog(currprogress);
                    pcallback.ShowMessage("Skipped Assembly " + loopassembly.FullName);
                }
            }

            //at the conclusion of the loop, show a summary.
            if (!(pcallback is Nullcallback))
            {
                pcallback.ShowMessage("Assembly enumeration complete.(" + checkassemblies.Count().ToString() + " Assemblies ");
                //^save time by not doing this for a Nullcallback...
                foreach (var loopltm in loadeddata)
                {
                    pcallback.ShowMessage(" found " + loopltm.Value.ManagedTypes.Count + " instances of type " + loopltm.Key.Name);
                }
            }
        }
    }
Exemplo n.º 19
0
 public MultiTypeManager(String[] lookfolders, Type[] typesload,
                         iManagerCallback pcallback, AssemblyLoadTestFunction TestAssembly,
                         TypeManagerLoadProgressCallback pp, Assembly[] preloadedassemblies)
     : this(AssembliesFromStrings(lookfolders), typesload, pcallback, TestAssembly, pp, preloadedassemblies)
 {
 }
Exemplo n.º 20
0
 public MultiTypeManager(Assembly[] checkassemblies, Type[] typesload, IEnumerable <String> IgnoreAssemblies, iManagerCallback pcallback, TypeManagerLoadProgressCallback pprog, Assembly[] preloadedassemblies)
     : this(checkassemblies, typesload, IgnoreAssemblies, new List <String>(), pcallback, pprog, preloadedassemblies)
 {
 }
Exemplo n.º 21
0
 public MultiTypeManager(String[] lookfolders, Type[] typesload, IEnumerable <String> IgnoreAssemblies,
                         iManagerCallback pcallback, TypeManagerLoadProgressCallback pp, Assembly[] preloadedassemblies)
     : this(AssembliesFromStrings(lookfolders), typesload, IgnoreAssemblies, pcallback, pp, preloadedassemblies)
 {
 }
Exemplo n.º 22
0
        public static bool CheckType(Type looptype, Type TypeManage, iManagerCallback mcallback)
        {
            if (looptype == null || TypeManage == null)
            {
                return(false);
            }
            int CountInFile = 0;


            if (!looptype.IsAbstract)
            {
                //if this is the type we want already, then we add it.
                //Seems a class cannot be a "Subclass" of itself. Realistically if the Type we are looking for is itself
                //instantiable we want to include it.
                if (looptype == TypeManage)
                {
                    return(true);
                }
                //added more recently: check wether it is a class derived from the given type.
                if (looptype.IsSubclassOf(TypeManage))
                {
                    mcallback.ShowMessage
                        ("Found " + TypeManage.Name + " Derivation:" +
                        looptype.Name);

                    //ManagedTypes.Add(looptype);
                    CountInFile++;
                    //break out of the immediate loop.
                }
                else
                {
                    foreach (var loopinterface in looptype.GetInterfaces())
                    {
                        try
                        {
                            if (loopinterface.Equals(TypeManage))
                            {
                                mcallback.ShowMessage
                                    ("Found " + TypeManage.Name + " Implementor:" +
                                    looptype.Name);

                                //ManagedTypes.Add(looptype);
                                CountInFile++;
                                //break out of the immediate loop.
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.Print("Exception:" + ex.Message);
                        }
                    }
                }
            }
            else
            {
                // Debug.Print("Skipped Abstract class:" + looptype.FullName);
            }

            return(CountInFile > 0);
        }
Exemplo n.º 23
0
 public TemplateManager(IEnumerable<String> Directories, iManagerCallback callback)
     : this((from p in Directories select new DirectoryInfo(p)), callback)
 {
 }
Exemplo n.º 24
0
 /// <summary>
 /// Directly initializes a LoadedTypeManager instance with a specified list of managed types and the Type being managed.
 /// </summary>
 /// <param name="pTypeManage"></param>
 /// <param name="pmanagedtypes"></param>
 /// <param name="pcallback"></param>
 internal LoadedTypeManager(Type pTypeManage, Type[] pmanagedtypes, iManagerCallback pcallback)
 {
     TypeManage   = pTypeManage;
     ManagedTypes = pmanagedtypes.ToList();
     mcallback    = pcallback;
 }
Exemplo n.º 25
0
 public MultiTypeManager(IEnumerable <Assembly> lookassemblies, IEnumerable <Type> typesload,
                         iManagerCallback pcallback, AssemblyLoadTestFunction TestAssembly,
                         TypeManagerLoadProgressCallback pprog, IEnumerable <Assembly> preloadedassemblies)
     : this(lookassemblies, typesload, pcallback, TestAssembly, pprog, null, preloadedassemblies)
 {
 }
Exemplo n.º 26
0
 public LoadedTypeManager(string[] slookfolders, Type lookfor, iManagerCallback pcallback)
     : this(slookfolders, lookfor, new String[] { }, pcallback)
 {
 }
Exemplo n.º 27
0
 public LoadedTypeManager(String lookfolder, Type lookfor, iManagerCallback pcallback)
     : this(new string[] { lookfolder }, lookfor, pcallback)
 {
 }
Exemplo n.º 28
0
 public LoadedTypeManager(Assembly[] lookassemblies, Type lookfor, IEnumerable <string> ignoreassemblynames,
                          iManagerCallback pcallback)
     : this(lookassemblies, lookfor, ignoreassemblynames, pcallback, null)
 {
 }