コード例 #1
0
        public static void SaveTickCallBack(int period, string pair, Action <object> progressCallback, ActionBlock <Action> saveTickActionBlock, RateLoadingCallbackArgs <Rate> args)
        {
            if (progressCallback != null)
            {
                progressCallback(args.Message);
            }
            else
            {
                Debug.WriteLine("{0}", args.Message);
            }
            var context = new ForexEntities();

            //context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled = false;
            Action a = () =>
                       args.NewRates.Distinct().Do(t => {
                context.t_Bar.Add(FillBar(period, pair, context.t_Bar.Create(), t));
            }).TakeLast(1)
                       .ForEach(_ => {
                try {
                    context.SaveConcurrent();
                } catch (Exception exc) {
                    progressCallback?.Invoke(exc);
                }
                context.Dispose();
                args.NewRates.Clear();
            });

            a();
            //saveTickActionBlock.Post(a);
        }
コード例 #2
0
ファイル: PriceHistory.cs プロジェクト: kknet/HedgeHog
        public static void SaveTickCallBack(int period, string pair, Action <object> progressCallback, ActionBlock <Action> saveTickActionBlock, RateLoadingCallbackArgs <Rate> args)
        {
            if (progressCallback != null)
            {
                progressCallback(args.Message);
            }
            else
            {
                Debug.WriteLine("{0}", args.Message);
            }
            var context = new ForexEntities();

            //context.Configuration.AutoDetectChangesEnabled = false;
            context.Configuration.ValidateOnSaveEnabled = false;
            Action a = () =>
                       args.NewRates.Distinct(r => r.StartDate2).Do(t => {
                context.t_Bar.Add(FillBar(period, pair, context.t_Bar.Create(), t));
            }).TakeLast(1)
                       .ForEach(_ => {
                try {
                    context.SaveConcurrent();
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException exc) when(exc.InnerException is System.Data.Entity.Core.UpdateException)
                {
                    // get failed entries
                    var entries = exc.Entries;
                    foreach (var entry in entries)
                    {
                        // change state to remove it from context
                        entry.State = System.Data.Entity.EntityState.Detached;
                    }
                    progressCallback?.Invoke(exc);
                }
                context.Dispose();
                args.NewRates.Clear();
            });

            a();
            //saveTickActionBlock.Post(a);
        }