Example #1
0
        public void Receive(SyncObject SyncObject, SiteCluster FromNode)
        {
            var repo = this.SiteDb.GetRepository(SyncObject.StoreName);

            if (repo == null)
            {
                return;
            }

            this.Control.LockItem(FromNode.Id, SyncObject.ObjectId);

            if (SyncObject.IsDelete)
            {
                repo.Delete(SyncObject.ObjectId);
            }
            else
            {
                var siteobject = SyncObjectConvertor.FromSyncObject(SyncObject);
                if (siteobject is ICoreObject)
                {
                    var core = siteobject as ICoreObject;
                    core.Version = -1;
                    repo.AddOrUpdate(core);
                }
            }

            this.Control.UnlockItem(FromNode.Id, SyncObject.ObjectId);
        }
Example #2
0
        public static string Push(SiteCluster cluster)
        {
            string url = "http://" + cluster.ServerIp;

            if (cluster.Port != 80)
            {
                url += ":" + cluster.Port.ToString();
            }

            url += "/_api/cluster/receive";
            return(url);
        }
Example #3
0
        public List <LogEntry> GetLogItems(SiteCluster cluster)
        {
            if (cluster == null)
            {
                return(new List <LogEntry>());
            }

            var keyconverter = ObjectContainer.GetConverter <Guid>();

            var currentlogid = cluster.Version;

            List <LogEntry> result = new List <LogEntry>();

            var alllogs = this.SiteDb.Log.Store.Where(o => o.Id > currentlogid).SelectAll();

            foreach (var item in alllogs.OrderByDescending(o => o.Id))
            {
                if (item.KeyBytes == null)
                {
                    continue;
                }
                Guid key           = keyconverter.FromByte(item.KeyBytes);
                var  currentrecord = result.Find(o => o.KeyHash == item.KeyHash);
                if (currentrecord == null)
                {
                    result.Add(item);
                }
                else
                {
                    if (item.EditType == EditType.Add)
                    {
                        if (currentrecord.EditType == EditType.Delete)
                        {
                            // new added item also get deleted at the end...==> should not push to it.
                            result.Remove(currentrecord);
                        }
                        else if (currentrecord.EditType == EditType.Update)
                        {
                            currentrecord.EditType = EditType.Add;
                        }
                    }
                }
            }
            return(result);
        }
Example #4
0
        public void Receive(SyncObject SyncObject, string ClientIp)
        {
            SiteCluster node = null;

            foreach (var item in this.SiteCluster)
            {
                if (Lib.Helper.IPHelper.IsInSameCClass(ClientIp, item.ServerIp))
                {
                    node = item;
                    break;
                }
            }

            if (node != null)
            {
                Receive(SyncObject, node);
            }
        }
Example #5
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.Global.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 = Kooboo.Data.Account.Url.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);
                }
            }
        }