コード例 #1
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                _sdk     = sdk;
                _atc     = atc;
                _console = console;

                if (!Json.HasValue)
                {
                    console.WriteLine("Starting model training...");
                }

                var modelId = Int64.Parse(ModelId);

                CreateAndWait(() => sdk.TrainModel(modelId, atc.GetToken()), modelId, Wait, (modelId) => IsTrained(modelId), Json.HasValue ? false : true);

                if (!Json.HasValue)
                {
                    if (!Wait)
                    {
                        console.WriteLine("Training submitted.");
                    }
                }
                else
                {
                    string sts = Wait ? "success" : "submitted";
                    console.WriteLine(SafeJsonConvert.SerializeObject(new { status = sts }, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }
                return(0);
            }
コード例 #2
0
ファイル: Conn.cs プロジェクト: jeason0813/DryIoc
 public AccessTokenCacheClient(
     IAccessTokenClient arg0,
     IAccessTokenCache arg1
     )
 {
     field0 = arg0;
     field1 = arg1;
 }
コード例 #3
0
 public ReauthenticateAuth0Handler(
     ILogger <ReauthenticateAuth0Handler> logger, TokenRequest tokenRequest, AccessToken accessToken, IAccessTokenClient accessTokenClient)
 {
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     _tokenRequest = tokenRequest ?? throw new ArgumentNullException(nameof(tokenRequest));
     _accessToken  = accessToken ?? throw new ArgumentNullException(nameof(accessToken));
     _client       = accessTokenClient ?? throw new ArgumentNullException(nameof(accessTokenClient));
 }
コード例 #4
0
 public ConnPasswordPolicyService(
     IHttpClientFactory arg0,
     IAccessTokenClient arg1
     )
 {
     field0 = arg0;
     field1 = arg1;
 }
コード例 #5
0
 public ConnPublicApiClientFactory(
     IAccessTokenClient arg0,
     IConnClient arg1
     )
 {
     field0 = arg0;
     field1 = arg1;
 }
コード例 #6
0
 public ConnClient(
     IAccessTokenClient arg0,
     IConnConfiguration arg1
     )
 {
     field0 = arg0;
     field1 = arg1;
 }
コード例 #7
0
ファイル: Conn.cs プロジェクト: jeason0813/DryIoc
 public UserService(
     IAccessTokenClient arg0,
     IHttpClientFactory arg1
     )
 {
     field0 = arg0;
     field1 = arg1;
 }
コード例 #8
0
 public ConnEmailChangeService(
     IHttpClientFactory arg0,
     IAccessTokenClient arg1,
     IConnClient arg2,
     IConnErrorFactory arg3,
     IConnPublicApiClientFactory arg4
     )
 {
     field0 = arg0;
     field1 = arg1;
     field2 = arg2;
     field3 = arg3;
     field4 = arg4;
 }
コード例 #9
0
 public ConnClientService(
     IHttpClientFactory arg0,
     IAccessTokenClient arg1,
     IConnConfiguration arg2,
     IConnClient arg3,
     IConnErrorFactory arg4,
     IConnPublicApiClientFactory arg5
     )
 {
     field0 = arg0;
     field1 = arg1;
     field2 = arg2;
     field3 = arg3;
     field4 = arg4;
     field5 = arg5;
 }
コード例 #10
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                _sdk     = sdk;
                _atc     = atc;
                _console = console;

                if (!Json.HasValue)
                {
                    console.WriteLine("Starting model deployment...");
                }

                var regions = new List <ModelRegionStatus>();

                regions.Add(new ModelRegionStatus()
                {
                    Region     = 1,
                    IsDeployed = !NorthAmerica.HasValue ? true : NorthAmerica.Value
                });
                regions.Add(new ModelRegionStatus()
                {
                    Region     = 2,
                    IsDeployed = !Europe.HasValue ? true : Europe.Value
                });
                regions.Add(new ModelRegionStatus()
                {
                    Region     = 3,
                    IsDeployed = !Asia.HasValue ? true : Asia.Value
                });

                CallApi(() => sdk.DeployModel(Int64.Parse(ModelId), atc.GetToken(), regions));

                if (!Json.HasValue)
                {
                    console.WriteLine("Deployment request submitted.");
                }
                else
                {
                    console.WriteLine(SafeJsonConvert.SerializeObject(new { status = "submitted" }, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }

                return(0);
            }
コード例 #11
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                if (!Json.HasValue)
                {
                    console.WriteLine("Getting models...");
                }

                int pageIndex           = 1;
                List <ModelInfo> models = new List <ModelInfo>();

                while (true)
                {
                    var res = CallApi <ModelsResponse>(() => sdk.GetProjectsByIdModels(new Guid(ProjectId), atc.GetToken(), pageIndex));
                    if (res == null)
                    {
                        throw new Exception("GetProjectsByIdModels returned null response");
                    }

                    models.AddRange(res.Models);

                    pageIndex++;
                    if (pageIndex > res.TotalPageCount)
                    {
                        break;
                    }
                }

                if (!Json.HasValue)
                {
                    foreach (var model in models)
                    {
                        console.WriteLine($"{model.Id,-10} {model.Name,-50} {model.ModelStatus}");
                    }
                }
                else
                {
                    console.WriteLine(SafeJsonConvert.SerializeObject(models, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }

                return(0);
            }
コード例 #12
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                if (!Json.HasValue)
                {
                    console.WriteLine("Getting projects...");
                }

                int pageIndex = 1;
                List <ProjectInfo> projects = new List <ProjectInfo>();

                while (true)
                {
                    var res = CallApi <ProjectsResponse>(() => sdk.GetProjects(atc.GetToken(), WorkspaceId, pageIndex));
                    if (res == null)
                    {
                        throw new Exception("GetProjects returned null response");
                    }

                    projects.AddRange(res.Projects);

                    pageIndex++;
                    if (pageIndex > res.TotalPageCount)
                    {
                        break;
                    }
                }

                if (!Json.HasValue)
                {
                    foreach (var project in projects)
                    {
                        console.WriteLine($"{project.Id,30} {project.Name,-25}");
                    }
                }
                else
                {
                    console.WriteLine(SafeJsonConvert.SerializeObject(projects, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }

                return(0);
            }
コード例 #13
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                if (!Json.HasValue)
                {
                    console.WriteLine("Getting documents...");
                }

                int pageIndex = 1;
                List <DocumentInfo> documents = new List <DocumentInfo>();

                while (true)
                {
                    var res = CallApi <DocumentsResponse>(() => sdk.GetDocuments(atc.GetToken(), pageIndex, WorkspaceId));
                    if (res == null)
                    {
                        throw new Exception("GetDocuments returned null response");
                    }

                    documents.AddRange(res.PaginatedDocuments.Documents);

                    pageIndex++;
                    if (pageIndex > res.PaginatedDocuments.TotalPageCount)
                    {
                        break;
                    }
                }

                //Report results
                if (!Json.HasValue)
                {
                    foreach (var document in documents)
                    {
                        console.WriteLine($"{document.Id} {document.Languages[0].LanguageCode} {document.Name}");
                    }
                }
                else
                {
                    console.WriteLine(SafeJsonConvert.SerializeObject(documents, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }

                return(0);
            }
コード例 #14
0
 public PushNotificationManager(IPushNotificationClient pushNotificationClient, IAccessTokenClient accessTokenClient, ILogger <PushNotificationManager> logger)
 {
     _pushNotificationClient = pushNotificationClient;
     _accessTokenClient      = accessTokenClient;
     _logger = logger;
 }
コード例 #15
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                LanguagePair = LanguagePair.ToLower();

                // Get the supported language pairs
                var languagePairs = CallApi <IList <LanguagePair> >(() => sdk.GetSupportedLanguagePairs(atc.GetToken()));

                if (languagePairs == null)
                {
                    return(-1);
                }

                var languagePairId = (from lp in languagePairs
                                      where lp.SourceLanguage.LanguageCode == LanguagePair.Split(":")[0] &&
                                      (lp.TargetLanguage.LanguageCode == LanguagePair.Split(":")[1])
                                      select lp.Id).FirstOrDefault();

                if (languagePairId == null)
                {
                    console.WriteLine("Invalid or unsupported LanguagePair.");
                    return(-1);
                }

                // Get the categories
                var categories = CallApi <IList <TranslatorCategory> >(() => sdk.GetCategories(atc.GetToken()));

                if (categories == null)
                {
                    return(-1);
                }

                var categoryId = (from c in categories
                                  where c.Name.ToLower() == Category.ToLower()
                                  select c.Id).FirstOrDefault();

                if (categoryId == 0)
                {
                    console.WriteLine("Invalid or unsupported Category.");
                    return(-1);
                }

                // Populate the new project data
                var projectDefinition = new CreateProjectData()
                {
                    LanguagePairId     = (int)languagePairId.Value,
                    CategoryId         = (int)categoryId,
                    Name               = Name,
                    CategoryDescriptor = CategoryDescriptor,
                    Description        = Description,
                    Label              = Label
                };

                if (!Json.HasValue)
                {
                    console.WriteLine("Creating project...");
                }

                CallApi(() => sdk.CreateProject(projectDefinition, atc.GetToken(), WorkspaceId));

                if (Label == null)
                {
                    Label = string.Empty;
                }
                var res1 = CallApi <ProjectsResponse>(() => sdk.GetProjects(atc.GetToken(), WorkspaceId, 1, $"name eq {Name}", "createdDate desc"));

                if (res1 == null)
                {
                    return(-1);
                }

                if (res1.Projects.Count == 0)
                {
                    throw new Exception("Error: project creation failed.");
                }
                else
                {
                    bool foundIt = false;

                    foreach (var project in res1.Projects)
                    {
                        if (project.Name == Name && (project.Label == Label))
                        {
                            foundIt = true;
                            if (!Json.HasValue)
                            {
                                console.WriteLine($"{project.Id,30} {project.Name,-25}");
                            }
                            else
                            {
                                console.WriteLine(SafeJsonConvert.SerializeObject(project, new Newtonsoft.Json.JsonSerializerSettings()
                                {
                                    Formatting = Newtonsoft.Json.Formatting.Indented
                                }));
                            }
                            break;
                        }
                    }
                    if (!foundIt)
                    {
                        throw new Exception("Error: project creation failed.");
                    }
                }

                return(0);
            }
コード例 #16
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                if (!Json.HasValue)
                {
                    console.WriteLine("Deleting model...");
                }

                CallApi(() => sdk.DeleteModel(Int64.Parse(ModelId), atc.GetToken()));

                console.WriteLine(!Json.HasValue ? "Success." : SafeJsonConvert.SerializeObject(new { status = "success" }, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    Formatting = Newtonsoft.Json.Formatting.Indented
                }));

                return(0);
            }
コード例 #17
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                _sdk     = sdk;
                _atc     = atc;
                _console = console;

                // Populate the new model data
                var docIDs = new List <long?>();

                foreach (var docId in DocumentIDs.Split(','))
                {
                    docIDs.Add(Int64.Parse(docId));
                }
                var modelDefinition = new CreateModelRequest()
                {
                    Name          = Name,
                    DocumentIds   = docIDs,
                    IsTuningAuto  = true,
                    IsTestingAuto = true,
                    IsAutoDeploy  = true,
                    IsAutoTrain   = Train.HasValue ? true : false,
                    ProjectId     = new Guid(ProjectId)
                };

                if (!Json.HasValue)
                {
                    console.WriteLine("Creating model...");
                }

                CallApi(() => sdk.CreateModel(modelDefinition, atc.GetToken()));

                // CreateModel does not return the new model Id so we must query for it
                var res1 = CallApi <ModelsResponse>(() => sdk.GetProjectsByIdModels(new Guid(ProjectId), atc.GetToken(), 1, $"modelName eq {Name}"));

                if (res1 == null)
                {
                    return(-1);
                }

                if (res1.Models.Count == 0)
                {
                    if (!Json.HasValue)
                    {
                        console.WriteLine("Error: Model not created.");
                        return(-1);
                    }
                }
                else
                {
                    ModelInfo createdModel = res1.Models.FirstOrDefault((s) => s.Name == Name);
                    if (createdModel == null)
                    {
                        console.WriteLine("Error: Model not created.");
                        return(-1);
                    }

                    bool waitRequested = Wait && (modelDefinition.IsAutoTrain.HasValue && modelDefinition.IsAutoTrain.Value);
                    if (waitRequested)
                    {
                        CreateAndWait(() => sdk.GetModel(createdModel.Id, atc.GetToken()), createdModel.Id, true, (modelId) => IsTrained(modelId), Json.HasValue ? false : true);
                        createdModel = CallApi <ModelInfo>(() => sdk.GetModel(createdModel.Id, atc.GetToken()));
                    }

                    if (!Json.HasValue)
                    {
                        console.WriteLine($"{createdModel.Id,-10} {createdModel.Name,-50} {createdModel.ModelStatus}");
                    }
                    else
                    {
                        console.WriteLine(SafeJsonConvert.SerializeObject(createdModel, new Newtonsoft.Json.JsonSerializerSettings()
                        {
                            Formatting = Newtonsoft.Json.Formatting.Indented
                        }));
                    }
                }

                return(0);
            }
コード例 #18
0
 public AccessTokenAccessor(IAccessTokenClient client, IAccessTokenStorage storage)
 {
     _client  = client;
     _storage = storage;
 }
コード例 #19
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                _sdk     = sdk;
                _atc     = atc;
                _console = console;

                // Get the supported language pairs
                var languagePairs = CallApi <IList <LanguagePair> >(() => sdk.GetSupportedLanguagePairs(atc.GetToken()));

                if (languagePairs == null)
                {
                    return(-1);
                }

                var languagePairId = (from lp in languagePairs
                                      where lp.SourceLanguage.LanguageCode == LanguagePair.Split(":")[0] &&
                                      (lp.TargetLanguage.LanguageCode == LanguagePair.Split(":")[1])
                                      select lp.Id).FirstOrDefault();

                if (languagePairId == null)
                {
                    console.WriteLine("Invalid or unsupported LanguagePair.");
                    return(-1);
                }

                // Validate arg combinations
                if (!string.IsNullOrEmpty(ComboFile) && !string.IsNullOrEmpty(SourceFile))
                {
                    console.WriteLine("--ComboFile and --SourceFile cannot be specified together.");
                    return(-1);
                }
                if (!string.IsNullOrEmpty(ComboFile) && !string.IsNullOrEmpty(TargetFile))
                {
                    console.WriteLine("--ComboFile and --TargetFile cannot be specified together.");
                    return(-1);
                }
                if (!string.IsNullOrEmpty(SourceFile) && string.IsNullOrEmpty(TargetFile))
                {
                    console.WriteLine("--SourceFile and --TargetFile must be specified together.");
                    return(-1);
                }
                if (string.IsNullOrEmpty(SourceFile) && !string.IsNullOrEmpty(TargetFile))
                {
                    console.WriteLine("--SourceFile and --TargetFile must be specified together.");
                    return(-1);
                }
                if (!string.IsNullOrEmpty(SourceFile) && !string.IsNullOrEmpty(TargetFile) && string.IsNullOrEmpty(ParallelName))
                {
                    console.WriteLine("--ParallelName must be specified with --SourceFile and --TargetFile.");
                    return(-1);
                }

                // Build request data
                if (!Json.HasValue)
                {
                    console.WriteLine("Uploading documents...");
                }

                var documentDetails = new DocumentDetailsForImportRequest()
                {
                    DocumentName = ParallelName,
                    DocumentType = DocumentTypeLookup.Types[DocumentType.ToLowerInvariant()],
                    FileDetails  = new List <FileForImportRequest>()
                };

                if (!string.IsNullOrEmpty(ComboFile))
                {
                    documentDetails.FileDetails.Add(new FileForImportRequest()
                    {
                        Name              = Path.GetFileName(ComboFile),
                        LanguageCode      = LanguagePair.Split(":")[1],
                        OverwriteIfExists = Override.HasValue ? true : false
                    });
                    documentDetails.IsParallel = false;
                }
                else
                {
                    documentDetails.FileDetails.Add(new FileForImportRequest()
                    {
                        Name              = Path.GetFileName(SourceFile),
                        LanguageCode      = LanguagePair.Split(":")[0],
                        OverwriteIfExists = Override.HasValue ? true : false
                    });
                    documentDetails.FileDetails.Add(new FileForImportRequest()
                    {
                        Name              = Path.GetFileName(TargetFile),
                        LanguageCode      = LanguagePair.Split(":")[1],
                        OverwriteIfExists = Override.HasValue ? true : false
                    });
                    documentDetails.IsParallel = true;
                }
                var details = new List <DocumentDetailsForImportRequest>()
                {
                    documentDetails
                };

                var files = string.Empty;

                if (!string.IsNullOrEmpty(ComboFile))
                {
                    files = ComboFile;
                }
                else
                {
                    files = SourceFile + "|" + TargetFile;
                }

                var importFilesJobResponse = CallApi <ImportFilesResponse>(() => sdk.ImportDocuments(atc.GetToken(), files, JsonConvert.SerializeObject(details, Formatting.Indented), WorkspaceId));

                if (importFilesJobResponse == null)
                {
                    return(-1);
                }

                if (!Wait)
                {
                    console.WriteLine(SafeJsonConvert.SerializeObject(importFilesJobResponse, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }
                else
                {
                    Guid jobId = importFilesJobResponse.JobId.Value;
                    CreateAndWait(() => sdk.GetImportJobsByJobId(atc.GetToken(), jobId, 1, 100), jobId, true, (jobId) => IsUploaded(jobId), Json.HasValue ? false : true);

                    var jobStatusResponse = CallApi <ImportJobStatusResponse>(() => sdk.GetImportJobsByJobId(atc.GetToken(), jobId, 1, 100));
                    console.WriteLine(SafeJsonConvert.SerializeObject(jobStatusResponse, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }

                return(0);
            }
コード例 #20
0
            private WorkspaceInfo FindWorkspace(string name, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                var wsList = CallApi <List <WorkspaceInfo> >(() => sdk.GetWorkspaces(atc.GetToken()));

                if (wsList == null)
                {
                    return(null);
                }

                WorkspaceInfo ws = null;

                if (wsList.Count > 0)
                {
                    foreach (var workspace in wsList)
                    {
                        if (workspace.Name == name)
                        {
                            ws = workspace;
                            break;
                        }
                    }
                }

                return(ws);
            }
コード例 #21
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                if (!Json.HasValue)
                {
                    console.WriteLine("Getting workspaces...");
                }

                var res = CallApi <List <WorkspaceInfo> >(() => sdk.GetWorkspaces(atc.GetToken()));

                if (res == null)
                {
                    return(-1);
                }

                if (res.Count == 0)
                {
                    if (!Json.HasValue)
                    {
                        console.WriteLine("No workspaces found.");
                    }
                    else
                    {
                        console.WriteLine(SafeJsonConvert.SerializeObject(res, new Newtonsoft.Json.JsonSerializerSettings()
                        {
                            Formatting = Newtonsoft.Json.Formatting.Indented
                        }));
                    }
                }
                else
                {
                    if (!Json.HasValue)
                    {
                        foreach (var workspace in res)
                        {
                            console.WriteLine($"{workspace.Id,30} {workspace.Name,-25}");
                        }
                    }
                    else
                    {
                        console.WriteLine(SafeJsonConvert.SerializeObject(res, new Newtonsoft.Json.JsonSerializerSettings()
                        {
                            Formatting = Newtonsoft.Json.Formatting.Indented
                        }));
                    }
                }

                return(0);
            }
コード例 #22
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                _sdk     = sdk;
                _console = console;
                _config  = config;
                _atc     = atc;

                // See if it already exists
                var ws = FindWorkspace(Name, sdk, atc);

                if (ws != null)
                {
                    if (!Json.HasValue)
                    {
                        console.WriteLine($"Workspace '{Name}' already exists");
                        console.WriteLine($"{ws.Id,30} {ws.Name,-25}");
                    }
                    else
                    {
                        console.WriteLine(SafeJsonConvert.SerializeObject(ws, new Newtonsoft.Json.JsonSerializerSettings()
                        {
                            Formatting = Newtonsoft.Json.Formatting.Indented
                        }));
                    }

                    return(0);
                }

                var billingRegions = CallApi <List <BillingRegions> >(() => sdk.GetBillingregions(atc.GetToken()));
                var billingRegion  = (from br in billingRegions
                                      where br.BillingRegionName.ToLower() == config.TranslatorRegion.ToLower()
                                      select br).FirstOrDefault();

                if (billingRegion == null)
                {
                    throw new Exception($"Unknown billing region '{config.TranslatorRegion}'. Run 'config set' and add your Translator key and region or select proper configuration set by calling 'config select <name>'.");
                }

                var workspaceDefinition = new CreateWorkspaceData()
                {
                    Name         = Name,
                    Subscription = new Subscription()
                    {
                        SubscriptionKey   = config.TranslatorKey,
                        BillingRegionCode = billingRegion.BillingRegionCode
                    }
                };

                if (!Json.HasValue)
                {
                    console.WriteLine("Creating workspace...");
                }

                CallApi <HttpOperationResponse>(() => sdk.CreateWorkspace(workspaceDefinition, atc.GetToken()));

                var workspace = FindWorkspace(Name, sdk, atc);

                if (workspace == null)
                {
                    throw new Exception("FAILED: Workspace not created.");
                }

                if (!Json.HasValue)
                {
                    console.WriteLine($"{workspace.Id,30} {workspace.Name,-25}");
                }
                else
                {
                    console.WriteLine(SafeJsonConvert.SerializeObject(workspace, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                        Formatting = Newtonsoft.Json.Formatting.Indented
                    }));
                }

                return(0);
            }
コード例 #23
0
 public DocumentManagerBearerTokenHandler(IAccessTokenClient accessTokenClient, DocumentManagerClientCredentials credentials)
 {
     _tokenClient = accessTokenClient ?? throw new ArgumentNullException(nameof(accessTokenClient));
     _credentials = credentials ?? throw new ArgumentNullException(nameof(credentials));
 }
コード例 #24
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                if (!Json.HasValue)
                {
                    console.WriteLine("Getting model...");
                }

                var res = CallApi <ModelInfo>(() => sdk.GetModel(Int64.Parse(ModelId), atc.GetToken()));

                if (res == null)
                {
                    return(-1);
                }

                console.WriteLine(SafeJsonConvert.SerializeObject(res, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    Formatting = Newtonsoft.Json.Formatting.Indented
                }));

                return(0);
            }
コード例 #25
0
 public AccessTokenClientTests()
 {
     _sut = new AccessTokenClient(new HttpClient());
 }
コード例 #26
0
            int OnExecute(IConsole console, IConfig config, IConfiguration appConfiguration, IMicrosoftCustomTranslatorAPIPreview10 sdk, IAccessTokenClient atc)
            {
                console.WriteLine("Getting Import Status...");

                int pageIndex = 1;
                List <ImportJobFileStatusInfo> jobStatus = new List <ImportJobFileStatusInfo>();

                while (true)
                {
                    var res = CallApi <ImportJobStatusResponse>(() => sdk.GetImportJobsByJobId(atc.GetToken(), new Guid(JobId), pageIndex, 100));
                    if (res == null)
                    {
                        throw new Exception("GetImportJobsByJobId returned null response");
                    }

                    jobStatus.AddRange(res.FileProcessingStatus);

                    pageIndex++;
                    if (pageIndex > res.TotalPageCount)
                    {
                        break;
                    }
                }

                console.WriteLine(SafeJsonConvert.SerializeObject(jobStatus, new Newtonsoft.Json.JsonSerializerSettings()
                {
                    Formatting = Newtonsoft.Json.Formatting.Indented
                }));

                return(0);
            }