public static void Main(string[] args) { allRegBase = new Dictionary <long, bool>(); for (long memorySize = 0; memorySize < Memory.MemorySize; memorySize = memorySize + Memory.FrameSize) { allRegBase.Add(memorySize, false); } Console.WriteLine(); var scriptProcessMemory = new ScriptProcess(Memory.MemorySize, Memory.FrameSize, allRegBase); scriptProcessMemory.CreateFile("../../../Inputs/data.csv", "M"); var orignalMemory = new Memory(); orignalMemory.PrintMemory(); Console.WriteLine(); var scriptProcess = new ScriptProcess(orignalMemory.Size, orignalMemory.FramesSize, null, 500); scriptProcess.CreateFile("../../../Inputs/processos.csv"); String Buffer = Utils.ReadInputFile("../../../Inputs/processos.csv"); List <Process> listProcess = Utils.CsvToProcessList(Buffer); FirstFit(listProcess); BestFit(listProcess); WorstFit(listProcess); QuickFit(listProcess); Console.WriteLine("Done!"); }
public JsonResult GerarProcessosInserir(int memoryID, long MemoryToFeelPerc, int ini, int fin) { try { if (ini > fin) { throw new Exception("O tamanho máximo do processo precisa ser maior que o mínimo!"); } Memory _memory = _context.Memories.Find(memoryID); if (_memory == null) { throw new Exception("Houve um erro! Memória não encontrada."); } if (_memory.IsGeneratedProcessList) { throw new Exception("A lista de memória já foi gerada, atualize a paginá para visualizar a lista de processos!"); } if ((_memory.InitialState + MemoryToFeelPerc) > 120) { throw new Exception("Valor para preencher inválido!"); } long _memoryToFeel = (long)(_memory.Size * ((float)MemoryToFeelPerc / 100)); List <Models.Process> processToInsert = ScriptProcess.GerarProcessosList(memoryID, _memoryToFeel, ini, fin); _memory.IsGeneratedProcessList = true; _context.Processes.AddRange(processToInsert); _context.SaveChangesAsync(); if (_memory.UserID != HttpContext.Session.GetInt32("UserID")) { throw new Exception("Você não possui permissão para gerar processos para essa memória!"); } return(Json( new { success = true } )); } catch (Exception e) { return(Json( new { success = false, error = e.Message } )); } }
/// <summary> /// Initializes a new instance of this class with the given data. /// </summary> /// <param name="entity">Entity to attach this process to.</param> /// <param name="process">Script process that this entitys logic script is contained in.</param> public ScriptExecutionProcess(EntityNode entity, ScriptProcess process) { _entity = entity; Process = process; _eventListener = new EventListener(ProcessEvent); EventManager.AttachListener(_eventListener); _priority = 1; // We always want to be executed before other processes. }
/// <summary> /// Called when this process needs to be destroyed. /// </summary> public override void Dispose() { if (_eventListener != null) { EventManager.DetachListener(_eventListener); } if (_process != null) { _process.Dispose(); } _eventListener = null; _process = null; _entity = null; }
/// <summary> /// Called when the state of this entities script is changed. /// </summary> /// <param name="process">Process that had its state changed.</param> /// <param name="sate">New state.</param> public void OnStateChange(ScriptProcess process, StateSymbol state) { if (_isServer == true) { return; } if (_mapScriptProcess != null && process == _mapScriptProcess.Process) { _window.MapScriptRenderFunction = state.FindSymbol("OnRender", SymbolType.Function) as FunctionSymbol; } else if (_gameScriptProcess != null && process == _gameScriptProcess.Process) { _window.GameScriptRenderFunction = state.FindSymbol("OnRender", SymbolType.Function) as FunctionSymbol; } }
/// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } //释放Telnet资源 if (Controller != null) { Controller.Dispose(); } //释放用户线程 if (ScriptProcess != null) { ScriptProcess.Abort(); ScriptProcess.Join(); } } base.Dispose(disposing); }
public IncomingType(MainForm mainForm, ScriptProcess script) { this._mainFrom = mainForm; this._scriptProcess = script; }
/// <summary> /// Loads this scene node from a given binary reader. /// </summary> /// <param name="reader">Binary reader to load this scene node from.</param> public override void Load(BinaryReader reader) { // Load all the basic entity details. base.Load(reader); // Load all the scripted specific details. if (reader.ReadBoolean() == true) { string url = reader.ReadString(); // Load the objects script from the memory stream we dumped it into. ScriptProcess process = VirtualMachine.GlobalInstance.LoadScript(url); #region Property Loading int propertyCount = reader.ReadInt16(); for (int i = 0; i < propertyCount; i++) { string identifier = reader.ReadString(); DataTypeValue dataTypeValue = new DataTypeValue((DataType)reader.ReadByte(), false, false); bool isArray = reader.ReadBoolean(); // Look through the script processes global variables to see if this // variable exists. VariableSymbol variableSymbol = null; if (process != null) { foreach (Symbol symbol in process.GlobalScope.Symbols) { if (symbol is VariableSymbol == false || ((VariableSymbol)symbol).Identifier != identifier || ((VariableSymbol)symbol).DataType != dataTypeValue) { continue; } variableSymbol = symbol as VariableSymbol; break; } } // Quickly find out the meta data of this symbol. string editMethod = ""; if (variableSymbol != null) { foreach (Symbol subSymbol in variableSymbol.Symbols) { if (subSymbol is MetaDataSymbol) { if (((MetaDataSymbol)subSymbol).Identifier.ToLower() == "editmethod") { editMethod = ((MetaDataSymbol)subSymbol).Value; break; } } } } // Read in value based on data type. if (isArray == true && reader.ReadBoolean() == true) { int arrayLength = reader.ReadInt32(); int arrayIndex = process == null ? 0 : process[0].AllocateArray(dataTypeValue.DataType, arrayLength); for (int k = 0; k < arrayLength; k++) { switch (dataTypeValue.DataType) { case DataType.Bool: { bool value = reader.ReadBoolean(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Byte: { byte value = reader.ReadByte(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Double: { double value = reader.ReadDouble(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Float: { float value = reader.ReadSingle(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Int: { int value = reader.ReadInt32(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Long: { long value = reader.ReadInt64(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.Short: { short value = reader.ReadInt16(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, k, value); } } break; case DataType.String: { string value = reader.ReadString(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, i, value); } } break; case DataType.Object: { if (reader.ReadBoolean() == true) { int type = reader.ReadByte(); if (type == 0) { string imageUrl = reader.ReadString(); int cellWidth = reader.ReadInt32(); int cellHeight = reader.ReadInt32(); int hSpacing = reader.ReadInt16(); int vSpacing = reader.ReadInt16(); if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, i, new Fusion.Engine.ScriptingFunctions.ImageScriptObject(GraphicsManager.LoadImage(imageUrl, cellWidth, cellHeight, hSpacing, vSpacing, 0))); } } else if (type == 1) { string soundUrl = reader.ReadString(); int freq = reader.ReadInt32(); float innerRadius = reader.ReadSingle(); float outerRadius = reader.ReadSingle(); bool loop = reader.ReadBoolean(); float pan = reader.ReadSingle(); float volume = reader.ReadSingle(); bool streaming = reader.ReadBoolean(); bool positional = reader.ReadBoolean(); Audio.SoundFlags flags = 0; if (streaming == true) { flags |= Audio.SoundFlags.Streamed; } if (positional == true) { flags |= Audio.SoundFlags.Positional; } Audio.Sound sound = Audio.AudioManager.LoadSound(soundUrl, flags); sound.Frequency = freq; sound.InnerRadius = innerRadius; sound.OuterRadius = outerRadius; sound.Looping = loop; sound.Pan = pan; sound.Volume = volume; if (process != null && variableSymbol != null) { process[0].SetArrayElement(arrayIndex, i, new Fusion.Engine.ScriptingFunctions.SoundScriptObject(sound)); } } } } break; } } } else { switch (dataTypeValue.DataType) { case DataType.Bool: { bool value = reader.ReadBoolean(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Byte: { byte value = reader.ReadByte(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Double: { double value = reader.ReadDouble(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Float: { float value = reader.ReadSingle(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Int: { int value = reader.ReadInt32(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Long: { long value = reader.ReadInt64(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Short: { short value = reader.ReadInt16(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.String: { string value = reader.ReadString(); if (process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, value); } } break; case DataType.Object: { if (reader.ReadBoolean() == true) { int type = reader.ReadByte(); if (type == 0) { string imageUrl = reader.ReadString(); int cellWidth = reader.ReadInt32(); int cellHeight = reader.ReadInt32(); int hSpacing = reader.ReadInt16(); int vSpacing = reader.ReadInt16(); if (ResourceManager.ResourceExists(imageUrl) == true && process != null && variableSymbol != null) { process[0].SetGlobalVariable(identifier, new Fusion.Engine.ScriptingFunctions.ImageScriptObject(GraphicsManager.LoadImage(imageUrl, cellWidth, cellHeight, hSpacing, vSpacing, 0))); } } else if (type == 1) { string soundUrl = reader.ReadString(); int freq = reader.ReadInt32(); float innerRadius = reader.ReadSingle(); float outerRadius = reader.ReadSingle(); bool loop = reader.ReadBoolean(); float pan = reader.ReadSingle(); float volume = reader.ReadSingle(); bool streaming = reader.ReadBoolean(); bool positional = reader.ReadBoolean(); Audio.SoundFlags flags = 0; if (streaming == true) { flags |= Audio.SoundFlags.Streamed; } if (positional == true) { flags |= Audio.SoundFlags.Positional; } if (ResourceManager.ResourceExists(soundUrl) == true && process != null && variableSymbol != null) { Audio.Sound sound = Audio.AudioManager.LoadSound(soundUrl, flags); sound.Frequency = freq; sound.InnerRadius = innerRadius; sound.OuterRadius = outerRadius; sound.Looping = loop; sound.Pan = pan; sound.Volume = volume; process[0].SetGlobalVariable(identifier, new Fusion.Engine.ScriptingFunctions.SoundScriptObject(sound)); } } } } break; } } } #endregion // Now set the process! _process.Process = process; if (_process.Process != null) { _process.Process.OnStateChange += OnStateChange; } if (_process.Process != null && _process.Process.State != null) { OnStateChange(_process.Process, _process.Process.State); } SyncCollisionEvents(); } }
/// <summary> /// Called when the state of this entities script is changed. /// </summary> /// <param name="process">Process that had its state changed.</param> /// <param name="sate">New state.</param> public void OnStateChange(ScriptProcess process, StateSymbol state) { _renderFunction = state == null ? null : _process.Process.State.FindSymbol("OnRender", SymbolType.Function) as FunctionSymbol; // SyncCollisionEvents(); }
public GuiType(MainForm mainForm, ScriptProcess scriptp) { _scriptProcess = scriptp; }
public DataInterceptedType(MainForm mainForm, ScriptProcess script) { this._script = script; }
/// <summary> /// Called when the state of this entities script is changed. /// </summary> /// <param name="process">Process that had its state changed.</param> /// <param name="sate">New state.</param> public void OnStateChange(ScriptProcess process, StateSymbol state) { _tickFunction = (state == null ? null : (state.FindSymbol("OnTick", SymbolType.Function) as FunctionSymbol)); }
public OutgoingType(MainForm mainForm, ScriptProcess script) { this._mainForm = mainForm; this._scriptProcess = script; }
public JsonResult Create(string Name, int SimulationID, long Size, long FramesSize, int InitialState, int InitialProcessMin, int InitialProcessMax) { ViewBag.userName = HttpContext.Session.GetString("UserName"); ViewBag.SimulationID = new SelectList(_context.Simulations.Where(s => s.UserID == HttpContext.Session.GetInt32("UserID")), "ID", "Name"); ViewBag.UserID = HttpContext.Session.GetInt32("UserID"); try { if (Name == null || SimulationID == 0 || Size == 0 || FramesSize == 0 || InitialState == 0 || InitialProcessMin == 0 || InitialProcessMax == 0) { throw new Exception("É necessário preencher os campos obrigatórios."); } if (Size % FramesSize != 0) { throw new Exception("Valor inválido para o tamanho do frame! O tamanho do frame precisa ser um multiplo do tamanho da memória."); } Memory memory = new Memory { Name = Name, UserID = HttpContext.Session.GetInt32("UserID"), IsGeneratedProcessList = false, SimulationID = SimulationID, Size = Size, FramesSize = FramesSize, InitialState = InitialState, InitialProcessMin = InitialProcessMin, InitialProcessMax = InitialProcessMax }; if (memory.InitialProcessMin > memory.InitialProcessMax) { throw new Exception("O tamanho máximo do processo precisa ser maior que o mínimo."); } memory.Size = Size * 1024; //transfoma em bytes memory.CreateDate = DateTime.Now; memory.FramesQTD = memory.Size / memory.FramesSize; memory.IsFirstFitCompleted = false; memory.IsNextFitCompleted = false; memory.IsBestFitCompleted = false; memory.IsWorstFitCompleted = false; int initialState = memory.InitialState; _context.Add(memory); int processesNeeded = (int)memory.FramesQTD * initialState / 100; List <Models.Process> processList = ScriptProcess.GerarProcessosIniciais(memory, initialState, memory.InitialProcessMin, memory.InitialProcessMax); List <Models.Frame> framesList = new List <Models.Frame>(); //generate the frames foreach (var item in processList) { var framesNeeded = item.RegL / memory.FramesSize; framesNeeded = item.RegL % memory.FramesSize > 0 ? framesNeeded + 1 : framesNeeded; for (int i = 0; i < framesNeeded; ++i) { Frame frameToAdd = new Frame(); frameToAdd.Memory = memory; frameToAdd.Name = item.Name; frameToAdd.IsInitial = true; frameToAdd.Process = item; frameToAdd.RegB = item.RegB + (i * memory.FramesSize); frameToAdd.FrameNumber = frameToAdd.RegB > 0 ? (int)(frameToAdd.RegB / memory.FramesSize) : 0; frameToAdd.FrameSize = (int)memory.FramesSize; //se for o ultimo frame, verifica qual a capacidade utilizada do mesmo if (i + 1 == framesNeeded) { frameToAdd.CapacidadeUtilizada = (int)(item.RegL % memory.FramesSize); } else { frameToAdd.CapacidadeUtilizada = (int)memory.FramesSize; } framesList.Add(frameToAdd); } } _context.AddRange(processList); _context.AddRange(framesList); _context.SaveChangesAsync(); return(Json( new { success = true } )); } catch (Exception e) { return(Json( new { success = false, error = e.Message } )); } }