public async Task <IActionResult> PutTrackerEvent([FromRoute] int id, [FromBody] TrackerEvent trackerEvent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != trackerEvent.Id) { return(BadRequest()); } _context.Entry(trackerEvent).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TrackerEventExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void UpdateTrackers(TrackerEvent ev, string id, int port) { foreach (var tracker in Trackers) { tracker.Update(this, ev, id, port); } }
private void HandleMarkerEvent(TrackerEvent <MarkerState> e) { if (e.type == TrackerEventType.Down) { if (_markers.TryGetValue(e.id, out var marker)) { _markers.Remove(e.id); TrackedMarkers.Remove(marker); } marker = new TrackedMarkerViewModel(e.id, _scaleAdapter); marker.UpdateValues(e.state); _markers.Add(e.id, marker); TrackedMarkers.Add(marker); } else if (e.type == TrackerEventType.Up) { if (_markers.TryGetValue(e.id, out var marker)) { _markers.Remove(e.id); TrackedMarkers.Remove(marker); } } else if (e.type == TrackerEventType.Update) { if (_markers.TryGetValue(e.id, out var marker)) { marker.UpdateValues(e.state); } } }
public void DeleteDir(TrackerEvent evnt, int trackerId) { var files = ( from t in Trackers join f in Files on t.TrackerId equals f.TrackerId where t.TrackerId.Equals(trackerId) && f.FullName.IndexOf(evnt.FullName) == 0 select f ).ToList(); lock (lockObj) { files.ForEach(file => { file.ChangeList.Add(new Change() { UserId = GetUserId(evnt, trackerId), EventName = TrackerEvents.Deleted, DateTime = evnt.DateTime, }); file.IsWasDeletedChange = true; file.IsNeedDelete = true; file.RemoveFromDbTime = DateTime.UtcNow.AddDays(14); }); SaveChanges(); } }
public override void Send(TrackerEvent e) { string s = serializer.Serialize(e); Debug.Log("Registrado evento: " + s); events.Add(s); }
public void CreateDir(TrackerEvent evnt, int trackerId) { var files = ( from t in Trackers join f in Files on t.TrackerId equals f.TrackerId join c in Changes on f.FileId equals c.FileId where t.TrackerId.Equals(trackerId) && f.FullName.Equals(evnt.FullName) select f ).ToList(); lock (lockObj) { files.ForEach(file => { file.ChangeList.Add(new Change() { UserId = GetUserId(evnt, trackerId), EventName = TrackerEvents.Created, DateTime = evnt.DateTime, }); file.IsWasDeletedChange = false; file.IsNeedDelete = false; file.RemoveFromDbTime = null; }); SaveChanges(); } }
public IActionResult PostTrackerEvent(string trackerGuid) { var ipAddress = HttpContext.Connection.RemoteIpAddress.ToString(); var whiteListedIPs = _configuration.GetSection("WhiteListedIPs"); if (!whiteListedIPs.GetChildren().Any(item => item.Key == ipAddress)) { var trackerId = _context.Trackers.Where(t => t.ExternalID.ToString() == trackerGuid) .Select(i => i.TrackerID) .FirstOrDefault(); var trackerEvent = new TrackerEvent(); trackerEvent.TrackerID = trackerId; trackerEvent.IPAddress = ipAddress; trackerEvent.CreatedDate = DateTime.Now; _context.TrackerEvents.Add(trackerEvent); _context.SaveChanges(); } var directory = Directory.GetCurrentDirectory(); var imagePath = directory + "\\images\\1px.png"; var b = System.IO.File.ReadAllBytes(imagePath); return(File(b, "image/png")); }
public void RenameDir(TrackerEvent evnt, int trackerId) { var files = ( from t in Trackers join f in Files on t.TrackerId equals f.TrackerId where t.TrackerId.Equals(trackerId) && f.FullName.IndexOf(evnt.OldFullName) == 0 select f ).ToList(); lock (lockObj) { files.ForEach(file => { file.ChangeList.Add(new Change() { UserId = GetUserId(evnt, trackerId), EventName = TrackerEvents.Renamed, DateTime = evnt.DateTime, OldName = file.FileName, OldFullName = file.FullName }); file.FullName = file.FullName.Replace(evnt.OldFullName, evnt.FullName); }); SaveChanges(); } }
/// <summary> /// Change tracker status. /// </summary> /// <param name="status"></param> internal void ChangeStatus(TrackerEvent status) { announceTimer?.Stop(); Event = status; OnAnnounceEvent(this); Event = TrackerEvent.None; // Reset it back to default on next tick announceTimer?.Start(); }
private void WriteToJson() { JSONObject obj = new JSONObject(); TrackerEvent auxTE = _eventQueue.Dequeue(); auxTE.DumpEventDataToJson(ref obj); File.AppendAllText(TELEMETRY_PATH + _fileName + ".json", obj.ToString(4) + ",\n"); }
private void WriteToBinary() { JSONObject obj = new JSONObject(); TrackerEvent auxTE = _eventQueue.Dequeue(); auxTE.DumpEventDataToJson(ref obj); obj.SaveToBinaryBase64(); File.AppendAllText(TELEMETRY_PATH + _fileName + ".bn", obj.SaveToBinaryBase64() + "\n"); }
public void TrackEvent(TrackerEvent e) { int eventInt = (int)e.eventType; if (testing && options != null && eventInt < options.Length && options[eventInt].activated) { persistenceObject.Send(e); } }
public void DeletedEvent(TrackerEvent evnt, int trackerId) { var userId = GetUserId(evnt, trackerId); var change = new Change() { EventName = evnt.EventName, DateTime = evnt.DateTime, UserId = userId, }; AddChange(evnt, change, null, trackerId); }
public async Task <IActionResult> PostTrackerEvent([FromBody] TrackerEvent trackerEvent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.TrackerEvents.Add(trackerEvent); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTrackerEvent", new { id = trackerEvent.Id }, trackerEvent)); }
/// <summary> /// /// </summary> /// <param name="torrent"></param> /// <param name="ev"></param> /// <param name="id"></param> /// <param name="port"></param> public void Update(Torrent torrent, TrackerEvent ev, string id, int port) { // We should wait for request interval to elapse before asking for new peers if (ev == TrackerEvent.Started && DateTime.UtcNow < LastPeerRequest.Add(PeerRequestInterval)) { return; } LastPeerRequest = DateTime.UtcNow; var url = $"{Address}?info_hash={torrent.UrlSafeStringInfohash}&peer_id={id}&port={port}&uploaded={torrent.Uploaded}&downloaded={torrent.Downloaded}&left={torrent.Left}&event={Enum.GetName(typeof(TrackerEvent), ev).ToLower()}&compact=1"; Request(url); }
override public TrackerEvent Deserialize(string s) { TrackerEvent e = JsonConvert.DeserializeObject <TrackerEvent>(s); switch (e.eventType) { case EventType.AIM: return(JsonConvert.DeserializeObject <AimEvent>(s)); case EventType.TARGET: return(JsonConvert.DeserializeObject <TargetEvent>(s)); default: return(e); } }
private string TrackerEventToString(TrackerEvent trackerEvent) { if (trackerEvent == TrackerEvent.Started) { return("started"); } if (trackerEvent == TrackerEvent.Completed) { return("completed"); } if (trackerEvent == TrackerEvent.Stopped) { return("stopped"); } throw new Exception("Not supported tracker event format"); }
public void Update(Torrent torrent, TrackerEvent ev, string id, int port) { // wait until after request interval has elapsed before asking for new peers if (ev == TrackerEvent.Started && DateTime.UtcNow < LastPeerRequest.Add(PeerRequestInterval)) { return; } LastPeerRequest = DateTime.UtcNow; string url = String.Format("{0}?info_hash={1}&peer_id={2}&port={3}&uploaded={4}&downloaded={5}&left={6}&event={7}&compact=1", Address, torrent.UrlSafeStringInfohash, id, port, torrent.Uploaded, torrent.Downloaded, torrent.Left, Enum.GetName(typeof(TrackerEvent), ev).ToLower()); Request(url); }
public void EndChangeAmbitAsExtensions(TrackerEvent trace) { var currentAmbitTrace = this.ambitTraces.Pop(); var currentChanges = EndChangeAmbit(false); if (currentAmbitTrace != trace) { Debug.LogError("Closed trace ambit is not the topmost trace!!"); } foreach (var varChange in currentChanges) { TrackerAsset.Instance.setVar(varChange.Key, varChange.Value); } if (trace != null) { TrackerAsset.Instance.AddExtensionsToTrace(trace); } }
public async Task <TrackerResponse> Track(Torrent torrent, TrackerEvent trackerEvent, bool compact = false) { var hostUrl = torrent.AnnounceUrl; var encodedInfoHash = torrent.Info.GetUrlEncodedInfoHash(); var formattedTrackerRequestData = FormatTrackerRequestData(encodedInfoHash, torrent.Uploaded, torrent.Downloaded, torrent.Left, trackerEvent, compact); var fullUrl = hostUrl + formattedTrackerRequestData; var responseWrapper = await HttpClient.Send(HttpMethod.Get, fullUrl); if (!responseWrapper.IsSuccessStatusCode()) { throw new Exception("Request failed"); } var bytes = responseWrapper.ByteContent; return(TrackerResponseFactory.GetTrackerResponse(ref bytes)); }
public void CreatedEvent(TrackerEvent evnt, string path, int trackerId) { var userId = GetUserId(evnt, trackerId); Content content = new Content() { Payload = evnt.Content, FilePath = path, }; var change = new Change() { UserId = userId, EventName = evnt.EventName, DateTime = evnt.DateTime, Content = content, }; AddChange(evnt, change, path, trackerId); }
public void MoveDir(TrackerEvent evnt, int trackerId) { var files = ( from t in Trackers join f in Files on t.TrackerId equals f.TrackerId where t.TrackerId.Equals(trackerId) && f.FullName.Equals(evnt.OldFullName) select f ).ToList(); lock (lockObj) { files.ForEach(file => { file.ChangeList.Add(new Change() { UserId = GetUserId(evnt, trackerId), EventName = TrackerEvents.Moved, DateTime = evnt.DateTime, }); file.FullName = evnt.FullName; }); SaveChanges(); } }
private int GetUserId(TrackerEvent evnt, int trackerId) { var user = ( from u in Users where u.UserName.Equals(evnt.UserName) && u.TrackerId.Equals(trackerId) select u ).FirstOrDefault(); if (user == null) { user = new User() { TrackerId = trackerId, UserName = evnt.UserName, }; Users.Add(user); lock (lockObj) { SaveChanges(); } } return(user.UserId); }
// Adds an event to the event queue public void AddEvent(TrackerEvent trackerEvent) { _eventQueue.Enqueue(trackerEvent); }
// Var flag change ambits public void BeginChangeAmbit(TrackerEvent trace) { this.ambitTraces.Push(trace); this.varFlagChangeAmbits.Push(new List <KeyValuePair <string, int> >()); Debug.Log("Opened change ambit " + varFlagChangeAmbits.Count); }
virtual public void Send(TrackerEvent e) { }
private void AddChange(TrackerEvent evnt, Change change, string path, int trackerId) { var db = this; var tracker = db.Trackers .Include(tr => tr.FileList) .FirstOrDefault(tr => tr.TrackerId == trackerId); if (tracker == null) { return; } File file; bool newFile = false; if (evnt.EventName == TrackerEvents.Moved || evnt.EventName == TrackerEvents.Renamed) { file = tracker.FileList .FirstOrDefault(fl => fl.FullName.Equals(evnt.OldFullName)); if (file == null) { file = new File() { FullName = evnt.FullName, FileName = evnt.Name, }; newFile = true; } if (evnt.EventName == TrackerEvents.Moved) { file.FullName = evnt.FullName; } else { file.FileName = evnt.Name; file.FullName = evnt.FullName; } } else { file = tracker.FileList .FirstOrDefault(fl => fl.FullName.Equals(evnt.FullName)); if (file == null) { file = new File() { FullName = evnt.FullName, FileName = evnt.Name, }; newFile = true; } if (evnt.EventName == TrackerEvents.Created) { file.IsWasDeletedChange = false; file.IsNeedDelete = false; file.RemoveFromDbTime = null; } if (evnt.EventName == TrackerEvents.Deleted) { file.IsWasDeletedChange = true; file.RemoveFromDbTime = DateTime.UtcNow.AddDays(14); } } if (!String.IsNullOrEmpty(path)) { file.FilePath = path; } lock (lockObj) { file.ChangeList.Add(change); if (newFile) { tracker.FileList.Add(file); } db.SaveChanges(); } }
public override string Serialize(TrackerEvent e) { return(JsonConvert.SerializeObject(e, Tracker.getInstance().jsonFormatting).ToString()); }
/// <summary> /// Adds the given value to the Queue. /// </summary> /// /// <param name="value"> New value for the variable. </param> public void Trace(TrackerEvent value) { queue.Enqueue(value); }
public TrackerContext(TrackerEvent trackerEvent, string userId) { TrackerEvent = trackerEvent; UserId = userId; }
private static KeyValuePair <TrackerEvent, Action <ILogger, string, Exception> > CreateSuccessMessageKvp(TrackerEvent trackerEvent, string messageWithPlaceholder) => new KeyValuePair <TrackerEvent, Action <ILogger, string, Exception> >(trackerEvent, LoggerMessage.Define <string>(LogLevel.Information, (int)trackerEvent, messageWithPlaceholder));