Exemple #1
0
        /// <summary>
        /// Process a TWAIN Direct task...
        /// </summary>
        /// <param name="a_jsonlookup">data for the task</param>
        /// <param name="a_swordtask">the result of the task</param>
        /// <returns>a twain local status</returns>
        private TwainLocalScanner.ApiStatus DeviceScannerSendTask(JsonLookup a_jsonlookup, out SwordTask a_swordtask, ref bool a_blSetAppCapabilities)
        {
            bool   blSuccess;
            string szTask;
            Sword  sword;

            // Init stuff...
            a_swordtask            = new SwordTask();
            m_szScanImageArguments = "";

            // Create our object...
            sword = new Sword();

            // Grab our task...
            szTask = a_jsonlookup.GetJson("task");

            // Run our task...
            blSuccess = sword.BatchMode(m_szScanner, szTask, true, ref a_swordtask, ref a_blSetAppCapabilities, out m_szScanImageArguments);
            if (!blSuccess)
            {
                return(TwainLocalScanner.ApiStatus.invalidCapturingOptions);
            }

            // All done...
            return(TwainLocalScanner.ApiStatus.success);
        }
Exemple #2
0
        /// <summary>
        /// Run a task...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_buttonRun_Click(object sender, EventArgs e)
        {
            // Protection...
            if (m_sword != null)
            {
                return;
            }

            // Init stuff...
            m_swordtask = new SwordTask();

            // Buttons off, cancel on...
            SetButtonMode(ButtonMode.Scanning);

            // Let the user select a default driver...
            m_sword = Sword.Task(m_szWriteFolder, m_szTwainDefaultDriver, (string)m_listviewTasks.SelectedItems[0].Tag, m_blWriteFolderNotNull, null, ref m_swordtask);
            if (m_sword == null)
            {
                MessageBox.Show("Unable to run task...", "Error");
                SetButtonMode(ButtonMode.Ready);
                return;
            }

            // Set up a timer to wait for completion...
            Timer m_timer = new Timer();

            m_timer.Interval = 1000;
            m_timer.Start();
            m_timer.Tick += new EventHandler(m_timer_Tick);

            // Yike...
            m_listviewTasks.Focus();
        }
 private void CollectSword(SwordTask sword)
 {
     if (sword == null)
     {
         throw new System.Exception("No sword component in SwordCollector receiver. Layer matrix is incorrect");
     }
     sword.GiveSword(transform);
     foreach (var listener in completionListeners)
     {
         listener.onTaskCompleted();
     }
     OnTrigger.Invoke();
     Destroy(sword.gameObject);
 }
Exemple #4
0
        /// <summary>
        /// Select the mode for this session, batch or interactive,
        /// based on the arguments.  Don't be weirded out by this
        /// function calling TWAIN Local On Sane and then that function using
        /// Sword.  This is a static function, it's just a convenience
        /// to use the Sword object to hold it, it could go anywhere
        /// and later on probably will (like as a function inside of
        /// the Program module).
        /// </summary>
        /// <returns>true for batch mode, false for interactive mode</returns>
        public static bool SelectMode()
        {
            int    iPid       = 0;
            string szIpc      = null;
            string szTaskFile = "";
            string szWriteFolder;

            // Sleep so we can attach and debug stuff...
            int iDelay = (int)Config.Get("delayTwainDirectOnSane", 0);

            if (iDelay > 0)
            {
                Thread.Sleep(iDelay);
            }

            // Check the arguments...
            szWriteFolder = Config.Get("writeFolder", null);
            szTaskFile    = Config.Get("task", null);
            szIpc         = Config.Get("ipc", null);
            iPid          = int.Parse(Config.Get("parentpid", "0"));

            // Handle the SANE list...
            string szSaneList = Config.Get("sanelist", null);

            if (szSaneList != null)
            {
                if (szSaneList == "")
                {
                    szSaneList = Path.Combine(Config.Get("writeFolder", ""), "sanelist.txt");
                }
                System.IO.File.WriteAllText(szSaneList, Sword.SaneListDrivers());
                return(true);
            }

            // Run in IPC mode.  The caller has set up a 'pipe' for us, so we'll use
            // that to send commands back and forth...
            if (szIpc != null)
            {
                TwainLocalOnSane twainlocalonsane;

                // Create our object...
                twainlocalonsane = new TwainLocalOnSane(szWriteFolder, szIpc, iPid);

                // Run our object...
                twainlocalonsane.Run();

                // All done...
                return(true);
            }

            // If we have a file, then take the shortcut, this is the path to use
            // when running under another program, like an HTTP service.
            if (File.Exists(szTaskFile))
            {
                bool      blSetAppCapabilities = false;
                string    szScanImageArguments = "";
                Sword     sword;
                SwordTask swordtask;

                // Init stuff...
                swordtask = new SwordTask();

                // Create our object...
                sword = new Sword();

                // Run our task...
                sword.BatchMode(Config.Get("scanner", null), szTaskFile, false, ref swordtask, ref blSetAppCapabilities, out szScanImageArguments);

                // All done...
                return(true);
            }

            // Otherwise let the user interact with us...
            TwainDirect.Support.Log.Info("Interactive mode...");
            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Select the mode for this session, batch or interactive,
        /// based on the arguments.  Don't be weirded out by this
        /// function calling TWAIN Local On Twain and then that function using
        /// Sword.  This is a static function, it's just a convenience
        /// to use the Sword object to hold it, it could go anywhere
        /// and later on probably will (like as a function inside of
        /// the Program module).
        /// </summary>
        /// <returns>true for batch mode, false for interactive mode</returns>
        public static bool SelectMode()
        {
            int    iPid = 0;
            long   lResponseCharacterOffset;
            string szIpc;
            string szTaskFile;
            bool   blTestPdfRaster;
            bool   blTestTwainLocalOnTwain;
            bool   blTestJson;
            bool   blTestDnssd;

            // Check the arguments...
            string szWriteFolder    = Config.Get("writeFolder", null);
            string szExecutableName = Config.Get("executableName", null);

            szTaskFile              = Config.Get("task", null);
            blTestPdfRaster         = (Config.Get("testpdfraster", null) != null);
            blTestTwainLocalOnTwain = (Config.Get("testtwainlocalontwain", null) != null);
            blTestJson              = (Config.Get("testjson", null) != null);
            blTestDnssd             = (Config.Get("testdnssd", null) != null);
            szIpc = Config.Get("ipc", null);
            iPid  = int.Parse(Config.Get("parentpid", "0"));

            // Run in IPC mode.  The caller has set up a 'pipe' for us, so we'll use
            // that to send commands back and forth.  This is the normal mode when
            // we're running with a scanner...
            if (szIpc != null)
            {
                // With Windows we need a window for the driver, but we can hide it...
                if (TWAINCSToolkit.GetPlatform() == "WINDOWS")
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new FormTwain(szWriteFolder, szIpc, iPid, RunInUiThread));
                    return(true);
                }

                // Linux and Mac OS X are okay without a window...
                else
                {
                    TwainLocalOnTwain twainlocalontwain;

                    // Create our object...
                    twainlocalontwain = new TwainLocalOnTwain(szWriteFolder, szIpc, iPid, null, null, IntPtr.Zero);

                    // Run our object...
                    twainlocalontwain.Run();

                    // All done...
                    return(true);
                }
            }

            // Handle the TWAIN list, we use this during registration to find out
            // what drivers we can use, and collect some info about them...
            string szTwainList = Config.Get("twainlist", null);

            if (szTwainList != null)
            {
                if (szTwainList == "")
                {
                    szTwainList = Path.Combine(Config.Get("writeFolder", ""), "twainlist.txt");
                }
                System.IO.File.WriteAllText(szTwainList, Sword.TwainListDrivers());
                return(true);
            }

            // Test PDF/Raster...
            if (blTestPdfRaster)
            {
                TestPdfRaster testpdfraster;

                // Create our object...
                testpdfraster = new TestPdfRaster();

                // Do the test...
                testpdfraster.Test();

                // All done...
                TWAINWorkingGroup.Log.Close();
                return(true);
            }

            // Test TWAIN Local on TWAIN...
            if (blTestTwainLocalOnTwain)
            {
                TestTwainLocalOnTwain testtwainlocalontwain;

                // Create our object...
                testtwainlocalontwain = new TestTwainLocalOnTwain(Config.Get("scanner", null), szWriteFolder, iPid, szTaskFile);

                // Do the test...
                testtwainlocalontwain.Test();

                // All done...
                return(true);
            }

            // Test JSON...
            if (blTestJson)
            {
                TwainDirectSupport.JsonLookup jsonlookup = new TwainDirectSupport.JsonLookup();

                string szTest =
                    "{\n" +
                    "    \"array\": [\n" +
                    "        {\n" +
                    "            \\\"aaa\\\": 0,\n" +
                    "            'bbb': 1\n" +
                    "        },\n" +
                    "        {\n" +
                    "            ccc : 2,\n" +
                    "            'ddd' : 3,\n" +
                    "            \"xxx\": [\n" +
                    "                {\n" +
                    "                    \"mmm\": 111\n" +
                    "                },\n" +
                    "                {\n" +
                    "                    \"nnn\": 222\n" +
                    "                },\n" +
                    "                {\n" +
                    "                    \"ooo\": 333\n" +
                    "                }\n" +
                    "            ]\n" +
                    "        },\n" +
                    "        {\n" +
                    "            \"eee\": 4,\n" +
                    "            \"fff\": 5\n" +
                    "        }\n" +
                    "    ],\n" +
                    "    \"string\": \"value\"\n" +
                    "}";

                // Load something interesting...
                bool blSuccess = jsonlookup.Load(szTest, out lResponseCharacterOffset);
                if (!blSuccess)
                {
                    string sz = szTest.Substring(0, (int)lResponseCharacterOffset);
                }

                NativeMethods.AllocConsole();
                jsonlookup.Dump();

                // Find something interesting...
                string szValue;
                TwainDirectSupport.JsonLookup.EPROPERTYTYPE epropertytype;
                blSuccess = jsonlookup.GetCheck("array[0].aaa", out szValue, out epropertytype, true);

                // Test...
                string[] aszFile = Directory.GetFiles("C:/Users/l252353/Desktop/TwainDirect/source/TwainDirectOnTwain/bin/x86/Debug/data");
                if (aszFile != null)
                {
                    foreach (string szFile in aszFile)
                    {
                        // Skip non-.json files...
                        if (!szFile.Contains("pass0.json"))
                        {
                            continue;
                        }

                        // Read it...
                        string szJson = File.ReadAllText(szFile);

                        // Load it...
                        blSuccess = jsonlookup.Load(szJson, out lResponseCharacterOffset);

                        // File we're working on...
                        Console.WriteLine("\r\n*******************************************************************************");
                        Console.WriteLine(szFile);

                        // Fail file results...
                        if (szFile.Contains("fail"))
                        {
                            if (blSuccess)
                            {
                                Console.WriteLine("FAILED ON THE FAIL...");
                            }
                            else
                            {
                                Console.WriteLine("Error at offset: " + lResponseCharacterOffset);
                                Console.WriteLine(szJson.Substring(0, (int)lResponseCharacterOffset) + "^ERROR^" + szJson.Substring((int)lResponseCharacterOffset));
                            }
                        }

                        // Pass file results...
                        else
                        {
                            if (blSuccess)
                            {
                                jsonlookup.Dump();
                                jsonlookup.GetCheck("devices[0].id", out szValue, out epropertytype, true);
                            }
                            else
                            {
                                Console.WriteLine("Error at offset: " + lResponseCharacterOffset);
                                Console.WriteLine(szJson.Substring(0, (int)lResponseCharacterOffset) + "^ERROR^" + szJson.Substring((int)lResponseCharacterOffset));
                            }
                        }
                    }
                }

                // All done...
                return(true);
            }

            /// Test DNS-SD...
            if (blTestDnssd)
            {
                // Do the test...
                int tt;
                int jj;
                TwainDirectSupport.Dnssd.DnssdDeviceInfo[] adnssddeviceinfo = null;
                NativeMethods.AllocConsole();
                TwainDirectSupport.Dnssd dnssd = new TwainDirectSupport.Dnssd(TwainDirectSupport.Dnssd.Reason.Monitor);
                dnssd.MonitorStart();
                for (tt = 0; tt < 6000000; tt++)
                {
                    bool blUpdated;
                    TwainDirectSupport.Dnssd.DnssdDeviceInfo[] adnssddeviceinfoNew;
                    TwainDirectSupport.Dnssd.DnssdDeviceInfo[] adnssddeviceinfoCompare = adnssddeviceinfo;
                    adnssddeviceinfoNew = dnssd.GetSnapshot(adnssddeviceinfoCompare, out blUpdated);
                    adnssddeviceinfo    = adnssddeviceinfoNew;
                    adnssddeviceinfoNew = null;
                    if (adnssddeviceinfo == null)
                    {
                        if (blUpdated)
                        {
                            Console.Out.WriteLine("");
                            Console.Out.WriteLine("*** empty list ***");
                        }
                        System.Threading.Thread.Sleep(1000);
                        continue;
                    }
                    if (blUpdated)
                    {
                        Console.Out.WriteLine("");
                        for (jj = 0; jj < adnssddeviceinfo.Length; jj++)
                        {
                            Console.Out.WriteLine
                            (
                                adnssddeviceinfo[jj].szServiceName + Environment.NewLine +
                                "  " + adnssddeviceinfo[jj].szLinkLocal +
                                " " + adnssddeviceinfo[jj].lInterface +
                                ((adnssddeviceinfo[jj].szIpv4 == null) ? " NoIpv4" : (" " + adnssddeviceinfo[jj].szIpv4)) +
                                ((adnssddeviceinfo[jj].szIpv6 == null) ? " NoIpv6" : (" " + adnssddeviceinfo[jj].szIpv6)) +
                                " " + adnssddeviceinfo[jj].lPort +
                                ((adnssddeviceinfo[jj].aszText == null) ? "" : (Environment.NewLine + "  " + string.Join(" ", adnssddeviceinfo[jj].aszText)))
                            );
                        }
                    }
                    System.Threading.Thread.Sleep(1000);
                }
                dnssd.MonitorStop();

                // All done...
                return(true);
            }

            // Execute the specified task...
            if (File.Exists(szTaskFile))
            {
                bool      blSetAppCapabilities = false;
                Sword     sword;
                SwordTask swordtask;

                // Init stuff...
                swordtask = new SwordTask();

                // Create our object...
                sword = new Sword(null);

                // Run our task...
                sword.BatchMode(Config.Get("scanner", null), szTaskFile, false, ref swordtask, ref blSetAppCapabilities);

                // All done...
                return(true);
            }

            // Otherwise let the user interact with us...
            TWAINWorkingGroup.Log.Info("Interactive mode...");
            return(false);
        }