Beispiel #1
0
        // Add from SiteRepositoryBase Event....
        public void AddTask(IRepository repo, ISiteObject value, ChangeType changetype)
        {
            if (repo == null || value == null)
            {
                return;
            }
            var core = value as ICoreObject;

            if (core == null)
            {
                return;
            }

            lock (_queuelocker)
            {
                PushTask task = new PushTask()
                {
                    StoreName = repo.StoreName, ObjectId = value.Id
                };

                if (changetype == ChangeType.Delete)
                {
                    task.Version  = GetJustDeltedVersion(repo, value.Id);
                    task.IsDelete = true;
                }
                else
                {
                    task.Version = core.Version;
                }
                this.AddTask(task);
            }
        }
Beispiel #2
0
        public SyncObject GetSyncObject(PushTask task)
        {
            SyncObject syncobject = null;

            if (task.IsDelete)
            {
                syncobject          = new SyncObject();
                syncobject.IsDelete = true;
                syncobject.ObjectId = task.ObjectId;
            }
            else
            {
                var repo = this.SiteDb.GetRepository(task.StoreName);
                if (repo == null)
                {
                    return(null);
                }

                var log = this.SiteDb.Log.Get(task.Version);
                if (log == null)
                {
                    return(null);
                }
                var siteobject = repo.GetByLog(log);
                syncobject = SyncObjectConvertor.ToSyncObject(siteobject);
            }

            syncobject.StoreName  = task.StoreName;
            syncobject.SenderPort = GetPort();
            return(syncobject);
        }
Beispiel #3
0
        internal void InitTask()
        {
            foreach (var item in this.SiteCluster)
            {
                var alllogs = GetLogItems(item);

                foreach (var log in alllogs.OrderBy(o => o.Id))
                {
                    PushTask task = new PushTask();
                    task.ObjectId  = this.KeyConverter.FromByte(log.KeyBytes);
                    task.IsDelete  = log.EditType == EditType.Delete;
                    task.StoreName = log.StoreName;
                    task.Version   = log.Id;
                    this.AddTask(task);
                }
            }
        }
Beispiel #4
0
        private void _Processtask()
        {
            PushTask task = PeekTask();

            if (task.Version != default(long) && task.ClusterId != default(Guid))
            {
                SyncObject syncobject = GetSyncObject(task);

                PostSyncObject postobject = new PostSyncObject()
                {
                    SyncObject = syncobject
                };

                postobject.RemoteSiteId = this.SiteDb.WebSite.Id;

                TaskQueue.TaskExecutor.PostSyncObjectTask executor = new TaskQueue.TaskExecutor.PostSyncObjectTask();

                foreach (var item in this.SiteCluster)
                {
                    postobject.RemoteUrl = ClusterUrl.Push(item);

                    try
                    {
                        if (!executor.Execute(this.SiteDb, Lib.Helper.JsonHelper.Serialize(postobject)))
                        {
                            TaskQueue.QueueManager.Add(postobject, this.SiteDb.WebSite.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        TaskQueue.QueueManager.Add(postobject, this.SiteDb.WebSite.Id);
                        // TODO: log to system log.
                    }
                }
                _Processtask();
            }
        }
Beispiel #5
0
        public void AddTask(PushTask intask)
        {
            lock (_queuelocker)
            {
                foreach (var cluster in this.SiteCluster)
                {
                    if (!this.Control.HasLock(cluster.Id, intask.ObjectId))
                    {
                        // clone a new task.
                        PushTask task = new PushTask()
                        {
                            ObjectId = intask.ObjectId, Version = intask.Version, StoreName = intask.StoreName, ClusterId = cluster.Id, IsDelete = intask.IsDelete
                        };

                        // check for each site cluster..
                        var SameItems = this.PushQueue.Where(o => o.ClusterId == task.ClusterId && o.ObjectId == task.ObjectId).ToList();
                        if (SameItems == null || SameItems.Count == 0)
                        {
                            this.PushQueue.Add(task);
                        }
                        else
                        {
                            if (task.IsDelete)
                            {
                                foreach (var item in SameItems)
                                {
                                    this.PushQueue.Remove(item);
                                }
                            }
                            this.PushQueue.Add(task);
                        }
                    }
                }
            }
            EnsureStart();
        }