public Simulator.Infrastructure.Repository.SimulationStatus InicializeModuleByStream(System.IO.Stream XMLInputstream) { XmlSerializer serializer = new XmlSerializer(typeof(VAM_Descriptor)); try { using (XmlReader reader = XmlReader.Create(XMLInputstream)) { InputDescriptor = (VAM_Descriptor)serializer.Deserialize(reader); } } catch (Exception e) { return SimulationStatus.Corrupted; } try { SimulatorViewModel.SimulatorModel.CreateSimulatorDomain(InputDescriptor); SimulatorViewModel.InputDescriptor = InputDescriptor; } catch (Exception e) { return SimulationStatus.Corrupted; } return SimulationStatus.Runnable; }
public VAM_SimulatorModel(VAM_Descriptor InputDescriptor) { this.CreateSimulatorDomain(InputDescriptor); }
public void CreateSimulatorDomain(VAM_Descriptor descriptor) { StepCounter = 0; Addressing = new AddressingExtended(descriptor.Addressing); Metrics = new Metrics(Addressing.AssociativeMemoryAccessTime, Addressing.MemoryAccessTime); ObservableCollection<MappingRecordOfProcessAndMemory> addList = new ObservableCollection<MappingRecordOfProcessAndMemory>(); foreach (MappingRecordOfProcessAndMemory record in descriptor.ProcessPageAndMemoryPageMapping) { bool addItem = true; if (record.ProcessPage >= Addressing.NumberOfPages || record.ProcessPage < 0) { addItem = false; continue; } if (record.MemoryFrame >= Addressing.QuantityOfPagesStorableInUserMemory || record.MemoryFrame < 0) { addItem = false; continue; } for (int i = addList.Count - 1; i > 0; i--) { if (record.MemoryFrame == addList.ElementAt(i).MemoryFrame) { addItem = false; break; } if (record.ProcessPage == addList.ElementAt(i).ProcessPage) { addItem = false; break; } } if (addItem) { addList.Add(record); } } ProcessPageAndMemoryPageMapping = MyCloner.DeepClone<ObservableCollection<MappingRecordOfProcessAndMemory>>(addList); // associativ memóriába csak azok a page addressek mennek be, akikhez tartozó process lap a memóriában van AssociativeMemory = new ObservableCollection<FourElementTuple>(); if (descriptor.Addressing.IsAssociativeMemoryInUse) { foreach (int processPage in descriptor.AssociativeMemoryInitialContent) { AddPageToAssociativeMemory(processPage); } } // ellenőrzéssel kell ActionSequence = MyCloner.DeepClone<ObservableCollection<ActionBase>>(descriptor.ActionSequence); ObservableCollection<ActionBase> removeList = new ObservableCollection<ActionBase>(); foreach (ActionBase action in ActionSequence) { string fullName = action.GetType().Name; switch (fullName) { case "ResolveVirtualAddress": break; case "AddPageToMemory": if (((AddPageToMemory)action).ProcessPage >= Addressing.NumberOfPages || ((AddPageToMemory)action).ProcessPage < 0 || ((AddPageToMemory)action).MemoryFrame >= Addressing.QuantityOfPagesStorableInUserMemory || ((AddPageToMemory)action).MemoryFrame < 0) { removeList.Add(action); } break; case "RemovePageFromMemory": if (((RemovePageFromMemory)action).MemoryFrame >= Addressing.QuantityOfPagesStorableInUserMemory || ((RemovePageFromMemory)action).MemoryFrame < 0) { removeList.Add(action); } break; case "AddPageToAssociativeMemory": if (descriptor.Addressing.IsAssociativeMemoryInUse == false) { removeList.Add(action); } break; case "RemovePageFromAssociativeMemory": if (descriptor.Addressing.IsAssociativeMemoryInUse == false) { removeList.Add(action); } break; } } foreach (ActionBase action in removeList) { ActionSequence.Remove(action); } }