Skip to content

Commit

Permalink
Merge pull request #137 from kartverket/timeoutFromConfig
Browse files Browse the repository at this point in the history
Timeout from config
  • Loading branch information
jarped committed Sep 18, 2020
2 parents fe0b68b + e4fca33 commit f3836bd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -40,6 +41,9 @@ public void InitTransactionsSummary()

public TransactionSummary TransactionsSummary;

private static int _timeout = -1;
private int timeout { get { return _timeout == -1 ? GetTimeout() : _timeout; } }

public IBindingList GetCapabilitiesProviderDataset(string url, string UserName, string Password)
{
var cdb = new CapabilitiesDataBuilder(url, UserName, Password);
Expand Down Expand Up @@ -563,19 +567,12 @@ private void GetStatusForChangelogOnProvider(int datasetId, string changeLogId)
{
var changeLogStatus = GetChangelogStatusResponse(datasetId, changeLogId);

var starttid = DateTime.Now;
var elapsedTicks = DateTime.Now.Ticks - starttid.Ticks;

var elapsedSpan = new TimeSpan(elapsedTicks);
var timeout = 15;
//timeout = 50; // TODO: Fix for Norkart Provider,
var stopWatch = Stopwatch.StartNew();

while ((changeLogStatus == ChangelogStatusType.queued || changeLogStatus == ChangelogStatusType.working) &&
elapsedSpan.Minutes < timeout)
stopWatch.Elapsed.TotalMinutes < timeout)
{
System.Threading.Thread.Sleep(3000);
elapsedTicks = DateTime.Now.Ticks - starttid.Ticks;
elapsedSpan = new TimeSpan(elapsedTicks);
changeLogStatus = GetChangelogStatusResponse(datasetId, changeLogId);
}
if (changeLogStatus == ChangelogStatusType.finished)
Expand All @@ -594,7 +591,7 @@ private void GetStatusForChangelogOnProvider(int datasetId, string changeLogId)
throw new IOException("Recieved ChangelogStatus == failed from provider");
default:
Logger.Info("Timeout");
throw new IOException("Timed out waiting for ChangelogStatus == finished from provider");
throw new TimeoutException($"Timed out waiting for ChangelogStatus == finished from provider. Try increasing the TimeOut-value in the .config-file. Current value: {timeout} minutes");
}
}
}
Expand All @@ -607,6 +604,18 @@ private void GetStatusForChangelogOnProvider(int datasetId, string changeLogId)
}
}

private static int GetTimeout()
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

var settings = config.GetSectionGroup("userSettings");
var section = settings.Sections["Kartverket.Geosynkronisering.Subscriber.Properties.Subscriber"] as ClientSettingsSection;

_timeout = int.Parse(section.Settings.Get("TimeOut").Value.ValueXml.InnerText);

return _timeout;
}

private static List<string> ChangeLogMapper(IEnumerable<string> fileList, int datasetId)
{
var newFileList = new List<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<nlog throwExceptions="true" internalLogToConsole="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
For nlog use TEMP folder, one file for error, one for logging.
<target name="errorfile" xsi:type="File" fileName="${tempdir:dir}/Kartverket.Geosynkronisering.Subscriber_Error_${shortdate}.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=tostring}|${stacktrace}" /><target name="logfile" xsi:type="File" fileName="${tempdir:dir}/Kartverket.Geosynkronisering.Subscriber_Log_${shortdate}.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}" /></targets>
<target name="errorfile" xsi:type="File" fileName="${tempdir:dir}/Kartverket.Geosynkronisering.Subscriber_Error_${shortdate}.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=tostring}|${stacktrace}" /><target name="logfile" xsi:type="File" fileName="${tempdir:dir}/Kartverket.Geosynkronisering.Subscriber_Log_${shortdate}.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}" />
</targets>
<rules>
<logger name="*" writeTo="logfile" minlevel="Info" />
<logger name="*" writeTo="logfile" minlevel="Debug" />
Expand All @@ -41,9 +42,15 @@
</nlog>
<userSettings>
<Kartverket.Geosynkronisering.Subscriber.Properties.Subscriber>
<setting name="DefaultDatasetId" serializeAs="String">
<value>1</value>
</setting>
<setting name="DefaultServerURL" serializeAs="String">
<value>https://geosynk.nois.no/tilbyder/</value>
</setting>
<setting name="TimeOut" serializeAs="String">
<value>15</value>
</setting>
</Kartverket.Geosynkronisering.Subscriber.Properties.Subscriber>
</userSettings>
<runtime>
Expand Down Expand Up @@ -84,6 +91,8 @@
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" /><add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" /></DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
</configuration>

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

Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
<Setting Name="DefaultServerURL" Type="System.String" Scope="User">
<Value Profile="(Default)">https://geosynk.nois.no/tilbyder/</Value>
</Setting>
<Setting Name="TimeOut" Type="System.Int32" Scope="User">
<Value Profile="(Default)">15</Value>
</Setting>
</Settings>
</SettingsFile>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<setting name="DefaultServerURL" serializeAs="String">
<value>https://geosynk.nois.no/tilbyder/</value>
</setting>
<setting name="TimeOut" serializeAs="String">
<value>15</value>
</setting>
</Kartverket.Geosynkronisering.Subscriber.Properties.Subscriber>
</userSettings>
<!--<system.serviceModel>
Expand Down

0 comments on commit f3836bd

Please sign in to comment.