Пример #1
0
        /// <summary>
        /// Method to check whether a search path on a project
        /// contains the image path passed as a parameter to the application
        /// </summary>
        /// <param name="p_strPath">Path of the image folder to search for</param>
        /// <returns></returns>
        public bool CheckSearchFolder(string p_strPath)
        {
            XmlDocument m_xmlProj = new XmlDocument();

            try
            {
                m_xmlProj.Load(ProjectPath);
                XmlNode m_xmlSearchPath = m_xmlProj.SelectSingleNode(Constants.IMG_PROJECT_XPATH_SEARCHPATH);
                if (m_xmlSearchPath != null)
                {
                    string[] m_strFolders = m_xmlSearchPath.InnerText.Split(new[] { Constants.IMG_SEPARATOR_SPLIT_CHAR }, StringSplitOptions.RemoveEmptyEntries);
                    if (m_strFolders.Length > 0)
                    {
                        foreach (string m_strSearchPath in m_strFolders)
                        {
                            string m_strCombinedPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ProjectPath), m_strSearchPath));
                            if (m_strCombinedPath.Equals(p_strPath, StringComparison.OrdinalIgnoreCase))
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (FileNotFoundException p_exNotFound)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_SEARCH_NOT_FOUND, ProjectPath, p_exNotFound.Message));
            }
            catch (IOException p_exIO)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_SEARCH_IO_EXCEPTION, ProjectPath, p_exIO.Message));
            }
            catch (XmlException p_exXml)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_SEARCH_XML_EXCEPTION, ProjectPath, p_exXml.Message));
            }
            catch (XPathException p_exXPath)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_SEARCH_XPATH_EXCEPTION, ProjectPath, p_exXPath.Message));
            }
            return(false);
        }
Пример #2
0
 static void Main(string[] args)
 {
     //This program must receive two arguments,
     //a path to a folder to search for documentation projects
     //and a full path to an image file
     if (args.Length == Constants.IMG_ARG_VALID_COUNT)
     {
         ImageSearch m_isSearch = new ImageSearch(args[Constants.IMG_ARG_PATH_NAME_INDEX], args[Constants.IMG_ARG_IMAGE_NAME_INDEX]);
         m_isSearch.LoadProjects();
         m_isSearch.SearchForImageOnTopics();
     }
     else
     {
         GlobalResult.LogErrorAndQuit(Constants.IMG_PROG_MSG_INVALID_ARG);
     }
 }
Пример #3
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="p_strBasePath">A base path to start searching for</param>
 /// <param name="p_strImageName">A full path to an image file to search for</param>
 public ImageSearch(string p_strBasePath, string p_strImageName)
 {
     if (String.IsNullOrEmpty(p_strBasePath))
     {
         GlobalResult.LogErrorAndQuit(Constants.IMG_SEARCH_MSG_ERROR_BASE_NULL_EMPTY);
     }
     else
     {
         if (Directory.Exists(p_strBasePath))
         {
             BasePath = p_strBasePath;
         }
         else
         {
             GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_SEARCH_MSG_ERROR_BASE_DOES_NOT_EXIST, p_strBasePath));
         }
     }
     if (String.IsNullOrEmpty(p_strImageName))
     {
         GlobalResult.LogErrorAndQuit(Constants.IMG_SEARCH_MSG_ERROR_IMG_NULL_EMPTY);
     }
     else
     {
         if (File.Exists(p_strImageName))
         {
             if (IsValidImageName(Path.GetFileName(p_strImageName)))
             {
                 ImageName = Path.GetFileName(p_strImageName);
                 ImagePath = String.Format(Constants.IMG_SEARCH_PROJECT_IMAGE_FOLDER, Path.GetDirectoryName(p_strImageName));
             }
             else
             {
                 GlobalResult.LogErrorAndQuit(Constants.IMG_SEARCH_MSG_ERROR_IMG_INVALID);
             }
         }
         else
         {
             GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_SEARCH_MSG_ERROR_BASE_IMG_DOES_NOT_EXIST, p_strImageName));
         }
     }
     Projects = new List <Project>();
     GlobalResult.NumberOfReferences = 0;
     ExecutionTime = new Stopwatch();
     ExecutionTime.Start();
 }
Пример #4
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="p_strPath">Full path of a topic file</param>
 public Topic(string p_strPath)
 {
     if (String.IsNullOrEmpty(p_strPath))
     {
         GlobalResult.LogErrorAndQuit(Constants.IMG_TOPIC_MSG_ERROR_NULL_EMPTY);
     }
     else
     {
         if (File.Exists(p_strPath))
         {
             TopicPath = p_strPath;
         }
         else
         {
             GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_TOPIC_MSG_ERROR_DOES_NOT_EXIST, p_strPath));
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Method to load all projects found on the base path
        /// </summary>
        public void LoadProjects()
        {
            GlobalResult.LogGeneralMessage(Constants.IMG_SEARCH_MSG_START_APP);
            GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_START_BASE_DIR, BasePath));
            GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_START_BASE_IMAGE_DIR, ImagePath));
            GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_START_IMAGE_NAME, ImageName));
            GlobalResult.LogGeneralMessage(Constants.IMG_SEARCH_MSG_START_LOADING_PROJECT);
            IEnumerable <string> m_lstProjects;

            try
            {
                m_lstProjects = Directory.EnumerateFileSystemEntries(BasePath, Constants.IMG_SEARCH_PROJECT_EXTENSION, SearchOption.AllDirectories);
                if (m_lstProjects.Count() > 0)
                {
                    foreach (string m_strProject in m_lstProjects)
                    {
                        Project m_prjProject = new Project(m_strProject);
                        if (m_prjProject.CheckSearchFolder(ImagePath))
                        {
                            Projects.Add(m_prjProject);
                        }
                    }
                    GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_PROJECT_FOUND, m_lstProjects.Count(), Projects.Count()));
                }
                else
                {
                    GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_SEARCH_MSG_ERROR_NO_PROJECT, BasePath));
                }
            }
            catch (ArgumentException m_exArg)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_SEARCH_MSG_ERROR_ARG_EXCEPTION, BasePath, m_exArg.Message));
            }
            catch (DirectoryNotFoundException m_exDirNotFound)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_SEARCH_MSG_ERROR_DIR_EXCEPTION, BasePath, m_exDirNotFound.Message));
            }
            catch (IOException m_exIO)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_SEARCH_MSG_ERROR_IO_EXCEPTION, BasePath, m_exIO.Message));
            }
        }
Пример #6
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="p_strPath">Project path</param>
 public Project(string p_strPath)
 {
     if (String.IsNullOrEmpty(p_strPath))
     {
         GlobalResult.LogErrorAndQuit(Constants.IMG_PROJECT_MSG_ERROR_NULL_EMPTY);
     }
     else
     {
         if (File.Exists(p_strPath))
         {
             ProjectPath   = p_strPath;
             ProjectMap    = String.Format(Constants.IMG_PROJECT_MAP_FULL_PATH, Directory.GetParent(ProjectPath).FullName);
             ProjectTopics = String.Format(Constants.IMG_PROJECT_TOPIC_PATH, Directory.GetParent(ProjectPath).FullName);
         }
         else
         {
             GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_DOES_NOT_EXIST, p_strPath));
         }
     }
     Topics = new List <Topic>();
 }
Пример #7
0
 /// <summary>
 /// Method to search for an image file on all topics
 /// of all projects found on the base path
 /// </summary>
 public void SearchForImageOnTopics()
 {
     GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_START_SEARCH_IMAGE, ImageName));
     foreach (Project m_prj in Projects)
     {
         m_prj.LoadTopics();
         m_prj.SearchImageOnTopics(ImageName);
     }
     GlobalResult.LogSeparator();
     if (GlobalResult.NumberOfReferences > 0)
     {
         GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_REFERENCE_FOUND, GlobalResult.NumberOfReferences));
     }
     else
     {
         GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_NO_REFERENCE_FOUND, ImageName));
     }
     ExecutionTime.Stop();
     GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_SEARCH_MSG_EXECUTION_TIME, ExecutionTime.Elapsed.Hours, ExecutionTime.Elapsed.Minutes, ExecutionTime.Elapsed.Seconds, ExecutionTime.Elapsed.Milliseconds));
     GlobalResult.SaveLogFile();
 }
Пример #8
0
        /// <summary>
        /// Method to search for an image file on a topic file
        /// </summary>
        /// <param name="p_strImage">Name of an image file, without a path</param>
        public void SearchForImage(string p_strImage)
        {
            XmlDocument m_xmlTopic = new XmlDocument();

            try
            {
                m_xmlTopic.Load(TopicPath);
                XmlNodeList m_xmlImages = m_xmlTopic.SelectNodes(String.Format(Constants.IMG_TOPIC_XPATH_IMAGE_SRC, p_strImage));
                if (m_xmlImages.Count > 0)
                {
                    if (m_xmlImages.Count == 1)
                    {
                        GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_TOPIC_MSG_IMAGE_FOUND_SINGLE, m_xmlImages.Count, p_strImage, TopicPath));
                    }
                    else
                    {
                        GlobalResult.LogGeneralMessage(String.Format(Constants.IMG_TOPIC_MSG_IMAGE_FOUND_MANY, m_xmlImages.Count, p_strImage, TopicPath));
                    }
                    GlobalResult.NumberOfReferences += m_xmlImages.Count;
                }
            }
            catch (FileNotFoundException m_exNotFound)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_TOPIC_MSG_ERROR_FILE_NOT_FOUND, TopicPath, m_exNotFound.Message));
            }
            catch (IOException m_exIO)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_TOPIC_MSG_ERROR_IO_EXCEPTION, TopicPath, m_exIO.Message));
            }
            catch (XmlException m_exXml)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_TOPIC_MSG_ERROR_XML_EXCEPTION, TopicPath, m_exXml.Message));
            }
            catch (XPathException m_exXPath)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_TOPIC_MSG_ERROR_XPATH_EXCEPTION, TopicPath, m_exXPath.Message));
            }
        }
Пример #9
0
        /// <summary>
        /// Method to load all topics from this project
        /// </summary>
        public void LoadTopics()
        {
            XmlDocument m_xmlToc = new XmlDocument();

            try
            {
                m_xmlToc.Load(ProjectMap);
                XmlNodeList m_xmlTopics = m_xmlToc.SelectNodes(Constants.IMG_PROJECT_XPATH_TOPICREF);
                if (m_xmlTopics.Count > 0)
                {
                    foreach (XmlNode m_xmlTopic in m_xmlTopics)
                    {
                        string m_strHref      = m_xmlTopic.Attributes.GetNamedItem(Constants.IMG_PROJECT_TOPIC_ATTR_HREF).Value;
                        string m_strTopicPath = String.Format(Constants.IMG_PROJECT_TOPIC_FULL_PATH, ProjectTopics, m_strHref);
                        Topic  m_tpcTopic     = new Topic(m_strTopicPath);
                        Topics.Add(m_tpcTopic);
                    }
                }
            }
            catch (FileNotFoundException m_exNotFound)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_MAP_NOT_FOUND, ProjectMap, m_exNotFound.Message));
            }
            catch (IOException m_exIO)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_IO_EXCEPTION, ProjectMap, m_exIO.Message));
            }
            catch (XmlException m_exXml)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_XML_EXCEPTION, ProjectMap, m_exXml.Message));
            }
            catch (XPathException m_exXPath)
            {
                GlobalResult.LogErrorAndQuit(String.Format(Constants.IMG_PROJECT_MSG_ERROR_XPATH_EXCEPTION, ProjectMap, m_exXPath.Message));
            }
        }