public static AzLogPart Create(DateTime dttmMin, DateTime dttmMac, AzLogPartState azlps) { if (dttmMin.Minute != 0 || dttmMac.Minute != 0) throw new Exception("all dates must be on even hours!"); AzLogPart azlp = new AzLogPart(); azlp.m_dttmMin = dttmMin; azlp.m_dttmMac = dttmMac; azlp.m_azlps = azlps; return azlp; }
/* S E T P A R T S T A T E */ /*---------------------------------------------------------------------------- %%Function: SetPartState %%Qualified: AzLog.AzLogParts.SetPartState %%Contact: rlittle ----------------------------------------------------------------------------*/ public void SetPartState(DateTime dttmMin, DateTime dttmMac, AzLogPartState azlps) { bool fMatched; int iazlp = IazlpFindPart(dttmMin, out fMatched); if (!fMatched && iazlp == -1) { // just insert a new one AzLogPart azlpNew = AzLogPart.Create(dttmMin, dttmMac, azlps); m_plazlp.Add(dttmMin, azlpNew); return; } AzLogPart azlp = m_plazlp.Values[iazlp]; // does this part start *before* we do? if so, we need to split AzLogPart azlpPre = null; AzLogPart azlpReplace = null; AzLogPart azlpPost = null; bool fReplace = false; if (azlp.DttmMin < dttmMin) { // if it doesn't contain us, then just add a new part and be done if (!azlp.Contains(dttmMin)) { AzLogPart azlpNew = AzLogPart.Create(dttmMin, dttmMac, azlps); m_plazlp.Add(dttmMin, azlpNew); // CAN'T JUST RETURN HERE because this new part might overlap a following part. } else { fReplace = true; // ok, there's some overlap. azlpPre = AzLogPart.Create(azlp.DttmMin, dttmMin, azlp.State); // now create the replacement part that covers what we want. if (azlp.DttmMac > dttmMac) { // the end of the current node extends beyond what we want. need to create a replace and a post part azlpReplace = AzLogPart.Create(dttmMin, dttmMac, azlps); azlpPost = AzLogPart.Create(dttmMac, azlp.DttmMac, azlp.State); } else { // the end of the matched block is *not* beyond our end. create a replacement that extends to where // we want // NOTE!! This might create overlap with the following block. we will need to coalesce!! azlpReplace = AzLogPart.Create(dttmMin, dttmMac, azlps); // there is no post because we just extended } } } else { if (fMatched) { azlpReplace = AzLogPart.Create(dttmMin, dttmMac, azlps); fReplace = true; } else { // the matched block does *NOT* begin before us, so just create a new pre block for us, and then coalesce // any following blocks azlpPre = AzLogPart.Create(dttmMin, dttmMac, azlps); } } // ok, do the operations if (fReplace) m_plazlp.RemoveAt(iazlp); if (azlpPre != null) m_plazlp.Add(azlpPre.DttmMin, azlpPre); if (azlpReplace != null) m_plazlp.Add(azlpReplace.DttmMin, azlpReplace); if (azlpPost != null) m_plazlp.Add(azlpPost.DttmMin, azlpPost); // at this point, iazlp points to at least the new item, and maybe some overlapping items. fix those (coalescing) CoalesceLogParts(iazlp); }
/* U P D A T E P A R T */ /*---------------------------------------------------------------------------- * %%Function: UpdatePart * %%Qualified: AzLog.AzLogModel.UpdatePart * %%Contact: rlittle * * ----------------------------------------------------------------------------*/ public void UpdatePart(DateTime dttmMin, DateTime dttmMac, Int32 grfDatasource, AzLogPartState azlps) { m_azles.UpdatePart(dttmMin, dttmMac, grfDatasource, azlps); }