Skip to content

Instantly share code, notes, and snippets.

View Madhufuture's full-sized avatar

Madhu Sangaraju Madhufuture

  • MOQdigital
  • Melbourne
View GitHub Profile
public async Task<List<string>> GetDocumentAttachment(string attachmentUrl)
{
var attachmentLinks = new List<string>();
try
{
var attachments = await _client.ReadAttachmentFeedAsync(attachmentUrl);
foreach (var attachment in attachments) attachmentLinks.Add(attachment.MediaLink);
}
catch (Exception ex)
{
public async Task<List<string>> GetDocumentAttachment(string attachmentUrl)
{
var attachmentLinks = new List<string>();
try
{
var attachments = await _client.ReadAttachmentFeedAsync(attachmentUrl);
foreach (var attachment in attachments) attachmentLinks.Add(attachment.MediaLink);
}
catch (Exception ex)
{
public async Task<Document> UpdateDocumentAsync(string id, T item, List<BlobDetails> lstBlobDetails)
{
try
{
var updateResponse =
await _client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(_databaseId, _collectionId, id),
item);
if (updateResponse.StatusCode != HttpStatusCode.OK) return updateResponse;
var attachmentsUrl = string.Concat(updateResponse.Resource.AltLink, "/attachments/");
public async Task<Document> CreateDocumentAsync(T item, List<BlobDetails> lstBlobDetailses)
{
try
{
var response =
await _client.CreateDocumentAsync(
UriFactory.CreateDocumentCollectionUri(_databaseId, _collectionId), item);
if (response.StatusCode != HttpStatusCode.Created) return response;
var attachmentUrl = string.Concat(response.Resource.AltLink, "/attachments/"); //AltLink, will give us the encoded url for the document in cosmosdb
{
"resortName":"",
"resortDescription":"",
"resortLocation":"",
"thingsToDo":"",
"documents":"", /* object which holds all types of documents, media/blobs */
"resortType":"",
"resortAddress":{
"streetAddress":"",
"city":"",
@Madhufuture
Madhufuture / Description.txt
Created May 8, 2019 02:46
Method which converts arbitrary nested array to flatten array
Usage of Dynamic
-----------------
I have used Dynamic instead of object. If I use object then I have to write typecasting statements when reading the integer values in the array.
Readability is good with dynamic.
Usage of Queue
---------------
Since we are reading the elements in the FIFO order, I used Queue rather than List.
<system.serviceModel>
<client>
<endpoint name="YourService" contract="<namespace.IYourService>" binding="netTcpRelayBinding" address="sb://<relaynamespace>.servicebus.windows.net/<serviceAddress>" behaviorConfiguration="sbTokenProvider"></endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="sbTokenProvider">
<transportClientEndpointBehavior>
<tokenProvider>
<sharedAccessSignature keyName="RootManageSharedAccessKey" key="<SAS key>" />
public interface IServiceChannel : IYourService, IClientChannel
{
}
static void Main(string[] args)
{
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;
var serviceChannelObj = new ChannelFactory<Iservicechannel>("yourService");
var response = new YourObject();
Iservicechannel channel = null;
try
{
channel = serviceChannelObj.CreateChannel();
response = channel.GetDetails(someValue);
public class YourService : IYourService
{
public YourObject GetDetails(int id)
{
Console.WriteLine($"Requested Id {id}");
return new YourObject
{
//Data
};
}