public CLI(Org org) { _org = org; currentEmployee = null; logoutFlag = false; QUIT_INFO_PROMPT = "Press " + QUIT_FULL + " or " + QUIT_SHORT + " at any time to exit."; initOptions(); }
private bool Construct() { string[] splat; string line, name, prefix; bool firstLine = true; int depth = 0; int depthDiff = 0; President president; Employee parent = null; Employee hiree = null; lineNumber = 0; line = name = prefix = ""; while((line = _sr.ReadLine()) != null){ lineNumber++;//increment the line count line = line.Trim(); if(!ValidatePrefixIndent(line)){ return SetError("Wrong number of indents"); } if(line == ""){ continue; } splat = line.Split(':'); if(splat.Length != 2){ return SetError("Improperly formatted line."); } depth = splat[0].Length-1; prefix = splat[0][depth].ToString().Trim(); name = splat[1].Trim(); if(!ValidateName(name)){ return SetError(INVALID_NAME); } depthDiff = _prefixStack.Count - depth; if(depthDiff > 0){ _prefixStack.RemoveRange(_prefixStack.Count-depthDiff, depthDiff); _parentStack.RemoveRange(_parentStack.Count-depthDiff, depthDiff); }else if(depthDiff < 0){ //if the depth isn't different, the previously pushed role // will have the same parent as the current role, SetError // pop the last elem return SetError(SKIPPED_DEPTH); } hiree = Util.EmployeeFromPrefix(prefix, name); if(firstLine){ if(prefix != "P"){ return SetError(INVALID_INIT_PREFIX+prefix); } firstLine = false; //initialize the org org = new Org(hiree); }else{ //validate based on last prefix if(!ValidateParent(prefix)){ return false; } //attempt to add the name to the org org.AddName(name);//will throw OrgException if name exists //otherwise add the current employee under it's parent if(!LastParent().Hire(hiree)){ return SetError(BAD_HIREE+": \n\t\"" +name+"\" is a "+Util.GetRoleString(Util.RoleFromPrefix(prefix)) +"\n\t with parent \""+LastParent().Name+"\" who is a " +Util.GetRoleString(LastParent().Position)); } } _parentStack.Add(hiree); _prefixStack.Add(prefix); } return true; }