Skip to content

Instantly share code, notes, and snippets.

Avatar

Asish Padhy AsishP

  • Sydney, Australia
View GitHub Profile
View GetTranslatedText.cs
public string getTranslatedText(string text)
{
string host = "https://api.cognitive.microsofttranslator.com";
string route = "/translate?api-version=3.0&to=en";
string translatedText = "";
System.Object[] body = new System.Object[] { new { Text = text } };
var requestBody = JsonConvert.SerializeObject(body);
using (var client = new HttpClient())
View DetectLanguage.cs
public string DetectLanguageFromText(string text)
{
log.Info($"Got Text {text}");
string detectedLanguage = "";
var result = client.DetectLanguageAsync(new BatchInput(
new List<Input>()
{
new Input("1", text)
})).Result;
View TextAnalyticsInitialisation.cs
public TextAnalyticsProcessing(TraceWriter Log)
{
log = Log;
log.Info("Text Processing Section Called");
// Create a client.
client = new TextAnalyticsClient(new ApiKeyServiceClientCredentials())
{
Endpoint = "https://australiaeast.api.cognitive.microsoft.com"
}; //Replace 'australiaeast' with the correct region for your Text Analytics subscription
log.Info("Text Processing section initialized");
@AsishP
AsishP / AddUpdateSPHttpClient.ts
Last active May 6, 2019
Add/Update with SP Http Client
View AddUpdateSPHttpClient.ts
try
{
let addorUpdateObj : any = {
AuthorId : customObj.user.id,
__metadata : {
'type': `SP.Data.CustomListItem`
}
}
console.log(`Sending object ${addorUpdateObj}`);
@AsishP
AsishP / GetSPDataHttpClient.ts
Created May 6, 2019
Get operation using SP Http Client
View GetSPDataHttpClient.ts
try {
let spHttpClient : SPHttpClient = context.spHttpClient;
let url = `${context.pageContext.web.absoluteUrl}/_api/web/lists/GetByTitle('${listTitle}')/Items?$select=Author/EMail,*&$expand=Author&$filter=Author/EMail eq 'XYZ@xyz.com'`;
spHttpClient.get(url, SPHttpClient.configurations.v1).then((response : SPHttpClientResponse) => {
if(response.ok)
{
response.json().then((responseJson : any) => {
console.log(responseJson);
if (this.isValidObject(responseJson) && responseJson.value.length !== 0) {
resolve({
@AsishP
AsishP / SingleWebPartApp.ps1
Last active Feb 27, 2019
Add Single Web Part App Page
View SingleWebPartApp.ps1
Connect-PnPOnline -Url "https://sharepoint.com"
## Add Page using PnP PowerShell
$page = Add-PnPClientSidePage -Name "TestAppPart.aspx" -LayoutType SingleWebPartAppPage
## Add a section the Page
Add-PnPClientSidePageSection -Page $page -SectionTemplate OneColumnFullWidth
## Add a Client Side Web Part
Add-PnPClientSideWebPart -Page $page -DefaultWebPartType SiteActivity -Section 0 -Column 0
View MasterComponentReactControl
export default class MasterComponent extends React.Component<MasterComponentProps, MasterComponentState> {
constructor()
{
super();
this._childSelect = this._childSelect.bind(this);
this.state= {
stateprop1 : null,
stateprop2 : true
}
View ChildComponentReactControl
import * as React from 'react';
import { ChildComponentState } from './ChildComponentState';
import { WebPartContext } from '@microsoft/sp-webpart-base';
export interface ChildComponentProps
{
context : WebPartContext;
childoutput?: (item: any) => void;
}
@AsishP
AsishP / Get data from Office 365 Azure Log
Last active Jul 17, 2019
Get data from Office 365 Azure Log
View Get data from Office 365 Azure Log
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
using System.Web;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using Newtonsoft.Json;
using System.IO;
using Microsoft.Extensions.Logging;
using System.Linq;
@AsishP
AsishP / Connect to Azure AD in Azure Function
Last active Jun 13, 2019
Connect to Azure AD in Azure Function
View Connect to Azure AD in Azure Function
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using System.Collections.Generic;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs.Extensions.Http;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Extensions.Logging;
You can’t perform that action at this time.