void Awake() { // string loadeditem = ReadJson.LoadJsonAsResource("DataForSettings/RoadData/lanes"); // Debug.Log(loadeditem); www = new WWW(url); StartCoroutine(WaitForRequest(www)); request = WebRequest.Create(url); request.ContentType = "application/json; charset=utf-8"; response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); reader = new StreamReader(dataStream); string loadeditem = reader.ReadToEnd(); // string loadeditem = www.text; Debug.Log("loaded item:" + loadeditem); oneLineCon = JsonUtility.FromJson <LineContainer>(loadeditem); foreach (LineTemplate lineSegment in oneLineCon.LineList) { DrawLine(lineSegment); } }
private static bool SaveFile(LineContainer lc, string filename) { int counter = 0; var newFileName = filename; while (true) { try { if (File.Exists(newFileName)) { return(true); } StreamWriter writer = new StreamWriter(newFileName + ".xml"); writer.Write(lc.OriginalXml); writer.Flush(); writer.Close(); return(true); } catch (Exception) { newFileName = filename + counter++; } } }
public string Solve(string input) { var splitData = input.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); var initData = splitData[0].Replace("initial state: ", ""); var rules = splitData.Skip(1).ToList(); var container = new LineContainer(initData); var rulesList = rules.Select(w => new Rule(w)).ToList(); for (var generation = 0; generation < CountGeneration; generation++) { var nextGeneration = container.Position.Select(w => w.Copy()).ToList(); //Console.WriteLine(container.Position.Aggregate("", (s, cell) => s + (cell.IsPlant ? "#" : "."))); for (var i = 2; i < container.Position.Count - 2; i++) { var prePreCell = container.Position[i - 2]; var preCell = container.Position[i - 1]; var currentCell = container.Position[i]; var nextCell = container.Position[i + 1]; var nextNextCell = container.Position[i + 2]; var rightRules = rulesList.Where(w => w.IsRight(prePreCell.IsPlant, preCell.IsPlant, currentCell.IsPlant, nextCell.IsPlant, nextNextCell.IsPlant)).ToList(); var currentRule = rightRules.FirstOrDefault(); if (currentRule != null) { nextGeneration[i].IsPlant = currentRule.Output; } } var firstIsPlant = nextGeneration.Take(InputLength).TakeWhile(w => !w.IsPlant).ToList(); if (firstIsPlant.Count < InputLength) { var first = nextGeneration.First(); for (var i = 0; i < InputLength - firstIsPlant.Count; i++) { nextGeneration.Insert(0, new Cell(first.Position - i - 1, '.')); } } var endIsPlant = nextGeneration.TakeLast(InputLength).ToList(); endIsPlant.Reverse(); endIsPlant = endIsPlant.TakeWhile(w => !w.IsPlant).ToList(); if (endIsPlant.Count < InputLength) { var last = nextGeneration.Last(); for (var i = 0; i < InputLength - endIsPlant.Count; i++) { nextGeneration.Add(new Cell(last.Position + i + 1, '.')); } } container.Position = nextGeneration; } return(container.Position.Where(w => w.IsPlant).Sum(w => w.Position).ToString()); }
private void Awake() { this.line = new LineContainer(this as ILine); if (this.keyNote.a == 0 && this.keyNote.b == 0) { throw new Exception("Value needed for keyNote"); } }
private void Register(GameLine l, int x, int y) { var key = GetCellKey(x, y); LineContainer<GameLine> cell; if (!Cells.TryGetValue(key, out cell)) { cell = new LineContainer<GameLine>(); Cells[key] = cell; } cell.AddLine(l); }
private IEnumerator Initialisation() { yield return(new WaitForEndOfFrame()); Transform[] startPositions = new Transform[mContainer.BuildInfo.SourceCount]; Transform[] endPositions = new Transform[mContainer.BuildInfo.TargetCount]; for (byte i = 0; i < mContainer.BuildInfo.SourceCount; i++) { startPositions[i] = mContainer.SourceScheme.Design.IOBase(mContainer.BuildInfo.SourceGroupName, (byte)(mContainer.BuildInfo.SourceStart + i)).ConnectionPosition; } for (byte i = 0; i < mContainer.BuildInfo.TargetCount; i++) { endPositions[i] = mContainer.TargetScheme.Design.IOBase(mContainer.BuildInfo.TargetGroupName, (byte)(mContainer.BuildInfo.TargetStart + i)).ConnectionPosition; } mLines = new LineContainer[mContainer.BuildInfo.TargetCount]; for (byte i = 0; i < mContainer.BuildInfo.TargetCount; i++) { var line = Instantiate(mLinePrefab, transform).GetComponent <LineRenderer> (); mLines[i] = new LineContainer(); mLines[i].LineRenderer = line; if (mContainer.BuildInfo.SourceCount == 1) { mLines[i].Start = startPositions[0]; line.gameObject.name = mContainer.BuildInfo.SourceStart.ToString() + " - " + (mContainer.BuildInfo.TargetStart + i).ToString(); } else { mLines[i].Start = startPositions[i]; line.gameObject.name = (mContainer.BuildInfo.SourceStart + i).ToString() + " - " + (mContainer.BuildInfo.TargetStart + i).ToString(); } mLines[i].End = endPositions[i]; } enabled = true; yield break; }
public static void SaveXml(LineContainer slc, string sline) { savingQueue.Enqueue(new LineMessage(slc, sline)); if (savingThread == null) { savingThread = new Thread(() => { while (true) { if (savingQueue.Count == 0) { Thread.Sleep(10); continue; } var linemsg = savingQueue.Dequeue(); var time = DateTime.Now; var folderPath = ConfigurationManager.AppSettings["betradar_xml_files"] + linemsg.Line + "\\" + time.Year + "_" + time.Month + "_" + time.Day + "_" + time.Hour + "_00" + "\\"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var timestamp = time.ToFileTime().ToString(); var filename = folderPath + linemsg.LineContainer.Attributes["type"] + timestamp; int index = 1; var tempfilename = filename; while (!SaveFile(linemsg.LineContainer, tempfilename)) { tempfilename = filename + " " + index++; } } }); savingThread.Start(); } }
public static LineContainer ToMetaDataLineContainer(DictionaryOfLineObjectCollection diAll) { dynamic lc = new LineContainer(); LineObjectCollectionToSerializableObjectList <TaggedStringLn>(lc, diAll); LineObjectCollectionToSerializableObjectList <TimeTypeLn>(lc, diAll); LineObjectCollectionToSerializableObjectList <ScoreTypeLn>(lc, diAll); LineObjectCollectionToSerializableObjectList <BetTypeLn>(lc, diAll); LineObjectCollectionToSerializableObjectList <BetDomainTypeLn>(lc, diAll); //LineObjectCollectionToSerializableObjectList<GroupLn>(lc, diAll); LineObjectCollectionToSerializableObjectList <CompetitorLn>(lc, diAll); //LineObjectCollectionToSerializableObjectList<MatchLn>(lc, diAll); //LineObjectCollectionToSerializableObjectList<LiveMatchInfoLn>(lc, diAll); //LineObjectCollectionToSerializableObjectList<MatchResultLn>(lc, diAll); //LineObjectCollectionToSerializableObjectList<MatchToGroupLn>(lc, diAll); //LineObjectCollectionToSerializableObjectList<BetDomainLn>(lc, diAll); //LineObjectCollectionToSerializableObjectList<OddLn>(lc, diAll); return(lc); }
public LineContainer<GameLine> LinesInRect(DoubleRect rect) { int starty = (int)Math.Floor(rect.Top / CellSize); int startx = (int)Math.Floor(rect.Left / CellSize); int endy = (int)Math.Floor((rect.Top + rect.Height) / CellSize); int endx = (int)Math.Floor((rect.Left + rect.Width) / CellSize); LineContainer<GameLine> ret = new LineContainer<GameLine>(); using (Sync.AcquireWrite()) { for (int x = startx; x <= endx; x++) { for (int y = starty; y <= endy; y++) { var cell = GetCell(x, y); if (cell != null) { ret.Combine(cell); } } } } return ret; }
private static void LineObjectCollectionToSerializableObjectList <T>(LineContainer lc, ILineObjectCollection <T> locObjects) where T : ILineObject <T> { string sObjectListName = LineContainer.ContentTypeToObjectListName(typeof(T)); SyncList <T> lObjects = locObjects.ToSyncList(); SerializableObjectList lSerializableObjects = lc.Objects.EnsureSerializableObjectList(typeof(T), sObjectListName); foreach (T objSource in lObjects) { try { ISerializableObject so = objSource.Serialize(); lSerializableObjects.Add(so); } catch (Exception excp) { m_logger.Excp(excp, "ToLineContainer() ERROR. Could not add serializable object for {0}", objSource); } } Thread.Sleep(1); }
internal override void InterFormatLink(string prePipeCode, bool isSelf = false) { if (!string.IsNullOrEmpty(prePipeCode)) { var links = LineContainer.GetLinkDics(); var linkKey = string.Concat(prePipeCode, "_", PipeCode); if (links.ContainsKey(linkKey)) { return; } links.Add(linkKey,new PipeLink() { pre_pipe_code = prePipeCode, pipe_code = PipeCode }); } if (NextPipe == null || Equals(LineContainer.EndPipe)) return ; NextPipe.InterFormatLink(PipeCode,false); }
private static void WorkerThread(ThreadContext tc) { while (m_bRunning) //(!m_bImportError) { try { int counter = 0; int iLiveQueueCount = m_sqMessages.Count; if (!m_liveClient.IsAlive) { m_sqMessages.Clear(); } else if (iLiveQueueCount > 0) { while (m_sqMessages.Count > 0) { counter++; LineContainer lc = m_sqMessages.Dequeue(); eFileSyncResult fsr = eFileSyncResult.Failed; Debug.Assert(lc != null); try { string sSrcTime = lc.Attributes["srctime"]; DateTimeSr dtSrcTime = DateTimeSr.FromString(sSrcTime); string sSrcDelay = (DateTime.UtcNow - dtSrcTime.UtcDateTime).ToString(); string sTime = lc.Attributes["time"]; DateTimeSr dt = DateTimeSr.FromString(sTime); TimeSpan ts = DateTime.UtcNow - dt.UtcDateTime; string sType = lc.Attributes.ContainsKey("line") ? lc.Attributes["line"] : "none"; m_logger.InfoFormat("Queue={0} Delay={1} Size={2}", iLiveQueueCount, ts, lc.OriginalXml.Length); if (ConfigurationManager.AppSettings["betradar_xml_files"] != null) { SaveXml(lc, "Live"); } fsr = LineSr.SyncRoutines(eUpdateType.LiveBet, string.Format("Host='{0}' Connected={1}; SrcDelay={2}; Delay={3}; Line={4}", m_sHost, DateTime.Now - m_dtConnected, sSrcDelay, ts, sType), DalStationSettings.Instance.UseDatabaseForLiveMatches, null, delegate(object objParam) { return(ProviderHelperNew.MergeFromLineContainer(lc)); }); } catch (Exception excp) { fsr = eFileSyncResult.Failed; m_logger.Excp(excp, "WorkerThread() ERROR for {0}", lc); } if (fsr == eFileSyncResult.Failed) { m_liveClient.Disconnect(); RemoveLiveMatches(eServerSourceType.BtrPre); RemoveLiveMatches(eServerSourceType.BtrLive); } } LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.LiveBet, string.Format("liveUpdate {0} messages", counter)); } } catch (Exception excp) { m_logger.Excp(excp, "WorkerThread() general ERROR"); } Thread.Sleep(10); } }
private static void ReaderThread(ThreadContext tc) { RemoveLiveMatches(eServerSourceType.BtrPre); RemoveLiveMatches(eServerSourceType.BtrLive); DateTime dtLastReceived = DateTime.Now; bool bDisabled = false; bool bRemoved = false; var lineReseiveCopy = ""; while (m_bRunning && !tc.IsToStop) { m_dtConnected = DateTime.Now; try { string sServerMessage = ""; while (m_bRunning && !tc.IsToStop && m_liveClient.IsAlive) { lineReseiveCopy = LinesToReceive; //if (m_liveClient.HaveData) sServerMessage = m_liveClient.ReadLine(); ExcpHelper.ThrowIf(string.IsNullOrEmpty(sServerMessage), "Received Empty Message"); m_logger.Debug("received live message " + sServerMessage.Length); m_liveClient.WriteLine(lineReseiveCopy); if (sServerMessage == LIVEBET_MSG_HELLO || sServerMessage == LIVEBET_MSG_EMPTY) { m_logger.DebugFormat("Received '{0}'", sServerMessage); dtLastReceived = DateTime.Now; LineSr.LiveBetConnected = true; } else { try { var originalLength = sServerMessage.Length; if (sServerMessage.StartsWith(COMPRESSED)) { string sPrefix = sServerMessage.Substring(0, COMPRESSED_MASK_SIZE); string sSize = sPrefix.Substring(COMPRESSED.Length); int iCompressedMessageSize = 0; bool bSizeParsed = int.TryParse(sSize, out iCompressedMessageSize); Debug.Assert(bSizeParsed && iCompressedMessageSize > 0); //Debug.Assert(iCompressedMessageSize + COMPRESSED_MASK_SIZE == sServerMessage.Length); sServerMessage = TextUtil.DecompressBase64String(sServerMessage.Substring(COMPRESSED_MASK_SIZE)); } int startIndex = sServerMessage.IndexOf('<'); ExcpHelper.ThrowIf(startIndex < 0, "Cannot find start xml point '<'"); sServerMessage = sServerMessage.Substring(startIndex); TimeSpan tsDuration = DateTime.Now - m_dtConnected; LineContainer lc = LineContainer.FromXml(sServerMessage); ExcpHelper.ThrowIf <NullReferenceException>(lc == null, "LineContainer is Null"); //lc.Duration = tsDuration; m_sqMessages.Enqueue(lc); int iQueueCount = m_sqMessages.Count; ExcpHelper.ThrowIf(iQueueCount > DalStationSettings.Instance.LiveErrorQueueSize, "Live Client Queue size ({0}) is too big.", iQueueCount); if (iQueueCount > DalStationSettings.Instance.LiveWarnQueueSize) { m_logger.Warn("Live Client Queue size = " + iQueueCount); } dtLastReceived = DateTime.Now; bDisabled = false; bRemoved = false; string sType = lc.Attributes.ContainsKey("line") ? lc.Attributes["line"] : "none"; m_logger.DebugFormat("Enqueueing message {0} (Total messages in queue {1}; Connected {2}; Duration {3},type {4},length {5},compressedLength {6})", lc.GetDocId(), m_sqMessages.Count, m_dtConnected, tsDuration, sType, sServerMessage.Length, originalLength); } catch (Exception excp) { m_logger.Warn(ExcpHelper.FormatException(excp, "Could not process incoming server message (Size={0})", sServerMessage.Length)); throw; } } LineSr.LiveBetConnected = true; Thread.Sleep(10); } } catch (Exception excp) { m_logger.Error(excp.Message, excp); m_sqMessages.Clear(); m_logger.Excp(excp, "Connection to server lost after importing time ({0}) ms bacause of {1}", DateTime.Now - m_dtConnected, excp.GetType()); LineSr.LiveBetConnected = false; } if (dtLastReceived + LIVE_TIME_OUT_TO_DISABLE < DateTime.Now && !bDisabled) { LineSr.SyncRoutines(eUpdateType.LiveBet, "Connection lost. SportRadar LiveMarket is disabled.", DalStationSettings.Instance.UseDatabaseForLiveMatches, null, delegate(object obj) { LineSr.Instance.DisableLiveMatches(eServerSourceType.BtrLive); return(false); }); LineSr.ProcessDataSqlUpdateSucceeded(eUpdateType.LiveBet, "Connection lost. SportRadar LiveMarket is cleared."); bDisabled = true; } else if (dtLastReceived + LIVE_TIME_OUT_TO_REMOVE < DateTime.Now && !bRemoved) { m_logger.ErrorFormat("Removing all live matches because last message ('{0}') were too long time ago (TimeOut='{1}')", new Exception(), dtLastReceived, LIVE_TIME_OUT_TO_REMOVE); RemoveLiveMatches(eServerSourceType.BtrPre); RemoveLiveMatches(eServerSourceType.BtrLive); bRemoved = true; } Thread.Sleep(10); EnsureConnection(); } }
public static bool MergeFromLineContainer(LineContainer lc) { CheckTime ct = new CheckTime(false, "MergeFromLineContainer() entered"); long lOperationMask = 0L; eServerSourceType esst = eServerSourceType.BtrPre; if (lc.Attributes.ContainsKey("line")) { string sLine = lc.Attributes["line"]; ExcpHelper.ThrowIf(!Enum.TryParse(sLine, true, out esst), "Cannot parse LineType from '{0}'", sLine); } string sType = lc.Attributes["type"]; string sMessageId = lc.Attributes["messageid"]; try { /* * sTrace += string.Format("{0} docid={1}\r\n", sTrace, sMessageId); * * if (bExtendTrace) * { * sTrace += lc.BuildTraceString(); * } */ // TimeTypeLn { TimeTypeDictionary ttd = LineSr.Instance.AllObjects.GetLineObjectCollection <TimeTypeLn>() as TimeTypeDictionary; int iCount = LineSr.MergeLineObjects <TimeTypeLn>(lc, ttd, new LineSr.MergeLineObjectsCallBack <TimeTypeLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>; return(ttd.GetObject(spTag.Value)); }, CreateLineObject = delegate() { return(new TimeTypeLn()); } }); ct.AddEvent("TimeType(s) Succeeded ({0})", iCount); } // ScoreTypeLn { ScoreTypeDictionary std = LineSr.Instance.AllObjects.GetLineObjectCollection <ScoreTypeLn>() as ScoreTypeDictionary; int iCount = LineSr.MergeLineObjects <ScoreTypeLn>(lc, std, new LineSr.MergeLineObjectsCallBack <ScoreTypeLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>; return(std.GetObject(spTag.Value)); }, CreateLineObject = delegate() { return(new ScoreTypeLn()); } }); ct.AddEvent("ScoreType(s) Succeeded ({0})", iCount); } // BetTypeLn { BetTypeDictionary btd = LineSr.Instance.AllObjects.GetLineObjectCollection <BetTypeLn>() as BetTypeDictionary; int iCount = LineSr.MergeLineObjects <BetTypeLn>(lc, btd, new LineSr.MergeLineObjectsCallBack <BetTypeLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>; return(btd.GetObject(spTag.Value)); }, CreateLineObject = delegate() { return(new BetTypeLn()); } }); ct.AddEvent("BetType(s) Succeeded ({0})", iCount); } // BetDomainTypeLn { BetDomainTypeDictionary bdtd = LineSr.Instance.AllObjects.GetLineObjectCollection <BetDomainTypeLn>() as BetDomainTypeDictionary; int iCount = LineSr.MergeLineObjects <BetDomainTypeLn>(lc, bdtd, new LineSr.MergeLineObjectsCallBack <BetDomainTypeLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <string> spTag = so.GetSerializableProperty("Tag") as SerializableProperty <string>; return(bdtd.GetObject(spTag.Value)); }, CreateLineObject = delegate() { return(new BetDomainTypeLn()); } }); ct.AddEvent("BetDomainType(s) Succeeded ({0})", iCount); } // Groups { GroupDictionary gd = LineSr.Instance.AllObjects.GetLineObjectCollection <GroupLn>() as GroupDictionary; int iCount = LineSr.MergeLineObjects <GroupLn>(lc, gd, new LineSr.MergeLineObjectsCallBack <GroupLn>() { GetLineObject = delegate(ISerializableObject so) { // 143881406612 SerializableProperty <string> spType = so.GetSerializableProperty("Type") as SerializableProperty <string>; SerializableProperty <long> spSvrId = so.GetSerializableProperty("SvrGroupId") as SerializableProperty <long>; Debug.Assert(spType != null); Debug.Assert(spSvrId != null); return(gd.SafelyGetGroupByKeyName(spType.Value, spSvrId.Value)); }, CreateLineObject = delegate() { return(new GroupLn()); } }); ct.AddEvent("Group(s) Succeeded ({0})", iCount); } // Competitors { CompetitorDictionary cd = LineSr.Instance.AllObjects.GetLineObjectCollection <CompetitorLn>() as CompetitorDictionary; int iCount = LineSr.MergeLineObjects <CompetitorLn>(lc, cd, new LineSr.MergeLineObjectsCallBack <CompetitorLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spCompetitor = so.GetSerializableProperty("CompetitorId") as SerializableProperty <long>; Debug.Assert(spCompetitor != null); return(cd.GetObject(spCompetitor.Value)); }, CreateLineObject = delegate() { return(new CompetitorLn()); } }); ct.AddEvent("Competitor(s) Succeeded ({0})", iCount); } // CompetitorToOutrightLn { var cd = LineSr.Instance.AllObjects.GetLineObjectCollection <CompetitorToOutrightLn>() as CompetitorToOutrightDictionary; int iCount = LineSr.MergeLineObjects <CompetitorToOutrightLn>(lc, cd, new LineSr.MergeLineObjectsCallBack <CompetitorToOutrightLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spCompetitor = so.GetSerializableProperty("match2competitorid") as SerializableProperty <long>; Debug.Assert(spCompetitor != null); return(cd.GetObject(spCompetitor.Value)); }, CreateLineObject = delegate() { return(new CompetitorToOutrightLn()); } }); ct.AddEvent("Competitor(s) Succeeded ({0})", iCount); } // Strings { TaggedStringDictionary tsd = LineSr.Instance.AllObjects.GetLineObjectCollection <TaggedStringLn>() as TaggedStringDictionary; int iCount = LineSr.MergeLineObjects <TaggedStringLn>(lc, tsd, new LineSr.MergeLineObjectsCallBack <TaggedStringLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spStringId = so.GetSerializableProperty("StringId") as SerializableProperty <long>; return(tsd.GetObject(spStringId.Value)); }, CreateLineObject = delegate() { return(new TaggedStringLn()); } }); ct.AddEvent("String(s) Succeeded ({0})", iCount); } SyncList <MatchLn> lMatchesToRemove = new SyncList <MatchLn>(); // Matches { SyncHashSet <long> lMatchIds = new SyncHashSet <long>(); MatchDictionary md = LineSr.Instance.AllObjects.GetLineObjectCollection <MatchLn>() as MatchDictionary; int iCount = LineSr.MergeLineObjects <MatchLn>(lc, md, new LineSr.MergeLineObjectsCallBack <MatchLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spMatchId = so.GetSerializableProperty("MatchId") as SerializableProperty <long>; lMatchIds.Add(spMatchId.Value); return(md.GetObject(spMatchId.Value)); }, CreateLineObject = delegate() { return(new MatchLn()); }, OnLineObjectMerged = delegate(MatchLn match) { if (match != null) { if (match.Code.Value == 0) { match.Code.Value = Math.Abs((int)(match.MatchId % 100000)); } if (match.EndDate.Value == null) { match.EndDate.Value = new DateTimeSr(DateTime.MaxValue); } } }, RemoveLineObject = delegate(MatchLn match) { lMatchesToRemove.Add(match); } }, ref lOperationMask); if (sType.ToLowerInvariant() == "initial") { SyncList <MatchLn> lAllLiveMatches = LineSr.Instance.QuickSearchMatches(delegate(MatchLn match) { return(match.IsLiveBet.Value && match.SourceType == esst); }); foreach (var match in lAllLiveMatches) { if (!lMatchIds.Contains(match.MatchId)) { lMatchesToRemove.Add(match); } } } ct.AddEvent("Match(es) Succeeded ({0})", iCount); } // MatchToGroup items { MatchToGroupDictionary mtogd = LineSr.Instance.AllObjects.GetLineObjectCollection <MatchToGroupLn>() as MatchToGroupDictionary; int iCount = LineSr.MergeLineObjects <MatchToGroupLn>(lc, mtogd, new LineSr.MergeLineObjectsCallBack <MatchToGroupLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spMatchId = so.GetSerializableProperty("MatchId") as SerializableProperty <long>; SerializableProperty <long> spGroupId = so.GetSerializableProperty("GroupId") as SerializableProperty <long>; return(mtogd.GetObject(MatchToGroupLn.GetKeyName(spMatchId.Value, spGroupId.Value))); }, CreateLineObject = delegate() { return(new MatchToGroupLn()); } }); ct.AddEvent("MatchToGroup(s) Succeeded ({0})", iCount); } // LiveMatchInfo { LiveMatchInfoDictionary lmid = LineSr.Instance.AllObjects.GetLineObjectCollection <LiveMatchInfoLn>() as LiveMatchInfoDictionary; int iCount = LineSr.MergeLineObjects <LiveMatchInfoLn>(lc, lmid, new LineSr.MergeLineObjectsCallBack <LiveMatchInfoLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spMatchId = so.GetSerializableProperty("MatchId") as SerializableProperty <long>; return(lmid.GetObject(spMatchId.Value)); }, CreateLineObject = delegate() { return(new LiveMatchInfoLn()); }, OnLineObjectMerged = delegate(LiveMatchInfoLn matchInfo) { if (matchInfo != null) { if (matchInfo.ExpiryDate.Value == null) { matchInfo.ExpiryDate.Value = new DateTimeSr(DateTime.Now.AddMinutes(30)); // Half an hour } if (matchInfo.ChangedProps.Contains(matchInfo.PeriodInfo)) { lOperationMask |= (long)eOperationMask.MatchPeriodInfoChanged; } } }, RemoveLineObject = delegate(LiveMatchInfoLn lmi) { } }); ct.AddEvent("LiveMatchInfo(s) Succeeded ({0})", iCount); } // BetDomainLn { BetDomainDictionary bdmd = LineSr.Instance.AllObjects.GetLineObjectCollection <BetDomainLn>() as BetDomainDictionary; int iCount = LineSr.MergeLineObjects <BetDomainLn>(lc, bdmd, new LineSr.MergeLineObjectsCallBack <BetDomainLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spBetDomainId = so.GetSerializableProperty("BetDomainId") as SerializableProperty <long>; return(bdmd.GetObject(spBetDomainId.Value)); }, CreateLineObject = delegate() { return(new BetDomainLn()); }, RemoveLineObject = delegate(BetDomainLn bdmn) { LineSr.Instance.RemoveBetDomain(bdmn); } }, ref lOperationMask); ct.AddEvent("BetDomain(s) Succeeded ({0})", iCount); } // OddLn { OddDictionary oddd = LineSr.Instance.AllObjects.GetLineObjectCollection <OddLn>() as OddDictionary; int iCount = LineSr.MergeLineObjects <OddLn>(lc, oddd, new LineSr.MergeLineObjectsCallBack <OddLn>() { GetLineObject = delegate(ISerializableObject so) { SerializableProperty <long> spOutcomeId = so.GetSerializableProperty("OutcomeId") as SerializableProperty <long>; return(oddd.GetObject(spOutcomeId.Value)); }, CreateLineObject = delegate() { return(new OddLn()); }, RemoveLineObject = delegate(OddLn odd) { odd.Active.Value = false; //LineSr.Instance.RemoveOdd(odd); } }); ct.AddEvent("Odd(s) Succeeded ({0})", iCount); } // Process Removed matches foreach (var match in lMatchesToRemove) { LiveMatchInfoLn lmi = match.LiveMatchInfo; if (lmi.Status.Value == eMatchStatus.Ended && match.SourceType == eServerSourceType.BtrLive) { MergeMatchResult(match); } LineSr.Instance.RemoveMatch(match); } } catch (Exception excp) { ct.AddEvent("ERROR"); m_logger.Error(excp.Message, excp); m_logger.Excp(excp, "MergeFromLigaStavok() ERROR"); throw; } finally { //m_logger.Info(sTrace); //m_logger.DebugFormat("LineContainer Trace Length = {0}", sTrace.Length); ct.AddEvent("MergeFromLigaStavok(Type={0}, MessageId={1}) completed", sType, sMessageId); ct.Info(m_logger); } #if DEBUG if ((lOperationMask & EVENT_REASON_MASK) > 0) { m_logger.InfoFormat("MergeFromLineContainer() result {0}", lOperationMask); } #endif return(true); }
/// <summary> /// Returns the longest list of line containers, for which no line containers overlap. Addtionaly /// these containers are sorted by start time. /// </summary> public static List <LineContainer <T> > GetNonOverlappingTimeSpans <T>(LinkedList <T> lines, double threshold = 0) where T : ITimeSpan { var containers = new LinkedList <LineContainer <T> >(); var lineAlreadyAdded = new bool[lines.Count]; var lineANode = lines.First; var lineBNode = lines.First; int lineAindex = 0; int lineBindex = 0; while (lineANode != null) { if (lineAlreadyAdded [lineAindex]) { lineAindex++; lineANode = lineANode.Next; continue; } // create new container for this line var lineContainer = new LineContainer <T>(); lineContainer.AddLine(lineANode.Value); lineAlreadyAdded[lineAindex] = true; containers.AddLast(lineContainer); restartLoop: lineBNode = lineANode.Next; lineBindex = lineAindex + 1; while (lineBNode != null) { if (lineAlreadyAdded [lineBindex]) { lineBindex++; lineBNode = lineBNode.Next; continue; } // just test treshold if line collides with container if (UtilsCommon.IsOverlapping(lineBNode.Value, lineContainer)) { foreach (ITimeSpan timeSpanInContainer in lineContainer.TimeSpans) { if (UtilsCommon.OverlappingScore(lineBNode.Value, timeSpanInContainer) > threshold) { lineContainer.AddLine(lineBNode.Value); lineAlreadyAdded[lineBindex] = true; goto restartLoop; } } } lineBindex++; lineBNode = lineBNode.Next; } lineAindex++; lineANode = lineANode.Next; } // XXX: is sort necessary var containerList = containers.ToList(); containerList.Sort(); return(containerList); }
public static int MergeLineObjects <T>(LineContainer lc, ILineObjectCollection <T> loc, MergeLineObjectsCallBack <T> objectsCallBack) where T : ILineObject <T> { long lOperationMask = 0L; return(MergeLineObjects <T>(lc, loc, objectsCallBack, ref lOperationMask)); }
public static int MergeLineObjects <T>(LineContainer lc, ILineObjectCollection <T> loc, MergeLineObjectsCallBack <T> objectsCallBack, ref long lOperationMask) where T : ILineObject <T> { Debug.Assert(objectsCallBack.GetLineObject != null); Debug.Assert(objectsCallBack.CreateLineObject != null); int iSucceededCount = 0; if (loc != null) { string sObjectListName = LineContainer.ContentTypeToObjectListName(typeof(T)); SerializableObjectList lObjects = lc.Objects.SafelyGetValue(sObjectListName); if (lObjects != null) { foreach (ISerializableObject so in lObjects) { //so.MethodTag = dgo; try { T tObj = objectsCallBack.GetLineObject(so); if (so.IsToRemove()) { if (tObj != null) { tObj = loc.MergeLineObject(tObj, so); if (objectsCallBack.RemoveLineObject != null) { objectsCallBack.RemoveLineObject(tObj); //m_logger.InfoFormat("Removed from Line {0}", tObj); lOperationMask |= (long)eOperationMask.RemovedFromCollection; } } } else { if (tObj == null) { // Object is NEW - DOES NOT exist yet in line tObj = objectsCallBack.CreateLineObject(); tObj.Deserialize(so); tObj = loc.MergeLineObject(tObj); lOperationMask |= (long)eOperationMask.AddedToCollection; //m_logger.DebugFormat("Added to Line {0}", tObj); } else { // Object Already Exists tObj = loc.MergeLineObject(tObj, so); if (tObj.ChangedProps != null && tObj.ChangedProps.Count > 0) { lOperationMask |= (long)eOperationMask.ObjectEdited; } } if (objectsCallBack.OnLineObjectMerged != null) { objectsCallBack.OnLineObjectMerged(tObj); } } iSucceededCount++; } catch (Exception excp) { m_logger.Error(excp.Message, excp); ExcpHelper.ThrowUp(excp, "MergeLineObjects<{0}>() ERROR for {1}", typeof(T).Name, so); } } } } return(iSucceededCount); }
public LineMessage(LineContainer slc, string sline) { LineContainer = slc; Line = sline; }
private static void LineObjectCollectionToSerializableObjectList <T>(LineContainer lc, DictionaryOfLineObjectCollection diAll) where T : ILineObject <T> { LineObjectCollectionToSerializableObjectList <T>(lc, diAll.GetLineObjectCollection <T>()); }