/// <summary> /// Gets the value at specified position which indicated by <paramref name="id" />. /// </summary> /// <param name="id">A <see cref="T:Dt.CalcEngine.CalcIdentity" /> indicates the identity of a address.</param> /// <returns> /// An <see cref="T:System.Object" /> indicates the value. /// If the <paramref name="id" /> is not recognized, return <see cref="F:Dt.CalcEngine.CalcErrors.Reference" />. /// </returns> public virtual object GetValue(CalcIdentity id) { if (id is CalcExternalIdentity) { CalcExternalIdentity identity = id as CalcExternalIdentity; ICalcSource source = identity.Source; if (source != null) { CalcLocalIdentity identity3; CalcLocalIdentity identity2 = identity.ConvertToLocal(); if ((this.ArrayFormulaMode || (this.RowCount > 1)) || (this.ColumnCount > 1)) { identity3 = new CalcRangeIdentity(this.Row, this.Column, this.RowCount, this.ColumnCount); } else { identity3 = new CalcCellIdentity(this.Row, this.Column); } return(source.GetEvaluatorContext(identity3).GetValue(identity2)); } } else if ((this.Source != null) && (id is CalcLocalIdentity)) { CalcRangeIdentity objA = id as CalcRangeIdentity; if (object.ReferenceEquals(objA, null)) { return(this.Source.GetValue(id as CalcLocalIdentity)); } if (objA._isFullColumn && objA._isFullRow) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, this.Column))); } if (objA._isFullColumn) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex))); } if (objA._isFullRow) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column))); } if (((objA._rowCount == 1) && (objA._columnIndex <= this.Column)) && (this.Column < (objA._columnIndex + objA._columnCount))) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, this.Column))); } if (((objA._columnCount == 1) && (objA._rowIndex <= this.Row)) && (this.Row < (objA._rowIndex + objA._rowCount))) { return(this.Source.GetValue(new CalcCellIdentity(this.Row, objA._columnIndex))); } if ((objA._rowCount == 1) && (objA._columnCount == 1)) { return(this.Source.GetValue(new CalcCellIdentity(objA._rowIndex, objA._columnIndex))); } return(CalcErrors.Value); } return(CalcErrors.Reference); }
/// <summary> /// Normalizes the specified node to convert all external reference to internal reference. /// </summary> /// <param name="service">The service.</param> /// <param name="node">The node.</param> /// <returns> /// If <paramref name="node" /> is external identity, return a new node which identity is not external, otherwise, return <paramref name="node" />. /// </returns> internal static CalcNode Normalize(CalcService service, CalcNode node) { if (!object.ReferenceEquals(node, null) && (node.Id is CalcExternalIdentity)) { CalcExternalIdentity id = node.Id as CalcExternalIdentity; CalcGraph graph = service.GetCalculationManager(id.Source, null, true).Graph; CalcLocalIdentity identity2 = id.ConvertToLocal(); node = graph.GetNode(identity2) ?? new CalcNode(id.Source, identity2); } return(node); }
/// <summary> /// Gets the reference at specified position which indicated by <paramref name="id" />. /// </summary> /// <param name="id">A <see cref="T:Dt.CalcEngine.CalcIdentity" /> indicates the identity of a address.</param> /// <returns> /// An <see cref="T:System.Object" /> indicates the reference. /// If the <paramref name="id" /> is not recognized, return <see cref="F:Dt.CalcEngine.CalcErrors.Reference" />. /// </returns> public virtual object GetReference(CalcIdentity id) { if (id is CalcExternalIdentity) { CalcExternalIdentity identity = id as CalcExternalIdentity; ICalcSource source = identity.Source; if (source != null) { return(source.GetReference(identity.ConvertToLocal())); } } else { if (id is CalcSheetRangeIdentity) { IMultiSourceProvider provider = this.Source as IMultiSourceProvider; if (provider == null) { return(CalcErrors.Reference); } try { CalcSheetRangeIdentity identity2 = id as CalcSheetRangeIdentity; CalcLocalIdentity identity3 = identity2.ConvertToLocal(); List <CalcReference> references = new List <CalcReference>(); foreach (ICalcSource source2 in provider.GetCalcSources(identity2.StartSource, identity2.EndSource)) { CalcReference item = source2.GetReference(identity3) as CalcReference; if (item != null) { references.Add(item); } } return(new SheetRangeReference(references)); } catch { return(CalcErrors.Reference); } } if ((this.Source != null) && (id is CalcLocalIdentity)) { return(this.Source.GetReference(id as CalcLocalIdentity)); } } return(CalcErrors.Reference); }