private IDirectAccessIterator <IdentificationUnit> _identificationUnitIterator;//Dieser iteriert im Gegensatz zu den anderen KLassen in Datamanagement nur auf dem TopLevel #endregion #region Constructor internal IdentificationUnits(CollectionSpecimen cs) { if (cs != null) { this._collectionSpecimen = cs; _identificationUnitIterator = cs.IdentificationUnits; _identificationUnitIterator.Reset(); this._currentIdentificationUnit = _identificationUnitIterator.First(); if (this._currentIdentificationUnit != null) { while (this._currentIdentificationUnit.RelatedUnitID != null) { try { this._currentIdentificationUnit = this.Next; } catch (DataFunctionsException) { this._currentIdentificationUnit = null; } } } //this._identificationUnitBrotherIterator = this._identificationUnitIterator; } }
public CollectionSpecimen CreateSpecimen() { CollectionSpecimen cs = null; try { cs = SERIALIZER.CreateISerializableObject <CollectionSpecimen>(); SERIALIZER.ConnectOneToMany(_parent, cs); cs.CollectionEventID = _parent.CollectionEventID; con.Save(cs); } catch (Exception) { throw new DataFunctionsException("New Specimen couldn't be created."); } try { if (UserProfiles.Instance.Current != null) { try { CollectionAgent agent = SERIALIZER.CreateISerializableObject <CollectionAgent>(); SERIALIZER.ConnectOneToMany(cs, agent); agent.CollectionSpecimenID = cs.CollectionSpecimenID; agent.CollectorsName = UserProfiles.Instance.Current.CombinedNameCache; if (UserProfiles.Instance.Current.AgentURI != null) { agent.CollectorsAgentURI = UserProfiles.Instance.Current.AgentURI; } con.Save(agent); } catch (Exception) { throw new DataFunctionsException("Associated Agent of new Specimen couldn't be created."); } try { CollectionProject csProject = SERIALIZER.CreateISerializableObject <CollectionProject>(); csProject.CollectionSpecimenID = cs.CollectionSpecimenID; csProject.ProjectID = (int)UserProfiles.Instance.Current.ProjectID; con.Save(csProject); } catch (Exception) { throw new DataFunctionsException("Associated Project of new Specimen couldn't be created."); } } } catch (ConnectionCorruptedException) { } this._currentSpecimen = this._csIterator.Last(); return(cs); }
public SpecimenEditForm(CollectionSpecimen currentSpecimen) : this(true) { if (currentSpecimen != null) { this._specimen = currentSpecimen; //tabPage Specimen füllen und anzeigen Cursor.Current = Cursors.WaitCursor; this.fillSpecimenData(); Cursor.Current = Cursors.Default; } else { this.Close(); } }
bool isRoot(ISerializableObject iso) { if (iso is CollectionEventSeries) { return(true); } if (iso is CollectionEvent) { CollectionEvent ce = (CollectionEvent)iso; if (ce.SeriesID == null) { return(true); } } if (iso is CollectionSpecimen) { CollectionSpecimen spec = (CollectionSpecimen)iso; if (spec.CollectionEventID == null) { return(true); } } return(false); }
public CollectionEvent getEventForSpecimen(int specimenID) { CollectionSpecimen cs = null; try { IRestriction restrict = RestrictionFactory.Eq(typeof(CollectionSpecimen), "_CollectionSpecimenID", specimenID); cs = con.Load <CollectionSpecimen>(restrict); } catch (Exception) { return(null); } //SERIALIZER.ConnectOneToMany(cs, ce); if (cs != null) { return(cs.CollectionEvent); } else { return(null); } }
public SpecimenVM(CollectionSpecimen spec) : base(spec) { }
private void bottomUp(ISerializableObject iso, List <ISerializableObject> parents) { if (iso.GetType().Equals(typeof(IdentificationUnitAnalysis))) { IdentificationUnitAnalysis iua = (IdentificationUnitAnalysis)iso; IdentificationUnit iu = iua.IdentificationUnit; if (iu != null) { parents.Add(iu); bottomUp(iu, parents); } else { throw new Exception(); } } else if (iso.GetType().Equals(typeof(IdentificationUnit))) { IdentificationUnit iu = (IdentificationUnit)iso; /* * IDirectAccessIterator<Identification> identifications = iu.Identifications; * short i = 0; * Identification ident = null; * foreach (Identification id in identifications) * { * if (id.IdentificationSequence != null && id.IdentificationSequence > i) * { * i = (short)id.IdentificationSequence; * ident = id; * } * } * if (ident != null) * parents.Add(ident);*/ IdentificationUnit relatedUnit = iu.RelatedUnit; if (relatedUnit != null) { parents.Add(relatedUnit); bottomUp(relatedUnit, parents); } else { CollectionSpecimen spec = iu.CollectionSpecimen; if (spec != null) { parents.Add(spec); bottomUp(spec, parents); } else { throw new Exception(); } } } else if (iso.GetType().Equals(typeof(CollectionSpecimen))) { CollectionSpecimen spec = (CollectionSpecimen)iso; CollectionAgent ca = spec.CollectionAgent.First(); if (ca != null) { parents.Add(ca); } CollectionEvent ce = spec.CollectionEvent; if (ce != null) { parents.Add(ce); bottomUp(ce, parents); } else { this.root = spec; }; //Warnung dass das Specimen nicht angezeigt werden kann } else if (iso.GetType().Equals(typeof(CollectionEvent))) { CollectionEvent ce = (CollectionEvent)iso; IDirectAccessIterator <CollectionEventLocalisation> locations = ce.CollectionEventLocalisation; foreach (CollectionEventLocalisation loc in locations) { parents.Add(loc); } IDirectAccessIterator <CollectionEventProperty> properties = ce.CollectionEventProperties; foreach (CollectionEventProperty prop in properties) { parents.Add(prop); } CollectionEventSeries cs = ce.CollectionEventSeries; if (cs != null) { parents.Add(cs); this.root = cs; } else { this.root = ce; } } else if (iso.GetType().Equals(typeof(CollectionEventSeries))) { CollectionEventSeries cs = (CollectionEventSeries)iso; this.root = cs; } }
private void topDown(ISerializableObject iso, List <ISerializableObject> children) { if (iso.GetType().Equals(typeof(CollectionEventSeries))) { CollectionEventSeries cs = (CollectionEventSeries)iso; IDirectAccessIterator <CollectionEvent> events = cs.CollectionEvents; foreach (CollectionEvent ce in events) { children.Add(ce); topDown(ce, children); } } if (iso.GetType().Equals(typeof(CollectionEvent))) { CollectionEvent ce = (CollectionEvent)iso; IDirectAccessIterator <CollectionEventLocalisation> locations = ce.CollectionEventLocalisation; foreach (CollectionEventLocalisation loc in locations) { children.Add(loc); } IDirectAccessIterator <CollectionEventProperty> properties = ce.CollectionEventProperties; foreach (CollectionEventProperty prop in properties) { children.Add(prop); } IDirectAccessIterator <CollectionSpecimen> specimen = ce.CollectionSpecimen; foreach (CollectionSpecimen spec in specimen) { children.Add(spec); topDown(spec, children); } } if (iso.GetType().Equals(typeof(CollectionSpecimen))) { CollectionSpecimen spec = (CollectionSpecimen)iso; CollectionAgent ca = spec.CollectionAgent.First(); if (ca != null) { children.Add(ca); } IDirectAccessIterator <CollectionProject> projects = spec.CollectionProject; foreach (CollectionProject pr in projects) { children.Add(pr); } IDirectAccessIterator <IdentificationUnit> units = spec.IdentificationUnits; foreach (IdentificationUnit iu in units) { if (iu.RelatedUnit == null)//Hier kann der Aufwand optimiert werden indem gleich alle IdentificationUnits angehängt werden, alerdings muss dann der Fall von einer IU als Startpunkt gesondert behandelt werden { children.Add(iu); topDown(iu, children); } } } if (iso.GetType().Equals(typeof(IdentificationUnit))) { IdentificationUnit iu = (IdentificationUnit)iso; IDirectAccessIterator <IdentificationUnitAnalysis> analyses = iu.IdentificationUnitAnalysis; IDirectAccessIterator <IdentificationUnitGeoAnalysis> geoAnalyses = iu.IdentificationUnitGeoAnalysis; IDirectAccessIterator <Identification> ids = iu.Identifications; foreach (IdentificationUnitAnalysis iua in analyses) { children.Add(iua); } foreach (IdentificationUnitGeoAnalysis iuga in geoAnalyses) { children.Add(iuga); } foreach (Identification id in ids) { children.Add(id); } IDirectAccessIterator <IdentificationUnit> units = iu.ChildUnits; foreach (IdentificationUnit childUnit in units) { children.Add(childUnit); topDown(childUnit, children); } } }
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(); }
public void Remove(CollectionSpecimen collectionSpecimen) { if (collectionSpecimen != null) { try { //// Remove Collection Specimen Attributs //foreach (CollectionAgent agent in DataFunctions.Instance.RetrieveAgentForCollectionSpecimen((int)collectionSpecimen.CollectionSpecimenID)) //{ // if (agent != null) // { // try // { // DataFunctions.Instance.Remove(agent); // } // catch (DataFunctionsException ex) // { // throw ex; // } // } //} // Remove all CollectionSpecimenImages assigned to CollectionSpecimen IList <CollectionSpecimenImage> csImgList; IRestriction restrict; try { restrict = RestrictionFactory.Eq(typeof(CollectionSpecimenImage), "_CollectionSpecimenID", collectionSpecimen.CollectionSpecimenID); csImgList = con.LoadList <CollectionSpecimenImage>(restrict); } catch (Exception) { throw new DataFunctionsException("List of assigned images couldn't be loaded."); } foreach (CollectionSpecimenImage csImgTemp in csImgList) { if (csImgTemp != null) { try { DataFunctions.Instance.Remove(csImgTemp); } catch (DataFunctionsException ex) { throw ex; } } } // Remove all IdentificationUnit assigned to CollectionSpecimen //IList<IdentificationUnit> iuList; //try //{ // restrict = RestrictionFactory.Eq(typeof(IdentificationUnit), "_CollectionSpecimenID", collectionSpecimen.CollectionSpecimenID); // iuList = con.LoadList<IdentificationUnit>(restrict); //} //catch (Exception) //{ // throw new DataFunctionsException("List of associated Identification Units couldn't be loaded."); //} //foreach (IdentificationUnit iuTemp in iuList) //{ // if (iuTemp != null) // { // try // { // DataFunctions.Instance.Remove(iuTemp); // } // catch (DataFunctionsException ex) // { // throw ex; // } // } //} //Remove all CollectionProjects assigned to CollectionSpecimen //IList<CollectionProject> projList; //try //{ // restrict = RestrictionFactory.Eq(typeof(CollectionProject), "_CollectionSpecimenID", collectionSpecimen.CollectionSpecimenID); // projList = con.LoadList<CollectionProject>(restrict); //} //catch (Exception) //{ // throw new DataFunctionsException("List of associated Identification Units couldn't be loaded."); //} //foreach (CollectionProject projTemp in projList) //{ // if (projTemp != null) // { // try // { // DataFunctions.Instance.Remove(projTemp); // } // catch (DataFunctionsException ex) // { // throw ex; // } // } //} try { con.Delete(collectionSpecimen); } catch (Exception) { throw new DataFunctionsException("Object (CollectionSpecimen) couldn't be removed."); } try { if (!this.HasNext) { if (this.HasPrevious) { this.Current = this.Previous; } else { this.Current = this.First; } } else { this.Current = this.Next; } } catch (DataFunctionsException ex) { throw ex; } } catch (ConnectionCorruptedException ex) { throw ex; } } }