Exemplo n.º 1
0
        /// <summary>
        /// DAISY Plugin -  This method will return complete data for selected entitySet.
        /// Get an XML element containing data from the specified table + container combination,
        /// filtering according
        /// to the filter criteria specified by the caller.
        /// </summary>
        /// <param name="container">Alias of the container</param>
        /// <param name="tableName">EntitySet\Table name</param>
        /// <param name="filter">Filter criteria, in Azure Table Services query syntax.</param>
        /// <returns>An XML element containing the results of the query.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="WebException"></exception>
        /// <exception cref="Exception"></exception>
        public override XDocument GetDataAsDaisy(string container, string tableName, string filter)
        {
            XElement  tempGetData          = null;
            string    tempNextPartitionKey = string.Empty;
            string    tempNextRowKey       = string.Empty;
            XDocument daisyDataXml         = null;

            if (string.IsNullOrEmpty(container))
            {
                throw new ArgumentNullException(AzureResources.ContainerCannotBeNull);
            }

            //handling internal paging.
            do
            {
                if (tempGetData == null)
                {
                    // 1000 is the max results Azure Table Storage allows per query
                    tempGetData          = GetData(container, tableName, filter, 1000, null, null);
                    tempNextPartitionKey = tempGetData.Attribute("nextPartitionKey").Value;
                    tempNextRowKey       = tempGetData.Attribute("nextRowKey").Value;
                }
                else
                {
                    // 1000 is the max results Azure Table Storage allows per query
                    XElement tp = GetData(container, tableName, filter, 1000, tempNextPartitionKey, tempNextRowKey);
                    tempGetData.Add(tp.Elements("properties"));

                    // Update the partitionkey values at the top.
                    tempGetData.SetAttributeValue("currentPartitionKey", tp.Attribute("currentPartitionKey").Value);
                    tempGetData.SetAttributeValue("currentRowKey", tp.Attribute("currentRowKey").Value);
                    tempGetData.SetAttributeValue("nextPartitionKey", tp.Attribute("nextPartitionKey").Value);
                    tempGetData.SetAttributeValue("nextRowKey", tp.Attribute("nextRowKey").Value);

                    tempNextPartitionKey = tp.Attribute("nextPartitionKey").Value;
                    tempNextRowKey       = tp.Attribute("nextRowKey").Value;
                }
            }while (!string.IsNullOrEmpty(tempNextPartitionKey) && !string.IsNullOrEmpty(tempNextRowKey));

            //Function to get the header information of a particular entity set
            AddMetadataToXElement(container, tempGetData);

            String xmlDataFromAzure = tempGetData.ToString();

            TextReader inputXMLDataForTrans = new StringReader(xmlDataFromAzure);
            XmlReader  xmlReader            = XmlReader.Create(inputXMLDataForTrans);

            // Translate dat in daisy format.
            DTBookTranslation.DTBook objBook = new DTBookTranslation.DTBook();

            TextReader validatedDTBookXml;
            //Xml got from azure environment is given as input for DTBook translation method
            string mappedPath = (HttpContext.Current != null) ? HttpContext.Current.Server.MapPath(PathDTD)
                : Path.Combine(Environment.CurrentDirectory, PathDTD);

            validatedDTBookXml = objBook.TranslationOfAzureXml(xmlReader, mappedPath);
            daisyDataXml       = XDocument.Load(validatedDTBookXml);
            return(daisyDataXml);
        }
        /// <summary>
        /// DAISY Plugin -  This method will return complete data for selected entitySet.
        /// Get an XML element containing data from the specified table + container combination,
        /// filtering according
        /// to the filter criteria specified by the caller.
        /// </summary>
        /// <param name="container">Alias of the container</param>
        /// <param name="tableName">EntitySet\Table name</param>
        /// <param name="filter">Filter criteria, in Azure Table Services query syntax.</param>
        /// <returns>An XML element containing the results of the query.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="WebException"></exception>
        /// <exception cref="Exception"></exception>
        public override XDocument GetDataAsDaisy(string container, string tableName, string filter)
        {
            XElement tempGetData = null;
            string tempNextPartitionKey = string.Empty;
            string tempNextRowKey = string.Empty;
            XDocument daisyDataXml = null;

            if (string.IsNullOrEmpty(container))
            {
                throw new ArgumentNullException(AzureResources.ContainerCannotBeNull);
            }

            //handling internal paging.
            do
            {
                if (tempGetData == null)
                {
                    // 1000 is the max results Azure Table Storage allows per query
                    tempGetData = GetData(container, tableName, filter, 1000, null, null);
                    tempNextPartitionKey = tempGetData.Attribute("nextPartitionKey").Value;
                    tempNextRowKey = tempGetData.Attribute("nextRowKey").Value;
                }
                else
                {
                    // 1000 is the max results Azure Table Storage allows per query
                    XElement tp = GetData(container, tableName, filter, 1000, tempNextPartitionKey, tempNextRowKey);
                    tempGetData.Add(tp.Elements("properties"));

                    // Update the partitionkey values at the top.
                    tempGetData.SetAttributeValue("currentPartitionKey", tp.Attribute("currentPartitionKey").Value);
                    tempGetData.SetAttributeValue("currentRowKey", tp.Attribute("currentRowKey").Value);
                    tempGetData.SetAttributeValue("nextPartitionKey", tp.Attribute("nextPartitionKey").Value);
                    tempGetData.SetAttributeValue("nextRowKey", tp.Attribute("nextRowKey").Value);

                    tempNextPartitionKey = tp.Attribute("nextPartitionKey").Value;
                    tempNextRowKey = tp.Attribute("nextRowKey").Value;
                }
            }
            while (!string.IsNullOrEmpty(tempNextPartitionKey) && !string.IsNullOrEmpty(tempNextRowKey));

            //Function to get the header information of a particular entity set
            AddMetadataToXElement(container, tempGetData);

            String xmlDataFromAzure = tempGetData.ToString();

            TextReader inputXMLDataForTrans = new StringReader(xmlDataFromAzure);
            XmlReader xmlReader = XmlReader.Create(inputXMLDataForTrans);

            // Translate dat in daisy format.
            DTBookTranslation.DTBook objBook = new DTBookTranslation.DTBook();

            TextReader validatedDTBookXml;
            //Xml got from azure environment is given as input for DTBook translation method
            string mappedPath = (HttpContext.Current!=null) ? HttpContext.Current.Server.MapPath(PathDTD)
                : Path.Combine(Environment.CurrentDirectory,PathDTD);
            validatedDTBookXml = objBook.TranslationOfAzureXml(xmlReader, mappedPath);
            daisyDataXml = XDocument.Load(validatedDTBookXml);
            return daisyDataXml;
        }
        /// <summary>
        /// DAISY Plugin -  This method will return complete data for selected entitySet.
        /// Get an XML element containing data from the specified table + container combination,
        /// filtering according
        /// to the filter criteria specified by the caller.
        /// </summary>
        /// <param name="container">Alias of the container</param>
        /// <param name="tableName">EntitySet\Table name</param>
        /// <param name="filter">Filter criteria, in Azure Table Services query syntax.</param>
        /// <returns>An XML element containing the results of the query.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="WebException"></exception>
        /// <exception cref="Exception"></exception>
        public override XDocument GetDataAsDaisy(string realUri, string container, string tableName, string filter)
        {
            XElement  tempGetData          = null;
            string    tempNextPartitionKey = string.Empty;
            string    tempNextRowKey       = string.Empty;
            XDocument daisyDataXml         = null;

            if (string.IsNullOrEmpty(container))
            {
                throw new ArgumentNullException(AzureResources.ContainerCannotBeNull);
            }

            try
            {
                //we don't need paging
                //tempGetData = GetData(realUri, container, tableName, filter, 0, null, null);
                tempGetData = GetDataAsXElement(realUri, container, tableName, filter);

                ////handling internal paging.
                //do
                //{
                //    if (tempGetData == null)
                //    {
                //        // 1000 is the max results Azure Table Storage allows per query
                //        tempGetData = GetData(realUri, container, tableName, filter, 1000, null, null);
                //        tempNextPartitionKey = tempGetData.Attribute("nextPartitionKey").Value;
                //        tempNextRowKey = tempGetData.Attribute("nextRowKey").Value;
                //    }
                //    else
                //    {
                //        // 1000 is the max results Azure Table Storage allows per query
                //        XElement tp = GetData(realUri, container, tableName, filter, 1000, tempNextPartitionKey, tempNextRowKey);
                //        tempGetData.Add(tp.Elements("properties"));

                //        // Update the partitionkey values at the top.
                //        tempGetData.SetAttributeValue("currentPartitionKey", tp.Attribute("currentPartitionKey").Value);
                //        tempGetData.SetAttributeValue("currentRowKey", tp.Attribute("currentRowKey").Value);
                //        tempGetData.SetAttributeValue("nextPartitionKey", tp.Attribute("nextPartitionKey").Value);
                //        tempGetData.SetAttributeValue("nextRowKey", tp.Attribute("nextRowKey").Value);

                //        tempNextPartitionKey = tp.Attribute("nextPartitionKey").Value;
                //        tempNextRowKey = tp.Attribute("nextRowKey").Value;
                //    }
                //}
                //while (!string.IsNullOrEmpty(tempNextPartitionKey) && !string.IsNullOrEmpty(tempNextRowKey));

                //Function to get the header information of a particular entity set
                AddMetadataToXElement(realUri, container, tempGetData);

                String xmlDataFromAzure = tempGetData.ToString();

                TextReader inputXMLDataForTrans = new StringReader(xmlDataFromAzure);
                XmlReader  xmlReader            = XmlReader.Create(inputXMLDataForTrans);

                // Translate dat in daisy format.
                DTBookTranslation.DTBook objBook = new DTBookTranslation.DTBook();

                TextReader validatedDTBookXml;
                //Xml got from azure environment is given as input for DTBook translation method
                string mappedPath = (HttpContext.Current != null) ? HttpContext.Current.Server.MapPath(PathDTD)
                    : Path.Combine(Environment.CurrentDirectory, PathDTD);
                validatedDTBookXml = objBook.TranslationOfAzureXml(xmlReader, mappedPath);
                daisyDataXml       = XDocument.Load(validatedDTBookXml);
            }
            catch (Exception ex)
            {
                string sSource;
                string sLog;
                string sEvent;

                sSource = "ODP API";
                sLog    = "Application";
                sEvent  = ex.Message;

                if (!System.Diagnostics.EventLog.SourceExists(sSource))
                {
                    System.Diagnostics.EventLog.CreateEventSource(sSource, sLog);
                }

                System.Diagnostics.EventLog.WriteEntry(sSource, sEvent);
                System.Diagnostics.EventLog.WriteEntry(sSource, sEvent, System.Diagnostics.EventLogEntryType.Warning, 234);

                throw;
            }
            return(daisyDataXml);
        }
        /// <summary>
        /// DAISY Plugin -  This method will return complete data for selected entitySet.
        /// Get an XML element containing data from the specified table + container combination,
        /// filtering according
        /// to the filter criteria specified by the caller.
        /// </summary>
        /// <param name="container">Alias of the container</param>
        /// <param name="tableName">EntitySet\Table name</param>
        /// <param name="filter">Filter criteria, in Azure Table Services query syntax.</param>
        /// <returns>An XML element containing the results of the query.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="WebException"></exception>
        /// <exception cref="Exception"></exception>
        public override XDocument GetDataAsDaisy(string realUri, string container, string tableName, string filter)
        {
            XElement tempGetData = null;
            string tempNextPartitionKey = string.Empty;
            string tempNextRowKey = string.Empty;
            XDocument daisyDataXml = null;

            if (string.IsNullOrEmpty(container))
            {
                throw new ArgumentNullException(AzureResources.ContainerCannotBeNull);
            }

            try
            {
                //we don't need paging
                //tempGetData = GetData(realUri, container, tableName, filter, 0, null, null);
                tempGetData = GetDataAsXElement(realUri, container, tableName, filter);

                ////handling internal paging.
                //do
                //{
                //    if (tempGetData == null)
                //    {
                //        // 1000 is the max results Azure Table Storage allows per query
                //        tempGetData = GetData(realUri, container, tableName, filter, 1000, null, null);
                //        tempNextPartitionKey = tempGetData.Attribute("nextPartitionKey").Value;
                //        tempNextRowKey = tempGetData.Attribute("nextRowKey").Value;
                //    }
                //    else
                //    {
                //        // 1000 is the max results Azure Table Storage allows per query
                //        XElement tp = GetData(realUri, container, tableName, filter, 1000, tempNextPartitionKey, tempNextRowKey);
                //        tempGetData.Add(tp.Elements("properties"));

                //        // Update the partitionkey values at the top.
                //        tempGetData.SetAttributeValue("currentPartitionKey", tp.Attribute("currentPartitionKey").Value);
                //        tempGetData.SetAttributeValue("currentRowKey", tp.Attribute("currentRowKey").Value);
                //        tempGetData.SetAttributeValue("nextPartitionKey", tp.Attribute("nextPartitionKey").Value);
                //        tempGetData.SetAttributeValue("nextRowKey", tp.Attribute("nextRowKey").Value);

                //        tempNextPartitionKey = tp.Attribute("nextPartitionKey").Value;
                //        tempNextRowKey = tp.Attribute("nextRowKey").Value;
                //    }
                //}
                //while (!string.IsNullOrEmpty(tempNextPartitionKey) && !string.IsNullOrEmpty(tempNextRowKey));

                //Function to get the header information of a particular entity set
                AddMetadataToXElement(realUri, container, tempGetData);

                String xmlDataFromAzure = tempGetData.ToString();

                TextReader inputXMLDataForTrans = new StringReader(xmlDataFromAzure);
                XmlReader xmlReader = XmlReader.Create(inputXMLDataForTrans);

                // Translate dat in daisy format.
                DTBookTranslation.DTBook objBook = new DTBookTranslation.DTBook();

                TextReader validatedDTBookXml;
                //Xml got from azure environment is given as input for DTBook translation method
                string mappedPath = (HttpContext.Current != null) ? HttpContext.Current.Server.MapPath(PathDTD)
                    : Path.Combine(Environment.CurrentDirectory, PathDTD);
                validatedDTBookXml = objBook.TranslationOfAzureXml(xmlReader, mappedPath);
                daisyDataXml = XDocument.Load(validatedDTBookXml);
            }
            catch (Exception ex)
            {
                string sSource;
                string sLog;
                string sEvent;

                sSource = "ODP API";
                sLog = "Application";
                sEvent = ex.Message;

                if (!System.Diagnostics.EventLog.SourceExists(sSource))
                    System.Diagnostics.EventLog.CreateEventSource(sSource, sLog);

                System.Diagnostics.EventLog.WriteEntry(sSource, sEvent);
                System.Diagnostics.EventLog.WriteEntry(sSource, sEvent, System.Diagnostics.EventLogEntryType.Warning, 234);

                throw;
            }
            return daisyDataXml;
        }