Exemplo n.º 1
0
        private TableRow GetSqlEntity(string partitionKey, string rowKey, DateTime?timeStamp)
        {
            string   str      = partitionKey;
            string   str1     = rowKey;
            TableRow tableRow = null;

            str  = DevelopmentStorageDbDataContext.EncodeKeyString(str);
            str1 = DevelopmentStorageDbDataContext.EncodeKeyString(str1);
            if (!timeStamp.HasValue || !timeStamp.HasValue)
            {
                tableRow = (
                    from r in this.m_dbContext.TableRows
                    where (r.AccountName == this.AccountName) && (r.TableName == this.m_currentResourceContainer.Name.ToLowerInvariant()) && (r.PartitionKey == str) && (r.RowKey == str1)
                    select r).FirstOrDefault <TableRow>();
            }
            else
            {
                DateTime sql2005DateTime = DevelopmentStorageDbDataContext.GetSql2005DateTime(timeStamp.Value);
                tableRow = (
                    from r in this.m_dbContext.TableRows
                    where (r.AccountName == this.AccountName) && (r.TableName == this.m_currentResourceContainer.Name.ToLowerInvariant()) && (r.PartitionKey == str) && (r.RowKey == str1) && (r.Timestamp == sql2005DateTime)
                    select r).FirstOrDefault <TableRow>();
            }
            return(tableRow);
        }
Exemplo n.º 2
0
        private TableRow CreateAndPopulateSqlEntity(UtilityRow utilRow)
        {
            TableRow tableRow = new TableRow()
            {
                AccountName  = this.AccountName,
                TableName    = this.m_currentResourceContainer.Name.ToLowerInvariant(),
                PartitionKey = DevelopmentStorageDbDataContext.EncodeKeyString(utilRow.PartitionKey),
                RowKey       = DevelopmentStorageDbDataContext.EncodeKeyString(utilRow.RowKey),
                Data         = XmlUtility.GetXmlFromUtilityRow(utilRow)
            };

            return(tableRow);
        }
Exemplo n.º 3
0
        private void ProcessChange(ChangeDescription changeDescription)
        {
            TableRow           sqlEntity          = null;
            PointQueryTracker  pointQuery         = null;
            DbTableDataContext failedCommandIndex = this;

            failedCommandIndex.FailedCommandIndex = failedCommandIndex.FailedCommandIndex + 1;
            switch (changeDescription.UpdateType)
            {
            case UpdateKind.Insert:
            {
                this.CheckPermissions(null, changeDescription);
                this.CheckPartitionAndRowKeys(((UtilityRow)changeDescription.Row).PartitionKey, ((UtilityRow)changeDescription.Row).RowKey, changeDescription.UpdateType);
                DateTime?nullable = null;
                sqlEntity = this.GetSqlEntity(((UtilityRow)changeDescription.Row).PartitionKey, ((UtilityRow)changeDescription.Row).RowKey, nullable);
                if (sqlEntity != null)
                {
                    throw new TableServiceGeneralException(TableServiceError.EntityAlreadyExists, null);
                }
                UtilityRow row = (UtilityRow)changeDescription.Row;
                this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(row.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(row.RowKey), changeDescription);
                this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(row));
                return;
            }

            case UpdateKind.Delete:
            {
                if (changeDescription.IfMatchHeaderMissing)
                {
                    throw new XStoreArgumentException("If-Match header is mandatory when deleting an entity.");
                }
                sqlEntity = this.CheckAndGetEntity(changeDescription, true);
                this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription);
                this.m_dbContext.TableRows.DeleteOnSubmit(sqlEntity);
                return;
            }

            case UpdateKind.Replace:
            {
                sqlEntity = this.CheckAndGetEntity(changeDescription, true);
                this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription);
                sqlEntity.Data = XmlUtility.GetXmlFromUtilityRow(changeDescription.Row as UtilityRow);
                return;
            }

            case UpdateKind.Merge:
            {
                sqlEntity = this.CheckAndGetEntity(changeDescription, true);
                this.AddChangeToMap(sqlEntity.PartitionKey, sqlEntity.RowKey, changeDescription);
                sqlEntity.Data = XmlUtility.MergeXmlProperties(changeDescription.Row as UtilityRow, sqlEntity.Data);
                return;
            }

            case UpdateKind.InsertOrMerge:
            {
                this.ExecuteQuery <UtilityRow>(changeDescription);
                pointQuery = ((DbTableRowQueryProvider <UtilityRow>)changeDescription.QueryableRow.Provider).PointQuery;
                if (pointQuery == null)
                {
                    throw new DataServiceException(400, "PK and RK not present in the required format");
                }
                (changeDescription.Row as UtilityRow).PartitionKey = pointQuery.PartitionKey;
                (changeDescription.Row as UtilityRow).RowKey       = pointQuery.RowKey;
                sqlEntity = this.CheckAndGetEntity(changeDescription, false);
                this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.RowKey), changeDescription);
                if (sqlEntity != null)
                {
                    sqlEntity.Data = XmlUtility.MergeXmlProperties(changeDescription.Row as UtilityRow, sqlEntity.Data);
                    return;
                }
                this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(changeDescription.Row as UtilityRow));
                return;
            }

            case UpdateKind.InsertOrReplace:
            {
                this.ExecuteQuery <UtilityRow>(changeDescription);
                pointQuery = ((DbTableRowQueryProvider <UtilityRow>)changeDescription.QueryableRow.Provider).PointQuery;
                if (pointQuery == null)
                {
                    throw new DataServiceException(400, "PK and RK not present in the required format");
                }
                (changeDescription.Row as UtilityRow).PartitionKey = pointQuery.PartitionKey;
                (changeDescription.Row as UtilityRow).RowKey       = pointQuery.RowKey;
                sqlEntity = this.CheckAndGetEntity(changeDescription, false);
                this.AddChangeToMap(DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.PartitionKey), DevelopmentStorageDbDataContext.EncodeKeyString(pointQuery.RowKey), changeDescription);
                if (sqlEntity != null)
                {
                    sqlEntity.Data = XmlUtility.GetXmlFromUtilityRow(changeDescription.Row as UtilityRow);
                    return;
                }
                this.m_dbContext.TableRows.InsertOnSubmit(this.CreateAndPopulateSqlEntity(changeDescription.Row as UtilityRow));
                return;
            }

            default:
            {
                return;
            }
            }
        }
Exemplo n.º 4
0
        protected Expression VisitBinary(BinaryExpression b)
        {
            int            num      = 0;
            ExpressionType nodeType = b.NodeType;

            switch (nodeType)
            {
            case ExpressionType.And:
            case ExpressionType.AndAlso:
            {
Label0:
                this.m_needsClosing.Push(true);
                break;
            }

            default:
            {
                switch (nodeType)
                {
                case ExpressionType.Or:
                case ExpressionType.OrElse:
                {
                    goto Label0;
                }

                default:
                {
                    this.m_needsClosing.Push(false);
                    break;
                }
                }
                break;
            }
            }
            if (!this.m_needsClosing.Peek() && !this.m_hasVisitiedBinary)
            {
                this.m_hasVisitiedBinary = true;
                if (b.Right.NodeType == ExpressionType.Constant && b.Right.Type == typeof(object))
                {
                    this.RecordCallerAndVisit(b.Left, null);
                    this.m_needsClosing.Pop();
                    return(b);
                }
            }
            bool flag   = false;
            bool flag1  = false;
            int  count  = -1;
            int  count1 = -1;

            this.PartialClause.Append("( ");
            this.isKeyAccess = false;
            bool methodCall = this.IsCompareToMethodCall(b.Left);

            if (!methodCall)
            {
                if (!this.m_needsClosing.Peek())
                {
                    ExpressionUtility.ValidateIsSimpleExpression(b.Left);
                    flag = ExpressionUtility.IsConstantExpressionEquivalent(b.Left);
                }
                this.RecordCallerAndVisit(b.Left, b);
                this.CloseBooleanExpression(b.NodeType, b.Left);
            }
            else
            {
                Expression item = ((MethodCallExpression)b.Left).Arguments[0];
                ExpressionUtility.ValidateIsSimpleExpression(item);
                flag = ExpressionUtility.IsConstantExpressionEquivalent(item);
                this.RecordCallerAndVisit(item, b.Left);
            }
            if (b.Left is ConstantExpression || b.Left.NodeType == ExpressionType.Convert)
            {
                num++;
            }
            if (flag)
            {
                count = this.Parameters.Count - 1;
            }
            this.ProcessBinaryExpressionOperator(b.NodeType);
            if (!methodCall)
            {
                this.RecordCallerAndVisit(b.Right, b);
                if (!this.m_needsClosing.Peek())
                {
                    flag1 = ExpressionUtility.IsConstantExpressionEquivalent(b.Right);
                }
                this.CloseBooleanExpression(b.NodeType, b.Right);
            }
            else
            {
                this.RecordCallerAndVisit(((MethodCallExpression)b.Left).Arguments[1], b.Left);
                if (!this.m_needsClosing.Peek())
                {
                    flag1 = ExpressionUtility.IsConstantExpressionEquivalent(((MethodCallExpression)b.Left).Arguments[1]);
                }
            }
            if (!this.m_needsClosing.Peek() && flag ^ flag1)
            {
                throw new NotImplementedException();
            }
            if (b.Right is ConstantExpression || b.Right.NodeType == ExpressionType.Convert)
            {
                num++;
            }
            if (flag1)
            {
                count1 = this.Parameters.Count - 1;
            }
            if (flag || flag1)
            {
                int num1 = -1;
                if (count != -1 && this.Parameters[count].IsStringValue)
                {
                    num1 = count;
                }
                else if (count1 != -1 && this.Parameters[count1].IsStringValue)
                {
                    num1 = count1;
                }
                if (num1 != -1)
                {
                    string value = this.Parameters[num1].Value as string;
                    if (value != null)
                    {
                        if (!this.isKeyAccess)
                        {
                            this.Parameters[num1].Value = DevelopmentStorageDbDataContext.EncodeDataString(value);
                        }
                        else
                        {
                            this.Parameters[num1].Value = DevelopmentStorageDbDataContext.EncodeKeyString(value);
                        }
                    }
                }
            }
            this.PartialClause.Append(")");
            this.m_needsClosing.Pop();
            if ((b.NodeType == ExpressionType.GreaterThan || b.NodeType == ExpressionType.GreaterThanOrEqual || b.NodeType == ExpressionType.LessThan || b.NodeType == ExpressionType.LessThanOrEqual || b.NodeType == ExpressionType.Equal || b.NodeType == ExpressionType.NotEqual) && num < 1)
            {
                CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                object[]    mLinqExpression  = new object[] { this.m_linqExpression };
                throw new NotSupportedException(string.Format(invariantCulture, "Query filter '{0}' not supported. A constant should be provided in a binary expression.", mLinqExpression));
            }
            return(b);
        }
Exemplo n.º 5
0
        internal void TranslateQuery()
        {
            StringBuilder whereClause = this.WhereClause;

            string[] strArrays = new string[] { "AccountName = '", this._accountName, "' and TableName = '", this._tableName, "'" };
            whereClause.Append(string.Concat(strArrays));
            this.WhereClause.AppendLine();
            if (this._continuationToken != null)
            {
                string str = string.Concat("@p", this.paramIndex);
                this.paramIndex++;
                this.Parameters.Add(new ParameterRecord(DevelopmentStorageDbDataContext.EncodeKeyString(this._continuationToken["PartitionKey"]), false));
                if (this._continuationToken.Count != 1)
                {
                    string str1 = string.Concat("@p", this.paramIndex);
                    this.paramIndex++;
                    this.Parameters.Add(new ParameterRecord(DevelopmentStorageDbDataContext.EncodeKeyString(this._continuationToken["RowKey"]), false));
                    this.WhereClause.AppendFormat("AND ((PartitionKey = {0} AND RowKey >= {1})\r\n     OR PartitionKey > {0})", str, str1);
                    this.WhereClause.AppendLine();
                }
                else
                {
                    this.WhereClause.Append(string.Concat("AND PartitionKey >= ", str));
                    this.WhereClause.AppendLine();
                }
            }
            if (this.SASKeyBounds != null)
            {
                string str2 = null;
                string str3 = null;
                if (this.SASKeyBounds.MinPartitionKey != null)
                {
                    str2 = string.Concat("@p", this.paramIndex);
                    this.paramIndex++;
                    this.Parameters.Add(new ParameterRecord(DevelopmentStorageDbDataContext.EncodeKeyString(this.SASKeyBounds.MinPartitionKey), false));
                    if (this.SASKeyBounds.MinRowKey == null)
                    {
                        this.WhereClause.AppendFormat("AND PartitionKey >= {0}", str2);
                        this.WhereClause.AppendLine();
                    }
                    else
                    {
                        str3 = string.Concat("@p", this.paramIndex);
                        this.paramIndex++;
                        this.Parameters.Add(new ParameterRecord(DevelopmentStorageDbDataContext.EncodeKeyString(this.SASKeyBounds.MinRowKey), false));
                        this.WhereClause.AppendFormat("AND ( PartitionKey > {0} OR (PartitionKey = {0} AND RowKey >= {1}) )", str2, str3);
                        this.WhereClause.AppendLine();
                    }
                }
                if (this.SASKeyBounds.MaxPartitionKey != null)
                {
                    str2 = string.Concat("@p", this.paramIndex);
                    this.paramIndex++;
                    this.Parameters.Add(new ParameterRecord(DevelopmentStorageDbDataContext.EncodeKeyString(this.SASKeyBounds.MaxPartitionKey), false));
                    if (this.SASKeyBounds.MaxRowKey != null)
                    {
                        str3 = string.Concat("@p", this.paramIndex);
                        this.paramIndex++;
                        this.Parameters.Add(new ParameterRecord(DevelopmentStorageDbDataContext.EncodeKeyString(this.SASKeyBounds.MaxRowKey), false));
                        this.WhereClause.AppendFormat("AND ( PartitionKey < {0} OR (PartitionKey = {0} AND RowKey <= {1}) )", str2, str3);
                        this.WhereClause.AppendLine();
                    }
                    this.WhereClause.AppendFormat("AND PartitionKey <= {0}", str2);
                    this.WhereClause.AppendLine();
                }
            }
            this.TranslateExpression();
            if (this.TakeCount < 0)
            {
                this.TakeCount = this.MaxRowCount;
            }
            if (!this.m_HasOrderBy)
            {
                this.OrderByClause.Append("PartitionKey, RowKey");
            }
            int takeCount = this.TakeCount + 1;

            this.XmlQuery.Append(string.Concat("SELECT TOP ", takeCount.ToString(), " *\n"));
            this.XmlQuery.Append("FROM TableRow");
            this.XmlQuery.AppendLine();
            this.XmlQuery.Append("WHERE ");
            this.XmlQuery.Append(this.WhereClause.ToString());
            this.XmlQuery.AppendLine();
            this.XmlQuery.Append("ORDER BY ");
            this.XmlQuery.Append(this.OrderByClause.ToString());
        }