Пример #1
0
        private static void AddInHostV2List(
            SyncModel syncModel,
            int fromVersion)
        {
            IHostTypesDataService            hostTypesDataService = AndroAdminDataAccessFactory.GetHostTypesDataService();
            IHostV2DataService               hostV2DataService    = AndroAdminDataAccessFactory.GetHostV2DataService();
            IHostV2ForStoreDataService       hostV2ForStore       = AndroAdminDataAccessFactory.GetHostV2ForStoreDataService();
            IHostV2ForApplicationDataService hostV2ForApplication = AndroAdminDataAccessFactory.GetHostV2ForApplicationDataService();

            var hosts = hostV2DataService.List(e => e.DataVersion > fromVersion);

            var activeHosts   = hosts.Where(e => e.Enabled);
            var disabledHosts = hosts.Where(e => !e.Enabled);

            var deletedHosts = hostV2DataService.ListDeleted(e => e.DataVersion > fromVersion);

            var hosttypes        = hostTypesDataService.List(e => true);
            var hostApplications = hostV2ForApplication.ListHostConnections(e => e.HostV2.Any(hostV2 => hostV2.DataVersion > fromVersion));
            var hostStores       = hostV2ForStore.ListHostConnections(e => e.HostV2.Any(hostV2 => hostV2.DataVersion > fromVersion));

            syncModel.HostV2Models = new CloudSyncModel.HostV2.HostV2Models()
            {
                //full list of host types that are available
                HostTypes = hosttypes.Select(e => e.Name).ToList(),
                //actual list of active, available hosts
                Hosts = activeHosts.Select(hostV2 => hostV2.ToSyncModel()).ToList(),
                //any hosts that must be removed (disabled for maintenance or removed completely, even the ones that may even be back later)
                DeletedHosts = disabledHosts.Union(deletedHosts).Select(hostV2 => hostV2.ToSyncModel()).ToList(),
                //store specific links to the hosts
                StoreLinks = hostStores.Select(e => e.ToSyncModel()).ToList(),
                //application specific links to the hosts
                ApplicationLinks = hostApplications.Select(e => e.ToSyncModel()).ToList()
            };
        }
Пример #2
0
        private static void AddinMenuUpdates(SyncModel syncModel, int fromVersion)
        {
            IStoreMenuThumbnailsDataService dataService = AndroAdminDataAccessFactory.GetStoreMenuThumbnailDAO();

            IEnumerable <AndroAdminDataAccess.Domain.StoreMenu> menuChanges =
                dataService.GetStoreMenuChangesAfterDataVersion(fromVersion);
            IEnumerable <AndroAdminDataAccess.Domain.StoreMenuThumbnails> thumbnailChanges =
                dataService.GetStoreMenuThumbnailChangesAfterDataVersion(fromVersion);

            foreach (var change in menuChanges)
            {
                syncModel.MenuUpdates.MenuChanges.Add(new CloudSyncModel.Menus.StoreMenuUpdate()
                {
                    AndromediaSiteId = change.AndromedaSiteId,
                    Data             = change.MenuData,
                    Id          = change.Id,
                    LastUpdated = change.LastUpdated,
                    MenuType    = change.MenuType,
                    Version     = change.Version,
                });
            }

            foreach (var change in thumbnailChanges)
            {
                syncModel.MenuUpdates.MenuThumbnailChanges.Add(new CloudSyncModel.Menus.StoreMenuUpdate()
                {
                    Id               = change.Id,
                    LastUpdated      = change.LastUpdate,
                    AndromediaSiteId = change.AndromediaSiteId,
                    Data             = change.Data,
                    MenuType         = change.MenuType
                });
            }
        }
Пример #3
0
        private static void AddInPartnerUpdates(IPartnerDAO partnerDao, IStoreDAO storeDao, SyncModel syncModel, int fromVersion)
        {
            // Get all the partners that have changed since the last sync with this specific cloud server
            List <AndroAdminDataAccess.Domain.Partner> partners = (List <AndroAdminDataAccess.Domain.Partner>)partnerDao.GetAfterDataVersion(fromVersion);

            foreach (AndroAdminDataAccess.Domain.Partner partner in partners)
            {
                // Add the partner
                Partner syncPartner = new Partner()
                {
                    Id         = partner.Id,
                    ExternalId = partner.ExternalId,
                    Name       = partner.Name
                };

                syncModel.Partners.Add(syncPartner);

                // Get the partner DAO
                IACSApplicationDAO acsApplicationDao = AndroAdminDataAccessFactory.GetACSApplicationDAO();
                if (SyncHelper.ConnectionStringOverride != null)
                {
                    acsApplicationDao.ConnectionStringOverride = SyncHelper.ConnectionStringOverride;
                }

                // Get all the applications that have changed for this partner since the last sync with this specific cloud server
                IList <AndroAdminDataAccess.Domain.ACSApplication> acsApplications = acsApplicationDao.GetByPartnerAfterDataVersion(partner.Id, fromVersion);
                foreach (AndroAdminDataAccess.Domain.ACSApplication acsApplication in acsApplications)
                {
                    // Add the application
                    Application syncApplication = new Application()
                    {
                        Id = acsApplication.Id,
                        ExternalApplicationId = acsApplication.ExternalApplicationId,
                        Name = acsApplication.Name,
                        ExternalDisplayName = acsApplication.ExternalApplicationName
                    };
                    syncPartner.Applications.Add(syncApplication);

                    // Get all the application stores that have changed for this application since the last sync with this specific cloud server
                    StringBuilder siteIds = new StringBuilder();
                    IList <AndroAdminDataAccess.Domain.Store> acsApplicationStores = storeDao.GetByACSApplicationId(acsApplication.Id);
                    foreach (AndroAdminDataAccess.Domain.Store store in acsApplicationStores)
                    {
                        if (siteIds.Length > 0)
                        {
                            siteIds.Append(",");
                        }

                        siteIds.Append(store.AndromedaSiteId.ToString());
                    }

                    syncApplication.Sites = siteIds.ToString();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Must be called from the Cloud Master.  Syncs Cloud master with all cloud servers
        /// </summary>
        public static string ServerSync()
        {
            // Get the current data version
            string toVersionString = string.Empty;

            AndroAdminDataAccessFactory.GetSettingsDAO().GetByName("DataVersion", out toVersionString);

            int toVersion = 0;

            if (!int.TryParse(toVersionString, out toVersion))
            {
                return("Internal error");
            }

            // Get all the hosts
            IList <AndroAdminDataAccess.Domain.Host> hosts = AndroAdminDataAccessFactory
                                                             .GetHostDAO()
                                                             .GetAll();

            string errorMessage = string.Empty;

            foreach (AndroAdminDataAccess.Domain.Host host in hosts)
            {
                // 1) Ask the server for it's current data version
                int fromVersion = 0;
                errorMessage = AcsSyncHelper.GetAcsServerDataVersion(host, out fromVersion);

                //todo make the response enumerable
                //yield errorMessage

                if (errorMessage.Length == 0)
                {
                    // 2) Generate a block of XML that contains Add, Delete, Update objects that have changed on Cloud Master after the Cloud Servers version for:
                    string syncXml = string.Empty;

                    errorMessage = AndroAdminSyncHelper.TryGetExportSyncXml(fromVersion, toVersion, out syncXml);
                    if (errorMessage.Length != 0)
                    {
                        return(errorMessage);
                    }

                    // 3) Send sync XML to Cloud Server.  Cloud server returns a list of logs and audit data which have occurred since the last update.
                    errorMessage = AcsSyncHelper.SyncAcsServer(host, syncXml);
                    if (errorMessage.Length != 0)
                    {
                        return(errorMessage);
                    }

                    // 4) Insert logs/audit data into Cloud Master.
                    // Run out of time - future task
                }
            }

            return(errorMessage);
        }
Пример #5
0
        public static string TryGetExportSyncXml(int fromVersion, int masterVersion, out string syncXml)
        {
            SyncModel syncModel = new SyncModel();

            // The current data version
            syncModel.FromDataVersion = fromVersion;
            syncModel.ToDataVersion   = masterVersion;

            // Get the store DAO
            IStoreDAO storeDao = AndroAdminDataAccessFactory.GetStoreDAO();
            // Get the partner DAO
            IPartnerDAO partnerDao = AndroAdminDataAccessFactory.GetPartnerDAO();
            // Get the store payment provider DAO
            IStorePaymentProviderDAO storePaymentProviderDao = AndroAdminDataAccessFactory.GetStorePaymentProviderDAO();

            //get the list of hosts, host types and connections based on version.
            //var a = AndroAdminDataAccessFactory.gethost

            if (SyncHelper.ConnectionStringOverride != null)
            {
                storeDao.ConnectionStringOverride   = SyncHelper.ConnectionStringOverride;
                partnerDao.ConnectionStringOverride = SyncHelper.ConnectionStringOverride;
                storePaymentProviderDao.ConnectionStringOverride = SyncHelper.ConnectionStringOverride;
            }

            AndroAdminSyncHelper.AddInStoreUpdates(storeDao, syncModel, fromVersion);

            AndroAdminSyncHelper.AddInPartnerUpdates(partnerDao, storeDao, syncModel, fromVersion);

            AndroAdminSyncHelper.AddInStorePaymentProviders(storePaymentProviderDao, syncModel, fromVersion);

            AndroAdminSyncHelper.AddInHubTasks(syncModel, fromVersion);

            //Menu updates as pushed on by MyAndromeda.
            AndroAdminSyncHelper.AddinMenuUpdates(syncModel, fromVersion);

            //Host V2 changes
            AndroAdminSyncHelper.AddInHostV2List(syncModel, fromVersion);

            AndroAdminSyncHelper.AddInStoreDevices(syncModel, fromVersion);
            // Serialize the sync model to XML

            ////add delivery areas to sync model
            //AndroAdminSyncHelper.AddDeliveryAreas(syncModel, fromVersion);

            //add postcodeSectors to sync model
            AndroAdminSyncHelper.AddPostCodeSectors(syncModel, fromVersion);

            AndroAdminSyncHelper.AddLoyalty(syncModel, fromVersion);

            syncXml = SerializeHelper.Serialize <SyncModel>(syncModel);

            return(string.Empty);
        }
Пример #6
0
        /// <summary>
        /// Must be called from the cloud signPost master.  Syncs cloud SignPost master with all cloud signpost servers
        /// </summary>
        public static string ServerSync()
        {
            // Get the current data version
            string toVersionString = string.Empty;

            AndroAdminDataAccessFactory.GetSettingsDAO().GetByName("DataVersion", out toVersionString);

            int toVersion = 0;

            if (!int.TryParse(toVersionString, out toVersion))
            {
                return("Internal error");
            }

            // Get the signpost server names
            string signpostServerList = ConfigurationManager.AppSettings["SignPostServers"];

            string[] signpostServers = signpostServerList.Split(',');

            string errorMessage = string.Empty;

            foreach (string signpostServer in signpostServers)
            {
                // 1) Ask the server for it's current data version
                int signpostServerDataVersion = -1;
                errorMessage = SignpostServerSync.GetSignpostServerDataVersion(signpostServer, out signpostServerDataVersion);

                if (errorMessage.Length == 0)
                {
                    // 2) Generate a block of JSON that contains the sync data
                    string exportJson = string.Empty;

                    errorMessage = SignpostServerSync.GenerateExportJson(signpostServerDataVersion, out exportJson);
                    if (errorMessage.Length != 0)
                    {
                        return(errorMessage);
                    }

                    // 3) Send sync XML to signpost server
                    errorMessage = SignpostServerSync.DoSync(signpostServer, exportJson);
                    if (errorMessage != null && errorMessage.Length != 0)
                    {
                        return(errorMessage);
                    }

                    // 4) Insert logs/audit data into Cloud Master.
                    // Run out of time - future task
                }
            }

            return(errorMessage);
        }
Пример #7
0
        private static void AddInHubTasks(SyncModel syncModel, int fromVersion)
        {
            //get the hub and site-hub data services
            IHubDataService      hubDataDao       = AndroAdminDataAccessFactory.GetHubDAO();
            IStoreHubDataService storeHubDataDao  = AndroAdminDataAccessFactory.GetSiteHubDAO();
            IHubResetDataService storeHubResetDao = AndroAdminDataAccessFactory.GetHubResetDAO();

            var signalRHubs = hubDataDao.GetAfterDataVersion(fromVersion);

            var activeHubs   = signalRHubs.Where(e => !e.Removed && e.Active).ToList();
            var inactiveHubs = signalRHubs.Where(e => e.Removed || !e.Active).ToList();
            var resets       = storeHubResetDao.GetStoresToResetAfterDataVersion(fromVersion);

            syncModel.HubUpdates = new CloudSyncModel.Hubs.HubUpdates()
            {
                ActiveHubList = activeHubs.Select(e => new CloudSyncModel.Hubs.HubHostModel()
                {
                    Id       = e.Id,
                    Url      = e.Address,
                    SiteHubs = storeHubDataDao.GetSitesUsingHub(e.Id).Select(s => new CloudSyncModel.Hubs.SiteHubs()
                    {
                        HubId = e.Id, ExternalId = s.StoreExternalId
                    }).ToList()
                }).ToList(),
                InActiveHubList = inactiveHubs.Select(e => new CloudSyncModel.Hubs.HubHostModel()
                {
                    Id       = e.Id,
                    Url      = e.Address,
                    SiteHubs = new List <CloudSyncModel.Hubs.SiteHubs>()//empty list as the tables will enforce the dropping related rows
                }).ToList(),
                SiteHubHardwareKeyResets = resets.Select(e => new CloudSyncModel.Hubs.SiteHubReset()
                {
                    AndromedaSiteId = e.AndromedaSiteId,
                    ExternalSiteId  = e.ExternalSiteId
                }).ToList()
            };
        }
Пример #8
0
        private static string GenerateExportJson(int fromDataVersion, out string exportJson)
        {
            string error = "";

            exportJson = "";
            int    toDataVersion = -1;
            string settingValue  = "";

            // Get the current data version
            error = AndroAdminDataAccessFactory.GetSettingsDAO().GetByName("DataVersion", out settingValue);

            if (String.IsNullOrEmpty(error))
            {
                if (!int.TryParse(settingValue, out toDataVersion))
                {
                    error = "Version setting is not a number: " + settingValue;
                }
            }
            SignpostSync signpostSync = null;

            if (String.IsNullOrEmpty(error))
            {
                List <SignpostACSApplication> signpostACSApplications = new List <SignpostACSApplication>();

                // Get the acs applications that have changed since the last sync
                IList <ACSApplication> acsApplications = AndroAdminDataAccessFactory.GetACSApplicationDAO().GetDataBetweenVersions(fromDataVersion, toDataVersion);

                signpostSync = new SignpostSync()
                {
                    fromVersion = fromDataVersion,
                    toVersion   = toDataVersion
                };

                foreach (ACSApplication acsApplication in acsApplications)
                {
                    // Get the sites for the acs application
                    IList <int> siteIds = AndroAdminDataAccessFactory.GetACSApplicationDAO().GetSites(acsApplication.Id);

                    // Put together the ACS application data
                    SignpostACSApplication signpostACSApplication = new SignpostACSApplication()
                    {
                        id = acsApplication.Id,
                        acsApplicationSites   = siteIds,
                        environmentId         = acsApplication.EnvironmentId,
                        externalApplicationId = acsApplication.ExternalApplicationId,
                        name = acsApplication.Name
                    };

                    signpostSync.acsApplicationSyncs.Add(signpostACSApplication);
                }
            }

            if (String.IsNullOrEmpty(error))
            {
                if (signpostSync != null)
                {
                    exportJson = JsonConvert.SerializeObject(signpostSync);
                }
            }

            return(error);
        }