示例#1
0
        void Simulation_OnProgressUpdate(object sender, ProgressUpdateArgs arg)
        {
            Result r = arg.Result;

            labelCurrentDate.Text = "Current date: " + r.Date.Month.ToString() + "//" + r.Date.Day.ToString() + "//" + r.Date.Year.ToString();
            progressBar1.Value    = (int)(r.PercComp * 100);
        }
示例#2
0
        public void SyncBrand()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Sync required data from FHGLocal to DB

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // State Table

            Repository<int, EvtBrand> _fhgBrandRepo = new Repository<int, EvtBrand>(_UnitOfWorkFHG.Session);
            Repository<Guid, Brand> _aplBrandRepo = new Repository<Guid, Brand>(_UnitOfWorkAPL.Session);

            var aplBrand = _aplBrandRepo.All().ToList();
            var fhgBrand = _fhgBrandRepo.All().ToList();

            int itemCount = 1;
            // Add Missing data
            foreach (EvtBrand evtBrand in fhgBrand)
            {
                e.TotalWorkItems = fhgBrand.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Brands - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (Brand brand in aplBrand)
                {
                    if (brand.FhgBrandId == evtBrand.Id)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Brand newBrand = new Brand();
                    newBrand.FhgBrandId = evtBrand.Brandid;
                    newBrand.Name = evtBrand.Brandname;
                    _aplBrandRepo.Add(newBrand);
                }

                itemCount++;
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
示例#3
0
 private void Context_ProgressUpdated(object sender, ProgressUpdateArgs e)
 {
     Logger.Info($"Progress updated for op {e.ProgressID}: {e.Progress.ToString("P2")}");
 }
示例#4
0
        public void SyncVenue()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Venue Table

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            Repository<int, CusOrgentity> _fhgVenueRepo = new Repository<int, CusOrgentity>(_UnitOfWorkFHG.Session);
            Repository<Guid, Venue> _aplVenueRepo = new Repository<Guid, Venue>(_UnitOfWorkAPL.Session);
            Repository<Guid, Region> _aplRegionRepo = new Repository<Guid, Region>(_UnitOfWorkAPL.Session);

            //IList<object[]> fhgVenue = _sessionHelper.GetStatelessSession("FHG").QueryOver<CusOrgentity>()
            //                            .Select(c => c.Orgentityid,
            //                            c => c.Active,
            //                            c => c.Name).List<object[]>();

            //IList<object[]> aplVenueResult = _sessionHelper.GetStatelessSession("APL").QueryOver<Venue>()
            //    .Select(c => c.Id,
            //    c => c.FHGVenueId,
            //    c => c.Active,
            //    c => c.Name).List<object[]>();

            var fhgVenue = _fhgVenueRepo.All().ToList();
            var aplVenueResult = _aplVenueRepo.All().ToList();

            Dictionary<int, object> aplVenues = new Dictionary<int, object>();
            foreach (Venue o in aplVenueResult)
            {
                aplVenues.Add(o.FHGVenueId, o);
            }

            // Add Missing data
            int itemCount = 1;
            foreach (CusOrgentity fhgCustOrgEntity in fhgVenue)
            {
                try
                {
                     e.TotalWorkItems = fhgVenue.Count();
                    e.CurrentWorkItem = itemCount;
                    e.StatusString = "Syncing Venues - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                    this.ProgressUpdate(e);

                    if (!aplVenues.ContainsKey(fhgCustOrgEntity.Id))
                    {
                        CusOrgentity c = fhgCustOrgEntity;
                        Venue v = new Venue();
                        v.Name = c.Name;
                        v.Active = (c.Active != null) ? (bool)c.Active : true;
                        v.FHGVenueId = c.Id;
                        if (c.Region.Count > 0)
                        {
                            v.Region = _aplRegionRepo.FilterBy(x => x.Name == c.Region[0].Regionname).FirstOrDefault();
                        }
                        _aplVenueRepo.Add(v);
                    }
                    else
                    {
                        Venue aplVenue = (Venue)aplVenues[fhgCustOrgEntity.Id];

                        if (aplVenue.Active != fhgCustOrgEntity.Active || aplVenue.Name != fhgCustOrgEntity.Name)
                        {
                            aplVenue.Name = fhgCustOrgEntity.Name;
                            aplVenue.Active = (bool)(fhgCustOrgEntity.Active.HasValue ? false : fhgCustOrgEntity.Active);
                            _aplVenueRepo.Update(aplVenue);
                        }
                    }
                    itemCount++;
                }
                catch (Exception mException)
                {
                    int x = 1;
                    continue;
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
示例#5
0
        public void SyncState()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Sync required data from FHGLocal to DB

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // State Table

            Repository<int, CusState> _fhgStateRep = new Repository<int, CusState>(_UnitOfWorkFHG.Session);
            Repository<Guid, State> _aplStateRepo = new Repository<Guid, State>(_UnitOfWorkAPL.Session);

            var stateAPLDB = _aplStateRepo.All().ToList();
            var stateFHG = _fhgStateRep.All().ToList();

            int itemCount = 1;
            // Add Missing data
            foreach (CusState c in stateFHG)
            {
                e.TotalWorkItems = stateFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing States - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (State s in stateAPLDB)
                {
                    if (s.Shortname == c.Shortname)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    State s = new State();
                    s.Shortname = c.Shortname;
                    s.Name = c.Fullname;
                    _aplStateRepo.Add(s);
                }

                itemCount++;
            }

            // Remove extra data.
            foreach (State s in stateAPLDB)
            {
                bool found = false;
                foreach (CusState c in stateFHG)
                {
                    if (s.Shortname == c.Shortname)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplStateRepo.Delete(s);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
示例#6
0
        public void SyncRegion()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Region Table
            //
            // Select data from FHGLocal
            // Select data from Local DB
            // Compare and update/insert.

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            DataLayer.Repository<int, CusRegion> _fhgRegionRepo = new Repository<int, CusRegion>(_UnitOfWorkFHG.Session);
            Repository<Guid, Region> _aplRegionRepo = new Repository<Guid, Region>(_UnitOfWorkAPL.Session);
            Repository<Guid, State> _aplStateRepo = new Repository<Guid, State>(_UnitOfWorkAPL.Session);
            Repository<Guid, Brand> _aplBrandRepo = new Repository<Guid, Brand>(_UnitOfWorkAPL.Session);

            var regionAPLDB = _aplRegionRepo.All().ToList();
            var regionFHG = _fhgRegionRepo.All().ToList();
            int itemCount = 1;
            // Add Missing data
            foreach (CusRegion c in regionFHG)
            {
                e.TotalWorkItems = regionFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Regions - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (Region s in regionAPLDB)
                {
                    if (s.Name == c.Regionname)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Region r = new Region();
                    r.Name = c.Regionname;
                    r.Active = !c.Archived.HasValue ? false : !(bool)c.Archived;
                    r.State = _aplStateRepo.FilterBy(s => s.Name == c.CusState.Fullname).FirstOrDefault();
                    r.Brand = _aplBrandRepo.FilterBy(x => x.FhgBrandId == c.Brandid).FirstOrDefault();
                    _aplRegionRepo.Add(r);
                }
                itemCount++;
            }

            // Remove extra data.
            foreach (Region r in regionAPLDB)
            {
                bool found = false;
                foreach (CusRegion cr in regionFHG)
                {
                    if (r.Name == cr.Regionname)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplRegionRepo.Delete(r);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
示例#7
0
        public void SyncGameType()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            // Sync required data from FHGLocal to DB

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // State Table

            Repository<int, EvtDivision> _fhgEvtDivisionRep = new Repository<int, EvtDivision>(_UnitOfWorkFHG.Session);
            Repository<Guid, GameType> _aplGameTypeRepo = new Repository<Guid, GameType>(_UnitOfWorkAPL.Session);

            var gametypeAPLDB = _aplGameTypeRepo.All().ToList();
            var divisionFHG = _fhgEvtDivisionRep.All().ToList();

            int itemCount = 1;
            // Add Missing data
            foreach (EvtDivision c in divisionFHG)
            {
                e.TotalWorkItems = divisionFHG.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Game Types - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                this.ProgressUpdate(e);

                bool found = false;
                foreach (GameType s in gametypeAPLDB)
                {
                    if (s.FhgDivisionId == c.Id)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    GameType s = new GameType();
                    s.FhgDivisionId = c.Id;
                    s.Gametype = c.Divisionname;
                    _aplGameTypeRepo.Add(s);
                }

                itemCount++;
            }

            // Remove extra data.
            foreach (GameType s in gametypeAPLDB)
            {
                bool found = false;
                foreach (EvtDivision c in divisionFHG)
                {
                    if (s.FhgDivisionId == c.Id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    _aplGameTypeRepo.Delete(s);
                }
            }

            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }
示例#8
0
        public void SyncGame()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            e.StatusString = "Syncing Games - Reading data";
            this.ProgressUpdate(e);

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            // Customer/Memeber Table
            Repository<int, EvtEvent> _fhgEventRepo = new Repository<int, EvtEvent>(_UnitOfWorkFHG.Session);
            Repository<Guid, EvtGame> _fhgEvtGameRepo = new Repository<Guid, EvtGame>(_UnitOfWorkFHG.Session);
            Repository<Guid, Game> _aplGameRepo = new Repository<Guid, Game>(_UnitOfWorkAPL.Session);
            Repository<Guid, Venue> _aplVenueRepo = new Repository<Guid, Venue>(_UnitOfWorkAPL.Session);
            Repository<Guid, GameType> _aplGameTypeRepo = new Repository<Guid, GameType>(_UnitOfWorkAPL.Session);

            IList<object[]> fhgEvents = _UnitOfWorkFHG.Session.QueryOver<EvtEvent>()
                .Select(x => x.Eventid,
                x => x.Updateversion).Where(x => x.Eventdate >= DateTime.Today.AddDays(-7)).List<object[]>();

            IList<object[]> aplGames = _UnitOfWorkAPL.Session.QueryOver<Game>()
                .Select(c => c.Id,
                c => c.FHGEventId,
                c => c.FHGUpdateVersion).List<object[]>();

            Dictionary<int, object> aplGameList = new Dictionary<int, object>();
            foreach (object[] o in aplGames)
            {
                aplGameList.Add(int.Parse(o[1].ToString()), o);
            }

            int itemCount = 1;

            foreach (object[] fhgEventObject in fhgEvents)
            {
                try
                {
                    e.TotalWorkItems = fhgEvents.Count();
                    e.CurrentWorkItem = itemCount;
                    e.StatusString = "Syncing Games - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";
                    this.ProgressUpdate(e);

                    int fhgEventId = int.Parse(fhgEventObject[0].ToString());
                    Guid fhgUpdateVersion = Guid.Parse(fhgEventObject[1].ToString());

                    if (!aplGameList.ContainsKey(fhgEventId))
                    {

                        EvtEvent curEvent = _fhgEventRepo.FindBy(fhgEventId);

                        // Skip events which don't have a venue assigned.  Why??
                        if (!curEvent.Orgentityid.HasValue)
                        {
                            continue;
                        }

                        EvtGame curEventGame = curEvent.EvtGame[0];

                        Venue gameVenue = _aplVenueRepo.FilterBy(x => x.FHGVenueId == curEvent.Orgentityid).FirstOrDefault();
                        GameType gameType = _aplGameTypeRepo.FilterBy(x => x.FhgDivisionId == curEventGame.Divisionid).FirstOrDefault();

                        Game newGame = new Game();
                        newGame.FHGEventId = fhgEventId;
                        newGame.FHGUpdateVersion = curEvent.Updateversion;
                        newGame.Description = (!string.IsNullOrEmpty(curEventGame.Gamedescription)) ? curEventGame.Gamedescription : curEvent.Eventdescription;
                        newGame.GameDate = curEvent.Eventdate;
                        newGame.Name = curEvent.Eventname;
                        newGame.RegoTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Registrationtime);
                        newGame.StartTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Starttime);
                        newGame.Venue = gameVenue;
                        newGame.GameType = gameType;
                        newGame.Active = !curEvent.Archived.HasValue ? false : !(bool)curEvent.Archived;
                        newGame.BuyIn = curEventGame.Playerentryfee != null ? (float)curEventGame.Playerentryfee : 0;

                        _aplGameRepo.Add(newGame);

                    }
                    else
                    {
                        object[] aplComparison = (object[])aplGameList[fhgEventId];
                        Guid aplGameId = Guid.Parse(aplComparison[0].ToString());
                        int aplfhgGameId = int.Parse(aplComparison[1].ToString());
                        Guid aplfhgGameUpdateVersion = Guid.Parse(aplComparison[2].ToString());
                        // Check for updates.
                        if (fhgUpdateVersion != aplfhgGameUpdateVersion)
                        {
                            Game aplGame = _aplGameRepo.FindBy(aplGameId);
                            EvtEvent curEvent = _fhgEventRepo.FindBy(fhgEventId);
                            EvtGame curEventGame = curEvent.EvtGame[0];
                            Venue gameVenue = _aplVenueRepo.FilterBy(x => x.FHGVenueId == curEvent.Orgentityid).FirstOrDefault();
                            GameType gameType = _aplGameTypeRepo.FilterBy(x => x.FhgDivisionId == curEventGame.Divisionid).FirstOrDefault();
                            aplGame.FHGEventId = fhgEventId;
                            aplGame.FHGUpdateVersion = curEvent.Updateversion;
                            aplGame.Description = (!string.IsNullOrEmpty(curEventGame.Gamedescription)) ? curEventGame.Gamedescription : curEvent.Eventdescription;
                            aplGame.GameDate = curEvent.Eventdate;
                            aplGame.Name = curEvent.Eventname;
                            aplGame.RegoTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Registrationtime);
                            aplGame.StartTime = DateTime.Parse(curEvent.Eventdate.Value.ToShortDateString() + " " + curEvent.Starttime);
                            aplGame.Venue = gameVenue;
                            aplGame.GameType = gameType;
                            aplGame.Active = !curEvent.Archived.HasValue ? false : !(bool)curEvent.Archived;
                            aplGame.BuyIn = curEventGame.Playerentryfee != null ? (float)curEventGame.Playerentryfee : 0;

                            _aplGameRepo.Update(aplGame);

                        }
                    }
                }
                catch (Exception mException)
                {
                    int x = 1;
                }
                finally
                {
                    itemCount++;
                }
            }
        }
示例#9
0
        //public int SyncCustomer()
        public void SyncCustomer()
        {
            ProgressUpdateArgs e = new ProgressUpdateArgs();
            e.StatusString = "Syncing Customers - Reading data";
            this.ProgressUpdate(e);

            _UnitOfWorkAPL = new UnitOfWork(_sessionHelper.GetSessionFactory("APL"));
            _UnitOfWorkFHG = new UnitOfWork(_sessionHelper.GetSessionFactory("FHG"));

            //// Game Table
            DataLayer.Repository<Guid, CusCustomer> _fhgCustomerRepo = new Repository<Guid, CusCustomer>(_UnitOfWorkFHG.Session);
            DataLayer.Repository<Guid, MemMembership> _fhgMembershipRepo = new Repository<Guid, MemMembership>(_UnitOfWorkFHG.Session);
            Repository<Guid, User> _aplUserRepo = new Repository<Guid, User>(_UnitOfWorkFHG.Session);

            IList<object[]> fhgCustomers = _sessionHelper.GetStatelessSession("FHG").QueryOver<CusCustomer>()
                .Select(c => c.Customerguid,
                c => c.Updateversion).List<object[]>();

            IList<object[]> aplCustomerResult = _sessionHelper.GetStatelessSession("APL").QueryOver<User>()
                .Select(c => c.Id,
                c => c.FHGID,
                c => c.FHGUpdateID).List<object[]>();

            Dictionary<Guid, object> aplCustomers = new Dictionary<Guid, object>();
            foreach (object[] o in aplCustomerResult)
            {
                aplCustomers.Add(Guid.Parse(o[1].ToString()), o);
            }

            // Add Missing data
            int itemCount = 1;
            foreach (object[] fhgCustomerObject in fhgCustomers)
            {
                Guid fhgCustomerGuid = Guid.Parse(fhgCustomerObject[0].ToString());
                Guid fhgCustomerUpdateVersion = Guid.Parse(fhgCustomerObject[1].ToString());
                e.TotalWorkItems = fhgCustomers.Count();
                e.CurrentWorkItem = itemCount;
                e.StatusString = "Syncing Customers - (" + itemCount.ToString() + "/" + e.TotalWorkItems.ToString() + ")";

                this.ProgressUpdate(e);
                if (!aplCustomers.ContainsKey(fhgCustomerGuid))
                {
                    CusCustomer c = _fhgCustomerRepo.FindBy(fhgCustomerGuid);
                    User u = new User();
                    u.ContactEmail = c.Emailaddress;
                    u.ContactMobile = CleanPhoneNumber(c.Phonemobile);
                    u.ContactPhone = CleanPhoneNumber(c.Phonenumber);
                    if (c.Membership != null)
                        u.APLNumber = c.Membership.Membershipnumber;
                    u.Enabled = true;
                    u.FHGID = c.Id;
                    u.Surname = c.Lastname;
                    u.FirstName = c.Firstname;
                    u.Username = c.Username;
                    u.FHGUpdateID = c.Updateversion;

                    _aplUserRepo.Add(u);
                }
                else
                {
                    object[] aplComparison = (object[])aplCustomers[fhgCustomerGuid];
                    Guid aplUserId = Guid.Parse(aplComparison[0].ToString());
                    Guid aplfhgCustomerId = Guid.Parse(aplComparison[1].ToString());
                    Guid aplfhgCustomerUpdateVersion = Guid.Parse(aplComparison[2].ToString());
                    // Check for updates.
                    if (fhgCustomerUpdateVersion != aplfhgCustomerUpdateVersion)
                    {
                        CusCustomer c = _fhgCustomerRepo.FindBy(fhgCustomerGuid);
                        User u = _aplUserRepo.FindBy(aplUserId);
                        u.ContactEmail = c.Emailaddress;
                        u.ContactMobile = CleanPhoneNumber(c.Phonemobile);
                        u.ContactPhone = CleanPhoneNumber(c.Phonenumber);
                        u.Enabled = true;
                        u.FHGID = c.Id;
                        u.Surname = c.Lastname;
                        u.FirstName = c.Firstname;
                        u.Username = c.Username;
                        u.FHGUpdateID = c.Updateversion;
                        _aplUserRepo.Update(u);
                    }
                }

                itemCount++;
            }
            _UnitOfWorkAPL.Commit();
            _UnitOfWorkFHG.Commit();
        }