Yeey!!! I completed "Introduction to Databases" from Stanford Online (last March 15, 2014)!
"Introduction to Databases" About page:
// Runs an infinite loop that listens to the keyboard input. // When a key is pressed (any key), the program blackens the screen, // i.e. writes "black" in every pixel. When no key is pressed, the // program clears the screen, i.e. writes "white" in every pixel. // (RESET_SCREEN_COUNTER) // @SCREEN // D=A // @counter // M=D // counter = SCREEN (LISTEN_FOR_NO_KEY_PRESS) // reset screen counter @SCREEN D=A @counter M=D // if KBD == 0 jump to CLEAR_SCREEN @KBD D=M @CLEAR_SCREEN D;JEQ // loop (keep on checking if KBD == 0 @LISTEN_FOR_NO_KEY_PRESS 0;JEQ (LISTEN_FOR_KEY_PRESS) // reset screen counter @SCREEN D=A @counter M=D // if KBD > 0 jump to BLACKEN_SCREEN @KBD D=M @BLACKEN_SCREEN D;JGT // loop (keep on checking if KBD > 0 @LISTEN_FOR_KEY_PRESS 0;JEQ (BLACKEN_SCREEN) // blacken 16-bit memory location @counter A=M // A = counter M=-1 // blacken current memory location // if KBD == 0 jump to LISTEN_FOR_NO_KEY_PRESS (to reset counter) @KBD D=M @LISTEN_FOR_NO_KEY_PRESS D;JEQ // increment counter @counter M=M+1 // check if you have reached memory location 24575 (the final address for the screen) D=M @24575 D=A-D @LISTEN_FOR_NO_KEY_PRESS D;JLT // goto LISTEN_FOR_NO_KEY_PRESS if counter > 24575 // loop BLACKEN_SCREEN if you have NOT reached memory location 24575 @BLACKEN_SCREEN 0;JEQ (CLEAR_SCREEN) // clear 16-bit memory location @counter A=M // A = counter M=0 // clear current memory location // if KBD > 0 jump to LISTEN_FOR_KEY_PRESS (to reset counter) @KBD D=M @LISTEN_FOR_KEY_PRESS D;JGT // increment counter @counter M=M+1 // check if you have reached memory location 24575 (the final address for the screen) D=M @24575 D=A-D @LISTEN_FOR_KEY_PRESS D;JLT // goto LISTEN_FOR_KEY_PRESS if counter > 24575 // loop CLEAR_SCREEN if you have NOT reached memory location 24575 @CLEAR_SCREEN 0;JEQ
X509CertificateCollection certificateCollection = X509Certificate2UI.SelectFromCollection( store.Certificates, "Caption", "Message", X509SelectionFlag.SingleSelection);
WindowInteropHelper windowHwnd =new WindowInteropHelper(this); IntPtr hWnd = windowHwnd.Handle; X509CertificateCollection certificateCollection = X509Certificate2UI.SelectFromCollection( store.Certificates, "Caption", "Message", X509SelectionFlag.SingleSelection, hWnd);
<Window ... Name="TheMainWindow" DataContext="{Binding Main, Source={StaticResource Locator}}"> <Button Command="{Binding SelectCertificateCommand}" CommandParameter="{Binding ElementName=TheMainWindow}" Content="Select Certificate From the Store" /> </Window>
public class MainViewModel : ViewModelBase { private X509Certificate2 _selectedCertificate; public ICommand SelectCertificateCommand { get; private set; } public MainViewModel() { this.SelectCertificateCommand = new RelayCommand( (window) => { X509Certificate2 cert = PickCertificate(StoreLocation.CurrentUser, StoreName.My, window); if (cert != null) { this.Certificate = cert; } }); } public X509Certificate2 Certificate { get { return _selectedCertificate; } set { if (_selectedCertificate == value) { return; } _selectedCertificate = value; RaisePropertyChanged(() => Certificate); } } private static X509Certificate2 PickCertificate(StoreLocation location, StoreName name, Window window) { X509Store store = new X509Store(name, location); try { store.Open(OpenFlags.ReadOnly); // pick a certificate from the store X509Certificate2 certificate = null; X509CertificateCollection certificateCollection = X509Certificate2UI.SelectFromCollection( store.Certificates, "Select a certificate", "Select a certificate", X509SelectionFlag.SingleSelection, new WindowInteropHelper(window).Handle); if (certificateCollection.Count > 0) { certificate = (X509Certificate2)certificateCollection[0]; } return certificate; } finally { store.Close(); } } }