Exemple #1
0
 private bool HandlePoll <TResponse, TMetadata>(GlossaryInfo info, Operation <TResponse, TMetadata> operation)
     where TResponse : class, IMessage <TResponse>, new()
     where TMetadata : class, IMessage <TMetadata>, new()
 {
     if (operation.IsFaulted)
     {
         info.Status       = GlossaryStatus.Error;
         info.AlertMessage = operation.Exception?.Message ?? "(Faulted)";
         return(true);
     }
     else if (operation.IsCompleted)
     {
         if ((object)operation.Result is Glossary glossary)
         {
             info.UpdateFrom(glossary);
         }
         else if ((object)operation.Result is DeleteGlossaryResponse delete)
         {
             info.Status = GlossaryStatus.Faint;
         }
         else
         {
             throw new ApplicationException($"Unknown TResponse type {typeof(TResponse)}");
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #2
0
        public async Task RefreshAsync()
        {
            StopPolling();
            List.Clear();

            // Add all known glossaries from the cloud.
            var client = await GetTranslationServiceClientAsync();

            var response = client.ListGlossariesAsync(GetLocationName());
            await response.ForEachAsync(glossary =>
            {
                var info = new GlossaryInfo(glossary);
                var id   = glossary.GlossaryName.GlossaryId;
                if (IndexOf(id) is int p && p >= 0)
                {
                    List[p] = info;
                }