private ICAConfig BuildConfiguration(IProjection <ICell> grid) { CAConfig configuration = new CAConfig(_memory.GetObjects().Count, grid.GetObjects()[0].GetDefaultState()); foreach (ICell cell in grid.GetObjects()) { configuration.AddCellState(cell, cell.GetState()); } return(configuration); }
//private static Token newLine = new Token("\n"); /** * <returns> IPattern </returns> */ public Object Parse(ITokenStream tokenStream) { Token token; CAConfig pattern = new CAConfig(0, null); //LivingCell.DeadState);//Determine the size of the configuration! //CellState[,] patternState = new CellState[,]; IList <IList <CellState> > rows = new List <IList <CellState> >(); IList <CellState> row = null; Boolean rowOpened = false; int rowIndex = 0; int columnIndex = 0; while ((token = tokenStream.NextToken()) != null) { if (token.Equals(stateSeparator)) { //token=tokenStream.NextToken(); //do nothing } else if (token.Equals(rowStart)) //init a new row { if (rowOpened) { throw new InvalidOperationException(string.Format("Missing enclosing bracket! Please, enclose the row, before creating a new one")); } row = new List <CellState>(); rowOpened = true; rowIndex++; columnIndex = 0; } else if (token.Equals(rowEnd)) //add the existing row to the list of rows { rows.Add(row); rowOpened = false; } else if (!char.IsWhiteSpace(token.ToString(), 0)) //State Token { if (row == null || !rowOpened) { throw new InvalidOperationException("You should define a cell state within a Row. Use the following format: {D,A,D,D} "); } CellState cellState = null;//CellState.ValueOf(token.ToString()); row.Add(cellState); pattern.AddCellState(null, cellState); columnIndex++; } } return(pattern); }
//private ICAConfig CreateICAConfig(IList<On3dPoint> latticePoints, IList<On3dPoint> configurationPoints) //creates an ICAConfig instance out of the OpenNurbs state configuration private ICAConfig CreateICAConfig(OnStateConfig stateConfig) { CAConfig cfg = new CAConfig(0, cellPrototype.GetState()); int latticePointIndex = 0; foreach (Point3d latticePoint in pointLattice) { foreach (Point3d configurationPoint in stateConfig.GetPoints()) { if (latticePoint.X == configurationPoint.X && latticePoint.Y == configurationPoint.Y && latticePoint.Z == configurationPoint.Z) { cfg.AddCellState(cellularGrid.GetObject(latticePointIndex), stateConfig.GetState()); } } latticePointIndex++; }//foreach return(cfg); }
/** * The CA evolves to a new state, according to the behavior of each cell. * The old generations is archieved in the list of generations */ public ICAConfig Update() { currentTime++; CAConfig nextConfiguration = new CAConfig(_memory.GetObjects().Count, grid.GetObjects()[0].GetDefaultState()); foreach (ICell cell in grid.GetObjects()) { //do not alter the cells' states directly //as the states affect the evolution //the result of the evolution is saved //and the cells are updated when all cells evolved CellState evolvedCellState = cell.UpdateState(); nextConfiguration.AddCellState(cell, evolvedCellState); } //update the cells's states according to the evolution foreach (ICell cell in grid.GetObjects()) { cell.SetState(nextConfiguration.GetCellState(cell)); } return(nextConfiguration); }
private void butCreate_Click(object sender, EventArgs e) { CAConfig caConfig; // Assemble all the info try { caConfig = new CAConfig() { name = tbName.Text, DN = new X509Name(true, tbDN.Text), // 'true' reverses the name to have C= on the left profile = profile, profileFile = profileFile, pkAlgo = pkAlgo, pkSize = pkSize, sigAlgo = sigAlgo + pkAlgo, keyUsage = 0x06, // Hardwired to CertSign|CRLSign per RFC 5280 version = version, life = Convert.ToInt32(tbCertValid.Text), units = lbCertUnits.Text, location = tbFolder.Text, crlInterval = Convert.ToInt32(tbCRLInterval.Text) }; } catch (Exception ex) { MessageBox.Show("Error " + ex.Message, "Create CA", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cbFIPS.Checked) { if (rbTA.Checked) { caConfig.caType = CA_Type.dhTA; } else if (!rbECDSA.Checked) { caConfig.caType = CA_Type.sysCA; } else { caConfig.caType = CA_Type.cngCA; } caConfig.FIPS140 = true; } else { if (rbTA.Checked) { MessageBox.Show("CA of type TA is only supported with FIPS crypto", "Create CA", MessageBoxButtons.OK, MessageBoxIcon.Hand); DialogResult = DialogResult.Cancel; } caConfig.caType = CA_Type.bcCA; caConfig.FIPS140 = false; // Set a password Setpassword password = new Setpassword(); if (password.ShowDialog() == DialogResult.OK) { caConfig.password = password.tbPassword.Text; } else { // Abort DialogResult = DialogResult.Cancel; } } // Now lets create the CA CA newCA = new CA(); // Create the profiles directory Directory.CreateDirectory(tbFolder.Text + "\\Profiles"); switch (caConfig.profile) { case CA_Profile.rootCA: newCA.CaName = caConfig.name; newCA.Role = "rootCA"; // Create the CA newCA.ConfigLocation = CaFactory.CreateRootCA(caConfig); break; case CA_Profile.SubCA: // find the CA entry CA issuingCA = mgrConfig.CaList.Find(m => m.CaName == lbIssuingCA.Text); if (issuingCA.CaControl.CAStatus == CAstatus.Stopped) { MessageBox.Show("Issuing CA is STOPPED", "Create CA", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } //find the Profile entry ProfileDb profile = issuingCA.CaControl.Profiles.Find(m => m.profile.Name == lbProfile.Text); caConfig.profileFile = profile.file; // populate the CA entry newCA.CaName = caConfig.name; newCA.Role = "subCA"; // Create the CA try { newCA.ConfigLocation = CaFactory.CreateSubCA(caConfig, issuingCA.CaControl); } catch (Exception ex) { MessageBox.Show("There was a problem: " + ex.Message, "OSCA - Issue Certificate", MessageBoxButtons.OK, MessageBoxIcon.Error); butCancel_Click(null, null); } break; } // Add the new CA into the list mgrConfig.InsertCA(newCA); DialogResult = DialogResult.OK; }