/// <summary> /// Creates default cursor type on category with default options. /// </summary> /// <param name="cmc">Native FormOA (Commence) reference.</param> /// <param name="pName">Commence category name.</param> /// <param name="rcwReleasePublisher">RCWReleasePublisher object used for COM Interop object cleanup.</param> internal CommenceCursor(FormOA.ICommenceDB cmc, string pName, IRcwReleasePublisher rcwReleasePublisher) { // default cursor type, on category, default flag _cur = cmc.GetCursor(0, pName, 0); _rcwReleasePublisher = rcwReleasePublisher; _rcwReleasePublisher.RCWRelease += this.RCWReleaseHandler; }
private bool disposedValue = false; // To detect redundant calls /// <summary> /// Dispose /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { Close(); // dispose managed state (managed objects). if (DDETimer != null) { DDETimer.Stop(); _conv.CloseConversation(); } _conv = null; } // free unmanaged resources (unmanaged objects) and override a finalizer below. if (_db != null) { while (Marshal.ReleaseComObject(_db) > 0) { } ; _db = null; } // set large fields to null. disposedValue = true; } }
/// <summary> /// Creates custom Category cursor. /// </summary> /// <param name="cmc">Native FormOA (Commence) reference.</param> /// <param name="pCursorType">CmcCursorType.</param> /// <param name="pName">Commence category or view name.</param> /// <param name="rcwReleasePublisher">RCWReleasePublisher object used for COM Interop object cleanup.</param> /// <param name="pCursorFlags">CmcOptionFlags.</param> internal CommenceCursor(FormOA.ICommenceDB cmc, CmcCursorType pCursorType, string pName, IRcwReleasePublisher rcwReleasePublisher, CmcOptionFlags pCursorFlags) { CursorType = pCursorType; Flags = pCursorFlags; _cur = cmc.GetCursor((int)pCursorType, pName, (int)pCursorFlags); // notice the type conversion _rcwReleasePublisher = rcwReleasePublisher; _rcwReleasePublisher.RCWRelease += this.RCWReleaseHandler; }
private void RCWReleaseHandler(object sender, EventArgs e) { if (_db != null) { while (Marshal.ReleaseComObject(_db) > 0) { } ; _db = null; } }
/// <summary> /// Creates custom View cursor. /// </summary> /// <param name="cmc">Native FormOA (Commence) reference.</param> /// <param name="pCursorType">CmcCursorType.</param> /// <param name="pName">Commence category or view name.</param> /// <param name="rcwReleasePublisher">RCWReleasePublisher object used for COM Interop object cleanup.</param> /// <param name="pCursorFlags">CmcOptionFlags.</param> /// <param name="viewType">Viewtype.</param> internal CommenceCursor(FormOA.ICommenceDB cmc, CmcCursorType pCursorType, string pName, IRcwReleasePublisher rcwReleasePublisher, CmcOptionFlags pCursorFlags, string viewType) { CursorType = pCursorType; Flags = pCursorFlags; if (CursorType == CmcCursorType.View) { _viewName = pName; //_viewType = Utils.GetValueFromEnumDescription<CommenceViewType>(viewType); _viewType = Utils.EnumFromAttributeValue <CommenceViewType, StringValueAttribute>(nameof(StringValueAttribute.StringValue), viewType); } _cur = cmc.GetCursor((int)pCursorType, pName, (int)pCursorFlags); // notice the type conversion _rcwReleasePublisher = rcwReleasePublisher; _rcwReleasePublisher.RCWRelease += this.RCWReleaseHandler; }
/// <summary> /// Public constructor. /// </summary> public CommenceDatabase() { _app = new CommenceApp(); // when we call this first, the next line does not fail when called from COM. // we also want this call to CommenceApp because it contains the check to see if commence.exe is running. _db = _app.Db; /* We create a publisher object so any classes created from this instance can use it. * The idea is that this way, COM clients can create and close the several COM-visible components (CommenceApp, Export) safely. * It would be easier to use a static event notifying all classes that consume a COM resource to release it. * This leads to unwanted behaviour because all instances will be notified. * The down-side of the current approach is that we have to pass the event publisher to all classes that will subscribe to it. * There must be a better way? */ _rcwReleasePublisher = new RcwReleasePublisher(); _rcwReleasePublisher.RCWRelease += _app.RCWReleaseHandler; _rcwReleasePublisher.RCWRelease += this.RCWReleaseHandler; }