Esempio n. 1
0
 /// <summary>
 /// Invoked to indicate that the Source needs to be closed.
 /// </summary>
 /// <exception cref="DataSourceException"></exception>
 protected virtual void OnCloseDSReq()
 {
     for (var _rc = DataSourceServices.DsmInvoke(this.AppIdentity, TwMSG.CloseDSReq); _rc != TwRC.Success;)
     {
         throw new DataSourceException(TwRC.Failure, TwCC.OperationError);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Every Source is required to have a single entry point called DS_Entry. DS_Entry is only called by the Source Manager.
        /// </summary>
        /// <param name="appId">This points to a TwIdentity structure, allocated by the application, that describes the
        /// application making the call. One of the fields in this structure, called Id, is an arbitrary and
        /// unique identifier assigned by the Source Manager to tag the application as a unique TWAIN
        /// entity. The Source Manager maintains a copy of the application’s identity structure, so the
        /// application must not modify that structure unless it first breaks its connection with the Source
        /// Manager,then reconnects to cause the Source Manager to store the new, modified identity.</param>
        /// <param name="dg">The Data Group of the operation triplet. Currently, only DG_CONTROL, DG_IMAGE, and DG_AUDIO are defined.</param>
        /// <param name="dat">The Data Argument Type of the operation triplet.</param>
        /// <param name="msg">The Message of the operation triplet.</param>
        /// <param name="data">The pData parameter is a pointer to the data (a variable or, more
        /// typically, a structure) that will be used according to the action specified by the operation
        /// triplet.</param>
        /// <returns>TWAIN Return Codes.</returns>
        public TwRC ProcessRequest(TwIdentity appId, TwDG dg, TwDAT dat, TwMSG msg, IntPtr data)
        {
            try {
                if (dg == TwDG.Control)
                {
                    switch (dat)
                    {
                    case TwDAT.Identity:
                        return(this._IdentityControlProcessRequest(appId, msg, data));

                    case TwDAT.Status:
                        return(this._StatusControlProcessRequest(appId, msg, data));

                    case TwDAT.EntryPoint:
                        return(this._EntryPointControlProcessRequest(appId, msg, Marshal.PtrToStructure(data, typeof(TwEntryPoint)) as TwEntryPoint));
                    }
                }
                this._SetConditionCode(appId, TwCC.Success);
                return(this._handlers[appId.Id].ProcessRequest(dg, dat, msg, data));
            } catch (DataSourceException ex) {
                DataSourceServices._ToLog(ex);
                this._SetConditionCode(appId, ex.ConditionCode);
                return(ex.ReturnCode);
            } catch (Exception ex) {
                DataSourceServices._ToLog(ex);
            }
            this._SetConditionCode(appId, TwCC.OperationError);
            return(TwRC.Failure);
        }
Esempio n. 3
0
 /// <summary>
 /// Invoked to indicate that the Source has data that is ready to be transferred.
 /// </summary>
 /// <exception cref="DataSourceException"></exception>
 protected virtual void OnXferReady()
 {
     if (this.XferEnvironment.PendingXfers == 0)
     {
         this.XferEnvironment.PendingXfers = (ushort)Math.Abs((short)this[TwCap.XferCount].Value);
     }
     this.State |= DataSourceState.Ready;
     for (var _rc = DataSourceServices.DsmInvoke(this.AppIdentity, TwMSG.XFerReady); _rc != TwRC.Success;)
     {
         this.State &= ~DataSourceState.Ready;
         this.XferEnvironment.PendingXfers = 0;
         throw new DataSourceException(TwRC.Failure, TwCC.OperationError);
     }
 }