本文整理汇总了C#中Utils.ProgressBlock类的典型用法代码示例。如果您正苦于以下问题:C# Utils.ProgressBlock类的具体用法?C# Utils.ProgressBlock怎么用?C# Utils.ProgressBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Utils.ProgressBlock类属于命名空间,在下文中一共展示了Utils.ProgressBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportMethod
protected override void ImportMethod()
{
int max = _gcList.Count; //caches, waypoints, logs
int index = 0;
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_ASSIGNCITY, STR_ASSIGNCITY, max, 0, true))
{
foreach (Framework.Data.Geocache gc in _gcList)
{
if (index>0)
{
System.Threading.Thread.Sleep(1000); //OSM policy
}
gc.City = Utils.Geocoder.GetCityName(gc.Lat, gc.Lon);
index++;
if (DateTime.Now >= nextUpdate)
{
if (!progress.UpdateProgress(STR_ASSIGNCITY, STR_ASSIGNCITY, max, index))
{
break;
}
}
}
}
}
示例2: ImportMethod
protected override void ImportMethod()
{
try
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, _gcList.Count, 0, true))
{
int gcupdatecount = 1;
int max = _gcList.Count;
while (_gcList.Count > 0)
{
List<string> lcs = _gcList.Take(gcupdatecount).ToList();
_gcList.RemoveRange(0, lcs.Count);
List<OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
Import.AddGeocaches(Core, caches);
if (!progress.UpdateProgress(STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, max, max - _gcList.Count))
{
break;
}
}
}
}
catch (Exception e)
{
_errormessage = e.Message;
}
}
示例3: ImportMethod
protected override void ImportMethod()
{
using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGDATA, _filenames.Length, 0))
{
for (int fileindex = 0; fileindex < _filenames.Length; fileindex++)
{
List<Framework.Data.Geocache> res = ProcessWaymarkComGPXFile(_filenames[fileindex]);
if (res != null && res.Count > 0)
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGGEOCACHES, res.Count, 0))
{
int index = 0;
int procStep = 0;
foreach (Framework.Data.Geocache gc in res)
{
AddGeocache(gc, Framework.Data.Geocache.V1);
index++;
procStep++;
if (procStep >= 100)
{
progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGGEOCACHES, res.Count, index);
procStep = 0;
}
}
}
}
fixpr.UpdateProgress(STR_IMPORTING, STR_IMPORTINGDATA, _filenames.Length, fileindex + 1);
}
}
}
示例4: ExecuteAsync
public override async Task ExecuteAsync(object parameter)
{
Core.ApplicationData.Instance.BeginActiviy();
Core.Storage.Database db = Core.ApplicationData.Instance.ActiveDatabase;
if (db != null)
{
using (Utils.DataUpdater upd = new Utils.DataUpdater(db))
{
await Task.Run(() =>
{
Utils.ProgressBlock prog = null;
int max = Core.ApplicationData.Instance.MainWindow.GeocacheSelectionCount;
DateTime nextUpdate = DateTime.Now.AddSeconds(1);
if (_showProgress)
{
prog = new Utils.ProgressBlock("PerfomingAction", "PerfomingAction", max, 0, true);
}
try
{
int index = 0;
foreach (Core.Data.Geocache gc in db.GeocacheCollection)
{
if (gc.Selected)
{
_geocacheAction(gc);
if (prog != null)
{
index++;
if (DateTime.Now >= nextUpdate)
{
if (!prog.Update("PerfomingAction", max, index))
{
break;
}
nextUpdate = DateTime.Now.AddSeconds(1);
}
}
}
}
if (prog != null)
{
prog.Dispose();
prog = null;
}
}
catch(Exception e)
{
Core.ApplicationData.Instance.Logger.AddLog(this, e);
if (prog!=null)
{
prog.Dispose();
prog = null;
}
}
});
}
};
Core.ApplicationData.Instance.EndActiviy();
}
示例5: searchInDescriptionThreadMethod
private void searchInDescriptionThreadMethod()
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_ACTIONTITLE, STR_ACTIONTEXT, _gcSearchList.Count, 0, true))
{
try
{
int block = 0;
int index = 0;
foreach (Framework.Data.Geocache wp in _gcSearchList)
{
wp.Selected = (wp.ShortDescription.IndexOf(_txt, _scType) >= 0 || wp.LongDescription.IndexOf(_txt, _scType) >= 0);
block++;
index++;
if (block > 1000)
{
block = 0;
if (!progress.UpdateProgress(STR_ACTIONTITLE, STR_ACTIONTEXT, _gcSearchList.Count, index))
{
break;
}
}
}
}
catch
{
}
//signal finished
}
_actionReady.Set();
}
示例6: ImportMethod
protected override void ImportMethod()
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORT, STR_DOWNLOAD, 1, 0))
{
using (System.IO.TemporaryFile tmp = new System.IO.TemporaryFile(true))
using (System.Net.WebClient wc = new System.Net.WebClient())
{
wc.DownloadFile("http://www.globalcaching.eu/service/cachedistance.aspx?country=Netherlands&prefix=GC", tmp.Path);
using (var fs = System.IO.File.OpenRead(tmp.Path))
using (ZipInputStream s = new ZipInputStream(fs))
{
ZipEntry theEntry = s.GetNextEntry();
byte[] data = new byte[1024];
if (theEntry != null)
{
StringBuilder sb = new StringBuilder();
while (true)
{
int size = s.Read(data, 0, data.Length);
if (size > 0)
{
if (sb.Length == 0 && data[0] == 0xEF && size > 2)
{
sb.Append(System.Text.ASCIIEncoding.UTF8.GetString(data, 3, size - 3));
}
else
{
sb.Append(System.Text.ASCIIEncoding.UTF8.GetString(data, 0, size));
}
}
else
{
break;
}
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
XmlElement root = doc.DocumentElement;
XmlNodeList nl = root.SelectNodes("wp");
if (nl != null)
{
Core.Geocaches.AddCustomAttribute(CUSTOM_ATTRIBUTE);
foreach (XmlNode n in nl)
{
var gc = Utils.DataAccess.GetGeocache(Core.Geocaches, n.Attributes["code"].InnerText);
if (gc != null)
{
string dist = Utils.Conversion.StringToDouble(n.Attributes["dist"].InnerText).ToString("000.0");
gc.SetCustomAttribute(CUSTOM_ATTRIBUTE, dist);
}
}
}
}
}
}
}
}
示例7: ImportMethod
protected override void ImportMethod()
{
//for now, we just use the active site
//howver, in the future it is better to automatically switcg according geocode prefix
//at this moment, the user is responsible for selecting the geocaches and the active site
try
{
//first get a list of geocache codes
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHES, _gcList.Count, 0, true))
{
int gcupdatecount = 1;
int max = _gcList.Count;
while (_gcList.Count > 0)
{
List<string> lcs = (from Framework.Data.Geocache g in _gcList select g.Code).Take(gcupdatecount).ToList();
_gcList.RemoveRange(0, lcs.Count);
List<OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
Import.AddGeocaches(Core, caches);
if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHES, max, max - _gcList.Count))
{
break;
}
}
}
}
catch (Exception e)
{
_errormessage = e.Message;
}
}
示例8: ImportMethod
protected override void ImportMethod()
{
using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock(this, STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, 1, 0))
{
try
{
//first get a list of geocache codes
List<string> gcList = OKAPIService.GetGeocachesWithinRadius(SiteManager.Instance.ActiveSite, _centerLoc, _radiusKm, _filter);
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, gcList.Count, 0, true))
{
int gcupdatecount = 1;
int max = gcList.Count;
while (gcList.Count > 0)
{
List<string> lcs = gcList.Take(gcupdatecount).ToList();
gcList.RemoveRange(0, lcs.Count);
List<OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs);
Import.AddGeocaches(Core, caches);
if (!progress.UpdateProgress(STR_IMPORTINGCACHES, STR_IMPORTINGCACHES, max, max - gcList.Count))
{
break;
}
}
}
}
catch (Exception e)
{
_errormessage = e.Message;
}
}
}
示例9: ImportMethod
protected override void ImportMethod()
{
int max = _gcList.Count;
int gcupdatecount = 50;
int index = 0;
TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
DateTime prevCall = DateTime.MinValue;
bool dodelay = (_gcList.Count > 30);
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTING, max, 0, true))
{
try
{
using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)))
{
while (_gcList.Count > 0)
{
if (dodelay)
{
TimeSpan ts = DateTime.Now - prevCall;
if (ts < interval)
{
Thread.Sleep(interval - ts);
}
}
Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest();
req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1;
req.AccessToken = client.Token;
req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter();
req.CacheCode.CacheCodes = _gcList.Take(gcupdatecount).ToArray();
req.MaxPerPage = gcupdatecount;
req.GeocacheLogCount = 5;
index += req.CacheCode.CacheCodes.Length;
_gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
prevCall = DateTime.Now;
var resp = client.Client.SearchForGeocaches(req);
if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
{
Utils.API.Import.AddGeocaches(Core, resp.Geocaches);
}
else
{
_errormessage = resp.Status.StatusMessage;
break;
}
if (!progress.UpdateProgress(STR_IMPORTING, STR_IMPORTING, max, index))
{
break;
}
}
}
}
catch(Exception e)
{
_errormessage = e.Message;
}
}
}
示例10: 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);
}
}
}
示例11: assignRegionsThreadMethod
private void assignRegionsThreadMethod()
{
try
{
using (Utils.ProgressBlock prog = new Utils.ProgressBlock(_plugin, STR_ASSIGNINGREGION, STR_ASSIGNINGREGION, _gcList.Count, 0, true))
{
List<Framework.Data.AreaInfo> areasFilter = Utils.GeometrySupport.Instance.GetAreasByLevel(_level);
if (areasFilter != null && areasFilter.Count > 0)
{
int index = 0;
foreach (var gc in _gcList)
{
List<Framework.Data.AreaInfo> areas = Utils.GeometrySupport.Instance.GetAreasOfLocation(new Framework.Data.Location(gc.Lat, gc.Lon), areasFilter);
if (areas != null && areas.Count > 0)
{
Framework.Data.AreaInfo ai = areas[0];
if (_prefix.Length > 0)
{
ai = (from g in areas where g.Name.StartsWith(_prefix) select g).FirstOrDefault();
}
if (ai != null)
{
switch (_level)
{
case Framework.Data.AreaType.Country:
gc.Country = ai.Name;
break;
case Framework.Data.AreaType.State:
gc.State = ai.Name;
break;
case Framework.Data.AreaType.Municipality:
gc.Municipality = ai.Name;
break;
case Framework.Data.AreaType.City:
gc.City = ai.Name;
break;
}
}
}
index++;
if (index % 50 == 0)
{
if (!prog.UpdateProgress(STR_ASSIGNINGREGION, STR_ASSIGNINGREGION, _gcList.Count, index))
{
break;
}
}
}
}
}
}
catch
{
}
_actionReady.Set();
}
示例12: 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);
}
});
}
示例13: 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;
}
示例14: Action
public override bool Action(string action)
{
bool result = base.Action(action);
if (result && action == ACTION_SHOW)
{
try
{
var logs = new List<Utils.API.LiveV6.GeocacheLog>();
using (var api = new Utils.API.GeocachingLiveV6(Core))
{
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, "Importing logs", "Importing logs...", 100, 0, true))
{
var req = new Utils.API.LiveV6.GetUsersGeocacheLogsRequest();
req.AccessToken = api.Token;
req.Username = "SKAMS";
req.ExcludeArchived = true;
req.MaxPerPage = 100;
req.StartIndex = 0;
req.LogTypes = (from a in Core.LogTypes where a.AsFound 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)
{
req.StartIndex = logs.Count;
if (!progress.UpdateProgress("Importing logs", "Importing logs...", logs.Count + req.MaxPerPage, logs.Count))
{
break;
}
resp = api.Client.GetUsersGeocacheLogs(req);
}
else
{
break;
}
}
if (resp.Status.StatusCode != 0)
{
//_errormessage = resp.Status.StatusMessage;
}
}
}
}
catch
{
}
}
return result;
}
示例15: DownloadAllLogImages
public void DownloadAllLogImages()
{
try
{
_logImagesToGrab = (from Framework.Data.LogImage li in Core.LogImages select li).ToList();
using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, _logImagesToGrab.Count, 0, true))
{
int cnt = _logImagesToGrab.Count;
int orgListCount = cnt;
Thread[] thrd = new Thread[6];
for (int i = 0; i < thrd.Length; i++)
{
thrd[i] = new Thread(new ThreadStart(this.getImagesThreadMethod));
thrd[i].Start();
}
while (cnt > 0)
{
Thread.Sleep(500);
System.Windows.Forms.Application.DoEvents();
lock (_logImagesToGrab)
{
cnt = _logImagesToGrab.Count;
}
if (!progress.UpdateProgress(STR_GRABBING_IMAGES, STR_GRABBING_IMAGES, orgListCount, orgListCount - cnt))
{
lock (_logImagesToGrab)
{
_logImagesToGrab.Clear();
cnt = 0;
}
}
}
for (int i = 0; i < thrd.Length; i++)
{
thrd[i].Join();
}
}
}
catch
{
}
}