Ejemplo n.º 1
0
 public void Save(string id, Deal deal)
 {
     Logger.Saving(deal);
     Storage.Save(id, Serializer.SerializeDeal(deal));
     Cache.Save(id, new Maybe<Deal>(deal));
     Logger.Saved(deal);
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Logging.LogProvider.SetCurrentLogProvider(new ColoredConsoleLogProvider());

            DealService service = new DealService();

            service.Username = "******";
            var id = Guid.NewGuid().ToString();
            var deal = new Deal
            {
                Id = id,
                Price = 500.00,
                Quantity = 10,
                Symbol = "MSFT",
                Time = DateTime.Now
            };
            var result = service.Save(id, deal);

            Console.WriteLine(result);

            Console.WriteLine();
            Console.WriteLine();

               var vincentDeal =  service.Load(id);
               Console.WriteLine(vincentDeal);

            Console.ReadLine();
        }
Ejemplo n.º 3
0
 public void Save(string id, Deal deal)
 {
     _logger.Info("Saving deal "+ deal.Id);
     var path = GetFileName(id);
     File.WriteAllText(path, JsonConvert.SerializeObject(deal));
     var savedDeal = ImmutableInterlocked.AddOrUpdate(ref _cache, id, deal, (i, d) => deal );
     _logger.Info("Saved deal " + savedDeal.Id );
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string username = Environment.UserName;

            Logging.LogProvider.SetCurrentLogProvider(new ColoredConsoleLogProvider());

            DealService service = new DealService(username);

            var id = Guid.NewGuid().ToString();
            var deal = new Deal
            {
                Id = id,
                Price = 500.00,
                Quantity = 10,
                Symbol = "MSFT",
                Time = DateTime.Now
            };

            service.Save(id, deal);

            Console.WriteLine(service.GetFileName(id));

            Console.WriteLine();
            Console.WriteLine();

            var defaultDeal = new Deal
            {
                Id = "UnSet",
                Price = 0,
                Quantity = 0,
                Symbol = "UnSet",
                Time = DateTime.MinValue
            };

            var vincentDeal =  service.Load(id).DefaultIfEmpty(defaultDeal).Single();
               Console.WriteLine(vincentDeal);

               Console.ReadLine();
        }
Ejemplo n.º 5
0
 public virtual void Saving(Deal deal)
 {
     _logger.Info($"Saving deal {deal.Id}.");
 }
Ejemplo n.º 6
0
 public virtual void Loaded(Deal deal)
 {
     _logger.Info($"Returning deal {deal.Id}.");
 }
Ejemplo n.º 7
0
 public virtual void AddOrUpdate(string id, Deal deal)
 {
     ImmutableInterlocked.AddOrUpdate(ref _cache, id, deal, (i, d) => deal);
 }
Ejemplo n.º 8
0
 public void Saved(Deal deal)
 {
     _logger.Info($"Saved deal {deal.Id}.");
 }
Ejemplo n.º 9
0
 public string SerializeDeal(Deal deal)
 {
     return JsonConvert.SerializeObject(deal);
 }