This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Diagnostics; | |
| using System.Linq; | |
| static partial class Sequence | |
| { | |
| /// <summary> | |
| /// Splits the sequence into two sequences, containing the elements | |
| /// for which the given predicate returns <c>true</c> and <c>false</c> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Xml.Linq; | |
| namespace Json.Linq | |
| { | |
| public class JDocument : XDocument | |
| { | |
| public JDocument() : base() { } | |
| public JDocument(params object[] content) : base(content) { } | |
| public JDocument(XDocument other) : base(other) { } | |
| public JDocument(XDeclaration declaration, params object[] content) : base(declaration, content) { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static async Task<IEnumerable<T>> WhereAsync<T>(this IEnumerable<T> collection, Func<T, Task<bool>> predicate) | |
| { | |
| var itemTaskList = collection.Select(item => new { Item = item, PredTask = predicate.Invoke(item) }).ToList(); | |
| await Task.WhenAll(itemTaskList.Select(x => x.PredTask)).ConfigureAwait(false); | |
| return itemTaskList.Where(x => x.PredTask.Result).Select(x => x.Item); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Abstraction | |
| { | |
| Bridge bridge; | |
| public Abstraction(Bridge implementation) | |
| { | |
| bridge = implementation; | |
| } | |
| public string Operation() | |
| { | |
| return "Abstraction <<< BRIDGE >>>> " + bridge.OperationImp(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Guard.Against<InvalidOperationException>(string.IsNullOrEmpty(serverName), "Server name must be provided") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Linq.Expressions; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace Ormazabal.PanelMonitoring.Helpers | |
| { | |
| static class Expressions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class Guard | |
| { | |
| public static void NotNull<T>(Expression<Func<T>> notNullableExpression) where T : class | |
| { | |
| var compliedExpression = notNullableExpression.Compile(); | |
| if (compliedExpression() == null) | |
| { | |
| var paramName = notNullableExpression.GetObjectNameGraph(); | |
| throw new ArgumentNullException(paramName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static TSource Strict<TSource, TExpect>(this IEnumerable<TSource> source) | |
| { | |
| if (source is null) throw new ArgumentNullException(nameof(source)); | |
| return source.Single(sour => sour.GetType() == typeof(TExpect)); | |
| } | |
| public static TSource StrictOrDefault<TSource, TExpect>(this IEnumerable<TSource> source) | |
| { | |
| if (source is null) throw new ArgumentNullException(nameof(source)); | |
| return source.SingleOrDefault(sour => sour.GetType() == typeof(TExpect)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static HttpClient client = new HttpClient(); | |
| // GET | |
| var response = await client.GetAsync(@"http://localhost/admin"); | |
| var cookies = response.Headers.FirstOrDefault(pair => String.Compare(pair.Key, @"Set-Cookie", StringComparison.OrdinalIgnoreCase) == 0).Value; | |
| // get token from html | |
| var html = await response.Content.ReadAsStringAsync(); | |
| var regex = new Regex("(name=\\\"_token\\\" value=)\\\"(.*)\\\""); | |
| var token = regex.Match(html).Groups[2].Value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using Newtonsoft.Json; | |
| using System.Net.Http; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using Newtonsoft.Json.Converters; | |
| namespace ArchDev | |
| { | |
| public static class HttpClientExtensions |