Beispiel #1
0
        internal static CloudBlockBlob CreateBlob(string containerName, string tableName, string ext)
        {
            IsdkStorageProviderInterface service            = Helper.ServiceObject;
            CloudBlobDirectory           ContainerDirectory = convertedData.GetDirectoryReference(containerName);

            switch (ext)
            {
            case ".xml":
                // Get dbf data and save to blob
                XDocument      dataInDbfFormat = service.GetDataAsDaisy(containerName, tableName, null);
                CloudBlockBlob dbfBlob         = ContainerDirectory.GetBlockBlobReference(tableName + ext);
                using (MemoryStream xmlStream = new MemoryStream())
                {
                    using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream))
                    {
                        dataInDbfFormat.Save(xmlWriter);
                        xmlWriter.Close();
                        xmlStream.Position = 0;
                        dbfBlob.UploadFromStream(xmlStream);
                    }
                }
                return(dbfBlob);

            case ".csv":
                // Get csv data and save to blob
                string dataInCsvFormat = service.GetdDataAsCsv(containerName, tableName, null);

                CloudBlockBlob csvBlob = ContainerDirectory.GetBlockBlobReference(tableName + ext);
                using (MemoryStream csvStream = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(csvStream))
                    {
                        sw.Write(dataInCsvFormat);
                        sw.Flush();
                        csvStream.Position = 0;
                        csvBlob.UploadFromStream(csvStream);
                        sw.Close();
                    }
                }
                return(csvBlob);

            case ".ANSI.csv":
                // Get csv data and save to blob for Excel
                string dataInANSICsvFormat = service.GetdDataAsCsv(containerName, tableName, null);

                //Encoding winLatinCodePage = Encoding.GetEncoding(1252);
                Encoding winLatinCodePage = Encoding.GetEncoding(Convert.ToInt32(OgdiConfiguration.GetValue("ANSICodePage")));

                CloudBlockBlob ANSIcsvBlob   = ContainerDirectory.GetBlockBlobReference(tableName + ext);
                MemoryStream   ANSIcsvStream = new MemoryStream(Encoding.Convert(Encoding.Unicode, winLatinCodePage, Encoding.Unicode.GetBytes(dataInANSICsvFormat)));

                ANSIcsvStream.Position = 0;
                ANSIcsvBlob.UploadFromStream(ANSIcsvStream);

                return(ANSIcsvBlob);
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// This method gives the meta data for the given container & entitySet
        /// </summary>
        /// <param name="container">Container: Alias</param>
        /// <param name="tableName">EntitySetName</param>
        /// <returns>returns an object of EntitySetDetails</returns>
        internal static EntitySetDetails GetMetaData(string container,
                                                     string tableName)
        {
            // Declare object of class EntitySetDetails
            EntitySetDetails entitySetDetails = null;

            // Validatie the parameters
            if ((!String.IsNullOrEmpty(container)) &&
                !(String.IsNullOrEmpty(tableName)))
            {
                // 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));
                    }
                }
            }

            return(entitySetDetails);
        }
Beispiel #3
0
        public void ProcessMessage(string msg)
        {
            var messageParts  = msg.Split(new char[] { ',' });
            var containerName = messageParts[0];
            var tableName     = messageParts[1];

            // Get service interface to access azure storage
            string serviceUri = RoleEnvironment.GetConfigurationSettingValue("serviceUri");
            string pathDTD    = RoleEnvironment.GetConfigurationSettingValue("pathDTD");
            IsdkStorageProviderInterface service = IsdkStorageProviderInterface.GetServiceObject(serviceUri, pathDTD);

            // Get dbf data and save to blob
            XDocument      dataInDbfFormat = service.GetDataAsDaisy(containerName, tableName, null);
            CloudBlockBlob dbfBlob         = container.GetBlockBlobReference(tableName + ".xml");

            using (MemoryStream xmlStream = new MemoryStream())
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream))
                {
                    dataInDbfFormat.Save(xmlWriter);
                    xmlWriter.Close();
                    xmlStream.Position = 0;
                    dbfBlob.UploadFromStream(xmlStream);
                }
            }

            // Get csv data and save to blob
            string         dataInCsvFormat = service.GetdDataAsCsv(containerName, tableName, null);
            CloudBlockBlob csvBlob         = container.GetBlockBlobReference(tableName + ".csv");

            using (MemoryStream csvStream = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(csvStream))
                {
                    sw.Write(dataInCsvFormat);
                    sw.Flush();
                    csvStream.Position = 0;
                    csvBlob.UploadFromStream(csvStream);
                    sw.Close();
                }
            }
        }
Beispiel #4
0
        internal static CloudBlockBlob CreateBlob(string containerName, string tableName, string ext)
        {
            IsdkStorageProviderInterface service = Helper.ServiceObject;

            switch (ext)
            {
            case ".xml":
                // Get dbf data and save to blob
                XDocument      dataInDbfFormat = service.GetDataAsDaisy(containerName, tableName, null);
                CloudBlockBlob dbfBlob         = convertedData.GetBlockBlobReference(tableName + ".xml");
                using (MemoryStream xmlStream = new MemoryStream())
                {
                    using (XmlWriter xmlWriter = XmlWriter.Create(xmlStream))
                    {
                        dataInDbfFormat.Save(xmlWriter);
                        xmlWriter.Close();
                        xmlStream.Position = 0;
                        dbfBlob.UploadFromStream(xmlStream);
                    }
                }
                return(dbfBlob);

            case ".csv":
                // Get csv data and save to blob
                string         dataInCsvFormat = service.GetdDataAsCsv(containerName, tableName, null);
                CloudBlockBlob csvBlob         = convertedData.GetBlockBlobReference(tableName + ".csv");
                using (MemoryStream csvStream = new MemoryStream())
                {
                    using (StreamWriter sw = new StreamWriter(csvStream))
                    {
                        sw.Write(dataInCsvFormat);
                        sw.Flush();
                        csvStream.Position = 0;
                        csvBlob.UploadFromStream(csvStream);
                        sw.Close();
                    }
                }
                return(csvBlob);
            }

            return(null);
        }
Beispiel #5
0
        /// <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);
        }
        /// <summary>
        /// This method gives the meta data for the given container & entitySet
        /// </summary>
        /// <param name="container">Container: Alias</param>
        /// <param name="tableName">EntitySetName</param>
        /// <returns>returns an object of EntitySetDetails</returns>
        internal static EntitySetDetails GetMetaData(string container,
                                                     string tableName)
        {
            // Declare object of class EntitySetDetails
            EntitySetDetails entitySetDetails = null;

            // Validatie the parameters
            if ((!String.IsNullOrEmpty(container)) &&
                !(String.IsNullOrEmpty(tableName)))
            {
                // 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 metadataUri = es.DataSvcLink;

                //first get rid of ?option1=...&option2=....
                var uriParts = metadataUri.Split('?');
                metadataUri = uriParts[0];
                if (metadataUri[metadataUri.Length - 1] != '/')//if it's not / terminated, let's terminate it
                {
                    metadataUri = metadataUri + "/";
                }

                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);

                //sl-king: why is this done twice??? see GetBrowserData
                // Remove the unnecessary columns
                var properties = metaDataXML.Element("EntityType");//Elements("properties");
                properties.Elements("Key").Remove();
                //properties.Elements("entityset").Remove();
                //properties.Elements("entitykind").Remove();

                // Set the column list
                var propertyMetaData = properties.Elements();// metaDataXML.Elements("properties").First().Elements();

                // Add the column names in the detailsTable of the object entitySetDetails
                foreach (var property in propertyMetaData)
                {
                    //sl-king: we tryed to get rid of these in GetData, but Azure XML is different from OGDI's
                    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")//.Name == "entityid")
                    {
                        entitySetDetails.DetailsTable.Columns.Add(property.Name.ToString(),
                                                                  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.Name.ToString(), property.Value));
                    }
                }
            }

            return(entitySetDetails);
        }