Skip to content

Instantly share code, notes, and snippets.

View Hereigo's full-sized avatar

Hereigo Hereigo

  • Ukraine, Kyiv
View GitHub Profile
@Hereigo
Hereigo / ConcurrentDictionary.cs
Created June 22, 2017 11:56
.Net - ConcurrentDictionary (thead safe)
void ConcurrentDicTest()
{
ConcurrentDictionary<string, string> concurrDic = new ConcurrentDictionary<string, string>();
Task tsk1 = Task.Factory.StartNew(() =>
{
for (int i = 0; i < 100; i++)
{
concurrDic.TryAdd(i.ToString(), (i + i).ToString());
Thread.Sleep(100);
@Hereigo
Hereigo / IRepository.cs
Last active June 21, 2017 09:16
.Net - IRepository Patterm (with EF)
public class BookContext : DbContext // DbContext - ADOModel Generated by EF.
{
public BookContext() : base("DefaultConnection")
{ }
public DbSet<Book> Books { get; set; }
}
interface IRepository<T> //: IDisposable where T : class
{
IEnumerable<T> GetBookList();
@Hereigo
Hereigo / DummyNewWordGenerator.cs
Created June 21, 2017 07:41
.Net - Dummy New Word Generator
private static string GenerateNewWord(int minLength, int maxLength)
{
string wordNew = "";
int wordLength = r.Next(minLength, maxLength);
for (int k = 0; k < wordLength; k++)
{
int charNew;
charNew = (k == 0) ? r.Next(65, 90) : r.Next(97, 122);
// (char)48..57 = 0-9
// (char)65..90 = A-Z
@Hereigo
Hereigo / UnityContainer.BuildUp.cs
Created June 19, 2017 09:39
.Net - DI UnityContainer.BuildUp (for Outer objects)
public class OuterHelperClass
{
public void HlprClaWork()
{
Console.WriteLine("Outer HelperClass Doing something...");
}
}
public class MyService
{
@Hereigo
Hereigo / DI_Constructors_and_Params.cs
Last active June 19, 2017 07:49
.Net - DI Constructors and Parameters
public class MyService
{
public int _intVal;
public MyService(int x)
{
_intVal = x;
}
[Dependency]
public Random MyRnd { get; set; }
@Hereigo
Hereigo / Unity_Config_Double.cs
Last active June 14, 2017 12:13
.Net - DI UnityContainer double Configuration
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using System;
using System.Configuration;
// Classes Pursuit_Game & Maze_Game are : IGame
public class Game_Box
{
private IGame _game;
@Hereigo
Hereigo / RMQ_Send_Receive.cs
Last active June 14, 2017 12:21
.Net - RMQ : Sender_and_Receiver C#
void WorkWithRMQ(bool isReceiver)
{
string Exchange = "my.special";
string Queue = "my.special.outq2";
string RoutingKey = "my.special.outq2";
var factory = new ConnectionFactory()
{
HostName = "RabbitMQ.server",
Port = 15672,
@Hereigo
Hereigo / TaskComplitionSource.cs
Last active June 9, 2017 06:57
.Net - TaskComplitionSource (return Task<string>)
internal void Run()
{
var rez = Task<string>.Run(() =>
{
return LongTermProcedure();
});
// OR use "TaskCompletionSource" :
// var rez = GetDataAsync();
Console.WriteLine(rez.Result);
}
@Hereigo
Hereigo / SendWebRequest.cs
Last active June 2, 2017 11:25
.Net - Send WebRequest (with Certificate)
class Program
{
static void Main(string[] args)
{
int port = 31519;
string url = "http://localhost:" + port + "/api/hello";
WebRequest REQ = WebRequest.Create(url);
REQ.Method = "POST";
@Hereigo
Hereigo / Simple_DI.cs
Last active June 1, 2017 06:12
.Net - DI simple example.
// ATTENTION !!!
using System.Configuration;
// ATTENTION !!!
class Program
{
static void Main(string[] args)
{
IMessageWriter writer = new ConsoleMessageWriter();
var app = new AppForMsgWriter(writer);
app.Exec();