public enum YesNoEnum
{
Yes = 0,
No = 1
}
I also like how they defined the enum values.
private readonly FooType _foo = new FooType();
/// <summary>
/// Gets the controller of this component
/// </summary>
private FooType Foo
{
get
{
return _foo;
}
}
return IsActive == true ? true : false;
public static class time
{
public const int minutes_per_hour = 60;
public const int seconds_per_minute = 60;
public const int hours_per_day = 24;
public const int minutes_per_day = minutes_per_hour * hours_per_day;
public const int seconds_per_day = seconds_per_minute * minutes_per_day;
public const int days_per_year = 365;
}
public class NullableFloatToNullableDoubleConverter : ITypeConverter<float?, double?>
{
public double? Convert(float? source, double? destination, ResolutionContext context)
{
if (source == null)
{
return null;
}
var floatAsString = source.Value.ToString(CultureInfo.InvariantCulture);
return double.Parse(floatAsString);
}
}
string date = user.RegistrationDate.ToShortDateString().ToString();
if (model.env.Trim().ToUpper() == "Release")
{
retVal = false;
if (!string.IsNullOrEmpty(model.Server_Core))
{
// Perform a trim in case user specified just whitespace...
string tmpStr = model.Server_Core.Trim();
if (!string.IsNullOrEmpty(tmpStr))
{
retVal = true;
}
}
}
protected override void OnStartup(StartupEventArgs e)
{
Current.DispatcherUnhandledException += ApplicationUnhandledException;
base.OnStartup(e);
#if (DEBUG)
RunInDebugMode(e.Args);
#else
RunInReleaseMode(e.Args);
#endif
}
#endregion
private static void RunInReleaseMode(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
try
{
SplashScreen screen = new SplashScreen(@"Images\splashscreen.png");
screen.Show(true, true);
RunInDebugMode(args);
}
catch (Exception ex)
{
HandleException(ex);
}
}
private static void RunInDebugMode(string[] args)
{
var bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
public static bool ValidateEmailAddress(string emailAddress)
{
string pattern = "^((?>[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+\x20*|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\"\x20*)*(?<angle><))?((?!\\.)(?>\\.?[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+)+|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\")@(((?!-)[a-zA-Z\\d\\-]+(?<!-)\\.)+[a-zA-Z]{2,}|\\[(((?(?<!\\[)\\.)(25[0-5]|2[0-4]\\d|[01]?\\d?\\d)){4}|[a-zA-Z\\d\\-]*[a-zA-Z\\d]:((?=[\x01-\x7f])[^\\\\[\\]]|\\[\x01-\x7f])+)\\])(?(angle)>)$";
if (!String.IsNullOrEmpty(emailAddress) && !(Regex.Match(emailAddress.Trim(), pattern, RegexOptions.IgnoreCase)).Success)
{
return false;
}
return true;
}
if ((bool)greenButton.IsChecked)
{
CurrentColor = Color.FromArgb(0xFF, 0x00, 0xCC, 0x00);
}
else if ((bool)greyButton.IsChecked)
{
CurrentColor = Color.FromArgb(0xFF, 0x79, 0x79, 0x79);
}
foreach (var item in ItemsList.Items)
{
if ((grid.Background as SolidColorBrush).Color == CurrentColor)
{
selectedItems.Add(item);
}
}
[HttpPost]
[Route("validaPrepacks")]
public IHttpActionResult ValidaPrepacks(ValidaPrepackVO validacion)
{
try
{
return Ok();
}
catch (Exception e)
{
return Ok(e.Message);
}
}
A code that "validate" a pack in the backend
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var token = new CancellationTokenSource().Token;
Task.Factory.StartNew (() => {
while (!token.IsCancellationRequested) {
try {
if (/*Condition*/)
this.Invoke(new Action(() => label.Text = " =)"));
else
this.Invoke(new Action(() => label.Text = " =("));
Thread.Sleep(10);
}
catch (Exception) {
throw;
}
finally {
throw new Exception();
}
}
}) ;
}
}
My collegue's way of using multithreading features (and exceptions handling) :)
if (date.Training != null)
{
var training = date.Training;
var status = new TrainingStatus();
var refresher = new Training();
if (training.Trainings != null)
refresher = training.Trainings;
bool hasTakenRefresher = false;
status.Value = date.Date.AddDays(
TrainingHelper.CalculateValidityDays(training.Validity ?? 0, training.ValidityType ?? 0));
status.Name = training.TrainingName;
status.ID = training.TrainingID;
status.Category = training.CategoryTraining != null ? training.CategoryTraining.Name : "Other";
status.IsTrained = _validityUtilsService.IsValid(training, date.Date);
if (status.IsTrained)
{
status.IsExpiring = _validityUtilsService.IsExpiring(training, date.Date,
TrainingHelper.CalculateValidityDays(
training.ExpirationWarningValidity ?? 0,
training.ExpirationWarningValidityType ?? 0));
}
if (refresher.ID != 0)
{
hasTakenRefresher = employee.Dates
.Count(x => x.Training != null
&& x.TrainingID == refresher.ID) > 1;
if (hasTakenRefresher && (status.IsExpiring || !status.IsTrained))
{
status.IsExpiring = false;
var trainingWithNewValidity = new Training();
status.Value = date.Date.AddDays(
TrainingHelper.CalculateValidityDays(training.ValidityRefresher ?? 0,
training.ValidityRefresherType ?? 0));
trainingWithNewValidity.Validity = training.ValidityRefresher;
trainingWithNewValidity.ValidityType = training.ValidityRefresherType;
status.IsTrained = _validityUtilsService.IsValid(trainingWithNewValidity, date.Date);
if (status.IsTrained)
{
status.IsExpiring = _validityUtilsService.IsExpiring(trainingWithNewValidity, date.Date,
TrainingHelper.CalculateValidityDays(
refresher.ExpirationWarningValidity ?? 0,
refresher.ExpirationWarningValidityType ?? 0));
}
}
}
if (status.IsTrained && !status.IsExpiring)
status.Status = TrainingStatuses.Trained;
else if (status.IsTrained && status.IsExpiring)
status.Status = TrainingStatuses.Expiring;
else if (!status.IsTrained && !status.IsExpiring)
status.Status = TrainingStatuses.Expired;
status.EmpID = employee.ID;
return status;
}
test
public class MetricsChecker
{
protected const string AwaitingRecognitionCountMetricName = "AwaitingRecognitionCount";
protected const string AwaitingExportCountMetricName = "AwaitingExportCount";
protected const string NotYetDownloadedEventCountMetricName = "NotYetDownloadedEventCount";
...
public virtual void PublishNotYetDownloadedEventCounts()
{
this.logger.Trace($"Starting to gather and publish {NotYetDownloadedEventCountMetricName}(s).");
...
}
...
}
var doc = (Parent as Doc);
doc.Name = (doc != null) ? "" : doc.Name