示例#1
0
            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);
                }
            }
示例#2
0
        public List <ListViewItem> searchIUResults(Dictionary <String, String> searchStrings, bool strategyAND)
        {
            List <ListViewItem> items = new List <ListViewItem>();

            try
            {
                LogicalRestriction restrict = null;

                if (strategyAND)
                {
                    restrict = RestrictionFactory.And();
                }
                else
                {
                    restrict = RestrictionFactory.Or();
                }

                foreach (String key in searchStrings.Keys)
                {
                    if (key != null)
                    {
                        IRestriction r = RestrictionFactory.Like(typeof(IdentificationUnit), key, searchStrings[key]);
                        restrict.Add(r);
                    }
                }

                foreach (IdentificationUnit iu in con.LoadList <IdentificationUnit>(restrict))
                {
                    if (iu != null)
                    {
                        ListViewItem item = new ListViewItem();
                        item.Text = iu.IdentificationUnitID.ToString();
                        item.SubItems.Add(iu.LastIdentificationCache);
                        item.SubItems.Add(iu.TaxonomicGroup);
                        item.SubItems.Add(iu.UnitIdentifier);
                        item.Tag = iu.IdentificationUnitID;

                        items.Add(item);
                    }
                }
            }
            catch (Exception)
            {
                items.Clear();
            }

            return(items);
        }
示例#3
0
        public IList <ListViewItem> searchEventResults(Dictionary <String, String> searchStrings, bool strategyAND)
        {
            List <ListViewItem> items = new List <ListViewItem>();

            try
            {
                LogicalRestriction restrict = null;

                if (strategyAND)
                {
                    restrict = RestrictionFactory.And();
                }
                else
                {
                    restrict = RestrictionFactory.Or();
                }

                foreach (String key in searchStrings.Keys)
                {
                    if (key != null)
                    {
                        IRestriction r = RestrictionFactory.Like(typeof(CollectionEvent), key, searchStrings[key]);
                        restrict.Add(r);
                    }
                }

                foreach (CollectionEvent ce in con.LoadList <CollectionEvent>(restrict))
                {
                    if (ce != null)
                    {
                        ListViewItem item = new ListViewItem();
                        item.Text = ce.CollectionEventID.ToString();
                        item.SubItems.Add(ce.CollectorsEventNumber);
                        item.SubItems.Add(ce.CollectionDate.ToShortDateString());
                        item.Tag = ce.CollectionEventID;

                        items.Add(item);
                    }
                }
            }
            catch (Exception) {
                items.Clear();
            }

            return(items);
        }
示例#4
0
        public List <ListViewItem> searchSpecimenResults(Dictionary <String, String> searchStrings, bool strategyAND)
        {
            List <ListViewItem> items = new List <ListViewItem>();

            try
            {
                LogicalRestriction restrict = null;

                if (strategyAND)
                {
                    restrict = RestrictionFactory.And();
                }
                else
                {
                    restrict = RestrictionFactory.Or();
                }

                foreach (String key in searchStrings.Keys)
                {
                    if (key != null)
                    {
                        IRestriction r = RestrictionFactory.Like(typeof(CollectionSpecimen), key, searchStrings[key]);
                        restrict.Add(r);
                    }
                }

                foreach (CollectionSpecimen cs in con.LoadList <CollectionSpecimen>(restrict))
                {
                    if (cs != null)
                    {
                        ListViewItem item = new ListViewItem();
                        item.Text = cs.CollectionSpecimenID.ToString();
                        item.Tag  = cs.CollectionSpecimenID;

                        items.Add(item);
                    }
                }
            }
            catch (Exception)
            {
                items.Clear();
            }

            return(items);
        }
示例#5
0
            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);
                }
            }
示例#6
0
        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);
            }
        }
            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();
            }
示例#8
0
        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);
                    }
                }
            }
        }
示例#9
0
        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();
        }