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(); } }
public void Push(ApiCall call) { var sitedb = call.WebSite.SiteDb(); var setting = sitedb.SyncSettings.Get(call.ObjectId); if (setting == null) { throw new Exception(Data.Language.Hardcoded.GetValue("Setting not found", call.Context)); } verifysite(setting.RemoteServerUrl, setting.RemoteWebSiteId, call.Context.User.UserName, call.Context.User.PasswordHash.ToString()); string ApiReceiveUrl = "/_api/receiver/push"; string serveapiurl = setting.RemoteServerUrl; if (!serveapiurl.ToLower().StartsWith("http")) { serveapiurl = "http://" + serveapiurl; } serveapiurl = Kooboo.Lib.Helper.UrlHelper.Combine(serveapiurl, ApiReceiveUrl); string json = call.GetValue("logids"); List <long> ids = new List <long>(); bool DirectSubmit = false; try { ids = Lib.Helper.JsonHelper.Deserialize <List <long> >(json); if (ids.Count() < 5) { DirectSubmit = true; } } catch (Exception ex) { throw new Exception(ex.Message); } bool hasqueue = false; Kooboo.Sites.TaskQueue.TaskExecutor.PostSyncObjectTask executor = new Sites.TaskQueue.TaskExecutor.PostSyncObjectTask(); string username = call.Context.User.UserName; string password = Data.Service.UserLoginService.GetUserPassword(call.Context.User); foreach (var item in ids) { var eachsync = SyncService.Prepare(sitedb, item); PostSyncObject postobject = new PostSyncObject(); postobject.SyncObject = eachsync; postobject.RemoteSiteId = setting.RemoteWebSiteId; postobject.RemoteUrl = serveapiurl; postobject.UserName = username; postobject.Password = password; postobject.RemoteSiteId = setting.RemoteWebSiteId; if (DirectSubmit) { if (!executor.Execute(sitedb, Lib.Helper.JsonHelper.Serialize(postobject))) { Sites.TaskQueue.QueueManager.Add(postobject, call.WebSite.Id); hasqueue = true; } } else { Sites.TaskQueue.QueueManager.Add(postobject, call.WebSite.Id); hasqueue = true; } sitedb.Synchronization.AddOrUpdate(new Synchronization { SyncSettingId = setting.Id, StoreName = eachsync.StoreName, ObjectId = eachsync.ObjectId, In = false, Version = item }); } if (hasqueue) { System.Threading.Tasks.Task.Run(() => Sites.TaskQueue.QueueManager.Execute(call.WebSite.Id)); } }