Wednesday, February 3, 2021

How can I call an async method in Main?

That kind if issue are facing beginner and those developer are not familiar with async and await used.
So in this post i have explain you how to call async method.

 
namespace PracticeHemaware
{
class Program
{
private static string result = "123";

static void Main(string[] args)
{
var data= Task.Run(async () => await saytest());
// saytest(result).Wait();
Console.WriteLine(data.Result);

Console.Read();
}
static async Task<string> saytest()
{
await Task.Delay(5);
result = "Hello World";
return result;
}
}
}
this is my code and saytest() is my async method.

Thank you.

Tuesday, February 2, 2021

Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync

 Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync 

Error:
Full error is as below, while generating reports in Developer VM.

Unable to connect to the remote server at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.CloudTable.Exists(Boolean primaryOnly, TableRequestOptions requestOptions, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.CloudTable.CreateIfNotExists(TableRequestOptions requestOptions, OperationContext operationContext) at Microsoft.DynamicsOnline.Infrastructure.Components.TableAccessor.TableStorageAccessor.PerformOperation(CloudStorageAccount storageAccount, String tableName, Func`1 operation) at

Reason:
Azure emulator service is not running due to port conflict with another windows service.
 
How to find what is running on what port?

using any of the below commands in cmd will give you list of the ports used by services.

netstat -bano

netstat -a

In my case, those ports were in use by windows application, which i can not stop or change port.

How to solve error?

To resolve this error open CMD with Administrative privileges

Navigate to location: "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\"

Execute command AzureStorageEmulator.exe start.

In my case service was not started due to same ports were being used by another application.

I have changed port number for Azure Emulator to run on different port and started service.

Below is Picturization for the same.


 

 

 

 

 

 

 

Thank you .

Upload Image To Azure China Blob Storage In ASP.NET MVC

 Upload Image To Azure China Blob Storage In ASP.NET MVC Code.
 1st step:-Use below code in web.config file.

<appSettings>
    <add key="StorageAccountName" value="YOURAZURECHINAACCOUNTNAME" />
    <add key="StorageAccountKey" value="YOURAZURECHINAACCOUNTKEY" />
  </appSettings>

The below is controller code

I am using service here the code are as below:-

using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace BlobStorageDemo
{
    public class ImageService
    {
        public async Task<string> UploadImageAsync(HttpPostedFileBase imageToUpload)
        {
            string account = CloudConfigurationManager.GetSetting("StorageAccountName");
            string key = CloudConfigurationManager.GetSetting("StorageAccountKey");
            string imageFullPath = null;
            if (imageToUpload == null || imageToUpload.ContentLength==0)
            {
                return null;
            }
            try
            {
                StorageCredentials credn = new StorageCredentials(account, key);
                CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(credn, new Uri("https://deice2staging.blob.core.chinacloudapi.cn "),
           new Uri(" https://deice2staging.blob.core.chinacloudapi.cn/ "),
           new Uri("https://deice2staging.blob.core.chinacloudapi.cn/ "), null);
                //CloudStorageAccount cloudStorageAccount = ConnectionString.GetConnectionString();
                CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("blobstor1");

                if(await cloudBlobContainer.CreateIfNotExistsAsync())
                {
                    await cloudBlobContainer.SetPermissionsAsync(
                        new BlobContainerPermissions {
                            PublicAccess = BlobContainerPublicAccessType.Blob
                        }
                        );
                }
                string imageName = Guid.NewGuid().ToString() + "-" + Path.GetExtension(imageToUpload.FileName);

                CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(imageName);
                cloudBlockBlob.Properties.ContentType = imageToUpload.ContentType;
                await cloudBlockBlob.UploadFromStreamAsync(imageToUpload.InputStream);

               imageFullPath = cloudBlockBlob.Uri.ToString();
            }
            catch (Exception ex)
            {

            }
            return imageFullPath;
        }
    }
}

and my UI code are as below :-


@{
    ViewBag.Title = "Upload";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Upload Image</h2>
<br />

@using (Html.BeginForm("Upload", "Image", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <fieldset class="form-horizontal">
        <div class="form-group">
            <label class="control-label col-md-2" for="Photo">Photo</label>
            <div class="col-md-10">
                <input type="file" name="photo" />
            </div>
        </div>
        <div class="form-group">
            &nbsp;
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Submit" class="btn" />
            </div>

        </div>
    </fieldset>
   
}


Thank you .

Hope it is help you

Thursday, September 10, 2020

Sign out azure in vs code

 I was using an app service in Visual Studio Code to access a certain set of subscriptions I was working against and deploying to. This was prior to getting my pipelines ready, as that was my eventual deployment destination. In the meantime, I needed to sign out the account and noticed there wasn’t any GUI way to do this in the Azure extension (that I could find anyway). I did some looking and found the process:

Start by opening the Command Palette:


Find the sign-out command:

You can now sign back in:

Enjoy!



Thursday, July 30, 2020

Get an Invalid or Expired Token Error Response in postman for twitter api

The following error can occur if you have regenerated tokens or revoked access to your Twitter application.

Solution: Check the authorization for your application on the Twitter developer page and update the credentials for the adapter.

  1. Log in to the Twitter developer page and go to https://apps.twitter.com.

  2. If you have revoked access to the application, provide access by clicking Generate Access Token.

    
  1. Make a note of the following tokens in the Keys and Access Tokens tab:

    • Consumer key

    • Consumer secret

    • Access token

    • Access token secret

  2. Update the Twitter Adapter connection with these credentials.

Wednesday, June 17, 2020

How to Install NVM on Windows

If you want to use multiple Node version in you single system so you need to install the NVM (Node Version Manager) So in this post i have explain you how to install the NVM in window system.

Go to below URL.
https://github.com/coreybutler/nvm-windows

Click on Download Now 



Click on nvm-setup.zip than you download the zip file.



Extract the nvm-setup.zip file.


when you extract the file you will get nvm-setup.exe.So install this exe file in your system.
Go to start men type Git bash 


Thank you hope it is help you.



Tuesday, June 9, 2020

How to create an account on Azure DevOps?

Hello Friends in this post i will explain you how to create an account on Azure DevOps.


Azure DevOps can be accessed using following website-


click =>   Start free  =>  logged in  by using  you Microsoft username and Password.

On successful login you will get below screen.




Thank you