/// <summary> /// Take us through the signin process... /// </summary> /// <param name="a_szApiRoot">our cloud url</param> /// <param name="a_szSigninUrl">our signin url</param> /// <returns></returns> public TwainLocalScannerClient Signin(string a_szApiRoot, string a_szSigninUrl) { // Cleanup... m_twaincloudclient = null; m_twaincloudtokens = null; if (m_twainlocalscannerclient != null) { m_twainlocalscannerclient.Dispose(); m_twainlocalscannerclient = null; } // Remember stuff... m_szApiRoot = a_szApiRoot; m_szSigninUrl = a_szSigninUrl; // Signin... AutoResetEvent autoresetevent = new AutoResetEvent(false); Invoke(new MethodInvoker(delegate { FacebookLoginForm facebookloginform = new FacebookLoginForm(m_szSigninUrl); facebookloginform.Authorized += async(_, args) => { // Form goes bye-bye... facebookloginform.Close(); // Squirrel this away... m_twaincloudtokens = args.Tokens; // Put the authorization bearer token where we can get it... m_twainlocalscannerclient = new TwainLocalScannerClient(EventCallback, this, false); m_twaincloudclient = new TwainCloudClient(m_szApiRoot, m_twaincloudtokens); await m_twainlocalscannerclient.ConnectToCloud(m_twaincloudclient); m_twainlocalscannerclient.m_dictionaryExtraHeaders.Add("Authorization", m_twaincloudtokens.AuthorizationToken); autoresetevent.Set(); }; })); autoresetevent.WaitOne(); // All done... return(m_twainlocalscannerclient); }
/////////////////////////////////////////////////////////////////////////////// // Public Methods... /////////////////////////////////////////////////////////////////////////////// #region Public Methods... /// <summary> /// Init stuff... /// </summary> /// <param name="a_dnssddeviceinfo">the device we're talking to</param> /// <param name="a_twainlocalscannerclient">our interface to the scanner</param> /// <param name="a_szWriteFolder">where we get/put stuff</param> /// <param name="a_resourcemanager">for localization</param> /// <param name="a_twainlocalscannerclient">for encryptionReport</param> public FormSetup ( Dnssd.DnssdDeviceInfo a_dnssddeviceinfo, TwainLocalScannerClient a_twainlocalscannerclient, string a_szWriteFolder, ResourceManager a_resourcemanager ) { float fScale; // Init stuff... InitializeComponent(); MinimizeBox = false; MaximizeBox = false; m_dnssddeviceinfo = a_dnssddeviceinfo; m_resourcemanager = a_resourcemanager; // Handle scaling... fScale = (float)Config.Get("scale", 1.0); if (fScale <= 1) { fScale = 1; } else if (fScale > 2) { fScale = 2; } if (fScale != 1) { this.Font = new Font(this.Font.FontFamily, this.Font.Size * fScale, this.Font.Style); } // Localize... m_labelSelectDestinationFolder.Text = Config.GetResource(m_resourcemanager, "strLabelSelectImageDestination"); this.Text = Config.GetResource(m_resourcemanager, "strFormSetupTitle"); // More init stuff... m_twainlocalscannerclient = a_twainlocalscannerclient; this.FormClosing += new FormClosingEventHandler(FormSetup_FormClosing); // Location of current task... m_szCurrentTaskFile = Path.Combine(a_szWriteFolder, "currenttask"); // We're putting the tasks into the write folder... m_szTasksFolder = Path.Combine(a_szWriteFolder, "tasks"); if (!Directory.Exists(m_szTasksFolder)) { try { Directory.CreateDirectory(m_szTasksFolder); } catch (Exception exception) { Log.Error("Can't create folder <" + m_szTasksFolder + ">, so using current folder - " + exception.Message); m_szTasksFolder = Directory.GetCurrentDirectory(); } } // Restore values... m_textboxFolder.Text = RestoreFolder(); m_textboxUseUiSettings.Text = ""; if (File.Exists(m_szCurrentTaskFile)) { m_textboxUseUiSettings.Text = File.ReadAllText(m_szCurrentTaskFile); } }
public void SetTwainLocalScannerClient(TwainLocalScannerClient a_twainlocalscannerclient) { m_twainlocalscannerclient = a_twainlocalscannerclient; }
/////////////////////////////////////////////////////////////////////////////// // Public Methods... /////////////////////////////////////////////////////////////////////////////// #region Public Methods... /// <summary> /// Init stuff... /// </summary> /// <param name="a_dnssddeviceinfo">the device we're talking to</param> /// <param name="a_twainlocalscannerclient">our interface to the scanner</param> public FormSetup(Dnssd.DnssdDeviceInfo a_dnssddeviceinfo, TwainLocalScannerClient a_twainlocalscannerclient) { float fScale; string szWriteFolder; ResourceManager resourcemanager; // Init stuff... InitializeComponent(); m_dnssddeviceinfo = a_dnssddeviceinfo; // Find our write folder... szWriteFolder = Config.Get("writeFolder", ""); // Handle scaling... fScale = (float)Config.Get("scale", 1.0); if (fScale <= 1) { fScale = 1; } else if (fScale > 2) { fScale = 2; } if (fScale != 1) { this.Font = new Font(this.Font.FontFamily, this.Font.Size * fScale, this.Font.Style); } // Localize... string szCurrentUiCulture = "." + Thread.CurrentThread.CurrentUICulture.ToString(); if (szCurrentUiCulture == ".en-US") { szCurrentUiCulture = ""; } try { resourcemanager = new ResourceManager("TwainDirect.App.WinFormStrings" + szCurrentUiCulture, typeof(FormSelect).Assembly); } catch { resourcemanager = new ResourceManager("TwainDirect.App.WinFormStrings", typeof(FormSelect).Assembly); } m_labelSelectDestinationFolder.Text = resourcemanager.GetString("strLabelSelectImageDestination"); this.Text = resourcemanager.GetString("strFormSetupTitle"); // More init stuff... m_twainlocalscannerclient = a_twainlocalscannerclient; this.FormClosing += new FormClosingEventHandler(FormSetup_FormClosing); // Location of current task... m_szCurrentTaskFile = Path.Combine(szWriteFolder, "currenttask"); // We're putting the tasks into the write folder... m_szTasksFolder = Path.Combine(Path.GetDirectoryName(szWriteFolder), "tasks"); if (!Directory.Exists(m_szTasksFolder)) { try { Directory.CreateDirectory(m_szTasksFolder); } catch (Exception exception) { Log.Error("Can't create folder <" + m_szTasksFolder + ">, so using current folder - " + exception.Message); m_szTasksFolder = Directory.GetCurrentDirectory(); } } // Restore values... m_textboxFolder.Text = RestoreFolder(); m_textboxUseUiSettings.Text = ""; if (File.Exists(m_szCurrentTaskFile)) { m_textboxUseUiSettings.Text = File.ReadAllText(m_szCurrentTaskFile); } }