Skip to content

Commit

Permalink
Add back dybaseapi
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jul 31, 2024
1 parent 05b8ca9 commit 9cd37de
Show file tree
Hide file tree
Showing 93 changed files with 9,110 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aliyun-net-sdk-dybaseapi/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
2019-06-28 Version 1.0.1
- Release dybaseapi to nuget.
2019-06-28 Version 1.0.1
- Release dybaseapi to nuget.
2018-11-20 Version: 1.0.0
1, Add MNS STS Token Query API
2, Add MNS Minimal Package

30 changes: 30 additions & 0 deletions aliyun-net-sdk-dybaseapi/Dybaseapi/MNS/IMNS.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) Alibaba Cloud Computing
* All rights reserved.
*/

using System;
using Aliyun.Acs.Dybaseapi.MNS.Model;

namespace Aliyun.Acs.Dybaseapi.MNS
{
/// <summary>
/// Interface for accessing MNS.
/// </summary>
public partial interface IMNS : IDisposable
{

#region GetNativeQueue

/// <summary>
/// Get a native queue object with the specified queueName.
/// </summary>
///
/// <param name="queueName">The name of native queue object to be created</param>
///
/// <returns>A native queue object</returns>
Queue GetNativeQueue(string queueName);

#endregion
}
}
247 changes: 247 additions & 0 deletions aliyun-net-sdk-dybaseapi/Dybaseapi/MNS/IQueue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
/*
* Copyright (C) Alibaba Cloud Computing
* All rights reserved.
*/

using System;
using Aliyun.Acs.Dybaseapi.MNS.Model;
using System.Collections.Generic;

namespace Aliyun.Acs.Dybaseapi.MNS
{
/// <summary>
/// Interface for accessing MNS queue
/// </summary>
public partial interface IQueue
{

#region DeleteMessage

/// <summary>
/// Deletes the specified message from the specified queue.
/// </summary>
/// <param name="receiptHandle">The receipt handle associated with the message to delete.</param>
///
/// <returns>The response returned by the MNS DeleteMessage service.</returns>
/// <exception cref="ReceiptHandleErrorException">
/// The receipt handle you provide is not valid.
/// </exception>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="InvalidArgumentException">
/// The value of Element should between Low and High seconds/bytes.
/// </exception>
DeleteMessageResponse DeleteMessage(string receiptHandle);

/// <summary>
/// Deletes the specified message from the specified queue.
/// </summary>
/// <param name="request">The request object to be sent to MNS DeleteMessage service.</param>
///
/// <returns>The response returned by the MNS DeleteMessage service.</returns>
/// <exception cref="ReceiptHandleErrorException">
/// The receipt handle you provide is not valid.
/// </exception>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="InvalidArgumentException">
/// The value of Element should between Low and High seconds/bytes.
/// </exception>
DeleteMessageResponse DeleteMessage(DeleteMessageRequest request);

/// <summary>
/// Deletes the specified message from the specified queue.
/// </summary>
/// <param name="request">The request object to be sent to MNS BatchDeleteMessage service.</param>
///
/// <returns>The response returned by the MNS BatchDeleteMessage service.</returns>
/// <exception cref="ReceiptHandleErrorException">
/// The receipt handle you provide is not valid.
/// </exception>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="InvalidArgumentException">
/// The value of Element should between MIN and MAX seconds/bytes.
/// </exception>
/// <exception cref="BatchDeleteFailException">
/// Some messages are not deleted.
/// </exception>
BatchDeleteMessageResponse BatchDeleteMessage(BatchDeleteMessageRequest request);

/// <summary>
/// Begins an asynchronous request to MNS DeleteMessage service.
/// </summary>
///
/// <param name="request">The request object to be sent to MNS DeleteMessage service.</param>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">The state object for this request.</param>
///
/// <returns>An IAsyncResult that references the asynchronous request for a response.</returns>
IAsyncResult BeginDeleteMessage(DeleteMessageRequest request, AsyncCallback callback, object state);

/// <summary>
/// Ends an asynchronous request for MNS DeleteMessage service.
/// </summary>
///
/// <param name="asyncResult">The IAsyncResult returned by the call to BeginDeleteMessage.</param>
///
/// <returns>The response returned by the MNS DeleteMessage service.</returns>
DeleteMessageResponse EndDeleteMessage(IAsyncResult asyncResult);

/// <summary>
/// Begins an asynchronous request to MNS BatchDeleteMessage service.
/// </summary>
///
/// <param name="request">The request object to be sent to MNS BatchDeleteMessage service.</param>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">The state object for this request.</param>
///
/// <returns>An IAsyncResult that references the asynchronous request for a response.</returns>
IAsyncResult BeginBatchDeleteMessage(BatchDeleteMessageRequest request, AsyncCallback callback, object state);

/// <summary>
/// Ends an asynchronous request for MNS BatchDeleteMessage service.
/// </summary>
///
/// <param name="asyncResult">The IAsyncResult returned by the call to BeginBatchDeleteMessage.</param>
///
/// <returns>The response returned by the MNS BatchDeleteMessage service.</returns>
BatchDeleteMessageResponse EndBatchDeleteMessage(IAsyncResult asyncResult);

#endregion

#region ReceiveMessage

/// <summary>
/// Retrieves one message from this queue.
/// </summary>
///
/// <returns>The response returned by the MNS ReceiveMessage service.</returns>
///
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="MessageNotExistException">
/// no messages exist.
/// </exception>
ReceiveMessageResponse ReceiveMessage();

/// <summary>
/// Retrieves one message.
/// </summary>
/// <param name="waitSeconds">Wait polling time for this request.</param>
///
/// <returns>The response returned by the MNS ReceiveMessage service.</returns>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="MessageNotExistException">
/// no messages exist.
/// </exception>
ReceiveMessageResponse ReceiveMessage(uint waitSeconds);

/// <summary>
/// Retrieves one message.
/// </summary>
/// <param name="request">The request object to be sent to MNS ReceiveMessage service.</param>
///
/// <returns>The response returned by the MNS ReceiveMessage service.</returns>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="MessageNotExistException">
/// no messages exist.
/// </exception>
ReceiveMessageResponse ReceiveMessage(ReceiveMessageRequest request);

/// <summary>
/// batch retrieves messages.
/// </summary>
/// <param name="batchSize">the most count limit of retrieved messages</param>
/// <param name="waitSeconds">Wait polling time for this request.</param>
///
/// <returns>The response returned by the MNS ReceiveMessage service.</returns>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="MessageNotExistException">
/// no messages exist.
/// </exception>
BatchReceiveMessageResponse BatchReceiveMessage(uint batchSize);

/// <summary>
/// batch retrieves messages.
/// </summary>
/// <param name="batchSize">the most count limit of retrieved messages</param>
/// <param name="waitSeconds">Wait polling time for this request.</param>
///
/// <returns>The response returned by the MNS ReceiveMessage service.</returns>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="MessageNotExistException">
/// no messages exist.
/// </exception>
BatchReceiveMessageResponse BatchReceiveMessage(uint batchSize, uint waitSeconds);

/// <summary>
/// batch retrieves messages.
/// </summary>
/// <param name="batchSize">the most count limit of retrieved messages</param>
/// <param name="waitSeconds">Wait polling time for this request.</param>
///
/// <returns>The response returned by the MNS ReceiveMessage service.</returns>
/// <exception cref="QueueNotExistException">
/// The queue name you provided is not exist.
/// </exception>
/// <exception cref="MessageNotExistException">
/// no messages exist.
/// </exception>
BatchReceiveMessageResponse BatchReceiveMessage(BatchReceiveMessageRequest request);

/// <summary>
/// Begins an asynchronous request to MNS ReceiveMessage service.
/// </summary>
///
/// <param name="request">The request object to be sent to MNS ReceiveMessage service.</param>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">The state object for this request.</param>
///
/// <returns>An IAsyncResult that references the asynchronous request for a response.</returns>
IAsyncResult BeginReceiveMessage(ReceiveMessageRequest request, AsyncCallback callback, object state);

/// <summary>
/// Ends an asynchronous request for MNS ReceiveMessage service.
/// </summary>
///
/// <param name="asyncResult">The IAsyncResult returned by the call to BeginReceiveMessage.</param>
///
/// <returns>The response returned by the MNS ReceiveMessage service.</returns>
ReceiveMessageResponse EndReceiveMessage(IAsyncResult asyncResult);

/// <summary>
/// Begins an asynchronous request to MNS BatchReceiveMessage service.
/// </summary>
///
/// <param name="request">The request object to be sent to MNS BatchReceiveMessage service.</param>
/// <param name="callback">The AsyncCallback delegate.</param>
/// <param name="state">The state object for this request.</param>
///
/// <returns>An IAsyncResult that references the asynchronous request for a response.</returns>
IAsyncResult BeginBatchReceiveMessage(BatchReceiveMessageRequest request, AsyncCallback callback, object state);

/// <summary>
/// Ends an asynchronous request for MNS BatchReceiveMessage service.
/// </summary>
///
/// <param name="asyncResult">The IAsyncResult returned by the call to BeginBatchReceiveMessage.</param>
///
/// <returns>The response returned by the MNS BatchReceiveMessage service.</returns>
BatchReceiveMessageResponse EndBatchReceiveMessage(IAsyncResult asyncResult);

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Globalization;
using System.Text;
using Aliyun.Acs.Dybaseapi.MNS.Model;
using Aliyun.Acs.Dybaseapi.MNS.Runtime.Pipeline;
using Aliyun.Acs.Dybaseapi.MNS.Runtime.Pipeline.Handlers;
using Aliyun.Acs.Dybaseapi.MNS.Util;

namespace Aliyun.Acs.Dybaseapi.MNS.Internal
{
/// <summary>
/// This handler validates response returned by MNS.
/// </summary>
internal class ResponseValidationHandler : GenericHandler
{
/// <summary>
/// Validates the response returned by MNS.
/// </summary>
/// <param name="executionContext">The execution context which contains both the
/// requests and response context.</param>
protected override void PostInvoke(IExecutionContext executionContext)
{
return;
/*
var request = executionContext.RequestContext.Request;
var response = executionContext.ResponseContext.Response;
ReceiveMessageResponse receiveMessageResponse = response as ReceiveMessageResponse;
if (receiveMessageResponse != null)
{
ValidateReceiveMessage(receiveMessageResponse);
}
SendMessageResponse sendMessageResponse = response as SendMessageResponse;
SendMessageRequest sendMessageRequest = request.OriginalRequest as SendMessageRequest;
if (sendMessageRequest != null && sendMessageResponse != null)
{
ValidateSendMessage(sendMessageRequest, sendMessageResponse);
}
*/
}

public static string CalculateMD5(string message)
{
var messageBytes = Encoding.UTF8.GetBytes(message);
return CalculateMD5(messageBytes);
}
public static string CalculateMD5(byte[] bytes)
{
var md5Hash = CryptoUtilFactory.CryptoInstance.ComputeMD5Hash(bytes);
var calculatedMd5 = BitConverter.ToString(md5Hash).Replace("-", string.Empty).ToLower(CultureInfo.InvariantCulture);
return calculatedMd5;
}
public static bool CompareMD5(string message, string md5FromService)
{
var calculatedMd5 = CalculateMD5(message);
return (string.Equals(calculatedMd5, md5FromService, StringComparison.OrdinalIgnoreCase));
}

public static void ValidateMD5(string message, string md5FromService)
{
if (!CompareMD5(message, md5FromService))
throw new MD5ValidateException("MD5 hash mismatch");
}

public static void ValidateMD5(string message, string messageId, string md5FromService)
{
if (!CompareMD5(message, md5FromService))
throw new MD5ValidateException(string.Format(CultureInfo.InvariantCulture, "MD5 hash mismatch for message id {0}", messageId));
}
public static void ValidateMD5(string message, string messageId, string md5FromService, string receiptHandle)
{
if (!CompareMD5(message, md5FromService))
throw new MD5ValidateException(string.Format(CultureInfo.InvariantCulture, "MD5 hash mismatch for message id {0}", messageId), receiptHandle);
}
public static void ValidateMD5(Message message)
{
ValidateMD5(message.Body, message.Id, message.BodyMD5, message.ReceiptHandle);
}

public static void ValidateReceiveMessage(ReceiveMessageResponse response)
{
if (response != null && response.Message != null)
{
ValidateMD5(response.Message);
}
}
}
}
Loading

0 comments on commit 9cd37de

Please sign in to comment.