예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MetaWeblogHandler" /> class.
        /// </summary>
        /// <exception cref="BlogSystemException">unable to create container</exception>
        /// <exception cref="RahulRai.Websites.Utilities.Common.Exceptions.BlogSystemException">unable to create container</exception>
        public MetaWeblogHandler()
        {
            TraceUtility.LogInformation("Metawebloghander started initializing");
            try
            {
                if (null == this.metaweblogTable)
                {
                    this.metaweblogTable = new AzureTableStorageService <TableBlogEntity>(
                        this.connectionString,
                        this.blogTableName,
                        AzureTableStorageAssist.ConvertEntityToDynamicTableEntity,
                        AzureTableStorageAssist.ConvertDynamicEntityToEntity <TableBlogEntity>);
                    this.metaweblogTable.CreateStorageObjectAndSetExecutionContext();
                    TraceUtility.LogInformation("Blog table created");
                }

                if (null == this.mediaStorageService)
                {
                    this.mediaStorageService = new BlobStorageService(this.connectionString);
                    if (FileOperationStatus.FolderCreated
                        != this.mediaStorageService.CreateContainer(
                            this.blogResourceContainerName,
                            VisibilityType.FilesVisibleToAll))
                    {
                        TraceUtility.LogWarning("Resource container could not be created");
                        throw new BlogSystemException("unable to create container");
                    }
                }

                if (null == this.azureQueueService)
                {
                    this.azureQueueService = new AzureQueueService(this.connectionString, this.queueName);
                }

                if (null != this.searchService)
                {
                    return;
                }

                this.searchService = new AzureSearchService(
                    this.searchServiceName,
                    this.searchServiceKey,
                    ApplicationConstants.SearchIndex);
                TraceUtility.LogInformation("Search service initialized");
            }
            catch (BlogSystemException)
            {
                //// This is a custom exception. Throw it again.
                throw;
            }
            catch (Exception exception)
            {
                TraceUtility.LogError(exception);
                throw new BlogSystemException("failed to initialize");
            }
        }
예제 #2
0
 public static void CreateQueue(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlString queueName,
     SqlInt32 timeoutSeconds,
     SqlGuid xmsclientrequestId)
 {
     ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     aqs.CreateQueue(queueName.Value, timeoutSeconds.Value,
                     xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
 }
예제 #3
0
 public static void CreateQueue(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlString queueName,
     SqlInt32 timeoutSeconds,
     SqlGuid xmsclientrequestId)
 {
     ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     aqs.CreateQueue(queueName.Value, timeoutSeconds.Value,
         xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
 }
 public void SetUp()
 {
     _ParseKeyAndAccount();
     _queueName = Guid.NewGuid().ToString("N");
     var accountInfo = new AzureStorageAccountInfo { Account = _account, Key = _key, };
     var accountLookup = new AzureStorageAccountInfoLookup();
     accountLookup.Add(accountInfo);
     _queueUri = new QueueUri(_account, _queueName);
     _azureQueueService = new AzureQueueService(accountLookup);
     _azureQueueService.CreateIfNotExist(_queueUri);
 }
예제 #5
0
        public static void RetrieveApproximateMessageCount(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString queueName,
            SqlInt32 timeoutSeconds,
            SqlString xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            ITPCfSQL.Azure.Queue             q   = aqs.GetQueue(queueName.Value);
            int iRet = q.RetrieveApproximateMessageCount(timeoutSeconds.Value, xmsclientrequestId.Value);

            Utils.PushSingleRecordResult(iRet, System.Data.SqlDbType.Int);
        }
예제 #6
0
 public static void EnqueueMessage(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlString queueName,
     SqlXml xmlMessage,
     SqlInt32 timeoutSeconds,
     SqlGuid xmsclientrequestId)
 {
     ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     ITPCfSQL.Azure.Queue             q   = aqs.GetQueue(queueName.Value);
     q.PutMessage(new Message(xmlMessage.Value),
                  timeoutSeconds.IsNull ? 60 : timeoutSeconds.Value,
                  xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlogService" /> class.
 /// </summary>
 /// <param name="blogContext">The blog context.</param>
 /// <param name="newsletterContext">The newsletter context.</param>
 /// <param name="newSubscriberQueueContext">The new subscriber queue context.</param>
 /// <param name="pageSize">Size of the page.</param>
 /// <param name="searchRecordsSize">Size of the search records.</param>
 public BlogService(
     AzureTableStorageService <TableBlogEntity> blogContext,
     AzureTableStorageService <TableNewsletterEntity> newsletterContext,
     AzureQueueService newSubscriberQueueContext,
     int pageSize,
     int searchRecordsSize)
 {
     this.blogContext               = blogContext;
     this.newsletterContext         = newsletterContext;
     this.newSubscriberQueueContext = newSubscriberQueueContext;
     this.pageSize          = pageSize;
     this.searchRecordsSize = searchRecordsSize;
 }
예제 #8
0
        public static System.Collections.IEnumerable ListQueues_Faulty(SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
                                                                       SqlString prefix,
                                                                       SqlBoolean IncludeMetadata,
                                                                       SqlInt32 timeoutSeconds,
                                                                       SqlString xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);

            List <ITPCfSQL.Azure.Queue> lQueues = aqs.ListQueues_Faulty(
                prefix != null ? prefix.Value : null,
                IncludeMetadata.Value,
                timeoutSeconds.Value,
                xmsclientrequestId != null ? xmsclientrequestId.Value : null);

            return(lQueues);
        }
예제 #9
0
        public static void DequeueMessage(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString queueName,
            SqlInt32 visibilityTimeoutSeconds, // we won't support peek so we should do it fast
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            ITPCfSQL.Azure.Queue             q   = aqs.GetQueue(queueName.Value);
            Message msg = q.Get(visibilityTimeoutSeconds.Value, timeoutSeconds.Value,
                                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            if (msg == null) // empty queue
            {
                return;
            }

            msg.Delete(timeoutSeconds.Value,
                       xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);


            try // try to convert it to XML, if it fails, return a simple string
            {
                SqlXml xml;
                using (System.IO.StringReader sr = new System.IO.StringReader(msg.Body))
                {
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(sr))
                    {
                        xml = new SqlXml(reader);
                    }
                }

                Utils.PushSingleRecordResult(xml.Value, System.Data.SqlDbType.Xml);
            }
            catch (Exception exce)
            {
                SqlContext.Pipe.Send("Cannot parse as XML:" + exce.Message);
                Utils.PushSingleRecordResult(msg.Body, System.Data.SqlDbType.NVarChar);
            }
        }
예제 #10
0
        public static void DequeueMessage(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString queueName,
            SqlInt32 visibilityTimeoutSeconds, // we won't support peek so we should do it fast
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            ITPCfSQL.Azure.Queue q = aqs.GetQueue(queueName.Value);
            Message msg = q.Get(visibilityTimeoutSeconds.Value, timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            if (msg == null) // empty queue
                return;

            msg.Delete(timeoutSeconds.Value,
                 xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            try // try to convert it to XML, if it fails, return a simple string
            {
                SqlXml xml;
                using (System.IO.StringReader sr = new System.IO.StringReader(msg.Body))
                {
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(sr))
                    {
                        xml = new SqlXml(reader);
                    }
                }

                Utils.PushSingleRecordResult(xml.Value, System.Data.SqlDbType.Xml);
            }
            catch (Exception exce)
            {
                SqlContext.Pipe.Send("Cannot parse as XML:" + exce.Message);
                Utils.PushSingleRecordResult(msg.Body, System.Data.SqlDbType.NVarChar);
            }
        }
예제 #11
0
        public static void ListQueuesProc(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString prefix,
            SqlBoolean IncludeMetadata,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);

            //SqlContext.Pipe.Send("Created " + aqs);

            List <ITPCfSQL.Azure.Queue> lQueues = aqs.ListQueues(
                prefix != null ? prefix.Value : null,
                IncludeMetadata.Value,
                timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            for (int i = 0; i < lQueues.Count; i++)
            {
                SqlDataRecord record = new SqlDataRecord(new SqlMetaData[] {
                    new SqlMetaData("Name", System.Data.SqlDbType.NVarChar, 4000),
                    new SqlMetaData("Url", System.Data.SqlDbType.NVarChar, 4000),
                    new SqlMetaData("Metadata", System.Data.SqlDbType.Xml)
                });

                record.SetString(0, lQueues[i].Name);
                record.SetString(1, lQueues[i].Url.ToString());

                if (IncludeMetadata)
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();

                    using (System.Xml.XmlWriter wr = System.Xml.XmlWriter.Create(ms))
                    {
                        wr.WriteStartElement("MetadataList");

                        foreach (string s in lQueues[i].Metadata.Keys)
                        {
                            wr.WriteStartElement(s);
                            wr.WriteString(lQueues[i].Metadata[s]);
                            wr.WriteEndElement();
                        }

                        wr.WriteEndElement();

                        wr.Flush();
                        wr.Close();
                    }

                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                    record.SetSqlXml(2, new SqlXml(ms));
                }
                if (i == 0)
                {
                    SqlContext.Pipe.SendResultsStart(record);
                }

                SqlContext.Pipe.SendResultsRow(record);

                if ((i + 1) >= lQueues.Count)
                {
                    SqlContext.Pipe.SendResultsEnd();
                }
            }
        }
예제 #12
0
 public static void EnqueueMessage(
     SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
     SqlString queueName,
     SqlXml xmlMessage,
     SqlInt32 timeoutSeconds,
     SqlGuid xmsclientrequestId)
 {
     ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
     ITPCfSQL.Azure.Queue q = aqs.GetQueue(queueName.Value);
     q.PutMessage(new Message(xmlMessage.Value),
         timeoutSeconds.IsNull ? 60 : timeoutSeconds.Value,
         xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);
 }
예제 #13
0
        public static void RetrieveApproximateMessageCount(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString queueName,
            SqlInt32 timeoutSeconds,
            SqlString xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);
            ITPCfSQL.Azure.Queue q = aqs.GetQueue(queueName.Value);
            int iRet = q.RetrieveApproximateMessageCount(timeoutSeconds.Value, xmsclientrequestId.Value);

            Utils.PushSingleRecordResult(iRet, System.Data.SqlDbType.Int);
        }
예제 #14
0
        public static System.Collections.IEnumerable ListQueues_Faulty(SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
               SqlString prefix,
               SqlBoolean IncludeMetadata,
               SqlInt32 timeoutSeconds,
               SqlString xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);

            List<ITPCfSQL.Azure.Queue> lQueues = aqs.ListQueues_Faulty(
                prefix != null ? prefix.Value : null,
                IncludeMetadata.Value,
                timeoutSeconds.Value,
                xmsclientrequestId != null ? xmsclientrequestId.Value : null);

            return lQueues;
        }
예제 #15
0
        public static void ListQueuesProc(
            SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS,
            SqlString prefix,
            SqlBoolean IncludeMetadata,
            SqlInt32 timeoutSeconds,
            SqlGuid xmsclientrequestId)
        {
            ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value);

            //SqlContext.Pipe.Send("Created " + aqs);

            List<ITPCfSQL.Azure.Queue> lQueues = aqs.ListQueues(
                prefix != null ? prefix.Value : null,
                IncludeMetadata.Value,
                timeoutSeconds.Value,
                xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value);

            for (int i = 0; i < lQueues.Count; i++)
            {
                SqlDataRecord record = new SqlDataRecord(new SqlMetaData[] {
                new SqlMetaData("Name", System.Data.SqlDbType.NVarChar, 4000),
                new SqlMetaData("Url", System.Data.SqlDbType.NVarChar, 4000),
                new SqlMetaData("Metadata", System.Data.SqlDbType.Xml)
                });

                record.SetString(0, lQueues[i].Name);
                record.SetString(1, lQueues[i].Url.ToString());

                if (IncludeMetadata)
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();

                    using (System.Xml.XmlWriter wr = System.Xml.XmlWriter.Create(ms))
                    {
                        wr.WriteStartElement("MetadataList");

                        foreach (string s in lQueues[i].Metadata.Keys)
                        {
                            wr.WriteStartElement(s);
                            wr.WriteString(lQueues[i].Metadata[s]);
                            wr.WriteEndElement();
                        }

                        wr.WriteEndElement();

                        wr.Flush();
                        wr.Close();
                    }

                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                    record.SetSqlXml(2, new SqlXml(ms));
                }
                if (i == 0)
                    SqlContext.Pipe.SendResultsStart(record);

                SqlContext.Pipe.SendResultsRow(record);

                if ((i + 1) >= lQueues.Count)
                    SqlContext.Pipe.SendResultsEnd();
            }
        }