How to get WellKnownFolderName.MsgFolderRoot using Microsoft graph SDk (GraphClient) in C# - microsoft-graph-sdks

In EWS WellKnownFolderName.MsgFolderRoot is present to get root folder details but in Graph SDK unable to find similar method. Our application supports EWS call but due to user migration to M365 this didn't work.

Graph API has similar well-known folder names but they are not defined in Microsoft Graph Client Library for .NET.
When you call Graph API you need to specify the name of well-known folder.
I have a class for this.
public static class WellKnownFolderNames
{
public const string Archive = "archive";
public const string Clutter = "clutter";
public const string Conflicts = "conflicts";
public const string ConversationHistory = "conversationhistory";
public const string DeletedItems = "deleteditems";
public const string Drafts = "drafts";
public const string Inbox = "inbox";
public const string JunkEmail = "junkemail";
public const string LocalFailures = "localfailures";
public const string MsgFolderRoot = "msgfolderroot";
public const string Outbox = "outbox";
public const string RecoverableItemsDeletions = "recoverableitemsdeletions";
public const string Scheduled = "scheduled";
public const string SearchFolders = "searchfolders";
public const string SentItems = "sentitems";
public const string ServerFailures = "serverfailures";
public const string SyncIssues = "syncissues";
}
await graphClient.Me.MailFolders[WellKnownFolderNames.MsgFolderRoot]
.Request()
.GetAsync();

Related

Getting json data from Spoonacular in Android Studio

trying to get to an Android App random recipes from Spoonacular. For some reason, I'm not getting the data from the json. I know how to do this in Javascript, but that's no use to me in Java.
My repository file:
public class RecipeRepository {
private static final String API_KEY = "472f31ce4a5e4e5792ca9ab6d1833e51";
private static final String URL = "https://api.spoonacular.com/recipes/random?apiKey=%s";
private final Application application;
private final MutableLiveData<ArrayList<Recipe>> recipeLiveData;
private final ArrayList<Recipe> arrayList = new ArrayList<>();
public RecipeRepository(Application application) {
this.application = application;
recipeLiveData = new MutableLiveData<>();
}
public void getDayRecipe() {
Ion.with(application)
.load(String.format(URL,API_KEY)).asJsonObject()
.setCallback((e, result) -> {
Log.i( "getRandomRecipe",result.getAsJsonPrimitive().toString());
parseResults(result);
});
}
public String removeAbles(String text) {return text.substring(1,text.length()-1); }
private void parseResults(JsonObject result) {
JsonObject randomRecipe = (JsonObject) result.getAsJsonArray("recipes").get(0);
String title = String.valueOf(randomRecipe.get("title"));
String instructions = String.valueOf(randomRecipe.get("Instructions"));
//ingredients
//image
recipeLiveData.setValue(arrayList);
}
public MutableLiveData<ArrayList<Recipe>> getRecipeLiveData() {
return recipeLiveData;
}
}
I get a 'variable is never used' with title, instructions and removeAbles

Passing JSON from Unity Application to Firebase function with onCall results as undefined

Hey why are Firebase Logs telling me that following data is undefined:
In unity i have following class:
public class Question
{
private string question;
private string answerA;
private string answerB;
private string answerC;
private string answerD;
private string rightAnswer;
public Question(string question, string answerA, string answerB, string answerC, string answerD, string rightAnswer)
{
this.question = question;
this.answerA = answerA;
this.answerB = answerB;
this.answerC = answerC;
this.answerD = answerD;
this.rightAnswer = rightAnswer;
}
}
When i click a button i create a object of Question and transform it into a JSON:
submitButton.onClick.AddListener(() =>
{
Question myQuestion = new Question(questionField.text, answerAField.text,
answerBField.text, answerCField.text, answerDField.text, rightAnswer.text);
string json = JsonUtility.ToJson(myQuestion);
firebaseManager.createQuestion(json);
});
finally i pass the JSON string to following function:
public void createQuestion(string json)
{
var function = FirebaseFunctions.DefaultInstance.GetHttpsCallable("createQuestion");
function.CallAsync(json).ContinueWithOnMainThread(task =>
{
if (task.IsCompleted)
Debug.Log("done");
});
}
My firebase function is just printing some fields of the JSON but the problem is that my firebase function says that the data is undefined:
exports.createQuestion = functions.https.onCall((data, context) => {
console.log(data.answerA);
console.log(data.answerB);
return 0;
});
When i use a Dictionary<string,object> instead of the JSON string then it is working but i wanna know why the JSON solution is not working?
SOLUTION
had to change the code on the server:
exports.createQuestion = functions.https.onCall((data, context) => {
var myObject = JSON.parse(data);
console.log(myObject.answerA);
console.log(myObject.answerB);
return 0;
});
Put this attribute on top of your data class
[System.Serializable]
Classes without that wont serialize.
Make the fields you want to serialize public, Private fields wont serialize.
[System.Serializable]
public class Question
{
public string question;
public string answerA;
public string answerB;
public string answerC;
public string answerD;
public string rightAnswer;
public Question(string question, string answerA, string answerB, string answerC, string answerD, string rightAnswer)
{
this.question = question;
this.answerA = answerA;
this.answerB = answerB;
this.answerC = answerC;
this.answerD = answerD;
this.rightAnswer = rightAnswer;
}
}

Get JSON response from Web API

I want to get JSON response from Web API Call. I am calling it like below
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://myapi.proj.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("Authorization", "Basic TUNTRTpNQ1MhZTIwMTc=");
client.DefaultRequestHeaders.Add("ClientURL", "http://123.com");
var response = client.PostAsJsonAsync("api/name/", priceRequest).Result;
I am unable to JSON in response variable. I want to get JSON response and assign it to my class which is somewhat like below
public class Information
{
public int id{ get; set; }
public string Name{ get; set; }
public string address{ get; set; }
}
Try this:
Information obj = await response.Content.ReadAsAsync<Information>();
You need to reference System.Net.Http.Formatting assembly where extension method ReadAsAsync<T> is defined.
I found myself
This is what i used
var result = response.Content.ReadAsStringAsync().Result;
var test = Newtonsoft.Json.JsonConvert.DeserializeObject(result);

UWP: Nested Custom Types with DataContractJsonSerializer

I am creating a nested custom type with primitive datatypes.
I am having a Web APi that returns the data in JSON.
using json2csharp.com, I am generating classes for the same.
I have decorated the primitive datatypes in all classes with DataMember and the types with DataContract.
I am using the following code for deserialization:
var resp = httpClient.GetAsync("http://ACTUAL_API_URI").Result;
var res = await resp.Content.ReadAsStringAsync();
var serializer = new DataContractJsonSerializer(typeof(RootObject));
byte[] byteArr= Encoding.ASCII.GetBytes(res);
var ms = new MemoryStream(byteArr);
var deserializedObj= (RootObject)serializer.ReadObject(ms);
I am not getting any exception. but the deserializedObj has null values for all the properties.
Any suggestions ?
You have a couple mistakes.
You returns collection of elements and try to deserialize one element instead collection
public IEnumerable<SampleData> Get()
{
return new SampleData[]
{
new SampleData()
{
Value = 100,
NestedTypeObject1 = new NestedType1()
{
ID = 101,
BD = "Description#1",
UD = "Description#2"
},
NestedTypeObject2 = new NestedType2()
{
Date = DateTime.Now.ToString(),
S1 = "S1 String",
S2 = "S2 String"
}
}
};
}
so you just change your code to
var serializer = new DataContractJsonSerializer(typeof(List<RootObject>));
var deserializedObj= (List<RootObject>)serializer.ReadObject(ms);
You have different model names between service side and client side, just you your SampleData model and all will be good. You must to rename MyNestedType1 to NestedTypeObject1 or add name to DataContractAttribute, e.g:
[DataContract(Name = "NestedTypeObject1")]
public class MyNestedType1
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string BD { get; set; }
[DataMember]
public string UD { get; set; }
}
It belongs for property names too.

Retrieving Data from File in Windows 8 Store App

I have created an application in which i have successfully write the details in the file. But while accessing the file from the application i am getting the following exceptoin:
Following is my class:
public class UserDetails
{
public string Name { get; set; }
public string Course { get; set; }
public string City { get; set; }
}
Following is my code to write and read and file:
private async void btnSearch_Click(object sender, RoutedEventArgs e)
{
details.Name = TxtName.Text;
details.Course = TxtCouse.Text;
details.City = TxtCity.Text;
await SaveAsync();
this.Frame.Navigate(typeof(string));
}
private async Task SaveAsync()
{
StorageFolder localfolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Storage Application", CreationCollisionOption.OpenIfExists);
StorageFile sampleFile = await localfolder.CreateFileAsync("UserDetails", CreationCollisionOption.ReplaceExisting);
IRandomAccessStream stream = await sampleFile.OpenAsync(FileAccessMode.ReadWrite);
using(IOutputStream outstream = stream.GetOutputStreamAt(0))
{
DataContractSerializer serializer = new DataContractSerializer(typeof(UserDetails));
serializer.WriteObject(outstream.AsStreamForWrite(), details);
await outstream.FlushAsync();
}
await RestoreDataAsync();
}
private async Task RestoreDataAsync()
{
StorageFolder localfolder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Storage Application");
StorageFile sampleFile = await localfolder.GetFileAsync("UserDetails");
IRandomAccessStream inStream = await sampleFile.OpenAsync(FileAccessMode.Read);
DataContractSerializer serializer = new DataContractSerializer(typeof(UserDetails));
var Details = (UserDetails)serializer.ReadObject(inStream.AsStreamForRead());
inStream.Dispose();
TblName.Text = details.Name;
TblCourse.Text = details.Course;
TblCity.Text = details.City;
}
I am new in creating Windows Store App.
The issue is your SaveAsync() method, You opened the StorageFile of sampleFile, but havn't disposed it. Try to add sampleFile.Dispose(); after you used it.