示例#1
0
        private void AddDependantTaxonomy(string filename, string hintpath, string ns, ref int myErrors)
        {
            // compare against ourself
            if (string.Compare(filename, schemaFilename, true) == 0)
            {
                throw new AucentFatalException("XBRLParser.Error.RecursiveTaxonomies");
            }

            string fileNameWithoutPath = Path.GetFileName(filename);

            int index = allFiles.BinarySearch(fileNameWithoutPath);
            if (index >= 0 || IsDependentTaxonomyLoaded(fileNameWithoutPath))
            {
                Console.WriteLine("Taxonomy.GetDependantTaxonomies (" + schemaFile + "): Skip: " + fileNameWithoutPath);
                return; //nothing to add as the file is already loaded.
            }

            if (TaxonomyCacheManager != null)
            {
                Taxonomy depTax = TaxonomyCacheManager.GetTaxonomyByFileName(fileNameWithoutPath);

                if (depTax != null)
                {
                    allFiles.Insert(~index, fileNameWithoutPath);

                    //we found the dependant taxonomy in the cache .. we need to copy it to
                    // make sure that we are not messing with the original
                    Taxonomy copyToAdd = depTax.CopyTaxonomyForMerging();
                    if (copyToAdd.allFiles != null)
                    {
                        this.allFiles.AddRange(copyToAdd.allFiles);
                        this.allFiles.Sort();
                    }
                    dependantTaxonomies.Add(copyToAdd);
                    dependantTaxonomyFilenames.Add(copyToAdd.schemaFilename);

                    return;
                }

            }
            string fn = filename;
            string schemaFolder = schemaPath.Replace("\\", "/");
            if (!schemaFolder.EndsWith("/"))
            {
                schemaFolder = schemaFolder + "/";
            }

            if (hintpath != null)
            {
                hintpath = hintpath.Replace("\\", "/");
            }
            //hint could be relative.. in which case we need to combine it with the
            //schema location of the taxonomy...
            if (hintpath == null || hintpath.Length == 0 || hintpath.StartsWith("..") || hintpath.StartsWith("/"))
            {
                if (hintpath != null && hintpath.Length > 0)
                {
                    fn = schemaFolder + hintpath + "/" + filename;
                }
                else
                {
                    fn = schemaFolder +  filename;

                }
            }
            else if (hintpath != null )
            {
                if (hintpath.EndsWith("/"))
                {
                    fn = hintpath  + filename;

                }
                else
                {

                    fn = hintpath + "/" + filename;
                }
            }

            bool local = false;

            DateTime lastModified = DateTime.MinValue;
            bool URLExists;
            Dictionary<string, bool> filesAlreadyChecked = new Dictionary<string, bool>();
            bool isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
            filesAlreadyChecked[fn] = true;
            if (!isValid && Directory.Exists(schemaFolder))
            {
                fn = schemaFolder + "/" + filename;
                isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                filesAlreadyChecked[fn] = true;

                if (!isValid)
                {
                    fn = schemaFolder + hintpath + "/" + filename;
                    isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                    filesAlreadyChecked[fn] = true;

                }
            }

            while (true )
            {

                #region Check other locations if we cannot find the file in the location it is supposed to be in

                //check the following locations
                //ns + filename
                //hintpath + file name
                //parent location + hint path + filename
                //parent location + filename
                //current schema path + hint path + file name
                //current schema path + file name
                //ns + hint path + filename
                //just file name
                //isolated storage
                bool localPromptUser = false;

                if( !isValid)
                {
                    //hintpath + file name
                    fn = Aucent.MAX.AXE.Common.Utilities.AucentGeneral.AppendFileNameToSchemaPath(hintpath, filename);
                    if (!filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }
                }

                if (!isValid)
                {
                    //parent location + hint path + filename
                    fn = Aucent.MAX.AXE.Common.Utilities.AucentGeneral.AppendFileNameToSchemaPath(schemaPath + hintpath, filename);
                    if (!filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }
                }
                if (!isValid)
                {
                    //parent location + filename
                    fn = Aucent.MAX.AXE.Common.Utilities.AucentGeneral.AppendFileNameToSchemaPath(schemaPath, filename);
                    if (!filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }
                }
                if (!isValid)
                {
                    //ns + filename
                    fn = Aucent.MAX.AXE.Common.Utilities.AucentGeneral.AppendFileNameToSchemaPath(ns, filename);
                    if (!isValid && !filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }
                }

                if (!isValid)
                {
                    //current schema path + hint path + file name
                    string path2 = string.Empty;

                    if (local)
                        path2 = schemaPath + Path.DirectorySeparatorChar + hintpath;
                    else
                        path2 = schemaPath + "/" + hintpath;

                    fn = Aucent.MAX.AXE.Common.Utilities.AucentGeneral.AppendFileNameToSchemaPath(path2, filename);
                    if (!filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }
                }
                if (!isValid)
                {
                    //current path + filename try -
                    fn = Aucent.MAX.AXE.Common.Utilities.AucentGeneral.AppendFileNameToSchemaPath(schemaPath, filename);
                    if (!filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }
                }
                if (!isValid)
                {
                    //ns + hint path + filename
                    string path2 = string.Empty;
                    if (local)
                        path2 = ns + Path.DirectorySeparatorChar + hintpath;
                    else
                        path2 = ns + "/" + hintpath;

                    fn = Aucent.MAX.AXE.Common.Utilities.AucentGeneral.AppendFileNameToSchemaPath(path2, filename);
                    if (!filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }
                }
                if (!isValid)
                {
                    fn = filename;
                    if (!filesAlreadyChecked.ContainsKey(fn))
                    {
                        isValid = ValidateFileExistance(fn, false, out local, out fn, out lastModified, out  URLExists);
                        filesAlreadyChecked[fn] = true;
                    }

                }

                if (!isValid)
                {
                    localPromptUser = true;
                    // don't bother to test this one - we're done trying
                    fn = filename;

                }

                Console.WriteLine("Taxonomy.GetDependantTaxonomies (" + schemaFile + "): Load: " + fn);
                #endregion

                Taxonomy t = new Taxonomy(true);
                t.PromptUser = this.PromptUser;
                t.OwnerHandle = OwnerHandle;
                //set the loading tax to the current tax or its loading tax object...
                t.loadingTaxonomy = GetLoadingTaxonomy();

                // continue adding all files
                t.allFiles = allFiles;
                if (this.TopLevelTaxonomy != null)
                {
                    t.TopLevelTaxonomy = this.TopLevelTaxonomy;
                }
                else
                {
                    t.TopLevelTaxonomy = this;
                }

                try
                {
                    if (t.Load(fn, localPromptUser && t.PromptUser ) != 0)
                    {

                        if (!localPromptUser)
                        {
                            //we found a valid file that does not exist....
                            //lets see if we can find a different file this time
                            continue;
                        }
                        else
                        {
                            Common.WriteError("XBRLParser.Error.CantLoadFilename", errorList, fn, " to find the file");
                            ++myErrors;
                            string errorMsg = null;
                            if (errorList != null && errorList.Count > 0)
                            {
                                errorMsg = errorList[errorList.Count - 1] as string;

                                if (errorMsg == null && errorList[errorList.Count - 1] is ParserMessage)
                                {
                                    ParserMessage msg = errorList[errorList.Count - 1] as ParserMessage;
                                    if (msg != null)
                                    {
                                        errorMsg = msg.Message;
                                    }
                                }

                            }
                            else
                            {
                                errorMsg = string.Format("Failed to load file {0}.", fn);
                            }
                            throw new AucentFatalException(errorMsg);

                        }
                    }
                }
                catch (XmlException xe)
                {
                    Common.WriteError("XBRLParser.Error.CantLoadFilename", errorList, fn, xe.Message);
                    ++myErrors;
                    return;
                }

                if (BuildTaxonomyRelationship)
                {
                    if (DirectDependantTaxonomies == null) DirectDependantTaxonomies = new List<string>();
                    if (!DirectDependantTaxonomies.Contains(fn))
                    {
                        DirectDependantTaxonomies.Add(fn);
                    }
                }

                allFiles.Insert(~index, fileNameWithoutPath);

                dependantTaxonomyFilenames.Add(fn);
                dependantTaxonomies.Add(t);

                int errors = t.LoadDependantTaxonomies(t.schemaPath);

                dependantTaxonomies.AddRange(t.dependantTaxonomies);
                dependantTaxonomyFilenames.AddRange(t.dependantTaxonomyFilenames);

                if (errors > 0)
                {
                    errorList.Add(t.errorList);
                    myErrors += errors;
                }

                break;
            }
        }