Exemplo n.º 1
0
        private static async Task <bool> TrySaveEnvoyAsync(Envoy envoy)
        {
            try
            {
                await envoy.SaveAsync();

                return(true);
            }
            catch (Exception e) when(ExceptionHelper.ShouldExceptionBeCaught(e))
            {
                CommandLineInterfaceApplication.WriteError(DocumentExtensions.GetUserVisibleSaveFailureMessage(envoy.FileName(), e));
                return(false);
            }
        }
Exemplo n.º 2
0
        private async Task <bool> LoadAndBuildComponentEnvoyAsync(Envoy componentEnvoy)
        {
            CommandLineInterfaceApplication.WriteLineVerbose($"Resolved to {componentEnvoy.Name.Last}");

            ILockedSourceFile componentFileLock;

            try
            {
                componentFileLock = await componentEnvoy.LoadAsync();
            }
            catch (Exception e) when(ExceptionHelper.ShouldExceptionBeCaught(e))
            {
                string loadErrorMessage = DocumentExtensions.GetLoadErrorMessageForException(e, componentEnvoy.FileName());

                throw new CommandLineOperationException(loadErrorMessage, e);
            }
            using (componentFileLock)
            {
                CommandLineInterfaceApplication.WriteLineVerbose($"Loaded {componentEnvoy.Name.Last}");
                var configurationReference = componentEnvoy.GetOwningComponentConfigurationReference();
                if (ShowErrorIfSubTypeNotSupported(configurationReference))
                {
                    return(false);
                }
                bool buildSucceeded = await BuildComponentAsync(configurationReference);

                bool saveFailed = Save && !await TrySaveProjectFilesAsync(componentEnvoy.Project);

                if (!buildSucceeded || saveFailed)
                {
                    CommandLineInterfaceApplication.WriteError(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            LocalizedStrings.BuildComponentTool_BuildFailed,
                            componentEnvoy.Name.Last));
                    return(false);
                }

                WriteSuccessMessage(componentEnvoy.Name.Last, configurationReference.Configuration.GetOutputDirectory());
                return(true);
            }
        }