Skip to content

Commit

Permalink
moved time before msg in log
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHazee committed Jan 12, 2021
1 parent 717739e commit 7f2f99a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public partial class Form1 : Form

public Form1()
{

InitializeComponent();
Log.InitLogger(loggerRichTextBox);

Expand All @@ -29,15 +28,13 @@ public Form1()
locationWeather = new LocaleData();

databaseHandler = new DataBaseHandler();
// Not necessary to use delegate here
// Not necessary to use delegate here, just trying out
databaseHandler.OnDatabasIsReady += new DataBaseHandler.StatusUpdateHandler(UpdateAndShowPhotoPanels);

}


private void UpdateAndShowPhotoPanels(object sender, ProgressEventArgs e)
{

Log.AddToLog($"We recieved photo attribute \"{e.Attr}\" from databse class. Proof of delegate concept.");
// Clear list before filling it up
photosListView.Clear();
Expand All @@ -63,14 +60,12 @@ private void UpdateAndShowPhotoPanels(object sender, ProgressEventArgs e)
radioButtonNo.Checked = false;
radioButtonYes.Checked = false;
}

// Show relevant panes, should break this out or solve in better way
pictureBox1.Visible = true;
photosListView.Visible = true;
funnyPanel.Visible = true;
infoPane.Visible = false;
ipPanel.Visible = false;

// Return cursor to normal icon
this.Cursor = System.Windows.Forms.Cursors.Default;
}
Expand Down Expand Up @@ -103,14 +98,11 @@ private void MenuBtn_Clicked(object sender, EventArgs e)
photosListView.Visible = false;
funnyPanel.Visible = false;
this.Cursor = System.Windows.Forms.Cursors.Default;

}


}
private void PhotoListView_SelectedIndexChanged(object sender, EventArgs e)
{

// PhotoListView clicked, load corresponding picture into pictureBox
List<int> indexes = photosListView.SelectedIndices.Cast<int>().ToList();
if (indexes.Count > 0)
Expand All @@ -124,9 +116,7 @@ private void PhotoListView_SelectedIndexChanged(object sender, EventArgs e)
else {
radioButtonNo.Checked = true;
}

}

}
private void IpTextBox_KeyDown(object sender, KeyEventArgs e)
{
Expand All @@ -141,7 +131,6 @@ private void IpTextBox_KeyDown(object sender, KeyEventArgs e)
TextBox objTextBox = (TextBox)sender;
CustomIp(objTextBox.Text);
}

}
public void IpRichTextBox_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -172,24 +161,20 @@ public void CustomIp(string userIp)
// If all succeeded, update gui
if (success) UpdateLocationUI();
else errMsg = "Only public IP!";

}
if (!success)
{
ipTextBox.Text = errMsg;
ipTextBox.ForeColor = Color.Red;
}

this.Cursor = System.Windows.Forms.Cursors.Default;
}
private void ClockTimer_Tick(object sender, EventArgs e)
{
localTimeLabelVal.Text = locationWeather.getLocalTime();

}
private void UpdateLocationUI()
{

// Update map
gMapControl1.Position = new GMap.NET.PointLatLng(double.Parse(locationWeather._Lat), double.Parse(locationWeather._Lon));
gMapControl1.Update();
Expand Down Expand Up @@ -233,17 +218,14 @@ private void MapZoomInBtn_Click(object sender, EventArgs e)
gMapControl1.Update();
}
}

private void MapZoomOutBtn_Click(object sender, EventArgs e)
{
if (gMapControl1.Zoom > gMapControl1.MinZoom)
{
gMapControl1.Zoom--;
gMapControl1.Update();

}
}

private void RadioButtons_CheckedChanged(object sender, EventArgs e)
{
RadioButton radioButton = sender as RadioButton;
Expand All @@ -261,7 +243,6 @@ private void RadioButtons_CheckedChanged(object sender, EventArgs e)

}
}

private void GetMyIpBtn_Click(object sender, EventArgs e)
{
// Retrieve public IP of this computer
Expand Down
14 changes: 1 addition & 13 deletions LocaleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,21 @@ public class LocaleData
public string _TempMax { get; private set; }
public string _TempMin { get; private set; }
public string _flagIconUrl { get; private set; }

public string _IP { get; private set; }

public int _Timezone { get; private set; }


public string _CountryDisplayName { get; private set; }
public string _Currency { get; private set; }
public string _CurrencySymbol { get; private set; }

public string _localTime { get; private set; }

public string _IP { get; private set; }
public void FillWeatherProperties()
{

GetWeather(GetLocation(GetIPAddress()));
}
public bool FillWeatherProperties(string ip)
{

return GetWeather(GetLocation(ip));

}

private bool GetWeather(string city)
Expand Down Expand Up @@ -77,8 +70,6 @@ private bool GetWeather(string city)
this._TempMax = Convert.ToString(weatherInfo.Main.Temp_max);
this._TempMin = Convert.ToString(weatherInfo.Main.Temp_min);
this._Timezone = weatherInfo.Timezone;


}
Log.AddToLog("Done");
return true;
Expand All @@ -87,7 +78,6 @@ private bool GetWeather(string city)
{
return false;
}

}
private string GetIPAddress()
{
Expand Down Expand Up @@ -137,14 +127,12 @@ private string GetLocation(string ip)
}
catch (Exception e)
{

Log.AddToLog("Error when retrieving location: " + e.Message);
return "";
}


}

internal string getLocalTime()
{

Expand Down
4 changes: 1 addition & 3 deletions Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ namespace MonitorPhotoApp
static class Log
{
static RichTextBox Logger { get; set; }

public static void InitLogger(RichTextBox logTextBox)
{
Logger = logTextBox;
}

static public void AddToLog(string msg) => Logger.Text += $"{msg} {DateTime.UtcNow.ToLongTimeString()}\n";
static public void AddToLog(string msg) => Logger.Text += $"{DateTime.UtcNow.ToLongTimeString()} {msg}\n";
}
}
5 changes: 0 additions & 5 deletions PhotoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ class PhotosHandler
{
public ImageList ImageList { get; private set; }
private List<Bitmap> BitMapList { get; set; }

public PhotosHandler()
{

this.ImageList = new ImageList();
this.ImageList.ImageSize = new Size(56, 56);
this.ImageList.ColorDepth = ColorDepth.Depth32Bit;
Expand All @@ -22,7 +20,6 @@ public PhotosHandler()
}
public ImageList GetImageListFromURLs(List<PhotoInfo> photoInfoList)
{

this.ImageList.Images.Clear();
this.BitMapList.Clear();

Expand All @@ -37,7 +34,6 @@ public ImageList GetImageListFromURLs(List<PhotoInfo> photoInfoList)
this.BitMapList.Add(new Bitmap(Image.FromStream(stream)));

}

return this.ImageList;
}

Expand Down Expand Up @@ -69,7 +65,6 @@ private Color GetMostUsedColor(Bitmap bmp)
total++;
}
}

//Calculate average
r /= total;
g /= total;
Expand Down

0 comments on commit 7f2f99a

Please sign in to comment.