Ejemplo n.º 1
0
    public void Invoke(EventHandler <T> handler, object sender)
    {
        var @new = new ExContext(Context.Current, handler, sender);

        if (Interlocked.CompareExchange(ref _Context, @new, null) != null)
        {
            throw new InvalidOperationException();
        }

        Next();
    }
Ejemplo n.º 2
0
    public bool Done()
    {
        var xContext = _Context;

        if (xContext == null)
        {
            return(true);
        }

        if (xContext.Context != Context.Current)
        {
            throw new InvalidOperationException();
        }

#if UseInterlocked
        return(Interlocked.CompareExchange(ref _Context, null, xContext) == xContext);
#else
        _Context = null;
        return(false);
#endif
    }
Ejemplo n.º 3
0
    public void Next()
    {
        var xContext = _Context;

        if (xContext == null)
        {
            return;
        }

        var context = xContext.Context;

        if (context != Context.Current)
        {
            throw new InvalidOperationException();
        }

        var handler = xContext.Handler;
        var sender  = xContext.Sender;

        var current = (EventHandler <T>)handler.GetInvocationList().Last();

        var remains = handler - current;
        var @new    = (remains == null) ? null : new ExContext(context, remains, sender);

#if UseInterlocked
        if (Interlocked.CompareExchange(ref _Context, @new, xContext) != xContext)
        {
            throw new InvalidOperationException();
        }
#else
        _Context = @new;
#endif

        current(sender, (T)this);

        Next();
    }
Ejemplo n.º 4
0
        public void initRepositoryFromFile(string fileName)
        {
            ExelData exelData = new ExelData(fileName, progressChanged);

            progress.Status   = "Delete old visitors";
            progress.Progress = 0;
            using (var ctx = new ExContext())
            {
                int count      = 1;
                var collection = ctx.Visitors.ToList();
                var size       = collection.Count() + 1;
                foreach (var u in collection)
                {
                    progress.Progress = (int)(count * 100 / size);
                    progressChanged(progress);
                    ctx.Visitors.Remove(u);
                    count++;
                }
                ctx.SaveChanges();
            }
            exelData.setDataToCollection(context.Visitors, progressChanged);
            context.SaveChanges();
            progress.Status   = "Add new data to collection";
            progress.Progress = 0;
            int c   = 1;
            var col = context.Visitors;
            var s   = col.Count() + 1;

            foreach (var v in col)
            {
                progress.Progress = (int)(c * 100 / s);
                progressChanged(progress);
                visitorCollection.Add(v);
                c++;
            }
        }
Ejemplo n.º 5
0
        public CFExRepository()
        {
            progress = new Progress_Bar();
            displaySettingCollection  = new ObservableCollection <DisplaySetting>();
            dsColumnSettingCollection = new ObservableCollection <DSCollumnSetting>();
            visitorCollection         = new ObservableCollection <Visitor>();
            context = new ExContext();
            var d = context.DisplaySettings.ToList();

            if (d.Count() == 0)
            {
                //create default setting
                DisplaySetting defaultSetting = new DisplaySetting {
                    Name = "default", IsSelected = true
                };
                context.DisplaySettings.Add(defaultSetting); context.SaveChanges();
                //find setting in database wich contain parameter Id
                var defaulSetting = context.DisplaySettings.Where(s => s.Name == "default").FirstOrDefault();
                //add setting to repository
                displaySettingCollection.Add(defaulSetting);
                //find value Id for DisplaySettingId in DSCollumnSetting
                var defaulSettingId = defaulSetting.Id;
                //create collumn for default setting
                //add collumn in database
                context.DSCollumnSettings.Add(new DSCollumnSetting {
                    Name = "Id", Alias = "№", Width = 100, Visible = true, IsSelected = true, DisplaySettingId = defaulSettingId
                });
                context.DSCollumnSettings.Add(new DSCollumnSetting {
                    Name = "FirstName", Alias = "Имя", Width = 100, Visible = true, IsSelected = false, DisplaySettingId = defaulSettingId
                });
                context.DSCollumnSettings.Add(new DSCollumnSetting {
                    Name = "LastName", Alias = "Фамилия", Width = 100, Visible = true, IsSelected = false, DisplaySettingId = defaulSettingId
                });
                context.DSCollumnSettings.Add(new DSCollumnSetting {
                    Name = "Сompany", Alias = "Компания", Width = 100, Visible = true, IsSelected = false, DisplaySettingId = defaulSettingId
                });
                context.DSCollumnSettings.Add(new DSCollumnSetting {
                    Name = "Jobtitle", Alias = "Должность", Width = 100, Visible = true, IsSelected = false, DisplaySettingId = defaulSettingId
                });
                context.SaveChanges();
                //extract collumns from database which contain parameter Id and add its into the perository
                var _dsCollumnSettings = context.DSCollumnSettings;
                foreach (var c in _dsCollumnSettings)
                {
                    dsColumnSettingCollection.Add(c);
                }
            }
            else
            {
                //find settings in database
                var _displaySettingCollection = context.DisplaySettings;
                //add setting to repository
                foreach (var c in _displaySettingCollection)
                {
                    displaySettingCollection.Add(c);
                }
                //extract collumns from database which contain parameter Id and add its into the perository
                var _dsCollumnSettings = context.DSCollumnSettings;
                foreach (var c in _dsCollumnSettings)
                {
                    dsColumnSettingCollection.Add(c);
                }
            }
        }
Ejemplo n.º 6
0
 public Repository(ExContext exContext)
 {
     _exContext = exContext;
     _table     = _exContext.Set <T>();
 }