- Add `GetSession` method in `SocialvoidClient` class.
- Move `ListW<T>` class from `Socialvoid.SvObjects` namespace to `Socialvoid.SvObjects.Math` namespace. - Let `Document` class implement `IIdentitiable<string>` and `IFlagable<string>` interfaces. - Add `ServerInformation` class in `Socialvoid.SvObjects.Server` namespace. - Add `EntityTypes` enum in `Socialvoid.SvObjects.Text` namespace. - Add `IEntity` interface in `Socialvoid.SvObjects.Text` namespace. - Add `TextEntity` class in `Socialvoid.SvObjects.Text` namespace (which implemenets `IEntity` interface. - Add `FileTypes` and `PeerTypes` enums and `IFlagable<T>` interface in `Socialvoid.SvObjects` namespace. - Let `Peer` class implement `IIdentitiable<string>` and `IFlagable<string>` interfaces. Signed-off-by: Aliwoto <aminnimaj@gmail.com>
This commit is contained in:
parent
d7bb3c45b7
commit
60c342ddbf
|
@ -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
|
|||
/// </summary>
|
||||
protected const string RegisterMethod = "session.register";
|
||||
/// <summary>
|
||||
/// <c>authenticate_user</c> method value.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
protected const string GetSessionMethod = "session.get";
|
||||
/// <summary>
|
||||
/// <c>get_terms_of_service</c> method value.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
|
@ -207,6 +213,11 @@ namespace Socialvoid.Client
|
|||
/// </summary>
|
||||
protected internal SessionEstablished _session;
|
||||
/// <summary>
|
||||
/// Session info object of this client.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
protected internal Session _sessionInfo;
|
||||
/// <summary>
|
||||
/// if the client should send an otp answer in the next request,
|
||||
/// this field should be set to <c>true</c>.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
|
@ -289,7 +300,7 @@ namespace Socialvoid.Client
|
|||
// some methods here
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region ordinary Method's Region
|
||||
#region Session Method's Region
|
||||
/// <summary>
|
||||
/// CreateSession method (session.create), establishes a new session
|
||||
/// to the network.
|
||||
|
@ -561,6 +572,81 @@ namespace Socialvoid.Client
|
|||
return jresp.Result;
|
||||
}
|
||||
/// <summary>
|
||||
/// GetSession method (session.get), Returns information about the
|
||||
/// current session identified by the SessionIdentification parameter.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <param name="sessionID">
|
||||
/// The Session Identification object.
|
||||
/// (optional if and only if this client has already established
|
||||
/// a session OR <see cref="AutoSession"/> is set to <c>true</c>).
|
||||
/// </param>
|
||||
/// <param name="store">
|
||||
/// set it to <c>true</c> if you want to store the session in the
|
||||
/// client.
|
||||
/// </param>
|
||||
/// <exception cref="InternalServerErrorException"/>
|
||||
/// <exception cref="InvalidParamsException"/>
|
||||
/// <exception cref="InvalidSessionIdentificationException"/>
|
||||
/// <exception cref="BadSessionChallengeAnswerException"/>
|
||||
/// <exception cref="SessionExpiredException"/>
|
||||
/// <exception cref="SessionNotFoundException"/>
|
||||
/// <exception cref="InvalidClientPublicHashException"/>
|
||||
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<Session>(
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// returns a challenge's answer using the session's challenge secret.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
protected internal virtual string GetChallengeAnswer(string secret) =>
|
||||
KeyGeneration.GetChallengeAnswer(secret, PrivateHash);
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// returns a challenge's answer using the session's challenge secret.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
protected internal virtual string GetChallengeAnswer(string secret) =>
|
||||
KeyGeneration.GetChallengeAnswer(secret, PrivateHash);
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
/// <summary>
|
||||
/// Gets the session of this <see cref="SocialvoidClient"/> 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public virtual SessionEstablished GetSession()
|
||||
{
|
||||
return _session;
|
||||
}
|
||||
public virtual SessionEstablished GetSessionVariable() =>
|
||||
_session;
|
||||
/// <summary>
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
|
|
|
@ -26,6 +26,8 @@ namespace Socialvoid.Security
|
|||
/// </summary>
|
||||
public interface IChallenge
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
/// <summary>
|
||||
/// Checks if the challenge is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
|
@ -49,5 +51,7 @@ namespace Socialvoid.Security
|
|||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
void DelSecret();
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Socialvoid.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for classes and structs which provides a valid ID.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public interface IIdentitiable<T>
|
||||
where T: IComparable, IConvertible
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
/// <summary>
|
||||
/// Checks if the ID of this object is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the ID is valid;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool HasValidID();
|
||||
/// <summary>
|
||||
/// Returns the ID of this <see cref="IIdentitiable{T}"/> object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
T GetID();
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ namespace Socialvoid.Security
|
|||
/// </summary>
|
||||
public interface ISender
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
/// <summary>
|
||||
/// Sends data to a remote service.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
|
@ -35,5 +37,7 @@ namespace Socialvoid.Security
|
|||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
bool AddSome(string key, string data);
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using Socialvoid.SvObjects;
|
||||
|
||||
namespace Socialvoid.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="SessionEstablished"/> object contains basic information
|
||||
/// about the session that the server has created for us.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public sealed class Session: IIdentitiable<string>, IFlagable<string>
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
// some members here
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region static Properties Region
|
||||
// some members here
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Properties Region
|
||||
/// <summary>
|
||||
/// The ID of the session obtained when establishing a session.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("id")]
|
||||
public string SessionID { get; set; }
|
||||
/// <summary>
|
||||
/// An array of flags that has been set to this session.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("flags")]
|
||||
public string[] Flags { get; set; }
|
||||
/// <summary>
|
||||
/// Indicates if the session is currently authenticated to a user.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("authenticated")]
|
||||
public bool Authenticated { get; set; }
|
||||
/// <summary>
|
||||
/// The Unix Timestamp for when this session was first created.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("created")]
|
||||
public long Created { get; set; }
|
||||
/// <summary>
|
||||
/// The Unix Timestamp for when this session expires.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[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
|
||||
/// <summary>
|
||||
/// Checks if the ID of this object is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the ID is valid;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasValidID() =>
|
||||
!string.IsNullOrWhiteSpace(SessionID);
|
||||
/// <summary>
|
||||
/// Returns the ID of this <see cref="Session"/> object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public string GetID() => SessionID;
|
||||
/// <summary>
|
||||
/// Returns the flags of this object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the flags of this object as an array of
|
||||
/// <see cref="string"/> objects.
|
||||
/// </returns>
|
||||
public string[] GetFlags() => Flags;
|
||||
/// <summary>
|
||||
/// Checks if this object has any flag or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array is not null and it's length
|
||||
/// is more than zero; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasFlag() => Flags != null && Flags.Length > 0;
|
||||
/// <summary>
|
||||
/// 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 <see cref="HasFlags(string[])"/> method.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object contains at the very
|
||||
/// least one of the specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the length of the flag arrays of this object.
|
||||
/// If the flag array is empty, this method will return zero.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public int GetFlagLength() =>
|
||||
Flags == null ? default : Flags.Length;
|
||||
/// <summary>
|
||||
/// Checks if the length of the flag array is zero or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public bool HasZeroFlags() => GetFlagLength() == default;
|
||||
/// <summary>
|
||||
/// Checks if this object has all of the specified flags or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object has all of the
|
||||
/// specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the flag of this object using the specified index
|
||||
/// in the flag array.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <param name="index">
|
||||
/// the index of the flag.
|
||||
/// </param>
|
||||
/// <param name="ex">
|
||||
/// set this argument to <c>true</c> if you want the method to
|
||||
/// throw an exception in the case it couldn't return any flag.
|
||||
/// if you set this to <c>false</c> the method will return
|
||||
/// <c>null</c> (or default).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
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];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the flag array of this object contains a single flag
|
||||
/// or not.
|
||||
/// </summary>
|
||||
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
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -25,7 +25,8 @@ namespace Socialvoid.Security
|
|||
/// about the session that the server has created for us.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public sealed class SessionEstablished : IChallenge
|
||||
public sealed class SessionEstablished:
|
||||
IChallenge, IIdentitiable<string>
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
|
@ -123,6 +124,21 @@ namespace Socialvoid.Security
|
|||
/// </returns>
|
||||
public bool HasSecret() =>
|
||||
!string.IsNullOrWhiteSpace(ChallengeSecret);
|
||||
/// <summary>
|
||||
/// Checks if the ID of this object is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the ID is valid;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasValidID() =>
|
||||
!string.IsNullOrWhiteSpace(SessionID);
|
||||
/// <summary>
|
||||
/// Returns the ID of this <see cref="SessionEstablished"/> object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public string GetID() => SessionID;
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Set Method's Region
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Socialvoid.Security
|
|||
/// will cause the request to fail as it's validated upon request.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public sealed class SessionIdentification
|
||||
public sealed class SessionIdentification: IIdentitiable<string>
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
|
@ -114,7 +114,21 @@ namespace Socialvoid.Security
|
|||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
// some methods here
|
||||
/// <summary>
|
||||
/// Checks if the ID of this object is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the ID is valid;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasValidID() =>
|
||||
!string.IsNullOrWhiteSpace(SessionID);
|
||||
/// <summary>
|
||||
/// Returns the ID of this <see cref="SessionIdentification"/> object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public string GetID() => SessionID;
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Set Method's Region
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public enum FileTypes
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region general types
|
||||
/// <summary>
|
||||
/// The default value of an <see cref="FileTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Document = 0,
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Another styling
|
||||
/// <summary>
|
||||
/// The file is an image file type.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Photo = 1,
|
||||
/// <summary>
|
||||
/// The file is an video file type.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Video = 2,
|
||||
/// <summary>
|
||||
/// The file is an audio file type.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Audio = 3,
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
|
@ -16,9 +16,9 @@
|
|||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public class HelpDocument
|
||||
public class HelpDocument: IIdentitiable<string>
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
|
@ -58,7 +58,7 @@ namespace Socialvoid.SvObjects
|
|||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[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
|
||||
/// <summary>
|
||||
/// Returns the ID of this <see cref="HelpDocument"/> object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public string GetID() => ID;
|
||||
/// <summary>
|
||||
/// Checks if the ID of this object is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the ID is valid;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasValidID() =>
|
||||
!string.IsNullOrWhiteSpace(ID);
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Set Method's Region
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Socialvoid.SvObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// This interface is created for solving compability issues.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public interface IFlagable<T>
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
/// <summary>
|
||||
/// Returns the flags of this object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the flags of this object as an array of
|
||||
/// <see cref="string"/> objects.
|
||||
/// </returns>
|
||||
T[] GetFlags();
|
||||
/// <summary>
|
||||
/// Returns the length of the flag arrays of this object.
|
||||
/// If the flag array is empty, this method will return zero.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
int GetFlagLength();
|
||||
/// <summary>
|
||||
/// Checks if the length of the flag array is zero or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
bool HasZeroFlags();
|
||||
/// <summary>
|
||||
/// Checks if this object has any flag or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array is not null and it's length
|
||||
/// is more than zero; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
bool HasFlag();
|
||||
/// <summary>
|
||||
/// 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 <see cref="HasFlags(T[])"/> method.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object contains at the very
|
||||
/// least one of the specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
bool HasFlag(params T[] flags);
|
||||
/// <summary>
|
||||
/// Checks if this object has all of the specified flags or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object has all of the
|
||||
/// specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
bool HasFlags(params T[] flags);
|
||||
/// <summary>
|
||||
/// Returns the flag of this object using the specified index
|
||||
/// in the flag array.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <param name="index">
|
||||
/// the index of the flag.
|
||||
/// </param>
|
||||
/// <param name="ex">
|
||||
/// set this argument to <c>true</c> if you want the method to
|
||||
/// throw an exception in the case it couldn't return any flag.
|
||||
/// if you set this to <c>false</c> the method will return
|
||||
/// <c>null</c> (or default).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
T GetFlag(int index, bool ex = true);
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Socialvoid.SvObjects
|
||||
namespace Socialvoid.SvObjects.Math
|
||||
{
|
||||
/// <summary>
|
||||
/// ListW is a wrapper for <see cref="List{T}"/> that allows for the use
|
|
@ -17,18 +17,43 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using Socialvoid.Security;
|
||||
|
||||
namespace Socialvoid.SvObjects.Media
|
||||
{
|
||||
/// <summary>
|
||||
/// ListW is a wrapper for <see cref="List{T}"/> 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public class Document
|
||||
public class Document: IIdentitiable<string>, IFlagable<string>
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
/// <summary>
|
||||
/// The file is a general file, it doesn't consist of any special type
|
||||
/// that was detected by the server.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string DocumentTypeStr = "DOCUMENT";
|
||||
/// <summary>
|
||||
/// The file is an image file type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string PhotoTypeStr = "PHOTO";
|
||||
/// <summary>
|
||||
/// The file is an video file type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string VideoTypeStr = "VIDEO";
|
||||
/// <summary>
|
||||
/// The file is an audio file type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string AudioTypeStr = "AUDIO";
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Properties Region
|
||||
/// <summary>
|
||||
|
@ -60,7 +85,32 @@ namespace Socialvoid.SvObjects.Media
|
|||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The height of the picture.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// Checks if this <see cref="DisplayPictureSize"/> has a
|
||||
/// valid document.
|
||||
///
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public bool HasID() => !string.IsNullOrEmpty(ID);
|
||||
public FileTypes GetEnumFileType() => _type;
|
||||
/// <summary>
|
||||
/// Returns the type of this file as a string.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the type of this file as <see cref="string"/>.
|
||||
/// </returns>
|
||||
public virtual string GetStringType() => _typeStr;
|
||||
/// <summary>
|
||||
/// Checks if the type of this file is
|
||||
/// valid/supported by this client.
|
||||
/// or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsTypeValid() => !_invalidType;
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the file type is considered as a document;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsDocumentType() => _type == FileTypes.Document;
|
||||
/// <summary>
|
||||
/// Checks if the file type is photo or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the file type is considered as a photo;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsPhotoType() => _type == FileTypes.Photo;
|
||||
/// <summary>
|
||||
/// Checks if the file type is video or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the file type is considered as a video;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsVideoType() => _type == FileTypes.Video;
|
||||
/// <summary>
|
||||
/// Checks if the file type is audio or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the file type is considered as an audio;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsAudioType() => _type == FileTypes.Audio;
|
||||
/// <summary>
|
||||
/// converts file size to KB.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
|
@ -124,6 +233,197 @@ namespace Socialvoid.SvObjects.Media
|
|||
public System.DateTime GetTimeStamp() =>
|
||||
_createdAt != DateTime.MinValue ? _createdAt:
|
||||
new(Convert.ToInt64(CreatedAt));
|
||||
/// <summary>
|
||||
/// Checks if the ID of this object is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the ID is valid;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasValidID() =>
|
||||
!string.IsNullOrWhiteSpace(ID);
|
||||
/// <summary>
|
||||
/// Returns the ID of this <see cref="Document"/> object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public string GetID() => ID;
|
||||
/// <summary>
|
||||
/// Returns the flags of this object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the flags of this object as an array of
|
||||
/// <see cref="string"/> objects.
|
||||
/// </returns>
|
||||
public string[] GetFlags() => Flags;
|
||||
/// <summary>
|
||||
/// Checks if this object has any flag or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array is not null and it's length
|
||||
/// is more than zero; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasFlag() => Flags != null && Flags.Length > 0;
|
||||
/// <summary>
|
||||
/// 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 <see cref="HasFlags(string[])"/> method.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object contains at the very
|
||||
/// least one of the specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the length of the flag arrays of this object.
|
||||
/// If the flag array is empty, this method will return zero.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public int GetFlagLength() =>
|
||||
Flags == null ? default : Flags.Length;
|
||||
/// <summary>
|
||||
/// Checks if the length of the flag array is zero or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public bool HasZeroFlags() => GetFlagLength() == default;
|
||||
/// <summary>
|
||||
/// Checks if this object has all of the specified flags or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object has all of the
|
||||
/// specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the flag of this object using the specified index
|
||||
/// in the flag array.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <param name="index">
|
||||
/// the index of the flag.
|
||||
/// </param>
|
||||
/// <param name="ex">
|
||||
/// set this argument to <c>true</c> if you want the method to
|
||||
/// throw an exception in the case it couldn't return any flag.
|
||||
/// if you set this to <c>false</c> the method will return
|
||||
/// <c>null</c> (or default).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
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];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the flag array of this object contains a single flag
|
||||
/// or not.
|
||||
/// </summary>
|
||||
private bool hasFlag(string flag)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(flag))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var f in Flags)
|
||||
{
|
||||
if (f == flag)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public class Peer
|
||||
public class Peer: IIdentitiable<string>, IFlagable<string>
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
// some members here
|
||||
/// <summary>
|
||||
/// The string value for normal user account type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string UserTypeStr = "USER";
|
||||
/// <summary>
|
||||
/// The string value for a bot account that performs automated
|
||||
/// actions on the network.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string BotTypeStr = "BOT";
|
||||
/// <summary>
|
||||
/// The string value for a proxy account that mirrors content
|
||||
/// from another platform.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string ProxyTypeStr = "PROXY";
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region static Properties Region
|
||||
|
@ -52,7 +70,29 @@ namespace Socialvoid.SvObjects
|
|||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The ID of the session obtained when establishing a session.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
|
@ -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
|
||||
/// <summary>
|
||||
/// Returns the flags of this object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the flags of this object as an array of
|
||||
/// <see cref="string"/> objects.
|
||||
/// </returns>
|
||||
public virtual string[] GetFlags() => Flags;
|
||||
/// <summary>
|
||||
/// Checks if this object has any flag or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array is not null and it's length
|
||||
/// is more than zero; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool HasFlag() => Flags != null && Flags.Length > 0;
|
||||
/// <summary>
|
||||
/// 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 <see cref="HasFlags(string[])"/> method.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object contains at the very
|
||||
/// least one of the specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the length of the flag arrays of this object.
|
||||
/// If the flag array is empty, this method will return zero.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public virtual int GetFlagLength() =>
|
||||
Flags == null ? default : Flags.Length;
|
||||
/// <summary>
|
||||
/// Checks if the length of the flag array is zero or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public virtual bool HasZeroFlags() => GetFlagLength() == default;
|
||||
/// <summary>
|
||||
/// Checks if this object has all of the specified flags or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the flag array of this object has all of the
|
||||
/// specified flags; otherwise <c>false</c>.
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the flag of this object using the specified index
|
||||
/// in the flag array.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <param name="index">
|
||||
/// the index of the flag.
|
||||
/// </param>
|
||||
/// <param name="ex">
|
||||
/// set this argument to <c>true</c> if you want the method to
|
||||
/// throw an exception in the case it couldn't return any flag.
|
||||
/// if you set this to <c>false</c> the method will return
|
||||
/// <c>null</c> (or default).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
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];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the flag array of this object contains a single flag
|
||||
/// or not.
|
||||
/// </summary>
|
||||
protected bool hasFlag(string flag)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(flag))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var f in Flags)
|
||||
{
|
||||
if (f == flag)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the ID of this <see cref="Peer"/> object.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public string GetID() => PeerID;
|
||||
/// <summary>
|
||||
/// Checks if the ID of this object is valid.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the ID is valid;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool HasValidID() =>
|
||||
!string.IsNullOrWhiteSpace(PeerID);
|
||||
/// <summary>
|
||||
/// Checks if the type of this peer is
|
||||
/// valid/supported by this client or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsTypeValid() => _type != PeerTypes.None;
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Set Method's Region
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Peer Types indicates the account type that's registered to the server,
|
||||
/// some actions may be restricted depending on the peer type.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public enum PeerTypes
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region general types
|
||||
/// <summary>
|
||||
/// The default value of an <see cref="PeerTypes"/>, 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.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
None = 0,
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Another styling
|
||||
/// <summary>
|
||||
/// Normal user account.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
User = 1,
|
||||
/// <summary>
|
||||
/// A bot account that performs automated actions on the network.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Bot = 2,
|
||||
/// <summary>
|
||||
/// A proxy account that mirrors content from another platform.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Proxy = 3,
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Socialvoid.SvObjects.Server
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ServerInformation"/> 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public class ServerInformation
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
// some members here
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region static Properties Region
|
||||
// some members here
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Properties Region
|
||||
/// <summary>
|
||||
/// The name of the network, eg; "Socialvoid".
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("network_name")]
|
||||
public string NetworkName { get; set; }
|
||||
/// <summary>
|
||||
/// The version of the protocol standard that the server is using, eg; "1.0"
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("protocol_version")]
|
||||
public string ProtocolVersion { get; set; }
|
||||
/// <summary>
|
||||
/// The HTTP URL Endpoint for the CDN server of the network
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("cdn_server")]
|
||||
public string AddressCDN { get; set; }
|
||||
/// <summary>
|
||||
/// The maximum size of a file that you can upload
|
||||
/// to the CDN Server (in bytes)
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("upload_max_file_size")]
|
||||
public int MaxUploadSize { get; set; }
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("unauthorized_session_ttl ")]
|
||||
public int UnauthorizedSessionTTL { get; set; }
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[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
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Socialvoid.SvObjects.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// Text Entity types describes the entity type applied to the referenced
|
||||
/// text so that the client can apply the supported styling or
|
||||
/// clickable action.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public enum EntityTypes
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Normal styling
|
||||
/// <summary>
|
||||
/// The default value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Normal = 0,
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Another styling
|
||||
/// <summary>
|
||||
/// The Bold text style value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Bold = 1,
|
||||
/// <summary>
|
||||
/// The Italic text style value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Italic = 2,
|
||||
/// <summary>
|
||||
/// The Code text style value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Code = 3,
|
||||
/// <summary>
|
||||
/// The Strike-through text style value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
StrikeThrough = 4,
|
||||
/// <summary>
|
||||
/// The Underline text style value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Underline = 5,
|
||||
/// <summary>
|
||||
/// The URL entity value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Url = 6,
|
||||
/// <summary>
|
||||
/// The Mention entity value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Mention = 7,
|
||||
/// <summary>
|
||||
/// The Hashtag entity value of an <see cref="EntityTypes"/>.
|
||||
/// <code> Since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
Hashtag = 8,
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Socialvoid.SvObjects.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// <see cref="TextEntity"/> 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public interface IEntity
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Get Method's Region
|
||||
/// <summary>
|
||||
/// Returns the type of this entity as a string.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the type of this entity as <see cref="string"/>.
|
||||
/// </returns>
|
||||
string GetStringType();
|
||||
/// <summary>
|
||||
/// Returns the type of this entity as a string.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the type of this entity as <see cref="EntityTypes"/>.
|
||||
/// </returns>
|
||||
EntityTypes GetEnumType();
|
||||
/// <summary>
|
||||
/// Checks if the type of this entity is valid/supported by this client
|
||||
/// or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsTypeValid();
|
||||
/// <summary>
|
||||
/// Checks if this <see cref="IEntity"/> object has
|
||||
/// a valid value property or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this object has a value;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool HasValue();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is normal or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is normal;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsNormal();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is bold or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is bold;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsBold();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is italic or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is italic;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsItalic();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is code or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is code;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsCode();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is strike-through or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is strike-through;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsStrikeThrough();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is underline or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is underline;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsUnderline();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is url or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is url;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsUrl();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is mention or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is mention;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsMention();
|
||||
/// <summary>
|
||||
/// Checks if the entity type is hashtag or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is hashtag;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
bool IsHashtag();
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Socialvoid.SvObjects.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public class TextEntity: IEntity
|
||||
{
|
||||
//-------------------------------------------------
|
||||
#region Constant's Region
|
||||
/// <summary>
|
||||
/// The string value for normal entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string NormalTypeStr = "NORMAL";
|
||||
/// <summary>
|
||||
/// The string value for bold entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string BoldTypeStr = "BOLD";
|
||||
/// <summary>
|
||||
/// The string value for italic entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string ItalicTypeStr = "ITALIC";
|
||||
/// <summary>
|
||||
/// The string value for code entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string CodeTypeStr = "CODE";
|
||||
/// <summary>
|
||||
/// The string value for strike-through entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string StrikeTypeStr = "STRIKE";
|
||||
/// <summary>
|
||||
/// The string value for underline entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string UnderlineTypeStr = "UNDERLINE";
|
||||
/// <summary>
|
||||
/// The string value for url entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string UrlTypeStr = "URL";
|
||||
/// <summary>
|
||||
/// The string value for mention entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string MentionTypeStr = "MENTION";
|
||||
/// <summary>
|
||||
/// The string value for hashtag entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public const string HashtagTypeStr = "HASHTAG";
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region static Properties Region
|
||||
// some members here
|
||||
#endregion
|
||||
//-------------------------------------------------
|
||||
#region Properties Region
|
||||
/// <summary>
|
||||
/// The text entity type.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The offset for when the entity begins in the text.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("offset")]
|
||||
public int Offset { get; set; }
|
||||
/// <summary>
|
||||
/// The length of the entity.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[JsonPropertyName("length")]
|
||||
public int Length { get; set; }
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
[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
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// Checks if this <see cref="TextEntity"/> object has
|
||||
/// a valid <see cref="Value"/> property or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
public virtual bool HasValue() => !string.IsNullOrEmpty(Value);
|
||||
/// <summary>
|
||||
/// Returns the type of this entity as a string.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the type of this entity as <see cref="string"/>.
|
||||
/// </returns>
|
||||
public virtual string GetStringType() => _typeStr;
|
||||
/// <summary>
|
||||
/// Returns the type of this entity as a string.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// the type of this entity as <see cref="EntityTypes"/>.
|
||||
/// </returns>
|
||||
public virtual EntityTypes GetEnumType() => _type;
|
||||
/// <summary>
|
||||
/// Checks if the type of this entity is
|
||||
/// valid/supported by this client
|
||||
/// or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the type is valid and supported;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsTypeValid() => !_invalid;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is normal or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is normal;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsNormal() => _type == EntityTypes.Normal;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is bold or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is bold;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsBold() => _type == EntityTypes.Bold;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is italic or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is italic;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsItalic() => _type == EntityTypes.Italic;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is code or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is code;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsCode() => _type == EntityTypes.Code;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is strike-through or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is strike-through;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsStrikeThrough() => _type == EntityTypes.StrikeThrough;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is underline or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is underline;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsUnderline() => _type == EntityTypes.Underline;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is url or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is url;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsUrl() => _type == EntityTypes.Url;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is mention or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is mention;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public virtual bool IsMention() => _type == EntityTypes.Mention;
|
||||
/// <summary>
|
||||
/// Checks if the entity type is hashtag or not.
|
||||
/// <code> since: v0.0.0 </code>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// <c>true</c> if the entity type is hashtag;
|
||||
/// otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
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
|
||||
//-------------------------------------------------
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue