/// <summary>
        /// Extract Pages from Project List
        /// </summary>
        /// <param name="ProjectPath"></param>
        /// <param name="Prefix"></param>
        public int GetAllProjectPages(string Prefix, string ProjectPath)
        {
            var path = Path.GetDirectoryName(ProjectPath);
            //get list of sub directories with project prefix
            var directories = Directory.GetDirectories(ProjectPath).Where(s => s.Contains(Prefix)).ToArray();
            //var searchList = Directory.GetFiles(path, "pages.dbf", SearchOption.AllDirectories).Where(s => s.Contains(Prefix));
            var errors = 0;

            //get list of pages in project
            foreach (var searchDir in directories)
            {
                try
                {
                    CitectPages.Clear();
                    GetProjectPages(string.Format("{0}\\pages.dbf", searchDir), false);
                    var pagelist  = new List <CitectPages>();
                    var directory = searchDir.Split(new char[] { '\\' });
                    pagelist.AddRange(CitectPages);
                    ProjectPages.Add(new ProjectPages {
                        ProjectName = directory[directory.Length - 1], PageList = pagelist
                    });
                }
                catch (Exception ex)
                {
                    log.Error("GetAllProjectPage:", ex);
                    errors++;
                }
            }

            var LogCsv = new LogCsv(@"C:\QR_PSCS\Logs\ProjectPages.csv", true);

            LogCsv.WriteToFile("Project,Citect Page,ANs");
            foreach (var projectPage in ProjectPages)
            {
                foreach (var citectPage in projectPage.PageList)
                {
                    LogCsv.WriteToFile("{0},{1},{2}", projectPage.ProjectName, citectPage.PageName, string.Empty);
                }
            }
            LogCsv.CloseFile();
            return(errors);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// setup the project dbfs.
        /// </summary>
        /// <param name="root"></param>
        /// <param name="projectprefix"></param>
        /// <returns></returns>
        public static bool FunctionRefExistInDBFs(string root, string projectprefix)
        {
            var path            = Path.GetDirectoryName(root);
            var searchList      = Directory.GetFiles(path, "*.dbf", SearchOption.AllDirectories);
            var dbflistToSearch = new Dictionary <string, string>();
            var dbfReadList     = new Dictionary <string, DbfTable>();

            foreach (var file in searchList)
            {
                if (!file.Contains(projectprefix) || file.Contains("_FUNCSYM") || file.Contains("_funcsym"))
                {
                    continue;
                }

                var tableName = file.Substring(file.LastIndexOf('\\'), file.IndexOf('.') - file.LastIndexOf('\\')).TrimStart(new char[] { '\\', '*', '?' });

                //exclude dbf in excluded list
                if (ExcludeDBF.Contains(tableName))
                {
                    continue;
                }

                //dbfReadList.Add(file, new DbfTable(file, System.Text.Encoding.UTF8));

                dbflistToSearch.Add(file, tableName);

                //update list of CicodeFunctions
                foreach (var listfunctions in cicodefunctions)
                {
                    foreach (var kvp in listfunctions.FunctionLocations)
                    {
                        if (!listfunctions.FunctionDBFReferences.ContainsKey(kvp.Value))
                        {
                            var metadetails = new List <CicodeMetaDetails>()
                            {
                                new CicodeMetaDetails {
                                    Name = tableName, ReferenceCount = 0
                                }
                            };
                            listfunctions.FunctionDBFReferences.Add(kvp.Value, metadetails);
                        }
                        else
                        {
                            var metadetails = listfunctions.FunctionDBFReferences[kvp.Value];
                            if (metadetails == null || !metadetails.Exists(s => s.Name == tableName))
                            {
                                metadetails.Add(new CicodeMetaDetails {
                                    Name = tableName, ReferenceCount = 0
                                });
                            }
                        }
                    }
                }
            }


            LogCsv = new LogCsv(@"C:\QR_PSCS\Logs\cicodefuncDBFRef.csv", true);
            LogCsv.WriteToFile("FunctionName,Path,DBF,References");
            foreach (var funcLoc in cicodefunctions)
            {
                foreach (var kvpfunc in funcLoc.FunctionLocations)  //key is the line number, value is the functionName
                {
                    var funcsearch = DateTime.UtcNow;
                    foreach (var kvp in dbflistToSearch)    //key is tablename, value is dbftable object
                    {
                        var tableName = kvp.Key.Substring(kvp.Key.LastIndexOf('\\'), kvp.Key.IndexOf('.') - kvp.Key.LastIndexOf('\\')).TrimStart(new char[] { '\\', '*', '?' });

                        var datettime = DateTime.UtcNow;
                        //var refcount = FunctionRefExistsInDBF(kvp.Value, kvpfunc.Value);
                        var refcount = FunctionRefExistsInDBF(kvp.Key, kvpfunc.Value);
                        var dbfmeta  = funcLoc.FunctionDBFReferences[kvpfunc.Value];
                        CicodeMetaDetails metaDetails = null;

                        //find from cicodemeta list in dbf references
                        if (funcLoc.FunctionDBFReferences.ContainsKey(kvpfunc.Value))
                        {
                            metaDetails = dbfmeta.FirstOrDefault(s => s.Name == tableName);
                        }

                        if (metaDetails == null)
                        {
                            log.DebugFormat("unable to locate {0}", kvpfunc.Value);
                            continue;
                        }

                        if (refcount > 0)
                        {
                            metaDetails.ReferenceCount += refcount;
                        }

                        LogCsv.WriteToFile("{0},{1},{2},{3}", kvpfunc.Value, kvp.Key, metaDetails.Name, metaDetails.ReferenceCount);

                        //log.DebugFormat("time to search dbf {0}-{1}", metaDetails.Name, DateTime.UtcNow.Subtract(datettime).TotalMilliseconds);
                    }
                    log.DebugFormat("Total time:{0} - dbfs {1} for {2} ", DateTime.UtcNow.Subtract(funcsearch).TotalMilliseconds, dbflistToSearch.Count, kvpfunc.Value);
                }
            }

            //release all resources
            //foreach (var kvp in dbfReadList)
            //    kvp.Value.Dispose();

            LogCsv.CloseFile();
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// find the functions that exist in Cicode
        /// </summary>
        public static void FunctionRefExistInCicode()
        {
            var cicodefilelist = cicodefunctions.Select(a => new { a.FileName }).ToList();


            foreach (var funcLoc in cicodefunctions)
            {
                //search against all list cicode file contents for function ref.
                foreach (var kvp in funcLoc.FunctionLocations)
                {
                    foreach (var file in cicodefilelist)
                    {
                        //open the file stream
                        //check function against file stream
                        var found   = 0;
                        var lineNum = 1;
                        //get file name
                        var ciFile = file.FileName.Substring(file.FileName.LastIndexOf('\\'), file.FileName.IndexOf('.') - file.FileName.LastIndexOf('\\')).TrimStart(new char[] { '\\', '*', '?' });
                        using (var streamReader = new StreamReader(file.FileName))
                        {
                            while (!streamReader.EndOfStream)
                            {
                                //for debugging only
                                //if (funcLoc.FileName.Contains("multimonitors") && file.FileName.Contains("multimonitors"))
                                //    if (lineNum == 1148 && kvp.Value.Contains("_MMNumPadKey0"))
                                //        log.Debug("stop test");

                                try
                                {
                                    var line = streamReader.ReadLine().Trim();
                                    if (string.IsNullOrEmpty(line) || line.StartsWith("//") || line.Contains("FUNCTION") || line.EndsWith("*/") || line.StartsWith("/*") || line.StartsWith("!"))
                                    {
                                        lineNum++;
                                        continue;
                                    }

                                    //use pattern recognition
                                    if (Regex.IsMatch(line, string.Format(@"(?<=^([^\""]|\""[^\""]*\"")*)\b{0}\b", kvp.Value)))
                                    {
                                        if (funcLoc.FileName.Equals(file.FileName) && lineNum.Equals(kvp.Key))
                                        {
                                            lineNum++;
                                            continue;
                                        }

                                        found++;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    log.Error("streamreader:error", ex);
                                }
                                lineNum++;
                            }
                        }

                        if (found > 0)
                        {
                            //locate function in the reference
                            if (funcLoc.FunctionCicodeReferences.ContainsKey(kvp.Value))
                            {
                                var result   = funcLoc.FunctionCicodeReferences[kvp.Value];
                                var metadata = result.Find(s => s.Name.Equals(ciFile));
                                if (metadata != null)
                                {
                                    metadata.ReferenceCount += found;
                                }
                                else
                                {
                                    result.Add(new CicodeMetaDetails {
                                        Name = ciFile, ReferenceCount = found
                                    });
                                }
                            }
                            else
                            {
                                var metadata = new List <CicodeMetaDetails> {
                                    new CicodeMetaDetails {
                                        Name = ciFile, ReferenceCount = found
                                    }
                                };
                                funcLoc.FunctionCicodeReferences.Add(kvp.Value, metadata);
                            }
                        }
                    }
                }
            }

            LogCsv = new LogCsv(@"C:\QR_PSCS\Logs\FuncRefInCicode.csv", true);
            LogCsv.WriteToFile("cicodeFile,Function Name,cicode File,References");
            foreach (var funcLoc in cicodefunctions)
            {
                //search against all list cicode file contents for function ref.
                var ciFile = funcLoc.FileName.Substring(funcLoc.FileName.LastIndexOf('\\'), funcLoc.FileName.IndexOf('.') - funcLoc.FileName.LastIndexOf('\\')).TrimStart(new char[] { '\\', '*', '?' });

                foreach (var kvp in funcLoc.FunctionLocations)
                {
                    //get value of kvp.value from dictionary
                    if (funcLoc.FunctionCicodeReferences.ContainsKey(kvp.Value))
                    {
                        var metaDetails = funcLoc.FunctionCicodeReferences[kvp.Value];
                        metaDetails.ForEach(s => LogCsv.WriteToFile("{0},{1},{2},{3}", ciFile, kvp.Value, s.Name, s.ReferenceCount));
                    }
                    else
                    {
                        LogCsv.WriteToFile("{0},{1},{2},{3}", ciFile, kvp.Value, "", 0);
                    }
                }
            }

            LogCsv.CloseFile();
            //foreach function check existance in all cicode files?

            //get filepath into list
            //foreach function open file and check existance in that cicode file.
            //ignore lines where it begins with // or /* or */
        }