private SldDMComponentItem GetComponentInfo(
            SwDMComponent9 currentComponent,
            int level,
            int parentId)
        {
            if (currentComponent == null || level < 0 || parentId <= 0)
            {
                return(null);
            }
            string             fullPath = currentComponent.PathName;;
            SldDMComponentItem item     = SldDMComponentItem.GenerateTheNext();

            item.ParentId = parentId;
            item.Level    = level;
            try
            {
                item.FullPath     = fullPath;
                item.FeatureName  = currentComponent.Name2;
                item.FeatureId    = currentComponent.GetID();
                item.IsSuppressed = currentComponent.IsSuppressed();
                item.FileName2D   = EngineeringDrawingFile.Get2DFileNameIfExisting(fullPath);
                item.Visible      = !currentComponent.IsHidden();

                SwDmDocumentOpenError openResult;
                SwDMDocument17        doc = currentComponent.GetDocument2(true, this.GlobalSearchOption, out openResult) as SwDMDocument17;
                if (doc == null || openResult != SwDmDocumentOpenError.swDmDocumentOpenErrorNone)
                {
                    Debug.WriteLine(string.Format("GetComponentInfo:couldn't open {0},the return value is:{1}", fullPath, openResult.ToString()));
                    return(null);
                }
                SwDMConfiguration14 config = doc.ConfigurationManager.GetConfigurationByName(currentComponent.ConfigurationName) as SwDMConfiguration14;

                if (File.Exists(fullPath))
                {
                    item.AllCustomProperties = GetDocumentPropertiesViaDM.RetrievePropertiesUnderConfig(
                        fullPath,
                        config,
                        GetDocumentPropertiesViaDM.PropertyNamesOftenUsed,
                        true);
                }

                item.ConfigurationCount = doc.ConfigurationManager.GetConfigurationCount();
                item.ChildrenCount      = doc.GetComponentCount();
                doc.CloseDoc();
                Marshal.ReleaseComObject(doc);
                this.CallbackGettingExtraInfo?.Invoke(ref item);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("GetComponentInfo:when dealing {0}, exception occurred:{1}", fullPath, ex.Message));
            }
            return(item);
        }
        private int GetCurrentComponentInfo(
            SwDMComponent9 currentComponent,
            string fullPath,
            int level,
            int parentId)
        {
            if (currentComponent == null || string.IsNullOrEmpty(fullPath) || level < 0 || parentId <= 0)
            {
                return(-1);
            }
            SldDMComponentItem item = SldDMComponentItem.GenerateTheNext();
            Task task = Task.Factory.StartNew(() =>
            {
                item.ParentId     = parentId;
                item.Level        = level;
                item.FullPath     = fullPath;
                item.FeatureName  = currentComponent.Name2;
                item.FeatureId    = currentComponent.GetID();
                item.IsSuppressed = currentComponent.IsSuppressed();
                item.FileName2D   = EngineeringDrawingFile.Get2DFileNameIfExisting(fullPath);
                item.Visible      = !currentComponent.IsHidden();

                try
                {
                    SwDmDocumentOpenError openResult;
                    SwDMDocument17 doc = currentComponent.GetDocument2(true, this.GlobalSearchOption, out openResult) as SwDMDocument17;
                    if (doc == null || openResult != SwDmDocumentOpenError.swDmDocumentOpenErrorNone)
                    {
                        Debug.WriteLine(string.Format("GetCurrentComponentInfo:couldn't open {0},the return value is :{1}", fullPath, openResult.ToString()));
                        return;
                    }
                    SwDMConfiguration14 config = doc.ConfigurationManager.GetConfigurationByName(currentComponent.ConfigurationName) as SwDMConfiguration14;

                    if (File.Exists(fullPath))
                    {
                        item.AllCustomProperties = GetDocumentPropertiesViaDM.RetrievePropertiesUnderConfig(
                            fullPath,
                            config,
                            GetDocumentPropertiesViaDM.PropertyNamesOftenUsed,
                            true);
                    }
                    item.ConfigurationCount = doc.ConfigurationManager.GetConfigurationCount();
                    item.ChildrenCount      = doc.GetComponentCount();
                    this.ResultsAtPopulating.Enqueue(item);
                    doc.CloseDoc();
                    Marshal.ReleaseComObject(doc);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("GetCurrentComponentInfo:when dealing {0}, exception occurred:{1}", fullPath, ex.Message));
                    return;
                }
                this.CallbackGettingExtraInfo?.Invoke(ref item);
                Debug.WriteLine(string.Format("GetCurrentComponentInfo:got [{0}] (ID={1})", fullPath, item.Id));
            });
            string           originalExt;
            SwDmDocumentType docType = SldFileExtentionChecker.CheckDM(fullPath, out originalExt);

            if (docType == SwDmDocumentType.swDmDocumentAssembly)
            {
                this.AllWalkingTasks.Enqueue(new ComponentAndTask_Assembly()
                {
                    ParentId = parentId,
                    TheTask  = task,
                    FullPath = fullPath,
                    Id       = item.Id
                });
            }
            else
            {
                this.AllWalkingTasks.Enqueue(new ComponentAndTask_Part()
                {
                    ParentId = parentId,
                    TheTask  = task,
                    FullPath = fullPath,
                    Id       = item.Id
                });
            }
            return(item.Id);
        }
        protected bool TraverseRecursively(SwDMComponent9 currentComponent, int level, int parentId)
        {
            if (currentComponent == null || level <= 0)
            {
                return(false);
            }
            try
            {
                string           fullPath         = currentComponent.PathName;
                ComponentAndTask componentAndTask = this.AllWalkingTasks.FirstOrDefault(x => (x is ComponentAndTask_Assembly) && string.Compare(fullPath, ((ComponentAndTask_Assembly)x).FullPath, true) == 0);
                if (componentAndTask != null)
                {
                    this.CopyFromPreviousSubAssembly(componentAndTask as ComponentAndTask_Assembly, level, parentId);
                    return(true);
                }
                int myId = this.GetCurrentComponentInfo(currentComponent, fullPath, level, parentId);
                Debug.WriteLine(string.Format("TraverseRecursively:will handle ID={0}:{1}", myId, fullPath));
                if (currentComponent.DocumentType == SwDmDocumentType.swDmDocumentAssembly)
                {
                    List <SwDMComponent9> componentsToTraverseInTasks = new List <SwDMComponent9>();
                    SwDmDocumentOpenError openResult;
                    SwDMDocument17        doc = currentComponent.GetDocument2(true, this.GlobalSearchOption, out openResult) as SwDMDocument17;
                    if (doc == null || openResult != SwDmDocumentOpenError.swDmDocumentOpenErrorNone)
                    {
                        Debug.WriteLine(string.Format("TraverseRecursively:failed to open{0}, return value is:{1}", fullPath, openResult.ToString()));
                        return(false);
                    }
                    SwDMConfigurationMgr swDMConfigurationMgr = doc.ConfigurationManager;
                    string             currentConfigName      = currentComponent.ConfigurationName;
                    SwDMConfiguration2 config        = swDMConfigurationMgr.GetConfigurationByName(currentConfigName) as SwDMConfiguration2;
                    object[]           allComponents = null;
                    try
                    {
                        object componentsRaw = config.GetComponents();
                        if (componentsRaw != null)
                        {
                            allComponents = (object[])componentsRaw;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(string.Format("TraverseRecursively:exception occurred when dealing {0}, exception message:{1}", fullPath, ex.Message));
                        return(false);
                    }
                    if (allComponents != null)
                    {
                        foreach (object o in allComponents)
                        {
                            SwDMComponent9 subComponent = o as SwDMComponent9;
                            //this.AllComObjects.Enqueue(subComponent);
                            if (subComponent.DocumentType == SwDmDocumentType.swDmDocumentAssembly)
                            {
                                this.TraverseRecursively(subComponent, level + 1, myId);
                            }
                            else
                            {
                                componentsToTraverseInTasks.Add(subComponent);
                            }
                        }
                    }

                    foreach (var v in componentsToTraverseInTasks)
                    {
                        string           subComponentPath    = v.PathName;
                        ComponentAndTask subComponentAndTask = this.AllWalkingTasks.FirstOrDefault(x => string.Compare(subComponentPath, x.FullPath, true) == 0);
                        if (componentAndTask != null)
                        {
                            this.CopyFromPreviousPart(componentAndTask as ComponentAndTask_Part, level, parentId);
                            return(true);
                        }
                        else
                        {
                            this.GetCurrentComponentInfo(v, subComponentPath, level + 1, myId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("TraverseRecursively:when getting an item under the parent ID={0} {1}, exception occurred:{2}", parentId, currentComponent.PathName, ex.Message));
            }
            return(true);
        }
        protected bool TraverseCore(string assemblyPath, string configurationName)
        {
            if (string.IsNullOrEmpty(assemblyPath))
            {
                return(false);
            }
            if (!File.Exists(assemblyPath))
            {
                return(false);
            }
            string           originalExt;
            SwDmDocumentType docType = SldFileExtentionChecker.CheckDM(assemblyPath, out originalExt);

            if (docType != SwDmDocumentType.swDmDocumentAssembly && docType != SwDmDocumentType.swDmDocumentPart)
            {
                return(false);
            }
            SwDMClassFactory swDMClassFactory = new SwDMClassFactory();
            //this.AllComObjects.Enqueue(swDMClassFactory);
            SwDMApplication swDMApp = swDMClassFactory.GetApplication(GetDocumentPropertiesViaDM.LinktronLicenseKey);

            this.GlobalSearchOption = swDMApp.GetSearchOptionObject();
            //this.AllComObjects.Enqueue(swDMApp);
            SwDmDocumentOpenError returnValue = 0;
            SwDMDocument17        swDoc       = (SwDMDocument17)swDMApp.GetDocument(assemblyPath, docType, true, out returnValue);

            if (swDoc == null || returnValue != SwDmDocumentOpenError.swDmDocumentOpenErrorNone)
            {
                return(false);
            }
            //this.AllComObjects.Enqueue(swDoc);
            SwDMConfigurationMgr dmConfigMgr = swDoc.ConfigurationManager;

            //this.AllComObjects.Enqueue(dmConfigMgr);
            string[] configurationNames = (string[])dmConfigMgr.GetConfigurationNames();
            if (configurationNames == null || configurationNames.Length <= 0)
            {
                return(false);
            }
            string configNameToOpen = null;

            if (string.IsNullOrEmpty(configurationName))
            {
                configNameToOpen = dmConfigMgr.GetActiveConfigurationName();
            }
            else
            {
                configNameToOpen = configurationName;
            }
            SwDMConfiguration14 activeCfg = (SwDMConfiguration14)dmConfigMgr.GetConfigurationByName(configNameToOpen);

            if (activeCfg == null)
            {
                return(false);
            }
            //this.AllComObjects.Enqueue(activeCfg);
            int topId = this.GetTopDocumentInfo(assemblyPath, swDoc, activeCfg);

            if (topId <= 0)
            {
                return(false);
            }

            if (docType == SwDmDocumentType.swDmDocumentAssembly)
            {
                try
                {
                    object[] allComponents = activeCfg.GetComponents();
                    if (allComponents != null)
                    {
                        foreach (object o in allComponents)
                        {
                            SwDMComponent9 subComponent = o as SwDMComponent9;
                            this.TraverseRecursively(subComponent, 1, topId);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(string.Format("TraverseCore:exception:{0}", ex.Message));
                }
            }
            return(true);
        }