public ResourceRecord(Process process, IoBurstDescriptor burst)
 {
     this.process = process;
     this.burst = burst;
 }
        public void AddToHistory(int time, Process executingProcess, ObservableCollection<Process> queue)
        {
            // hogy ne kelljen teljes Process-t emiatt sorosítani, ezért csak a neveket kiszedni
            ObservableCollection<string> queueWithProcessNames = new ObservableCollection<string>();
            foreach (Process process in queue)
            {
                queueWithProcessNames.Add(process.ProcessName);
            }

            string executingProcessName = "";
            if (executingProcess != null)
            {
                executingProcessName = executingProcess.ProcessName;
            }

            QueueAssign queueAssign = new QueueAssign(previousTime, time, queueWithProcessNames);


            if (ProcessQueueCouples.Count > 0)  // már van tárolva Gannt egység
            {
                ProcessWithQueueAssigns processWithQueueAssigns = ProcessQueueCouples.Last();

                if (processWithQueueAssigns.ProcessName != null)
                {
                    if (processWithQueueAssigns.ProcessName.Equals(executingProcessName))
                    {
                        if (processWithQueueAssigns.PartTimes.Count > 0)
                        {
                            if (CheckIfQuesAreEqual(queueWithProcessNames, processWithQueueAssigns.PartTimes.Last().Queue))
                            {
                                processWithQueueAssigns.setLastPartTimesEndInterval(time);
                            }
                            else
                            {
                                QueueAssigns.Add(queueAssign);
                                processWithQueueAssigns.addNewPartTime(queueAssign);
                            }
                        }
                        else
                        { 
                        
                        }
                    }
                    else
                    {
                        QueueAssigns.Add(queueAssign);
                        ObservableCollection<QueueAssign> partTime = new ObservableCollection<QueueAssign>();
                        partTime.Add(queueAssign);
                        processQueueCouples.Add(new ProcessWithQueueAssigns(executingProcessName, partTime));
                    }
                }
                else    // ha előzőleg nem volt tárolva process, ami végrehajtás alatt lett volna (tipikusan 2. iteráció, vagy esetleg sokadik) // több esetre kell szétválasztani
                {
                    QueueAssigns.Add(queueAssign);
                    ObservableCollection<QueueAssign> partTime = new ObservableCollection<QueueAssign>();
                    partTime.Add(queueAssign);
                    processQueueCouples.Add(new ProcessWithQueueAssigns(executingProcessName, partTime));
                }
            }
            else        // ha az adatszerkezetben még nincs korábban eltárolt Gannt egység  (1. iteráció)
            {
                QueueAssigns.Add(queueAssign);
                ObservableCollection<QueueAssign> partTime = new ObservableCollection<QueueAssign>();
                partTime.Add(queueAssign);
                processQueueCouples.Add(new ProcessWithQueueAssigns(executingProcessName, partTime));
            }
            previousTime = time;
        }
        private void ElpaseTime()
        {
            foreach (Resource resource in Resources)
            {
                resource.ElpaseResourceTime();
            }

            foreach (Process process in ArrivedProcesses)
            {
                if (process.ProcessStatus != ProcessStatusEnum.Running)
                {
                    process.Wait();
                }
            }
            Process runningProcess = ArrivedProcesses.FirstOrDefault(x => x.ProcessStatus == ProcessStatusEnum.Running);
            if (runningProcess != null)
            {
                runningProcess.ElpaseCpuTime();
                Metrics.CountOfMillisecondsWhereProcessWasRunning++;
            }
            else
            {
                Metrics.CountOfMillisecondsWhereProcessWasNotRunning++;
            }

            if (prevRunningProcess != runningProcess)
            {
                if (runningProcess != null)
                {
                    Metrics.CountOfContextSwitchings++;
                }
            }
            prevRunningProcess = runningProcess;
        }
 // Process hívhatja, e formában kéri az operációs rendszertől az erőforrások lefoglalását
 public void UseResources(Process process, List<IoBurstDescriptor> initResourcesList)
 {
     foreach (IoBurstDescriptor ioBurst in initResourcesList)
     {
         Resource executingResource = null;
         foreach (Resource resource in Resources)
         {
             if (resource.ResourceName.Equals(ioBurst.ResourceName))
             {
                 executingResource = resource;
                 break;
             }
         }
         if (executingResource != null)
         {
             // ellenőrizni kell, hogy nem adtuk-e már korábban hozzá az erőforráshoz ugyanezeket a burstöket
             bool wasAddedToResource = false;
             foreach (ResourceRecord record in executingResource.CurrentlyUsing.Concat(executingResource.Queue))
             {
                 if (record.Process.ProcessName.Equals(process.ProcessName)
                     && record.Burst.Equals(ioBurst))
                 {
                     wasAddedToResource = true;
                 }
             }
             if (!wasAddedToResource)
             {
                 executingResource.addProcess(new ResourceRecord(process, ioBurst));
             }
         }
     }
 }
        public void CreateSimulatorDomain(TS_Descriptor descriptor)
        {
            // erőforrások létrehozása
            foreach (ResourceDescriptor resourceDescriptor in descriptor.Resources)
            {
                Resource resource = new Resource(resourceDescriptor, this);
                Resources.Add(resource);
            }
            // processzek létrehozása és használt erőforrásainak ellenőrzése
            foreach (ProcessDescriptor processDescriptor in descriptor.Processes)
            {
                Process process = new Process(this, MyCloner.DeepClone<ProcessDescriptor>(processDescriptor), Resources);
                InitialProcessList.Add(process);
            }

            Metrics = new Metrics(this, descriptor);

            LoadSchedulerAlgorithm(descriptor.SchedulerAlgorithm);

            Process runningProcess = ArrivedProcesses.FirstOrDefault(x => x.ProcessStatus == ProcessStatusEnum.Running);
            GanntHistory.AddToHistory(ActualStep, runningProcess, queue);

            InitiateProcesses();
            RunSchedulerIfNecassary();
        }