Esempio n. 1
0
        //allows derived classes to override the default streaming
        //and save method
        protected virtual bool StreamAndSaveCalculation()
        {
            bool bHasCalculations = false;

            //both calculators and analyzers use observationpath for initial file
            if (!CalculatorHelpers.URIAbsoluteExists(
                    this.GCCalculatorParams.ExtensionDocToCalcURI,
                    this.GCCalculatorParams.AnalyzerParms.ObservationsPath))
            {
                this.GCCalculatorParams.AnalyzerParms.ObservationsPath
                    = this.GCCalculatorParams.ExtensionDocToCalcURI.URIDataManager.TempDocPath;
            }
            if (!CalculatorHelpers.URIAbsoluteExists(
                    this.GCCalculatorParams.ExtensionDocToCalcURI,
                    this.GCCalculatorParams.AnalyzerParms.ObservationsPath))
            {
                return(bHasCalculations);
            }
            //when writing to file, close it with the using
            StringWriter output = new StringWriter();

            this.GCCalculatorParams.DocToCalcReader
                = DevTreks.Data.Helpers.FileStorageIO.GetXmlReader(
                      this.GCCalculatorParams.ExtensionDocToCalcURI.URIDataManager.InitialDocToCalcURI,
                      this.GCCalculatorParams.AnalyzerParms.ObservationsPath);
            if (this.GCCalculatorParams.DocToCalcReader != null)
            {
                using (this.GCCalculatorParams.DocToCalcReader)
                {
                    //new temporary path to store calculator results
                    //string sNewDocToCalcTempDocPath = CalculatorHelpers.GetFileToCalculate(this.GCCalculatorParams);
                    //descendant nodes are also processed using streaming techniques
                    //note that XStreamingElements were tested but had faults
                    IEnumerable <XElement> root =
                        from startingElement in StreamRoot()
                        select startingElement;
                    XmlWriterSettings writerSettings = new XmlWriterSettings();
                    writerSettings.OmitXmlDeclaration = true;
                    writerSettings.Indent             = true;
                    using (XmlWriter writer = XmlWriter.Create(
                               output, writerSettings))
                    {
                        foreach (XElement el in root)
                        {
                            //stop processing if any error message is found
                            if (this.GCCalculatorParams.ErrorMessage == string.Empty)
                            {
                                el.WriteTo(writer);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            using (output)
            {
                if (this.GCCalculatorParams.ErrorMessage == string.Empty &&
                    this.GCArguments.HasCalculations)
                {
                    //move the new calculations to tempDocToCalcPath
                    //this returns an error msg
                    this.GCCalculatorParams.ErrorMessage = CalculatorHelpers.MoveURIs(
                        this.GCCalculatorParams.ExtensionDocToCalcURI, output,
                        this.GCCalculatorParams.ExtensionDocToCalcURI.URIDataManager.TempDocPath);
                    bHasCalculations = true;
                }
            }
            return(bHasCalculations);
        }