Ejemplo n.º 1
0
        public ClusterEditViewModel GetNew(ApiCall call)
        {
            var user = call.Context.User;

            if (user == null)
            {
                return(null);
            }

            ClusterEditViewModel viewmodel = new ClusterEditViewModel();

            Dictionary <string, string> para = new Dictionary <string, string>();

            para.Add("SiteId", call.GetValue("SiteId"));
            para.Add("OrganizationId", user.CurrentOrgId.ToString());

            var datacenterlist = Lib.Helper.HttpHelper.Get <List <DataCenter> >(AccountUrlHelper.Cluster("GetDataCenter"), para, user.UserName, user.PasswordHash.ToString());

            viewmodel.DataCenter = datacenterlist;

            viewmodel.EnableCluster = datacenterlist.Where(o => o.IsSelected).Count() >= 2;

            viewmodel.EnableLocationRedirect = datacenterlist.Where(o => !string.IsNullOrWhiteSpace(o.PrimaryDomain)).Any();

            if (viewmodel.EnableLocationRedirect)
            {
                foreach (var item in datacenterlist.Where(o => !string.IsNullOrWhiteSpace(o.PrimaryDomain)))
                {
                    var domainresult = Kooboo.Data.Helper.DomainHelper.Parse(item.PrimaryDomain);
                    if (domainresult != null)
                    {
                        viewmodel.LocationRedirect.Add(new ClusterLocationRedirect()
                        {
                            Name = item.Name, SubDomain = domainresult.SubDomain, RootDomain = domainresult.Domain
                        });
                    }
                }
            }

            return(viewmodel);
        }
Ejemplo n.º 2
0
        public void Post(ClusterEditViewModel model, ApiCall call)
        {
            ValidatePort(call);

            var sitedb = call.Context.WebSite.SiteDb();

            Data.GlobalDb.WebSites.UpdateBoolColumn(call.Context.WebSite.Id, o => o.EnableCluster, model.EnableCluster);

            if (Data.AppSettings.IsOnlineServer)
            {
                // check and update the SiteInfo of EnableCluster.
                var siteid = call.GetValue <Guid>("SiteId");
                var user   = call.Context.User;
                if (user == null)
                {
                    throw new Exception(Data.Language.Hardcoded.GetValue("user required", call.Context));
                }
                // Set the website doamins and send to Account for update...
                // Get a list of ServerId back for sync purpose...
                string url = AccountUrlHelper.Cluster("SaveSetting") + "?SiteId=" + siteid.ToString() + "&OrganizatioinId=" + user.CurrentOrgId.ToString();

                var result = Lib.Helper.HttpHelper.Post <List <SiteClusterViewModel> >(url, Lib.Helper.JsonHelper.Serialize(model));

                if (result != null)
                {
                }
                /// var errro;
            }

            else
            {
                // local server, no need for location redirect.
                // local server does not support location redirect..
                List <SiteCluster> updates = new List <SiteCluster>();
                foreach (var item in model.DataCenter)
                {
                    if (!item.IsRoot)
                    {
                        // can not contains itself...
                        SiteCluster cluster = new SiteCluster();
                        cluster.ServerIp   = item.Ip;
                        cluster.Port       = item.Port;
                        cluster.Name       = item.DisplayName;
                        cluster.DataCenter = item.Name;
                        cluster.IsRoot     = item.IsRoot;
                        cluster.IsSelected = item.IsSelected;
                        updates.Add(cluster);
                    }
                }

                // do the delection.
                HashSet <Guid> deleteIds = new HashSet <Guid>();
                foreach (var item in sitedb.SiteCluster.All())
                {
                    var find = updates.Find(o => o.Id == item.Id);
                    if (find == null)
                    {
                        deleteIds.Add(item.Id);
                    }
                }
                foreach (var item in deleteIds)
                {
                    sitedb.SiteCluster.Delete(item);
                }

                foreach (var item in updates)
                {
                    sitedb.SiteCluster.AddOrUpdate(item);
                }
            }
        }