예제 #1
0
        /// <summary>
        /// Start a expolre request.
        /// </summary>
        public async Task <ExploreResponse> ExploreAssemblyAsync(string aAssemblyPath, string aRevitVersion, CancellationToken aCancellationToken)
        {
            ExploreResponse response = null;
            ExploreRequest  request  = new ExploreRequest {
                Timestamp     = DateTime.Now,
                Id            = GenerateId(),
                ClientName    = mClientName,
                ClientVersion = mClientVersion,
                AssemblyPath  = aAssemblyPath
            };

            RevitHelper.StartRevit(aRevitVersion);
            bool isRunnerAvailable = await IsRunnerAvailable(aCancellationToken);

            if (isRunnerAvailable)
            {
                string requestFilePath = FileNames.ExploreRequestFilePath(request.Id);
                JsonHelper.ToFile(requestFilePath, request);

                var responseDirectoryPath = await GetResponseDirectory(request.Id);

                if (Directory.Exists(responseDirectoryPath))
                {
                    while (response == null && !aCancellationToken.IsCancellationRequested)
                    {
                        string responseFile = Path.Combine(responseDirectoryPath, FileNames.ExploreResponseFileName);
                        response = JsonHelper.FromFile <ExploreResponse>(responseFile);

                        if (response == null)
                        {
                            await Task.Delay(500, aCancellationToken);
                        }
                    }
                }
                else
                {
                    FileHelper.DeleteWithLock(requestFilePath);
                }
            }

            return(response);
        }