示例#1
0
        /// <summary>
        ///   evaluate the expression and return the result
        /// </summary>
        /// <param name = "resType">is the expected type </param>
        /// <param name = "length">of expected Alpha string </param>
        /// <returns> evaluated value or null if value evaluated to null (by ExpressionEvaluator) </returns>
        internal String evaluate(StorageAttribute resType, int length)
        {
            ExpressionEvaluator.ExpVal expVal = null;
            String retVal = null;

            if (computedByClient())
            {
                expVal = ExpressionEvaluator.eval(_expBytes, resType, _task);

                ConvertExpValForDotNet(expVal);

                if (expVal.IsNull)
                {
                    // even if actual dotnet obj is null, we need to return blobPrefix
                    if (expVal.Attr == StorageAttribute.DOTNET)
                    {
                        retVal = expVal.ToMgVal();
                    }
                    else
                    {
                        retVal = null;
                    }
                }
                else if (resType == StorageAttribute.BLOB_VECTOR && expVal.Attr == StorageAttribute.BLOB)
                {
                    if (VectorType.validateBlobContents(expVal.StrVal))
                    {
                        retVal = expVal.ToMgVal();
                    }
                    else
                    {
                        retVal = null;
                    }
                }
                else if (expVal.Attr == StorageAttribute.BLOB_VECTOR &&
                         resType != StorageAttribute.BLOB_VECTOR && resType != StorageAttribute.BLOB)
                {
                    retVal = null;
                }
                else
                {
                    retVal = expVal.ToMgVal();
                }
            }
            else
            {
                RunTimeEvent rtEvt       = ClientManager.Instance.EventsManager.getLastRtEvent();
                Task         mprgCreator = null;

                if (rtEvt != null)
                {
                    mprgCreator = rtEvt.getMainPrgCreator();
                }

                // create a new command object only when necessary
                if (resType != _prevResType)
                {
                    _cmdToServer = CommandFactory.CreateEvaluateCommand(_task.getTaskTag(), resType, _id, length, mprgCreator);
                }
                ClientManager.Instance.execRequestWithSubformRecordCycle(_cmdsToServer, _cmdToServer, this, _task);

                if (resType != StorageAttribute.BLOB && resType != StorageAttribute.BLOB_VECTOR)
                {
                    retVal = _resultValue;
                }
                else if (_resultValue != null && _resultValue.Equals(" "))
                {
                    retVal = "";
                }
                else
                {
                    retVal = RecordUtils.byteStreamToString(_resultValue);
                }
            }
            _prevResType = resType;
            return(retVal);
        }