Exemple #1
0
        /// <inheritdoc />
        public void ExportCategory(string categoryName, IEnumerable <ICursorFilter> filters, string fileName, IExportSettings settings = null)
        {
            if (settings != null)
            {
                this.Settings = settings;
            }                                                   // use custom settings if supplied
            CmcOptionFlags flags = this.Settings.UseThids
                ? CmcOptionFlags.UseThids
                : CmcOptionFlags.Default | CmcOptionFlags.IgnoreSyncCondition;

            using (var db = new CommenceDatabase())
            {
                if (this.Settings.SkipConnectedItems && this.Settings.HeaderMode != HeaderMode.CustomLabel)
                {
                    using (ICommenceCursor cur = GetCategoryCursorFieldsOnly(db, categoryName, flags))
                    {
                        ApplyFilters(cur, filters);
                        this.Settings.MaxFieldSize = (int)Math.Pow(2, 15); // 32.768‬, the built-in Commence max fieldlength (large text) is 30.000
                        ExportCursor(cur, fileName, this.Settings);
                    }
                }
                else
                {
                    using (ICommenceCursor cur = GetCategoryCursorAllFieldsAndConnections(db, categoryName, flags))
                    {
                        ApplyFilters(cur, filters);
                        ExportCursor(cur, fileName, this.Settings);
                    }
                }
            }
        }
 /// <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;
 }
Exemple #3
0
 /// <inheritdoc />
 public int DeleteRow(int nRow, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_drs.DeleteRow(nRow, (int)flags));
     }
     catch (COMException)
     {
         return(-1);
     }
 }
 /// <inheritdoc />
 public string GetRowTimeStamp(int nRow, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_qrs.GetRowTimeStamp(nRow, (int)flags));
     }
     catch (COMException)
     {
         return(null);
     }
 }
 /// <inheritdoc />
 public bool SetActiveItem(string pCategoryName, string pRowID, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_cur.SetActiveItem(pCategoryName, pRowID, (int)flags));
     }
     catch (System.Runtime.Remoting.RemotingException)
     {
         return(false);
     }
 }
        ///// <inheritdoc />
        //[ObsoleteAttribute("Use the Filters collection.")]
        //public bool SetLogic(string pLogic, int flags) // used from COM
        //{
        //    return SetLogic(pLogic, (CmcOptionFlags)flags);
        //}

        /// <inheritdoc />
        public bool SetSort(string pSort, CmcOptionFlags flags)
        {
            try
            {
                return(_cur.SetSort(pSort, (int)flags));
            }
            catch (System.Runtime.Remoting.RemotingException)
            {
                return(false);
            }
        }
 /// <inheritdoc />
 public override int GetColumnIndex(string pLabel, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_qrs.GetColumnIndex(pLabel, (int)flags));
     }
     catch (COMException)
     {
         return(-1);
     }
 }
 /// <inheritdoc />
 public int GetFieldToFile(int nRow, int nCol, string filename, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_qrs.GetFieldToFile(nRow, nCol, filename, (int)flags));
     }
     catch (COMException)
     {
         return(-1);
     }
 }
 /// <inheritdoc />
 public override string GetRowValue(int nRow, int nCol, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_qrs.GetRowValue(nRow, nCol, (int)flags));
     }
     catch (COMException)
     {
         return(null);
     }
 }
 /// <inheritdoc />
 public override string GetColumnLabel(int nCol, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_qrs.GetColumnLabel(nCol, (int)flags));
     }
     catch (COMException)
     {
         return(null);
     }
 }
 /// <inheritdoc />
 public int Commit(CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_ars.Commit((int)flags));
     }
     catch (COMException)
     {
         return(-1);
     }
 }
 /// <inheritdoc />
 public int ModifyRow(int nRow, int nCol, string fieldValue, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_ars.ModifyRow(nRow, nCol, fieldValue, (int)flags));
     }
     catch (COMException)
     {
         return(-1);
     }
 }
 /// <inheritdoc />
 public bool SetActiveDate(string sDate, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         return(_cur.SetActiveDate(sDate, (int)flags));
     }
     catch (System.Runtime.Remoting.RemotingException)
     {
         return(false);
     }
 }
 /// <inheritdoc />
 public bool SetColumn(int nColumn, string pName, CmcOptionFlags flags)
 {
     try
     {
         _directColumnsWereSet = true;
         return(_cur.SetColumn(nColumn, pName, (int)flags));
     }
     catch (System.Runtime.Remoting.RemotingException)
     {
         return(false);
     }
 }
        /// <inheritdoc />
        public IEnumerable <string> GetColumnNames(CmcOptionFlags flags = CmcOptionFlags.Fieldname)
        {
            var retval = new List <string>();

            using (var qrs = GetQueryRowSet(0, CmcOptionFlags.Default))
            {
                for (int i = 0; i < qrs.ColumnCount; i++)
                {
                    retval.Add(qrs.GetColumnLabel(i, flags));
                }
            }
            return(retval.ToArray());
        }
        /// <inheritdoc />
        public ICommenceDeleteRowSet GetDeleteRowSet(CmcOptionFlags flags = CmcOptionFlags.Default)
        {
            ICommenceDeleteRowSet drs = null;

            try
            {
                drs = new CommenceDeleteRowSet(_cur, _rcwReleasePublisher, flags);
            }
            catch (COMException e)
            {
                throw new CommenceCOMException("Unable to get a DeleteRowSet object from Commence", e);
            }
            return(drs);
        }
        /// <inheritdoc />
        public ICommenceAddRowSet GetAddRowSet(int nRows, CmcOptionFlags flags = CmcOptionFlags.Default)
        {
            ICommenceAddRowSet ars = null;

            try
            {
                ars = new CommenceAddRowSet(_cur, nRows, _rcwReleasePublisher, flags);
            }
            catch (COMException e)
            {
                throw new CommenceCOMException("Unable to get a AddRowSet object from Commence", e);
            }
            return(ars);
        }
        /// <inheritdoc />
        // only works on shared databases; local databases have no thids
        // you cannot just pass a thid value you retrieved by GetRowID(), you must strip off the category (=first) sequence
        // e.g. if GetRowID returns 0C:80006901:94BD3402, you must strip off the leading 0C: part
        public ICommenceQueryRowSet GetQueryRowSetByThid(string pThid, CmcOptionFlags flags = CmcOptionFlags.UseThids)
        {
            ICommenceQueryRowSet qrs = null;

            try
            {
                qrs = new CommenceQueryRowSet(_cur, pThid, _rcwReleasePublisher, flags, RowSetIdentifier.Thid);
            }
            catch (COMException e)
            {
                throw new CommenceCOMException("Unable to get a QueryRowSet object from Commence", e);
            }
            return(qrs);
        }
 /// <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;
 }
        /// <inheritdoc />
        public ICommenceQueryRowSet GetQueryRowSetByID(string pRowID, CmcOptionFlags flags = CmcOptionFlags.Default)
        {
            ICommenceQueryRowSet qrs = null;

            try
            {
                qrs = new CommenceQueryRowSet(_cur, pRowID, _rcwReleasePublisher, flags);
            }
            catch (COMException e)
            {
                throw new CommenceCOMException("Unable to get a QueryRowSet object from Commence", e);
            }
            return(qrs);
        }
 /// <inheritdoc />
 public override object[] GetRow(int nRow, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     object[] retval = null;
     try
     {
         retval = _ers.GetRow(nRow, base.Delim, (int)flags)
                  .Split(base.Splitter, StringSplitOptions.None)
                  .ToArray <object>();
     }
     catch (COMException)
     {
         // TO-DO: return something meaningful...
     }
     return(retval);
 }
        /// <inheritdoc />
        public ICommenceQueryRowSet GetQueryRowSet(int nRows, CmcOptionFlags flags = CmcOptionFlags.Default)
        {
            ICommenceQueryRowSet qrs = null;

            try
            {
                qrs = new CommenceQueryRowSet(_cur, nRows, _rcwReleasePublisher, flags);
            }
            catch (COMException e)
            {
                // when very large amounts of data are requested, this may cause a "Couldn't get memory" error in Commence.
                throw new CommenceCOMException("Unable to get a QueryRowSet object from Commence", e);
            }
            return(qrs);
        }
        /// <inheritdoc />
        public bool SetFilter(string pFilter, CmcOptionFlags flags)
        {
            try
            {
                return(_cur.SetFilter(pFilter, (int)flags));
            }

            /* Contrary to Commence documentation this method will not return false if it fails.
             * Instead, a System.Runtime.Remoting.RemotingException is thrown complaining about
             * 'ByRef value type parameter cannot be null.'
             */
            catch (System.Runtime.Remoting.RemotingException)
            {
                return(false);
            }
        }
        /// <inheritdoc />
        public CommenceCursor CommitGetCursor(CmcOptionFlags flags = CmcOptionFlags.Default)
        {
            CommenceCursor cc = null;

            FormOA.ICommenceCursor newcur = null;
            try
            {
                newcur = _ers.CommitGetCursor((int)flags);
                if (newcur != null)
                {
                    cc = new CommenceCursor(newcur, _rcwReleasePublisher);
                }
            }
            catch (COMException)
            {
            }
            return(cc);
        }
        /// <inheritdoc />
        public CommenceCursor CommitGetCursor(CmcOptionFlags flags = CmcOptionFlags.Default)
        {
            CommenceCursor cc = null;

            FormOA.ICommenceCursor newcur = null;
            try
            {
                newcur = _ars.CommitGetCursor((int)flags);
                if (newcur != null)
                {
                    cc = new CommenceCursor(newcur, _rcwReleasePublisher);
                }
            }
            catch (COMException)
            {
            }
            // we should Dispose ourselves now, the AddRowset is no longer valid.
            // ...but I don't know how.
            return(cc);
        }
Exemple #26
0
        /// <inheritdoc />
        public void ExportCategory(string categoryName, string fileName, IExportSettings settings = null)
        {
            if (settings != null)
            {
                this.Settings = settings;
            }                                                   // use custom settings if supplied
            CmcOptionFlags flags = this.Settings.UseThids
                ? CmcOptionFlags.UseThids
                : CmcOptionFlags.Default | CmcOptionFlags.IgnoreSyncCondition;

            // User requested we skip connections.
            // A default cursor on a category contains all fields *and* connections.
            // The data receiving routines will ignore them, but they will be read unless we do not include them in our cursor
            // We optimize here by only including direct fields in the cursor
            using (var db = new CommenceDatabase())
            {
                if (this.Settings.SkipConnectedItems && this.Settings.HeaderMode != HeaderMode.CustomLabel)
                {
                    using (ICommenceCursor cur = GetCategoryCursorFieldsOnly(db, categoryName, flags))
                    {
                        // we can limit MAX_FIELD_SIZE in this case
                        this.Settings.MaxFieldSize = (int)Math.Pow(2, 15); // 32.768‬, the built-in Commence max fieldlength (large text) is 30.000
                        ExportCursor(cur, fileName, this.Settings);
                    }
                }
                else
                {
                    using (ICommenceCursor cur = GetCategoryCursorAllFieldsAndConnections(db, categoryName, flags))
                    {
                        // You can create a cursor with all fields including connections by just
                        // supplying CmcOptionFlags.All.
                        // However, when the cursor is read, connected items are returned as comma-delimited strng,
                        // which, because Commence does not supply text-qualifiers, makes it impossible to split them.
                        // We therefore explicitly set the connections which deteriorates performance
                        // but gains us (more) reliability.
                        ExportCursor(cur, fileName, this.Settings);
                    }
                }
            }
        }
 /// <summary>
 /// Constructor that creates QueryRowSet with set number of items.
 /// </summary>
 /// <param name="cur">FormOA.ICommenceCursor reference.</param>
 /// <param name="nCount">Number of items to query.</param>
 /// <param name="rcwpub">RCWReleasePublisher object used for COM Interop object cleanup.</param>
 /// <param name="flags">option flags, must be 0.</param>
 internal CommenceQueryRowSet(FormOA.ICommenceCursor cur, int nCount, IRcwReleasePublisher rcwpub, CmcOptionFlags flags)
 {
     // queryrowset with set number of rows
     _qrs = cur.GetQueryRowSet(nCount, (int)flags);
     if (_qrs == null)
     {
         throw new CommenceCOMException("Unable to obtain a QueryRowSet from Commence.");
     }
     _rcwReleasePublisher             = rcwpub;
     _rcwReleasePublisher.RCWRelease += this.RCWReleaseHandler;
 }
 /// <inheritdoc />
 public bool SetRelatedColumn(int nColumn, string pConnName, string pCatName, string pName, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     try
     {
         _relatedColumnsWereSet = true; // logic error!!
         return(_cur.SetRelatedColumn(nColumn, pConnName, pCatName, pName, (int)flags));
     }
     catch (System.Runtime.Remoting.RemotingException)
     {
         return(false);
     }
 }
        /// <summary>
        /// Constructor that creates QueryRowSet for particular row identified by RowID.
        /// </summary>
        /// <param name="cur">FormOA.ICommenceCursor reference.</param>
        /// <param name="pRowID">row or thid  id.</param>
        /// <param name="rcwpub">RCWReleasePublisher object used for COM Interop object cleanup.</param>
        /// <param name="flags">option flags, must be 0.</param>
        /// <param name="identifier"><see cref="RowSetIdentifier"/></param>
        internal CommenceQueryRowSet(FormOA.ICommenceCursor cur, string pRowID, IRcwReleasePublisher rcwpub, CmcOptionFlags flags = CmcOptionFlags.Default, RowSetIdentifier identifier = RowSetIdentifier.RowId)
        {
            switch (identifier)
            {
            case RowSetIdentifier.RowId:
                _qrs = cur.GetQueryRowSetByID(pRowID, (int)flags);
                break;

            case RowSetIdentifier.Thid:
                // _qrs = cur.GetQueryRowSetByThid(pRowID, (int)flags);
                throw new NotSupportedException("GetQueryRowSetByThid no longer supported by Commence API");
                //break;
            }
            if (_qrs == null)
            {
                throw new CommenceCOMException("Unable to obtain a QueryRowSet from Commence.");
            }
            _rcwReleasePublisher             = rcwpub;
            _rcwReleasePublisher.RCWRelease += this.RCWReleaseHandler;
        }
 /// <inheritdoc />
 public bool SetActiveDateRange(string startDate, string endDate, CmcOptionFlags flags = CmcOptionFlags.Default)
 {
     return(_cur.SetActiveDateRange(startDate, endDate, (int)flags));
 }