Пример #1
0
        //allows derived classes to override the default streaming
        //and save method
        protected virtual bool RunDevPackCalculations()
        {
            bool bHasCalculation = false;
            IDictionary <string, string> fileOrFolderPaths =
                CalculatorHelpers.GetDevPackState(this.GCCalculatorParams);

            if (string.IsNullOrEmpty(this.GCCalculatorParams.ErrorMessage))
            {
                if (fileOrFolderPaths != null)
                {
                    if (fileOrFolderPaths.Count > 0)
                    {
                        string sId = string.Empty;
                        string sDocToCalcFilePath = string.Empty;
                        string sTempDocToCalcPath = string.Empty;
                        int    i = 0;
                        foreach (KeyValuePair <string, string> kvp
                                 in fileOrFolderPaths)
                        {
                            bHasCalculation    = false;
                            sId                = kvp.Key;
                            sDocToCalcFilePath = kvp.Value;
                            if (CalculatorHelpers.URIAbsoluteExists(
                                    this.GCCalculatorParams.ExtensionDocToCalcURI,
                                    sDocToCalcFilePath))
                            {
                                //make new calcparams using sDocToCalcFilePath
                                ExtensionContentURI devPackCalcURI
                                    = CalculatorHelpers.GetDevPackCalcURI(this.GCCalculatorParams.ExtensionDocToCalcURI,
                                                                          this.GCCalculatorParams.ExtensionCalcDocURI, sDocToCalcFilePath,
                                                                          ref sTempDocToCalcPath);
                                //copy the doctocalc to tempdoctocalcpath
                                CalculatorHelpers.CopyFiles(this.GCCalculatorParams.ExtensionDocToCalcURI,
                                                            sDocToCalcFilePath, sTempDocToCalcPath);
                                //reset calculatorparams to reflect devPackCalcURI
                                CalculatorParameters devPackCalcParameters
                                    = new CalculatorParameters(this.GCCalculatorParams);
                                devPackCalcParameters.CurrentElementNodeName
                                    = devPackCalcURI.URINodeName;
                                devPackCalcParameters.CurrentElementURIPattern
                                    = devPackCalcURI.URIPattern;
                                //reset the calcparams.extdoctocalcuri
                                devPackCalcParameters.ExtensionDocToCalcURI
                                    = devPackCalcURI;

                                //currentDevPackElement has current db-generated linked views
                                //and is more reliable for updating linked views in db
                                XElement currentDevPackElement = null;
                                XElement linkedViewElement     = null;
                                CalculatorHelpers.GetDevPackCalculator(this.GCCalculatorParams,
                                                                       devPackCalcParameters, out currentDevPackElement,
                                                                       out linkedViewElement);
                                //4. raise event to carry out calculations
                                GCArguments.CurrentElement    = currentDevPackElement;
                                GCArguments.LinkedViewElement = linkedViewElement;
                                GCArguments.CalculatorParams  = devPackCalcParameters;
                                GCArguments.CalculatorParams.CurrentElement    = currentDevPackElement;
                                GCArguments.CalculatorParams.LinkedViewElement = linkedViewElement;
                                OnRunDevPackCalculation(GCArguments);
                                bHasCalculation       = GCArguments.HasCalculations;
                                currentDevPackElement = GCArguments.CurrentElement;
                                linkedViewElement     = GCArguments.LinkedViewElement;
                                //5. SetXmlDocAttributes (using devPackElement)
                                if (bHasCalculation)
                                {
                                    //updates for children
                                    CalculatorHelpers.SetXmlDocUpdates(devPackCalcParameters,
                                                                       linkedViewElement, ref currentDevPackElement,
                                                                       this.GCCalculatorParams.Updates);
                                    //add the tempdoctocalcpath to updates for potential saving later
                                    string sErrorMsg = string.Empty;
                                    CalculatorHelpers.SetDevPackUpdatesState(
                                        devPackCalcURI, this.GCCalculatorParams.ExtensionCalcDocURI,
                                        this.GCCalculatorParams.Updates, ref sErrorMsg);
                                    if (i == 0)
                                    {
                                        //set the parent devpack
                                        this.GCCalculatorParams.CurrentElementNodeName
                                            = this.GCCalculatorParams.ExtensionDocToCalcURI.URINodeName;
                                        this.GCCalculatorParams.CurrentElementURIPattern
                                            = this.GCCalculatorParams.ExtensionDocToCalcURI.URIPattern;
                                        //currentDevPackElement has current db-generated linked views
                                        //and is reliable for updating linked views in db
                                        CalculatorHelpers.GetDevPackCalculator(this.GCCalculatorParams,
                                                                               this.GCCalculatorParams, out currentDevPackElement,
                                                                               out linkedViewElement);
                                        //update the parent
                                        this.GCCalculatorParams.NeedsXmlDocOnly = true;
                                        CalculatorHelpers.SetXmlDocUpdates(this.GCCalculatorParams,
                                                                           linkedViewElement, ref currentDevPackElement,
                                                                           this.GCCalculatorParams.Updates);
                                        //show them the first calculated document as feedback
                                        //refactor for future to show a summary of all calculated custom docs
                                        //move the doctocalc to tempdoctocalcpath
                                        CalculatorHelpers.CopyFiles(
                                            this.GCCalculatorParams.ExtensionDocToCalcURI, sTempDocToCalcPath,
                                            this.GCCalculatorParams.ExtensionDocToCalcURI.URIDataManager.TempDocPath);
                                    }
                                }
                            }
                            i++;
                        }
                    }
                }
            }
            return(bHasCalculation);
        }