本文整理汇总了C#中ProgressHandler类的典型用法代码示例。如果您正苦于以下问题:C# ProgressHandler类的具体用法?C# ProgressHandler怎么用?C# ProgressHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProgressHandler类属于命名空间,在下文中一共展示了ProgressHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fetch
/// <summary>
/// Fetch from the <see cref = "Remote" />.
/// </summary>
/// <param name="remote">The remote to fetch</param>
/// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param>
/// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param>
/// <param name="onCompletion">Completion callback. Corresponds to libgit2 completion callback.</param>
/// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param>
/// <param name="onTransferProgress">Callback method that transfer progress will be reported through.
/// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param>
/// <param name="credentials">Credentials to use for username/password authentication.</param>
public virtual void Fetch(
Remote remote,
TagFetchMode tagFetchMode = TagFetchMode.Auto,
ProgressHandler onProgress = null,
CompletionHandler onCompletion = null,
UpdateTipsHandler onUpdateTips = null,
TransferProgressHandler onTransferProgress = null,
Credentials credentials = null)
{
Ensure.ArgumentNotNull(remote, "remote");
// We need to keep a reference to the git_cred_acquire_cb callback around
// so it will not be garbage collected before we are done with it.
// Note that we also have a GC.KeepAlive call at the end of the method.
NativeMethods.git_cred_acquire_cb credentialCallback = null;
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true))
{
var callbacks = new RemoteCallbacks(onProgress, onCompletion, onUpdateTips);
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode);
if (credentials != null)
{
credentialCallback = (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) =>
NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password);
Proxy.git_remote_set_cred_acquire_cb(
remoteHandle,
credentialCallback,
IntPtr.Zero);
}
// It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of
// the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation
// to store a reference to the git_remote_callbacks structure this would introduce a subtle bug
// where the managed layer could move the git_remote_callbacks to a different location in memory,
// but libgit2 would still reference the old address.
//
// Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against
// GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords.
Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks);
try
{
Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch);
Proxy.git_remote_download(remoteHandle, onTransferProgress);
Proxy.git_remote_update_tips(remoteHandle);
}
finally
{
Proxy.git_remote_disconnect(remoteHandle);
}
}
// To be safe, make sure the credential callback is kept until
// alive until at least this point.
GC.KeepAlive(credentialCallback);
}
示例2: OnCreate
private ProgressBar progressBar; // Progress spinner to use for table operations
// Called when the activity initially gets created
protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Activity_To_Do);
// Initialize the progress bar
progressBar = FindViewById<ProgressBar>(Resource.Id.loadingProgressBar);
progressBar.Visibility = ViewStates.Gone;
// Create ProgressFilter to handle busy state
var progressHandler = new ProgressHandler ();
progressHandler.BusyStateChange += (busy) => {
if (progressBar != null)
progressBar.Visibility = busy ? ViewStates.Visible : ViewStates.Gone;
};
try
{
// PUSH NOTIFICATIONS: Register for push notifications
System.Diagnostics.Debug.WriteLine("Registering...");
// Initialize our Gcm Service Hub
GcmService.Initialize(this);
GcmService.Register(this);
// MOBILE SERVICES: Setup azure mobile services - this is separate from push notifications
CurrentPlatform.Init ();
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
client = new MobileServiceClient(
Constants.ApplicationURL,
Constants.ApplicationKey, progressHandler);
// Get the Mobile Service Table instance to use
todoTable = client.GetTable<TodoItem>();
// USER INTERFACE: setup the Android UI
textNewTodo = FindViewById<EditText>(Resource.Id.textNewTodo);
// Create an adapter to bind the items with the view
adapter = new TodoItemAdapter(this, Resource.Layout.Row_List_To_Do);
var listViewTodo = FindViewById<ListView>(Resource.Id.listViewTodo);
listViewTodo.Adapter = adapter;
// Load the items from the Mobile Service
await RefreshItemsFromTableAsync();
}
catch (Java.Net.MalformedURLException)
{
CreateAndShowDialog(new Exception ("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
catch (Exception e)
{
CreateAndShowDialog(e, "Error");
}
}
示例3: OnCreate
private ProgressBar progressBar; // Progress spinner to use for table operations
// Called when the activity initially gets created
protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Activity_To_Do);
// Initialize the progress bar
progressBar = FindViewById<ProgressBar>(Resource.Id.loadingProgressBar);
progressBar.Visibility = ViewStates.Gone;
// Create ProgressFilter to handle busy state
// Create ProgressFilter to handle busy state
var progressHandler = new ProgressHandler ();
progressHandler.BusyStateChange += (busy) => {
if (progressBar != null)
progressBar.Visibility = busy ? ViewStates.Visible : ViewStates.Gone;
};
try
{
// Check to ensure everything's setup right
PushClient.CheckDevice(this);
PushClient.CheckManifest(this);
// Register for push notifications
System.Diagnostics.Debug.WriteLine("Registering...");
PushClient.Register(this, PushHandlerBroadcastReceiver.SENDER_IDS);
CurrentPlatform.Init ();
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
client = new MobileServiceClient(
Constants.ApplicationURL,
Constants.ApplicationKey, progressHandler);
// Get the Mobile Service Table instance to use
todoTable = client.GetTable<TodoItem>();
textNewTodo = FindViewById<EditText>(Resource.Id.textNewTodo);
// Create an adapter to bind the items with the view
adapter = new TodoItemAdapter(this, Resource.Layout.Row_List_To_Do);
var listViewTodo = FindViewById<ListView>(Resource.Id.listViewTodo);
listViewTodo.Adapter = adapter;
// Load the items from the Mobile Service
await RefreshItemsFromTableAsync();
}
catch (Java.Net.MalformedURLException)
{
CreateAndShowDialog(new Exception ("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
catch (Exception e)
{
CreateAndShowDialog(e, "Error");
}
}
示例4: Progress
/// <summary>
/// Creates a new progress reporter.
/// </summary>
/// <param name="handler">Report through this handler.</param>
public Progress(ProgressHandler handler)
{
this.handler = handler;
this.fractions = new Stack<double>();
this.fractions.Push(1d);
this.value = 0d;
this.lastProgressSet = 0;
}
示例5: OnCreate
protected override async void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Activity_To_Do);
progressBar = FindViewById<ProgressBar> (Resource.Id.loadingProgressBar);
// Initialize the progress bar
progressBar.Visibility = ViewStates.Gone;
// Create ProgressFilter to handle busy state
var progressHandler = new ProgressHandler ();
progressHandler.BusyStateChange += (busy) => {
if (progressBar != null)
progressBar.Visibility = busy ? ViewStates.Visible : ViewStates.Gone;
};
try {
CurrentPlatform.Init ();
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
client = new MobileServiceClient (
applicationURL,
applicationKey, progressHandler);
string path =
Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "localstore.db");
if (!File.Exists(path))
{
File.Create(path).Dispose();
}
var store = new MobileServiceSQLiteStore(path);
store.DefineTable<ToDoItem>();
await client.SyncContext.InitializeAsync(store, new SyncHandler(this));
// Get the Mobile Service Table instance to use
toDoTable = client.GetSyncTable <ToDoItem> ();
textNewToDo = FindViewById<EditText> (Resource.Id.textNewToDo);
// Create an adapter to bind the items with the view
adapter = new ToDoItemAdapter (this, Resource.Layout.Row_List_To_Do);
var listViewToDo = FindViewById<ListView> (Resource.Id.listViewToDo);
listViewToDo.Adapter = adapter;
// Load the items from the Mobile Service
await RefreshItemsFromTableAsync ();
} catch (Java.Net.MalformedURLException) {
CreateAndShowDialog (new Exception ("There was an error creating the Mobile Service. Verify the URL"), "Error");
} catch (Exception e) {
CreateAndShowDialog (e, "Error");
}
}
示例6: OnCreate
private ProgressBar progressBar; // Progress spinner to use for table operations
// Called when the activity initially gets created
protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Activity_To_Do);
// Initialize the progress bar
progressBar = FindViewById<ProgressBar>(Resource.Id.loadingProgressBar);
progressBar.Visibility = ViewStates.Gone;
// TODO:: Uncomment the following code when using a mobile service
// Create ProgressFilter to handle busy state
var progressHandler = new ProgressHandler ();
progressHandler.BusyStateChange += (busy) => {
if (progressBar != null)
progressBar.Visibility = busy ? ViewStates.Visible : ViewStates.Gone;
};
try
{
// TODO:: Uncomment the following code to create the mobile services client
CurrentPlatform.Init ();
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
client = new MobileServiceClient(
Constants.ApplicationURL,
Constants.ApplicationKey, progressHandler);
// Get the Mobile Service Table instance to use
todoTable = client.GetTable<TodoItem>();
textNewTodo = FindViewById<EditText>(Resource.Id.textNewTodo);
// Create an adapter to bind the items with the view
adapter = new TodoItemAdapter(this, Resource.Layout.Row_List_To_Do);
var listViewTodo = FindViewById<ListView>(Resource.Id.listViewTodo);
listViewTodo.Adapter = adapter;
// Load the items from the Mobile Service
await RefreshItemsFromTableAsync();
}
catch (Java.Net.MalformedURLException)
{
CreateAndShowDialog(new Exception ("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
catch (Exception e)
{
CreateAndShowDialog(e, "Error");
}
}
示例7: RemoteCallbacks
internal RemoteCallbacks(
ProgressHandler onProgress = null,
TransferProgressHandler onDownloadProgress = null,
UpdateTipsHandler onUpdateTips = null,
CredentialsHandler credentialsProvider = null)
{
Progress = onProgress;
DownloadTransferProgress = onDownloadProgress;
UpdateTips = onUpdateTips;
CredentialsProvider = credentialsProvider;
}
示例8: OperationPending
public OperationPending(string langKey, string TaskName, ProgressHandler progressHandler, Cancel cancelCallback = null, bool AutoClose = false)
: base(langKey)
{
InitializeComponent();
this.progressHandler = progressHandler;
this.TaskName = TaskName;
this.CancelCallback = cancelCallback;
this.AutoClose = AutoClose;
this.LangKey = langKey;
Init();
}
示例9: Load
public static ResultCode Load(ProgressHandler handler)
{
currentProgressHandler = handler;
string gameConfigPath = Configuration.GetPath("GameConfigurations");
if (gameConfigPath == "")
{
Error = ErrorCode.MALFORMED_CONFIGURATION;
ErrorString = "Couldn't find the game configurations path.";
Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
return ResultCode.ERROR;
}
string gameConfigFile = Path.GetFullPath(gameConfigPath + Path.DirectorySeparatorChar + Configuration.CurrentGame + Path.DirectorySeparatorChar + "GUI.xml");
if (!File.Exists(gameConfigFile))
{
Error = ErrorCode.FILE_NOT_FOUND;
ErrorString = "Couldn't find the file \"" + gameConfigFile + "\".";
Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
return ResultCode.ERROR;
}
Debug.Log("GUIConfiguration", "Parsing the GUI configuration file \"" + gameConfigFile + "\".");
try
{
XDocument configuration = XDocument.Load(gameConfigFile);
Tabs = new List<Tab>();
if (!ParseTabs(configuration.Root))
{
Error = ErrorCode.MALFORMED_CONFIGURATION;
ErrorString = "The configuration file \"" + gameConfigFile + "\" contains invalid elements.";
Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
return ResultCode.ERROR;
}
}
catch (System.Xml.XmlException ex)
{
Error = ErrorCode.MALFORMED_CONFIGURATION;
ErrorString = "The file \"" + gameConfigFile + "\" couldn't be parsed. Exception: " + ex.ToString();
Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
return ResultCode.ERROR;
}
catch (Exception ex)
{
Error = ErrorCode.MALFORMED_CONFIGURATION;
ErrorString = "The file \"" + gameConfigFile + "\" couldn't be parsed. Unexpected exception: " + ex.ToString();
Debug.Log("GUIConfiguration", ErrorString, Debug.Type.ERROR);
return ResultCode.ERROR;
}
Debug.Log("GUIConfiguration", "Successfully parsed the GUI configuration.");
ChangeProgress(100f);
return ResultCode.OK;
}
示例10: Fetch
public virtual void Fetch(
Remote remote,
TagFetchMode? tagFetchMode = null,
ProgressHandler onProgress = null,
UpdateTipsHandler onUpdateTips = null,
TransferProgressHandler onTransferProgress = null,
Credentials credentials = null)
{
Fetch(remote, new FetchOptions
{
TagFetchMode = tagFetchMode,
OnProgress = onProgress,
OnUpdateTips = onUpdateTips,
OnTransferProgress = onTransferProgress,
Credentials = credentials
});
}
示例11: Fetch
/// <summary>
/// Fetch from the <see cref="Remote"/>.
/// </summary>
/// <param name="remote">The remote to fetch</param>
/// <param name="tagFetchMode">Optional parameter indicating what tags to download.</param>
/// <param name="onProgress">Progress callback. Corresponds to libgit2 progress callback.</param>
/// <param name="onUpdateTips">UpdateTips callback. Corresponds to libgit2 update_tips callback.</param>
/// <param name="onTransferProgress">Callback method that transfer progress will be reported through.
/// Reports the client's state regarding the received and processed (bytes, objects) from the server.</param>
/// <param name="credentials">Credentials to use for username/password authentication.</param>
public virtual void Fetch(
Remote remote,
TagFetchMode? tagFetchMode = null,
ProgressHandler onProgress = null,
UpdateTipsHandler onUpdateTips = null,
TransferProgressHandler onTransferProgress = null,
Credentials credentials = null)
{
Ensure.ArgumentNotNull(remote, "remote");
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true))
{
var callbacks = new RemoteCallbacks(onProgress, onTransferProgress, onUpdateTips, credentials);
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
if (tagFetchMode.HasValue)
{
Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode.Value);
}
// It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of
// the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation
// to store a reference to the git_remote_callbacks structure this would introduce a subtle bug
// where the managed layer could move the git_remote_callbacks to a different location in memory,
// but libgit2 would still reference the old address.
//
// Also, if GitRemoteCallbacks were a class instead of a struct, we would need to guard against
// GC occuring in between setting the remote callbacks and actual usage in one of the functions afterwords.
Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks);
try
{
Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch);
Proxy.git_remote_download(remoteHandle);
Proxy.git_remote_update_tips(remoteHandle);
}
finally
{
Proxy.git_remote_disconnect(remoteHandle);
}
}
}
示例12: handleProgress
private void handleProgress(int i)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.InvokeRequired)
{
ProgressHandler call = new ProgressHandler(handleProgress);
this.BeginInvoke(call, new object[] { i });
}
else
{
if (0 <= i && i <= 100)
{
progressBar1.Value = i;
progressBar1.Invalidate();
}
else this.Close();
}
}
示例13: Download
// Virtual solely so that we can subclass for testing, because mocks don't work with delegates.
public virtual void Download(string pid, AtStartHandler atStart, ProgressHandler progress, AtEndHandler atEnd) {
var page = GetIphonePage(pid);
if (!page.IsAvailable) {
atEnd(DownloadStatus.Unavailable, pid);
return;
}
var finalPath = FilenameSafe(GetTitle(pid)) + page.FileExtension;
var tempPath = finalPath + ".partial";
if (File.Exists(finalPath)){
atEnd(DownloadStatus.AlreadyExists, finalPath);
return;
}
atStart(finalPath);
var request = new CoreMediaRequest(page.EmbeddedMediaUrl, cookies);
var contentLength = request.ContentLength;
int totalReceived = 0;
using (var localStream = new FileStream(tempPath, FileMode.Append, FileAccess.Write, FileShare.Read)) {
totalReceived = (int)localStream.Position;
request.GetResponseStreamFromOffset(totalReceived, remoteStream => {
ReadFromStream(remoteStream, (buffer, bytesRead) => {
localStream.Write(buffer, 0, bytesRead);
totalReceived += bytesRead;
progress(totalReceived, contentLength);
});
});
}
if (totalReceived >= contentLength) {
File.Move(tempPath, finalPath);
atEnd(DownloadStatus.Complete, finalPath);
} else {
atEnd(DownloadStatus.Incomplete, tempPath);
}
}
示例14: OnCreate
private ProgressBar progressBar; // Progress spinner to use for table operations
// Called when the activity initially gets created
protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Activity_To_Do);
// Initialize the progress bar
progressBar = FindViewById<ProgressBar>(Resource.Id.loadingProgressBar);
progressBar.Visibility = ViewStates.Gone;
// Create ProgressFilter to handle busy state
var progressHandler = new ProgressHandler ();
progressHandler.BusyStateChange += (busy) => {
if (progressBar != null)
progressBar.Visibility = busy ? ViewStates.Visible : ViewStates.Gone;
};
try
{
CurrentPlatform.Init ();
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
client = new MobileServiceClient(
Constants.ApplicationURL,
Constants.ApplicationKey, progressHandler);
await Authenticate();
await CreateTable();
}
catch (Java.Net.MalformedURLException)
{
CreateAndShowDialog(new Exception ("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
catch (Exception e)
{
CreateAndShowDialog(e, "Error");
}
}
示例15: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.LoginScreen);
var submitButton = FindViewById<Button>(Resource.Id.BtnLogin);
var urlInput = FindViewById<EditText>(Resource.Id.LoginScreenServerUrlInput);
var keyInput = FindViewById<EditText>(Resource.Id.LoginScreenUserKeyInput);
var login = new Login();
urlInput.Text = login.Url;
keyInput.Text = login.Key;
submitButton.Click += delegate
{
var dialog = ProgressDialog.Show(this, "", "Connecting to server and validating key...", true);
var handler = new ProgressHandler(dialog);
new Login().ValidateAndStore(urlInput.Text, keyInput.Text, (valid) => RunOnUiThread(() =>
{
if (valid == Login.ValidationSuccess)
{
dialog.SetMessage("Successfully connected to " + urlInput.Text);
var widgetContainer = new Intent(this, typeof(WidgetContainer));
StartActivity(widgetContainer);
Finish();
handler.SendEmptyMessage(0);
} else
{
dialog.SetMessage("Connection failed. Please try again");
handler.SendEmptyMessage(0);
NotifyInvalidInput();
}
}));
};
}