private void OnTriggerExit(Collider other) { Hydrant.CheckConnections(); //sometimes it doesnt register leaving the pipe quick enough. This prevents that. if (other.CompareTag("pipe") == true) { if (connectedPipes.Contains(other.GetComponent <PipeScript>()) == true) { if (other.GetComponent <PipeScript>()._connectedToHydrant == true) { _connectedToHydrant = false; } if (other.GetComponent <PipeScript>()._connectedToFlower == true) { _connectedToFlower = false; } connectedPipes.Remove(other.GetComponent <PipeScript>()); } } else if (other.CompareTag("hydrant") == true) { _connectedToHydrant = false; StartPoint = null; } else if (other.CompareTag("flower") == true) { _connectedToFlower = false; EndPoint = null; } }
/// <summary> /// /// </summary> /// <param name="_hydrant"></param> /// <param name="_tag"></param> /// <param name="_positionAction"></param> /// <param name="_reviewerUserGuid"></param> public void UpdateHydrantWithNewTag(Hydrant _hydrant, Tag _tag, TagPositionAction _positionAction, Guid _reviewerUserGuid) { bool needsSaving = false; if (_hydrant != null && _tag != null) { if (_tag.ImageGuid != null) { if (_hydrant.PrimaryImageGuid == null) { _hydrant.PrimaryImageGuid = _tag.ImageGuid; _hydrant.LastModifiedDateTime = DateTime.UtcNow; _hydrant.LastReviewerUserGuid = _reviewerUserGuid; needsSaving = true; } AssignImageToHydrant(_hydrant.Guid, _tag.ImageGuid.Value); } if (needsSaving) { Persist(_hydrant); } } }
public ActionResult Create(Hydrant model) { if (ModelState.IsValid) { if (model.UploadFile != null) { string mapPath = Server.MapPath("~/upload/"); if (!Directory.Exists(mapPath)) { Directory.CreateDirectory(mapPath); } model.UploadFile.SaveAs(Path.Combine(mapPath, model.UploadFile.FileName)); model.ImagePath = model.UploadFile.FileName; } try { using (HydrantenContext context = new HydrantenContext()) { context.hydrantens.AddOrUpdate(model); context.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View(model)); } } else { return(View(model)); } }
/// <summary> /// /// </summary> /// <param name="_hydrant"></param> /// <param name="_newPosition"></param> /// <param name="_reviewerUserGuid"></param> public void UpdateHydrantPosition(Hydrant _hydrant, GeoPoint _newPosition, Guid _reviewerUserGuid) { _hydrant.Position = _newPosition; _hydrant.LastReviewerUserGuid = _reviewerUserGuid; _hydrant.LastModifiedDateTime = DateTime.UtcNow; Persist(_hydrant); }
public IActionResult EditHydrant(int id, [FromBody] Hydrant hydrant) { hydrant.Id = id; if (hydrant.GpsPoint != null) { _dbContext.GpsPoints.Update(hydrant.GpsPoint); } _dbContext.Hydrants.Update(hydrant); _dbContext.SaveChanges(); return(Json(hydrant)); }
public IActionResult AddHydrant([FromBody] Hydrant hydrant) { if (hydrant.GpsPoint == null) { hydrant.GpsPoint = new GpsPoint(); } _dbContext.GpsPoints.Add(hydrant.GpsPoint); _dbContext.Hydrants.Add(hydrant); _dbContext.SaveChanges(); return(Json(hydrant)); }
public IActionResult RemoveHydrant(int id) { Hydrant hydrant = _dbContext.Hydrants.FirstOrDefault(h => h.Id == id); if (hydrant != null) { _dbContext.Hydrants.Remove(hydrant); } _dbContext.SaveChanges(); return(Ok()); }
private string AcceptTag(DynamicDictionary _parameters) { User user; if (AuthHelper.IsAuthorized(Request, out user)) { if (user != null && (user.UserType == UserTypes.SuperUser || user.UserType == UserTypes.Administrator)) { HydrantWikiManager hwManager = new HydrantWikiManager(); string sTagGuid = _parameters["tagGuid"]; Guid tagGuid; if (Guid.TryParse(sTagGuid, out tagGuid)) { Tag tag = hwManager.GetTag(tagGuid); if (tag != null) { if (tag.Status == TagStatus.Pending) { Hydrant hydrant = new Hydrant { Active = true, CreationDateTime = tag.DeviceDateTime, LastModifiedBy = tag.LastModifiedBy, LastModifiedDateTime = tag.LastModifiedDateTime, LastReviewerUserGuid = user.Guid, OriginalReviewerUserGuid = user.Guid, OriginalTagDateTime = tag.DeviceDateTime, OriginalTagUserGuid = tag.UserGuid, Position = tag.Position, PrimaryImageGuid = tag.ImageGuid }; hwManager.Persist(hydrant); tag.Status = TagStatus.Approved; tag.HydrantGuid = hydrant.Guid; hwManager.Persist(tag); return(@"{ ""Result"":""Success"" }"); } } } } } return(@"{ ""Result"":""Failure"" }"); }
private string MatchTagWithHydrant(DynamicDictionary _parameters) { User user; if (AuthHelper.IsAuthorized(Request, out user)) { if (user != null && (user.UserType == UserTypes.SuperUser || user.UserType == UserTypes.Administrator)) { HydrantWikiManager hwManager = new HydrantWikiManager(); string sTagGuid = _parameters["tagGuid"]; Guid tagGuid; if (Guid.TryParse(sTagGuid, out tagGuid)) { Tag tag = hwManager.GetTag(tagGuid); if (tag != null) { if (tag.Status == TagStatus.Pending) { string sHydrantGuid = _parameters["hydrantGuid"]; Guid hydrantGuid; if (Guid.TryParse(sHydrantGuid, out hydrantGuid)) { Hydrant hydrant = hwManager.GetHydrant(hydrantGuid); if (hydrant != null) { tag.Status = TagStatus.Approved; tag.HydrantGuid = hydrantGuid; hwManager.Persist(tag); //TODO - Probably need to reaverage all tag positions and assign back to hydrant hydrant.LastReviewerUserGuid = user.Guid; hwManager.Persist(hydrant); return(@"{ ""Result"":""Success"" }"); } } } } } } } return(@"{ ""Result"":""Failure"" }"); }
public void SetHydrant(Hydrant _hydrant) { if (_hydrant.ImageUrl != null) { m_imgMainImage.Source = ImageSource.FromUri(new System.Uri(_hydrant.ImageUrl)); } m_lblUsername.Text = string.Format("Username: {0}", _hydrant.Username); if (_hydrant.Position != null) { m_lblLatitude.Text = _hydrant.Position.Latitude.AsLatitude(); m_lblLongitude.Text = _hydrant.Position.Longitude.AsLongitude(); } }
public ActionResult GetImage(int id) { using (HydrantenContext context = new HydrantenContext()) { Hydrant hydrant = context.hydrantens.FirstOrDefault(x => x.ID == id); if (hydrant == null || string.IsNullOrWhiteSpace(hydrant.ImagePath)) { return(null); } else { string mapPath = Server.MapPath("~/upload/"); return(File(Path.Combine(mapPath, hydrant.ImagePath), GetMimeType(hydrant.ImagePath))); } } }
/// <summary> /// /// </summary> /// <param name="_hydrant"></param> /// <param name="_showThumb"></param> /// <returns></returns> public static string GetUrl(this Hydrant _hydrant, bool _showThumb) { if (_hydrant.PrimaryImageGuid != null) { string temp = GetAWSPath(_hydrant.PrimaryImageGuid.Value, _showThumb); if (temp.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) { return(temp); } return(Config.GetSettingValue("S3Protocol", "https") + "://" + temp); } return(Config.GetSettingValue("NoImageURL")); }
public ActionResult Delete(int id, Hydrant model) { try { using (HydrantenContext context = new HydrantenContext()) { context.hydrantens.Remove(context.hydrantens.First(x => x.ID == id)); context.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public void SerializeTest() { GeoPoint pos = new GeoPoint(-100, 45); Hydrant hydrant = new Hydrant { Active = true, CreationDateTime = DateTime.Now, Guid = Guid.NewGuid(), LastModifiedBy = Guid.NewGuid(), LastModifiedDateTime = DateTime.Now, LastReviewerUserGuid = Guid.NewGuid(), OriginalReviewerUserGuid = Guid.NewGuid(), OriginalTagDateTime = DateTime.Now, OriginalTagUserGuid = Guid.NewGuid(), PersistedDateTime = DateTime.Now, Position = pos, PrimaryImageGuid = Guid.NewGuid() }; TGSerializedObject tgs = hydrant.GetTGSerializedObject(); Hydrant newHydrant = TGSerializedObject.GetTGSerializable <Hydrant>(tgs); Assert.AreEqual(hydrant.Active, newHydrant.Active); Assert.AreEqual(hydrant.CreationDateTime, newHydrant.CreationDateTime); Assert.AreEqual(hydrant.LastModifiedBy, newHydrant.LastModifiedBy); Assert.AreEqual(hydrant.LastModifiedDateTime, newHydrant.LastModifiedDateTime); Assert.AreEqual(hydrant.Guid, newHydrant.Guid); Assert.AreEqual(hydrant.LastReviewerUserGuid, newHydrant.LastReviewerUserGuid); Assert.AreEqual(hydrant.OriginalReviewerUserGuid, newHydrant.OriginalReviewerUserGuid); Assert.AreEqual(hydrant.OriginalTagDateTime, newHydrant.OriginalTagDateTime); Assert.AreEqual(hydrant.OriginalTagUserGuid, newHydrant.OriginalTagUserGuid); Assert.AreEqual(hydrant.PersistedDateTime, newHydrant.PersistedDateTime); Assert.AreEqual(hydrant.PrimaryImageGuid, newHydrant.PrimaryImageGuid); Assert.IsNotNull(newHydrant.Position); Assert.AreEqual(hydrant.Position.X, newHydrant.Position.X); Assert.AreEqual(hydrant.Position.Y, newHydrant.Position.Y); }
/// <summary> /// /// </summary> /// <param name="_tag"></param> /// <param name="_reviewerUserGuid"></param> /// <returns></returns> public Hydrant TagToNewHydrant(Tag _tag, Guid _reviewerUserGuid) { Hydrant hydrant = new Hydrant { Active = true, CreationDateTime = DateTime.Now, OriginalTagDateTime = _tag.DeviceDateTime, OriginalTagUserGuid = _tag.UserGuid, PrimaryImageGuid = _tag.ImageGuid, OriginalReviewerUserGuid = _reviewerUserGuid, LastReviewerUserGuid = _reviewerUserGuid, Position = _tag.Position }; hydrant.LastModifiedDateTime = hydrant.CreationDateTime; foreach (Property property in _tag.Properties) { hydrant.Properties.SetValue(property.Name, property.Value, property.AttributeType); } Persist(hydrant); //Assign initial image to hydrant if (hydrant.PrimaryImageGuid != null) { AssignImageToHydrant(hydrant.Guid, hydrant.PrimaryImageGuid.Value); } //Assign tag to hydrant _tag.HydrantGuid = hydrant.Guid; //Add to Geospatial table Persist(_tag); return(hydrant); }
private static void Main(string[] args) { var cultureInfo = CultureInfo.GetCultureInfo("zh-CN"); CultureInfo.CurrentCulture = cultureInfo; CultureInfo.CurrentUICulture = cultureInfo; CultureInfo.DefaultThreadCurrentCulture = cultureInfo; CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; // 配置 osu OsuFunction.SetApiKey(s_hardcodedConfigure.ApiKey); try { // 本应在此设置 HttpApiClient,并启动,但是使用反向 WebSocket 时,无需手动这么做。 #if DEBUG var rServer = new ReverseWebSocketServer("http://localhost:9191"); #else var rServer = new ReverseWebSocketServer(s_hardcodedConfigure.ServerPort); #endif rServer.SetListenerAuthenticationAndConfiguration(async r => { bool elevated = false; Action <NegativeWebSocketEventListener, long> configuration = (l, selfId) => { var logger = LogManager.LogFactory.GetLogger("Replica"); logger.Info($"客户端 {selfId} 成功连接。"); Hydrant hydrant = null; try { if (elevated) { hydrant = ConfigureHost(l.ApiClient, l, elevated, typeof(Highlight).Assembly, typeof(Bind).Assembly); } else { hydrant = ConfigureHost(l.ApiClient, l, elevated, typeof(Highlight).Assembly); } hydrant.Start(); Console.WriteLine("Running..."); var count = Interlocked.Increment(ref s_connectedClinetCount); logger.Info($"当前已有 {count} 个分身在连接。"); l.SocketDisconnected += () => { Console.WriteLine("Disconnected."); logger.Info("Disconnected"); Interlocked.Decrement(ref s_connectedClinetCount); (hydrant as IDisposable)?.Dispose(); }; } catch (Exception e) { Console.WriteLine(e); (hydrant as IDisposable)?.Dispose(); } }; Logger logger = LogManager.LogFactory.GetLogger("Replica"); logger.Info($"{r.Headers["X-Forwarded-For"]} 尝试连接。"); bool generalAuth = ReverseWebSocketServer.CreateAuthenticationFunction(s_hardcodedConfigure.ServerAccessToken, null)(r); if (!generalAuth && long.TryParse(r.Headers["X-Self-ID"], out long selfId)) { var auth = await new OsuQqBot.Database.Models.NewbieContext().DuplicateAuthentication.Where(a => a.SelfId == selfId).FirstOrDefaultAsync().ConfigureAwait(false); var headValue = r.Headers["Authorization"]; if (string.IsNullOrWhiteSpace(headValue)) { return(null); } int spaceIndex = headValue.IndexOf(' '); if (headValue[(spaceIndex + 1)..] == auth?.AccessToken) { elevated = true; logger.Info($"{selfId} 已提权。"); return(configuration); } else { return(null); } }
// Start is called before the first frame update void Start() { instance = this; allpipes = FindObjectsOfType <PipeScript>(); }
public BaseResponse HandleApproveTag(DynamicDictionary _parameters) { User user; string message = null; HydrantWikiManager hwm = new HydrantWikiManager(); if (AuthHelper.IsAuthorized(Request, out user)) { if (user.UserType == UserTypes.SuperUser || user.UserType == UserTypes.Administrator) { Guid?tagId = _parameters["tagid"]; if (tagId != null) { Tag tag = hwm.GetTag(tagId.Value); if (tag != null) { if (tag.Status == TagStatus.Pending) { //Create hydrant Hydrant hydrant = new Hydrant { Guid = Guid.NewGuid(), Active = true, CreationDateTime = tag.DeviceDateTime, LastModifiedBy = tag.LastModifiedBy, LastModifiedDateTime = tag.LastModifiedDateTime, LastReviewerUserGuid = user.Guid, OriginalReviewerUserGuid = user.Guid, OriginalTagDateTime = tag.DeviceDateTime, OriginalTagUserGuid = tag.UserGuid, Position = tag.Position, PrimaryImageGuid = tag.ImageGuid }; hwm.Persist(hydrant); //Set the tag to approved tag.Status = TagStatus.Approved; hwm.Persist(tag); //Update the stats Guid userGuid = tag.UserGuid; UserStats stats = hwm.GetUserStats(userGuid); if (stats == null) { stats = new UserStats(); stats.UserGuid = userGuid; stats.DisplayName = user.DisplayName; stats.Active = true; } stats.ApprovedTagCount++; hwm.Persist(stats); hwm.LogInfo(user.Guid, string.Format("Tag Approved ({0})", tagId)); return(new ReviewTagResponse { Success = true }); } else { message = "Tag already reviewed"; } } else { message = "Tag not found"; } } else { message = "Tag not specified"; } } hwm.LogWarning(user.Guid, string.Format("Tag Approve Error ({0})", message)); } else { LogUnauthorized(Request); } return(new ReviewTagResponse { Success = false, Message = message }); }
public BaseResponse HandleMatchTag(DynamicDictionary _parameters) { User user; string message = null; HydrantWikiManager hwm = new HydrantWikiManager(); if (AuthHelper.IsAuthorized(Request, out user)) { if (user.UserType == UserTypes.SuperUser || user.UserType == UserTypes.Administrator) { Guid?tagId = _parameters["tagid"]; Guid?hydrantId = _parameters["hydrantid"]; if (tagId != null && hydrantId != null) { Tag tag = hwm.GetTag(tagId.Value); if (tag != null) { Hydrant hydrant = hwm.GetHydrant(hydrantId.Value); if (hydrant != null) { //Set the tag to approved tag.HydrantGuid = hydrant.Guid; tag.Status = TagStatus.Approved; hwm.Persist(tag); //Set the hydrant review hydrant.LastReviewerUserGuid = user.Guid; hwm.Persist(hydrant); //Update the stats Guid userGuid = tag.UserGuid; UserStats stats = hwm.GetUserStats(userGuid); if (stats == null) { stats = new UserStats(); stats.UserGuid = userGuid; stats.DisplayName = user.DisplayName; stats.Active = true; } stats.ApprovedTagCount++; hwm.Persist(stats); hwm.LogInfo(user.Guid, string.Format("Tag Matched ({0} to {1})", tagId, hydrantId)); return(new ReviewTagResponse { Success = true }); } else { message = "Hydrant not found"; } } else { message = "Tag not found"; } } else { message = "TagId or HydrantId not specified"; } } hwm.LogWarning(user.Guid, string.Format("Tag Match Error ({0})", message)); } return(new ReviewTagResponse { Success = false, Message = message }); }
/// <summary> /// /// </summary> /// <param name="_hydrant"></param> public void DeleteHydrant(Hydrant _hydrant) { HydrantDAO dao = new HydrantDAO(MongoDB); dao.Delete(_hydrant); }
/// <summary> /// /// </summary> /// <param name="_hydrant"></param> public void Persist(Hydrant _hydrant) { HydrantDAO dao = new HydrantDAO(MongoDB); dao.Persist(_hydrant); }
private string HandleGet(DynamicDictionary _parameters) { HydrantWikiManager hwManager = new HydrantWikiManager(); StringBuilder sb = new StringBuilder(); string sGuid = _parameters["hydrantguid"]; if (sGuid != null) { Guid guid = new Guid(sGuid); Hydrant hydrant = hwManager.GetHydrant(guid); if (hydrant != null) { sb.Append("<table width=\"100%\" >"); sb.Append("<tr class=\"hdHeaderRow\">"); sb.Append("<td class=\"hdHeaderColumn\" colspan=\"2\"><h3>Hydrant</h3></td>"); sb.Append("</tr>"); if (hydrant.Position != null) { sb.Append("<tr class=\"hdPosition\" >"); sb.Append("<td class=\"hdPositionTitle\"><strong>Latitude</strong></td>"); sb.AppendFormat("<td class=\"hdPositionValue\">{0}</td>", hydrant.Position.Y.ToString("0.00000000")); sb.Append("</tr>"); sb.Append("<tr class=\"hdPosition\">"); sb.Append("<td class=\"hdPositionTitle\"><strong>Longitude</strong></td>"); sb.AppendFormat("<td class=\"hdPositionValue\">{0}</td>", hydrant.Position.X.ToString("0.00000000")); sb.Append("</tr>"); } //Add the primary image string thumbNailURL = hydrant.GetUrl(true); string mediumSizeURL = hydrant.GetUrl(false); if (thumbNailURL != null && mediumSizeURL != null) { sb.Append("<tr class=\"hdImageRow\" >"); sb.Append("<td class=\"hdImageColumn\" colspan=\"2\">"); sb.Append("<a href=\""); sb.Append(mediumSizeURL); sb.Append("\" target=\"_blank\" >"); sb.Append("<img src=\""); sb.Append(thumbNailURL); sb.Append("\" alt=\"Image\"/></a></td>"); sb.Append("</tr>"); } if (hydrant.Properties.Count > 0) { //Add the tagger attribution sb.Append("<tr class=\"hdTaggersRow\" >"); sb.Append("<td class=\"hdTaggersColumn\" colspan=\"2\"><h4>Extended Properties</h4></td>"); foreach (Property prop in hydrant.Properties) { sb.Append("<tr class=\"hdPosition\" >"); sb.Append("<td class=\"hdPositionTitle\"><strong>"); sb.Append(prop.Name); sb.Append("</strong></td>"); sb.AppendFormat("<td class=\"hdPositionValue\">{0}</td>", prop.Value); sb.Append("</tr>"); } } //Add the tagger attribution sb.Append("<tr class=\"hdTaggersRow\" >"); sb.Append("<td class=\"hdTaggersColumn\" colspan=\"2\"><h4>Taggers</h4></td>"); Dictionary <Guid, User> users = new Dictionary <Guid, User>(); List <Tag> tags = hwManager.GetTags(hydrant.Guid); foreach (Tag tag in tags) { if (!users.ContainsKey(tag.UserGuid)) { User user = (User)hwManager.GetUser(tag.UserGuid); users.Add(user.Guid, user); } } foreach (User user in users.Values) { string source; string userName; if (user.UserSource.Equals("OSM", StringComparison.InvariantCultureIgnoreCase)) { source = "Open Street Maps"; userName = user.DisplayName; } else if (user.UserSource.Equals("Yo", StringComparison.InvariantCultureIgnoreCase)) { source = "Yo"; userName = user.DisplayName; } else { source = "HydrantWiki"; userName = user.DisplayName; } sb.Append("<tr class=\"hdTaggerRow\" >"); sb.AppendFormat("<td class=\"hdTaggerColumn\" colspan=\"2\" >{0} : {1}</td>", source, userName); sb.Append("</tr>"); } sb.Append("</table>"); return(sb.ToString()); } } return("<strong>Hydrant Not Found</strong>"); }