示例#1
0
        public bool TryResolveResourceSet(string name, out ResourceSet resourceSet)
        {
            string str;

            if (this.m_currentResourceContainer == null || !name.Equals(this.m_currentResourceContainer.ResourceType.Name, StringComparison.OrdinalIgnoreCase))
            {
                if (!TableResourceContainer.IsUtilityTables(name))
                {
                    using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                    {
                        str = (
                            from t in dbContext.TableContainers
                            where (t.AccountName == this.AccountName) && (t.TableName == name.ToLowerInvariant())
                            select t.CasePreservedTableName).FirstOrDefault <string>();
                    }
                    if (str == null)
                    {
                        resourceSet = null;
                        throw new ContainerNotFoundException();
                    }
                    this.m_currentResourceContainer = TableResourceContainer.GetResourceContainer(this.AccountName, str, false);
                }
                else
                {
                    this.m_currentResourceContainer = TableResourceContainer.GetResourceContainer(this.AccountName, "Tables", false);
                }
            }
            resourceSet = this.m_currentResourceContainer;
            return(true);
        }
示例#2
0
        public void SetValue(object targetResource, string propertyName, object propertyValue)
        {
            object obj;

            try
            {
                ChangeDescription changeDescription = (ChangeDescription)targetResource;
                if (!TableResourceContainer.IsUtilityTables(this.m_currentResourceContainer.Name))
                {
                    UtilityRow row = (UtilityRow)changeDescription.Row;
                    if (!propertyName.Equals("Timestamp"))
                    {
                        if (changeDescription.UpdateType != UpdateKind.Insert && changeDescription.UpdateType != UpdateKind.InsertOrMerge && changeDescription.UpdateType != UpdateKind.InsertOrReplace && (propertyName.Equals("PartitionKey") || propertyName.Equals("RowKey")))
                        {
                            throw new InvalidOperationException("Cannot update key values.");
                        }
                        if (!TableDataContextHelper.IsValidPropertyName(propertyName, this.ApiVersion))
                        {
                            throw new TableServiceGeneralException(TableServiceError.PropertyNameInvalid, null);
                        }
                        if (row.ColumnValues.TryGetValue(propertyName, out obj) && obj != null)
                        {
                            throw new XStoreArgumentException("Multiple entries for same property specified in the input");
                        }
                        row[propertyName] = propertyValue;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    UtilityTable utilityTable = (UtilityTable)changeDescription.Row;
                    if (changeDescription.UpdateType == UpdateKind.Insert)
                    {
                        utilityTable[propertyName] = propertyValue;
                        if (string.Equals(propertyName, "TableName"))
                        {
                            if (TableResourceContainer.IsUtilityTables(propertyValue as string))
                            {
                                throw new TableServiceArgumentException("Invalid table container name");
                            }
                            if (!Regex.IsMatch(propertyValue as string, "^[A-Za-z][A-Za-z0-9]{2,62}$"))
                            {
                                throw new InvalidResourceNameException("Invalid table name");
                            }
                        }
                    }
                }
            }
            catch (InvalidCastException invalidCastException1)
            {
                InvalidCastException invalidCastException = invalidCastException1;
                CultureInfo          invariantCulture     = CultureInfo.InvariantCulture;
                object[]             objArray             = new object[] { propertyName };
                throw new XStoreArgumentException(string.Format(invariantCulture, "Invalid data type for property {0}", objArray), invalidCastException);
            }
        }
示例#3
0
 public void SaveChanges()
 {
     if (TableResourceContainer.IsUtilityTables(this.m_currentResourceContainer.Name))
     {
         this.SaveTableChanges();
         return;
     }
     this.SaveEntityChanges();
 }
示例#4
0
        public object ResolveResource(object resource)
        {
            ChangeDescription changeDescription = (ChangeDescription)resource;

            if (TableResourceContainer.IsUtilityTables(this.m_currentResourceContainer.Name))
            {
                return((UtilityTable)changeDescription.Row);
            }
            return((UtilityRow)changeDescription.Row);
        }
示例#5
0
        public object GetValue(object targetResource, string propertyName)
        {
            ChangeDescription changeDescription = (ChangeDescription)targetResource;

            if (TableResourceContainer.IsUtilityTables(this.m_currentResourceContainer.Name))
            {
                return(((UtilityTable)changeDescription.Row)[propertyName]);
            }
            return(((UtilityRow)changeDescription.Row)[propertyName]);
        }
示例#6
0
        public IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet)
        {
            TableResourceContainer tableResourceContainer = resourceSet as TableResourceContainer;

            if (TableResourceContainer.IsUtilityTables(tableResourceContainer.Name))
            {
                return(DbQueryBuilder.CreateTableQuery(this.AccountName, this));
            }
            return(DbQueryBuilder.CreateRowQuery(this.AccountName, tableResourceContainer.Name.ToLowerInvariant(), this));
        }
示例#7
0
        public object CreateResource(string containerName, string fullTypeName)
        {
            ChangeDescription changeDescription = new ChangeDescription(this.AccountName, containerName)
            {
                UpdateType = UpdateKind.Insert
            };

            if (!TableResourceContainer.IsUtilityTables(containerName))
            {
                changeDescription.Row = new UtilityRow();
            }
            else
            {
                changeDescription.Row = new UtilityTable();
            }
            this.changeDescriptionList.Add(changeDescription);
            return(changeDescription);
        }
示例#8
0
        public object GetResource(IQueryable query, string fullTypeName)
        {
            ChangeDescription changeDescription = null;

            changeDescription = new ChangeDescription(this.AccountName, this.m_currentResourceContainer.Name)
            {
                UpdateType = UpdateKind.Merge
            };
            if (!TableResourceContainer.IsUtilityTables(this.m_currentResourceContainer.Name))
            {
                changeDescription.Row = new UtilityRow();
            }
            else
            {
                changeDescription.Row = new UtilityTable();
            }
            changeDescription.QueryableRow = query;
            this.changeDescriptionList.Add(changeDescription);
            return(changeDescription);
        }
示例#9
0
        public TResult Execute <TResult>(Expression expression)
        {
            PointQueryTracker pointQuery;

            if (this.CheckForReadPermission && this._context != null)
            {
                bool flag = TableResourceContainer.IsUtilityTables(this._userResourceName);
                this._context.CheckPermission(this._userResourceName, flag, true, UpdateKind.None);
            }
            if (TableResourceContainer.IsUtilityTables(this._userResourceName))
            {
                string str = null;
                if (this._context.ContinuationToken != null)
                {
                    this._context.ContinuationToken.TryGetValue("TableName", out str);
                }
                DevStoreTableQueryVisitor devStoreTableQueryVisitor = new DevStoreTableQueryVisitor(this._accountName, expression, str, TableDataContextHelper.MaxRowCount);
                devStoreTableQueryVisitor.TranslateQuery();
                if (this._context.IsBatchRequest && (!devStoreTableQueryVisitor.IsPointQuery.HasValue || !devStoreTableQueryVisitor.IsPointQuery.HasValue || !devStoreTableQueryVisitor.IsPointQuery.Value))
                {
                    throw new NotImplementedException();
                }
                string   str1              = devStoreTableQueryVisitor.SqlQuery.ToString();
                object[] array             = devStoreTableQueryVisitor.Parameters.ToArray();
                List <TableContainer> list = this._context.m_dbContext.ExecuteQuery <TableContainer>(str1, array).ToList <TableContainer>();
                if (devStoreTableQueryVisitor.TakeCount >= 0 && devStoreTableQueryVisitor.TakeCount < list.Count)
                {
                    TableContainer item = list[list.Count - 1];
                    this._context.ContinuationToken = new Dictionary <string, string>()
                    {
                        { "NextTableName", item.CasePreservedTableName }
                    };
                    this._context.ContinuationTokenAvailableCallback(this._context.ContinuationToken);
                    list.RemoveAt(list.Count - 1);
                }
                return((TResult)DbUtilityResourceBuilder.GetUtilityTableEnumerator(list.GetEnumerator()));
            }
            LinqToXmlTranslator linqToXmlTranslator = new LinqToXmlTranslator(this._accountName, this._userResourceName, expression, this._context.ContinuationToken, TableDataContextHelper.MaxRowCount, this._context.IsBatchRequest, this.SASKeyBounds);

            linqToXmlTranslator.TranslateQuery();
            if (linqToXmlTranslator.PointQuery.IsPointQuery)
            {
                pointQuery = linqToXmlTranslator.PointQuery;
            }
            else
            {
                pointQuery = null;
            }
            this.PointQuery = pointQuery;
            if (this._context.IsBatchRequest && this.PointQuery == null)
            {
                throw new NotSupportedException("We support retrieving only a single resource via a batch.");
            }
            string str2 = linqToXmlTranslator.XmlQuery.ToString();

            object[] objArray = (
                from ParameterRecord  in linqToXmlTranslator.Parameters
                select r.Value).ToArray <object>();
            List <TableRow> tableRows = this._context.m_dbContext.ExecuteQuery <TableRow>(str2, objArray).ToList <TableRow>();

            if (linqToXmlTranslator.TakeCount >= 0 && linqToXmlTranslator.TakeCount < tableRows.Count)
            {
                TableRow tableRow = tableRows[tableRows.Count - 1];
                this._context.ContinuationToken = new Dictionary <string, string>();
                this._context.ContinuationToken["NextPartitionKey"] = DevelopmentStorageDbDataContext.DecodeKeyString(tableRow.PartitionKey);
                this._context.ContinuationToken["NextRowKey"]       = DevelopmentStorageDbDataContext.DecodeKeyString(tableRow.RowKey);
                this._context.ContinuationTokenAvailableCallback(this._context.ContinuationToken);
                tableRows.RemoveAt(tableRows.Count - 1);
            }
            if (linqToXmlTranslator.ProjectedPropertyCount < 0)
            {
                return((TResult)DbUtilityResourceBuilder.GetUtilityRowEnumerator(tableRows.GetEnumerator()));
            }
            return((TResult)DbUtilityResourceBuilder.GetProjectedWrapperEnumerator(tableRows.GetEnumerator(), linqToXmlTranslator.ProjectedPropertyCount, linqToXmlTranslator.PropertyListName, this._userResourceName, linqToXmlTranslator.ProjectedProperties));
        }