private static Task <PullResult> SkipPull() { var tsc = new TaskCompletionSource <PullResult>(); tsc.TrySetResult(PullResult.Ok(new List <Message>())); return(tsc.Task); }
public Reading(PullResult pr, DateTime date) { bikeCount = pr.Docked; dockCount = pr.Empty; active = ((pr.Installed == true) && (pr.Locked == false)); this.date = date.ToString(); }
private static Task <PullResult> ErrorTask(Exception e) { var tsc = new TaskCompletionSource <PullResult>(); tsc.TrySetResult(PullResult.Err(e, "error")); return(tsc.Task); }
/// <summary>从指定队列拉取消息</summary> /// <param name="mq"></param> /// <param name="offset"></param> /// <param name="maxNums"></param> /// <param name="msTimeout"></param> /// <returns></returns> public PullResult Pull(MessageQueue mq, Int64 offset, Int32 maxNums, Int32 msTimeout = -1) { var header = new PullMessageRequestHeader { ConsumerGroup = Group, Topic = Topic, QueueId = mq.QueueId, QueueOffset = offset, MaxMsgNums = maxNums, SysFlag = 6, SubVersion = StartTime.ToLong(), }; if (msTimeout >= 0) { header.SuspendTimeoutMillis = msTimeout; } var st = _Queues.FirstOrDefault(e => e.Queue == mq); if (st != null) { header.CommitOffset = st.CommitOffset; } var dic = header.GetProperties(); var bk = GetBroker(mq.BrokerName); var rs = bk.Invoke(RequestCode.PULL_MESSAGE, null, dic, true); if (rs?.Header == null) { return(null); } var pr = new PullResult(); if (rs.Header.Code == 0) { pr.Status = PullStatus.Found; } else if (rs.Header.Code == (Int32)ResponseCode.PULL_NOT_FOUND) { pr.Status = PullStatus.NoNewMessage; } else if (rs.Header.Code == (Int32)ResponseCode.PULL_OFFSET_MOVED) { pr.Status = PullStatus.OffsetIllegal; } pr.Read(rs.Header?.ExtFields); // 读取内容 if (rs.Body != null && rs.Body.Length > 0) { pr.Messages = MessageExt.ReadAll(rs.Body).ToArray(); } return(pr); }
public static void OpenRepo() { Git repository = Git.Open(@"C:\Git\NGit"); // Fetch changes without merging them NGit.Transport.FetchResult fetch = repository.Fetch().Call(); // Pull changes (will automatically merge/commit them) PullResult pull = repository.Pull().Call(); // Get the current branch status Status status = repository.Status().Call(); // The IsClean() method is helpful to check if any changes // have been detected in the working copy. I recommend using it, // as NGit will happily make a commit with no actual file changes. bool isClean = status.IsClean(); // You can also access other collections related to the status System.Collections.Generic.ICollection<string> added = status.GetAdded(); System.Collections.Generic.ICollection<string> changed = status.GetChanged(); System.Collections.Generic.ICollection<string> removed = status.GetRemoved(); // Clean our working copy System.Collections.Generic.ICollection<string> clean = repository.Clean().Call(); // Add all files to the stage (you could also be more specific) NGit.Dircache.DirCache add = repository.Add().AddFilepattern(".").Call(); // Remove files from the stage NGit.Dircache.DirCache remove = repository.Rm().AddFilepattern(".gitignore").Call(); }
/// <summary>从指定队列拉取消息</summary> /// <param name="mq"></param> /// <param name="offset"></param> /// <param name="maxNums"></param> /// <returns></returns> public PullResult Pull(MessageQueue mq, Int64 offset, Int32 maxNums) { var header = new PullMessageRequestHeader { ConsumerGroup = Group, Topic = Topic, QueueId = mq.QueueId, QueueOffset = offset, MaxMsgNums = maxNums, SysFlag = 6, }; var dic = header.GetProperties(); var bk = GetBroker(mq.BrokerName); var rs = bk.Invoke(RequestCode.PULL_MESSAGE, null, dic); var pr = new PullResult { Status = PullStatus.Found, }; pr.Read(rs.Header.ExtFields); return(pr); }
/// <summary>拉取到一批消息</summary> /// <param name="queue"></param> /// <param name="result"></param> /// <returns></returns> protected virtual Boolean Consume(MessageQueue queue, PullResult result) { if (OnConsume != null) { return(OnConsume(queue, result.Messages)); } return(true); }
public static bool AddPullData(XContainer xc, List<Station> stationList) { try { string LastUpdate = xc.Element("stations").Attribute("lastUpdate").Value; CaBiDataContext dc = new CaBiDataContext(); if ((from p in dc.Pulls where p.DateSignature == LastUpdate select p).Count<Pull>() == 0) { Pull p = new Pull(); p.DateSignature = LastUpdate; p.PullDate = DateTime.Now; dc.Pulls.InsertOnSubmit(p); dc.SubmitChanges(); int pullID = (from pid in dc.Pulls where pid.DateSignature == LastUpdate select pid.PullID).First<int>(); foreach (Station s in stationList) { if ((from ps in dc.PulledStations where ps.StationID == s.id select ps).Count<PulledStation>() == 0) { CaBiDataContext dcsub = new CaBiDataContext(); PulledStation ps = new PulledStation(); ps.StationID = s.id; ps.StationName = s.name; ps.Latitude = s.lat; ps.Longitude = s.lng; ps.Installed = s.installed; ps.Locked = s.locked; ps.Temporary = s.temporary; dcsub.PulledStations.InsertOnSubmit(ps); dcsub.SubmitChanges(); } PullResult pr = new PullResult(); pr.PullID = pullID; pr.StationID = s.id; pr.Docked = s.bikeCount; pr.Empty = s.dockCount; pr.Installed = s.installed; pr.Locked = s.locked; pr.Temporary = s.temporary; dc.PullResults.InsertOnSubmit(pr); } dc.SubmitChanges(); } return true; } catch { return false; } }
public static bool AddPullData(XContainer xc, List <Station> stationList) { try { string LastUpdate = xc.Element("stations").Attribute("lastUpdate").Value; CaBiDataContext dc = new CaBiDataContext(); if ((from p in dc.Pulls where p.DateSignature == LastUpdate select p).Count <Pull>() == 0) { Pull p = new Pull(); p.DateSignature = LastUpdate; p.PullDate = DateTime.Now; dc.Pulls.InsertOnSubmit(p); dc.SubmitChanges(); int pullID = (from pid in dc.Pulls where pid.DateSignature == LastUpdate select pid.PullID).First <int>(); foreach (Station s in stationList) { if ((from ps in dc.PulledStations where ps.StationID == s.id select ps).Count <PulledStation>() == 0) { CaBiDataContext dcsub = new CaBiDataContext(); PulledStation ps = new PulledStation(); ps.StationID = s.id; ps.StationName = s.name; ps.Latitude = s.lat; ps.Longitude = s.lng; ps.Installed = s.installed; ps.Locked = s.locked; ps.Temporary = s.temporary; dcsub.PulledStations.InsertOnSubmit(ps); dcsub.SubmitChanges(); } PullResult pr = new PullResult(); pr.PullID = pullID; pr.StationID = s.id; pr.Docked = s.bikeCount; pr.Empty = s.dockCount; pr.Installed = s.installed; pr.Locked = s.locked; pr.Temporary = s.temporary; dc.PullResults.InsertOnSubmit(pr); } dc.SubmitChanges(); } return(true); } catch { return(false); } }
static void Main(string[] args) { Random rnd = new Random(); SiaqodbConfigurator.SetDocumentSerializer(new MyJsonSerializer()); SiaqodbConfigurator.SetSyncableBucket("invoices", true); Sqo.SiaqodbConfigurator.SetLicense(@"put your license"); try { using (Siaqodb siaqodb = new Siaqodb(@"c:\DATA\")) { IBucket bucket = siaqodb.Documents["invoices"]; Invoice inv = new Invoice { CustomerName = "My Company", InvoiceDate = DateTime.Now, Total = 2390 }; Document document = new Document(); document.Key = "InVoice-" + rnd.Next(); document.SetContent <Invoice>(inv); bucket.Store(document); using (SiaqodbSync syncContext = new SiaqodbSync("http://localhost:11735/v0/", "97c7835153fd66617fad7b43f4000647", "4362kljh63k4599hhgm")) { //pull(which will trigger also push) will upload and than download changes to/from cloud/server PullResult syncResult = syncContext.Pull(bucket); if (syncResult.Error != null) { Console.WriteLine("Error downloading changes:" + syncResult.Error.Message); } else { Console.WriteLine("Sync finished!"); Console.WriteLine("Uploaded:" + syncResult.PushResult.SyncStatistics.TotalUploads + " documents!"); Console.WriteLine("Downloaded:" + syncResult.SyncStatistics.TotalDownloads + " documents!"); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
public PullResult Pull(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)); } long currentRemoteVersion = call.GetValue <long>("senderVersion"); if (currentRemoteVersion <= 0) { currentRemoteVersion = sitedb.Synchronization.GetLastIn(setting.Id); } string ApiSendToLocalUrl = "/_api/publish/SendToClient"; string serveapiurl = setting.RemoteServerUrl; verifysite(setting.RemoteServerUrl, setting.RemoteWebSiteId, call.Context.User.UserName, call.Context.User.PasswordHash.ToString()); if (!serveapiurl.ToLower().StartsWith("http")) { serveapiurl = "http://" + serveapiurl; } serveapiurl = Kooboo.Lib.Helper.UrlHelper.Combine(serveapiurl, ApiSendToLocalUrl); Dictionary <string, string> query = new Dictionary <string, string>(); query.Add("SiteId", setting.RemoteWebSiteId.ToString()); query.Add("LastId", currentRemoteVersion.ToString()); var syncobject = Kooboo.Lib.Helper.HttpHelper.Get <SyncObject>(serveapiurl, query, call.Context.User.UserName, call.Context.User.PasswordHash.ToString()); PullResult result = new PullResult(); if (syncobject != null) { SyncService.Receive(sitedb, syncobject, setting); result.IsFinish = false; result.SenderVersion = syncobject.SenderVersion; } else { result.IsFinish = true; } return(result); }
public Task <PullResult> Pull(int expectNum, TimeSpan timeout) { if (!_pullStrategy.NeedPull()) { return(SkipPull()); } var cluster = _controller.BrokerGroupService.ConsumerGetSubjectCluster(_originSubject, _consumerGroup); if (cluster.BrokerGroups.Count == 0) { return(ErrorTask(new BrokerUnassignedException(_subject, _consumerGroup))); } var brokerGroup = _loadBalance.Select(cluster); if (brokerGroup == null) { return(ErrorTask(new NoWritableBrokerException($"{_subject}/{_consumerGroup}"))); } var request = CreatePullRequest(expectNum, timeout); return(_controller.PullMessageService.Pull(brokerGroup, request).ContinueWith(task => { var response = task.Result; RefreshMetaOnDemand(response); AdjustLoadBalance(brokerGroup, expectNum, response); if (response.IsOk()) { return PullResult.Ok(RegisterAckHandler(_subject, brokerGroup.Name, (List <BaseMessage>)response.Result)); } if (response.Result is Exception ex) { return PullResult.Err(ex, response.ErrorMessage); } return PullResult.Ok(new List <Message>()); }, TaskScheduler.Default).ContinueWith(task => { // 请求成功的加权,失败的降权,避免没有消息的主题一直空拉阻塞降低效率 _pullStrategy.Record(task.Result.Success && task.Result.Messages.Count != 0); return task.Result; })); }
public static bool reset_on_MergeConflicts(this API_NGit nGit, PullResult pullResult) { if (nGit.notNull() && pullResult.notNull()) { try { if (pullResult.GetMergeResult().GetMergeStatus() == MergeStatus.CONFLICTING) { "[API_NGit][revert_on_MergeConflicts] pull result had a conflict so going to triger a hard reset".error(); return(nGit.reset_Hard()); } } catch (Exception ex) { ex.log("[API_NGit][reset_on_MergeConflicts]"); } } return(false); }
public void UpdateLastToken(string indexId, EntityType entityType, PullResult pullResult) { var sql = $@" MERGE INTO [core_index_pull_histories] as t USING ( VALUES (@TargetEntityId, @TargetEntityType, @PullResultStr, @LastUpdated) ) AS s([TargetEntityId], [TargetEntityType], [PullResultStr], [LastUpdated]) ON t.[TargetEntityId] = s.[TargetEntityId] AND t.[TargetEntityType] = s.[TargetEntityType] WHEN NOT MATCHED THEN INSERT ( [TargetEntityId], [TargetEntityType], [PullResultStr], [LastUpdated] ) VALUES( s.[TargetEntityId], s.[TargetEntityType], s.[PullResultStr], s.[LastUpdated] ) WHEN MATCHED THEN UPDATE SET [PullResultStr] = s.[PullResultStr], [LastUpdated] = s.[LastUpdated] ;"; var affectedRows = _connection.Execute( sql, new { LastUpdated = DateTime.Now.ToUnixTimestamp(), PullResultStr = pullResult == null ? null : JsonConvert.SerializeObject(new PullResult { LastToken = pullResult.LastToken, Status = pullResult.Status }), TargetEntityId = indexId, TargetEntityType = entityType }, transaction: _transaction); }
private void attach_PullResults(PullResult entity) { this.SendPropertyChanging(); entity.PulledStation = this; }
partial void DeletePullResult(PullResult instance);
partial void UpdatePullResult(PullResult instance);
partial void InsertPullResult(PullResult instance);
private void detach_PullResults(PullResult entity) { this.SendPropertyChanging(); entity.Pull = null; }
/// <summary>从指定队列拉取消息</summary> /// <param name="mq"></param> /// <param name="offset"></param> /// <param name="maxNums"></param> /// <param name="msTimeout"></param> /// <returns></returns> public PullResult Pull(MessageQueue mq, Int64 offset, Int32 maxNums, Int32 msTimeout = -1) { // 性能埋点 using var span = Tracer?.NewSpan($"mq:{Topic}:Consume"); try { var header = new PullMessageRequestHeader { ConsumerGroup = Group, Topic = Topic, QueueId = mq.QueueId, QueueOffset = offset, MaxMsgNums = maxNums, SysFlag = 6, SubVersion = StartTime.ToLong(), }; if (msTimeout >= 0) { header.SuspendTimeoutMillis = msTimeout; } var st = _Queues.FirstOrDefault(e => e.Queue == mq); if (st != null) { header.CommitOffset = st.CommitOffset; } var dic = header.GetProperties(); var bk = GetBroker(mq.BrokerName); var rs = bk.Invoke(RequestCode.PULL_MESSAGE, null, dic, true); if (rs?.Header == null) { return(null); } var pr = new PullResult(); if (rs.Header.Code == 0) { pr.Status = PullStatus.Found; } else if (rs.Header.Code == (Int32)ResponseCode.PULL_NOT_FOUND) { pr.Status = PullStatus.NoNewMessage; } else if (rs.Header.Code == (Int32)ResponseCode.PULL_OFFSET_MOVED || rs.Header.Code == (Int32)ResponseCode.PULL_RETRY_IMMEDIATELY) { pr.Status = PullStatus.OffsetIllegal; } else { pr.Status = PullStatus.Unknown; Log.Warn("响应编号:{0} 响应备注:{1} 序列编号:{2} 序列偏移量:{3}", rs.Header.Code, rs.Header.Remark, mq.QueueId, offset); } pr.Read(rs.Header?.ExtFields); // 读取内容 var pk = rs.Payload; if (pk != null) { pr.Messages = MessageExt.ReadAll(pk).ToArray(); } return(pr); } catch (Exception ex) { span?.SetError(ex, mq); throw; } }
private static void CombatThread() { try { Logging.Write("Started combat engine"); if (ObjectManager.MyPlayer.IsMounted && !ObjectManager.MyPlayer.TravelForm) { KeyHelper.SendKey("GMount"); } MoveHelper.ReleaseKeys(); if (DefendAgainst() == null) { Logging.Write("Pulling: " + Unit.Name + " " + Unit.GUID); MoveHelper.MoveToUnit(Unit, 30); if (!Unit.TargetHostile()) { if (ObjectManager.GetAttackers.Count == 0) { PPullBlackList.Blacklist(Unit, 800, true); } } Unit.Face(); MoveHelper.ReleaseKeys(); PullResult result = Pull(); Logging.Write("Pull result: " + result); if (result.Equals(PullResult.CouldNotPull)) { PPullBlackList.Blacklist(Unit, 800, true); return; } if (PPullBlackList.IsBlacklisted(Unit)) { return; } } else { Logging.Write("Got into combat with: " + Unit.Name); Unit.TargetHostile(); Unit.Face(); } Ticker combatTimeout; if (ObjectManager.MyPlayer.Level > 10) { combatTimeout = new Ticker(20 * 1000); } else { combatTimeout = new Ticker(40 * 1000); } while (!Unit.IsDead) { _combatLoopThread = new Thread(DoCombat) { IsBackground = true }; _combatLoopThread.Name = "DoCombat"; _combatLoopThread.SetApartmentState(ApartmentState.STA); _combatLoopThread.Start(); while (_combatLoopThread.IsAlive) { Thread.Sleep(50); if (!Langs.TrainingDummy(Unit.Name) && combatTimeout.IsReady && Unit.Health > 85) { Logging.Write("Combat took to long, bugged - blacklisting"); _combatResult = CombatResult.Bugged; if (!PBlackList.IsBlacklisted(Unit)) { PBlackList.Blacklist(Unit, 1200, false); } return; } } } } catch { } }
static void Main(string[] args) { Random rnd = new Random(); Sqo.SiaqodbConfigurator.SetLicense(@"your license"); SiaqodbConfigurator.SetDocumentSerializer(new MyJsonSerializer()); SiaqodbConfigurator.SetSyncableBucket("invoices_encrypted", true); //IQrypt settings IQryptSiaqodbConfigurator.SetEncryptionChiper(IQrypt.Cipher.AES256, "myencryption_key"); IQryptSiaqodbConfigurator.EncryptDocumentContent("invoices_encrypted"); IQryptSiaqodbConfigurator.EncryptTag("customer_code", IQrypt.EncryptionType.DET, typeof(string)); try { using (Siaqodb siaqodb = new Siaqodb(@"c:\DATA\")) { IBucket bucket = siaqodb.Documents["invoices_encrypted"]; Invoice inv = new Invoice { CustomerName = "My Company", InvoiceDate = DateTime.Now, Total = 2390 }; IQryptDocument document = new IQryptDocument(); document.Key = "InVoice-" + rnd.Next(); document.SetContent <Invoice>(inv); string tagVal = "CU2323" + rnd.Next(); document.SetTag("customer_code", tagVal); bucket.Store(document); // let's run a query Query query = new Query(); query.IQryptWhereEqual("customer_code", tagVal); var q = bucket.Find(query); foreach (Document o in q) { if (o.GetTag <string>("customer_code") == tagVal) { Console.WriteLine("Query over encrypted data run!"); } } using (SiaqodbSync syncContext = new SiaqodbSync("http://localhost:11735/v0/", "97c7835153fd66617fad7b43f4000647", "4362kljh63k4599hhgm")) { //pull(which will trigger also push) will upload and than download changes to/from cloud/server PullResult syncResult = syncContext.Pull(bucket); if (syncResult.Error != null) { Console.WriteLine("Error downloading changes:" + syncResult.Error.Message); } else { Console.WriteLine("Sync finished!"); Console.WriteLine("Uploaded:" + syncResult.PushResult.SyncStatistics.TotalUploads + " documents!"); Console.WriteLine("Downloaded:" + syncResult.SyncStatistics.TotalDownloads + " documents!"); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }