public CollectionEvent getEventForIU(int iuID) { IdentificationUnit iu; try { IRestriction restrict = RestrictionFactory.Eq(typeof(IdentificationUnit), "_IdentificationUnitID", iuID); iu = con.Load <IdentificationUnit>(restrict); } catch (Exception) { return(null); } //SERIALIZER.ConnectOneToMany(iu, cs); //return this.getEventForSpecimen((int)iu.CollectionSpecimenID); if (iu != null) { return(iu.CollectionSpecimen.CollectionEvent); } else { return(null); } }
private SyncItem FetchSyncItem(Guid guid) { IRestriction r = RestrictionFactory.Eq(typeof(SyncItem), "_SyncGuid", guid); SyncItem siSource = (SyncItem)_syncSerializer.Connector.Load(typeof(SyncItem), r); return(siSource); }
public IRestriction GetRestrictionForType(Type t) { if (IsEnabled) { switch (this.Type) { case RestrictionType.Equals: return(RestrictionFactory.Eq(t, property, Value)); break; case RestrictionType.Like: string search = (!string.IsNullOrEmpty(Value))? Value.Trim('%', ' '):""; search = "%" + search + "%"; return(RestrictionFactory.Like(t, property, search)); break; case RestrictionType.BetweenDates: return(RestrictionFactory.Btw(t, property, StartTime, EndTime)); break; default: break; } } return(null); }
public IRestriction GetQueryRestriction() { IRestriction projectRestriction = RestrictionFactory.Eq(typeof(CollectionProject), "_ProjectID", ConnectionsAccess.Profile.ProjectID); IRestriction selectionRestrictions = null; foreach (var restrictionSpecification in Restrictions) { var currentRestriction = restrictionSpecification.GetRestrictionForType(ObjectType); if (currentRestriction != null) { if (selectionRestrictions != null) { selectionRestrictions = RestrictionFactory.And().Add(selectionRestrictions).Add(currentRestriction); } else { selectionRestrictions = currentRestriction; } } } if (selectionRestrictions != null) { return(RestrictionFactory.And().Add(projectRestriction).Add(selectionRestrictions)); } else { return(projectRestriction); } }
//internal CollectionEvents() //{ // IRestriction restrict = RestrictionFactory.TypeRestriction(typeof(CollectionEvent)); // _ceIterator = new DirectAccesIteratorImpl<CollectionEvent>(); // _ceIterator.Serializer = SERIALIZER; // _ceIterator.Restriction = restrict; // this.Current = _ceIterator.First(); //} public CollectionEvents(int?seriesID) { IRestriction restrict = null; restrict = RestrictionFactory.Eq(typeof(CollectionEvent), "_SeriesID", seriesID); _ceIterator = new DirectAccesIteratorImpl <CollectionEvent>(); _ceIterator.Serializer = SERIALIZER; _ceIterator.Restriction = restrict; this.Current = _ceIterator.First(); }
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); }
private UserProfile createProfile() { UserProfile newProfile; UserProxy proxy; int i = 0; try { newProfile = ConnectionsAccess.MobileDB.CreateISerializableObject <UserProfile>(); i++; //Zuerst korrespondierenden Userproxy holen IRestriction r = RestrictionFactory.Eq(typeof(UserProxy), "_LoginName", OptionsAccess.RepositoryOptions.LastUsername); //IRestriction r = RestrictionFactory.Eq(typeof(UserProxy), "_LoginName", @"TestEditor"); proxy = ConnectionsAccess.RepositoryDB.Connector.Load <UserProxy>(r); i++; newProfile.LoginName = OptionsAccess.RepositoryOptions.LastUsername; //newProfile.LoginName = @"TestEditor"; string agentName = null; i++;//3 using (var conn = ConnectionsAccess.RepositoryDefinitions.CreateConnection()) { try { conn.Open(); i++; var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT [AgentName] FROM [" + OptionsAccess.RepositoryOptions.TaxonNamesInitialCatalog + "].[dbo].[IBFagents] WHERE [AgentURI] = '" + proxy.AgentURI + "'"; _Log.DebugFormat("Select AgentName Command: [{0}]", cmd.CommandText); i++;//5 agentName = cmd.ExecuteScalar() as string; _Log.DebugFormat("AgentName: [{0}]", agentName); i++; } finally { conn.Close(); i++;//7 } } newProfile.CombinedNameCache = (!string.IsNullOrEmpty(agentName)) ? agentName : proxy.CombinedNameCache; i++; newProfile.HomeDB = OptionsAccess.RepositoryOptions.InitialCatalog; i++;//9 newProfile.AgentURI = proxy.AgentURI; i++; } catch (Exception ex) { newProfile = null; _Log.ErrorFormat("Error Creating Profile: {0}", ex); } return(newProfile); }
private IRestriction fromTextRestriction(TextRestriction res) { string value = res.Value ?? ""; if (res.ExactMatch) { return(RestrictionFactory.Eq(_configuredSearch.ObjectType, res.Property, value)); } else { return(RestrictionFactory.Like(_configuredSearch.ObjectType, res.Property, string.Format("%{0}%", value.Trim('%')))); } }
public UserProfile RetrieveUserProfile(int UserProfileID) { IRestriction restrict = RestrictionFactory.Eq(typeof(UserProfile), "_UserProfileID", UserProfileID); UserProfile up = null; try { up = con.Load <UserProfile>(restrict); } catch (Exception) { throw new UserProfileCorruptedException("User Profile for ID: " + UserProfileID + " couldn't be loaded."); } return(up); }
public CollectionEvent getEvent(int eventID) { CollectionEvent ce; try { IRestriction restrict = RestrictionFactory.Eq(typeof(CollectionEvent), "_CollectionEventID", eventID); ce = con.Load <CollectionEvent>(restrict); } catch (Exception) { ce = null; } return(ce); }
private void updateProfile() { _profile = null; if (Connections != null) { if (Settings != null && (_settings = Settings.getOptions()) != null) { if ((_mobileSerializer = Connections.MobileDB) != null) { MessengerInstance.Send <StatusNotification>("Services_UserProfile_SearchingProfile"); //Prüfen ob ein UserProfile zum LoginNamen existiert. IList <UserProfile> profiles = new List <UserProfile>(); IRestriction r = RestrictionFactory.Eq(typeof(UserProfile), "_LoginName", _settings.Username); //IRestriction r = RestrictionFactory.Eq(typeof(UserProfile), "_LoginName", "TestEditor"); profiles = _mobileSerializer.Connector.LoadList <UserProfile>(r); if (profiles.Count > 0) { _profile = profiles[0]; } else { MessengerInstance.Send <StatusNotification>("Services_UserProfile_CreatingNew"); _profile = createProfile(); } MessengerInstance.Send <StatusNotification>("Services_UserProfile_Loaded"); _operation.success(); } else { _Log.Error("Mobile DB not connected"); } } else { _Log.Error("Settings N/A"); } } else { _Log.Error("Connections N/A"); } _operation.failure("Services_UserProfile_Error_MissingConnectivitiy", ""); }
private IRestriction GetQueryRestriction() { IRestriction projectRestriction = RestrictionFactory.Eq(typeof(CollectionProject), "_ProjectID", _currentProjectID); IRestriction selectionRestrictions = null; foreach (var restrictionSpecification in _configuredSearch.Restrictions) { if (restrictionSpecification == null || !restrictionSpecification.IsEnabled) { continue; } IRestriction currRes = null; if (restrictionSpecification is TextRestriction) { currRes = fromTextRestriction(restrictionSpecification as TextRestriction); } else if (restrictionSpecification is DateRangeRestriction) { currRes = fromDateRangeRestriction(restrictionSpecification as DateRangeRestriction); } if (currRes != null) { if (selectionRestrictions != null) { selectionRestrictions = RestrictionFactory.And().Add(selectionRestrictions).Add(currRes); } else { selectionRestrictions = currRes; } } } if (selectionRestrictions != null) { return(RestrictionFactory.And().Add(projectRestriction).Add(selectionRestrictions)); } else { return(projectRestriction); } }
public bool Find(int id) { CollectionSpecimen cs; try { IRestriction restrict = RestrictionFactory.Eq(typeof(CollectionSpecimen), "_CollectionSpecimenID", id); cs = con.Load <CollectionSpecimen>(restrict); } catch (Exception) { return(false); } if (cs != null) { this.Current = cs; this._csIterator.SetIteratorTo(this._currentSpecimen); return(true); } return(false); }
public bool Find(int id) { try { IRestriction restrict = RestrictionFactory.Eq(typeof(CollectionEventSeries), "_SeriesID", id); this._currentSeries = con.Load <CollectionEventSeries>(restrict); if (this._currentSeries == null) { return(false); } else { this._ceIterator.SetIteratorTo(this._currentSeries); return(true); } } catch (Exception) { return(false); } }
private void buttonUpdate_Click(object sender, EventArgs e) { IRestriction rIds = RestrictionFactory.TypeRestriction(typeof(Identification)); IRestriction rUnits = RestrictionFactory.TypeRestriction(typeof(IdentificationUnit)); IList <Identification> idents_mob = mobileDBSerializer.Connector.LoadList <Identification>(rIds); IList <Identification> idents_rep = new List <Identification>(); IList <IdentificationUnit> units_mob = mobileDBSerializer.Connector.LoadList <IdentificationUnit>(rUnits); IList <IdentificationUnit> units_rep = new List <IdentificationUnit>(); foreach (Identification mobi in idents_mob) { IRestriction r = RestrictionFactory.Eq(typeof(Identification), "_guid", mobi.Rowguid); Identification partner = repositorySerializer.Connector.Load <Identification>(r); if (partner == null) { MessageBox.Show(mobi.Rowguid.ToString()); } else { if (mobi.IdentificationDate != partner.IdentificationDate) { idents_rep.Add(partner); } } } //foreach (IdentificationUnit mobi in units_mob) //{ // IRestriction r = RestrictionFactory.Eq(typeof(IdentificationUnit), "_guid", mobi.Rowguid); // IdentificationUnit partner = repositorySerializer.Connector.Load<IdentificationUnit>(r); // if (partner == null) // MessageBox.Show(mobi.Rowguid.ToString()); // else // { // units_rep.Add(partner); // } //} MessageBox.Show("Success"); }
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); } }
private void adjustAutoIncKeys(ISerializableObject manipulatedObject) { try { Type t = manipulatedObject.GetType(); //1.Abhängigkeiten aus Liste holen <eigenes Feld,Klasse> Dictionary <String, Type> foreignKeys = LookupSynchronizationInformation.getDeterminingFields(t); foreach (KeyValuePair <String, Type> fk in foreignKeys) { FieldInfo foreignAutoInc = t.GetField(fk.Key, BindingFlags.NonPublic | BindingFlags.Instance);//Enthält die Information darüber in welchem Feld das manipulatedObject einen fremden AutoInc-Key stehen hat. if (foreignAutoInc.GetValue(manipulatedObject) != null) { //2.AutoincFeld der PartnerKlasse holen String autoInc = LookupSynchronizationInformation.getAutoIncFields()[fk.Value]; //3.In der QuelldatenBank nach dem referenzierten AutoincSchlüssel suchen und das entsprechnde Objekt laden. IRestriction r = RestrictionFactory.Eq(fk.Value, autoInc, foreignAutoInc.GetValue(manipulatedObject)); ISerializableObject parent = sourceSerializer.Connector.Load(fk.Value, r); Guid g = parent.Rowguid; //4. synchronisierten Partner in der Zieldatenbank über Guid holen ISerializableObject parentPartner = FetchObject(sinkSerializer, g, fk.Value); FieldInfo partnerField = fk.Value.GetField(autoInc, BindingFlags.Instance | BindingFlags.NonPublic); //5. Werte anpassen foreignAutoInc.SetValue(manipulatedObject, partnerField.GetValue(parentPartner)); } } } catch (Exception e) { MessageBox.Show("KeyAdjustmentError: " + e.Message); if (e.InnerException != null) { MessageBox.Show(e.InnerException.Message); } throw new SerializerException("KeyAdjustmentError: " + e.Message); } }
public bool FindTopLevelIU(int id) { try { IRestriction r1 = RestrictionFactory.Eq(typeof(IdentificationUnit), "_IdentificationUnitID", id); IRestriction r2 = RestrictionFactory.Eq(typeof(IdentificationUnit), "_RelatedUnitID", null); IRestriction restrict = RestrictionFactory.And().Add(r1).Add(r2); this._currentIdentificationUnit = con.Load <IdentificationUnit>(restrict); if (this._currentIdentificationUnit == null) { return(false); } else { this._identificationUnitIterator.SetIteratorTo(this._currentIdentificationUnit); return(true); } } catch (Exception) { return(false); } }
private UserProfile createProfile() { UserProfile newProfile = null; if ((_repositorySerializer = Connections.Repository) != null) { if ((_definitionsSerializer = Connections.Definitions) != null) { UserProxy proxy; try { //Zuerst korrespondierenden Userproxy holen IRestriction r = RestrictionFactory.Eq(typeof(UserProxy), "_LoginName", _settings.Username); //IRestriction r = RestrictionFactory.Eq(typeof(UserProxy), "_LoginName", @"TestEditor"); proxy = _repositorySerializer.Connector.Load <UserProxy>(r); if (proxy == null) { _Log.Error("No User Proxy"); _operation.failure("Services_UserProfile_Error_NoProxy", ""); return(null); } if (string.IsNullOrEmpty(proxy.AgentURI)) { _Log.Error("Cannot create Profile, empty AgentURI"); #if !DEBUG _operation.failure("Services_UserProfile_Error_EmptyAgentURL", ""); return(null); #endif } newProfile = _mobileSerializer.CreateISerializableObject <UserProfile>(); newProfile.LoginName = _settings.Username; //newProfile.LoginName = @"TestEditor"; string agentName = null; using (var conn = _definitionsSerializer.CreateConnection()) { try { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = "SELECT [AgentName] FROM [" + _settings.CurrentConnection.TaxonNamesInitialCatalog + "].[dbo].[IBFagents] WHERE [AgentURI] = '" + proxy.AgentURI + "'"; _Log.DebugFormat("Select AgentName Command: [{0}]", cmd.CommandText); agentName = cmd.ExecuteScalar() as string; _Log.DebugFormat("AgentName: [{0}]", agentName); } finally { conn.Close(); } } newProfile.CombinedNameCache = (!string.IsNullOrEmpty(agentName)) ? agentName : proxy.CombinedNameCache; newProfile.HomeDB = _settings.CurrentConnection.InitialCatalog; newProfile.AgentURI = proxy.AgentURI; _mobileSerializer.Connector.Save(newProfile); MessengerInstance.Send <SyncStepFinished>(SyncState.ProfileChanged); } catch (Exception ex) { newProfile = null; //TODO _operation.failure("", ""); _Log.ErrorFormat("Error Creating Profile: {0}", ex); } } else { _Log.Error("Definitions N/A"); } } else { _Log.Error("Repository N/A"); } return(newProfile); }
public void loadCollectionDefinitions(AsyncOperationInstance progress) { progress.StatusDescription = "Services_Definitions_LoadingCollectionDefinitions"; var uOptions = _owner.Settings.getOptions(); //TODO var connectionProfile = uOptions.CurrentConnection; //TODO var projectID = _owner.Profiles.ProjectID; var repSerializer = _owner.Connections.Repository; var mobSerializer = _owner.Connections.MobileDB; ObjectSyncList transferList = new ObjectSyncList(); String sql = @"SELECT * FROM [" + connectionProfile.InitialCatalog + "].[dbo].[AnalysisProjectList] (" + projectID + ")"; IList <ISerializableObject> list = repSerializer.Connector.LoadList(typeof(Analysis), sql); transferList.addList(list); foreach (ISerializableObject iso in list) { Analysis ana = (Analysis)iso; IRestriction rana = RestrictionFactory.Eq(typeof(AnalysisResult), "_AnalysisID", ana.AnalysisID); IList <ISerializableObject> resultList = repSerializer.Connector.LoadList(typeof(AnalysisResult), rana); transferList.addList(resultList); } sql = @"SELECT AnalysisID,TaxonomicGroup,RowGUID FROM [" + connectionProfile.InitialCatalog + "].[dbo].[AnalysisTaxonomicGroupForProject] (" + projectID + ")"; IList <AnalysisTaxonomicGroup> atgList = new List <AnalysisTaxonomicGroup>(); IDbConnection connRepository = repSerializer.CreateConnection(); connRepository.Open(); IDbCommand com = connRepository.CreateCommand(); com.CommandText = sql; IDataReader reader = null; try { reader = com.ExecuteReader(); while (reader.Read()) { AnalysisTaxonomicGroup atg = new AnalysisTaxonomicGroup(); atg.AnalysisID = reader.GetInt32(0); atg.TaxonomicGroup = reader.GetString(1); atg.Rowguid = Guid.NewGuid(); atgList.Add(atg); } connRepository.Close(); } catch (Exception e) { connRepository.Close(); _Log.ErrorFormat("Error loading Collection Definitions: [{0}]", e); progress.failure("Services_Definitions_Error_MissingRights", ""); } foreach (AnalysisTaxonomicGroup atg in atgList) { foreach (ISerializableObject iso in list) { if (iso.GetType().Equals(typeof(Analysis))) { Analysis ana = (Analysis)iso; if (ana.AnalysisID == atg.AnalysisID) { transferList.addObject(atg); } } } } float progressPerType = 100f / _defTypes.Count; progress.IsProgressIndeterminate = false; foreach (Type t in _defTypes) { repSerializer.Progress = new ProgressInterval(progress, progressPerType, 1); transferList.Load(t, repSerializer); } transferList.initialize(LookupSynchronizationInformation.downloadDefinitionsList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields()); List <ISerializableObject> orderedObjects = transferList.orderedObjects; foreach (ISerializableObject iso in orderedObjects) { try { mobSerializer.Connector.InsertPlain(iso); } catch (Exception) { try { if (iso.GetType().Equals(typeof(AnalysisTaxonomicGroup))) { AnalysisTaxonomicGroup atg = (AnalysisTaxonomicGroup)iso; IRestriction r1 = RestrictionFactory.Eq(iso.GetType(), "_AnalysisID", atg.AnalysisID); IRestriction r2 = RestrictionFactory.Eq(iso.GetType(), "_TaxonomicGroup", atg.TaxonomicGroup); IRestriction r = RestrictionFactory.And().Add(r1).Add(r2); ISerializableObject isoStored = mobSerializer.Connector.Load(iso.GetType(), r); atg.Rowguid = isoStored.Rowguid; } else { IRestriction r = RestrictionFactory.Eq(iso.GetType(), "_guid", iso.Rowguid); ISerializableObject isoStored = mobSerializer.Connector.Load(iso.GetType(), r); } mobSerializer.Connector.UpdatePlain(iso); } catch (Exception ex) { _Log.ErrorFormat("Exception while transferring [{0}]: [{1}]", iso, ex); } } } progress.success(); }
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() { if (this._currentEvent != null) { try { //// Remove Collection Event Attributs, schon im Cascaden enthalten. //foreach (CollectionEventLocalisation ceLoc in DataFunctions.Instance.RetrieveLocalisationSystemForCollectionEvent(this._currentEvent)) //{ // if (ceLoc != null) // { // try // { // DataFunctions.Instance.Remove(ceLoc); // } // catch (DataFunctionsException ex) // { // throw ex; // } // } //} //foreach (CollectionEventProperty ceProp in DataFunctions.Instance.RetrievePropertyForCollectionEvent(this._currentEvent)) //{ // if (ceProp != null) // { // try // { // DataFunctions.Instance.Remove(ceProp); // } // catch (DataFunctionsException ex) // { // throw ex; // } // } //} // Remove all CollectionEventImages assigned to CollectionEvent IList <CollectionEventImage> ceImgList; IRestriction restrict = RestrictionFactory.Eq(typeof(CollectionEventImage), "_CollectionEventID", this._currentEvent.CollectionEventID); ceImgList = con.LoadList <CollectionEventImage>(restrict); foreach (CollectionEventImage ceImgTemp in ceImgList) { if (ceImgTemp != null) { try { DataFunctions.Instance.Remove(ceImgTemp); } catch (DataFunctionsException ex) { throw ex; } } } // Remove all Collection Specimen assigned to Collection Event //IList<CollectionSpecimen> csList; //restrict = RestrictionFactory.Eq(typeof(CollectionSpecimen), "_CollectionEventID", this._currentEvent.CollectionEventID); //csList = con.LoadList<CollectionSpecimen>(restrict); //foreach (CollectionSpecimen csTemp in csList) //{ // if (csTemp != null) // { // try // { // DataFunctions.Instance.Remove(csTemp); // } // catch (DataFunctionsException ex) // { // throw ex; // } // } //} try { con.Delete(this._currentEvent); } catch (Exception) { throw new DataFunctionsException("Object (CollectionEvent) couldn't be removed."); } // Change Current Event 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; } } }
private void connectMobile() { int i = 0; try { MobileDB = new MS_SqlCeSerializer(localDivDBPath); i++;//1 MobileDB.RegisterTypes(divMobiTypes); i++; MobileDB.RegisterType(typeof(UserProfile)); i++; MobileDB.Activate(); i++; //Prüfen ob ein UserProfile zum LoginNamen existiert. IList <UserProfile> profiles = new List <UserProfile>(); i++;//5 IRestriction r = RestrictionFactory.Eq(typeof(UserProfile), "_LoginName", OptionsAccess.RepositoryOptions.LastUsername); //IRestriction r = RestrictionFactory.Eq(typeof(UserProfile), "_LoginName", "TestEditor"); profiles = MobileDB.Connector.LoadList <UserProfile>(r); i++; if (profiles.Count > 0) { Profile = profiles[0]; } else { Profile = createProfile(); } i++;//7 //mobile Tax Serializer erzeugen try { MobileTaxa = new MS_SqlCeSerializer(localTaxDBPath); i++; MobileTaxa.RegisterType(typeof(TaxonNames)); MobileTaxa.RegisterType(typeof(PropertyNames)); i++;//9 } catch { MobileTaxa = null; } } catch (Exception mobileDBEx) { _Log.ErrorFormat("ConnectionError {0} {1}", i, mobileDBEx.Message != null ? mobileDBEx.Message : ""); MobileDB = null; Profile = null; } finally { i = 0; if (Profile != null) { State |= ConnectionState.ProfilePresent; State |= ConnectionState.ConnectedToMobile; i = 10; } else { State &= ~ConnectionState.ProfilePresent; State &= ~ConnectionState.ConnectedToMobile; i = 20; } if (MobileTaxa != null) { State |= ConnectionState.ConnectedToMobileTax; i = i + 100; } else { State &= ~ConnectionState.ConnectedToMobileTax; i = i + 200; } if (i != 110) { _Log.ErrorFormat("Final Result: {0}", i); } } }
private void loadCollectionDefinitionsWorker(IReportDetailedProgress progress) { ObjectSyncList transferList = new ObjectSyncList(); progress.advanceProgress(5); String sql = null; IList <ISerializableObject> list = null; progress.ProgressDescriptionID = 1160; try { sql = @"SELECT * FROM [" + OptionsAccess.RepositoryOptions.InitialCatalog + "].[dbo].[AnalysisProjectList] (" + ConnectionsAccess.Profile.ProjectID + ")"; list = ConnectionsAccess.RepositoryDB.Connector.LoadList(typeof(Analysis), sql); transferList.addList(list); foreach (ISerializableObject iso in list) { Analysis ana = (Analysis)iso; IRestriction rana = RestrictionFactory.Eq(typeof(AnalysisResult), "_AnalysisID", ana.AnalysisID); IList <ISerializableObject> resultList = ConnectionsAccess.RepositoryDB.Connector.LoadList(typeof(AnalysisResult), rana); transferList.addList(resultList); } } catch (Exception e) { MessageBox.Show(e.Message); _Log.ErrorFormat("Exception while updating AnalysisTaxonomicGroups: {0}", e);; } sql = @"SELECT AnalysisID,TaxonomicGroup,RowGUID FROM [" + OptionsAccess.RepositoryOptions.InitialCatalog + "].[dbo].[AnalysisTaxonomicGroupForProject] (" + ConnectionsAccess.Profile.ProjectID + ")"; IList <AnalysisTaxonomicGroup> atgList = new List <AnalysisTaxonomicGroup>(); IDbConnection connRepository = ConnectionsAccess.RepositoryDB.CreateConnection(); connRepository.Open(); IDbCommand com = connRepository.CreateCommand(); com.CommandText = sql; IDataReader reader = null; try { reader = com.ExecuteReader(); while (reader.Read()) { AnalysisTaxonomicGroup atg = new AnalysisTaxonomicGroup(); atg.AnalysisID = reader.GetInt32(0); atg.TaxonomicGroup = reader.GetString(1); atg.Rowguid = Guid.NewGuid(); atgList.Add(atg); } connRepository.Close(); } catch (Exception e) { MessageBox.Show(e.Message); _Log.ErrorFormat("Exception while updating AnalysisTaxonomicGroups: {0}", e);; connRepository.Close(); } foreach (AnalysisTaxonomicGroup atg in atgList) { foreach (ISerializableObject iso in list) { if (iso.GetType().Equals(typeof(Analysis))) { Analysis ana = (Analysis)iso; if (ana.AnalysisID == atg.AnalysisID) { transferList.addObject(atg); } } } } double progressPerType = 90d / _defTypes.Count; foreach (Type t in _defTypes) { transferList.Load(t, ConnectionsAccess.RepositoryDB); progress.advanceProgress(progressPerType); } transferList.initialize(LookupSynchronizationInformation.downloadDefinitionsList(), LookupSynchronizationInformation.getReflexiveReferences(), LookupSynchronizationInformation.getReflexiveIDFields()); List <ISerializableObject> orderedObjects = transferList.orderedObjects; progress.ProgressDescriptionID = 1161; foreach (ISerializableObject iso in orderedObjects) { try { ConnectionsAccess.MobileDB.Connector.InsertPlain(iso); } catch (Exception) { try { if (iso.GetType().Equals(typeof(AnalysisTaxonomicGroup))) { AnalysisTaxonomicGroup atg = (AnalysisTaxonomicGroup)iso; IRestriction r1 = RestrictionFactory.Eq(iso.GetType(), "_AnalysisID", atg.AnalysisID); IRestriction r2 = RestrictionFactory.Eq(iso.GetType(), "_TaxonomicGroup", atg.TaxonomicGroup); IRestriction r = RestrictionFactory.And().Add(r1).Add(r2); ISerializableObject isoStored = ConnectionsAccess.MobileDB.Connector.Load(iso.GetType(), r); atg.Rowguid = isoStored.Rowguid; } else { IRestriction r = RestrictionFactory.Eq(iso.GetType(), "_guid", iso.Rowguid); ISerializableObject isoStored = ConnectionsAccess.MobileDB.Connector.Load(iso.GetType(), r); } ConnectionsAccess.MobileDB.Connector.UpdatePlain(iso); } catch (Exception ex) { _Log.ErrorFormat("Exception while transferring [{0}]: [{1}]", iso, ex); } } } }
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; } } }