Browse Source

Moved classes from Program.cs to their own files

master
Claire 4 years ago
parent
commit
3fd1e36ec5
  1. 34
      MatrixDotNetLib/MatrixDotNetCmd/Program.cs
  2. 55
      MatrixDotNetLib/MatrixDotNetLib/MatrixEvent.cs
  3. 76
      MatrixDotNetLib/MatrixDotNetLib/MatrixEventContent.cs
  4. 46
      MatrixDotNetLib/MatrixDotNetLib/MatrixEventPrevContent.cs
  5. 47
      MatrixDotNetLib/MatrixDotNetLib/MatrixEventUnsigned.cs
  6. 43
      MatrixDotNetLib/MatrixDotNetLib/MatrixFileInfo.cs
  7. 44
      MatrixDotNetLib/MatrixDotNetLib/MatrixImageInfo.cs
  8. 45
      MatrixDotNetLib/MatrixDotNetLib/MatrixImageThumbInfo.cs
  9. 198
      MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs
  10. 7
      MatrixDotNetLib/MatrixDotNetLib/MatrixSyncBody.cs
  11. 39
      MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRoom.cs
  12. 109
      MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRooms.cs
  13. 46
      MatrixDotNetLib/MatrixDotNetLib/MatrixTimeline.cs

34
MatrixDotNetLib/MatrixDotNetCmd/Program.cs

@ -193,3 +193,37 @@ namespace MatrixDotNetCmd
}
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

55
MatrixDotNetLib/MatrixDotNetLib/MatrixEvent.cs

@ -0,0 +1,55 @@
using Newtonsoft.Json;
using System;
namespace MatrixDotNetLib
{
public class MatrixEvent
{
[JsonProperty("type")]
public string EventType { get; set; }
public string Sender { get; set; }
public MatrixEventContent Content { get; set; }
[JsonProperty("state_key")]
public string StateKey { get; set; }
[JsonProperty("origin_server_ts")]
public Int64 OriginTs { get; set; }
public MatrixEventUnsigned Unsigned { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

76
MatrixDotNetLib/MatrixDotNetLib/MatrixEventContent.cs

@ -0,0 +1,76 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace MatrixDotNetLib
{
public class MatrixEventContent
{
public string Body { get; set; }
public string Creator { get; set; }
public string DisplayName { get; set; }
[JsonProperty("event_id")]
public string EventId { get; set; }
/// <summary>
/// Gets or sets the event content info property - check FileInfo.MimeType for file type
/// </summary>
[JsonProperty("info")]
public MatrixImageInfo FileInfo { get; set; }
[JsonProperty("currently_active")]
public bool IsActive { get; set; }
[JsonProperty("join_rule")]
public string JoinRule { get; set; }
[JsonProperty("last_active_ago")]
public int LastActive { get; set; }
public string Membership { get; set; }
public string Name { get; set; }
public string Presence { get; set; }
[JsonProperty("room_version")]
public string RoomVersion { get; set; }
public List<string> Users { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

46
MatrixDotNetLib/MatrixDotNetLib/MatrixEventPrevContent.cs

@ -0,0 +1,46 @@
using Newtonsoft.Json;
namespace MatrixDotNetLib
{
public class MatrixEventPrevContent
{
[JsonProperty("is_direct")]
public bool IsDirect { get; set; }
public string Membership { get; set; }
public string DisplayName { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

47
MatrixDotNetLib/MatrixDotNetLib/MatrixEventUnsigned.cs

@ -0,0 +1,47 @@
using Newtonsoft.Json;
namespace MatrixDotNetLib
{
public class MatrixEventUnsigned
{
public int Age { get; set; }
[JsonProperty("replaces_state")]
public string ReplaceState { get; set; }
[JsonProperty("prev_content")]
public MatrixEventPrevContent PrevContent { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

43
MatrixDotNetLib/MatrixDotNetLib/MatrixFileInfo.cs

@ -0,0 +1,43 @@
using System;
namespace MatrixDotNetLib
{
public class MatrixFileInfo
{
public Int64 size { get; set; }
public string MimeType { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

44
MatrixDotNetLib/MatrixDotNetLib/MatrixImageInfo.cs

@ -0,0 +1,44 @@
using Newtonsoft.Json;
namespace MatrixDotNetLib
{
public class MatrixImageInfo : MatrixImageThumbInfo
{
[JsonProperty("thumbnail_info")]
public MatrixImageThumbInfo ThumbnailInfo { get; set; }
public string ThumbnailUrl { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

45
MatrixDotNetLib/MatrixDotNetLib/MatrixImageThumbInfo.cs

@ -0,0 +1,45 @@
using Newtonsoft.Json;
namespace MatrixDotNetLib
{
public class MatrixImageThumbInfo : MatrixFileInfo
{
[JsonProperty("w")]
public int Width { get; set; }
[JsonProperty("h")]
public int Height { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

198
MatrixDotNetLib/MatrixDotNetLib/MatrixSessionManager.cs

@ -1,7 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
@ -283,202 +281,6 @@ namespace MatrixDotNetLib
}
}
}
// classes to be moved //
public class MatrixSyncBody
{
public MatrixSyncRooms Rooms { get; set; }
}
public class MatrixSyncRooms
{
// once the JSON from "join" is parsed, this is set to its contents as an object
public Dictionary<string,MatrixSyncRoom> Joined { get; private set;}
public Dictionary<string, MatrixSyncRoom> Invited { get; private set; }
public Dictionary<string, MatrixSyncRoom> Left { get; private set; }
public JObject Join
{
get { return null; }
set
{
// takes JSON children and parses them into objects
// we have to do this bc the entity names under "join" are dynamic
// each entity holds a well-defined object though
// create dict for Joined
Joined = new Dictionary<string, MatrixSyncRoom>();
// these AREN'T an array
ParseRooms(value, "Joined");
}
}
public JObject Invite
{
get { return null; }
set
{
// create dict for Joined
Invited = new Dictionary<string, MatrixSyncRoom>();
// these AREN'T an array
ParseRooms(value, "Invited");
}
}
public JObject Leave
{
get { return null; }
set
{
// create dict for Joined
Left = new Dictionary<string, MatrixSyncRoom>();
// these AREN'T an array
ParseRooms(value, "Left");
}
}
public void ParseRooms(JObject roomsJson, string valType)
{
// get the children of this object
JEnumerable<JToken> kids = roomsJson.Children();
Dictionary<string,MatrixSyncRoom> roomList = new Dictionary<string,MatrixSyncRoom>();
foreach (JProperty kid in kids)
{
MatrixSyncRoom msr = JsonConvert.DeserializeObject<MatrixSyncRoom>(kid.Value.ToString());
roomList.Add(kid.Name, msr);
}
// get the target
this.GetType().GetProperty(valType).SetValue(this,roomList);
}
}
public class MatrixSyncRoom
{
public MatrixTimeline Timeline { get; set; }
}
public class MatrixTimeline
{
public MatrixEvent[] Events { get; set; }
[JsonProperty("prev_batch")]
public string PreviousBatch { get; set; }
public bool IsLimited { get; set; }
}
public class MatrixEvent
{
[JsonProperty("type")]
public string EventType { get; set; }
public string Sender { get; set; }
public MatrixEventContent Content { get; set; }
[JsonProperty("state_key")]
public string StateKey { get; set; }
[JsonProperty("origin_server_ts")]
public Int64 OriginTs { get; set; }
public MatrixEventUnsigned Unsigned { get; set; }
}
public class MatrixEventUnsigned
{
public int Age { get; set; }
[JsonProperty("replaces_state")]
public string ReplaceState { get; set; }
[JsonProperty("prev_content")]
public MatrixEventPrevContent PrevContent { get; set; }
}
public class MatrixEventPrevContent
{
[JsonProperty("is_direct")]
public bool IsDirect { get; set; }
public string Membership { get; set; }
public string DisplayName { get; set; }
}
public class MatrixEventContent
{
public string Body { get; set; }
public string Creator { get; set; }
public string DisplayName { get; set; }
[JsonProperty("event_id")]
public string EventId { get; set; }
/// <summary>
/// Gets or sets the event content info property - check FileInfo.MimeType for file type
/// </summary>
[JsonProperty("info")]
public MatrixImageInfo FileInfo { get; set; }
[JsonProperty("currently_active")]
public bool IsActive { get; set; }
[JsonProperty("join_rule")]
public string JoinRule { get; set; }
[JsonProperty("last_active_ago")]
public int LastActive { get; set; }
public string Membership { get; set; }
public string Name { get; set; }
public string Presence { get; set; }
[JsonProperty("room_version")]
public string RoomVersion { get; set; }
public List<string> Users { get; set; }
}
public class MatrixFileInfo
{
public Int64 size { get; set; }
public string MimeType { get; set; }
}
public class MatrixImageThumbInfo : MatrixFileInfo
{
[JsonProperty("w")]
public int Width { get; set; }
[JsonProperty("h")]
public int Height { get; set; }
}
public class MatrixImageInfo : MatrixImageThumbInfo
{
[JsonProperty("thumbnail_info")]
public MatrixImageThumbInfo ThumbnailInfo { get; set; }
public string ThumbnailUrl { get; set; }
}
}

7
MatrixDotNetLib/MatrixDotNetLib/MatrixSyncBody.cs

@ -0,0 +1,7 @@
namespace MatrixDotNetLib
{
public class MatrixSyncBody
{
public MatrixSyncRooms Rooms { get; set; }
}
}

39
MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRoom.cs

@ -0,0 +1,39 @@
namespace MatrixDotNetLib
{
public class MatrixSyncRoom
{
public MatrixTimeline Timeline { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

109
MatrixDotNetLib/MatrixDotNetLib/MatrixSyncRooms.cs

@ -0,0 +1,109 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
namespace MatrixDotNetLib
{
public class MatrixSyncRooms
{
// once the JSON from "join" is parsed, this is set to its contents as an object
public Dictionary<string,MatrixSyncRoom> Joined { get; private set;}
public Dictionary<string, MatrixSyncRoom> Invited { get; private set; }
public Dictionary<string, MatrixSyncRoom> Left { get; private set; }
public JObject Join
{
get { return null; }
set
{
// takes JSON children and parses them into objects
// we have to do this bc the entity names under "join" are dynamic
// each entity holds a well-defined object though
// create dict for Joined
Joined = new Dictionary<string, MatrixSyncRoom>();
// these AREN'T an array
ParseRooms(value, "Joined");
}
}
public JObject Invite
{
get { return null; }
set
{
// create dict for Joined
Invited = new Dictionary<string, MatrixSyncRoom>();
// these AREN'T an array
ParseRooms(value, "Invited");
}
}
public JObject Leave
{
get { return null; }
set
{
// create dict for Joined
Left = new Dictionary<string, MatrixSyncRoom>();
// these AREN'T an array
ParseRooms(value, "Left");
}
}
public void ParseRooms(JObject roomsJson, string valType)
{
// get the children of this object
JEnumerable<JToken> kids = roomsJson.Children();
Dictionary<string,MatrixSyncRoom> roomList = new Dictionary<string,MatrixSyncRoom>();
foreach (JProperty kid in kids)
{
MatrixSyncRoom msr = JsonConvert.DeserializeObject<MatrixSyncRoom>(kid.Value.ToString());
roomList.Add(kid.Name, msr);
}
// get the target
this.GetType().GetProperty(valType).SetValue(this,roomList);
}
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}

46
MatrixDotNetLib/MatrixDotNetLib/MatrixTimeline.cs

@ -0,0 +1,46 @@
using Newtonsoft.Json;
namespace MatrixDotNetLib
{
public class MatrixTimeline
{
public MatrixEvent[] Events { get; set; }
[JsonProperty("prev_batch")]
public string PreviousBatch { get; set; }
public bool IsLimited { get; set; }
}
}
//// simplest implementation
//// might not work for UWP
//// sauce: https://stackoverflow.com/questions/5527316/how-to-set-the-content-of-an-httpwebrequest-in-c
//HttpContent requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
//HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(loginUrl);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//HttpResponseMessage responseMessage = client.PostAsync(loginUrl, requestContent).Result;
//string responseString = responseMessage.Content.ReadAsStringAsync().Result;
//if(responseString.Contains("errcode"))
//{
// // deserialize into error object
// MatrixError error = JsonConvert.DeserializeObject<MatrixError>(responseString);
// // convert error object to a string
// string errMsg = error.ErrorCode + ": " + error.ErrorMessage;
// // throw exception (can be caught and handled gracefully)
// throw new Exception(errMsg);
//}
//else
//{
// MatrixLoginResponse response = JsonConvert.DeserializeObject<MatrixLoginResponse>(responseString);
// return response;
//}
Loading…
Cancel
Save