Creation of log file on user choice [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
We have a console application name JetIDR. Where we are using log4net for logging log . THis application are currently creating 2 log file JetIDR-INFO.LOG and JetIDR-Debug.LOG .We want to enhance out application to support flexibility on creating log file as below.
Command line parameter should be named as -log
Valid parameter for -loglevel are 1 and 2 only
When parameter 1 is used with -loglevel JetIDR-INFO.LOG file should get created
When parameter 2 is used with -loglevel then JetIDR-INFO.LOG & JetIDR-DEBUG.LOG file should get created
We need to do it in C#.

Your question is effectively "how do I conditionally suppress output to an appender?", where the condition is "If the -loglevel is 1, don't write to the debug logs."
The code would then look like this:
if (logLevel == 1)
{
// assuming appender name is DebugAppender and it is a FileAppender
var appender = log4net.LogManager.GetRepository()
.GetAppenders()
.OfType<FileAppender>()
.SingleOrDefault(a => a.Name == "DebugAppender");
if (appender != null)
{
// Disable the appender
appender.Threshold = Level.Off;
appender.ActivateOptions();
}
}
Note however that if the appender is defined in configuration, the log file is created when log4net is configured: this code thus cannot stop the file from being created, but it will suppress logging to the file.

Related

MPXJ C# MSPID: Mark task as done (100% complete) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
We're using the C# version of MPXJ, but rather than examining an existing Project file we're using it to produce a new file purely from code (extracting data from a third party system) for import to Project via MSPDIWriter.
The goal is to have Tasks that report as completed in the other system show up with 100% completion and the ✔ checkmark next to them on the Gantt view when the XML is loaded in Project. This is working as expected only when the total Duration assigned to a task is zero days; for any other duration when Project opens the Task's percentage complete is set to 0%.
Our devs aren't Project people, so it's not clear to us which properties will affect this behaviour:
Task childTask = parent.AddTask();
childTask.Name = sourceItem.Title;
Duration duration = Duration.getInstance(sourceItem.Days, TimeUnit.DAYS);
childTask.PercentageComplete = new java.lang.Integer(childItem.PercentageComplete);
childTask.PercentageWorkComplete = childTask.PercentageComplete;
ResourceAssignment assignment = childTask.AddResourceAssignment(resource);
assignment.Work = duration;
assignment.RemainingWork = duration;
assignment.percentageWorkComplete = childTask.PercentageComplete;
childTask.EffortDriven = false;
childTask.Priority = childItem.Priority;
childTask.Duration = duration;
childTask.BaselineDuration = duration;
if (childItem.PercentComplete == 100)
{
childTask.RemainingWork = Duration.getInstance(0, TimeUnit.DAYS);
}
This sample code works through the steps to create a file from scratch with various combinations of un-started, partially complete, and completed tasks both with and without resource assignments. There is a C# version but I must admit that I haven't kept the two in line. The Java version is probably the more complete, hopefully it should be fairly straightforward to get a working C# version.
I'd suggest starting with these samples and generate MSPDI files from them first, verifying that you get the expected result when the files are imported into MS Project. Hopefully you'll then be able to update your code based on the approach taken in the sample files.
One thing to watch for is that there were some improvements made recently to MSPDI generation relating to getting percent complete to appear correctly so it would be worth verifying that you are working with the most recent version of MPXJ (7.9.2 at the time of writing).

Selenium C# Interact with Chrome Microphone Window [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have an application that when initiated, I receive the popup that "https://example.com wants to:"
"Use your microphone"
I have looked at autoit but it has not been helping. I was trying to use an x/y coordinate but no luck. The autoit window info gives me a name and a class but button info is not there.
Anyone have a way around this issue?
Works perfectly:
$WinTitle = "[CLASS:Chrome_WidgetWin_1]"
WinWait($WinTitle)
WinActivate($WinTitle)
ControlSend($WinTitle, "", "", "{TAB}{ENTER}")
Here is how I got around it using AutoIT. Remove one of the Send("+{TAB}") to set it to Block. I tried removing both of these and just using the enter for Allow but it did not work.
Allow Microphone for Chrome:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=chromeClickAllow.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Sleep(2000)
WinActivate("Tabs Outliner")
WinWait("[CLASS:Chrome_WidgetWin_1]")
Sleep(500)
WinActivate("[CLASS:Chrome_WidgetWin_1]")
Send("+{TAB}")
Send("+{TAB}")
Send("{ENTER}")

System.ServiceModel.FaultException in WCF service [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a WCF service which worked fine til today, an exception System.ServiceModel.FaultException was thrown, when i call a method of the this service.
using (EService = new FaService.EServiceClient())
{
DataSet ds = EService.GetCompanies(3375); // exception here
DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
{
Companies.Add(new Company() { Name = dr["c0"].ToString() });
}
}
In a service, the FaultException class is used to create an untyped fault to return to the client for debugging purposes. It really handles generic or "unknown" faults in a process in the program/client. You can pinpoint the error down to a line and typically can just debug your system/program/client to find where this "unknown" error is occurring. It may be helpful to post this method's code in which you are having issues, but as for your post thus far, I would debug your program and step line by line to make sure there isn't any unnecessary lines of code.
Reference: http://msdn.microsoft.com/en-us/library/system.servicemodel.faultexception(v=vs.110).aspx

Store data in C# application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a message prompting the user to upgrade some equipment connected to the computer. I want to let the user disable this message in the future, by checking a box before pressing cancel.
How can I store this user option, so that next time the program executes I can avoid showing this message based on the user choice made in the last session of the application?
The two cleanest ways are the Registry and User Settings.
I prefer User Settings because:
they're in XML (no registry hacking required)
a lot of the grunt work is done by the framework
User settings persist across upgrades automatically with ClickOnce
All you need to do is go to the Setings tab in the project's properties, add a setting, and set it's type to User.
Then just save the settings after changing them:
Properties.Settings.Default.ShowDisconnectMessage = false;
Properties.Settings.Default.Save();
The registry works similarly but it requires a bit more code and is not strongly-typed:
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software",true);
Key = key.OpenSubKey("AppName", true);
key.SetValue("ShowDisconnectMessage ", "false");
You'll need to make the messages in your application use a custom form. That form will need to show the message as well as have the check box. Then you'll want to store that information somewhere. I'm going to say in the application configuration file.
So, to save the data in the configuration file, first build a few extension methods to make it easier:
public static class Extensions
{
public static void SetValue(this KeyValueConfigurationCollection o,
string key,
string val)
{
if (!o.AllKeys.Contains(key)) { o.Add(key, val); }
else { o[key].Value = val; }
}
public static string GetValue(this NameValueCollection o,
string key,
object defaultVal = null)
{
if (!o.AllKeys.Contains(key)) { return Convert.ToString(defaultVal); }
return o[key];
}
}
Then, when you want to read that value to determine if you ought to show the message, do this:
var val = (bool)ConfigurationManager.AppSettings.GetValue("ShowTheMessage");
and then when you want to save the value, do this:
var config = ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
var app = config.AppSettings.Settings;
app.SetValue("ShowTheMessage", checkBox.Checked);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

How can i run bat file i just added to the resources in my project properties? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I went to my project > properties > resources > add existing file > test.bat
Now i have this code :
private void Information()
{
}
I call this function from a button click event.
I want to execute the bat file, so every user which will use my program will be able to execute the bat file directly from the program.
The bat file just create dxdiag.txt in a specific directory.
How can i do that?
You can put the batch file into the executable file folder and then use the Process class like this:
System.Diagnostics.Process.Start(System.IO.Path.Combine(Application.StartupPath, yourBatFileName));
Pay attention that usually your solution is compiled into the Debug folder or into the Release folder depending on your configuration (so you have to put the file in the correct one).
Use this class
Process.Start Method
You can use the following for parameters...
var myProg = new System.Diagnostics.Process();
myProg .StartInfo.FileName = "file name with full path";
myProg .StartInfo.UseShellExecute = false;
myProg .StartInfo.Arguments = "";
myProg .StartInfo.RedirectStandardOutput = true;
myProg .StartInfo.CreateNoWindow = true;
myProg .Start();
myProg .StandardOutput.ReadToEnd().Dump();

Categories

Resources