Example #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="options">Options for the compiler.</param>
        public CompileAction(CompileOptions options, bool usedExternally = false)
        {
            Opcode.InitMachineCodeData();
            CompiledObject.InitTypeData();
            SafeSerializationMgr.CheckIDumperStatics();

            _usedExternally = usedExternally;
            _options        = options;

            _shared = new SafeSharedObjects();
            _shared.FunctionManager          = new FunctionManager(_shared);
            _shared.GameEventDispatchManager = new NoopGameEventDispatchManager();
            _shared.Processor     = new NoopProcessor();
            _shared.ScriptHandler = new KSScript();
            _shared.Screen        = new Screen();
            _shared.UpdateHandler = new UpdateHandler();
            _shared.VolumeMgr     = new VolumeManager();
            _shared.FunctionManager.Load();

            _compilerOptions = new CompilerOptions()
            {
                LoadProgramsInSameAddressSpace = false,
                IsCalledFromRun = false,
                FuncManager     = _shared.FunctionManager
            };

            _logger        = new CompilerLogger();
            _scriptLoader  = new KerboscriptLoader(_shared.VolumeMgr as VolumeManager, _logger, _options);
            _scriptDeleter = new KerboscriptDeleter(_options);
        }
Example #2
0
        public void CanHandleSerializableStructures()
        {
            Lexicon lex = new Lexicon();

            lex.Add(new StringValue("key1"), new StringValue("value1"));
            queue.Push(new BaseMessage(new SafeSerializationMgr(null).Dump(lex), 0, 0));

            Lexicon read = new SafeSerializationMgr(null).CreateFromDump(queue.Pop().Content as Dump) as Lexicon;

            Assert.AreEqual(new StringValue("value1"), read[new StringValue("key1")]);
        }
Example #3
0
        public override void Execute(SafeSharedObjects shared)
        {
            object pathObject = PopValueAssert(shared, true);

            AssertArgBottomAndConsume(shared);

            GlobalPath path   = shared.VolumeMgr.GlobalPathFromObject(pathObject);
            Volume     volume = shared.VolumeMgr.GetVolumeFromPath(path);

            VolumeFile volumeFile = volume.Open(path) as VolumeFile;

            if (volumeFile == null)
            {
                throw new KOSException("File does not exist: " + path);
            }

            Structure read = new SafeSerializationMgr(shared).Deserialize(volumeFile.ReadAll().String, JsonFormatter.ReaderInstance) as SerializableStructure;

            ReturnValue = read;
        }
Example #4
0
        public override void Execute(SafeSharedObjects shared)
        {
            object pathObject = PopValueAssert(shared, true);
            SerializableStructure serialized = PopValueAssert(shared, true) as SerializableStructure;

            AssertArgBottomAndConsume(shared);

            if (serialized == null)
            {
                throw new KOSException("This type is not serializable");
            }

            string serializedString = new SafeSerializationMgr(shared).Serialize(serialized, JsonFormatter.WriterInstance);

            FileContent fileContent = new FileContent(serializedString);

            GlobalPath path   = shared.VolumeMgr.GlobalPathFromObject(pathObject);
            Volume     volume = shared.VolumeMgr.GetVolumeFromPath(path);

            ReturnValue = volume.SaveFile(path, fileContent);
        }
Example #5
0
        public override void OnLoad(ConfigNode node)
        {
            Instance     = this;
            vesselQueues = new Dictionary <string, MessageQueue>();

            foreach (ConfigNode subNode in node.GetNodes())
            {
                if (subNode.name.Equals(VesselQueue))
                {
                    string id = subNode.GetValue(Id);

                    ConfigNode queueNode = subNode.GetNode(MessageQueue);

                    Dump queueDump = ConfigNodeFormatter.Instance.FromConfigNode(queueNode);

                    MessageQueue queue = new SafeSerializationMgr(null).CreateFromDump(queueDump) as MessageQueue;

                    if (queue.Count() > 0)
                    {
                        vesselQueues[id] = queue;
                    }
                }
            }
        }
Example #6
0
 static InterVesselManager()
 {
     // normally we do this in SerializationMgr, but KSPScenarios run before we create any instances
     SafeSerializationMgr.AddAssembly(typeof(SerializationMgr).Assembly.FullName);
 }
Example #7
0
 // This is what KSP calls during the initial loading screen (the screen
 // with the progress bar and all of the "Turning correct end toward space"
 // funny messages.)  This is where kOS *should* be putting all the
 // static initializing that does not change per-part, or per-vessel
 // or per-CPU.  It might be true that some of what we're doing up above
 // in OnLoad and OnStart might really belong here.
 //
 // At some future point it would be a really good idea to look very carefully
 // at *everything* being done during those initialzations and see if any of
 // those steps really are meant to be static do-once steps that belong here
 // instead:
 public override void OnAwake()
 {
     Opcode.InitMachineCodeData();
     CompiledObject.InitTypeData();
     SafeSerializationMgr.CheckIDumperStatics();
 }
Example #8
0
 public SerializationMgr(SharedObjects sharedObjects) : base(sharedObjects)
 {
     SafeSerializationMgr.AddAssembly(typeof(SerializationMgr).Assembly.FullName);
 }