/// <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;
 }
 /// <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;
 }
Exemple #3
0
        /// <summary>
        /// Get a CommenceCursor object that wraps the native FormOA.ICommenceCursor interface.
        /// </summary>
        /// <param name="pName">Commence category name.</param>
        /// <param name="pCursorType">Type of Commence data to access with this cursor.</param>
        /// <param name="pCursorFlags">Logical OR of Option flags.</param>
        /// <returns>CommenceCursor wrapping ICommenceCursor according to flags passed.</returns>
        /// <exception cref="ArgumentException">Viewtype cannot be used in a CommenceCursor.</exception>
        /// <exception cref="CommenceCOMException">Commence could not create a cursor.</exception>
        public Database.ICommenceCursor GetCursor(string pName, CmcCursorType pCursorType, CmcOptionFlags pCursorFlags)
        {
            CommenceCursor cur; // our own cursor object

            /*
             * Contrary to what Commence documentation says,
             * GetCursor() does not return null on error,
             * but instead a COM error is raised.
             */
            IViewDef vd;

            if (pCursorType == CmcCursorType.View)
            {
                vd = GetViewDefinition(pName);
                if (!((ViewDef)vd).ViewType
                    .GetAttributePropertyValue <bool, CursorCreatableAttribute>(nameof(CursorCreatableAttribute.CursorCreatable)))
                {
                    throw new ArgumentException($"Commence does not support cursors on views of type {vd.Type}.");
                }
                try
                {
                    cur = new CommenceCursor(_db, pCursorType, pName, _rcwReleasePublisher, pCursorFlags, vd.Type);
                }
                catch (COMException e)
                {
                    throw new CommenceCOMException($"GetCursor failed to create a cursor on category or view '{pName}'.", e);
                }
            }
            else
            {
                try
                {
                    cur = new CommenceCursor(_db, pCursorType, pName, _rcwReleasePublisher, pCursorFlags);
                }
                catch (COMException e)
                {
                    throw new CommenceCOMException($"GetCursor failed to create a cursor on category or view '{pName}'.", e);
                }
            }
            return(cur);
        }