public NewGPSLocalisationForm(CollectionEventLocalisation alt, CollectionEventLocalisation gps) : this(true) { this._start = true; Cursor.Current = Cursors.WaitCursor; if (alt != null) { this.locAlt = alt; } if (gps != null) { this.locGPS = gps; } // fill Form if (locGPS != null) { this.textBoxLongitude.Text = locGPS.Location1; this.textBoxLatitude.Text = locGPS.Location2; } if (locAlt != null) { this.textBoxAltitude.Text = locAlt.Location1; } Cursor.Current = Cursors.Default; this._start = false; }
private void buttonLoad_Click(object sender, RoutedEventArgs e) { IRestriction r = RestrictionFactory.TypeRestriction(typeof(CollectionEventLocalisation)); IList <CollectionEventLocalisation> spec = mobSer.Connector.LoadList <CollectionEventLocalisation>(r); CollectionEventLocalisation ce = spec.First(); Guid g = ce.Rowguid; r = RestrictionFactory.Eq(typeof(CollectionEventLocalisation), "_guid", g); obj2 = repSer.Connector.Load <CollectionEventLocalisation>(r); }
/// <summary> /// Extracts the geo location information stored in the client-side <see cref="Event"/> Object /// And converts it to its <see cref="CollectionEventLocalisation"/> representation. /// </summary> /// <param name="ev">The client-side Event object possibly containing location information.</param> /// <param name="profile">The Profile of the User responsible for creating this object.</param> /// <returns>Between 0 and 2 <see cref="CollectionEventLocalisation"/> objects depending on the amount of information in the Input object.</returns> public static IEnumerable<CollectionEventLocalisation> GetLocalisations(this Event ev, UserCredentials profile) { IList<CollectionEventLocalisation> localisations = new List<CollectionEventLocalisation>(); if (ev.Altitude.HasValue && !double.IsNaN(ev.Altitude.Value)) { CollectionEventLocalisation altitude = new CollectionEventLocalisation(); altitude.AverageAltitudeCache = ev.Altitude; altitude.AverageLatitudeCache = ev.Latitude; altitude.AverageLongitudeCache = ev.Longitude; altitude.CollectionEventID = ev.CollectionEventID; altitude.DeterminationDate = ev.CollectionDate; altitude.LocalisationSystemID = ALTITUDE_LOC_SYS_ID; altitude.Location1 = ev.Altitude.ToString(); altitude.ResponsibleAgentURI = profile.AgentURI; altitude.ResponsibleName = profile.AgentName; altitude.RecordingMethod = "Generated via DiversityMobile"; localisations.Add(altitude); } if (ev.Latitude.HasValue && !double.IsNaN(ev.Latitude.Value) && ev.Longitude.HasValue && !double.IsNaN(ev.Longitude.Value)) { CollectionEventLocalisation wgs84 = new CollectionEventLocalisation(); if (ev.Altitude != null && double.IsNaN((double)ev.Altitude) == false) { wgs84.AverageAltitudeCache = ev.Altitude; } else { wgs84.AverageAltitudeCache = null; } wgs84.AverageLatitudeCache = ev.Latitude; wgs84.AverageLongitudeCache = ev.Longitude; wgs84.CollectionEventID = ev.CollectionEventID; wgs84.DeterminationDate = ev.CollectionDate; wgs84.LocalisationSystemID = WGS84_LOC_SYS_ID; wgs84.Location1 = ev.Longitude.ToString(); wgs84.Location2 = ev.Latitude.ToString(); wgs84.ResponsibleAgentURI = profile.AgentURI; wgs84.ResponsibleName = profile.AgentName; wgs84.RecordingMethod = "Generated via DiversityMobile"; localisations.Add(wgs84); } return localisations; }
public void CreateNewEvent(int?seriesID, double altitude, double longitude, double latitude, int countSat, float dilution) { CollectionEvent ce = SERIALIZER.CreateISerializableObject <CollectionEvent>(); ce.SeriesID = seriesID; if (this.LastCollectorsEventNumber != -1) { ce.CollectorsEventNumber = (this.LastCollectorsEventNumber + 1).ToString(); } if (seriesID != null) { try { SERIALIZER.ConnectOneToMany(EventSeriess.Instance.Current, ce); } catch (ConnectionCorruptedException ex) { throw ex; } } try { con.Save(ce); this._currentEvent = this._ceIterator.Last(); } catch (Exception ex) { throw new DataFunctionsException("New CollectionEvent couldn't be saved. (" + ex.Message + ")"); } // Default Localisation: altitude CollectionEventLocalisation ceLoc1 = SERIALIZER.CreateISerializableObject <CollectionEventLocalisation>(); SERIALIZER.ConnectOneToMany(ce, ceLoc1); ceLoc1.LocalisationSystemID = 4; ceLoc1.AverageAltitudeCache = altitude; ceLoc1.Location1 = altitude.ToString("00.00"); // Notes: automatically changed per GPS StringBuilder builder = new StringBuilder(); builder.AppendLine("GPS Coordinates automatically changed"); builder.AppendLine("Number of Satellites: " + countSat.ToString()); builder.AppendLine("Position Dilution: " + dilution.ToString()); ceLoc1.LocationNotes = builder.ToString(); try { if (UserProfiles.Instance.Current != null) { ceLoc1.ResponsibleName = UserProfiles.Instance.Current.CombinedNameCache; if (UserProfiles.Instance.Current.AgentURI != null) { ceLoc1.ResponsibleAgentURI = UserProfiles.Instance.Current.AgentURI; } } } catch (ConnectionCorruptedException) { } try { con.Save(ceLoc1); } catch (Exception ex) { throw new DataFunctionsException("Associated Localisation (Type Altitude) couldn't be created. (" + ex.Message + ")"); } // Default Localisation: wgs84 CollectionEventLocalisation ceLoc2 = SERIALIZER.CreateISerializableObject <CollectionEventLocalisation>(); SERIALIZER.ConnectOneToMany(ce, ceLoc2); ceLoc2.LocalisationSystemID = 8; ceLoc2.AverageLatitudeCache = latitude; ceLoc2.AverageLongitudeCache = longitude; ceLoc2.AverageAltitudeCache = altitude; ceLoc2.Location1 = longitude.ToString("00.00000000"); ceLoc2.Location2 = latitude.ToString("00.00000000"); // Notes: automatically changed per GPS ceLoc2.LocationNotes = builder.ToString(); try { if (UserProfiles.Instance.Current != null) { ceLoc2.ResponsibleName = UserProfiles.Instance.Current.CombinedNameCache; if (UserProfiles.Instance.Current.AgentURI != null) { ceLoc2.ResponsibleAgentURI = UserProfiles.Instance.Current.AgentURI; } } } catch (ConnectionCorruptedException) { } try { con.Save(ceLoc2); } catch (Exception ex) { throw new DataFunctionsException("Associated Localisation (Type GPS) couldn't be created. (" + ex.Message + ")"); } }
public LocalisationDetailForm(CollectionEventLocalisation ceLoc) : this(true) { if (ceLoc != null) { this._ceLoc = ceLoc; Cursor.Current = Cursors.WaitCursor; LocalisationSystem locSystem = null; try { locSystem = DataFunctions.Instance.RetrieveLocalisationSystem((int)_ceLoc.LocalisationSystemID); } catch (ConnectionCorruptedException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); this.Close(); } // fill Form if (locSystem != null) { this.labelCaption.Text = locSystem.LocalisationSystemName; } if (_ceLoc.LocationAccuracy != null) { this.textBoxLocAccuracy.Text = _ceLoc.LocationAccuracy; } if (_ceLoc.Location1 != null) { this.textBoxLocation1.Text = _ceLoc.Location1; } if (_ceLoc.Location2 != null) { this.textBoxLocation2.Text = _ceLoc.Location2; } if (_ceLoc.ResponsibleName != null) { this.textBoxResponsibleName.Text = _ceLoc.ResponsibleName; } if (_ceLoc.DeterminationDate > DateTime.MinValue) { if (_ceLoc.DeterminationDate.CompareTo(this.dateTimePickerDeterminationDate.MinDate) >= 0) { try { if (!UserProfiles.Instance.Current.Context.Equals("ManagementMobile")) { this.dateTimePickerDeterminationDate.Visible = true; } } catch (ConnectionCorruptedException) { this.dateTimePickerDeterminationDate.Visible = false; } this.buttonNewDate.Visible = false; this.dateTimePickerDeterminationDate.Value = _ceLoc.DeterminationDate; } } else { this.dateTimePickerDeterminationDate.Visible = false; try { if (!UserProfiles.Instance.Current.Context.Equals("ManagementMobile")) { this.buttonNewDate.Visible = true; } } catch (ConnectionCorruptedException) { this.dateTimePickerDeterminationDate.Visible = false; } } // Altitude Localisation if (this._ceLoc.LocalisationSystemID == 4) { this.textBoxLocation2.Enabled = false; this.buttonShowMap.Enabled = false; } if (_ceLoc.AverageLongitudeCache != null) { this.labelLongitude.Text = ((double)_ceLoc.AverageLongitudeCache).ToString("F"); } if (_ceLoc.AverageLatitudeCache != null) { this.labelLatitude.Text = ((double)_ceLoc.AverageLatitudeCache).ToString("F"); } if (_ceLoc.AverageAltitudeCache != null) { this.labelAltitude.Text = ((double)_ceLoc.AverageAltitudeCache).ToString("F"); } Cursor.Current = Cursors.Default; } else { this.Close(); } }
public EventLocalisationVM(CollectionEventLocalisation l) : base(l) { }
public void transferPicture(ISerializableObject iso) { resetInformation(); _service = new DiversityMediaServiceClient(); if (_service.State != System.ServiceModel.CommunicationState.Opened) { try { _service.Open(); } catch (Exception e) { StringBuilder sb = new StringBuilder("Cant Open Connection: ").Append(e.Message); if (e.InnerException != null) { sb.Append(","); sb.Append(e.InnerException.Message); } throw new Exception(sb.ToString()); } } _author = this._userName; _projectId = this._project; //Fallunterscheidung nach ImageTypeClasse um benötigte informationen zu bekommen try { if (iso is CollectionEventImage) { CollectionEventImage cei = (CollectionEventImage)iso; _rowGuid = cei.Rowguid.ToString(); string pureFileName = System.IO.Path.GetFileName(cei.URI); string path = System.IO.Directory.GetCurrentDirectory(); StringBuilder sb = new StringBuilder(_pictureDirectory); sb.Append("\\"); sb.Append(pureFileName); _pathName = sb.ToString(); _type = cei.ImageType; IRestriction re = RestrictionFactory.Eq(typeof(CollectionEvent), "_CollectionEventID", cei.CollectionEventID); CollectionEvent ce = _sourceSerializer.Connector.Load <CollectionEvent>(re); IRestriction r1 = RestrictionFactory.Eq(typeof(CollectionEventLocalisation), "_CollectionEventID", cei.CollectionEventID); IRestriction r2 = RestrictionFactory.Eq(typeof(CollectionEventLocalisation), "_LocalisationSystemID", 8); IRestriction r = RestrictionFactory.And().Add(r1).Add(r2); CollectionEventLocalisation cel = _sourceSerializer.Connector.Load <CollectionEventLocalisation>(r); if (cel != null) { if (cel.AverageAltitudeCache != null) { _longitude = (float)cel.AverageLongitudeCache; } if (cel.AverageLatitudeCache != null) { _latitude = (float)cel.AverageLatitudeCache; } if (cel.AverageLongitudeCache != null) { _altitude = (float)cel.AverageAltitudeCache; } } _timestamp = cei.LogTime.ToString(); } else if (iso.GetType().Equals(typeof(CollectionSpecimenImage))) { CollectionSpecimenImage csi = (CollectionSpecimenImage)iso; _rowGuid = csi.Rowguid.ToString(); string pureFileName = System.IO.Path.GetFileName(csi.URI); string path = System.IO.Directory.GetCurrentDirectory(); StringBuilder sb = new StringBuilder(_pictureDirectory); sb.Append("\\"); sb.Append(pureFileName); _pathName = sb.ToString(); _type = csi.ImageType; IRestriction re = RestrictionFactory.Eq(typeof(CollectionSpecimen), "_CollectionSpecimenID", csi.CollectionSpecimenID); CollectionSpecimen cs = _sourceSerializer.Connector.Load <CollectionSpecimen>(re); CollectionEvent ce = cs.CollectionEvent; IRestriction r1 = RestrictionFactory.Eq(typeof(CollectionEventLocalisation), "_CollectionEventID", ce.CollectionEventID); IRestriction r2 = RestrictionFactory.Eq(typeof(CollectionEventLocalisation), "_LocalisationSystemID", 8); IRestriction r = RestrictionFactory.And().Add(r1).Add(r2); CollectionEventLocalisation cel = _sourceSerializer.Connector.Load <CollectionEventLocalisation>(r); if (cel != null) { if (cel.AverageAltitudeCache != null) { _longitude = (float)cel.AverageLongitudeCache; } else { _longitude = 0; } if (cel.AverageLatitudeCache != null) { _latitude = (float)cel.AverageLatitudeCache; } else { _latitude = 0; } if (cel.AverageLongitudeCache != null) { _altitude = (float)cel.AverageAltitudeCache; } else { _altitude = 0; } } else { _latitude = _longitude = _altitude = 0; } _timestamp = csi.LogTime.ToString(); } else { throw new TransferException("ImageClass not Supported"); } } catch (Exception e) { StringBuilder sb = new StringBuilder("Corresponding data not found: ").Append(e.Message); if (e.InnerException != null) { sb.Append(","); sb.Append(e.InnerException.Message); } throw new Exception(sb.ToString()); } FileStream fileStrm = null; BinaryReader rdr = null; byte[] data = null; DateTime start = DateTime.Now; String retString = String.Empty; try { // Create stream and reader for file data fileStrm = new FileStream(_pathName, FileMode.Open, FileAccess.Read); rdr = new BinaryReader(fileStrm); } catch (Exception e) { StringBuilder sb = new StringBuilder("Picture not found: ").Append(e.Message); if (e.InnerException != null) { sb.Append(","); sb.Append(e.InnerException.Message); } if (rdr != null) { rdr.Close(); } throw new Exception(sb.ToString()); } try { // Number of bytes to be transferred long numBytes = fileStrm.Length; // Package counter int count = 0; // Return string _fileName = Path.GetFileName(_pathName); if (numBytes > 0) { data = rdr.ReadBytes((int)numBytes); count++; //retString = f.ReadFileAndTransfer(pathName); retString = _service.Submit(_fileName, _fileName, _type, _latitude, _longitude, _altitude, _author, _timestamp, _projectId, data); // IDs 372, 373, 374 } TimeSpan dif = DateTime.Now - start; if (retString.StartsWith("http")) { MessageBox.Show(retString); MessageBox.Show(dif.ToString() + " msec - " + count.ToString() + " packets transmitted"); } else { MessageBox.Show("ERROR: " + retString); } // Close reader and stream rdr.Close(); fileStrm.Close(); } catch (Exception e) { StringBuilder sb = new StringBuilder("Transfer Error: ").Append(e.Message); if (e.InnerException != null) { sb.Append(","); sb.Append(e.InnerException.Message); } if (rdr != null) { rdr.Close(); } if (fileStrm != null) { fileStrm.Close(); } throw new Exception(sb.ToString()); } finally { // Abort faulted proxy if (_service.State == System.ServiceModel.CommunicationState.Faulted) { // Webservice method call // proxy.Rollback(); _service.Abort(); } // Close proxy else if (_service.State == System.ServiceModel.CommunicationState.Opened) { _service.Close(); } } if (iso.GetType().Equals(typeof(CollectionEventImage))) { CollectionEventImage cei = (CollectionEventImage)iso; cei.URI = retString; } if (iso.GetType().Equals(typeof(CollectionSpecimenImage))) { CollectionSpecimenImage csi = (CollectionSpecimenImage)iso; csi.URI = retString; } // Close reader and stream rdr.Close(); fileStrm.Close(); }