Exemplo n.º 1
0
 public TentativeStateCommitable(ITwainSessionInternal session, int newState)
 {
     _session   = session;
     _origState = session.State;
     _newState  = newState;
     _session.ChangeState(newState, false);
 }
Exemplo n.º 2
0
 internal DGControl(ITwainSessionInternal session)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     _session = session;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TripletBase" /> class.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 internal TripletBase(ITwainSessionInternal session)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     Session = session;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Verifies the session is within the specified state range (inclusive). Throws
 /// <see cref="TwainStateException" /> if violated.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="allowedMinimum">The allowed minimum.</param>
 /// <param name="allowedMaximum">The allowed maximum.</param>
 /// <param name="group">The triplet data group.</param>
 /// <param name="dataArgumentType">The triplet data argument type.</param>
 /// <param name="message">The triplet message.</param>
 /// <exception cref="TwainStateException"></exception>
 public static void VerifyState(this ITwainSessionInternal session, int allowedMinimum, int allowedMaximum, DataGroups group, DataArgumentType dataArgumentType, Message message)
 {
     if (session.EnforceState && (session.State < allowedMinimum || session.State > allowedMaximum))
     {
         throw new TwainStateException(session.State, allowedMinimum, allowedMaximum, group, dataArgumentType, message,
                                       string.Format(CultureInfo.InvariantCulture, "TWAIN state {0} does not match required range {1}-{2} for operation {3}-{4}-{5}.",
                                                     session.State, allowedMinimum, allowedMaximum, group, dataArgumentType, message));
     }
 }
Exemplo n.º 5
0
        private static void HandleReturnCode(ITwainSessionInternal session, ReturnCode rc)
        {
            switch (rc)
            {
            case ReturnCode.Success:
            case ReturnCode.XferDone:
            case ReturnCode.Cancel:
                // ok to keep going
                break;

            default:
                var status = session.CurrentSource.GetStatus();
                session.SafeSyncableRaiseEvent(new TransferErrorEventArgs(rc, status));
                break;
            }
        }
Exemplo n.º 6
0
        static ReturnCode DoAudioNativeXfer(ITwainSessionInternal session)
        {
            IntPtr     dataPtr   = IntPtr.Zero;
            IntPtr     lockedPtr = IntPtr.Zero;
            ReturnCode xrc       = ReturnCode.Failure;

            try
            {
                xrc = session.DGAudio.AudioNativeXfer.Get(ref dataPtr);
                if (xrc == ReturnCode.XferDone)
                {
                    session.ChangeState(7, true);
                    if (dataPtr != IntPtr.Zero)
                    {
                        lockedPtr = PlatformInfo.Current.MemoryManager.Lock(dataPtr);
                    }

                    session.SafeSyncableRaiseEvent(new DataTransferredEventArgs(session.CurrentSource, lockedPtr));
                }
                else
                {
                    HandleReturnCode(session, xrc);
                }
            }
            catch (Exception ex)
            {
                session.SafeSyncableRaiseEvent(new TransferErrorEventArgs(ex));
            }
            finally
            {
                session.ChangeState(6, true);
                // data here is allocated by source so needs to use shared mem calls
                if (lockedPtr != IntPtr.Zero)
                {
                    //PlatformInfo.Current.MemoryManager.Unlock(lockedPtr);
                    PlatformInfo.Current.MemoryManager.Unlock(dataPtr);
                    lockedPtr = IntPtr.Zero;
                }
                if (dataPtr != IntPtr.Zero)
                {
                    PlatformInfo.Current.MemoryManager.Free(dataPtr);
                    dataPtr = IntPtr.Zero;
                }
            }
            return(xrc);
        }
Exemplo n.º 7
0
        DataSource GetSourceInstance(ITwainSessionInternal session, TWIdentity sourceId)
        {
            DataSource source = null;

            PlatformInfo.Current.Log.Debug("Source id = {0}", sourceId.Id);
            var key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}", sourceId.Id, sourceId.Manufacturer, sourceId.ProductFamily, sourceId.ProductName);

            if (_ownedSources.ContainsKey(key))
            {
                source = _ownedSources[key];
            }
            else
            {
                _ownedSources[key] = source = new DataSource(session, sourceId);
            }
            return(source);
        }
Exemplo n.º 8
0
        static void DoImageXferredEventRoutine(ITwainSessionInternal session, IntPtr dataPtr, TWImageMemXfer memInfo, byte[] memData, string filePath, FileFormat format)
        {
            DataTransferredEventArgs args = null;

            if (dataPtr != IntPtr.Zero)
            {
                args = new DataTransferredEventArgs(session.CurrentSource, dataPtr);
            }
            else if (memData != null)
            {
                args = new DataTransferredEventArgs(session.CurrentSource, memInfo, memData);
            }
            else
            {
                args = new DataTransferredEventArgs(session.CurrentSource, filePath, format);
            }
            session.SafeSyncableRaiseEvent(args);
        }
Exemplo n.º 9
0
        static ReturnCode DoAudioFileXfer(ITwainSessionInternal session)
        {
            string          filePath = null;
            TWSetupFileXfer setupInfo;
            ReturnCode      xrc = session.DGControl.SetupFileXfer.Get(out setupInfo);

            if (xrc == ReturnCode.Success)
            {
                filePath = setupInfo.FileName;

                xrc = session.DGAudio.AudioFileXfer.Get();
                if (xrc == ReturnCode.XferDone)
                {
                    session.SafeSyncableRaiseEvent(new DataTransferredEventArgs(session.CurrentSource, filePath, (FileFormat)0));
                }
                else
                {
                    HandleReturnCode(session, xrc);
                }
            }
            return(xrc);
        }
Exemplo n.º 10
0
        static ReturnCode DoImageFileXfer(ITwainSessionInternal session)
        {
            string          filePath = null;
            TWSetupFileXfer setupInfo;

            if (session.DGControl.SetupFileXfer.Get(out setupInfo) == ReturnCode.Success)
            {
                filePath = setupInfo.FileName;
            }

            var xrc = session.DGImage.ImageFileXfer.Get();

            if (xrc == ReturnCode.XferDone)
            {
                DoImageXferredEventRoutine(session, IntPtr.Zero, null, null, filePath, setupInfo.Format);
            }
            else
            {
                HandleReturnCode(session, xrc);
            }
            return(xrc);
        }
Exemplo n.º 11
0
 internal PendingXfers(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 12
0
 internal ExtImageInfo(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 13
0
 internal IccProfile(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 14
0
 internal CustomDSData(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 15
0
 internal Parent(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 16
0
 internal GrayResponse(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 17
0
 internal DeviceEvent(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 18
0
 internal PassThru(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 19
0
 internal Filter(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 20
0
 internal XferGroup(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 21
0
 internal Callback(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 22
0
 internal Palette8(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 23
0
 internal ImageFileXfer(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 24
0
 internal AudioFileXfer(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 25
0
 internal RgbResponse(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 26
0
 internal Status(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 27
0
 internal CapabilityCustom(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 28
0
 internal AudioNativeXfer(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 29
0
 internal Identity(ITwainSessionInternal session) : base(session)
 {
 }
Exemplo n.º 30
0
 internal SetupFileXfer(ITwainSessionInternal session) : base(session)
 {
 }