internal bool Delete(ViewRoutePoint viewRoutePoint) { bool result = false; string rId = viewRoutePoint.RouteId; try { RealmInstance.Write(() => { var point = RealmInstance.Find <RoutePoint>(viewRoutePoint.Id); foreach (var item in point.MediaObjects) { RealmInstance.Remove(item); } RealmInstance.Remove(point); }); result = true; } catch (Exception e) { HandleError.Process("RoutePointManager", "DeleteRoutePoint", e, false); } return(result); }
internal bool Delete(string mediaObjectId) { bool result = false; try { RealmInstance.Write(() => { var mediaObject = RealmInstance.Find <RoutePointMediaObject>(mediaObjectId); if (mediaObject != null) { var pointObject = RealmInstance.Find <RoutePoint>(mediaObject.RoutePointId); if (pointObject != null) { mediaObject.IsDeleted = true; mediaObject.Version++; result = mediaObject.IsDeleted; //нужно для того, чтобы синхронизация обнаружила отличия от сервера и проверила версии с последующей отправкой изменений на сервер pointObject.MainRoute.ObjVerHash = string.Empty; } } } ); } catch (Exception e) { HandleError.Process("RoutePointMediaObjectManager", "Delete", e, false); } return(result); }
internal bool Save(ViewUserInfo viewUserInfo) { bool result = false; try { RealmInstance.Write(() => { var dbObject = !string.IsNullOrEmpty(viewUserInfo.UserId) ? RealmInstance.Find <User>(viewUserInfo.UserId) : null; if (dbObject == null) { dbObject = new User(); dbObject.UserId = viewUserInfo.UserId; RealmInstance.Add(dbObject); } dbObject.Name = viewUserInfo.Name; dbObject.Email = viewUserInfo.Email; dbObject.ImgUrl = viewUserInfo.ImgUrl; }); result = true; } catch (Exception e) { HandleError.Process("UserManager", "Save", e, false); } return(result); }
public bool SetSyncStatus(string Id, bool IsSyncPreview, bool Status) { bool result = false; try { RealmInstance.Write(() => { var mediaObject = RealmInstance.Find <RoutePointMediaObject>(Id); if (IsSyncPreview) { mediaObject.PreviewServerSynced = Status; } else { mediaObject.OriginalServerSynced = Status; } } ); result = true; } catch (Exception e) { HandleError.Process("RoutePointMediaObjectManager", "SetSyncStatus", e, false); } return(result); }
internal (int pointCountInRoute, double length) GetLengthRouteData(string routeId) { double length = 0; int countPoints = 0; if (!string.IsNullOrEmpty(routeId)) { var route = RealmInstance.Find <Route>(routeId); if (route != null) { countPoints = route.Points.Count; for (int index = 0; index < countPoints; index++) { if (index + 1 < countPoints) { var firstPoint = route.Points[index]; var secondPoint = route.Points[index + 1]; if ((firstPoint.Latitude != 0) && (firstPoint.Longitude != 0)) { if ((secondPoint.Latitude != 0) && (secondPoint.Longitude != 0)) { Location firstPointLocation = new Location(firstPoint.Latitude, firstPoint.Longitude); Location secondPointLocation = new Location(secondPoint.Latitude, secondPoint.Longitude); length += Location.CalculateDistance(firstPointLocation, secondPointLocation, DistanceUnits.Kilometers); } } } } } } return(countPoints, length); }
internal string GetDefaultImagePreviewFilename(string routePointId) { string filename = string.Empty; RoutePoint point = RealmInstance.Find <RoutePoint>(routePointId); if (point?.MediaObjects.Count > 0) { filename = $"img_{point.MediaObjects[0].RoutePointMediaObjectId}_preview.jpg"; } else { filename = "emptylist.png"; } return(filename); }
internal void Delete(string poiId) { try { RealmInstance.Write(() => { var poiDb = RealmInstance.Find <Poi>(poiId); if (poiDb != null) { RealmInstance.Remove(poiDb); } }); } catch (Exception e) { HandleError.Process("PoiManager", "Delete", e, false); } }
internal void Delete(string id) { try { RealmInstance.Write(() => { var dbObject = RealmInstance.Find <LocalFile>(id); if (dbObject != null) { RealmInstance.Remove(dbObject); } }); } catch (Exception e) { HandleError.Process("LocalFileCacheManager", "Delete", e, false); } }
public bool Save(ViewPoi viewPoi) { bool result = false; try { RealmInstance.Write(() => { var poi = !string.IsNullOrEmpty(viewPoi.Id) ? RealmInstance.Find <Poi>(viewPoi.Id) : null; if (null == poi) { poi = string.IsNullOrEmpty(viewPoi.Id) ? new Poi() : new Poi() { PoiId = viewPoi.Id }; RealmInstance.Add(poi); } poi.Name = viewPoi.Name; poi.CreateDate = viewPoi.CreateDate; poi.UpdateDate = viewPoi.UpdateDate; poi.IsDeleted = viewPoi.IsDeleted; poi.CreatorId = viewPoi.CreatorId; poi.ImgFilename = viewPoi.ImgFilename; poi.Description = viewPoi.Description; //poi.PoiType = viewPoi.PoiType; poi.Address = viewPoi.Address; poi.ByRoutePointId = viewPoi.ByRoutePointId; poi.ByRouteId = viewPoi.ByRouteId; poi.IsPublished = viewPoi.IsPublished; poi.Latitude = viewPoi.Location.Latitude; poi.Longitude = viewPoi.Location.Longitude; poi.LikesCount = viewPoi.LikesCount; poi.ViewsCount = viewPoi.ViewsCount; }); var poiSaved = RealmInstance.Find <Poi>(viewPoi.Id); viewPoi.Refresh(poiSaved.PoiId); result = true; } catch (Exception e) { HandleError.Process("PoiManager", "SavePoi", e, false); } return(result); }
internal string Save(ViewRoutePointMediaObject vmedia) { string returnId = string.Empty; try { var pointObject = RealmInstance.Find <RoutePoint>(vmedia.RoutePointId); RealmInstance.Write(() => { RoutePointMediaObject mediaObject = !string.IsNullOrEmpty(vmedia.Id) ? RealmInstance.Find <RoutePointMediaObject>(vmedia.Id) : null; if (mediaObject == null) { mediaObject = new RoutePointMediaObject(); mediaObject.RoutePointMediaObjectId = vmedia.Id; mediaObject.RoutePointId = vmedia.RoutePointId; mediaObject.Point = pointObject; RealmInstance.Add(mediaObject); } if (mediaObject.Version != vmedia.Version) { //нужно для того, чтобы синхронизация обнаружила отличия от сервера и проверила версии с последующей отправкой изменений на сервер var route = pointObject.MainRoute; route.ObjVerHash = string.Empty; } returnId = mediaObject.RoutePointMediaObjectId; mediaObject.OriginalServerSynced = vmedia.OriginalServerSynced; mediaObject.PreviewServerSynced = vmedia.PreviewServerSynced; mediaObject.ServerSyncedDate = vmedia.ServerSyncedDate; mediaObject.Version = vmedia.Version; mediaObject.IsDeleted = vmedia.IsDeleted; mediaObject.MediaType = (int)vmedia.MediaType; mediaObject.Processed = vmedia.Processed; mediaObject.ProcessResultText = vmedia.ProcessResultText; }); } catch (Exception e) { HandleError.Process("RoutePointMediaObjectManager", "SaveRoutePointMediaObject", e, false); } return(returnId); }
public bool Save(ViewRoute viewRoute) { bool result = false; RouteManager routeManager = new RouteManager(); try { RealmInstance.Write(() => { var route = !string.IsNullOrEmpty(viewRoute.Id) ? RealmInstance.Find <Route>(viewRoute.Id) : null; if (null == route) { route = string.IsNullOrEmpty(viewRoute.Id) ? new Route() : new Route() { RouteId = viewRoute.Id }; RealmInstance.Add(route); } route.Name = viewRoute.Name; route.Version = viewRoute.Version; route.CreateDate = viewRoute.CreateDate; route.IsShared = viewRoute.IsShared; route.IsPublished = viewRoute.IsPublished; route.IsDeleted = viewRoute.IsDeleted; route.CreatorId = viewRoute.CreatorId; route.ObjVerHash = viewRoute.ObjVerHash; route.ImgFilename = viewRoute.ImgFilename; route.Description = viewRoute.Description; if (!route.ServerSynced.Equals(viewRoute.ServerSynced) && viewRoute.ServerSynced) { route.ServerSyncedDate = DateTimeOffset.Now; } route.ServerSynced = !string.IsNullOrEmpty(viewRoute.ObjVerHash) && viewRoute.ServerSynced; viewRoute.Refresh(route.RouteId); }); result = true; } catch (Exception e) { HandleError.Process("RouteManager", "AddRoute", e, false); } return(result); }
internal void DeleteObjectFromLocalStorage(ViewRoutePointMediaObject vmedia) { if (vmedia != null) { try { RoutePointMediaObject media = !string.IsNullOrEmpty(vmedia.Id) ? RealmInstance.Find <RoutePointMediaObject>(vmedia.Id) : null; if (media != null) { RealmInstance.Write(() => { RealmInstance.Remove(media); }); } } catch (Exception e) { HandleError.Process("RoutePointMediaObjectManager", "DeleteObjectFromLocalStorage", e, false); } } }
internal void DeleteObjectFromLocalStorage(ViewRoute vRoute) { if (vRoute != null) { try { Route route = !string.IsNullOrEmpty(vRoute.Id) ? RealmInstance.Find <Route>(vRoute.Id) : null; if (route != null) { RealmInstance.Write(() => { RealmInstance.Remove(route); }); } } catch (Exception e) { HandleError.Process("RouteManager", "DeleteObjectFromLocalStorage", e, false); } } }
public bool Save(ViewLocalFile viewItem) { bool result = false; try { RealmInstance.Write(() => { var dbObject = !string.IsNullOrEmpty(viewItem.Id) ? RealmInstance.Find <LocalFile>(viewItem.Id) : null; if (null == dbObject) { dbObject = string.IsNullOrEmpty(viewItem.Id) ? new LocalFile() : new LocalFile() { LocalFileId = viewItem.Id }; RealmInstance.Add(dbObject); } dbObject.Address = viewItem.Address; dbObject.Country = viewItem.Country; dbObject.FileNameDate = viewItem.FileNameDate; dbObject.CreateDate = viewItem.CreateDate; dbObject.ImagePreviewFileName = viewItem.ImagePreviewFileName; dbObject.Latitude = viewItem.Latitude; dbObject.Longitude = viewItem.Longitude; dbObject.SourceFileName = viewItem.SourceFileName; dbObject.SourcePath = viewItem.SourcePath; dbObject.Processed = viewItem.Processed; }); result = true; } catch (Exception e) { HandleError.Process("LocalFileCacheManager", "Save", e, false); } return(result); }
internal string Save(ViewRoutePoint vpoint) { string returnid = string.Empty; RouteManager routeManager = new RouteManager(); vpoint.Version = vpoint.Version == 0 ? 1 : vpoint.Version; if (vpoint.CreateDate.Year == 1) { HandleError.Process("RoutePointManager", "Save", new Exception("CreateDate is empty"), false, $"routePointId:[{vpoint.RoutePointId}]"); //throw new Exception("create date year = 1"); //vpoint.CreateDate = new DateTime(2020,1,1); } try { RealmInstance.Write(() => { RoutePoint point = !string.IsNullOrEmpty(vpoint.Id) ? RealmInstance.Find <RoutePoint>(vpoint.Id) : null; if (point == null) { point = new RoutePoint(); point.RoutePointId = !string.IsNullOrEmpty(vpoint.Id) ? vpoint.Id: point.RoutePointId; point.RouteId = vpoint.RouteId; point.MainRoute = routeManager.GetRouteById(vpoint.RouteId); if (point.MainRoute != null) { point.MainRoute.Points.Add(point);//? } else { HandleError.Process("RoutePointManager", "SavePoint", new Exception($"routeId:{vpoint.RouteId}, pointId:{vpoint.Id}"), false); } RealmInstance.Add(point); } else { //point = _realmInstance.Find<RoutePoint>(vpoint.Id); } if (point.Version != vpoint.Version) { //нужно для того, чтобы синхронизация обнаружила отличия от сервера и проверила версии с последующей отправкой изменений на сервер point.MainRoute.ObjVerHash = string.Empty; } returnid = point.RoutePointId; point.Address = vpoint.Address; point.Description = vpoint.Description; point.Latitude = vpoint.Latitude; point.Longitude = vpoint.Longitude; point.Name = vpoint.Name; point.UpdateDate = DateTime.Now; point.Version = vpoint.Version; point.IsDeleted = vpoint.IsDeleted; point.CreateDate = vpoint.CreateDate; point.MediaObjects.Clear(); foreach (var media in vpoint.MediaObjects) { point.MediaObjects.Add(media); } }); } catch (Exception e) { HandleError.Process("RoutePointManager", "AddRoutePoint", e, false); } return(returnid); }
internal Route GetRouteById(string routeId) { return(RealmInstance.Find <Route>(routeId)); }
internal User GetById(string userId) { return(RealmInstance.Find <User>(userId)); }
internal RoutePoint GetPointById(string id) { return(!string.IsNullOrEmpty(id)? RealmInstance.Find <RoutePoint>(id):null); }
public bool MediaIsExists(string Id) { var mediaObject = RealmInstance.Find <RoutePointMediaObject>(Id); return(mediaObject != null); }
internal Poi GetPoiById(string id) { return(RealmInstance.Find <Poi>(id)); }
public string GetFullPathAndFilename(string mediaId) { var objLocalFile = RealmInstance.Find <LocalFile>(mediaId); return(Path.Combine(objLocalFile.SourcePath, objLocalFile.SourceFileName)); }