bool ShowListWindow(char firstChar, ICompletionDataProvider provider, ICompletionWidget completionWidget, ICodeCompletionContext completionContext, CompletionDelegate closedDelegate) { if (mutableProvider != null) { mutableProvider.CompletionDataChanging -= OnCompletionDataChanging; mutableProvider.CompletionDataChanged -= OnCompletionDataChanged; } this.provider = provider; this.completionContext = completionContext; this.closedDelegate = closedDelegate; mutableProvider = provider as IMutableCompletionDataProvider; if (mutableProvider != null) { mutableProvider.CompletionDataChanging += OnCompletionDataChanging; mutableProvider.CompletionDataChanged += OnCompletionDataChanged; if (mutableProvider.IsChanging) { OnCompletionDataChanging(null, null); } } this.completionWidget = completionWidget; this.firstChar = firstChar; return(FillList()); }
/// <summary> /// Constructor. Specify basic information about the Tween. /// </summary> /// <param name="duration">Duration of the tween (in seconds or frames).</param> /// <param name="type">Tween type, one of Tween.PERSIST (default), Tween.LOOPING, or Tween.ONESHOT.</param> /// <param name="onCompletion">Optional callback for when the Tween completes.</param> /// <param name="ease">Optional easer function to apply to the Tweened value.</param> public Tween(uint duration, uint type = 0, CompletionDelegate onCompletion = null, EaserDelegate ease = null) { _target = duration; _type = type; complete = onCompletion; _ease = ease; }
public void MoveToOverDuration(Vector3 _goalPosition, float _duration, CompletionDelegate _callback) { callback = _callback; speed = 1f / _duration; MoveTo(_goalPosition); }
public static void ShowWindow (char firstChar, ICompletionDataProvider provider, ICompletionWidget completionWidget, ICodeCompletionContext completionContext, CompletionDelegate closedDelegate) { try { if (!wnd.ShowListWindow (firstChar, provider, completionWidget, completionContext, closedDelegate)) { provider.Dispose (); return; } // makes control-space in midle of words to work string text = wnd.completionWidget.GetCompletionText (completionContext); if (text.Length == 0) { text = provider.DefaultCompletionString; if (text != null && text.Length > 0) wnd.SelectEntry (text); return; } wnd.PartialWord = text; //if there is only one matching result we take it by default if (wnd.IsUniqueMatch && !wnd.IsChanging) { wnd.UpdateWord (); wnd.Hide (); } } catch (Exception ex) { Console.WriteLine (ex); } }
public Form(bool ignoreAnnotations, FormConfiguration configuration = null, Fields <T> fields = null, List <IStep <T> > steps = null, CompletionDelegate <T> completion = null) { this._ignoreAnnotations = ignoreAnnotations; this._configuration = configuration ?? new FormConfiguration(); this._fields = fields ?? new Fields <T>(); this._steps = steps ?? new List <IStep <T> >(); this._completion = completion; }
/// <summary> /// Adds completions for an option. /// </summary> /// <typeparam name="TOption">The type of the option.</typeparam> /// <param name="option">The option for which to add completions.</param> /// <param name="complete">A <see cref="CompletionDelegate"/> that will be called to provide completions.</param> /// <returns>The option being extended.</returns> public static TOption AddCompletions <TOption>( this TOption option, CompletionDelegate complete) where TOption : Option { option.Argument.Completions.Add(complete); return(option); }
/// <summary> /// Adds completions for an argument. /// </summary> /// <typeparam name="TArgument">The type of the argument.</typeparam> /// <param name="argument">The argument for which to add completions.</param> /// <param name="complete">A <see cref="CompletionDelegate"/> that will be called to provide completions.</param> /// <returns>The configured argument.</returns> public static TArgument AddCompletions <TArgument>( this TArgument argument, CompletionDelegate complete) where TArgument : Argument { argument.Completions.Add(complete); return(argument); }
public void MoveToWithSpeed(Vector3 _goalPosition, float _speed, CompletionDelegate _callback) { callback = _callback; float distance = Vector3.Distance(transform.position, _goalPosition); speed = 1f / (distance / _speed); MoveTo(_goalPosition); }
internal static void SafeInvoke(this CompletionDelegate method, object sender, object result) { if (method != null) { try { method(sender, result); } catch { } } }
public new void Hide() { base.Hide(); declarationviewwindow.HideAll(); if (provider != null) { provider.Dispose(); provider = null; } if (closedDelegate != null) { closedDelegate(); closedDelegate = null; } }
/// <summary> /// Adds a completion source using a delegate. /// </summary> /// <param name="completionSources">The list of completion sources to add to.</param> /// <param name="complete">The delegate to be called when calculating completions.</param> public static void Add( this CompletionSourceList completionSources, CompletionDelegate complete) { if (completionSources is null) { throw new ArgumentNullException(nameof(completionSources)); } if (complete is null) { throw new ArgumentNullException(nameof(complete)); } completionSources.Add(new AnonymousCompletionSource(complete)); }
private void InviteToConference(string uri, CompletionDelegate completionDelegate) { Debug.Assert(!string.IsNullOrEmpty(uri), "New user could not be null."); ConferenceInvitationSettings convSettings = new ConferenceInvitationSettings(); convSettings.AvailableMediaTypes.Add(MediaType.Audio); var confInvitation = new ConferenceInvitation(this.CustomerSession.CustomerConversation, convSettings); try { if (this.CustomerSession.RosterTrackingService.ParticipantCount == 1) { this.StartMusic(this.CustomerSession.CustomerServiceChannel.ServiceChannelCall); } confInvitation.BeginDeliver( uri, ar => { try { confInvitation.EndDeliver(ar); completionDelegate(null); } catch (RealTimeException rte) { this.StopMusic(this.CustomerSession.CustomerServiceChannel.ServiceChannelCall); completionDelegate(rte); } }, null); } catch (InvalidOperationException ioe) { this.Logger.Log(Logger.LogLevel.Error, ioe); this.StopMusic(this.CustomerSession.CustomerServiceChannel.ServiceChannelCall); completionDelegate(ioe); } }
public static IForm <SandwichOrder> BuildForm() { CompletionDelegate <SandwichOrder> processOrder = async(context, state) => { await context.PostAsync("We are currently processing your sandwich. We will message you the status"); }; return(new FormBuilder <SandwichOrder>() .Message("Welcome to the sandwich order bot!") .Field(nameof(SandwichOrder.Sandwich)) .Field(nameof(SandwichOrder.Length)) .Field(nameof(SandwichOrder.Bread)) .Field(nameof(SandwichOrder.Cheese)) .Field(nameof(SandwichOrder.Toppings)) .Message("For sandwich toppings you have selected {Toppings}.") .Field(nameof(SandwichOrder.Sauces)) .Field(nameof(SandwichOrder.DeliveryAddress), validate: async(state, response) => { var result = new ValidateResult { IsValid = true }; var address = (response as string).Trim(); if (address.Length > 0 && address[0] < '0' || address[0] > '9') { result.Feedback = "Address must start with a number."; result.IsValid = false; } return result; }) .Field(nameof(SandwichOrder.DeliveryTime), "What time do you want your sandwich delivered? {||}") .Confirm("Do you want to order your {Length} {Sandwich} on {Bread} {&Bread} with {[{Cheese} {Toppings} {Sauces}]} to be sent to {DeliveryAddress} {?at {DeliveryTime:t}}?") .AddRemainingFields() .Message("Thanks for ordering a sandwich!") .OnCompletionAsync(processOrder) .Build()); }
private byte[] DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp) { WebResponse response = null; DownloadBitsState state = new DownloadBitsState(request, writeStream, completionDelegate, asyncOp, this.m_Progress, this); if (state.Async) { request.BeginGetResponse(new AsyncCallback(WebClient.DownloadBitsResponseCallback), state); return null; } response = this.m_WebResponse = this.GetWebResponse(request); int bytesRetrieved = state.SetResponse(response); while (!state.RetrieveBytes(ref bytesRetrieved)) { } state.Close(); return state.InnerBuffer; }
internal UploadBitsState(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer, CompletionDelegate uploadCompletionDelegate, CompletionDelegate downloadCompletionDelegate, AsyncOperation asyncOp, System.Net.WebClient.ProgressData progress, System.Net.WebClient webClient) { this.InnerBuffer = buffer; this.m_ChunkSize = chunkSize; this.m_BufferWritePosition = 0; this.Header = header; this.Footer = footer; this.ReadStream = readStream; this.Request = request; this.AsyncOp = asyncOp; this.UploadCompletionDelegate = uploadCompletionDelegate; this.DownloadCompletionDelegate = downloadCompletionDelegate; if (this.AsyncOp != null) { this.Progress = progress; this.Progress.HasUploadPhase = true; this.Progress.TotalBytesToSend = (request.ContentLength < 0L) ? -1L : request.ContentLength; } this.WebClient = webClient; }
private static extern void _RecSharePlugin_stopRecording(IntPtr instance, CompletionDelegate completion);
public static void ShowWindow(char firstChar, ICompletionDataProvider provider, ICompletionWidget completionWidget, ICodeCompletionContext completionContext, CompletionDelegate closedDelegate) { try { if (!wnd.ShowListWindow(firstChar, provider, completionWidget, completionContext, closedDelegate)) { provider.Dispose(); return; } // makes control-space in midle of words to work string text = wnd.completionWidget.GetCompletionText(completionContext); if (text.Length == 0) { text = provider.DefaultCompletionString; if (text != null && text.Length > 0) { wnd.SelectEntry(text); } return; } wnd.PartialWord = text; //if there is only one matching result we take it by default if (wnd.IsUniqueMatch && !wnd.IsChanging) { wnd.UpdateWord(); wnd.Hide(); } } catch (Exception ex) { Console.WriteLine(ex); } }
/// <devdoc> /// <para>Takes a byte array or an open file stream and writes it to a server</para> /// </devdoc> private void UploadBits(WebRequest request, Stream readStream, byte[] buffer, byte [] header, byte [] footer, CompletionDelegate completionDelegate, AsyncOperation asyncOp) { if (request.RequestUri.Scheme == Uri.UriSchemeFile) header = footer = null; UploadBitsState state = new UploadBitsState(request, readStream, buffer, header, footer, completionDelegate, asyncOp, m_Progress, this); Stream writeStream; if (state.Async) { request.BeginGetRequestStream(new AsyncCallback(UploadBitsRequestCallback), state); return; } else { writeStream = request.GetRequestStream(); } state.SetRequestStream(writeStream); while(!state.WriteBytes()); state.Close(); }
internal UploadBitsState(WebRequest request, Stream readStream, byte [] buffer, byte [] header, byte [] footer, CompletionDelegate completionDelegate, AsyncOperation asyncOp, ProgressData progress, WebClient webClient) { InnerBuffer = buffer; Header = header; Footer = footer; ReadStream = readStream; Request = request; AsyncOp = asyncOp; CompletionDelegate = completionDelegate; if (AsyncOp != null) { Progress = progress; Progress.HasUploadPhase = true; Progress.TotalBytesToSend = request.ContentLength < 0 ? -1 : request.ContentLength; } WebClient = webClient; }
public static void UpdateDownloadableLanguagesInfo(string ocrLanguagesManifestFileLocalPath, CompletionDelegate completion) { DownloadableLanguagesError = null; List <Task> downloadTasks = new List <Task>(); Task task = Task.Run(async() => { string[] directories = { LanguagesDirectory }; void ParseManifestJsonText(string jsonContent) { _originalDeserializedManifest = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonContent); if (_originalDeserializedManifest != null) { Manifest = new Dictionary <string, Dictionary <string, Dictionary <string, object> > >(_originalDeserializedManifest.Count); } foreach (KeyValuePair <string, object> entry in _originalDeserializedManifest) { if (entry.Value.GetType() != typeof(string)) { // Not the "Version" tag Dictionary <string, Dictionary <string, object> > val = (JToken.FromObject(entry.Value)).ToObject(typeof(Dictionary <string, Dictionary <string, object> >)) as Dictionary <string, Dictionary <string, object> >; Manifest.Add(entry.Key, val); } } DownloadableLanguagesError = Manifest != null ? null : new Exception("Error parsing OCR languages manifest file"); if (Manifest == null) { Manifest = GenerateTemporaryManifestWithLanguageFilesInDirectories(directories); } UpdateLanguagesWithCurrentManifest(); completion?.Invoke(null, DownloadableLanguagesError); } if (!string.IsNullOrWhiteSpace(ocrLanguagesManifestFileLocalPath)) { // Read from the embedded resource using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ocrLanguagesManifestFileLocalPath)) using (StreamReader reader = new StreamReader(stream)) { string jsonContent = reader.ReadToEnd(); ParseManifestJsonText(jsonContent); } } else if (AdditionalLanguagesURL != null) { string url = Path.Combine(AdditionalLanguagesURL, "Manifest.json"); string fileDownloadLocation = Path.Combine(_downloadLanguagesDirectory, Path.GetFileName(url)); HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); httpClientDownloader.DownloadCompleted += (object sender, DownloadCompletedEventArgs e) => { if (!string.IsNullOrWhiteSpace(fileDownloadLocation) && File.Exists(fileDownloadLocation)) { string jsonContent = File.ReadAllText(fileDownloadLocation); ParseManifestJsonText(jsonContent); } else { Manifest = null; DownloadableLanguagesError = e.Error; } }; try { await httpClientDownloader.DownloadFileAsync(url, fileDownloadLocation, null); } catch (Exception ex) { Console.WriteLine(ex.Message); } } else { Manifest = GenerateTemporaryManifestWithLanguageFilesInDirectories(directories); } }); if (!string.IsNullOrWhiteSpace(ocrLanguagesManifestFileLocalPath)) { downloadTasks.Add(task); Task.WaitAll(downloadTasks.ToArray(), -1); } }
public AnonymousCompletionSource(CompletionDelegate complete) { _complete = complete ?? throw new ArgumentNullException(nameof(complete)); }
private void DialOut(string destinationUri, string rosterUri, string displayName, CompletionDelegate completionDelegate) { try { var avmcuSession = this.CustomerSession.CustomerConversation.ConferenceSession.AudioVideoMcuSession; AudioVideoMcuDialOutOptions options = new AudioVideoMcuDialOutOptions(); options.PrivateAssistantDisabled = true; options.ParticipantUri = rosterUri; // uri that is shown in Roster. options.ParticipantDisplayName = displayName; bool stopMusic = false; if (this.CustomerSession.RosterTrackingService.ParticipantCount == 1) { this.StartMusic(this.CustomerSession.CustomerServiceChannel.ServiceChannelCall); stopMusic = true; } avmcuSession.BeginDialOut( destinationUri, // Uri to send the dial out to. options, ar => { try { if (stopMusic) { this.StopMusic(this.CustomerSession.CustomerServiceChannel.ServiceChannelCall); } avmcuSession.EndDialOut(ar); completionDelegate(null); } catch (RealTimeException rte) { completionDelegate(rte); } }, null); } catch (InvalidOperationException ioe) { completionDelegate(ioe); } }
internal DownloadBitsState(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp, ProgressData progress, WebClient webClient) { WriteStream = writeStream; Request = request; AsyncOp = asyncOp; CompletionDelegate = completionDelegate; WebClient = webClient; Progress = progress; }
public new void Hide () { base.Hide (); declarationviewwindow.HideAll (); if (provider != null) { provider.Dispose (); provider = null; } if (closedDelegate != null) { closedDelegate (); closedDelegate = null; } }
public IFormBuilder <T> OnCompletionAsync(CompletionDelegate <T> callback) { _form._completion = callback; return(this); }
public static bool DownloadLanguage(string language, ProgressDelegate progress, CompletionDelegate completion) { var localLanguages = LocalLanguages.Where(l => l.Language.Equals(language)); if (localLanguages.Count() > 0) { return(false); } var downloadableLanguages = DownloadableLanguages.Where(l => l.Language.Equals(language)); if (downloadableLanguages.Count() == 0) { return(false); } Task.Run(() => { DownloadLanguageFiles(downloadableLanguages.ElementAt(0).RemotePaths, language, progress, completion); }); return(true); }
private static void DownloadLanguageFiles(Dictionary <string, string> urls, string language, ProgressDelegate progress, CompletionDelegate completion) { OcrLanguage currentlyDownloadingLanguage = null; List <Exception> downloadErrors = new List <Exception>(); bool cancelled = false; try { if (urls.Count == 0) { var downloadableLanguages = DownloadableLanguages.Where(l => l.Language.Equals(language)); if (downloadableLanguages.Count() > 0) { currentlyDownloadingLanguage = downloadableLanguages.ElementAt(0); } completion?.Invoke(currentlyDownloadingLanguage, null); return; } currentlyDownloadingLanguage = GetCurrentlyDownloadingLanguage(urls.Values.ElementAt(0)); if (currentlyDownloadingLanguage != null) { if (currentlyDownloadingLanguage.CancellationTokenSource != null) { currentlyDownloadingLanguage.CancellationTokenSource.Dispose(); currentlyDownloadingLanguage.CancellationTokenSource = null; } currentlyDownloadingLanguage.CancellationTokenSource = new CancellationTokenSource(); currentlyDownloadingLanguage.IsDownloading = true; } long totalSizeToDownload = 0; Task task = null; Dictionary <string, long> totalBytesReceivedForAllDownloads = new Dictionary <string, long>(); List <Task> downloadTasks = new List <Task>(); HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); httpClientDownloader.DownloadCompleted += (object sender, DownloadCompletedEventArgs e) => { if (!e.Cancelled && e.Error == null) { string finalPath = Path.Combine(LanguagesDirectory, Path.GetFileName(e.TargetFilePath)); MoveFile(e.TargetFilePath, finalPath); } else if (e.Cancelled) { cancelled = true; } else if (e.Error != null) { downloadErrors.Add(e.Error); } if (cancelled || e.Error != null) { // Delete temporary file in case or cancellation or error. DeleteFile(e.TargetFilePath); } }; httpClientDownloader.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) => { // if error occurred while downloading any of this language files, then abort the rest. if (downloadErrors.Count > 0) { CancelDownloadForLanguage(currentlyDownloadingLanguage.Language); return; } if (currentlyDownloadingLanguage != null) { if (!currentlyDownloadingLanguage.IsDownloading) { // User cancelled the download of this language return; } long totalBytesReceived = 0; lock (totalBytesReceivedForAllDownloads) { totalBytesReceivedForAllDownloads[e.SourceFileUrl] = e.BytesReceived; foreach (KeyValuePair <string, long> entry in totalBytesReceivedForAllDownloads) { totalBytesReceived += entry.Value; } } currentlyDownloadingLanguage.DownloadPercentage = Math.Round((double)totalBytesReceived / totalSizeToDownload * 100, 2); progress?.Invoke(currentlyDownloadingLanguage, currentlyDownloadingLanguage.DownloadPercentage); } }; void StartDownloadTask(string url) { try { if (downloadErrors.Count > 0) { return; } string targetFilePath = Path.Combine(_downloadLanguagesDirectory, Path.GetFileName(url)); task = httpClientDownloader.DownloadFileAsync(url, targetFilePath, currentlyDownloadingLanguage.CancellationTokenSource?.Token); downloadTasks.Add(task); } catch (Exception ex2) { Console.WriteLine(ex2.Message); } } foreach (KeyValuePair <string, string> entry in urls) { string url = entry.Value; string languageFile = Path.GetFileName(url); string identifier = languageFile.Split('.')[1]; object sizeValue = Manifest[identifier][languageFile][FileSizeKeyString]; if (sizeValue.GetType() == typeof(long)) { totalSizeToDownload += (long)sizeValue; } StartDownloadTask(url); } Task.WaitAll(downloadTasks.ToArray(), -1, (currentlyDownloadingLanguage.CancellationTokenSource != null) ? currentlyDownloadingLanguage.CancellationTokenSource.Token : CancellationToken.None); downloadTasks.Clear(); if (!cancelled) { DownloadableLanguages.Remove(currentlyDownloadingLanguage); LocalLanguages.Add(currentlyDownloadingLanguage); //UpdateLanguagesWithCurrentManifest(); } } catch (Exception ex) { Console.WriteLine(ex.Message); if (ex.GetType() != typeof(TaskCanceledException) && ex.GetType() != typeof(OperationCanceledException) && currentlyDownloadingLanguage != null) { downloadErrors.Add(ex); } } finally { Exception error = null; currentlyDownloadingLanguage.IsDownloading = false; var errors = downloadErrors.Where(e => e != null); if (errors != null && errors.Count() > 0) { error = errors.ElementAt(0); } if (error != null) { DownloadableLanguagesError = error; currentlyDownloadingLanguage.DownloadPercentage = 0; } else { currentlyDownloadingLanguage.DownloadPercentage = 100; } if (!cancelled) { completion?.Invoke(currentlyDownloadingLanguage, error); } } }
public AnonymousCompletionSource(Func <CompletionContext, IEnumerable <string> > complete) { _complete = context => complete(context).Select(value => new CompletionItem(value)); }
/// <devdoc> /// <para>Generates a byte array or downloads data to an open file stream</para> /// </devdoc> private byte[] DownloadBits(WebRequest request, Stream writeStream, CompletionDelegate completionDelegate, AsyncOperation asyncOp) { WebResponse response = null; DownloadBitsState state = new DownloadBitsState(request, writeStream, completionDelegate, asyncOp, m_Progress, this); if (state.Async) { request.BeginGetResponse(new AsyncCallback(DownloadBitsResponseCallback), state); return null; } else { response = m_WebResponse = GetWebResponse(request); } bool completed; int bytesRead = state.SetResponse(response); do { completed = state.RetrieveBytes(ref bytesRead); } while (!completed); state.Close(); return state.InnerBuffer; }
bool ShowListWindow (char firstChar, ICompletionDataProvider provider, ICompletionWidget completionWidget, ICodeCompletionContext completionContext, CompletionDelegate closedDelegate) { if (mutableProvider != null) { mutableProvider.CompletionDataChanging -= OnCompletionDataChanging; mutableProvider.CompletionDataChanged -= OnCompletionDataChanged; } this.provider = provider; this.completionContext = completionContext; this.closedDelegate = closedDelegate; mutableProvider = provider as IMutableCompletionDataProvider; if (mutableProvider != null) { mutableProvider.CompletionDataChanging += OnCompletionDataChanging; mutableProvider.CompletionDataChanged += OnCompletionDataChanged; if (mutableProvider.IsChanging) OnCompletionDataChanging (null, null); } this.completionWidget = completionWidget; this.firstChar = firstChar; return FillList (); }
private void UploadBits(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer, CompletionDelegate uploadCompletionDelegate, CompletionDelegate downloadCompletionDelegate, AsyncOperation asyncOp) { if (request.RequestUri.Scheme == Uri.UriSchemeFile) { header = (byte[]) (footer = null); } UploadBitsState state = new UploadBitsState(request, readStream, buffer, chunkSize, header, footer, uploadCompletionDelegate, downloadCompletionDelegate, asyncOp, this.m_Progress, this); if (state.Async) { request.BeginGetRequestStream(new AsyncCallback(WebClient.UploadBitsRequestCallback), state); } else { Stream requestStream = request.GetRequestStream(); state.SetRequestStream(requestStream); while (!state.WriteBytes()) { } state.Close(); } }