예제 #1
0
        public CompilerErrorCollection TryCompileModule(dynamic moduleObject)
        {
            RequireSystemSigned();

            CompilerErrorCollection compilerErrors = new CompilerErrorCollection();

            Contract.Module module = ModuleManager.Session.Modules.Where(P => P.ID == moduleObject.ID).FirstOrDefault();

            if (module != null && !module.Locked)
            {
                module            = Contract.Module.FromString(module.ToString()); // Create a copy of the module
                module.References = ((ThirdParty.JsonArray)moduleObject.References).Select(r => (string)r).ToList();

                ModuleReversion moduleReversion = new ModuleReversion()
                {
                    Version = module.LatestReversion.Version + 1, Updated = DateTime.UtcNow, Classes = new List <ModuleClass>()
                };
                moduleReversion.Classes = ((ThirdParty.JsonArray)moduleObject.LatestReversion.Classes).Select(p => new ModuleClass()
                {
                    Name = ((dynamic)p).Name, Data = ((dynamic)p).Data
                }).ToList();

                module.LatestReversion = moduleReversion;
                module.CompileClasses(out compilerErrors, false);
            }
            else
            {
                compilerErrors.Add(new CompilerError("", 0, 0, "", "Module is locked."));
            }

            return(compilerErrors);
        }
예제 #2
0
        public CompilerErrorCollection UpdateModule(dynamic moduleObject)
        {
            RequireSystemSigned();

            CompilerErrorCollection compilerErrors = new CompilerErrorCollection();

            Contract.Module module = ModuleManager.Session.Modules.Where(P => P.ID == moduleObject.ID).FirstOrDefault();

            if (module == null)
            {
                module = new Contract.Module()
                {
                    ID         = moduleObject.ID,
                    References = ((ThirdParty.JsonArray)moduleObject.References).Select(r => (string)r).ToList(),
                };

                ModuleReversion moduleReversion = new ModuleReversion()
                {
                    Version = 1, Updated = DateTime.UtcNow, Classes = new List <ModuleClass>()
                };
                moduleReversion.Classes = ((ThirdParty.JsonArray)moduleObject.LatestReversion.Classes).Select(p => new ModuleClass()
                {
                    Name = ((dynamic)p).Name, Data = ((dynamic)p).Data
                }).ToList();

                module.LatestReversion = moduleReversion;
                ModuleManager.Session.AppendModuleReversion(module.ID, moduleReversion);

                ModuleManager.Session.Modules.Add(module);
                module.CompileClasses(out compilerErrors);
                module.Save();
            }
            else if (!module.Locked)
            {
                module.References = ((ThirdParty.JsonArray)moduleObject.References).Select(r => (string)r).ToList();
                ModuleReversion moduleReversion = new ModuleReversion()
                {
                    Version = module.LatestReversion.Version + 1, Updated = DateTime.UtcNow, Classes = new List <ModuleClass>()
                };
                moduleReversion.Classes = ((ThirdParty.JsonArray)moduleObject.LatestReversion.Classes).Select(p => new ModuleClass()
                {
                    Name = ((dynamic)p).Name, Data = ((dynamic)p).Data
                }).ToList();

                module.LatestReversion = moduleReversion;
                ModuleManager.Session.AppendModuleReversion(module.ID, moduleReversion);

                module.CompileClasses(out compilerErrors);
                module.Save();
            }
            else
            {
                compilerErrors.Add(new CompilerError("", 0, 0, "", "Module is locked"));
            }

            return(compilerErrors);
        }