/// <summary> /// Gets the log file directory and ensures it is writeable. /// </summary> public static string GetLogFileDirectory() { // try the program data directory. string logFileDirectory = ApplicationData.Current.LocalFolder.Path; logFileDirectory += "\\OPC Foundation\\Logs"; try { // create the directory. if (!Directory.Exists(logFileDirectory)) { Directory.CreateDirectory(logFileDirectory); } // ensure everyone has write access to it. List <ApplicationAccessRule> rules = new List <ApplicationAccessRule>(); ApplicationAccessRule rule = new ApplicationAccessRule(); rule.IdentityName = WellKnownSids.Users; rule.Right = ApplicationAccessRight.Configure; rule.RuleType = AccessControlType.Allow; rules.Add(rule); rule = new ApplicationAccessRule(); rule.IdentityName = WellKnownSids.NetworkService; rule.Right = ApplicationAccessRight.Configure; rule.RuleType = AccessControlType.Allow; rules.Add(rule); rule = new ApplicationAccessRule(); rule.IdentityName = WellKnownSids.LocalService; rule.Right = ApplicationAccessRight.Configure; rule.RuleType = AccessControlType.Allow; rules.Add(rule); ApplicationAccessRule.SetAccessRules(logFileDirectory, rules, false); } catch (Exception) { // try the MyDocuments directory instead. logFileDirectory = ApplicationData.Current.LocalFolder.Path; logFileDirectory += "OPC Foundation\\Logs"; if (!Directory.Exists(logFileDirectory)) { Directory.CreateDirectory(logFileDirectory); } } return(logFileDirectory); }
private void OkBTN_Click(object sender, EventArgs e) { try { IList <ApplicationAccessRule> rules = AccessRulesCTRL.GetAccessRules(); ApplicationAccessRule.SetAccessRules(ObjectPathTB.Text, rules, true); AccessRulesCTRL.Initialize((SecuredObject)ObjectTypeCB.SelectedItem, ObjectPathTB.Text); if (sender == OkBTN) { DialogResult = DialogResult.OK; } } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }
private void ApplyAllBTN_Click(object sender, EventArgs e) { try { StringBuilder buffer = new StringBuilder(); buffer.Append("The following objects will be affected:"); buffer.Append("\r\n\r\n"); foreach (SecuredObject objectType in ObjectTypeCB.Items) { buffer.Append(objectType); buffer.Append("\r\n"); } buffer.Append("\r\n"); buffer.Append("Are you sure you would like to apply access control changes to all of the objects listed above?"); if (new YesNoDlg().ShowDialog(buffer.ToString(), "Confirm Access Rule Changes") != DialogResult.Yes) { return; } IList <ApplicationAccessRule> rules = AccessRulesCTRL.GetAccessRules(); for (int ii = 0; ii < m_objectPaths.Count; ii++) { ApplicationAccessRule.SetAccessRules(m_objectPaths[ii], rules, true); } AccessRulesCTRL.Initialize((SecuredObject)ObjectTypeCB.SelectedItem, ObjectPathTB.Text); } catch (Exception exception) { GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception); } }