コード例 #1
0
        private static async Task <SavedGradeScale> LoadSavedGradeScale(IFile file)
        {
            try
            {
                GradeScale[] scales;

                using (Stream s = await file.OpenAsync(StorageEverywhere.FileAccess.Read))
                {
                    scales = SERIALIZER.ReadObject(s) as GradeScale[];
                }

                if (scales == null)
                {
                    return(null);
                }

                return(new SavedGradeScale()
                {
                    Name = file.Name,
                    GradeScales = scales
                });
            }

            catch (Exception ex)
            {
                TelemetryExtension.Current?.TrackException(ex);

                return(null);
            }
        }
コード例 #2
0
        public void CreateNewEvent(int?seriesID)
        {
            CollectionEvent ce = SERIALIZER.CreateISerializableObject <CollectionEvent>();

            // EventSeries
            ce.SeriesID = seriesID;
            if (seriesID != null)
            {
                try
                {
                    SERIALIZER.ConnectOneToMany(EventSeriess.Instance.Current, ce);
                }
                catch (ConnectionCorruptedException ex)
                {
                    throw ex;
                }
            }
            if (this.LastCollectorsEventNumber != -1)
            {
                ce.CollectorsEventNumber = (this.LastCollectorsEventNumber + 1).ToString();
            }
            try
            {
                con.Save(ce);
                this._currentEvent = this._ceIterator.Last();
            }
            catch (Exception ex)
            {
                throw new DataFunctionsException("New CollectionEvent couldn't be saved. (" + ex.Message + ")");
            }
        }
コード例 #3
0
        private UserProfiles()
        {
            IRestriction restrict = RestrictionFactory.TypeRestriction(typeof(UserProfile));

            _userList            = con.LoadList <UserProfile>(restrict);
            this._currentProfile = SERIALIZER.CreateISerializableObject <UserProfile>();
        }
コード例 #4
0
        /// <summary>
        /// Throws exception if saving failed
        /// </summary>
        /// <param name="name"></param>
        /// <param name="scales"></param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task SaveGradeScale(string name, GradeScale[] scales)
        {
            IFile file = await _savedGradeScalesFolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);

            using (Stream s = await file.OpenAsync(StorageEverywhere.FileAccess.ReadAndWrite))
            {
                SERIALIZER.WriteObject(s, scales);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public CollectionEventSeries CreateNewEventSeries()
 {
     try
     {
         CollectionEventSeries ceSeries = SERIALIZER.CreateISerializableObject <CollectionEventSeries>();
         con.Save(ceSeries);
         this._currentSeries = this._ceIterator.Last();
         return(ceSeries);
     }
     catch (Exception ex)
     {
         throw new DataFunctionsException("New CollectionEventSeries couldn't be created. (" + ex.Message + ")");
     }
 }
コード例 #7
0
 public IdentificationUnit CreateTopLevelIdentificationUnit(String lastIdentificationCache)
 {
     try
     {
         IdentificationUnit iu = SERIALIZER.CreateISerializableObject <IdentificationUnit>();
         iu.CollectionSpecimenID    = this._collectionSpecimen.CollectionSpecimenID;
         iu.LastIdentificationCache = lastIdentificationCache;
         SERIALIZER.ConnectOneToMany(this._collectionSpecimen, iu);
         SERIALIZER.Connector.Save(iu);
         this._currentIdentificationUnit = this._identificationUnitIterator.Last();
         return(iu);
     }
     catch (Exception)
     {
         throw new DataFunctionsException("New TopLevel Identification Unit couldn't be created");
     }
 }
コード例 #8
0
        public UserProfile CreateUserProfile(string loginName)
        {
            UserProfile up = SERIALIZER.CreateISerializableObject <UserProfile>();

            up.LoginName = loginName;

            try
            {
                con.Save(up);
            }
            catch (Exception ex)
            {
                throw new UserProfileCorruptedException("New User Profile '" + loginName + "' couldn't be created. (" + ex.Message + ")");
            }

            return(up);
        }
コード例 #9
0
        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 + ")");
            }
        }