public string Run(string input, int startAt = 0)
        {
            Match match = xpoMatch.Match(input, startAt);

            if (match.Success)
            {
                string xml = match.Value;

                if (!xml.Contains("<Optional>"))
                {
                    string fieldName = MetaData.extractFromXML(xml, "//AxTableIndexField/DataField");
                    string indexName = MetaData.extractPreviousXMLElement("Name", match.Index, input);
                    string tableName = MetaData.extractNextXMLElement("Name", 1, input);
                    string token     = tableName + "\\" + indexName + "\\" + fieldName;

                    if (fieldsToMakeOptional.Contains(token.ToLowerInvariant()))
                    {
                        if (xml.Contains("<Tags>"))
                        {
                            throw new NotSupportedException();
                        }
                        if (xml.Contains("<IncludedColumn>"))
                        {
                            throw new NotSupportedException();
                        }

                        int endpos   = xml.IndexOf("</DataField>") + "</DataField>".Length;
                        int startPos = xml.LastIndexOf(Environment.NewLine, endpos);
                        int xmlPos   = xml.IndexOf("<DataField>");

                        string updatedInput = input.Insert(match.Index + endpos, xml.Substring(startPos, xmlPos - startPos) + "<Optional>Yes</Optional>");

                        string indexToken = "<Name>" + indexName + "</Name>";
                        int    indexPos   = updatedInput.IndexOf(indexToken);

                        int endpos2 = updatedInput.IndexOf("</IsSystemGenerated>", indexPos) + "</IsSystemGenerated>".Length;
                        if (endpos2 > indexPos)
                        {
                            int startPos2 = updatedInput.LastIndexOf(Environment.NewLine, endpos2);
                            int xmlPos2   = updatedInput.IndexOf("<IsSystemGenerated>", startPos2);

                            if (!updatedInput.Substring(indexPos, endpos2 - indexPos).Contains("IsManuallyUpdated"))
                            {
                                updatedInput = updatedInput.Insert(xmlPos2, "<IsManuallyUpdated>Yes</IsManuallyUpdated>" + updatedInput.Substring(startPos2, xmlPos2 - startPos2));
                            }
                        }
                        Hits++;
                        return(this.Run(updatedInput, match.Index + match.Length));
                    }
                    return(this.Run(input, match.Index + match.Length));
                }
            }

            return(input);
        }
        public string Run(string _input, int _startAt = 0)
        {
            Match match = xpoMatch.Match(_input, _startAt);

            if (match.Success)
            {
                string xml            = _input;
                var    stringToUpdate = match.Value;
                string methodName     = MetaData.extractPreviousXMLElement("Name", match.Index, _input);
                var    sourceFile     = Path.GetFileNameWithoutExtension(Scanner.FILENAME);
                _input = this.processSource(_input, stringToUpdate, sourceFile + "." + methodName);
                _input = this.Run(_input, match.Index + 1);
            }

            return(_input);
        }
Exemple #3
0
        private string AOTPath(string xml, int pos)
        {
            string         name    = MetaData.extractPreviousXMLElement("Name", pos, xml);
            Stack <string> paths   = MetaData.XMLPathToFirstToken(xml, "IsObsolete");
            string         path    = string.Empty;
            var            asArray = paths.ToArray();

            for (int i = asArray.Length - 2; i >= 0; i--)
            {
                path += "\\" + asArray[i];
            }
            if (path != string.Empty)
            {
                return(path + "\\" + name);
            }
            return(string.Empty);
        }
Exemple #4
0
        public string Run(string input, int startAt = 0)
        {
            Match match = xpoMatch.Match(input, startAt);

            if (match.Success)
            {
                string xml        = match.Value;
                string table1Name = match.Groups[1].Value.Trim();
                string field1Name = match.Groups[2].Value.Trim();
                string table2Name = match.Groups[3].Value.Trim();
                string field2Name = match.Groups[4].Value.Trim();

                methodName = MetaData.extractPreviousXMLElement("Name", match.Index, input);

                if (methodName.ToLowerInvariant() == "init")
                {
                    string dsxml = MetaData.extractPreviousXMLElement("DataSource", match.Index, input);
                    if (dsxml != string.Empty) // Not a datasource method
                    {
                        string dsName = MetaData.extractNextXMLElement("Name", 1, dsxml);
                        if (dsName == table1Name && dsName != table2Name)
                        {
                            string methodxml = MetaData.extractPreviousXMLElement("Source", match.Index, input).ToLowerInvariant();

                            if (!methodxml.Contains(".adddatasource"))
                            {
                                this.log("Possibly wrong order of parameters. " + xml);
                            }
                        }
                    }
                }

                return(this.Run(input, match.Index + match.Length));
            }

            return(input);
        }
        public string Run(string _input, int _startAt = 0)
        {
            Match match = xpoMatch.Match(_input, _startAt);

            if (match.Success)
            {
                string methodName = MetaData.extractPreviousXMLElement("Name", match.Index, _input);
                if (methodName != string.Empty)
                {
                    string  obsAttr       = match.Groups[0].Value.Trim();
                    Boolean isParamsGiven = obsAttr.IndexOf('(') < obsAttr.IndexOf(']');

                    if (!isParamsGiven)
                    {
                        obsAttr = obsAttr.Substring(0, obsAttr.IndexOf(']'));
                    }
                    else
                    {
                        int pos = this.findEndParanthesis(obsAttr);
                        if (pos == -1)
                        {
                            return(this.Run(_input, match.Index + 50));
                        }
                        obsAttr = obsAttr.Substring(0, pos);
                    }

                    //Already has a date
                    if (!obsAttr.Contains(@"\"))
                    {
                        string obsoleteDate = this.getDate(methodName);
                        if (obsoleteDate != string.Empty)
                        {
                            string newObsAttr = obsAttr.Trim();

                            if (!isParamsGiven)
                            {
                                newObsAttr += "(''";
                            }

                            if (!newObsAttr.ToLowerInvariant().EndsWith("false") &&
                                !newObsAttr.ToLowerInvariant().EndsWith("true"))
                            {
                                if (newObsAttr.Trim().ToLowerInvariant().EndsWith("'") ||
                                    newObsAttr.Trim().ToLowerInvariant().EndsWith("\""))
                                {
                                    newObsAttr += ", false";
                                }
                                else
                                {
                                    newObsAttr += "'', false";
                                }
                            }

                            newObsAttr += ", " + obsoleteDate;

                            if (!isParamsGiven)
                            {
                                newObsAttr += ")";
                            }

                            int attributePos = newObsAttr.ToLowerInvariant().IndexOf("sysobsoleteattribute");
                            if (attributePos > -1)
                            {
                                newObsAttr = newObsAttr.Remove(attributePos + "sysobsolete".Length, "attribute".Length);
                            }

                            int    pos          = _input.IndexOf(obsAttr, _startAt);
                            string updatedInput = _input.Remove(pos, obsAttr.Length);
                            updatedInput = updatedInput.Insert(pos, newObsAttr);
                            Hits++;
                            return(this.Run(updatedInput, match.Index + 50));
                        }
                    }
                }
                _input = this.Run(_input, match.Index + 50);
            }

            return(_input);
        }
        public string Run(string input, int startAt = 0)
        {
            Match match = xpoMatch.Match(input, startAt);

            if (match.Success)
            {
                string xml     = match.Value;
                string varName = match.Groups[1].Value.Trim();
                formName = match.Groups[2].Value.Replace('\"', ' ').Replace('\'', ' ').Trim();

                methodName = MetaData.extractPreviousXMLElement("Name", match.Index, input);

                if (MetaData.isCodeProtectedByMenuItem(input, match.Index))
                {
                    this.log("Clicked method protected by menu item.");
                    return(this.Run(input, match.Index + match.Length));;
                }

                if (xml.ToLowerInvariant().Contains(".menuitemname") ||
                    xml.ToLowerInvariant().Contains(".run(" + varName + ")"))
                {
                    this.log("Already uses menu item.");
                    return(this.Run(input, match.Index + match.Length));;
                }

                if (MetaData.isFormLookup(formName))
                {
                    this.log("Is lookup form");
                    return(this.Run(input, match.Index + match.Length));
                }

                if (MetaData.isFormDialog(formName))
                {
                    this.log("Is dialog form");
                    return(this.Run(input, match.Index + match.Length));
                }

                var datasources = MetaData.getFormRootDataSources(formName);

                if (datasources.Count == 0)
                {
                    this.log("Has no data sources");
                    return(this.Run(input, match.Index + match.Length));
                }

                bool allDatasourcesTmp = true;
                foreach (var table in datasources)
                {
                    if (MetaData.isTablePersisted(table))
                    {
                        allDatasourcesTmp = false;
                    }
                }

                if (allDatasourcesTmp)
                {
                    this.log("Only has temporary data sources");
                    return(this.Run(input, match.Index + match.Length));;
                }

                var menuItems = MetaData.getMenuItemsFromFormName(formName);
                if (menuItems.Count == 0)
                {
                    this.log("Has no menu item, but datasources: " + getMenuItemsAsString(datasources), "Warning");
                    return(this.Run(input, match.Index + match.Length));;
                }
                string menuItem = string.Empty;

                if (menuItems.Count == 1)
                {
                    menuItem = menuItems[0];
                    this.log("Has one menu item:" + menuItem + ", and datasources: " + getMenuItemsAsString(datasources), "Fixable");
                }

                if (menuItem == string.Empty && datasources.Count == 1)
                {
                    var formRef = MetaData.tableFormRef(datasources[0]);
                    if (formRef != string.Empty &&
                        menuItems.Contains(formRef))
                    {
                        if (MetaData.isFormUsingArgsMenuItemNameAndMenuItem(formName, formRef))
                        {
                            this.log("FormRef points to menu item, but form uses args.menuItemName() and menuitemdisplaystr(" + formRef + ")", "Warning");
                            return(this.Run(input, match.Index + match.Length));;
                        }
                        menuItem = formRef;
                        this.log("Has one data source with formRef: " + menuItem + ", and datasources: " + getMenuItemsAsString(datasources) + ", and menu items:" + getMenuItemsAsString(menuItems), "Fixable");
                    }
                }

                if (menuItem == string.Empty && menuItems.Contains(formName))
                {
                    menuItem = formName;
                    if (MetaData.isFormUsingArgsMenuItemName(formName))
                    {
                        this.log("Has multiple menu items:" + getMenuItemsAsString(menuItems) + ", and datasources: " + getMenuItemsAsString(datasources) + ", and form uses args.menuItemName().", "Warning");
                        return(this.Run(input, match.Index + match.Length));;
                    }
                    this.log("Updated. Has menu item with same name as form. Menu items:" + getMenuItemsAsString(menuItems) + ", and datasources: " + getMenuItemsAsString(datasources), "Fixable");
                }

                if (menuItem != string.Empty)
                {
                    int pos           = xml.IndexOf(';');
                    int nextLineStart = xml.ToLowerInvariant().IndexOfAny("abcdefghijklmnopqrstuvwxyz".ToCharArray(), pos);
                    if (nextLineStart > 0)
                    {
                        string whitespace = xml.Substring(pos, nextLineStart - pos);
                        xml = xml.Insert(nextLineStart, whitespace);
                        xml = xml.Insert(nextLineStart, varName + ".menuItemName(menuItemDisplayStr(" + menuItem + "))");
                        string updatedInput = input.Remove(match.Index, match.Length);
                        updatedInput = updatedInput.Insert(match.Index, xml);
                        Hits++;
                        return(this.Run(updatedInput, match.Index + match.Length));
                    }
                    else
                    {
                        this.log("Cannot update file due to format", "Error");
                    }
                }
                else
                {
                    this.log("Has multiple menu items:" + getMenuItemsAsString(menuItems) + ", and datasources: " + getMenuItemsAsString(datasources), "Warning");
                }

                return(this.Run(input, match.Index + match.Length));
            }

            return(input);
        }