public void RemoveAtIndex(int index) { QueueObject temp = queuedObjects[index]; queuedObjects.RemoveAt(index); Destroy(temp.gameObject); }
private void SendMessageWorker() { Console.WriteLine("Entering OODSS Send Message loop"); while (_isRunning) { try { //Console.WriteLine("Top of loop" ); //Hold the thread here until it recieves a request to be processed. QueueObject q = _requestQueue.Take(_cancellationTokenSource.Token); //Push pull Console.WriteLine("Trying to send the string:" + q.Uid); SendDone = new ManualResetEventSlim(false); string messageForXml = MessageForXml(q.RequestMessage, q.Uid); Send(_clientSocket, messageForXml); SendDone.Wait(_cancellationTokenSource.Token); Console.WriteLine("--- Sent Request : {0}", q.Uid); } catch (OperationCanceledException e) { Console.WriteLine("The operation was cancelled." + e.TargetSite); } catch (Exception e) { Console.WriteLine("Caught Exception :\n " + e.StackTrace); } } Console.WriteLine("Performing disconnect"); }
private void swap(int fst, int snd) { QueueObject tmp = minHeap[fst]; minHeap[fst] = minHeap[snd]; minHeap[snd] = tmp; }
public T dequeue() { QueueObject removed = minHeap[1]; minHeap[1] = minHeap[size--]; Heapify(1); return(removed.data); }
IEnumerator CalculateRoute(QueueObject turn) { List <PathPoint> nav = pathfinding.FindPath(turn.start, turn.target); turn.comisionair.navigation = nav; queue.Remove(queue[0]); yield return(new WaitForEndOfFrame()); }
public void ResetQueue() { _currentObj = null; _queue.Sort((queueObject1, queueObject2) => queueObject1.Id - queueObject2.Id); _queue.ForEach(x => x.IsFound = null); }
public void AddToQueue(int playerIndex, int steps) { QueueObject newQueueObject = new QueueObject(); newQueueObject.playerIndex = playerIndex; newQueueObject.steps = steps; queueObjects.Add(newQueueObject); }
public void AddToQueue(IEntity c) { QueueObject newObject = Instantiate(prefab); newObject.transform.SetParent(transform); newObject.SetObject(c.Graphics.sRenderer.sprite, Hostility.Friendly); queuedObjects.Add(newObject); }
private void Awake() { if (Instance == null) { Instance = this; } prefab = Resources.Load <QueueObject>("Prefabs/QueueObject"); queuedObjects = new List <QueueObject>(); }
public void FillQueue(List <Character> characters) { for (int i = 0; i < characters.Count; i++) { QueueObject newObject = Instantiate(prefab); newObject.transform.SetParent(transform); newObject.SetObject(characters[i].Graphics.sRenderer.sprite, Hostility.Friendly); queuedObjects.Add(newObject); } }
/// <summary> /// /// </summary> /// <param name="requestMessage"> </param> /// <returns></returns> public async Task <ResponseMessage> RequestAsync(RequestMessage requestMessage) { TaskCompletionSource <ResponseMessage> tcs = new TaskCompletionSource <ResponseMessage>(); int uid = _uid++; QueueObject queueRequest = new QueueObject(requestMessage, uid, tcs); _pendingRequests.Put(uid, queueRequest); _requestQueue.Add(queueRequest); return(await tcs.Task); }
/// <summary> /// Adds an object to the end of the Generic Queue /// </summary> /// <param name="item">The object to add to the queue</param> /// <param name="size">The size in bytes of the item</param> /// <param name="timeoutIn">Timeout in milliseconds for call</param> /// <returns>True if item was successfully queued else False</returns> public bool Enqueue(T item, int size, int timeoutIn) { if (this.size > maxQueueSize) { numEventsLost++; if ((DateTime.Now.Ticks - lastErrorLogTick) > 600000000L || numEventsLost % 50000L == 1L) { EventLog.WriteEntry("WspEventRouter", "Event queue for application with PID " + Process.GetCurrentProcess().Id.ToString() + " and event type " + eventType.ToString() + " has exceeded max queue size of " + maxQueueSize.ToString() + " bytes and is now losing events until queue size is below max. Total events losts to this point is " + numEventsLost.ToString(), EventLogEntryType.Error); lastErrorLogTick = DateTime.Now.Ticks; } return(false); } if (mut.WaitOne(timeoutIn, false) == true) { try { QueueObject queueObject = new QueueObject(item, size); queue.Enqueue(queueObject); resetEvent.Set(); Interlocked.Add(ref this.size, (long)size); if (performanceCounter != null) { performanceCounter.RawValue = (long)queue.Count; } } finally { mut.ReleaseMutex(); } } else { EventLog.WriteEntry("WspEventRouter", "Event enqueue timed out for application with PID " + Process.GetCurrentProcess().Id.ToString() + " and event type " + eventType.ToString() + " with the event being lost", EventLogEntryType.Error); return(false); } return(true); }
public void ProcessPacket(Packet packet) { // Let's create a unique ID for the packet int packetID = Settings.Default.NextPacketID; string packetIDString = ""; packetID++; Settings.Default.NextPacketID = packetID; Settings.Default.Save(); string sentStr = packet.IsSent ? "sent" : "received"; // Let's save the packet header to our SQL database //TODO Fix this to be a proper header chain StringBuilder headerChain = new StringBuilder(""); //TODO removed packet header bytes need refactor //QueueObject headerQueueOjbect = new QueueObject(packetIDString, DateTime.UtcNow.Ticks, 0, "packet header", 0, headerChain, packet.packetHeaderBytes.Count() + packet.totalBytesLength, sentStr, packet.packetHeaderBytes, packet.Socket); //queue.Enqueue(headerQueueOjbect); PacketHeader header = packet.Header; //form1.UpdateHeaderLog("h_magic: " + ByteArrayToString(packet.packetHeaderBytes.Take(16).ToArray()) + ", h_timestampOffset: " + header.h_timestampOffset + ", h_unk3: " + header.h_unk3 + ", h_size: " + header.h_size + ", h_unk5: " + header.h_unk5 + ", h_subpacketCount: " + header.h_subpacketCount + ", h_unk6: " + header.h_unk6 + ", h_unk7: " + header.h_unk7 + ", h_deflated: " + header.h_deflated + ", h_unk9: " + header.h_unk9 + ", h_firstSubheadSize: " + header.h_firstSubheadSize); // Let's save the subpacket headers to our SQL database int counter = 0; foreach (Subpacket sp in packet.Subpackets) { int subpacketHeaderId = sp.SubpacketId;; counter++; QueueObject subpacketHeaderQueueObject = new QueueObject(packetIDString, DateTime.UtcNow.Ticks, counter, "subpacket header", subpacketHeaderId, headerChain, sp.RawPacketData.Count(), sentStr, sp.RawPacketData, packet.Socket); queue.Enqueue(subpacketHeaderQueueObject); headerChain.Append(subpacketHeaderId + " "); } // Let's save the subpacket headers to our SQL database counter = 0; foreach (Subpacket sp in packet.Subpackets) { int subpacketHeaderId = sp.SubpacketHeader.Id; counter++; QueueObject subpacketBodyQueueObject = new QueueObject(packetIDString, DateTime.UtcNow.Ticks, counter, "subpacket body", subpacketHeaderId, headerChain, sp.RawPacketData.Count(), sentStr, sp.RawPacketData, packet.Socket); queue.Enqueue(subpacketBodyQueueObject); } }
public QueueObject Pop() { if (list.Count > 0) { QueueObject obj = list[0]; list.RemoveAt(0); queueCount++; queueSum += list.Count; return(obj); } return(null); }
public T GetNext() { if (_currentObj == null) { _currentObj = _queue[0]; _currentObj.AttemptNum++; LastItemIndex = _currentObj.Id; return(_currentObj.Obj); } if (!_currentObj.IsFound.HasValue) { throw new Exception("Call SetCurrentObjectStatus function first!"); } _queue.RemoveAt(0); if (_currentObj.IsFound.Value) { _queue.Insert(_queue.Count, _currentObj); } else { var lastNotFoundObjIndex = _queue.FindLastIndex(x => x.IsFound == false); _queue.Insert(lastNotFoundObjIndex > -1 ? lastNotFoundObjIndex + 1 : _queue.Count, _currentObj); } _currentObj = _queue[0]; _currentObj.AttemptNum++; //if (CurrentItemIndex == LastItemIndex && _queue.FindAll(x => x.IsFound == false).Count == 1) //{ // _queue.RemoveAt(0); // _queue.Insert(_queue.Count, _currentObj); // _currentObj = _queue[0]; //} LastItemIndex = _currentObj.Id; //DubugQueue(); return(_currentObj.Obj); }
public void queue(float priority, T element) { if (size == maxsize) { return; } QueueObject t = new QueueObject(element, priority); minHeap[++size] = t; int pos = size; while (pos > 1 && minHeap[pos].priority < minHeap[getParent(pos)].priority) { swap(pos, getParent(pos)); pos = getParent(pos); } }
public QueueObject MontarObjeto() { var lstMensagem = (List <MensagemDto>)_mensagensService.SelecionarTodosNaoIntegrados().Result.Object; var mensagem = lstMensagem?.FirstOrDefault(); if (mensagem != null) { var response = new QueueObject { MensagemDescricao = mensagem.Descricao, MensagemId = mensagem.Id, SistemaId = mensagem.SistemaId }; return(response); } return(null); }
public OODSSClient(String host, int port, SimplTypesScope simplTypesScope, Scope<object> objectRegistry) { _sendMesssageThread = new Thread(SendMessageWorker); _receiveMesssageThread = new Thread(ReceiveMessageWorker); _pendingRequests = new ConcurrentDictionary<int, QueueObject>(); _requestQueue = new BlockingCollection<QueueObject>(new ConcurrentQueue<QueueObject>()); Host = host; Port = port; ObjectRegistry = objectRegistry; //Add the OODSS messages to the scope. simplTypesScope.AddTranslations(ServicesTranslationScope); SimplTypesScope = simplTypesScope; var initState = new InitConnectionRequest(); int uid = _uid; QueueObject q = new QueueObject(initState, uid, null); _requestQueue.Add(q); }
public OODSSClient(String host, int port, SimplTypesScope simplTypesScope, Scope <object> objectRegistry) { _sendMesssageThread = new Thread(SendMessageWorker); _receiveMesssageThread = new Thread(ReceiveMessageWorker); _pendingRequests = new ConcurrentDictionary <int, QueueObject>(); _requestQueue = new BlockingCollection <QueueObject>(new ConcurrentQueue <QueueObject>()); Host = host; Port = port; ObjectRegistry = objectRegistry; //Add the OODSS messages to the scope. simplTypesScope.AddTranslations(ServicesTranslationScope); SimplTypesScope = simplTypesScope; var initState = new InitConnectionRequest(); int uid = _uid; QueueObject q = new QueueObject(initState, uid, null); _requestQueue.Add(q); }
private void UploadQueueObject(QueueObject queueObject, MySqlConnection connection) { PacketDatabaseManager.UpdateWebDatabase(connection, queueObject.id, queueObject.timestamp, queueObject.line, queueObject.type, queueObject.header, queueObject.headerChain, queueObject.size, queueObject.status, queueObject.bytes, queueObject.socket); //form1.UpdateHeaderLog("Uploaded object to MySQL server: id = " + queueObject.id + " type = " + queueObject.type + " header = " + queueObject.header + " headerChain = " + queueObject.headerChain); }
private async Task <bool> GenerateReport(string qRepName, QueueObject obj) { var reportData = (BaseFilterReportRequest)obj.FilterDataObj; var resp = new UploadPdfReportDto { PdfReportId = reportData.PdfReportId, Schema = reportData.Schema, Key = reportData.Key, Status = PDFReportStatus.Ready }; try { PdfDocumentDto pdfDoc; BaseFilterReportRequest req; switch (obj.Executor.Method.Name) { case "GetContactPdf": req = (BaseFilterReportRequest)obj.FilterDataObj; resp.PdfByteArr = obj.Executor.Invoke(req.ReportDto); break; case "GetTransactionPdf": req = (BaseFilterReportRequest)obj.FilterDataObj; resp.PdfByteArr = obj.Executor.Invoke(req.Filter); break; case "CreateContactReportPDf": var reqContPdf = (ContactReportPdfOnlyRequest)obj.FilterDataObj; pdfDoc = new PdfDocumentDto { ReportDto = reqContPdf.ReportDto, Contacts = reqContPdf.Contacts }; resp.PdfByteArr = obj.Executor.Invoke(pdfDoc); break; case "CreateTransactionReportPDf": var reqTransPdf = (TransactionReportPdfOnlyRequest)obj.FilterDataObj; pdfDoc = new PdfDocumentDto { Filter = reqTransPdf.Filter, Grouped = reqTransPdf.Grouped, CountTrans = reqTransPdf.TransactionCount }; resp.PdfByteArr = obj.Executor.Invoke(pdfDoc); break; default: throw new MissingMethodException("can't get correct method for delegate"); } } catch (Exception e) { resp.Status = PDFReportStatus.GenerationError; resp.Message = e.Message; resp.StackTrace = e.StackTrace; isWorking = false; } AddToSending(resp); if (!isSending && _sendingDict.Any()) { await SendReport(); } return(true); }
//TO-DO MAKE LISTNER public void AddToQueue(QueueObject q) { queue.Add(q); }
private void Proceed() { if (server.Available) { CountServerSleep(); } tm = Min(L1, L2, h, Tf); if (tm == L1 || tm == L2) { if (tm == L1) { nextL1 = tm + GetL1(); if (server.Available) { server.Available = false; h = tm + SleepL1(); serverL1++; queueEmptyL1++; Console.WriteLine("L1 on server" + "\t| " + Math.Round(tm, 3) + ", " + Math.Round(nextL1, 3) + ", - , " + Math.Round(h, 3) + ", " + server.Available + ", Q:" + queue.Size + " L1:" + queue.CountObj(typeof(L1)) + " L2:" + queue.CountObj(typeof(L2))); } else { queue.Put(new L1()); queueL1++; Console.WriteLine("L1 in queue" + "\t| " + Math.Round(tm, 3) + ", " + Math.Round(nextL1, 3) + ", - , " + Math.Round(h, 3) + ", " + server.Available + ", Q:" + queue.Size + " L1:" + queue.CountObj(typeof(L1)) + " L2:" + queue.CountObj(typeof(L2))); } L1 = nextL1; reqL1++; } else { nextL2 = tm + GetL2(); if (server.Available) { server.Available = false; h = tm + SleepL2(); serverL2++; queueEmptyL2++; Console.WriteLine("L2 on server" + "\t| " + Math.Round(tm, 3) + ", - , " + Math.Round(nextL2, 3) + ", " + Math.Round(h, 3) + ", " + server.Available + ", Q:" + queue.Size + " L1:" + queue.CountObj(typeof(L1)) + " L2:" + queue.CountObj(typeof(L2))); } else { queue.Put(new L2()); queueL2++; Console.WriteLine("L2 in queue" + "\t| " + Math.Round(tm, 3) + ", - , " + Math.Round(nextL2, 3) + ", " + Math.Round(h, 3) + ", " + server.Available + ", Q:" + queue.Size + " L1:" + queue.CountObj(typeof(L1)) + " L2:" + queue.CountObj(typeof(L2))); } L2 = nextL2; reqL2++; } Proceed(); } else if (tm == h) { if (queue.Empty) { h = 501; server.Available = true; } else { QueueObject obj = queue.Pop(); if (obj.GetType() == typeof(L1)) { h = tm + SleepL1(); queueLeftL1++; serverL1++; Console.WriteLine("L1 from queue" + "\t| " + Math.Round(tm, 3) + ", - , - , " + Math.Round(h, 3) + ", " + server.Available + ", Q:" + queue.Size + " L1:" + queue.CountObj(typeof(L1)) + " L2:" + queue.CountObj(typeof(L2))); } else if (obj.GetType() == typeof(L2)) { h = tm + SleepL2(); queueLeftL2++; serverL2++; Console.WriteLine("L2 from queue" + "\t| " + Math.Round(tm, 3) + ", - , - , " + Math.Round(h, 3) + ", " + server.Available + ", Q:" + queue.Size + " L1:" + queue.CountObj(typeof(L1)) + " L2:" + queue.CountObj(typeof(L2))); } } Proceed(); } else { SummaryStats(); } }
/// <summary> /// /// </summary> /// <param name="requestMessage"> </param> /// <returns></returns> public async Task<ResponseMessage> RequestAsync(RequestMessage requestMessage) { TaskCompletionSource<ResponseMessage> tcs = new TaskCompletionSource<ResponseMessage>(); int uid = _uid++; QueueObject queueRequest = new QueueObject(requestMessage, uid, tcs); _pendingRequests.Put(uid, queueRequest); _requestQueue.Add(queueRequest); return await tcs.Task; }
public void Put(QueueObject obj) { list.Add(obj); queueCount++; queueSum += list.Count; }
private void AddRequest(RequestMessage obj) { QueueObject q = new QueueObject( obj, _uid, null); _requestQueue.Add(q); }
private void AddRequest(RequestMessage obj) { QueueObject q = new QueueObject(obj, _uid, null); _requestQueue.Add(q); }