示例#1
0
        //************************************************
        public void SaveTweet(Tweet t)
        {
            if (t == null)
                return;

            try
            {
                // Variables for the cloud storage objects.
                var StorageAccount = CloudStorageAccount.Parse(_config.StorageAccount);

                // Create the blob client, which provides
                // authenticated access to the Blob service.
                var blobClient = StorageAccount.CreateCloudBlobClient();

                // Get the container reference.
                var blobContainer = blobClient.GetContainerReference(_config.ContainerName);
                // Create the container if it does not exist.
                blobContainer.CreateIfNotExist();
                string BlobName = string.Format("{0}/{1}.txt", t.CreatedAt.ToString("yyyy-MM-dd"), t.UserName + "_" + t.CreatedAt.ToString("yyyyMMddHHmmss"));

                var blob = blobContainer.GetBlockBlobReference(BlobName);

                //char[] CharArray = t.RawJson.ToCharArray();
                byte[] ByteArray = System.Text.Encoding.UTF8.GetBytes(t.RawJson);

                MemoryStream memStream = new MemoryStream(0);

                // Write the JSON String to the stream.
                memStream.Write(ByteArray, 0, ByteArray.Length);

                // Set the position to the beginning of the stream
                memStream.Seek(0, SeekOrigin.Begin);

                //blobClient.ParallelOperationThreadCount = 1;

                blob.BeginUploadFromStream(memStream, ProcessComplete, memStream);

                //blob.UploadFromStream(memStream);

                // blob.PutBlock(BlobName, memStream);

            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void SaveTweet(Tweet t)
        {
            if (t == null)
                return;

            try
            {

                ExecuteNonQuery(
                    "sp_InsertTweetInfo",
                    new SqlParameter
                    {
                        ParameterName = "@TweetID",
                        Direction = ParameterDirection.Input,
                        DbType = DbType.Int64,
                        Value = t.ID
                    },
                    new SqlParameter
                    {
                        ParameterName = "@Sentiment",
                        Direction = ParameterDirection.Input,
                        DbType = DbType.Int32,
                        Size = 20,
                        Value = t.SentimentScore
                    },
                    new SqlParameter
                    {
                        ParameterName = "@Topic",
                        Direction = ParameterDirection.Input,
                        DbType = DbType.String,
                        Size = 100,
                        Value = t.Topic
                    },
                    new SqlParameter
                    {
                        ParameterName = "@CreatedAt",
                        Direction = ParameterDirection.Input,
                        DbType = DbType.DateTime,
                        Value = t.CreatedAt
                    });
            }
            catch (Exception ex)

            { throw ex; }
        }