This file contains 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 class PropertyParser : IPropertyParser | |
{ | |
public IEnumerable<string> Parse<TEntity>(Expression<Func<TEntity, object>> expression, bool validate = true) where TEntity : new() | |
{ | |
return ParseProperty<TEntity>(expression.Body, validate); | |
} | |
public IEnumerable<string> Parse<TEntity,UEntity>(Expression<Func<TEntity, UEntity, object>> expression, bool validate = true) where TEntity : new() | |
{ | |
return ParseProperty<TEntity>(expression.Body, validate); | |
} |
This file contains 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 string GenerateSasToken(string resourceUri, string key, string policyName = null, int expiryInSeconds = 3600) | |
{ | |
TimeSpan fromEpochStart = DateTime.UtcNow - new DateTime(1970, 1, 1); | |
string expiry = Convert.ToString((int)fromEpochStart.TotalSeconds + expiryInSeconds); | |
string stringToSign = WebUtility.UrlEncode(resourceUri) + "\n" + expiry; | |
HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String(key)); | |
string signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign))); |
This file contains 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
static void Main(string[] args) | |
{ | |
string deviceId = "YOUR-DEVICE-ID".ToLower(); | |
string deviceKey = "YOUR-DEVICE PK OR SK"; | |
string hostname = $"YOUR-ENDPOINT-NAMESPACE.azure-devices.net"; | |
string endpoint = $"{hostname}/devices/{deviceId}"; | |
var token = GenerateSasToken(endpoint, deviceKey); | |
var conn = $"HostName={hostname};CredentialType=SharedAccessSignature;DeviceId={deviceId};SharedAccessSignature={token}"; | |
var deviceClient = DeviceClient.CreateFromConnectionString(conn, TransportType.Amqp_WebSocket_Only); | |
SendEvent(deviceClient).ConfigureAwait(false).GetAwaiter().GetResult(); |
This file contains 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
static async Task SendEvent(DeviceClient deviceClient) | |
{ | |
var dataBuffer = JsonConvert.SerializeObject( | |
new | |
{ | |
Wind = 10, | |
Humidity = 70, | |
Precipitation = 0 | |
}); |
This file contains 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
const a = 1 |
This file contains 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
//this service for catching all error in place | |
import { Injectable, ErrorHandler } from '@angular/core'; | |
import { LogService } from './log.service'; | |
@Injectable() | |
export class ErrorHandlerService extends ErrorHandler { | |
constructor(private logService: LogService) { | |
super(); | |
} |
This file contains 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
function validation(id) { | |
id = String(id).trim(); | |
if (id.length > 9 || isNaN(id)) return false; | |
id = id.length < 9 ? ("00000000" + id).slice(-9) : id; | |
return Array.from(id, Number).reduce((counter, digit, i) => { | |
const step = digit * ((i % 2) + 1); | |
return counter + (step > 9 ? step - 9 : step); | |
}) % 10 === 0; | |
} |
This file contains 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
builder.Register(c => | |
{ | |
var cacheType = ConfigurationManager.AppSettings["Cache.Type"]; | |
var configCache = (CacheType)Enum.Parse(typeof(CacheType), cacheType); | |
switch (configCache) | |
{ | |
case CacheType.Context: | |
default: | |
return (ICacheService) c.Resolve<ContextCacheService>(); | |
case CacheType.Redis: |
This file contains 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 interface ICacheService | |
{ | |
T GetData<T>(string key); | |
Task<T> GetDataAsync<T>(string key); | |
Task SetDataAsync<T>(string key, T data); | |
bool ClearData(string key); | |
} |
This file contains 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 class ContextCacheService : ICacheService | |
{ | |
public T GetData<T>(string key) | |
{ | |
try | |
{ | |
var value = HttpContext.Current.Cache[key]; |
OlderNewer