diff --git a/Socialvoid/Client/SocialvoidClient.cs b/Socialvoid/Client/SocialvoidClient.cs index abfbcf5..64b1a10 100644 --- a/Socialvoid/Client/SocialvoidClient.cs +++ b/Socialvoid/Client/SocialvoidClient.cs @@ -24,9 +24,10 @@ using Socialvoid.JObjects; using Socialvoid.Security; using Socialvoid.Security.Otp; using Socialvoid.SvObjects; +using Socialvoid.Errors.RPCErrors; using Socialvoid.Errors.ServerErrors; -using Socialvoid.Errors.AuthenticationErrors; using Socialvoid.Errors.ValidationErrors; +using Socialvoid.Errors.AuthenticationErrors; using MType = System.Net.Http.Headers.MediaTypeHeaderValue; namespace Socialvoid.Client @@ -125,6 +126,11 @@ namespace Socialvoid.Client /// protected const string RegisterMethod = "session.register"; /// + /// authenticate_user method value. + /// since: v0.0.0 + /// + protected const string GetSessionMethod = "session.get"; + /// /// get_terms_of_service method value. /// since: v0.0.0 /// @@ -207,6 +213,11 @@ namespace Socialvoid.Client /// protected internal SessionEstablished _session; /// + /// Session info object of this client. + /// since: v0.0.0 + /// + protected internal Session _sessionInfo; + /// /// if the client should send an otp answer in the next request, /// this field should be set to true. /// since: v0.0.0 @@ -289,7 +300,7 @@ namespace Socialvoid.Client // some methods here #endregion //------------------------------------------------- - #region ordinary Method's Region + #region Session Method's Region /// /// CreateSession method (session.create), establishes a new session /// to the network. @@ -561,6 +572,81 @@ namespace Socialvoid.Client return jresp.Result; } /// + /// GetSession method (session.get), Returns information about the + /// current session identified by the SessionIdentification parameter. + /// since: v0.0.0 + /// + /// + /// The Session Identification object. + /// (optional if and only if this client has already established + /// a session OR is set to true). + /// + /// + /// set it to true if you want to store the session in the + /// client. + /// + /// + /// + /// + /// + /// + /// + /// + public virtual Session GetSession( + SessionIdentification sessionID = null, + bool store = true) + { + if (sessionID == null) + { + if (_session == null) + { + if (!AutoSession) + { + throw new InvalidOperationException("SessionID is not created."); + } + _session = CreateSession(); + } + + sessionID = new() + { + SessionID = _session.SessionID, + ClientPublicHash = PublicHash + }; + } + + JArgs args = new(){ + {SessionIDKey, sessionID}, + }; + + CheckAnswer(sessionID); + + var jresp = ParseContent( + GetMessage(GetSessionMethod, args)); + + if (jresp == null) + { + // this shouldn't happen in normal cases. + throw new InvalidOperationException( + "received invalid response from server."); + } + + if (store) + { + _sessionInfo = jresp.Result; + } + + return jresp.Result; + } + /// + /// returns a challenge's answer using the session's challenge secret. + /// since: v0.0.0 + /// + protected internal virtual string GetChallengeAnswer(string secret) => + KeyGeneration.GetChallengeAnswer(secret, PrivateHash); + #endregion + //------------------------------------------------- + #region Get Method's Region + /// /// GetTermsOfService (help.get_terms_of_service), Returns a /// HelpDocument object that contains information about the /// Terms of Services (ToS) for the network. @@ -582,26 +668,14 @@ namespace Socialvoid.Client return jresp.Result; } - - /// - /// returns a challenge's answer using the session's challenge secret. - /// since: v0.0.0 - /// - protected internal virtual string GetChallengeAnswer(string secret) => - KeyGeneration.GetChallengeAnswer(secret, PrivateHash); - #endregion - //------------------------------------------------- - #region Get Method's Region /// /// Gets the session of this if and only /// if you have already established a session (or has loaded it from a file); /// oterwise it will just return a null object instead of throwing an exception. /// since: v0.0.0 /// - public virtual SessionEstablished GetSession() - { - return _session; - } + public virtual SessionEstablished GetSessionVariable() => + _session; /// /// since: v0.0.0 /// diff --git a/Socialvoid/Security/IChallenge.cs b/Socialvoid/Security/IChallenge.cs index a3d4996..4389f9c 100644 --- a/Socialvoid/Security/IChallenge.cs +++ b/Socialvoid/Security/IChallenge.cs @@ -26,6 +26,8 @@ namespace Socialvoid.Security /// public interface IChallenge { + //------------------------------------------------- + #region Get Method's Region /// /// Checks if the challenge is valid. /// since: v0.0.0 @@ -49,5 +51,7 @@ namespace Socialvoid.Security /// since: v0.0.0 /// void DelSecret(); + #endregion + //------------------------------------------------- } } \ No newline at end of file diff --git a/Socialvoid/Security/IIdentitiable.cs b/Socialvoid/Security/IIdentitiable.cs new file mode 100644 index 0000000..f5959c0 --- /dev/null +++ b/Socialvoid/Security/IIdentitiable.cs @@ -0,0 +1,49 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +using System; + +namespace Socialvoid.Security +{ + /// + /// Interface for classes and structs which provides a valid ID. + /// since: v0.0.0 + /// + public interface IIdentitiable + where T: IComparable, IConvertible + { + //------------------------------------------------- + #region Get Method's Region + /// + /// Checks if the ID of this object is valid. + /// since: v0.0.0 + /// + /// + /// true if the ID is valid; + /// otherwise, false. + /// + bool HasValidID(); + /// + /// Returns the ID of this object. + /// since: v0.0.0 + /// + T GetID(); + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Security/ISender.cs b/Socialvoid/Security/ISender.cs index c9de355..3772240 100644 --- a/Socialvoid/Security/ISender.cs +++ b/Socialvoid/Security/ISender.cs @@ -25,6 +25,8 @@ namespace Socialvoid.Security /// public interface ISender { + //------------------------------------------------- + #region Get Method's Region /// /// Sends data to a remote service. /// since: v0.0.0 @@ -35,5 +37,7 @@ namespace Socialvoid.Security /// since: v0.0.0 /// bool AddSome(string key, string data); + #endregion + //------------------------------------------------- } } \ No newline at end of file diff --git a/Socialvoid/Security/Session.cs b/Socialvoid/Security/Session.cs new file mode 100644 index 0000000..d973156 --- /dev/null +++ b/Socialvoid/Security/Session.cs @@ -0,0 +1,319 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +using System; +using System.Text.Json.Serialization; +using Socialvoid.SvObjects; + +namespace Socialvoid.Security +{ + /// + /// A object contains basic information + /// about the session that the server has created for us. + /// since: v0.0.0 + /// + public sealed class Session: IIdentitiable, IFlagable + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The ID of the session obtained when establishing a session. + /// since: v0.0.0 + /// + [JsonPropertyName("id")] + public string SessionID { get; set; } + /// + /// An array of flags that has been set to this session. + /// since: v0.0.0 + /// + [JsonPropertyName("flags")] + public string[] Flags { get; set; } + /// + /// Indicates if the session is currently authenticated to a user. + /// since: v0.0.0 + /// + [JsonPropertyName("authenticated")] + public bool Authenticated { get; set; } + /// + /// The Unix Timestamp for when this session was first created. + /// since: v0.0.0 + /// + [JsonPropertyName("created")] + public long Created { get; set; } + /// + /// The Unix Timestamp for when this session expires. + /// since: v0.0.0 + /// + [JsonPropertyName("expires")] + public long Expires { get; set; } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Checks if the ID of this object is valid. + /// since: v0.0.0 + /// + /// + /// true if the ID is valid; + /// otherwise, false. + /// + public bool HasValidID() => + !string.IsNullOrWhiteSpace(SessionID); + /// + /// Returns the ID of this object. + /// since: v0.0.0 + /// + public string GetID() => SessionID; + /// + /// Returns the flags of this object. + /// since: v0.0.0 + /// + /// + /// the flags of this object as an array of + /// objects. + /// + public string[] GetFlags() => Flags; + /// + /// Checks if this object has any flag or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array is not null and it's length + /// is more than zero; otherwise false. + /// + public bool HasFlag() => Flags != null && Flags.Length > 0; + /// + /// Checks if this object has at the very least one of the specified + /// flags or not. If you want to check for all of the flags, please + /// use method. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object contains at the very + /// least one of the specified flags; otherwise false. + /// + public bool HasFlag(params string[] flags) + { + if (flags == null || flags.Length == 0 || !HasFlag()) + { + return false; + } + else if (flags.Length == 1) + { + // easy path: inlined so we can reduce the running time. + foreach (var f in Flags) + { + if (f == flags[default]) + { + return true; + } + } + } + + foreach(var f in flags) + { + if (hasFlag(f)) + { + return true; + } + } + + return false; + } + /// + /// Returns the length of the flag arrays of this object. + /// If the flag array is empty, this method will return zero. + /// since: v0.0.0 + /// + public int GetFlagLength() => + Flags == null ? default : Flags.Length; + /// + /// Checks if the length of the flag array is zero or not. + /// since: v0.0.0 + /// + public bool HasZeroFlags() => GetFlagLength() == default; + /// + /// Checks if this object has all of the specified flags or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object has all of the + /// specified flags; otherwise false. + /// + public bool HasFlags(params string[] flags) + { + if (flags == null || flags.Length == 0 || !HasFlag()) + { + return false; + } + else if (flags.Length == 1) + { + // easy path: inlined so we can reduce the running time. + foreach (var f in Flags) + { + if (f != flags[default]) + { + return false; + } + } + } + + foreach (var f in flags) + { + if (!hasFlag(f)) + { + return false; + } + } + + return true; + } + /// + /// Returns the flag of this object using the specified index + /// in the flag array. + /// since: v0.0.0 + /// + /// + /// the index of the flag. + /// + /// + /// set this argument to true if you want the method to + /// throw an exception in the case it couldn't return any flag. + /// if you set this to false the method will return + /// null (or default). + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + public string GetFlag(int index, bool ex = true) + { + if (HasZeroFlags()) + { + if (ex) + { + throw new InvalidOperationException( + $"flags length of this {GetType().ToString()} is 0"); + } + return null; + } + if (index < 0) + { + if (ex) + { + throw new ArgumentException( + "index cannot be negatice", + nameof(index)); + } + return null; + } + if (index > GetFlagLength()) + { + if (ex) + { + throw new ArgumentException( + $"index({index}), cannot be more than"+ + $" flags array length({GetFlagLength()})", + nameof(index)); + } + return null; + } + return Flags[index]; + } + + /// + /// Checks if the flag array of this object contains a single flag + /// or not. + /// + private bool hasFlag(string flag) + { + if (string.IsNullOrWhiteSpace(flag)) + { + return false; + } + foreach (var f in Flags) + { + if (f == flag) + { + return true; + } + } + return false; + } + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/Security/SessionEstablished.cs b/Socialvoid/Security/SessionEstablished.cs index 7969b48..9cc6861 100644 --- a/Socialvoid/Security/SessionEstablished.cs +++ b/Socialvoid/Security/SessionEstablished.cs @@ -25,7 +25,8 @@ namespace Socialvoid.Security /// about the session that the server has created for us. /// since: v0.0.0 /// - public sealed class SessionEstablished : IChallenge + public sealed class SessionEstablished: + IChallenge, IIdentitiable { //------------------------------------------------- #region Constant's Region @@ -123,6 +124,21 @@ namespace Socialvoid.Security /// public bool HasSecret() => !string.IsNullOrWhiteSpace(ChallengeSecret); + /// + /// Checks if the ID of this object is valid. + /// since: v0.0.0 + /// + /// + /// true if the ID is valid; + /// otherwise, false. + /// + public bool HasValidID() => + !string.IsNullOrWhiteSpace(SessionID); + /// + /// Returns the ID of this object. + /// since: v0.0.0 + /// + public string GetID() => SessionID; #endregion //------------------------------------------------- #region Set Method's Region diff --git a/Socialvoid/Security/SessionIdentification.cs b/Socialvoid/Security/SessionIdentification.cs index 5fc96a6..440f76d 100644 --- a/Socialvoid/Security/SessionIdentification.cs +++ b/Socialvoid/Security/SessionIdentification.cs @@ -30,7 +30,7 @@ namespace Socialvoid.Security /// will cause the request to fail as it's validated upon request. /// since: v0.0.0 /// - public sealed class SessionIdentification + public sealed class SessionIdentification: IIdentitiable { //------------------------------------------------- #region Constant's Region @@ -114,7 +114,21 @@ namespace Socialvoid.Security #endregion //------------------------------------------------- #region Get Method's Region - // some methods here + /// + /// Checks if the ID of this object is valid. + /// since: v0.0.0 + /// + /// + /// true if the ID is valid; + /// otherwise, false. + /// + public bool HasValidID() => + !string.IsNullOrWhiteSpace(SessionID); + /// + /// Returns the ID of this object. + /// since: v0.0.0 + /// + public string GetID() => SessionID; #endregion //------------------------------------------------- #region Set Method's Region diff --git a/Socialvoid/SvObjects/FileTypes.cs b/Socialvoid/SvObjects/FileTypes.cs new file mode 100644 index 0000000..e982deb --- /dev/null +++ b/Socialvoid/SvObjects/FileTypes.cs @@ -0,0 +1,53 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/// +/// File types indicate the content type of the file, if the server is +/// unable to determine the file type then it will default to DOCUMENT. +/// Since: v0.0.0 +/// +public enum FileTypes +{ + //------------------------------------------------- + #region general types + /// + /// The default value of an . + /// Since: v0.0.0 + /// + Document = 0, + #endregion + //------------------------------------------------- + #region Another styling + /// + /// The file is an image file type. + /// Since: v0.0.0 + /// + Photo = 1, + /// + /// The file is an video file type. + /// Since: v0.0.0 + /// + Video = 2, + /// + /// The file is an audio file type. + /// Since: v0.0.0 + /// + Audio = 3, + #endregion + //------------------------------------------------- +} diff --git a/Socialvoid/SvObjects/HelpDocument.cs b/Socialvoid/SvObjects/HelpDocument.cs index c29dbd1..25936d8 100644 --- a/Socialvoid/SvObjects/HelpDocument.cs +++ b/Socialvoid/SvObjects/HelpDocument.cs @@ -16,9 +16,9 @@ * If not, see . */ -using System.Collections.Generic; using System.Text.Json.Serialization; -using Socialvoid.SvObjects.Media; +using Socialvoid.SvObjects.Text; +using Socialvoid.Security; namespace Socialvoid.SvObjects { @@ -29,7 +29,7 @@ namespace Socialvoid.SvObjects /// what actions are available for a peer. /// since: v0.0.0 /// - public class HelpDocument + public class HelpDocument: IIdentitiable { //------------------------------------------------- #region Constant's Region @@ -58,7 +58,7 @@ namespace Socialvoid.SvObjects /// since: v0.0.0 /// [JsonPropertyName("entities")] - public object[] Entities { get; set; } + public TextEntity[] Entities { get; set; } #endregion //------------------------------------------------- #region static field's Region @@ -112,7 +112,21 @@ namespace Socialvoid.SvObjects #endregion //------------------------------------------------- #region Get Method's Region - // some methods here + /// + /// Returns the ID of this object. + /// since: v0.0.0 + /// + public string GetID() => ID; + /// + /// Checks if the ID of this object is valid. + /// since: v0.0.0 + /// + /// + /// true if the ID is valid; + /// otherwise, false. + /// + public bool HasValidID() => + !string.IsNullOrWhiteSpace(ID); #endregion //------------------------------------------------- #region Set Method's Region diff --git a/Socialvoid/SvObjects/IFlagable.cs b/Socialvoid/SvObjects/IFlagable.cs new file mode 100644 index 0000000..abe1666 --- /dev/null +++ b/Socialvoid/SvObjects/IFlagable.cs @@ -0,0 +1,100 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.SvObjects +{ + /// + /// This interface is created for solving compability issues. + /// since: v0.0.0 + /// + public interface IFlagable + { + //------------------------------------------------- + #region Get Method's Region + /// + /// Returns the flags of this object. + /// since: v0.0.0 + /// + /// + /// the flags of this object as an array of + /// objects. + /// + T[] GetFlags(); + /// + /// Returns the length of the flag arrays of this object. + /// If the flag array is empty, this method will return zero. + /// since: v0.0.0 + /// + int GetFlagLength(); + /// + /// Checks if the length of the flag array is zero or not. + /// since: v0.0.0 + /// + bool HasZeroFlags(); + /// + /// Checks if this object has any flag or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array is not null and it's length + /// is more than zero; otherwise false. + /// + bool HasFlag(); + /// + /// Checks if this object has at the very least one of the specified + /// flags or not. If you want to check for all of the flags, please + /// use method. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object contains at the very + /// least one of the specified flags; otherwise false. + /// + bool HasFlag(params T[] flags); + /// + /// Checks if this object has all of the specified flags or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object has all of the + /// specified flags; otherwise false. + /// + bool HasFlags(params T[] flags); + /// + /// Returns the flag of this object using the specified index + /// in the flag array. + /// since: v0.0.0 + /// + /// + /// the index of the flag. + /// + /// + /// set this argument to true if you want the method to + /// throw an exception in the case it couldn't return any flag. + /// if you set this to false the method will return + /// null (or default). + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + T GetFlag(int index, bool ex = true); + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/SvObjects/ListW.cs b/Socialvoid/SvObjects/Math/ListW.cs similarity index 98% rename from Socialvoid/SvObjects/ListW.cs rename to Socialvoid/SvObjects/Math/ListW.cs index dd7d0c3..8c37d1f 100644 --- a/Socialvoid/SvObjects/ListW.cs +++ b/Socialvoid/SvObjects/Math/ListW.cs @@ -18,7 +18,7 @@ using System.Collections.Generic; -namespace Socialvoid.SvObjects +namespace Socialvoid.SvObjects.Math { /// /// ListW is a wrapper for that allows for the use diff --git a/Socialvoid/SvObjects/Media/Document.cs b/Socialvoid/SvObjects/Media/Document.cs index 2f280be..b7f56b4 100644 --- a/Socialvoid/SvObjects/Media/Document.cs +++ b/Socialvoid/SvObjects/Media/Document.cs @@ -17,18 +17,43 @@ */ using System; -using System.Collections.Generic; using System.Text.Json.Serialization; +using Socialvoid.Security; namespace Socialvoid.SvObjects.Media { /// - /// ListW is a wrapper for that allows for the use - /// of some custom methods. + /// A document object contains basic information about the file associated + /// with the document and the document ID used to retrieve the document + /// from the CDN Server. /// since: v0.0.0 /// - public class Document + public class Document: IIdentitiable, IFlagable { + //------------------------------------------------- + #region Constant's Region + /// + /// The file is a general file, it doesn't consist of any special type + /// that was detected by the server. + /// since: v0.0.0 + /// + public const string DocumentTypeStr = "DOCUMENT"; + /// + /// The file is an image file type. + /// since: v0.0.0 + /// + public const string PhotoTypeStr = "PHOTO"; + /// + /// The file is an video file type. + /// since: v0.0.0 + /// + public const string VideoTypeStr = "VIDEO"; + /// + /// The file is an audio file type. + /// since: v0.0.0 + /// + public const string AudioTypeStr = "AUDIO"; + #endregion //------------------------------------------------- #region Properties Region /// @@ -60,7 +85,32 @@ namespace Socialvoid.SvObjects.Media /// since: v0.0.0 /// [JsonPropertyName("file_type")] - public virtual string FileType { get; set; } + public virtual string FileType + { + get => _typeStr; + set + { + switch (value) + { + case DocumentTypeStr: + _type = FileTypes.Document; + break; + case PhotoTypeStr: + _type = FileTypes.Photo; + break; + case VideoTypeStr: + _type = FileTypes.Video; + break; + case AudioTypeStr: + _type = FileTypes.Audio; + break; + default: + _invalidType = true; + break; + } + _typeStr = value; + } + } /// /// The height of the picture. /// since: v0.0.0 @@ -80,6 +130,9 @@ namespace Socialvoid.SvObjects.Media #endregion //------------------------------------------------- #region field's Region + private bool _invalidType; + private string _typeStr; + private FileTypes _type; private long _ticks; private DateTime _createdAt = DateTime.MinValue; #endregion @@ -97,11 +150,67 @@ namespace Socialvoid.SvObjects.Media //------------------------------------------------- #region Get Method's Region /// - /// Checks if this has a - /// valid document. + /// /// since: v0.0.0 /// - public bool HasID() => !string.IsNullOrEmpty(ID); + public FileTypes GetEnumFileType() => _type; + /// + /// Returns the type of this file as a string. + /// since: v0.0.0 + /// + /// + /// the type of this file as . + /// + public virtual string GetStringType() => _typeStr; + /// + /// Checks if the type of this file is + /// valid/supported by this client. + /// or not. + /// since: v0.0.0 + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + public virtual bool IsTypeValid() => !_invalidType; + /// + /// Checks if the file type is document or not. + /// Document type file is a general file, it doesn't consist of any + /// special type that was detected by the server. + /// since: v0.0.0 + /// + /// + /// true if the file type is considered as a document; + /// otherwise, false. + /// + public virtual bool IsDocumentType() => _type == FileTypes.Document; + /// + /// Checks if the file type is photo or not. + /// since: v0.0.0 + /// + /// + /// true if the file type is considered as a photo; + /// otherwise, false. + /// + public virtual bool IsPhotoType() => _type == FileTypes.Photo; + /// + /// Checks if the file type is video or not. + /// since: v0.0.0 + /// + /// + /// true if the file type is considered as a video; + /// otherwise, false. + /// + public virtual bool IsVideoType() => _type == FileTypes.Video; + /// + /// Checks if the file type is audio or not. + /// since: v0.0.0 + /// + /// + /// true if the file type is considered as an audio; + /// otherwise, false. + /// + public virtual bool IsAudioType() => _type == FileTypes.Audio; /// /// converts file size to KB. /// since: v0.0.0 @@ -124,6 +233,197 @@ namespace Socialvoid.SvObjects.Media public System.DateTime GetTimeStamp() => _createdAt != DateTime.MinValue ? _createdAt: new(Convert.ToInt64(CreatedAt)); + /// + /// Checks if the ID of this object is valid. + /// since: v0.0.0 + /// + /// + /// true if the ID is valid; + /// otherwise, false. + /// + public bool HasValidID() => + !string.IsNullOrWhiteSpace(ID); + /// + /// Returns the ID of this object. + /// since: v0.0.0 + /// + public string GetID() => ID; + /// + /// Returns the flags of this object. + /// since: v0.0.0 + /// + /// + /// the flags of this object as an array of + /// objects. + /// + public string[] GetFlags() => Flags; + /// + /// Checks if this object has any flag or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array is not null and it's length + /// is more than zero; otherwise false. + /// + public bool HasFlag() => Flags != null && Flags.Length > 0; + /// + /// Checks if this object has at the very least one of the specified + /// flags or not. If you want to check for all of the flags, please + /// use method. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object contains at the very + /// least one of the specified flags; otherwise false. + /// + public bool HasFlag(params string[] flags) + { + if (flags == null || flags.Length == 0 || !HasFlag()) + { + return false; + } + else if (flags.Length == 1) + { + // easy path: inlined so we can reduce the running time. + foreach (var f in Flags) + { + if (f == flags[default]) + { + return true; + } + } + } + + foreach(var f in flags) + { + if (hasFlag(f)) + { + return true; + } + } + + return false; + } + /// + /// Returns the length of the flag arrays of this object. + /// If the flag array is empty, this method will return zero. + /// since: v0.0.0 + /// + public int GetFlagLength() => + Flags == null ? default : Flags.Length; + /// + /// Checks if the length of the flag array is zero or not. + /// since: v0.0.0 + /// + public bool HasZeroFlags() => GetFlagLength() == default; + /// + /// Checks if this object has all of the specified flags or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object has all of the + /// specified flags; otherwise false. + /// + public bool HasFlags(params string[] flags) + { + if (flags == null || flags.Length == 0 || !HasFlag()) + { + return false; + } + else if (flags.Length == 1) + { + // easy path: inlined so we can reduce the running time. + foreach (var f in Flags) + { + if (f != flags[default]) + { + return false; + } + } + } + + foreach (var f in flags) + { + if (!hasFlag(f)) + { + return false; + } + } + + return true; + } + /// + /// Returns the flag of this object using the specified index + /// in the flag array. + /// since: v0.0.0 + /// + /// + /// the index of the flag. + /// + /// + /// set this argument to true if you want the method to + /// throw an exception in the case it couldn't return any flag. + /// if you set this to false the method will return + /// null (or default). + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + public string GetFlag(int index, bool ex = true) + { + if (HasZeroFlags()) + { + if (ex) + { + throw new InvalidOperationException( + $"flags length of this {GetType().ToString()} is 0"); + } + return null; + } + if (index < 0) + { + if (ex) + { + throw new ArgumentException( + "index cannot be negatice", + nameof(index)); + } + return null; + } + if (index > GetFlagLength()) + { + if (ex) + { + throw new ArgumentException( + $"index({index}), cannot be more than"+ + $" flags array length({GetFlagLength()})", + nameof(index)); + } + return null; + } + return Flags[index]; + } + + /// + /// Checks if the flag array of this object contains a single flag + /// or not. + /// + private bool hasFlag(string flag) + { + if (string.IsNullOrWhiteSpace(flag)) + { + return false; + } + foreach (var f in Flags) + { + if (f == flag) + { + return true; + } + } + return false; + } #endregion //------------------------------------------------- } diff --git a/Socialvoid/SvObjects/Peer.cs b/Socialvoid/SvObjects/Peer.cs index d831fb0..e513650 100644 --- a/Socialvoid/SvObjects/Peer.cs +++ b/Socialvoid/SvObjects/Peer.cs @@ -16,8 +16,10 @@ * If not, see . */ +using System; using System.Collections.Generic; using System.Text.Json.Serialization; +using Socialvoid.Security; using Socialvoid.SvObjects.Media; namespace Socialvoid.SvObjects @@ -29,11 +31,27 @@ namespace Socialvoid.SvObjects /// what actions are available for a peer. /// since: v0.0.0 /// - public class Peer + public class Peer: IIdentitiable, IFlagable { //------------------------------------------------- #region Constant's Region - // some members here + /// + /// The string value for normal user account type. + /// since: v0.0.0 + /// + public const string UserTypeStr = "USER"; + /// + /// The string value for a bot account that performs automated + /// actions on the network. + /// since: v0.0.0 + /// + public const string BotTypeStr = "BOT"; + /// + /// The string value for a proxy account that mirrors content + /// from another platform. + /// since: v0.0.0 + /// + public const string ProxyTypeStr = "PROXY"; #endregion //------------------------------------------------- #region static Properties Region @@ -52,7 +70,29 @@ namespace Socialvoid.SvObjects /// since: v0.0.0 /// [JsonPropertyName("type")] - public string PeerType { get; set; } + public string PeerType + { + get => _typeStr; + set + { + switch (value) + { + case UserTypeStr: + _type = PeerTypes.User; + break; + case BotTypeStr: + _type = PeerTypes.Bot; + break; + case ProxyTypeStr: + _type = PeerTypes.Proxy; + break; + default: + _type = PeerTypes.None; + break; + } + _typeStr = value; + } + } /// /// The ID of the session obtained when establishing a session. /// since: v0.0.0 @@ -84,7 +124,8 @@ namespace Socialvoid.SvObjects #endregion //------------------------------------------------- #region field's Region - // some members here + private string _typeStr; + private PeerTypes _type; #endregion //------------------------------------------------- #region static event field's Region @@ -130,7 +171,207 @@ namespace Socialvoid.SvObjects #endregion //------------------------------------------------- #region Get Method's Region - // some methods here + /// + /// Returns the flags of this object. + /// since: v0.0.0 + /// + /// + /// the flags of this object as an array of + /// objects. + /// + public virtual string[] GetFlags() => Flags; + /// + /// Checks if this object has any flag or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array is not null and it's length + /// is more than zero; otherwise false. + /// + public virtual bool HasFlag() => Flags != null && Flags.Length > 0; + /// + /// Checks if this object has at the very least one of the specified + /// flags or not. If you want to check for all of the flags, please + /// use method. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object contains at the very + /// least one of the specified flags; otherwise false. + /// + public virtual bool HasFlag(params string[] flags) + { + if (flags == null || flags.Length == 0 || !HasFlag()) + { + return false; + } + else if (flags.Length == 1) + { + // easy path: inlined so we can reduce the running time. + foreach (var f in Flags) + { + if (f == flags[default]) + { + return true; + } + } + } + + foreach(var f in flags) + { + if (hasFlag(f)) + { + return true; + } + } + + return false; + } + /// + /// Returns the length of the flag arrays of this object. + /// If the flag array is empty, this method will return zero. + /// since: v0.0.0 + /// + public virtual int GetFlagLength() => + Flags == null ? default : Flags.Length; + /// + /// Checks if the length of the flag array is zero or not. + /// since: v0.0.0 + /// + public virtual bool HasZeroFlags() => GetFlagLength() == default; + /// + /// Checks if this object has all of the specified flags or not. + /// since: v0.0.0 + /// + /// + /// true if the flag array of this object has all of the + /// specified flags; otherwise false. + /// + public virtual bool HasFlags(params string[] flags) + { + if (flags == null || flags.Length == 0 || !HasFlag()) + { + return false; + } + else if (flags.Length == 1) + { + // easy path: inlined so we can reduce the running time. + foreach (var f in Flags) + { + if (f != flags[default]) + { + return false; + } + } + } + + foreach (var f in flags) + { + if (!hasFlag(f)) + { + return false; + } + } + + return true; + } + /// + /// Returns the flag of this object using the specified index + /// in the flag array. + /// since: v0.0.0 + /// + /// + /// the index of the flag. + /// + /// + /// set this argument to true if you want the method to + /// throw an exception in the case it couldn't return any flag. + /// if you set this to false the method will return + /// null (or default). + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + public virtual string GetFlag(int index, bool ex = true) + { + if (HasZeroFlags()) + { + if (ex) + { + throw new InvalidOperationException( + $"flags length of this {GetType().ToString()} is 0"); + } + return null; + } + if (index < 0) + { + if (ex) + { + throw new ArgumentException( + "index cannot be negatice", + nameof(index)); + } + return null; + } + if (index > GetFlagLength()) + { + if (ex) + { + throw new ArgumentException( + $"index({index}), cannot be more than"+ + $" flags array length({GetFlagLength()})", + nameof(index)); + } + return null; + } + return Flags[index]; + } + + /// + /// Checks if the flag array of this object contains a single flag + /// or not. + /// + protected bool hasFlag(string flag) + { + if (string.IsNullOrWhiteSpace(flag)) + { + return false; + } + foreach (var f in Flags) + { + if (f == flag) + { + return true; + } + } + return false; + } + /// + /// Returns the ID of this object. + /// since: v0.0.0 + /// + public string GetID() => PeerID; + /// + /// Checks if the ID of this object is valid. + /// since: v0.0.0 + /// + /// + /// true if the ID is valid; + /// otherwise, false. + /// + public bool HasValidID() => + !string.IsNullOrWhiteSpace(PeerID); + /// + /// Checks if the type of this peer is + /// valid/supported by this client or not. + /// since: v0.0.0 + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + public virtual bool IsTypeValid() => _type != PeerTypes.None; #endregion //------------------------------------------------- #region Set Method's Region diff --git a/Socialvoid/SvObjects/PeerTypes.cs b/Socialvoid/SvObjects/PeerTypes.cs new file mode 100644 index 0000000..456ed4a --- /dev/null +++ b/Socialvoid/SvObjects/PeerTypes.cs @@ -0,0 +1,57 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +/// +/// Peer Types indicates the account type that's registered to the server, +/// some actions may be restricted depending on the peer type. +/// Since: v0.0.0 +/// +public enum PeerTypes +{ + //------------------------------------------------- + #region general types + /// + /// The default value of an , which means + /// the peer type is undefined (or is unsupported by this version of + /// library). + /// In the case where our client received this type, we should show user + /// the "please update your client" message. + /// Since: v0.0.0 + /// + None = 0, + #endregion + //------------------------------------------------- + #region Another styling + /// + /// Normal user account. + /// Since: v0.0.0 + /// + User = 1, + /// + /// A bot account that performs automated actions on the network. + /// Since: v0.0.0 + /// + Bot = 2, + /// + /// A proxy account that mirrors content from another platform. + /// Since: v0.0.0 + /// + Proxy = 3, + #endregion + //------------------------------------------------- +} diff --git a/Socialvoid/SvObjects/Server/ServerInformation.cs b/Socialvoid/SvObjects/Server/ServerInformation.cs new file mode 100644 index 0000000..a32fb38 --- /dev/null +++ b/Socialvoid/SvObjects/Server/ServerInformation.cs @@ -0,0 +1,148 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +using System.Text.Json.Serialization; + +namespace Socialvoid.SvObjects.Server +{ + /// + /// The object is a simple object that gives + /// details about the server's attributes and limits or location + /// of other servers that the client should communicate to for other + /// purposes such as a CDN. + /// since: v0.0.0 + /// + public class ServerInformation + { + //------------------------------------------------- + #region Constant's Region + // some members here + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The name of the network, eg; "Socialvoid". + /// since: v0.0.0 + /// + [JsonPropertyName("network_name")] + public string NetworkName { get; set; } + /// + /// The version of the protocol standard that the server is using, eg; "1.0" + /// since: v0.0.0 + /// + [JsonPropertyName("protocol_version")] + public string ProtocolVersion { get; set; } + /// + /// The HTTP URL Endpoint for the CDN server of the network + /// since: v0.0.0 + /// + [JsonPropertyName("cdn_server")] + public string AddressCDN { get; set; } + /// + /// The maximum size of a file that you can upload + /// to the CDN Server (in bytes) + /// since: v0.0.0 + /// + [JsonPropertyName("upload_max_file_size")] + public int MaxUploadSize { get; set; } + /// + /// The maximum time-to-live (in seconds) that an unauthorized + /// session may have. The server will often reset the expiration + /// whenever the session is used. + /// since: v0.0.0 + /// + [JsonPropertyName("unauthorized_session_ttl ")] + public int UnauthorizedSessionTTL { get; set; } + /// + /// The maximum time-to-live (in seconds) that an authorized + /// session may have. The server will often reset the expiration + /// whenever the session is used. + /// since: v0.0.0 + /// + [JsonPropertyName("authorized_session_ttl")] + public int SessionTTL { get; set; } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + // some members here + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// + /// + public ServerInformation() + { + + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + // some methods here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/SvObjects/Text/EntityTypes.cs b/Socialvoid/SvObjects/Text/EntityTypes.cs new file mode 100644 index 0000000..959c19c --- /dev/null +++ b/Socialvoid/SvObjects/Text/EntityTypes.cs @@ -0,0 +1,82 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.SvObjects.Text +{ + /// + /// Text Entity types describes the entity type applied to the referenced + /// text so that the client can apply the supported styling or + /// clickable action. + /// Since: v0.0.0 + /// + public enum EntityTypes + { + //------------------------------------------------- + #region Normal styling + /// + /// The default value of an . + /// Since: v0.0.0 + /// + Normal = 0, + #endregion + //------------------------------------------------- + #region Another styling + /// + /// The Bold text style value of an . + /// Since: v0.0.0 + /// + Bold = 1, + /// + /// The Italic text style value of an . + /// Since: v0.0.0 + /// + Italic = 2, + /// + /// The Code text style value of an . + /// Since: v0.0.0 + /// + Code = 3, + /// + /// The Strike-through text style value of an . + /// Since: v0.0.0 + /// + StrikeThrough = 4, + /// + /// The Underline text style value of an . + /// Since: v0.0.0 + /// + Underline = 5, + /// + /// The URL entity value of an . + /// Since: v0.0.0 + /// + Url = 6, + /// + /// The Mention entity value of an . + /// Since: v0.0.0 + /// + Mention = 7, + /// + /// The Hashtag entity value of an . + /// Since: v0.0.0 + /// + Hashtag = 8, + #endregion + //------------------------------------------------- + } +} diff --git a/Socialvoid/SvObjects/Text/IEntity.cs b/Socialvoid/SvObjects/Text/IEntity.cs new file mode 100644 index 0000000..83ebf9b --- /dev/null +++ b/Socialvoid/SvObjects/Text/IEntity.cs @@ -0,0 +1,154 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +namespace Socialvoid.SvObjects.Text +{ + /// + /// This interface is created for solving compability issues. + /// Most of the GUI clients (and libraries) define their own + /// unique classes (or structures) with similliar functionality to + /// class which is used for showing texts + /// on the UI to the users. This interface makes it easier to write + /// wrapper classes for them and use them more easily. + /// since: v0.0.0 + /// + public interface IEntity + { + //------------------------------------------------- + #region Get Method's Region + /// + /// Returns the type of this entity as a string. + /// since: v0.0.0 + /// + /// + /// the type of this entity as . + /// + string GetStringType(); + /// + /// Returns the type of this entity as a string. + /// since: v0.0.0 + /// + /// + /// the type of this entity as . + /// + EntityTypes GetEnumType(); + /// + /// Checks if the type of this entity is valid/supported by this client + /// or not. + /// since: v0.0.0 + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + bool IsTypeValid(); + /// + /// Checks if this object has + /// a valid value property or not. + /// since: v0.0.0 + /// + /// + /// true if this object has a value; + /// otherwise, false. + /// + bool HasValue(); + /// + /// Checks if the entity type is normal or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is normal; + /// otherwise, false. + /// + bool IsNormal(); + /// + /// Checks if the entity type is bold or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is bold; + /// otherwise, false. + /// + bool IsBold(); + /// + /// Checks if the entity type is italic or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is italic; + /// otherwise, false. + /// + bool IsItalic(); + /// + /// Checks if the entity type is code or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is code; + /// otherwise, false. + /// + bool IsCode(); + /// + /// Checks if the entity type is strike-through or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is strike-through; + /// otherwise, false. + /// + bool IsStrikeThrough(); + /// + /// Checks if the entity type is underline or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is underline; + /// otherwise, false. + /// + bool IsUnderline(); + /// + /// Checks if the entity type is url or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is url; + /// otherwise, false. + /// + bool IsUrl(); + /// + /// Checks if the entity type is mention or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is mention; + /// otherwise, false. + /// + bool IsMention(); + /// + /// Checks if the entity type is hashtag or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is hashtag; + /// otherwise, false. + /// + bool IsHashtag(); + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Socialvoid/SvObjects/Text/TextEntity.cs b/Socialvoid/SvObjects/Text/TextEntity.cs new file mode 100644 index 0000000..3635e84 --- /dev/null +++ b/Socialvoid/SvObjects/Text/TextEntity.cs @@ -0,0 +1,333 @@ +/* + * This file is part of Socialvoid.NET Project (https://github.com/Intellivoid/Socialvoid.NET). + * Copyright (c) 2021 Socialvoid.NET Authors. + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this source code of library. + * If not, see . + */ + +using System.Text.Json.Serialization; + +namespace Socialvoid.SvObjects.Text +{ + /// + /// The text entity object describes the text type, this is useful + /// for clients to render the given text correctly. + /// For example a "@mention" will have a TextEntity with the value + /// mention. So that the client can preform an action when this + /// entity is clicked. + /// since: v0.0.0 + /// + public class TextEntity: IEntity + { + //------------------------------------------------- + #region Constant's Region + /// + /// The string value for normal entity type. + /// since: v0.0.0 + /// + public const string NormalTypeStr = "NORMAL"; + /// + /// The string value for bold entity type. + /// since: v0.0.0 + /// + public const string BoldTypeStr = "BOLD"; + /// + /// The string value for italic entity type. + /// since: v0.0.0 + /// + public const string ItalicTypeStr = "ITALIC"; + /// + /// The string value for code entity type. + /// since: v0.0.0 + /// + public const string CodeTypeStr = "CODE"; + /// + /// The string value for strike-through entity type. + /// since: v0.0.0 + /// + public const string StrikeTypeStr = "STRIKE"; + /// + /// The string value for underline entity type. + /// since: v0.0.0 + /// + public const string UnderlineTypeStr = "UNDERLINE"; + /// + /// The string value for url entity type. + /// since: v0.0.0 + /// + public const string UrlTypeStr = "URL"; + /// + /// The string value for mention entity type. + /// since: v0.0.0 + /// + public const string MentionTypeStr = "MENTION"; + /// + /// The string value for hashtag entity type. + /// since: v0.0.0 + /// + public const string HashtagTypeStr = "HASHTAG"; + #endregion + //------------------------------------------------- + #region static Properties Region + // some members here + #endregion + //------------------------------------------------- + #region Properties Region + /// + /// The text entity type. + /// since: v0.0.0 + /// + [JsonPropertyName("type")] + public string Type + { + get => _typeStr ?? NormalTypeStr; + set + { + switch (value) + { + case NormalTypeStr: + _type = EntityTypes.Normal; + break; + case BoldTypeStr: + _type = EntityTypes.Bold; + break; + case ItalicTypeStr: + _type = EntityTypes.Italic; + break; + case CodeTypeStr: + _type = EntityTypes.Code; + break; + case StrikeTypeStr: + _type = EntityTypes.StrikeThrough; + break; + case UnderlineTypeStr: + _type = EntityTypes.Underline; + break; + case UrlTypeStr: + _type = EntityTypes.Url; + break; + case MentionTypeStr: + _type = EntityTypes.Mention; + break; + case HashtagTypeStr: + _type = EntityTypes.Hashtag; + break; + default: + _invalid = true; + break; + } + _typeStr = value; + } + } + /// + /// The offset for when the entity begins in the text. + /// since: v0.0.0 + /// + [JsonPropertyName("offset")] + public int Offset { get; set; } + /// + /// The length of the entity. + /// since: v0.0.0 + /// + [JsonPropertyName("length")] + public int Length { get; set; } + /// + /// The value of the entity, for styling entities such as BOLD, + /// ITALIC, etc. this value will be null, but for values such as MENTION, + /// HASHTAG & URL the value will contain the respective value for the entity, for example a URL entity will contain a value of a http URL + /// since: v0.0.0 + /// + [JsonPropertyName("value")] + public string Value { get; set; } + #endregion + //------------------------------------------------- + #region static field's Region + // some members here + #endregion + //------------------------------------------------- + #region field's Region + private EntityTypes _type; + private string _typeStr; + private bool _invalid; + #endregion + //------------------------------------------------- + #region static event field's Region + // some members here + #endregion + //------------------------------------------------- + #region event field's Region + // some members here + #endregion + //------------------------------------------------- + #region Constructor's Region + /// + /// + /// + public TextEntity() + { + + } + #endregion + //------------------------------------------------- + #region Destructor's Region + // some members here + #endregion + //------------------------------------------------- + #region Initialize Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Graphical Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region event Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region overrided Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region ordinary Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region Get Method's Region + /// + /// Checks if this object has + /// a valid property or not. + /// since: v0.0.0 + /// + public virtual bool HasValue() => !string.IsNullOrEmpty(Value); + /// + /// Returns the type of this entity as a string. + /// since: v0.0.0 + /// + /// + /// the type of this entity as . + /// + public virtual string GetStringType() => _typeStr; + /// + /// Returns the type of this entity as a string. + /// since: v0.0.0 + /// + /// + /// the type of this entity as . + /// + public virtual EntityTypes GetEnumType() => _type; + /// + /// Checks if the type of this entity is + /// valid/supported by this client + /// or not. + /// since: v0.0.0 + /// + /// + /// true if the type is valid and supported; + /// otherwise, false. + /// + public virtual bool IsTypeValid() => !_invalid; + /// + /// Checks if the entity type is normal or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is normal; + /// otherwise, false. + /// + public virtual bool IsNormal() => _type == EntityTypes.Normal; + /// + /// Checks if the entity type is bold or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is bold; + /// otherwise, false. + /// + public virtual bool IsBold() => _type == EntityTypes.Bold; + /// + /// Checks if the entity type is italic or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is italic; + /// otherwise, false. + /// + public virtual bool IsItalic() => _type == EntityTypes.Italic; + /// + /// Checks if the entity type is code or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is code; + /// otherwise, false. + /// + public virtual bool IsCode() => _type == EntityTypes.Code; + /// + /// Checks if the entity type is strike-through or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is strike-through; + /// otherwise, false. + /// + public virtual bool IsStrikeThrough() => _type == EntityTypes.StrikeThrough; + /// + /// Checks if the entity type is underline or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is underline; + /// otherwise, false. + /// + public virtual bool IsUnderline() => _type == EntityTypes.Underline; + /// + /// Checks if the entity type is url or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is url; + /// otherwise, false. + /// + public virtual bool IsUrl() => _type == EntityTypes.Url; + /// + /// Checks if the entity type is mention or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is mention; + /// otherwise, false. + /// + public virtual bool IsMention() => _type == EntityTypes.Mention; + /// + /// Checks if the entity type is hashtag or not. + /// since: v0.0.0 + /// + /// + /// true if the entity type is hashtag; + /// otherwise, false. + /// + public virtual bool IsHashtag() => _type == EntityTypes.Hashtag; + #endregion + //------------------------------------------------- + #region Set Method's Region + // some methods here + #endregion + //------------------------------------------------- + #region static Method's Region + // some methods here + #endregion + //------------------------------------------------- + } +} \ No newline at end of file diff --git a/Tests/Client/AuthenticateUser.cs b/Tests/Client/AuthenticateUser.cs index 2ea9f74..ff72acb 100644 --- a/Tests/Client/AuthenticateUser.cs +++ b/Tests/Client/AuthenticateUser.cs @@ -49,6 +49,9 @@ namespace Tests.Client try { myClient.CreateSession(); + var session = myClient.GetSession(); + Assert.IsNotNull(session); + Assert.IsNotNull(session.SessionID); } catch (Exception e) { @@ -60,6 +63,8 @@ namespace Tests.Client { myClient.GetTermsOfService(); var peer = myClient.Register("aliwoto6", "ilovehentai69", "エイリ・ヲト"); + Assert.IsNotNull(peer); + Log(peer.Name); } catch (UsernameAlreadyExistsException) { @@ -76,6 +81,14 @@ namespace Tests.Client try { isAuthenticated = myClient.AuthenticateUser("aliwoto", "ilovehentai69"); + if (isAuthenticated) + { + var session = myClient.GetSession(); + Assert.IsNotNull(session); + Assert.IsNotNull(session.SessionID); + Log("created: ", session.Created); + Log("Expires: ", session.Expires); + } } catch (Exception ex) {