Exemple #1
0
        public static Framework.Data.Geocache Geocache(Framework.Interfaces.ICore core, LiveV6.Geocache gc)
        {
            Framework.Data.Geocache result = null;
            if (gc != null)
            {
                Framework.Data.Geocache tmp = DataAccess.GetGeocache(core.Geocaches, gc.Code);
                result = new Framework.Data.Geocache();
                if (tmp != null)
                {
                    result.UpdateFrom(tmp, null);
                }
                result.Code      = gc.Code;
                result.ID        = gc.ID.ToString();
                result.Archived  = gc.Archived ?? false;
                result.Available = gc.Available ?? true;
                result.Container = DataAccess.GetGeocacheContainer(core.GeocacheContainers, (int)gc.ContainerType.ContainerTypeId);
                if (gc.Attributes != null)
                {
                    List <int> attr = new List <int>();
                    foreach (LiveV6.Attribute a in gc.Attributes)
                    {
                        attr.Add(a.IsOn ? a.AttributeTypeID : -1 * a.AttributeTypeID);
                    }
                    result.AttributeIds = attr;
                }
                if (gc.Latitude != null)
                {
                    result.Lat = (double)gc.Latitude;
                }
                if (gc.Longitude != null)
                {
                    result.Lon = (double)gc.Longitude;
                }
                if (gc.Country != null)
                {
                    result.Country = gc.Country;
                }
                result.DataFromDate = DateTime.Now;
                result.Difficulty   = gc.Difficulty;
                result.Terrain      = gc.Terrain;
                result.Title        = gc.Name;
                if (gc.FavoritePoints != null)
                {
                    result.Favorites = (int)gc.FavoritePoints;
                }
                result.GeocacheType = DataAccess.GetGeocacheType(core.GeocacheTypes, (int)gc.CacheType.GeocacheTypeId);
                if (gc.LongDescription != null)
                {
                    result.LongDescription       = gc.LongDescription;
                    result.LongDescriptionInHtml = gc.LongDescriptionIsHtml;
                }
                if (gc.EncodedHints != null)
                {
                    result.EncodedHints = gc.EncodedHints;
                }
                result.MemberOnly = gc.IsPremium ?? false;
                result.Owner      = gc.Owner.UserName;
                if (gc.Owner.Id != null)
                {
                    result.OwnerId = gc.Owner.Id.ToString();
                }
                result.PlacedBy      = gc.PlacedBy;
                result.PublishedTime = gc.UTCPlaceDate;
                if (result.ShortDescription != null)
                {
                    result.ShortDescription       = gc.ShortDescription;
                    result.ShortDescriptionInHtml = gc.ShortDescriptionIsHtml;
                }
                if (gc.State == "None")
                {
                    result.State = "";
                }
                else
                {
                    result.State = gc.State;
                }
                result.PersonaleNote = gc.GeocacheNote;
                if (gc.HasbeenFoundbyUser != null)
                {
                    result.Found = (bool)gc.HasbeenFoundbyUser;
                }
                result.Url           = gc.Url;
                result.PersonaleNote = gc.GeocacheNote ?? "";

                Calculus.SetDistanceAndAngleGeocacheFromLocation(result, core.CenterLocation);
            }
            return(result);
        }
Exemple #2
0
        public static Core.Data.Geocache ImportGeocache(Core.Storage.Database db, LiveV6.Geocache gc)
        {
            Core.Data.Geocache result = null;
            if (gc != null)
            {
                result = db.GeocacheCollection.GetGeocache(gc.Code);

                Core.Data.IGeocacheData gcData;
                if (result == null)
                {
                    gcData      = new Core.Data.GeocacheData();
                    gcData.Code = gc.Code;
                }
                else
                {
                    gcData = result;
                }

                gcData.Archived  = gc.Archived ?? false;
                gcData.Available = gc.Available ?? true;

                if (result == null || !result.Locked)
                {
                    gcData.Container = Utils.DataAccess.GetGeocacheContainer((int)gc.ContainerType.ContainerTypeId);
                    if (gc.Attributes != null)
                    {
                        List <int> attr = new List <int>();
                        foreach (LiveV6.Attribute a in gc.Attributes)
                        {
                            attr.Add(a.IsOn ? a.AttributeTypeID : -1 * a.AttributeTypeID);
                        }
                        gcData.AttributeIds = attr;
                    }
                    if (gc.Latitude != null)
                    {
                        gcData.Lat = (double)gc.Latitude;
                    }
                    if (gc.Longitude != null)
                    {
                        gcData.Lon = (double)gc.Longitude;
                    }
                    if (gc.Country != null)
                    {
                        gcData.Country = gc.Country;
                    }
                    gcData.DataFromDate = DateTime.Now;
                    gcData.Difficulty   = gc.Difficulty;
                    gcData.Terrain      = gc.Terrain;
                    gcData.Name         = gc.Name;
                    if (gc.FavoritePoints != null)
                    {
                        gcData.Favorites = (int)gc.FavoritePoints;
                    }
                    gcData.GeocacheType = Utils.DataAccess.GetGeocacheType((int)gc.CacheType.GeocacheTypeId);
                    if (gc.LongDescription != null)
                    {
                        gcData.LongDescription       = gc.LongDescription;
                        gcData.LongDescriptionInHtml = gc.LongDescriptionIsHtml;
                    }
                    if (gc.EncodedHints != null)
                    {
                        gcData.EncodedHints = gc.EncodedHints;
                    }
                    gcData.MemberOnly = gc.IsPremium ?? false;
                    gcData.Owner      = gc.Owner.UserName;
                    if (gc.Owner.Id != null)
                    {
                        gcData.OwnerId = gc.Owner.Id.ToString();
                    }
                    gcData.PlacedBy      = gc.PlacedBy;
                    gcData.PublishedTime = gc.UTCPlaceDate;
                    if (gcData.ShortDescription != null)
                    {
                        gcData.ShortDescription       = gc.ShortDescription;
                        gcData.ShortDescriptionInHtml = gc.ShortDescriptionIsHtml;
                    }
                    if (gc.State == "None")
                    {
                        gcData.State = "";
                    }
                    else
                    {
                        gcData.State = gc.State;
                    }
                    gcData.PersonalNote = gc.GeocacheNote;
                    if (gc.HasbeenFoundbyUser != null)
                    {
                        gcData.Found = (bool)gc.HasbeenFoundbyUser;
                    }
                    gcData.Url          = gc.Url;
                    gcData.PersonalNote = gc.GeocacheNote ?? "";

                    if (gcData is Core.Data.GeocacheData)
                    {
                        if (Utils.DataAccess.AddGeocache(db, gcData as Core.Data.GeocacheData))
                        {
                            result = db.GeocacheCollection.GetGeocache(gcData.Code);
                        }
                    }
                    if (result != null)
                    {
                        Utils.Calculus.SetDistanceAndAngleGeocacheFromLocation(result, Core.ApplicationData.Instance.CenterLocation);

                        ImportLogs(db, gc.GeocacheLogs);
                        ImportWaypoints(db, gc.AdditionalWaypoints);
                        ImportUserWaypoints(db, gc.UserWaypoints, gc.Code);
                        ImportGeocacheImages(db, gc.Images, gc.Code);
                    }
                }
            }
            return(result);
        }