コード例 #1
0
 internal void Start(StatisticsOptions options)
 {
     countersPublisher.Start();
     logStatistics.Start();
 }
コード例 #2
0
        private async Task OnRuntimeGrainServicesStart(CancellationToken ct)
        {
            var stopWatch = Stopwatch.StartNew();

            // Load and init grain services before silo becomes active.
            await StartAsyncTaskWithPerfAnalysis("Init grain services",
                                                 () => CreateGrainServices(), stopWatch);

            this.membershipOracleContext = (this.membershipOracle as SystemTarget)?.SchedulingContext ??
                                           this.fallbackScheduler.SchedulingContext;

            await StartAsyncTaskWithPerfAnalysis("Starting local silo status oracle", StartMembershipOracle, stopWatch);

            async Task StartMembershipOracle()
            {
                await scheduler.QueueTask(() => this.membershipOracle.Start(), this.membershipOracleContext)
                .WithTimeout(initTimeout, $"Starting MembershipOracle failed due to timeout {initTimeout}");

                logger.Debug("Local silo status oracle created successfully.");
            }

            var versionStore = Services.GetService <IVersionStore>();

            await StartAsyncTaskWithPerfAnalysis("Init type manager", () => scheduler
                                                 .QueueTask(() => this.typeManager.Initialize(versionStore), this.typeManager.SchedulingContext)
                                                 .WithTimeout(this.initTimeout, $"TypeManager Initializing failed due to timeout {initTimeout}"), stopWatch);

            //if running in multi cluster scenario, start the MultiClusterNetwork Oracle
            if (this.multiClusterOracle != null)
            {
                await StartAsyncTaskWithPerfAnalysis("Start multicluster oracle", StartMultiClusterOracle, stopWatch);

                async Task StartMultiClusterOracle()
                {
                    logger.Info("Starting multicluster oracle with my ServiceId={0} and ClusterId={1}.",
                                this.clusterOptions.ServiceId, this.clusterOptions.ClusterId);

                    this.multiClusterOracleContext = (multiClusterOracle as SystemTarget)?.SchedulingContext ??
                                                     this.fallbackScheduler.SchedulingContext;
                    await scheduler.QueueTask(() => multiClusterOracle.Start(), multiClusterOracleContext)
                    .WithTimeout(initTimeout, $"Starting MultiClusterOracle failed due to timeout {initTimeout}");

                    logger.Debug("multicluster oracle created successfully.");
                }
            }

            try
            {
                StatisticsOptions statisticsOptions = Services.GetRequiredService <IOptions <StatisticsOptions> >().Value;
                StartTaskWithPerfAnalysis("Start silo statistics", () => this.siloStatistics.Start(statisticsOptions), stopWatch);
                logger.Debug("Silo statistics manager started successfully.");

                // Finally, initialize the deployment load collector, for grains with load-based placement
                await StartAsyncTaskWithPerfAnalysis("Start deployment load collector", StartDeploymentLoadCollector, stopWatch);

                async Task StartDeploymentLoadCollector()
                {
                    var deploymentLoadPublisher = Services.GetRequiredService <DeploymentLoadPublisher>();

                    await this.scheduler.QueueTask(deploymentLoadPublisher.Start, deploymentLoadPublisher.SchedulingContext)
                    .WithTimeout(this.initTimeout, $"Starting DeploymentLoadPublisher failed due to timeout {initTimeout}");

                    logger.Debug("Silo deployment load publisher started successfully.");
                }


                // Start background timer tick to watch for platform execution stalls, such as when GC kicks in
                this.platformWatchdog = new Watchdog(statisticsOptions.LogWriteInterval, this.healthCheckParticipants, this.executorService, this.loggerFactory);
                this.platformWatchdog.Start();
                if (this.logger.IsEnabled(LogLevel.Debug))
                {
                    logger.Debug("Silo platform watchdog started successfully.");
                }
            }
            catch (Exception exc)
            {
                this.SafeExecute(() => this.logger.Error(ErrorCode.Runtime_Error_100330, String.Format("Error starting silo {0}. Going to FastKill().", this.SiloAddress), exc));
                throw;
            }
            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.Debug("Silo.Start complete: System status = {0}", this.SystemStatus);
            }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            Service <ISecurityService>      security      = null;
            Service <IFileManagerService>   fileManager   = null;
            Service <ITMService>            tm            = null;
            Service <IServerProjectService> serverProject = null;

            try
            {
                security      = new Service <ISecurityService>(baseUrl, apiKey);
                fileManager   = new Service <IFileManagerService>(baseUrl, apiKey);
                tm            = new Service <ITMService>(baseUrl, apiKey);
                serverProject = new Service <IServerProjectService>(baseUrl, apiKey);

                // Create user if it doesn't exist yet
                var users    = security.Proxy.ListUsers();
                var userInfo = Array.Find(users, x => x.UserName.ToLower() == userName.ToLower());
                // We'll need user Guid later when we assign document in project
                Guid userGuid;
                if (userInfo != null)
                {
                    userGuid = userInfo.UserGuid;
                }
                else
                {
                    // Password is SHA-1 hashed with hard-wired salt for this call
                    // A needless "security measure" that's simply a relic
                    const string  salt        = "fgad s d f sgds g  sdg gfdg";
                    var           sha1        = SHA1.Create();
                    byte[]        bytesToHash = Encoding.UTF8.GetBytes(userPass + salt);
                    HashAlgorithm algorithm   = SHA1.Create();
                    byte[]        hash        = algorithm.ComputeHash(bytesToHash);
                    // Create user
                    var newUser = new MQS.Security.UserInfo
                    {
                        UserName = userName,
                        Password = bytesToHex(hash),
                        FullName = userFullName,
                        // If we also specified an email address, memoQ server would send messages
                        // when we assign documents to this user in projects.
                    };
                    userGuid = security.Proxy.CreateUser(newUser);
                }
                // Create TM if it doesn't exist yet
                // Sloppiness warning: For simplicity, this code doesn't handle the situation
                // when a TM with the same name but a different language pair does exist.
                var  tms    = tm.Proxy.ListTMs(srcLang, trgLang);
                var  tmInfo = Array.Find(tms, x => x.Name.ToLower() == tmName.ToLower());
                Guid tmGuid;
                if (tmInfo != null)
                {
                    tmGuid = tmInfo.Guid;
                }
                else
                {
                    var newTM = new MQS.TM.TMInfo
                    {
                        Name = tmName,
                        SourceLanguageCode = srcLang,
                        TargetLanguageCode = trgLang,
                        AllowMultiple      = false,
                        AllowReverseLookup = true,
                        StoreFormatting    = true,
                        UseContext         = true,
                        UseIceSpiceContext = false,
                    };
                    tmGuid = tm.Proxy.CreateAndPublish(newTM);
                    // For this script's use case, remove all default explicit permissions from TM
                    security.Proxy.SetObjectPermissions(tmGuid, new ObjectPermission[0]);
                }
                // Delete old project if it exists (same name)
                var projects = serverProject.Proxy.ListProjects(null);
                var prInfo   = Array.Find(projects, x => x.Name.ToLower() == projectName.ToLower());
                if (prInfo != null)
                {
                    serverProject.Proxy.DeleteProject(prInfo.ServerProjectGuid);
                }
                // Create new project
                var newProject = new ServerProjectDesktopDocsCreateInfo
                {
                    CreateOfflineTMTBCopies  = false,
                    DownloadPreview          = true,
                    DownloadSkeleton         = true,
                    EnableSplitJoin          = true,
                    EnableWebTrans           = true,
                    EnableCommunication      = false,
                    AllowOverlappingWorkflow = true,
                    AllowPackageCreation     = false,
                    PreventDeliveryOnQAError = false,
                    RecordVersionHistory     = true,
                    CreatorUser        = userGuid,     // This makes our user PM in project
                    Deadline           = DateTime.Now, // Project-level deadline is display info only
                    Name               = projectName,
                    SourceLanguageCode = srcLang,
                    // Projects can have multiple target languages. In this use case, we only have one.
                    TargetLanguageCodes = new string[] { trgLang },
                };
                var projectGuid = serverProject.Proxy.CreateProject(newProject);
                // Add TM to project
                // If our project had multiple target languages, we would pass several such objects.
                var tmForTarget = new ServerProjectTMAssignmentsForTargetLang
                {
                    MasterTMGuid   = tmGuid,
                    PrimaryTMGuid  = tmGuid,
                    TMGuids        = new Guid[] { tmGuid },
                    TargetLangCode = trgLang,
                };
                serverProject.Proxy.SetProjectTMs2(projectGuid, new ServerProjectTMAssignmentsForTargetLang[] { tmForTarget });
                // Upload file to translate
                Guid fileGuid;
                using (FileStream fs = new FileStream(Path.Combine(filePath, fileName), FileMode.Open, FileAccess.Read))
                    using (BinaryReader br = new BinaryReader(fs))
                    {
                        fileGuid = fileManager.Proxy.BeginChunkedFileUpload(fileName, false);
                        while (true)
                        {
                            byte[] buf = br.ReadBytes(4096);
                            if (buf.Length == 0)
                            {
                                break;
                            }
                            fileManager.Proxy.AddNextFileChunk(fileGuid, buf);
                            if (buf.Length < 4096)
                            {
                                break;
                            }
                        }
                        fileManager.Proxy.EndChunkedFileUpload(fileGuid);
                    }
                // Import file into project
                var tdoc = serverProject.Proxy.ImportTranslationDocument(
                    projectGuid, fileGuid,
                    // If project had multiple target lanuages, array below would decide which ones
                    // we want to translate the document into. Passing null means: import into all TLs.
                    null,
                    null);
                // Sloppiness warning: In production code, you must check import result here.
                // One or more files might have failed to import.
                // Remove uploaded file
                fileManager.Proxy.DeleteFile(fileGuid);
                // Pre-translate document in project
                var preTransOptions = new PretranslateOptions
                {
                    UseMT = true,
                    OnlyUnambiguousMatches            = false,
                    PretranslateLookupBehavior        = PretranslateLookupBehavior.AnyMatch,
                    FinalTranslationState             = PretranslateExpectedFinalTranslationState.Confirmed,
                    ConfirmLockPretranslated          = PretranslateStateToConfirmAndLock.ExactMatchWithContext,
                    ConfirmLockUnambiguousMatchesOnly = true,
                    LockPretranslated = false,
                };
                serverProject.Proxy.PretranslateProject(
                    projectGuid,
                    null, // Passing null for target language array means: everything
                    preTransOptions);
                // Run statistics
                var statsOpt = new StatisticsOptions
                {
                    Algorithm                   = StatisticsAlgorithm.MemoQ,
                    Analysis_Homogenity         = false,
                    Analysis_ProjectTMs         = true,
                    Analyzis_DetailsByTM        = false,
                    DisableCrossFileRepetition  = false,
                    IncludeLockedRows           = false,
                    RepetitionPreferenceOver100 = true,
                    ShowCounts                  = false,
                    ShowResultsPerFile          = false,
                };
                var statsRes = serverProject.Proxy.GetStatisticsOnProject(projectGuid, null, statsOpt, StatisticsResultFormat.CSV_MemoQ);
                // ResultsForTargetLangs has one item per project target language
                byte[] statResBytes = statsRes.ResultsForTargetLangs[0].ResultData;
                // Result is byte array in Unicode encoding
                string statResStr = Encoding.Unicode.GetString(statResBytes);
                // Setup details about document-user assignment
                var assmt = new ServerProjectTranslationDocumentUserAssignments
                {
                    // tdoc.DocumentGuids only has one element, b/c we imported our document into a single
                    // target language only.
                    DocumentGuid = tdoc.DocumentGuids[0],
                    // We are only assigning one role, TR = translator.
                    UserRoleAssignments = new TranslationDocumentUserRoleAssignment[1],
                };
                assmt.UserRoleAssignments[0] = new TranslationDocumentUserRoleAssignment
                {
                    UserGuid = userGuid,
                    // 0: Translator
                    // 1: Reviewer 1
                    // 2: Reviewer 2
                    DocumentAssignmentRole = 0,
                    // In real life, deadline would be specified by client
                    DeadLine = DateTime.UtcNow.AddDays(3),
                };
                // Assign document to user
                serverProject.Proxy.SetProjectTranslationDocumentUserAssignments(
                    projectGuid,
                    // 1 item in array, b/c we're only assigning 1 doc in 1 target language.
                    new ServerProjectTranslationDocumentUserAssignments[] { assmt });
                // We're done! What now?
                // User can open document in webTrans, or check out online project and translate in memoQ.
            }
            finally
            {
                if (security != null)
                {
                    security.Dispose();
                }
                if (fileManager != null)
                {
                    security.Dispose();
                }
                if (tm != null)
                {
                    security.Dispose();
                }
                if (serverProject != null)
                {
                    security.Dispose();
                }
            }
        }