Skip to content
Permalink
Browse files

Merge pull request #3802 from ArchonMegalon/master

Some tweaks (and telemetry) to sharing chummerfiles
  • Loading branch information...
ArchonMegalon committed Aug 5, 2019
2 parents deeb5f8 + 94a7112 commit 42171d122698597072d5148745a021caeb08fa5c
@@ -188,6 +188,13 @@ static void Main()
}
}
Log.Info(strInfo);

if (Chummer.Properties.Settings.Default.UploadClientId == Guid.Empty)
{
Chummer.Properties.Settings.Default.UploadClientId = Guid.NewGuid();
Chummer.Properties.Settings.Default.Save();
}

Log.Info("Logging options are set to " + GlobalOptions.UseLogging + " and Upload-Options are set to " + GlobalOptions.UseLoggingApplicationInsights + " (Installation-Id: " + Chummer.Properties.Settings.Default.UploadClientId + ").");

if (GlobalOptions.UseLoggingApplicationInsights >= UseAILogging.OnlyMetric)
@@ -209,13 +216,6 @@ static void Main()
//live.Enable();

//Log an Event with AssemblyVersion and CultureInfo


if (Properties.Settings.Default.UploadClientId == Guid.Empty)
{
Properties.Settings.Default.UploadClientId = Guid.NewGuid();
Properties.Settings.Default.Save();
}
MetricIdentifier mi = new MetricIdentifier("Chummer", "Program Start", "Version", "Culture", dimension3Name:"AISetting");
var metric = TelemetryClient.GetMetric(mi);
metric.TrackValue(1,
@@ -18,6 +18,7 @@
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.Text;
@@ -35,7 +36,7 @@ public partial class frmSelectQuality : Form

private readonly XPathNavigator _xmlBaseQualityDataNode;
private readonly XPathNavigator _xmlMetatypeQualityRestrictionNode;

private readonly List<ListItem> _lstCategory = new List<ListItem>();

private static string s_StrSelectCategory = string.Empty;
@@ -77,7 +78,9 @@ private void frmSelectQuality_Load(object sender, EventArgs e)
cboCategory.BeginUpdate();
cboCategory.ValueMember = "Value";
cboCategory.DisplayMember = "Name";
cboCategory.DataSource = _lstCategory;
//this could help circumvent a exception like this? "InvalidArgument=Value of '0' is not valid for 'SelectedIndex'. Parameter name: SelectedIndex"
BindingList<ListItem> templist = new BindingList<ListItem>(_lstCategory);
cboCategory.DataSource = templist;

// Select the first Category in the list.
if (string.IsNullOrEmpty(s_StrSelectCategory))
@@ -170,7 +170,14 @@ public void FormMainInitialize(PageViewTelemetry pvt = null)
catch (UnauthorizedAccessException e)
{
Log.Trace(e,
"UnauthorizedAccessException in " + Utils.GetStartupPath + "can be ignored - probably a weird path like Recycle.Bin or something...");
"UnauthorizedAccessException in " + Utils.GetStartupPath +
"can be ignored - probably a weird path like Recycle.Bin or something...");
}
catch (System.IO.IOException e)
{
Log.Trace(e,
"IOException in " + Utils.GetStartupPath +
"can be ignored - probably another instance blocking it...");
}

// Populate the MRU list.
@@ -1102,7 +1109,16 @@ public DialogResult ShowMessageBox(String message, String caption, MessageBoxBut
//that setting off.
Debugger.Break();
}
return (DialogResult)this.Invoke(new PassStringStringReturnDialogResultDelegate(ShowMessageBox), message, caption, buttons, icon);

try
{
return (DialogResult)this.Invoke(new PassStringStringReturnDialogResultDelegate(ShowMessageBox), message, caption, buttons, icon);
}
catch (ObjectDisposedException)
{
//if the main form is disposed, we really don't need to bother anymore...
}

}
return MessageBox.Show(new Form() { TopMost = true }, message, caption, buttons, icon);
}
@@ -720,11 +720,14 @@ public static async Task<object> HandleError(Exception e)
if ((!String.IsNullOrEmpty(rb.ErrorText)
|| (rb.MyException != null)))
{
Log.Warn("SINners WebService returned: " + rb.ErrorText);
var frmSIN = new frmSINnerResponse();
frmSIN.SINnerResponseUI.Result = rb;
frmSIN.TopMost = true;
frmSIN.ShowDialog(PluginHandler.MainForm);
PluginHandler.MainForm.DoThreadSafe(() =>
{
Log.Warn("SINners WebService returned: " + rb.ErrorText);
var frmSIN = new frmSINnerResponse();
frmSIN.SINnerResponseUI.Result = rb;
frmSIN.TopMost = true;
frmSIN.Show(PluginHandler.MainForm);
});
}
return ResponseBody;
}
@@ -181,113 +181,166 @@ internal List<Tag> PopulateTags()
return MySINnerFile.SiNnerMetaData.Tags.ToList();
}

public async Task<bool> Upload(ucSINnerShare.MyUserState myState = null)
public async Task<bool> Upload(ucSINnerShare.MyUserState myState = null, CustomActivity parentActivity = null)
{
try
{
using (new CursorWait(true, PluginHandler.MainForm))
using (var op_uploadChummer = Timekeeper.StartSyncron(
"Uploading Chummer", parentActivity,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
if (myState != null)
using (new CursorWait(true, PluginHandler.MainForm))
{
HttpOperationResponse<ResultSinnerGetSINById> found = null;
using (var op_checkalreadyonlineChummer = Timekeeper.StartSyncron(
"Checking if already online Chummer", op_uploadChummer,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
if (myState != null)
{
//1 Step
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Checking online version of file...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Checking online version of file...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

if (MySINnerFile.DownloadedFromSINnersTime > this.MyCharacter.FileLastWriteTime)
{
if (myState != null)
{
myState.CurrentProgress += 4 * myState.ProgressSteps;
myState.StatusText = "File already uploaded.";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

return true;
}

var client = StaticUtils.GetClient();
found = await client.GetSINByIdWithHttpMessagesAsync(this.MySINnerFile.Id.Value);
await Backend.Utils.HandleError(found, found.Body);
}

if (MySINnerFile.DownloadedFromSINnersTime > this.MyCharacter.FileLastWriteTime)
{
if (myState != null)
//2 Step
myState.CurrentProgress += myState.ProgressSteps;
using (var op_VisibilityChummer = Timekeeper.StartSyncron(
"Setting Visibility for Chummer", op_uploadChummer,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
myState.CurrentProgress += 4 * myState.ProgressSteps;
myState.StatusText = "File already uploaded.";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
if (found.Response.StatusCode == System.Net.HttpStatusCode.OK)
{
if (found.Body.MySINner.LastChange >= this.MyCharacter.FileLastWriteTime)
{
if (myState != null)
{
myState.StatusText = "SINner already uploaded and updated online.";
myState.CurrentProgress += 3 * myState.ProgressSteps;
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

return true;
}

if (myState != null)
{
myState.StatusText = "SINner needs to be uploaded.";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

if (!MySINnerFile.SiNnerMetaData.Visibility.UserRights.Any())
{
MySINnerFile.SiNnerMetaData.Visibility.UserRights =
found.Body.MySINner.SiNnerMetaData.Visibility.UserRights;
}
}
}
return true;
}

var client = StaticUtils.GetClient();
var found = await client.GetSINByIdWithHttpMessagesAsync(this.MySINnerFile.Id.Value);
await Backend.Utils.HandleError(found, found.Body);
if (myState != null)
//2 Step
myState.CurrentProgress += myState.ProgressSteps;
if (found.Response.StatusCode == System.Net.HttpStatusCode.OK)
{
if (found.Body.MySINner.LastChange >= this.MyCharacter.FileLastWriteTime)
{
if (myState != null)
{
myState.StatusText = "SINner already uploaded and updated online.";
myState.CurrentProgress += 3 * myState.ProgressSteps;
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}
return true;
}
if (myState != null)
{
myState.StatusText = "SINner needs to be uploaded.";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}
if (!MySINnerFile.SiNnerMetaData.Visibility.UserRights.Any())
{
MySINnerFile.SiNnerMetaData.Visibility.UserRights =
found.Body.MySINner.SiNnerMetaData.Visibility.UserRights;
}
}
using (var op_PopulatingChummer = Timekeeper.StartSyncron(
"Populating Reflection Tags", op_uploadChummer,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
this.MySINnerFile.SiNnerMetaData.Tags = this.PopulateTags();
}

this.MySINnerFile.SiNnerMetaData.Tags = this.PopulateTags();
await this.PrepareModel();
if (myState != null)
{
using (var op_PopulatingChummer = Timekeeper.StartSyncron(
"Preparing Model", op_uploadChummer,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
await this.PrepareModel();
}

if (myState != null)
{
//3 Step
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummerfile prepared for uploading...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}
var res = await ChummerHub.Client.Backend.Utils.PostSINnerAsync(this);
await Backend.Utils.HandleError(res, res.Body);
if (myState != null)
{
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummerfile prepared for uploading...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

HttpOperationResponse<ResultSinnerPostSIN> res = null;
using (var op_PopulatingChummer = Timekeeper.StartSyncron(
"Posting SINner", op_uploadChummer,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
res = await ChummerHub.Client.Backend.Utils.PostSINnerAsync(this);
await Backend.Utils.HandleError(res, res.Body);
}

if (myState != null)
{
//4 Step
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummer Metadata stored in DB...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}
if (res.Response.IsSuccessStatusCode)
{
var uploadres = await ChummerHub.Client.Backend.Utils.UploadChummerFileAsync(this);
if (uploadres.Response.IsSuccessStatusCode)
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummer Metadata stored in DB...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

if (res.Response.IsSuccessStatusCode)
{
if (myState != null)
using (var op_PopulatingChummer = Timekeeper.StartSyncron(
"Uploading File", op_uploadChummer,
CustomActivity.OperationType.DependencyOperation, MyCharacter?.FileName))
{
var uploadres = await ChummerHub.Client.Backend.Utils.UploadChummerFileAsync(this);
if (uploadres.Response.IsSuccessStatusCode)
{
if (myState != null)
{
//5 Step
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummer uploaded...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummer uploaded...";
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

return true;
}

if (myState != null)
{
//5 Step
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummer upload failed: " + uploadres.Response.ReasonPhrase;
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

return false;
}
return true;
}

if (myState != null)
{
//5 Step
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummer upload failed: " + uploadres.Response.ReasonPhrase;
myState.StatusText = "Chummer upload of Metadata failed: " + res.Response.ReasonPhrase;
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}

return false;
}
if (myState != null)
{
//5 Step
myState.CurrentProgress += myState.ProgressSteps;
myState.StatusText = "Chummer upload of Metadata failed: " + res.Response.ReasonPhrase;
myState.myWorker?.ReportProgress(myState.CurrentProgress, myState);
}
return false;

}
}
catch(Exception e)
catch (Exception e)
{
await Backend.Utils.HandleError(e);
throw;

0 comments on commit 42171d1

Please sign in to comment.
You can’t perform that action at this time.