/// <summary> /// Code factory framework calls this method when the command has been executed. /// </summary> /// <param name="result">The code factory model that has generated and provided to the command to process.</param> public override async Task ExecuteCommandAsync(VsCSharpSource result) { try { //Get the missing members and the target class or classes they are to be loaded into. var missingMembers = result.SourceMissingInterfaceMembers(); //Getting the hosting project for the command. var hostingProject = await result.GetHostingProjectAsync(); //If no hosting project can be found this command should not be executed. if (hostingProject == null) { return; } //Determining if the project supports the asp.net extensions for the common delivery framework bool supportCDFAspnet = await hostingProject.HasReferenceLibraryAsync(AspNetCoreConstants.CommonDeliveryFrameworkAspNetLibraryName); //If the logging abstraction library is loaded then enable logging for members. var enableLogging = true; //Bounds checking will be supported for this command bool boundsChecking = true; //Async keyword will be used for this command bool supportAsync = true; //Process each class missing members foreach (var missingMember in missingMembers) { //Get the container model that has missing members. var container = missingMember.Key; //Confirming the container is a class if not continue if (container.ContainerType != CsContainerType.Class) { continue; } var targetClass = container as CsClass; //Adding the missing members await ClassMemberManagement.AddMembersToClassWithCDFSupportAsync(result.SourceCode, targetClass, missingMember.Value, boundsChecking, enableLogging, supportAsync, supportCDFAspnet); } } catch (Exception unhandledError) { _logger.Error($"The following unhandled error occured while executing the solution explorer C# document command {commandTitle}. ", unhandledError); } }
public override async Task <bool> EnableCommandAsync(VsCSharpSource result) { //Result that determines if the the command is enabled and visible in the context menu for execution. bool isEnabled = false; try { //Determines if there are missing members in the source document var missingMembers = result.SourceMissingInterfaceMembers(); //If missing members are found display the command. isEnabled = missingMembers.Any(); if (isEnabled) { var projectData = await result.GetHostingProjectAsync(); var hasLogging = await projectData.HasReferenceLibraryAsync(AspNetCoreConstants.MicrosoftLoggerLibraryName); var hasCDF = await projectData.HasReferenceLibraryAsync(AspNetCoreConstants.CommonDeliveryFrameworkLibraryName); if (hasLogging & hasCDF) { isEnabled = false; } } } catch (Exception unhandledError) { _logger.Error($"The following unhandled error occured while checking if the solution explorer C# document command {commandTitle} is enabled. ", unhandledError); isEnabled = false; } return(isEnabled); }