Exemplo n.º 1
0
        private void TryPortMissingParamsForAPI(IDocsAPI dApiToUpdate, TripleSlashMember?tsMemberToPort, DocsMember?interfacedMember)
        {
            bool   created;
            bool   isEII;
            string name;
            string value;
            string prefix = dApiToUpdate.Prefix;

            if (tsMemberToPort != null)
            {
                foreach (DocsParam dParam in dApiToUpdate.Params)
                {
                    if (IsEmpty(dParam.Value))
                    {
                        created = false;
                        isEII   = false;
                        name    = string.Empty;
                        value   = string.Empty;

                        TripleSlashParam tsParam = tsMemberToPort.Params.FirstOrDefault(x => x.Name == dParam.Name);

                        // When not found, it's a bug in Docs (param name not the same as source/ref), so need to ask the user to indicate correct name
                        if (tsParam == null)
                        {
                            ProblematicAPIs.AddIfNotExists($"Param=[{dParam.Name}] in Member DocId=[{dApiToUpdate.DocId}]");

                            if (tsMemberToPort.Params.Count() == 0)
                            {
                                ProblematicAPIs.AddIfNotExists($"Param=[{dParam.Name}] in Member DocId=[{dApiToUpdate.DocId}]");
                                Log.Warning($"  There were no triple slash comments for param '{dParam.Name}' in {dApiToUpdate.DocId}");
                            }
                            else
                            {
                                created = TryPromptParam(dParam, tsMemberToPort, out TripleSlashParam? newTsParam);
                                if (newTsParam == null)
                                {
                                    Log.Error($"  There param '{dParam.Name}' was not found in triple slash for {dApiToUpdate.DocId}");
                                }
                                else
                                {
                                    // Now attempt to document it
                                    if (!IsEmpty(newTsParam.Value))
                                    {
                                        // try to port triple slash comments
                                        dParam.Value = newTsParam.Value;
                                        name         = newTsParam.Name;
                                        value        = newTsParam.Value;
                                    }
                                    // or try to find if it implements a documented interface
                                    else if (interfacedMember != null)
                                    {
                                        DocsParam interfacedParam = interfacedMember.Params.FirstOrDefault(x => x.Name == newTsParam.Name || x.Name == dParam.Name);
                                        if (interfacedParam != null)
                                        {
                                            dParam.Value = interfacedParam.Value;
                                            name         = interfacedParam.Name;
                                            value        = interfacedParam.Value;
                                            isEII        = true;
                                        }
                                    }
                                }
                            }
                        }
                        // Attempt to port
                        else if (!IsEmpty(tsParam.Value))
                        {
                            // try to port triple slash comments
                            dParam.Value = tsParam.Value;
                            name         = tsParam.Name;
                            value        = tsParam.Value;
                        }
                        // or try to find if it implements a documented interface
                        else if (interfacedMember != null)
                        {
                            DocsParam interfacedParam = interfacedMember.Params.FirstOrDefault(x => x.Name == dParam.Name);
                            if (interfacedParam != null)
                            {
                                dParam.Value = interfacedParam.Value;
                                name         = interfacedParam.Name;
                                value        = interfacedParam.Value;
                                isEII        = true;
                            }
                        }


                        if (!IsEmpty(value))
                        {
                            string message = $"{prefix} {GetIsEII(isEII)} PARAM '{dParam.Name}' ({GetIsCreated(created)})";
                            PrintModifiedMember(message, dApiToUpdate.FilePath, dApiToUpdate.DocId);
                            TotalModifiedIndividualElements++;
                        }
                    }
                }
            }
            else if (interfacedMember != null)
            {
                foreach (DocsParam dParam in dApiToUpdate.Params)
                {
                    if (IsEmpty(dParam.Value))
                    {
                        DocsParam interfacedParam = interfacedMember.Params.FirstOrDefault(x => x.Name == dParam.Name);
                        if (interfacedParam != null && !IsEmpty(interfacedParam.Value))
                        {
                            dParam.Value = interfacedParam.Value;

                            string message = $"{prefix} EII PARAM '{dParam.Name}' ({GetIsCreated(false)})";
                            PrintModifiedMember(message, dApiToUpdate.FilePath, dApiToUpdate.DocId);
                            TotalModifiedIndividualElements++;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// If a Param is found in the DocsMember that did not exist in the Triple Slash member, it's possible the param was unexpectedly saved in the triple slash comments with a different name, so the user gets prompted to look for it.
        /// </summary>
        /// <param name="tsParam">The problematic triple slash param object.</param>
        /// <param name="dMember">The docs member where the param lives.</param>
        /// <param name="dParam">The docs param that was found to not match the triple slash param.</param>
        /// <returns></returns>
        private static bool TryPromptParam(TripleSlashParam tsParam, DocsMember dMember, out DocsParam dParam)
        {
            dParam = null;
            bool created = false;

            int option = -1;

            while (option == -1)
            {
                Log.Error("Problem in member {0} in file {1}!", dMember.DocId, dMember.FilePath);
                Log.Warning("The param from triple slash called '{0}' probably exists in code, but the name was not found in Docs. What would you like to do?", tsParam.Name);
                Log.Warning("    1 - Type the correct name as it shows up in Docs.");
                Log.Warning("    2 - Add the newly detected param to the Docs file (not recommended).");
                Log.Warning("        Note: Whatever your choice, make sure to double check the affected Docs file after the tool finishes executing.");
                Log.Info(false, "Your answer [1,2]: ");

                if (!int.TryParse(Console.ReadLine(), out option))
                {
                    Log.Error("Invalid selection. Try again.");
                    option = -1;
                }
                else
                {
                    switch (option)
                    {
                    case 1:
                    {
                        string newName = string.Empty;
                        while (string.IsNullOrWhiteSpace(newName))
                        {
                            Log.Info(false, "Type the new name: ");
                            newName = Console.ReadLine().Trim();
                            if (string.IsNullOrWhiteSpace(newName))
                            {
                                Log.Error("Invalid selection. Try again.");
                            }
                            else if (newName == tsParam.Name)
                            {
                                Log.Error("You specified the same name. Try again.");
                                newName = string.Empty;
                            }
                            else
                            {
                                dParam = dMember.Params.FirstOrDefault(x => x.Name == newName);
                                if (dParam == null)
                                {
                                    Log.Error("Could not find the param with the selected name. Try again.");
                                    newName = string.Empty;
                                }
                                else
                                {
                                    Log.Success("Found the param with the selected name!");
                                }
                            }
                        }
                        break;
                    }

                    case 2:
                    {
                        dParam  = dMember.SaveParam(tsParam.XEParam);
                        created = true;
                        break;
                    }

                    default:
                    {
                        Log.Error("Invalid selection. Try again.");
                        option = -1;
                        break;
                    }
                    }
                }
            }

            return(created);
        }