/// <summary> /// Fetches the EntitySetDetails and returns EntitySetDetails object /// XML format will be different depending on tableName parameter. /// </summary> /// <param name="container">Container: Alias</param> /// <param name="tableName">EntitySetName</param> /// <param name="filter">Filter Parameters</param> /// <param name="pageSize">PageSize - For Paging Purpose</param> /// <param name="nextPartitionKey">Next Partition Key - /// For Paging Purpose</param> /// <param name="nextRowKey">Next Row Key - For Paging Purpose</param> /// <param name="isFullData">true if required full data else false</param> /// <returns>returns an object of EntitySetDetails</returns> internal static EntitySetDetails GetBrowserData(string container, string tableName, string filter, int pageSize, string nextPartitionKey, string nextRowKey, bool isFullData) { // Declare object of class EntitySetDetails EntitySetDetails entitySetDetails = null; // Validatie the parameters if ((!String.IsNullOrEmpty(container)) && !(String.IsNullOrEmpty(tableName)) && pageSize > 0) { // Create an instance of class Storage IsdkStorageProviderInterface storage = Helper.ServiceObject; // Define entitySetDetails entitySetDetails = new EntitySetDetails(); // Set the properties of entitySetDetails object entitySetDetails.ContainerAlias = container; entitySetDetails.EntitySetName = tableName; // Set the filter string tableNameFilter = "entityset eq '" + tableName + "'"; // Fetches the data from Azure Table Storage XElement metaDataXML = storage.GetMetadata(container, Resources.MetaDataTableName, tableNameFilter); // Remove the unnecessary columns var properties = metaDataXML.Elements("properties"); properties.Elements("entityset").Remove(); properties.Elements("entitykind").Remove(); // Set the column list var propertyMetaData = metaDataXML.Elements("properties").First().Elements(); // Add the column names in the detailsTable of the object entitySetDetails foreach (var property in propertyMetaData) { if (property.Name == "entityid") { entitySetDetails.DetailsTable.Columns.Add( property.Name.ToString(), Type.GetType("System.Guid")); } else { entitySetDetails.DetailsTable.Columns.Add( property.Name.ToString(), Type.GetType(property.Value)); } } // Get the browser data XElement browserDataXML = null; if (isFullData == false) { browserDataXML = storage.GetData(container, tableName, filter, pageSize, nextPartitionKey, nextRowKey); // set the properties of entitySetDetails object depending on the // fetched results entitySetDetails.NextPartitionKey = browserDataXML.Attribute("nextPartitionKey").Value; entitySetDetails.NextRowKey = browserDataXML.Attribute("nextRowKey").Value; entitySetDetails.CurrentPartitionKey = browserDataXML.Attribute("currentPartitionKey").Value; entitySetDetails.CurrentRowKey = browserDataXML.Attribute("currentRowKey").Value; } else { browserDataXML = storage.GetData(container, tableName, filter); } // validate the XElement if (browserDataXML != null) { // for each XML node, fetch the internal details foreach (var element in browserDataXML.Elements("properties")) { try { // Get the row list for each elements DataRow row = entitySetDetails.DetailsTable.NewRow(); // Add each cell in the row foreach (var cell in element.Elements()) { try { row[cell.Name.ToString()] = cell.Value.ToString(); } catch (Exception) { } //To handle the wrong cells } // Add the newly created row in the table entitySetDetails.DetailsTable.Rows.Add(row); } catch (Exception) { // To handle the wrong rows } } } } // Return entitySetDetails return(entitySetDetails); }
/// <summary> /// Fetches the EntitySetDetails and returns EntitySetDetails object /// XML format will be different depending on tableName parameter. /// </summary> /// <param name="container">Container: Alias</param> /// <param name="tableName">EntitySetName</param> /// <param name="filter">Filter Parameters</param> /// <param name="pageSize">PageSize - For Paging Purpose</param> /// <param name="nextPartitionKey">Next Partition Key - /// For Paging Purpose</param> /// <param name="nextRowKey">Next Row Key - For Paging Purpose</param> /// <param name="isFullData">true if required full data else false</param> /// <returns>returns an object of EntitySetDetails</returns> internal static EntitySetDetails GetBrowserData(string container, string tableName, string filter, int pageSize, string nextPartitionKey, string nextRowKey, bool isFullData, int skip) { // Declare object of class EntitySetDetails EntitySetDetails entitySetDetails = null; // Validatie the parameters if ((!String.IsNullOrEmpty(container)) && !(String.IsNullOrEmpty(tableName)) && pageSize > 0) { // Create an instance of class Storage IsdkStorageProviderInterface storage = Helper.ServiceObject; // Define entitySetDetails entitySetDetails = new EntitySetDetails(); // Set the properties of entitySetDetails object entitySetDetails.ContainerAlias = container; entitySetDetails.EntitySetName = tableName; // Set the filter string tableNameFilter = "entityset eq '" + tableName + "'"; //sl-king //TODO make this a reusable code (find all sfdgsdfgsdfgd) EntitySet es = EntitySetRepository.GetEntitySet(container, tableName); //since this is OData address looks like this .../service/category/entityset //metadata is at address .../service/category/$metadata string realUri = es.DataSvcLink; //first get rid of ?option1=...&option2=.... var uriParts = realUri.Split('?'); realUri = uriParts[0]; if (realUri[realUri.Length - 1] != '/')//if it's not / terminated, let's terminate it { realUri = realUri + "/"; } string metadataUri = realUri; uriParts = metadataUri.Split('/'); metadataUri = uriParts[0]; for (int i = 1; i < uriParts.Length - 2; i++) { metadataUri += "/" + uriParts[i]; } metadataUri += "/$metadata"; // Fetches the data from Azure Table Storage XElement metaDataXML = storage.GetMetadata(metadataUri, container, tableName);//, tableNameFilter); // Remove the unnecessary columns //sl-king: why is this done twice??? see GetMetaData var entityType = metaDataXML.Element("EntityType"); var propertyMetaData = entityType.Elements("Property");//properties"); //properties.Elements("entityset").Remove(); //properties.Elements("entitykind").Remove(); // Set the column list //var propertyMetaData = metaDataXML.Elements("Property");//Elements("properties").First().Elements();//properties // Add the column names in the detailsTable of the object entitySetDetails foreach (var property in propertyMetaData) { if (property.Attribute("Name").Value.ToLower() == "partitionkey" || property.Attribute("Name").Value.ToLower() == "rowkey" || property.Attribute("Name").Value.ToLower() == "timestamp") { continue; } string sName = property.Attribute("Name").Value; if (sName == "entityid")//property.Name { entitySetDetails.DetailsTable.Columns.Add(sName, Type.GetType("System.Guid")); } else { string sType = property.Attribute("Type").Value; sType = sType.Replace("Edm.", "System."); entitySetDetails.DetailsTable.Columns.Add(sName, Type.GetType(sType));//property.Value)); } } // Get the browser data XElement browserDataXML = null; if (isFullData == false) { browserDataXML = storage.GetData(realUri, container, tableName, filter, pageSize, nextPartitionKey, nextRowKey, skip); int read = browserDataXML.Elements("entry").Count(); //for now let's just reuse the old mechanism with dummy values if (read == pageSize) { entitySetDetails.NextPartitionKey = "dummypartitionkey"; entitySetDetails.NextRowKey = "dummyrowkey"; } else { entitySetDetails.NextPartitionKey = ""; entitySetDetails.NextRowKey = ""; } entitySetDetails.Skip += skip + read; // set the properties of entitySetDetails object depending on the // fetched results //entitySetDetails.NextPartitionKey = // browserDataXML.Attribute("nextPartitionKey").Value; //entitySetDetails.NextRowKey = // browserDataXML.Attribute("nextRowKey").Value; //entitySetDetails.CurrentPartitionKey = // browserDataXML.Attribute("currentPartitionKey").Value; //entitySetDetails.CurrentRowKey = // browserDataXML.Attribute("currentRowKey").Value; } else { browserDataXML = storage.GetData(realUri, container, tableName, filter); } // validate the XElement if (browserDataXML != null) { // for each XML node, fetch the internal details foreach (var element in browserDataXML.Elements("entry"))//properties")) { try { XElement content = element.Element("content"); XElement props = content.Element("properties"); // Get the row list for each elements DataRow row = entitySetDetails.DetailsTable.NewRow(); // Add each cell in the row foreach (var cell in props.Elements())//element.Elements() { try { row[cell.Name.ToString()] = cell.Value.ToString(); } catch (Exception) { } //To handle the wrong cells } // Add the newly created row in the table entitySetDetails.DetailsTable.Rows.Add(row); } catch (Exception) { // To handle the wrong rows } } } } // Return entitySetDetails return(entitySetDetails); }