本文整理汇总了C#中Utils.ProgressBlock.Update方法的典型用法代码示例。如果您正苦于以下问题:C# Utils.ProgressBlock.Update方法的具体用法?C# Utils.ProgressBlock.Update怎么用?C# Utils.ProgressBlock.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utils.ProgressBlock
的用法示例。
在下文中一共展示了Utils.ProgressBlock.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOwnTrackables
public void AddOwnTrackables(TrackableGroup grp)
{
bool canceled = false;
using (Utils.ProgressBlock progr = new Utils.ProgressBlock("GetTrackableData", "GetTrackableData", 1, 0, true))
using (var api = new LiveAPI.GeocachingLiveV6())
{
List<string> trkCodes = new List<string>();
var req = new LiveAPI.LiveV6.GetTrackablesByOwnerRequest();
req.AccessToken = api.Token;
req.TrackableLogsCount = 0;
req.StartIndex = 0;
req.MaxPerPage = Core.Settings.Default.LiveAPIGetOwnedTrackablesBatchSize;
int total = 0;
while (true)
{
var resp = api.Client.GetOwnedTrackables(req);
if (resp.Status.StatusCode == 0)
{
if (resp.Trackables != null)
{
foreach (var t in resp.Trackables)
{
trkCodes.Add(t.Code);
Core.Settings.Default.AddUpdateTrackable(grp, GetTrackableItemFromLiveAPI(t));
total++;
}
if (!progr.Update("GetTrackableData", total, 2 * total))
{
canceled = true;
break;
}
}
if (resp.Trackables.Count() < req.MaxPerPage)
{
break;
}
else
{
req.StartIndex = total;
System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetOwnedTrackables);
}
}
else
{
Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage);
break;
}
}
if (!canceled)
{
progr.Update("GetTrackableData", total, total);
AddUpdateTrackables(grp, trkCodes);
}
}
}
示例2: DeleteImagesFromFolder
public async Task DeleteImagesFromFolder(List<Core.Data.Geocache> gcList, string folder)
{
await Task.Run(() =>
{
try
{
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("DeletingImages", "DeletingImages", gcList.Count, 0, true))
{
string imgFolder;
string checkFolder = Path.Combine(folder, "GeocachePhotos");
if (Directory.Exists(checkFolder))
{
imgFolder = checkFolder;
}
else
{
imgFolder = folder;
}
int index = 0;
foreach (var gc in gcList)
{
string cacheFolder = Path.Combine(imgFolder, gc.Code[gc.Code.Length - 1].ToString());
if (Directory.Exists(cacheFolder))
{
cacheFolder = Path.Combine(cacheFolder, gc.Code[gc.Code.Length - 2].ToString());
if (Directory.Exists(cacheFolder))
{
cacheFolder = Path.Combine(cacheFolder, gc.Code);
if (Directory.Exists(cacheFolder))
{
Directory.Delete(cacheFolder, true);
}
}
}
index++;
if (DateTime.Now >= nextUpdate)
{
if (!progress.Update("DeletingImages", gcList.Count, index))
{
break;
}
nextUpdate = DateTime.Now.AddSeconds(1);
}
}
}
}
catch (Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(this, e);
}
});
}
示例3: LogGeocachesAsync
public async Task<List<LogInfo>> LogGeocachesAsync(List<LogInfo> logInfos)
{
List<LogInfo> result = new List<LogInfo>();
Utils.DataUpdater upd = null;
if (Core.ApplicationData.Instance.ActiveDatabase != null)
{
upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase);
}
using (Utils.ProgressBlock prog = new Utils.ProgressBlock("LogGeocache", "Logging", logInfos.Count, 0, true))
{
using (var api = new LiveAPI.GeocachingLiveV6())
{
foreach (LogInfo li in logInfos)
{
int index = 0;
List<LiveAPI.LiveV6.Trackable> dropTbs = null;
List<string> retrieveTbs = null;
//todo: check if trackable dialog is needed
//fetch in background
bool ok = false;
await Task.Run(() =>
{
if (index > 0 && dropTbs == null && retrieveTbs == null)
{
System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayCreateFieldNoteAndPublish);
}
ok = LogGeocache(api, li, dropTbs, retrieveTbs);
});
if (ok)
{
result.Add(li);
index++;
if (!prog.Update("Logging", logInfos.Count, index))
{
break;
}
}
else
{
break;
}
}
}
}
if (upd!=null)
{
upd.Dispose();
upd = null;
}
return result;
}
示例4: ExportToFile
public static void ExportToFile(string filename, List<Core.Data.Geocache> gcList)
{
try
{
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock("ExportingiGeoKnife", "CreatingFile", 1, 0, true))
{
System.Collections.Hashtable logTypes = new System.Collections.Hashtable();
logTypes.Add(2, "Found it");
logTypes.Add(3, "Didn't find it");
logTypes.Add(4, "Write note");
logTypes.Add(5, "Archive");
logTypes.Add(7, "Needs Archived");
logTypes.Add(9, "Will Attend");
logTypes.Add(10, "Attended");
logTypes.Add(11, "Webcam Photo Taken");
logTypes.Add(12, "Unarchive");
logTypes.Add(22, "Temporarily Disable Listing");
logTypes.Add(23, "Enable Listing");
logTypes.Add(24, "Publish Listing");
logTypes.Add(25, "Retract Listing");
logTypes.Add(45, "Needs Maintenance");
logTypes.Add(46, "Owner Maintenance");
logTypes.Add(47, "Update Coordinates");
logTypes.Add(68, "Post Reviewer Note");
logTypes.Add(74, "Announcement");
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
Utils.ResourceHelper.SaveToFile("/iGeoKnife/sqlite.db3", filename, true);
using (SqliteConnection dbcon = new SqliteConnection(string.Format("data source=file:{0}", filename)))
{
dbcon.Open();
DbParameter par;
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ExportingiGeoKnife", "SavingGeocaches", gcList.Count, 0, true))
{
using (SqliteCommand cmd = new SqliteCommand("", dbcon))
using (SqliteCommand cmd2 = new SqliteCommand("", dbcon))
using (SqliteCommand cmd3 = new SqliteCommand("", dbcon))
using (SqliteCommand cmd4 = new SqliteCommand("", dbcon))
using (SqliteCommand cmd5 = new SqliteCommand("", dbcon))
using (SqliteCommand cmd6 = new SqliteCommand("", dbcon))
using (SqliteCommand cmd7 = new SqliteCommand("", dbcon))
using (SqliteCommand cmd8 = new SqliteCommand("", dbcon))
{
cmd.CommandText = "drop index CachesSmart";
cmd.ExecuteNonQuery();
cmd.CommandText = "insert into Caches (Code, Name, PlacedBy, Archived, CacheId, CacheType, Container, Country, Difficulty, Found, HasCorrected, HasUserNote, Latitude, LongHtm, Longitude, OwnerName, PlacedDate, ShortHtm, State, Terrain, UserFlag, IsOwner, LatOriginal, LonOriginal, Status, GcNote, IsPremium, FavPoints) values (@Code, @Name, @PlacedBy, @Archived, @CacheId, @CacheType, @Container, @Country, @Difficulty, @Found, @HasCorrected, @HasUserNote, @Latitude, @LongHtm, @Longitude, @OwnerName, @PlacedDate, @ShortHtm, @State, @Terrain, @UserFlag, @IsOwner, @LatOriginal, @LonOriginal, @Status, @GcNote, @IsPremium, @FavPoints)";
cmd2.CommandText = "insert into CacheMemo (Code, LongDescription, ShortDescription, Url, Hints, UserNote) values (@Code, @LongDescription, @ShortDescription, @Url, @Hints, @UserNote)";
cmd3.CommandText = "insert into Attributes (aCode, aId, aInc) values (@aCode, @aId, @aInc)";
cmd4.CommandText = "insert into LogMemo (lParent, lLogId, lText) values (@lParent, @lLogId, @lText)";
cmd5.CommandText = "insert into Logs (lParent, lLogId, lType, lBy, lDate, lLat, lLon, lEncoded, lownerid, lHasHtml, lIsowner, lTime) values (@lParent, @lLogId, @lType, @lBy, @lDate, @lLat, @lLon, @lEncoded, @lownerid, @lHasHtml, @lIsowner, @lTime)";
cmd6.CommandText = "insert into WayMemo (cParent, cCode, cComment, cUrl) values (@cParent, @cCode, @cComment, @cUrl)";
cmd7.CommandText = "insert into Waypoints (cParent, cCode, cPrefix, cName, cType, cLat, cLon, cByuser, cDate, cFlag, sB1) values (@cParent, @cCode, @cPrefix, @cName, @cType, @cLat, @cLon, @cByuser, @cDate, @cFlag, @sB1)";
cmd8.CommandText = "insert into Corrected (kCode, kBeforeLat, kBeforeLon, kAfterLat, kAfterLon) values (@kCode, @kBeforeLat, @kBeforeLon, @kAfterLat, @kAfterLon)";
par = cmd8.CreateParameter();
par.ParameterName = "@kCode";
par.DbType = DbType.String;
cmd8.Parameters.Add(par);
par = cmd8.CreateParameter();
par.ParameterName = "@kBeforeLat";
par.DbType = DbType.String;
cmd8.Parameters.Add(par);
par = cmd8.CreateParameter();
par.ParameterName = "@kBeforeLon";
par.DbType = DbType.String;
cmd8.Parameters.Add(par);
par = cmd8.CreateParameter();
par.ParameterName = "@kAfterLat";
par.DbType = DbType.String;
cmd8.Parameters.Add(par);
par = cmd8.CreateParameter();
par.ParameterName = "@kAfterLon";
par.DbType = DbType.String;
cmd8.Parameters.Add(par);
par = cmd7.CreateParameter();
par.ParameterName = "@cParent";
par.DbType = DbType.String;
cmd7.Parameters.Add(par);
par = cmd7.CreateParameter();
par.ParameterName = "@cCode";
par.DbType = DbType.String;
cmd7.Parameters.Add(par);
par = cmd7.CreateParameter();
par.ParameterName = "@cPrefix";
par.DbType = DbType.String;
cmd7.Parameters.Add(par);
par = cmd7.CreateParameter();
par.ParameterName = "@cName";
par.DbType = DbType.String;
cmd7.Parameters.Add(par);
par = cmd7.CreateParameter();
//.........这里部分代码省略.........
示例5: ExportToGDAK
public async Task ExportToGDAK(List<Core.Data.Geocache> gcList, string targetFolder, int maxLogCount, bool offlineImages, int maxInImgFolder)
{
string filename = Path.Combine(targetFolder, "sqlite.db3");
await Task.Run(() =>
{
try
{
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock("ExportingGDAK", "CreatingFile", 1, 0, true))
{
System.Collections.Hashtable logTypes = new System.Collections.Hashtable();
logTypes.Add(2, "Found it");
logTypes.Add(3, "Didn't find it");
logTypes.Add(4, "Write note");
logTypes.Add(5, "Archive");
logTypes.Add(7, "Needs Archived");
logTypes.Add(9, "Will Attend");
logTypes.Add(10, "Attended");
logTypes.Add(11, "Webcam Photo Taken");
logTypes.Add(12, "Unarchive");
logTypes.Add(22, "Temporarily Disable Listing");
logTypes.Add(23, "Enable Listing");
logTypes.Add(24, "Publish Listing");
logTypes.Add(25, "Retract Listing");
logTypes.Add(45, "Needs Maintenance");
logTypes.Add(46, "Owner Maintenance");
logTypes.Add(47, "Update Coordinates");
logTypes.Add(68, "Post Reviewer Note");
logTypes.Add(74, "Announcement");
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
SqliteConnection dbconFiles = null;
string basePath = null;
int imgFolderIndex = 0;
int imgInFolderCount = 0;
if (Core.Settings.Default.GDAKExportOfflineImages)
{
basePath = System.IO.Path.Combine(targetFolder, "GrabbedImages");
if (!System.IO.Directory.Exists(basePath))
{
System.IO.Directory.CreateDirectory(basePath);
}
if (Core.Settings.Default.GDAKMaxImagesInFolder > 0)
{
string imgSubFolder = System.IO.Path.Combine(basePath, string.Format("batch{0}", imgFolderIndex));
while (System.IO.Directory.Exists(imgSubFolder))
{
imgFolderIndex++;
imgSubFolder = System.IO.Path.Combine(basePath, string.Format("batch{0}", imgFolderIndex));
}
}
dbconFiles = new SqliteConnection(string.Format("data source=file:{0}", System.IO.Path.Combine(basePath, "files.db3")));
dbconFiles.Open();
using (SqliteCommand cmd = new SqliteCommand("", dbconFiles))
{
cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='fdone'";
object o = cmd.ExecuteScalar();
if (o == null || o.GetType() == typeof(DBNull))
{
cmd.CommandText = "CREATE TABLE fdone (dlink text)";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE INDEX ifdone on fdone (dlink)";
cmd.ExecuteNonQuery();
}
cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='files'";
o = cmd.ExecuteScalar();
if (o == null || o.GetType() == typeof(DBNull))
{
cmd.CommandText = "CREATE TABLE files (Link text collate nocase, Fname text collate nocase, Found integer)";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE INDEX ilink on files (Link)";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE INDEX ifname on files (Fname)";
cmd.ExecuteNonQuery();
}
cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' AND name='purge'";
o = cmd.ExecuteScalar();
if (o == null || o.GetType() == typeof(DBNull))
{
cmd.CommandText = "CREATE TABLE purge (pfile text)";
cmd.ExecuteNonQuery();
}
}
}
using (SqliteConnection dbcon = new SqliteConnection(string.Format("data source=file:{0}", filename)))
{
dbcon.Open();
using (SqliteCommand cmd = new SqliteCommand("", dbcon))
{
foreach (string s in SQLCREATEDBTABLES)
{
cmd.CommandText = s;
cmd.ExecuteNonQuery();
}
foreach (string s in SQLCREATEDBINDEXES)
//.........这里部分代码省略.........
示例6: ImportGeocacheStatus
public static void ImportGeocacheStatus(Core.Storage.Database db, List<string> gcCodes)
{
try
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("UpdatingGeocaches", "UpdatingGeocaches", gcCodes.Count, 0, true))
{
int totalcount = gcCodes.Count;
using (var client = new GeocachingLiveV6())
{
int index = 0;
while (gcCodes.Count > 0)
{
var req = new LiveV6.GetGeocacheStatusRequest();
req.AccessToken = client.Token;
req.CacheCodes = (from a in gcCodes select a).Take(Core.Settings.Default.LiveAPIGetGeocacheStatusBatchSize).ToArray();
index += req.CacheCodes.Length;
gcCodes.RemoveRange(0, req.CacheCodes.Length);
var resp = client.Client.GetGeocacheStatus(req);
if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null)
{
foreach (var gs in resp.GeocacheStatuses)
{
Core.Data.Geocache gc = db.GeocacheCollection.GetGeocache(gs.CacheCode);
if (gc != null)
{
gc.DataFromDate = DateTime.Now;
gc.Archived = gs.Archived;
gc.Available = gs.Available;
if (!gc.Locked)
{
gc.Name = gs.CacheName;
}
gc.MemberOnly = gs.Premium;
if (Core.Settings.Default.LiveAPIDeselectAfterUpdate)
{
gc.Selected = false;
}
}
}
}
else
{
Core.ApplicationData.Instance.Logger.AddLog(new Import(), new Exception(resp.Status.StatusMessage));
break;
}
if (!progress.Update("UpdatingGeocaches", totalcount, index))
{
break;
}
if (gcCodes.Count > 0)
{
System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetGeocacheStatus);
}
}
}
}
}
catch (Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(new Import(), e);
}
}
示例7: ImportGeocacheImages
public static void ImportGeocacheImages(Core.Storage.Database db, List<Core.Data.Geocache> gcList)
{
try
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("UpdatingGeocaches", "UpdatingGeocache", gcList.Count, 0, true))
{
int totalcount = gcList.Count;
using (LiveAPI.GeocachingLiveV6 client = new LiveAPI.GeocachingLiveV6())
{
int index = 0;
while (gcList.Count > 0)
{
if (index > 0)
{
Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetImagesForGeocache);
}
var resp = client.Client.GetImagesForGeocache(client.Token, gcList[0].Code);
if (resp.Status.StatusCode == 0)
{
if (resp.Images != null)
{
List<string> ids = new List<string>();
foreach (var img in resp.Images)
{
if (img.Url.IndexOf("/cache/log/") < 0)
{
Core.Data.GeocacheImage gcImg = ImportGeocacheImage(db, img, gcList[0].Code);
if (gcImg != null)
{
ids.Add(gcImg.ID);
}
}
}
List<Core.Data.GeocacheImage> allImages = Utils.DataAccess.GetGeocacheImages(db, gcList[0].Code);
foreach (Core.Data.GeocacheImage gim in allImages)
{
if (!ids.Contains(gim.ID))
{
gim.DeleteRecord();
db.GeocacheImageCollection.Remove(gim);
}
}
}
if (Core.Settings.Default.LiveAPIDeselectAfterUpdate)
{
gcList[0].Selected = false;
}
index++;
if (!progress.Update("UpdatingGeocache", totalcount, index))
{
break;
}
gcList.RemoveAt(0);
}
else
{
Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage);
break;
}
}
}
}
}
catch (Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(new Import(), e);
}
}
示例8: ImportFavorites
public void ImportFavorites(Core.Storage.Database db)
{
try
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("GetFavoritesFromGlobalcaching", "DownloadingData", 1, 0))
{
using (System.Net.WebClient wc = new System.Net.WebClient())
{
string doc = wc.DownloadString(string.Format("http://www.globalcaching.eu/Service/CacheFavorites.aspx?token={0}", System.Web.HttpUtility.UrlEncode(Core.Settings.Default.LiveAPIToken ?? "")));
if (doc != null)
{
string[] lines = doc.Replace("\r", "").Split(new char[] { '\n' });
progress.Update("SavingGeocaches", lines.Length, 0);
Core.Data.Geocache gc;
char[] sep = new char[] { ',' };
string[] parts;
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
int index = 0;
foreach (string s in lines)
{
parts = s.Split(sep);
if (parts.Length > 0)
{
gc = db.GeocacheCollection.GetGeocache(parts[0]);
if (gc != null)
{
gc.Favorites = int.Parse(parts[1]);
}
}
index++;
if (DateTime.Now >= nextUpdate)
{
progress.Update("SavingGeocaches", lines.Length, index);
nextUpdate = DateTime.Now.AddSeconds(1);
}
}
}
}
}
}
catch (Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(this, e);
}
}
示例9: ImportGeocaches
public static void ImportGeocaches(Core.Storage.Database db, LiveV6.SearchForGeocachesRequest req, int max)
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingGeocaches", "ImportingGeocaches", max, 0, true))
{
try
{
using (GeocachingLiveV6 client = new GeocachingLiveV6())
{
req.AccessToken = client.Token;
var resp = client.Client.SearchForGeocaches(req);
if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
{
ImportGeocaches(db, resp.Geocaches);
if (resp.Geocaches.Count() >= req.MaxPerPage && req.MaxPerPage < max)
{
if (progress.Update("ImportingGeocaches", max, resp.Geocaches.Count()))
{
var mreq = new LiveV6.GetMoreGeocachesRequest();
mreq.AccessToken = req.AccessToken;
mreq.GeocacheLogCount = req.GeocacheLogCount;
mreq.MaxPerPage = (int)Math.Min(req.MaxPerPage, max - resp.Geocaches.Count());
mreq.StartIndex = resp.Geocaches.Count();
mreq.TrackableLogCount = req.TrackableLogCount;
mreq.IsLite = req.IsLite;
mreq.GeocacheLogCount = req.GeocacheLogCount;
while (resp.Status.StatusCode == 0 && resp.Geocaches != null && resp.Geocaches.Count() >= req.MaxPerPage)
{
resp = client.Client.GetMoreGeocaches(mreq);
if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
{
ImportGeocaches(db, resp.Geocaches);
if (!progress.Update("ImportingGeocaches", max, mreq.StartIndex + resp.Geocaches.Count()))
{
break;
}
mreq.StartIndex += resp.Geocaches.Count();
mreq.MaxPerPage = (int)Math.Min(req.MaxPerPage, max - mreq.StartIndex);
if (mreq.StartIndex >= max - 1)
{
break;
}
}
else
{
Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage);
}
}
}
}
}
else
{
Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage);
}
}
}
catch (Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(new Import(), e);
}
}
}
示例10: GetLogsOfUser
public List<LiveAPI.LiveV6.GeocacheLog> GetLogsOfUser(string userName, List<Core.Data.LogType> logTypes)
{
List<LiveAPI.LiveV6.GeocacheLog> result = new List<LiveAPI.LiveV6.GeocacheLog>();
using (var api = new LiveAPI.GeocachingLiveV6())
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingLogs", "ImportingLogs", 100, 0, true))
{
var req = new LiveAPI.LiveV6.GetUsersGeocacheLogsRequest();
req.AccessToken = api.Token;
req.ExcludeArchived = false;
req.MaxPerPage = Core.Settings.Default.LiveAPIGetUsersGeocacheLogsBatchSize;
req.StartIndex = 0;
req.LogTypes = (from a in logTypes select (long)a.ID).ToArray();
var resp = api.Client.GetUsersGeocacheLogs(req);
while (resp.Status.StatusCode == 0)
{
//logs.AddRange(resp.Logs);
//if (resp.Logs.Count() >= req.MaxPerPage)
if (resp.Logs.Count() > 0)
{
result.AddRange(resp.Logs);
req.StartIndex = result.Count;
if (!progress.Update("ImportingLogs", result.Count + req.MaxPerPage, result.Count))
{
_cancelled = true;
break;
}
System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetUsersGeocacheLogs);
resp = api.Client.GetUsersGeocacheLogs(req);
}
else
{
break;
}
}
if (resp.Status.StatusCode != 0)
{
Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage);
_cancelled = true;
}
}
}
return result;
}
示例11: DownloadSelectedPQ
public async Task DownloadSelectedPQ()
{
List<LiveAPI.LiveV6.PQData> pqs = new List<LiveAPI.LiveV6.PQData>();
foreach (PQData p in listItems.SelectedItems)
{
pqs.Add(p.LiveAPIData);
}
using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
{
await Task.Run(new Action(() =>
{
try
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("DownloadingPQ", "DownloadingPQ", pqs.Count, 0, true))
{
int index = 0;
try
{
using (var api = new LiveAPI.GeocachingLiveV6())
{
Import imp = new Import();
foreach (LiveAPI.LiveV6.PQData pq in pqs)
{
if (progress.Update(pq.Name, pqs.Count, index))
{
LiveAPI.LiveV6.GetPocketQueryZippedFileResponse resp = api.Client.GetPocketQueryZippedFile(api.Token, pq.GUID);
if (resp.Status.StatusCode == 0)
{
using (System.IO.TemporaryFile tf = new System.IO.TemporaryFile(true))
{
System.IO.File.WriteAllBytes(tf.Path, Convert.FromBase64String(resp.ZippedFile));
imp.ImportFile(tf.Path);
updateProcessedPq(pq.GUID);
}
}
else
{
Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage);
break;
}
index++;
}
else
{
break;
}
}
}
}
catch (Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(this, e);
}
}
}
catch (Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(this, e);
}
}));
}
Close();
}
示例12: ExportToCachebox
public async Task ExportToCachebox(List<Core.Data.Geocache> gcList, string targetFolder, int maxLogCount)
{
await Task.Run(() =>
{
try
{
int max = gcList.Count;
int index = 0;
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ExportCachebox", "CreatingFile", 3, 0, true))
{
string cbFile = System.IO.Path.Combine(targetFolder, "cachebox.db3");
if (System.IO.File.Exists(cbFile))
{
System.IO.File.Delete(cbFile);
}
CreateDatabase(cbFile);
if (_dbcon != null)
{
int fixedCatId = 1;
string fixedGpxFilename = "12345678.gpx";
_dbcon.ExecuteNonQuery("PRAGMA user_version = 1022");
_dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseSchemeVersion", "1022"));
_dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseSchemeVersionWin", "1022"));
_dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseId", DateTime.Now.ToFileTime()));
_dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "MasterDatabaseId", DateTime.Now.ToFileTime() + 1));
_dbcon.ExecuteNonQuery(string.Format("insert into Category (Id, GpxFilename, Pinned) values ({0}, '{1}', {2})", fixedCatId, fixedGpxFilename, 0));
_dbcon.ExecuteNonQuery(string.Format("insert into GPXFilenames (Id, GpxFilename, Imported, CategoryId) values ({0}, '{1}', '{2}', {3})", 1, fixedGpxFilename, DateTime.Now.ToString("s"), fixedCatId));
//----------------------------
// CACHES
//----------------------------
DbCommand cmd = _dbcon.Command;
cmd.CommandText = "insert into Caches (Id, GcCode, GcId, Latitude, Longitude, Name, Size, Difficulty, Terrain, Archived, Available, Found, Type, PlacedBy, Owner, DateHidden, Hint, Description, Url, NumTravelbugs, Rating, Vote, VotePending, Notes, Solver, Favorit, AttributesPositive, AttributesNegative, TourName, GPXFilename_Id, HasUserData, ListingChanged, ImagesUpdated, DescriptionImagesUpdated, CorrectedCoordinates, AttributesPositiveHigh, AttributesNegativeHigh, State, Country) values (@Id, @GcCode, @GcId, @Latitude, @Longitude, @Name, @Size, @Difficulty, @Terrain, @Archived, @Available, @Found, @Type, @PlacedBy, @Owner, @DateHidden, @Hint, @Description, @Url, @NumTravelbugs, @Rating, @Vote, @VotePending, @Notes, @Solver, @Favorit, @AttributesPositive, @AttributesNegative, @TourName, @GPXFilename_Id, @HasUserData, @ListingChanged, @ImagesUpdated, @DescriptionImagesUpdated, @CorrectedCoordinates, @AttributesPositiveHigh, @AttributesNegativeHigh, @State, @Country)";
DbParameter par;
par = cmd.CreateParameter();
par.ParameterName = "@Id";
par.DbType = DbType.Int64;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@GcCode";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@GcId";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Latitude";
par.DbType = DbType.Single;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Longitude";
par.DbType = DbType.Single;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Name";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Size";
par.DbType = DbType.Int16;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Difficulty";
par.DbType = DbType.Int16;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Terrain";
par.DbType = DbType.Int16;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Archived";
par.DbType = DbType.Boolean;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Available";
par.DbType = DbType.Boolean;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Found";
par.DbType = DbType.Boolean;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Type";
par.DbType = DbType.Int16;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@PlacedBy";
par.DbType = DbType.String;
cmd.Parameters.Add(par);
par = cmd.CreateParameter();
par.ParameterName = "@Owner";
par.DbType = DbType.String;
//.........这里部分代码省略.........
示例13: ExportToExcel
public async Task ExportToExcel(string filename, List<Sheet> sheets, List<Core.Data.Geocache> gcList)
{
await Task.Run(() =>
{
try
{
FileInfo fi = new FileInfo(filename);
if (fi.Exists)
{
fi.Delete();
}
int totalToDo = sheets.Count * gcList.Count;
int totalDone = 0;
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
using (Utils.ProgressBlock prog = new Utils.ProgressBlock("ExportExcel", "CreatingFile", totalToDo, totalDone))
{
using (ExcelPackage package = new ExcelPackage(fi))
{
foreach (Sheet sheet in sheets)
{
// add a new worksheet to the empty workbook
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(sheet.Name);
//Add the headers
int col = 1;
foreach (PropertyItem pi in sheet.SelectedItems)
{
worksheet.Cells[1, col].Value = pi.Name;
col++;
}
int row = 2;
foreach (Core.Data.Geocache gc in gcList)
{
col = 1;
foreach (PropertyItem pi in sheet.SelectedItems)
{
/*
object o = pi.GetValue(gc);
if (o != null && o.GetType() == typeof(string))
{
o = validateXml((string)o);
}
worksheet.Cells[row, col].Value = o;
* */
/*
object o = pi.GetValue(gc);
if (o != null)
{
string s = o.ToString();
worksheet.Cells[row, col].Value = s;
}
*/
worksheet.Cells[row, col].Value = pi.GetValue(gc);
col++;
}
row++;
totalDone++;
if (DateTime.Now>=nextUpdate)
{
prog.Update("CreatingFile", totalToDo, totalDone);
nextUpdate = DateTime.Now.AddSeconds(1);
}
}
}
package.Workbook.Properties.Title = "GAPP SF Geocache Export";
package.Workbook.Properties.Author = "Globalcaching.eu";
package.Workbook.Properties.Comments = "This document has been created by GlobalcachingApplication (GAPP SF)";
package.Workbook.Properties.Company = "Globalcaching.eu";
package.Save();
}
}
}
catch(Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(this, e);
}
});
}
示例14: ExportToGarminPOI
//.........这里部分代码省略.........
CacheCsv(gc).WriteLine(lon + "," + lat + ",\"" + name + "\",\"" + desc + "\"");
}
/*
UserWaypoint
int ID (458421)
string GeocacheCode;
string Description; ("Coordinate Override")
double Lat;
double Lon;
DateTime Date;
public static List<Framework.Data.UserWaypoint> GetUserWaypointsFromGeocache(Framework.Data.UserWaypointCollection wpCollection, string geocacheCode)
*/
//Iterate all waypoints of cache
wpList = Utils.DataAccess.GetWaypointsFromGeocache(db, gc.Code);
foreach (var wp in wpList)
{ //only export waypoints with coords
if (wp.Lat != null && wp.Lon != null)
{
//Make Wpt name of Cachename + # + "wpt-ID 2-letter prefix"
//others may prefer simply wp.Code
String wpname = (nameIsGCCode ? gc.Code : ProcessName(gc.Name, intMaxNameLen - 3))
+ "#" + TolerantSubstring(wp.Code, 0, 2);
String wpdesc = wp.Code + " ";
//depending on source the "real" name of the wpt sometimes is either in "Name" or "Description"
String wpd = wp.Name;
if (wpd == wp.Code)
{//use description if name only holds the wpcode
wpd = wp.Description;
}
//POI description = name + comment
wpdesc = wpdesc + ProcessDescription(wpd + ": " +
wp.Comment, intMaxDescLen - wpdesc.Length);
String wplon = FmtCsvLatLon((double)wp.Lon);
String wplat = FmtCsvLatLon((double)wp.Lat);
//wpts have no custom lat/lon
if (boolExportWpts)
{
WptCsv(gc, wp).WriteLine(wplon + "," + wplat + ",\"" + wpname + "\",\"" + wpdesc + "\"");
}
}
}
index++;
if (index % 50 == 0)
{
progress.Update(strProgSubtitle, gcList.Count, index);
}
}
}
foreach (var kv in sd) //close csv streams
{
kv.Value.Flush();
kv.Value.Close();
}
sd = null;
/*
* POI Loader
*/
if (Core.Settings.Default.GarminPOIRunPOILoader && (Core.Settings.Default.GarminPOIPOILoaderFilename != ""))
{
if (Core.Settings.Default.GarminPOIPassDirectoryToPOILoader)
{
try
{
RegistryKey rkCU = Registry.CurrentUser;
RegistryKey rkSettings = rkCU.OpenSubKey(@"Software\Garmin\POI Loader\Settings", RegistryKeyPermissionCheck.ReadWriteSubTree);
rkSettings.SetValue("Directory", Core.Settings.Default.GarminPOIExportPath);
rkCU.Close();
}
catch { }
}
Process poiLoader = new Process();
poiLoader.StartInfo.FileName = Core.Settings.Default.GarminPOIPOILoaderFilename;
if (Core.Settings.Default.GarminPOIRunPOILoaderSilently)
{
poiLoader.StartInfo.Arguments = "/Silent";
}
else
{
poiLoader.StartInfo.Arguments = "";
}
//poiLoader.StartInfo.Arguments = "/Directory \"" + Properties.Settings.Default.POIExportPath + "\""; // /silent is possible
// /Silent|/s /UsbUnitId|/u <UNITID> /Silent|/s /Directory|/d "<DIRECTORY>"
// HKEY_CURRENT_USER\Software\Garmin\POI Loader\Settings Key "Directory" REG_SZ
poiLoader.StartInfo.UseShellExecute = true;
poiLoader.StartInfo.ErrorDialog = true;
poiLoader.Start();
}
//Properties.Settings.Default.RunPOILoader
//Properties.Settings.Default.POILoaderFilename
}
}
示例15: SelectGeocaches
async public Task SelectGeocaches()
{
if (Core.ApplicationData.Instance.ActiveDatabase != null)
{
using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase))
{
await Task.Run(() =>
{
List<Core.Data.Geocache> gcList;
if (selectionContext.GeocacheSelectionContext == SelectionContext.Context.NewSelection)
{
gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection;
}
else if (selectionContext.GeocacheSelectionContext == SelectionContext.Context.WithinSelection)
{
gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList();
}
else
{
gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList();
}
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true))
{
string[] foundByUsers = Core.Settings.Default.GeocacheFilterFoundBy == null ? new string[] { } : Core.Settings.Default.GeocacheFilterFoundBy.Split(',');
for (int i = 0; i < foundByUsers.Length; i++)
{
foundByUsers[i] = foundByUsers[i].Trim();
}
string[] notFoundByUsers = Core.Settings.Default.GeocacheFilterNotFoundBy == null ? new string[] { } : Core.Settings.Default.GeocacheFilterNotFoundBy.Split(',');
for (int i = 0; i < notFoundByUsers.Length; i++)
{
notFoundByUsers[i] = notFoundByUsers[i].Trim();
}
Core.Data.Location loc = null;
double dist = 0;
if (Core.Settings.Default.GeocacheFilterLocationExpanded)
{
loc = getLocation();
dist = Core.Settings.Default.GeocacheFilterLocationRadius * 1000;
if (Core.Settings.Default.GeocacheFilterLocationKm== BooleanEnum.False)
{
dist /= 0.621371192237;
}
}
List<int> cacheTypes = new List<int>();
if (Core.Settings.Default.GeocacheFilterGeocacheTypesExpanded)
{
if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheTypes))
{
string[] parts = Core.Settings.Default.GeocacheFilterGeocacheTypes.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach(string s in parts)
{
cacheTypes.Add(int.Parse(s));
}
}
}
List<int> cacheContainers = new List<int>();
if (Core.Settings.Default.GeocacheFilterGeocacheContainersExpanded)
{
if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheContainers))
{
string[] parts = Core.Settings.Default.GeocacheFilterGeocacheContainers.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in parts)
{
cacheContainers.Add(int.Parse(s));
}
}
}
List<int> cacheAttributes = new List<int>();
if (Core.Settings.Default.GeocacheFilterGeocacheAttributesExpanded)
{
if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheAttributes))
{
string[] parts = Core.Settings.Default.GeocacheFilterGeocacheAttributes.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in parts)
{
cacheAttributes.Add(int.Parse(s));
}
}
}
if (loc != null || !Core.Settings.Default.GeocacheFilterLocationExpanded)
{
//set selected within gcList
int index = 0;
foreach (var gc in gcList)
{
gc.Selected = (
(!Core.Settings.Default.GeocacheFilterStatusExpanded || ((Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Enabled && gc.Available) ||
(Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Disabled && !gc.Available && !gc.Archived) ||
(Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Archived && gc.Archived))) &&
(!Core.Settings.Default.GeocacheFilterOwnExpanded || ((Core.Settings.Default.GeocacheFilterOwn == BooleanEnum.True) == gc.IsOwn)) &&
(!Core.Settings.Default.GeocacheFilterFoundExpanded || ((Core.Settings.Default.GeocacheFilterFound == BooleanEnum.True) == gc.Found)) &&
(!Core.Settings.Default.GeocacheFilterFoundByExpanded || ((Core.Settings.Default.GeocacheFilterFoundByAll == BooleanEnum.True) && foundByAll(gc, foundByUsers)) ||
((Core.Settings.Default.GeocacheFilterFoundByAll == BooleanEnum.False) && foundByAny(gc, foundByUsers))) &&
(!Core.Settings.Default.GeocacheFilterNotFoundByExpanded || ((Core.Settings.Default.GeocacheFilterNotFoundByAny == BooleanEnum.True) && !foundByAny(gc, foundByUsers)) ||
((Core.Settings.Default.GeocacheFilterNotFoundByAny == BooleanEnum.False) && !foundByAll(gc, foundByUsers))) &&
//.........这里部分代码省略.........