private void SetValue(SettingsPropertyValue propVal) { XmlElement MachineNode; XmlElement SettingNode; // Determine if the setting is roaming. // If roaming then the value is stored as an element under the root // Otherwise it is stored under a machine name node try { if (IsRoaming(propVal.Property)) { SettingNode = (XmlElement)SettingsXML.SelectSingleNode(SettingsRootNode + "/" + propVal.Name); } else { SettingNode = (XmlElement)SettingsXML.SelectSingleNode(SettingsRootNode + "/" + Environment.MachineName + "/" + propVal.Name); } } catch (Exception) { SettingNode = null; } // Check to see if the node exists, if so then set its new value if (SettingNode != null) { SettingNode.InnerText = propVal.SerializedValue.ToString(); } else if (IsRoaming(propVal.Property)) { // Store the value as an element of the Settings Root Node SettingNode = SettingsXML.CreateElement(propVal.Name); SettingNode.InnerText = propVal.SerializedValue.ToString(); SettingsXML.SelectSingleNode(SettingsRootNode).AppendChild(SettingNode); } else { // Its machine specific, store as an element of the machine name node, // creating a new machine name node if one doesnt exist. try { MachineNode = (XmlElement)SettingsXML.SelectSingleNode(SettingsRootNode + "/" + Environment.MachineName); } catch (Exception) { MachineNode = SettingsXML.CreateElement(Environment.MachineName); SettingsXML.SelectSingleNode(SettingsRootNode).AppendChild(MachineNode); } if (MachineNode == null) { MachineNode = SettingsXML.CreateElement(Environment.MachineName); SettingsXML.SelectSingleNode(SettingsRootNode).AppendChild(MachineNode); } SettingNode = SettingsXML.CreateElement(propVal.Name); SettingNode.InnerText = propVal.SerializedValue.ToString(); MachineNode.AppendChild(SettingNode); } }
//------------------------------------------------------------------------------ // Creates machineNodes which are representative of the quarters given through // preferences. For example: if 8 quarters are declared, 8 machineNodes are // created. //------------------------------------------------------------------------------ protected void InitializeMachineNodes() { for (int i = 0; i < MaxYearLength; i++) { for (int j = 0; j < MaxQuarters; j++) { MachineNode m = new MachineNode(i, j); Quarters.Add(m); } } }
//------------------------------------------------------------------------------ // AN ERROR CHECKING METHOD TO PREVENT CLASSES FROM HAPPENING DURING THE SAME TIME // check to see if a job overlaps with another job's times in a single // MachineNode; can't be in 2 places at once you know? //------------------------------------------------------------------------------ protected bool Overlap(Job j, Machine goal, MachineNode mn) { bool flag = false; //Defaulted to continue //need list of all the start and end times from goal List <DayTime> dt = goal.GetDateTime(); List <Machine> myMachines = mn.GetAllScheduledMachines(); //Look for Scheduled Courses in All Quarters for (int i = 0; i < myMachines.Count; i++) { Machine m = myMachines[i]; List <DayTime> tempDT = m.GetDateTime(); //Each class is available for the same amount of days if (dt.Count == tempDT.Count) { for (int k = 0; k < dt.Count; k++) { //Checks to see if the start time or end time exists between the start and end of a scheduled course if ((dt[k].GetStartTime() >= tempDT[k].GetStartTime() && dt[k].GetStartTime() <= tempDT[k].GetEndTime()) || (dt[k].GetEndTime() >= tempDT[k].GetStartTime() && dt[k].GetEndTime() <= tempDT[k].GetEndTime())) { flag = true; } } } else { int min = Math.Min(dt.Count, tempDT.Count); //Which class starts earlier //Compares the courses for the day they are taken on if (dt.Count == min) { flag = compareDays(dt, tempDT); } else { flag = compareDays(tempDT, dt); } if (flag) { return(flag); } } } return(flag); }
protected void ScheduleCourse(Job j) { if (IsScheduled(j)) { return; } //we're always being called in order, no need to check for prereqs for (int i = 0; i < Quarters.Count; i++) { MachineNode mn = Quarters[i]; // Check the number of credits scheduled per quarter make sure it does not exceed preference. // Check the number of core credits scheduled per quarter make sure it does not exceed preference. // TODO: Add a default case. What if they dont have a preference should we assign all their classes in one quarter? // Probably not... //System.Diagnostics.Debug.WriteLine("NUM OF CREDITS FOR JOB: " + j.GetNumCredits() + " CORE COURSE: " + j.GetCoreCourse()); if (mn.GetCreditsScheduled() + j.GetNumCredits() > StudentPreferences.getCreditsPerQuarter() || (j.GetCoreCourse() && j.GetNumCredits() + mn.GetMajorCreditsScheduled() > StudentPreferences.getCoreCredits())) { continue; } List <Machine> machines = mn.GetMachines(); for (int k = 0; k < machines.Count; k++) { //<<----------------------------INSERT DAY/TIME PREFERENCE AND CHECK AGAINST IT Machine m = machines[k]; if (m.CanDoJob(j) && !m.CheckInUse()) { //if not in use and it can do the job if (Overlap(j, m, mn)) { //can't schedule it if the times overlap even if machine found continue; } m.SetCurrentJobProcessing(j); m.SetInUse(true); j.SetScheduled(true); j.SetQuarterScheduled(m.GetQuarter()); j.SetYearScheduled(m.GetYear()); // Need to update the machine node such that it reflects the new amount of credits, core credits, etc. //mn.AddClassesScheduled(1); mn.AddClassesScheduled(j); Schedule.Add(m); return; } } } }
//------------------------------------------------------------------------------ // HELPER FUNCTION FOR INITMACHINES() // // Adds a machine to the machine list for offered courses by first doing a search // amongst the machineNodes if the Course already exists there and acts // accordingly. //------------------------------------------------------------------------------ void addMachine(Machine dummyMachine, Job job) { dummyMachine.AddJob(job); //adds job for (int i = 0; i < Quarters.Count; i++) { MachineNode mn = Quarters[i]; List <Machine> machines = mn.GetMachines(); if (machines.Count > 0) { for (int j = 0; j < machines.Count; j++) { Machine m = machines[j]; if (m == dummyMachine) { //found the machine, just add job m.AddJob(job); break; } else if (dummyMachine.GetYear().Equals(mn.GetYear()) && dummyMachine.GetQuarter().Equals(mn.GetQuarter())) { //machine does not exist, add it in machines.Add(dummyMachine); break; } } } else if (dummyMachine.GetYear().Equals(mn.GetYear()) && dummyMachine.GetQuarter().Equals(mn.GetQuarter())) { machines.Add(dummyMachine); break; } else //in the instance that machines == 0 and either year or quarter were different { //NOTE: This isn't so much an error as a bookkeeping check. Because CourseTime contains only 1 year // machines dated beyond the first year throw this error. So this is a database issue. /* * Console.WriteLine("Dummy Machine Year: " + dummyMachine.GetYear()); * Console.WriteLine("Dummy Machine Quarter: " + dummyMachine.GetQuarter()); * Console.WriteLine("Dummy Course ID: " + course); * Console.WriteLine("mn Year: " + mn.GetYear()); * Console.WriteLine("mn Quarter: " + mn.GetQuarter()); * Console.WriteLine('\n'); */ } } }
}// GetNodeIndexNumber internal CSinglePermissionSet AddPermissionSet(PolicyLevel pl, NamedPermissionSet ps) { // Find the policy level we're after if (UserNode.MyPolicyLevel == pl) { return(UserNode.AddPermissionSet(ps)); } else if (MachineNode.MyPolicyLevel == pl) { return(MachineNode.AddPermissionSet(ps)); } else if (EnterpriseNode.MyPolicyLevel == pl) { return(EnterpriseNode.AddPermissionSet(ps)); } else { throw new Exception("I don't know about this policy level"); } }// AddPermissionSet
//------------------------------------------------------------------------------ // WARNING!!! - This function can overwrite information. PLEASE READ // // This makes the list of classes available over successive years. Current data // being used is for the duration of one year, therefore this function sets up // the machineNodes in such a way they work off the assumption that classes // will be held at the same time, on the same days, year after year. //------------------------------------------------------------------------------ void normalizeMachines() { //transfer all the same classes to the set of machine nodes if (quarters >= yearlength) { for (int i = yearlength; i < quarters; i++) { MachineNode oldMn = Quarters[i % yearlength]; MachineNode newMn = Quarters[i]; for (int j = 0; j < oldMn.GetMachines().Count; j++) { Machine oldMachine = oldMn.GetMachines()[j]; Machine newMachine = new Machine(oldMachine); newMachine.SetYear(i / yearlength); newMn.AddMachine(newMachine); } } return; } else { return; } }
} // End Function private static void SetValue(SettingsPropertyValue propVal) { Xml.XmlElement MachineNode; Xml.XmlElement SettingNode; // Determine if the setting is roaming. // If roaming then the value is stored as an element under the root // Otherwise it is stored under a machine name node try { if (IsRoaming(propVal.Property)) { SettingNode = DirectCast(SettingsXML.SelectSingleNode(SETTINGSROOT & "/" & propVal.Name), XmlElement); } else { SettingNode = DirectCast(SettingsXML.SelectSingleNode(SETTINGSROOT & "/" & My.Computer.Name & "/" & propVal.Name), XmlElement); } // End If } catch (Exception ex) { SettingNode = Nothing; } //End Try-Catch // Check to see if the node exists, if so then set its new value if (!SettingNode == null) { SettingNode.InnerText = propVal.SerializedValue.ToString; } else { if (IsRoaming(propVal.Property)) { // Store the value as an element of the Settings Root Node SettingNode = SettingsXML.CreateElement(propVal.Name); SettingNode.InnerText = propVal.SerializedValue.ToString; SettingsXML.SelectSingleNode(SETTINGSROOT).AppendChild(SettingNode); } else { // Its machine specific, store as an element of the machine name node, // creating a new machine name node if one doesnt exist. try { MachineNode = DirectCast(SettingsXML.SelectSingleNode(SETTINGSROOT & "/" & My.Computer.Name), XmlElement); } catch (Exception ex) { MachineNode = SettingsXML.CreateElement(My.Computer.Name); SettingsXML.SelectSingleNode(SETTINGSROOT).AppendChild(MachineNode); } // End Try-Catch if (MachineNode == null) { MachineNode = SettingsXML.CreateElement(My.Computer.Name); SettingsXML.SelectSingleNode(SETTINGSROOT).AppendChild(MachineNode); } // End If SettingNode = SettingsXML.CreateElement(propVal.Name); SettingNode.InnerText = propVal.SerializedValue.ToString; MachineNode.AppendChild(SettingNode); } // End If } // End If } // End Sub
}// AddMenuItems internal override void MenuCommand(int iCommandID) { // All these menu commands are going to require the policy nodes to be created and expanded. // Let's check to see if we've done that already.... if (NumChildren == 0) { CNodeManager.CNamespace.Expand(HScopeItem); } if (iCommandID == COMMANDS.NEW_SECURITYPOLICY) { CNewSecurityPolicyDialog nspd = new CNewSecurityPolicyDialog(); System.Windows.Forms.DialogResult dr = nspd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { // To get a 'New' Security policy, we just load a policy from a file that doesn't exist CSecurityPolicy secpolnode = GetSecurityPolicyNode(nspd.SecPolType); // Ok, this is really dumb. I need to create a security file where the user // wants to store the policy before I can tell the Security Manager about it. File.Copy(secpolnode.MyPolicyLevel.StoreLocation, nspd.Filename, true); PolicyLevel pl = SecurityManager.LoadPolicyLevelFromFile(nspd.Filename, nspd.SecPolType); pl.Reset(); secpolnode.SetNewSecurityPolicyLevel(pl); secpolnode.SecurityPolicyChanged(); // Select the policy node the user just mucked with CNodeManager.SelectScopeItem(secpolnode.HScopeItem); } } else if (iCommandID == COMMANDS.OPEN_SECURITYPOLICY) { COpenSecurityPolicyDialog ospd = new COpenSecurityPolicyDialog(new String[] { EnterpriseNode.ComputerPolicyFilename, MachineNode.ComputerPolicyFilename, UserNode.ComputerPolicyFilename }); System.Windows.Forms.DialogResult dr = ospd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { // Try and load the given security policy PolicyLevel pl; try { pl = SecurityManager.LoadPolicyLevelFromFile(ospd.Filename, ospd.SecPolType); } catch { MessageBox(String.Format(CResourceStore.GetString("CGenSecurity:isNotASecurityFile"), ospd.Filename), CResourceStore.GetString("CGenSecurity:isNotASecurityFileTitle"), MB.ICONEXCLAMATION); return; } CSecurityPolicy secpolnode = GetSecurityPolicyNode(ospd.SecPolType); secpolnode.SetNewSecurityPolicyLevel(pl); // Select the policy node the user just mucked with CNodeManager.SelectScopeItem(secpolnode.HScopeItem); } } else if (iCommandID == COMMANDS.EVALUATE_ASSEMBLY) { CWizard wiz = new CEvalAssemWizard(); wiz.LaunchWizard(Cookie); } else if (iCommandID == COMMANDS.TRUST_ASSEMBLY) { // Let's create a new wizard now to dump any old settings we have CFullTrustWizard wiz = new CFullTrustWizard(MachineNode.ReadOnly, UserNode.ReadOnly); wiz.LaunchWizard(Cookie); // See if it updated anything a codegroup if (wiz.MadeChanges) { CSecurityPolicy sp = GetSecurityPolicyNode(Security.GetPolicyLevelTypeFromLabel(wiz.PolLevel.Label)); sp.RedoChildren(); sp.SecurityPolicyChanged(); } } else if (iCommandID == COMMANDS.ADJUST_SECURITYPOLICY) { CSecurityAdjustmentWizard wiz = new CSecurityAdjustmentWizard(MachineNode.ReadOnly, UserNode.ReadOnly); wiz.LaunchWizard(Cookie); // Check to see if we need to tell any policies that we changed them if (wiz.didUserPolicyChange) { UserNode.RedoChildren(); UserNode.SecurityPolicyChanged(); } if (wiz.didMachinePolicyChange) { MachineNode.RedoChildren(); MachineNode.SecurityPolicyChanged(); } } else if (iCommandID == COMMANDS.CREATE_MSI) { CWizard wiz = new CCreateDeploymentPackageWizard(this); wiz.LaunchWizard(Cookie); } else if (iCommandID == COMMANDS.RESET_POLICY) { int nRes = MessageBox(CResourceStore.GetString("CGenSecurity:ConfirmResetAll"), CResourceStore.GetString("CGenSecurity:ConfirmResetAllTitle"), MB.YESNO | MB.ICONQUESTION); if (nRes == MB.IDYES) { if (!EnterpriseNode.ReadOnly) { EnterpriseNode.ResetSecurityPolicy(); } if (!MachineNode.ReadOnly) { MachineNode.ResetSecurityPolicy(); } if (!UserNode.ReadOnly) { UserNode.ResetSecurityPolicy(); } MessageBox(CResourceStore.GetString("CGenSecurity:PoliciesResetAll"), CResourceStore.GetString("CGenSecurity:PoliciesResetAllTitle"), MB.ICONINFORMATION); } } }// MenuCommand
private void SetValue(SettingsPropertyValue propVal) { System.Xml.XmlElement MachineNode; System.Xml.XmlElement SettingNode; //Determine if the setting is roaming. //If roaming then the value is stored as an element under the root //Otherwise it is stored under a machine name node try { if (IsRoaming(propVal.Property)) { SettingNode = (XmlElement) (SettingsXML.SelectSingleNode( System.Convert.ToString(SETTINGSROOT + "/" + propVal.Name))); } else { SettingNode = (XmlElement) (SettingsXML.SelectSingleNode( System.Convert.ToString(SETTINGSROOT + "/" + (new Microsoft.VisualBasic.Devices.Computer()).Name + "/" + propVal.Name))); } } catch (Exception) { SettingNode = null; } //Check to see if the node exists, if so then set its new value if (SettingNode != null) { if (propVal.SerializedValue != null) { SettingNode.InnerText = propVal.SerializedValue.ToString(); } } else { if (IsRoaming(propVal.Property)) { //Store the value as an element of the Settings Root Node SettingNode = SettingsXML.CreateElement(propVal.Name); if (propVal.SerializedValue != null) { SettingNode.InnerText = propVal.SerializedValue.ToString(); } var selectSingleNode = SettingsXML.SelectSingleNode(SETTINGSROOT); if (selectSingleNode != null)//ToDO: What if Null? { selectSingleNode.AppendChild(SettingNode); } } else { //Its machine specific, store as an element of the machine name node, //creating a new machine name node if one doesnt exist. try { MachineNode = (XmlElement) (SettingsXML.SelectSingleNode( System.Convert.ToString(SETTINGSROOT + "/" + (new Microsoft.VisualBasic.Devices.Computer()).Name))); } catch (Exception) { MachineNode = SettingsXML.CreateElement((new Microsoft.VisualBasic.Devices.Computer()).Name); SettingsXML.SelectSingleNode(SETTINGSROOT.ToString()).AppendChild(MachineNode); } if (MachineNode == null) { MachineNode = SettingsXML.CreateElement((new Microsoft.VisualBasic.Devices.Computer()).Name); SettingsXML.SelectSingleNode(SETTINGSROOT.ToString()).AppendChild(MachineNode); } SettingNode = SettingsXML.CreateElement(propVal.Name); if (propVal.SerializedValue != null) { SettingNode.InnerText = propVal.SerializedValue.ToString(); } MachineNode.AppendChild(SettingNode); } } }
public MachineNode(MachineNode node) { this.uri = node.uri; this.backsUp = new List <string>(node.backsUp); this.primaryOf = new List <string>(node.primaryOf); }