示例#1
0
        private bool SetSaveAs(string value, string setter)
        {
            try
            {
                this.SaveAs = (Filing.SaveAs)Enum.Parse(typeof(Filing.SaveAs), value);
                executor.Invoke(setter + ": Setting `" + SAVEAS_COMMAND + "` to `" + value + "`.");
                return(true);
            }
            catch { }

            string[] expected = Enum.GetNames(typeof(Filing.SaveAs));
            executor.Invoke(setter + ": Ignoring parameter `" + SAVEAS_COMMAND + "`.  Reason: unrecognized value `" + value + "`" + separator +
                            "\tExpected one of the following: " + string.Join(", ", expected));
            return(false);
        }
示例#2
0
        private bool SetSaveAs(string value, string setter)
        {
            try
            {
                this.SaveAs = (Filing.SaveAs)Enum.Parse(typeof(Filing.SaveAs), value);
                Console.WriteLine(setter + ": Setting '" + SAVEAS_COMMAND + "' to '" + value + "'.");
                return(true);
            }
            catch { }

            string[] expected = Enum.GetNames(typeof(Filing.SaveAs));
            Console.WriteLine(setter + ": Ignoring parameter '" + SAVEAS_COMMAND + "'.  Reason: unrecognized value '" + value + "'" + Environment.NewLine +
                              "\tExpected one of the following: " + string.Join(", ", expected));
            return(false);
        }
示例#3
0
        private bool GetOutputPath(string basePath, Filing.SaveAs saveAs, bool isMultiple, Filing f, out string outputPath)
        {
            outputPath = null;

            if (Path.IsPathRooted(this.ReportsFolder))
            {
                if (!Directory.Exists(this.ReportsFolder))
                {
                    executor.Invoke("Error: The ReportsFolder does not exist at " + this.ReportsFolder + ".");
                    executor.Invoke("\tSkipping filing: " + f.InstancePath);
                    return(false);
                }

                string tmpPath = this.ReportsFolder.TrimEnd('\\');
                if (string.Equals(basePath, tmpPath, StringComparison.CurrentCultureIgnoreCase))
                {
                    executor.Invoke("Error: The ReportsFolder matches the Filing folder:");
                    executor.Invoke("\tReportsFolder: " + this.ReportsFolder);
                    executor.Invoke("\tFiling folder: " + basePath);
                    executor.Invoke("\tSkipping filing: " + f.InstancePath);
                    return(false);
                }

                if (saveAs == Filing.SaveAs.Xml)
                {
                    string xmlPath = Path.Combine(this.ReportsFolder, Path.GetFileNameWithoutExtension(f.InstancePath));
                    if (!this.CleanOrCreateReportsPath(xmlPath, f))
                    {
                        return(false);
                    }

                    outputPath = xmlPath;
                    return(true);
                }
                else
                {
                    string zipPath = Path.Combine(this.ReportsFolder, Path.GetFileNameWithoutExtension(f.InstancePath) + ".zip");
                    if (!this.CleanOrOverwriteFile(zipPath, f))
                    {
                        return(false);
                    }

                    outputPath = zipPath;
                    return(true);
                }
            }
            else
            {
                if (saveAs == Filing.SaveAs.Xml)
                {
                    string xmlPath = Path.Combine(basePath, this.ReportsFolder);
                    if (!Directory.Exists(xmlPath))
                    {
                        Directory.CreateDirectory(xmlPath);
                    }

                    if (isMultiple)
                    {
                        xmlPath = Path.Combine(xmlPath, Path.GetFileNameWithoutExtension(f.InstancePath));
                    }

                    if (!this.CleanOrCreateReportsPath(xmlPath, f))
                    {
                        return(false);
                    }

                    outputPath = xmlPath;
                    return(true);
                }
                else
                {
                    string zipPath = Path.Combine(basePath, this.ReportsFolder);
                    if (!Directory.Exists(zipPath))
                    {
                        Directory.CreateDirectory(zipPath);
                    }

                    zipPath = Path.Combine(zipPath, Path.GetFileNameWithoutExtension(f.InstancePath) + ".zip");
                    if (!this.CleanOrOverwriteFile(zipPath, f))
                    {
                        return(false);
                    }

                    outputPath = zipPath;
                    return(true);
                }
            }
        }
示例#4
0
        public void ProcessFiling(Filing f, bool isMultipleFilings)
        {
            executor.Invoke("Information: Preparing " + f.InstancePath);

            if (!File.Exists(f.InstancePath))
            {
                executor.Invoke("Error: Instance document not found at " + f.InstancePath + ".");
                executor.Invoke("\tSkipping filing: " + f.InstancePath);
                return;
            }

            Filing.SaveAs saveAs = Filing.SaveAs.Auto;
            bool          isZip  = string.Equals(Path.GetExtension(f.InstancePath), ".zip", StringComparison.CurrentCultureIgnoreCase);

            if (isZip)
            {
                saveAs = Filing.SaveAs.Zip;
                if (this.SaveAs == Filing.SaveAs.Xml)
                {
                    saveAs = Filing.SaveAs.Xml;
                }
            }
            else
            {
                saveAs = Filing.SaveAs.Xml;
                if (this.SaveAs == Filing.SaveAs.Zip)
                {
                    saveAs = Filing.SaveAs.Zip;
                }
            }

            string outputPath;
            string basePath = Path.GetDirectoryName(f.InstancePath);

            if (!this.GetOutputPath(basePath, saveAs, isMultipleFilings, f, out outputPath))
            {
                return;
            }

            string tmpPath = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(f.InstancePath));

            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }
            else
            {
                CleanPath(tmpPath);
            }

            try
            {
                if (isZip)
                {
                    string[] packageFiles;
                    if (!UnzipPackage(executor, f, tmpPath, out packageFiles))
                    {
                        return;
                    }

                    string taxonomy;
                    bool   instanceFound = false;
                    foreach (string file in packageFiles)
                    {
                        if (IsInstance(file, out taxonomy))
                        {
                            instanceFound  = true;
                            f.InstancePath = file;
                            f.TaxonomyPath = taxonomy;
                            break;
                        }
                    }

                    if (!instanceFound)
                    {
                        executor.Invoke("Error: The ZIP file does not contain an instance document.");
                        executor.Invoke("\tSkipping filing: " + f.InstancePath);
                        return;
                    }
                }
                else
                {
                    string taxonomyPath;
                    if (!this.IsInstance(f.InstancePath, out taxonomyPath))
                    {
                        executor.Invoke("Error: Instance document not found at " + f.InstancePath + ".");
                        executor.Invoke("\tSkipping filing: " + f.InstancePath);
                        return;
                    }

                    f.TaxonomyPath = taxonomyPath;
                }
                string        error;
                FilingSummary fs;
                string        reportsPath = isZip ? Path.Combine(tmpPath, "Reports") : tmpPath;
                string        fsPath      = Path.Combine(reportsPath, FilingSummary.FilingSummaryXmlName);

                XRB.ReportBuilder rb = new XRB.ReportBuilder(executor, RulesEngineUtils.DefaultRulesFile, this.ReportFormat, this.HtmlReportFormat);
                rb.CurrencyMappingFile   = this.CurrencyMappingFile;
                rb.RemoteFileCachePolicy = this.RemoteFileCachePolicy;
                rb.XsltStylesheetPath    = this.XsltStylesheetPath;

                if (!rb.BuildReports(f.InstancePath, f.TaxonomyPath, fsPath, reportsPath, out fs, out error))
                {
                    executor.Invoke("Unexpected error: " + error);
                    executor.Invoke("\tFailed filing: " + f.InstancePath);
                }

                if (saveAs == Filing.SaveAs.Xml)
                {
                    foreach (string copyFrom in Directory.GetFiles(reportsPath))
                    {
                        string copyTo = Path.Combine(outputPath, Path.GetFileName(copyFrom));
                        File.Copy(copyFrom, copyTo);
                    }
                }
                else
                {
                    string[] reports = Directory.GetFiles(reportsPath);
                    this.ZipReports(outputPath, reports);
                }

                executor.Invoke("Information: Reports successfully created.");
                executor.Invoke("\t" + (fs.MyReports.Count - 1) + " reports created at " + outputPath + ".");
                if (string.IsNullOrEmpty(error))
                {
                    executor.Invoke("reload");
                }
            }
            catch (Exception ex)
            {
                executor.Invoke("Unexpected error: " + ex.Message);
            }
            finally
            {
                CleanPath(tmpPath);
            }
        }
示例#5
0
        private bool SetSaveAs( string value, string setter )
        {
            try
            {
                this.SaveAs = (Filing.SaveAs)Enum.Parse( typeof( Filing.SaveAs ), value );
                executor.Invoke( setter + ": Setting `" + SAVEAS_COMMAND + "` to `" + value + "`." );
                return true;
            }
            catch { }

            string[] expected = Enum.GetNames( typeof( Filing.SaveAs ) );
            executor.Invoke( setter + ": Ignoring parameter `" + SAVEAS_COMMAND + "`.  Reason: unrecognized value `" + value + "`" + separator +
                "\tExpected one of the following: " + string.Join( ", ", expected ) );
            return false;
        }