Esempio n. 1
0
        private static bool GetReferencedFiles(IEdmVault5 vault, IEdmReference10 reference, string filePath, string projectName, ref List <string> refFiles)
        {
            try
            {
                bool bTop = false;
                if (reference == null)
                {
                    bTop = true;
                    SWFileType type = GetSWFileType(filePath);
                    if (type != SWFileType.UNKNOWN)
                    {
                        refFiles.Add(filePath);
                        IEdmFile5   edmFile;
                        IEdmFolder5 edmFolder = null;
                        if (!GetFileFromPath(vault, filePath, out edmFile, out edmFolder))
                        {
                            return(false);
                        }
                        reference = (IEdmReference10)edmFile.GetReferenceTree(edmFolder.ID);
                        if (type == SWFileType.ASSEMBLY)    //装配体递归
                        {
                            GetReferencedFiles(vault, reference, "", projectName, ref refFiles);
                        }
                    }
                }
                else
                {
                    IEdmPos5 pos = default(IEdmPos5);
                    pos = reference.GetFirstChildPosition3(projectName, bTop, true, (int)EdmRefFlags.EdmRef_File, "", 0);
                    while ((!pos.IsNull))
                    {
                        IEdmReference10 @ref = (IEdmReference10)reference.GetNextChild(pos);
                        SWFileType      type = GetSWFileType(@ref.FoundPath);
                        if (type != SWFileType.UNKNOWN)
                        {
                            if (!refFiles.Contains(@ref.FoundPath))
                            {
                                refFiles.Add(@ref.FoundPath);
                                if (type == SWFileType.ASSEMBLY)    //装配体递归
                                {
                                    GetReferencedFiles(vault, @ref, "", projectName, ref refFiles);
                                }
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public void GetReferencedFiles(IEdmReference10 Reference, string FilePath, int Level, string ProjectName, ref Dictionary <string, string> RefFilesDictionary)
        {
            try
            {
                bool Top = false;
                if (Reference == null)
                {
                    //This is the first time this function is called for this
                    //reference tree; i.e., this is the root
                    Top = true;
                    //Add the top-level file path to the dictionary
                    RefFilesDictionary.Add(FilePath, Level.ToString());
                    IEdmFile5   File         = null;
                    IEdmFolder5 ParentFolder = null;
                    File = vault1.GetFileFromPath(FilePath, out ParentFolder);
                    //Get the reference tree for this file
                    Reference = (IEdmReference10)File.GetReferenceTree(ParentFolder.ID);
                    GetReferencedFiles(Reference, "", Level + 1, ProjectName, ref RefFilesDictionary);
                }
                else
                {
                    //Execute this code when this function is called recursively;
                    //i.e., this is not the top-level IEdmReference in the tree

                    //Recursively traverse the references
                    IEdmPos5        pos        = default(IEdmPos5);
                    IEdmReference10 Reference2 = (IEdmReference10)Reference;
                    pos = Reference2.GetFirstChildPosition3(ProjectName, Top, true, (int)EdmRefFlags.EdmRef_File, "", 0);
                    IEdmReference10 @ref = default(IEdmReference10);
                    while ((!pos.IsNull))
                    {
                        @ref = (IEdmReference10)Reference.GetNextChild(pos);
                        RefFilesDictionary.Add(@ref.FoundPath, Level.ToString());
                        GetReferencedFiles(@ref, "", Level + 1, ProjectName, ref RefFilesDictionary);
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }