Skip to content

Commit

Permalink
Page update improved
Browse files Browse the repository at this point in the history
  • Loading branch information
uholeschak committed Jan 21, 2022
1 parent 8002e6d commit cd78878
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 61 deletions.
67 changes: 23 additions & 44 deletions Tools/Psdz/WebPsdzClient/App_Data/SessionContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public EnetTcpChannel(bool control)
public AutoResetEvent SendEvent;
}

public delegate void UpdateDisplayDelegate();
public delegate void UpdateOptionsDelegate();
public delegate bool VehicleResponseDelegate();
public string SessionId { get; }
public ProgrammingJobs ProgrammingJobs { get; private set; }
Expand Down Expand Up @@ -184,44 +182,6 @@ private set
}
}

private UpdateDisplayDelegate _updateDisplay;
public UpdateDisplayDelegate UpdateDisplayFunc
{
get
{
lock (_lockObject)
{
return _updateDisplay;
}
}
set
{
lock (_lockObject)
{
_updateDisplay = value;
}
}
}

private UpdateOptionsDelegate _updateOptions;
public UpdateOptionsDelegate UpdateOptionsFunc
{
get
{
lock (_lockObject)
{
return _updateOptions;
}
}
set
{
lock (_lockObject)
{
_updateOptions = value;
}
}
}

private PdszDatabase.SwiRegisterEnum? _selectedSwiRegister;
public PdszDatabase.SwiRegisterEnum? SelectedSwiRegister
{
Expand Down Expand Up @@ -1524,9 +1484,27 @@ public void UpdateStatus(string message = null)
}
}

public void UpdateDisplay()
public void UpdateDisplay(bool withHeader = false)
{
UpdateDisplayFunc?.Invoke();
try
{
IHubContext<IPsdzClient> hubContext = GlobalHost.ConnectionManager.GetHubContext<PsdzVehicleHub, IPsdzClient>();
if (hubContext == null)
{
log.ErrorFormat("UpdateDisplay No hub context");
return;
}

List<string> connectionIds = PsdzVehicleHub.GetConnectionIds(SessionId);
foreach (string connectionId in connectionIds)
{
hubContext.Clients.Client(connectionId)?.UpdatePanels(withHeader, !withHeader);
}
}
catch (Exception ex)
{
log.ErrorFormat("UpdateDisplay Exception: {0}", ex.Message);
}
}

public void UpdateOptions(Dictionary<PdszDatabase.SwiRegisterEnum, List<ProgrammingJobs.OptionsItem>> optionsDict)
Expand All @@ -1552,7 +1530,8 @@ private void UpdateCurrentOptions()
log.ErrorFormat("UpdateCurrentOptions Exception: {0}", ex.Message);
}

UpdateOptionsFunc?.Invoke();
RefreshOptions = true;
UpdateDisplay(true);
}

private void UpdateProgress(int percent, bool marquee, string message = null)
Expand All @@ -1574,7 +1553,7 @@ private void UpdateProgress(int percent, bool marquee, string message = null)
if (ProgressText != text)
{
ProgressText = text;
UpdateDisplayFunc.Invoke();
UpdateDisplay();
}
}

Expand Down
21 changes: 19 additions & 2 deletions Tools/Psdz/WebPsdzClient/Default.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<style>.dropdown { width: 100%; max-width: 100%; }</style>
<style>.checkbox label { text-indent: 30px }</style>
<div class="jumbotron">
<asp:UpdatePanel ID="UpdatePanelHeader" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<asp:UpdatePanel ID="UpdatePanelHeader" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False" OnLoad="UpdatePanelHeader_OnLoad">
<ContentTemplate>
<asp:Panel ID="PanelButtons" runat="server" CssClass="panel-body" HorizontalAlign="Center">
<asp:Button ID="ButtonStopHost" runat="server" CssClass="btn" Text="Stop Host" OnClick="ButtonStopHost_Click" />
Expand All @@ -27,15 +27,32 @@
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanelStatus" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<asp:UpdatePanel ID="UpdatePanelStatus" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False" OnLoad="UpdatePanelStatus_OnLoad">
<ContentTemplate>
<asp:Panel ID="PanelStatus" runat="server" CssClass="panel-body" HorizontalAlign="Center" >
<asp:TextBox ID="TextBoxStatus" runat="server" CssClass="text-left" ReadOnly="True" TextMode="MultiLine" Rows="10"></asp:TextBox>
<asp:TextBox ID="TextBoxProgress" runat="server" CssClass="text-left" ReadOnly="True" TextMode="SingleLine"></asp:TextBox>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="TimerUpdatePanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
<ContentTemplate>
<asp:Timer ID="TimerUpdate" runat="server" Interval="5000" OnTick="TimerUpdate_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<script type="text/javascript">
function updatePanelHeader()
{
console.log("updatePanelHeader called");
__doPostBack("<%=UpdatePanelHeader.UniqueID %>", "");
}
function updatePanelStatus()
{
console.log("updatePanelStatus called");
__doPostBack("<%=UpdatePanelStatus.UniqueID %>", "");
}
</script>
</asp:Content>
32 changes: 17 additions & 15 deletions Tools/Psdz/WebPsdzClient/Default.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ protected void Page_Load(object sender, EventArgs e)
return;
}

sessionContainer.UpdateDisplayFunc = UpdateDisplay;
sessionContainer.UpdateOptionsFunc = UpdateOptions;

if (!IsPostBack)
{
try
Expand Down Expand Up @@ -66,7 +63,7 @@ protected void Page_Load(object sender, EventArgs e)
log.ErrorFormat("Page_Load Exception: {0}", ex.Message);
}

UpdateDisplay();
UpdateStatus();
}

if (!IsPostBack || sessionContainer.RefreshOptions)
Expand Down Expand Up @@ -286,7 +283,7 @@ protected void CheckBoxListOptions_OnSelectedIndexChanged(object sender, EventAr

protected void TimerUpdate_Tick(object sender, EventArgs e)
{
UpdateStatus(true);
log.InfoFormat("_Default TimerUpdate_Tick");
}

private SessionContainer GetSessionContainer()
Expand All @@ -300,14 +297,9 @@ private SessionContainer GetSessionContainer()
return null;
}

private void UpdateDisplay()
private void UpdateStatus(bool withButtons = false)
{
UpdateStatus();
}

private void UpdateStatus(bool fromTimer = false)
{
log.InfoFormat("UpdateStatus FromTimer: {0}", fromTimer);
log.InfoFormat("UpdateStatus Buttons: {0}", withButtons);

try
{
Expand Down Expand Up @@ -348,17 +340,17 @@ private void UpdateStatus(bool fromTimer = false)
TextBoxStatus.Text = sessionContainer.StatusText;
TextBoxProgress.Text = sessionContainer.ProgressText;

UpdatePanels(fromTimer);
UpdatePanels(withButtons);
}
catch (Exception ex)
{
log.ErrorFormat("UpdateStatus Exception: {0}", ex.Message);
}
}

private void UpdatePanels(bool fromTimer = false)
private void UpdatePanels(bool withButtons = false)
{
if (!fromTimer)
if (withButtons)
{
try
{
Expand Down Expand Up @@ -555,5 +547,15 @@ private void SelectOptions(PdszDatabase.SwiRegisterEnum? swiRegisterEnum)

return selectedSwiActions;
}

protected void UpdatePanelHeader_OnLoad(object sender, EventArgs e)
{
UpdateStatus(true);
}

protected void UpdatePanelStatus_OnLoad(object sender, EventArgs e)
{
UpdateStatus();
}
}
}
9 changes: 9 additions & 0 deletions Tools/Psdz/WebPsdzClient/Default.aspx.designer.cs

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

3 changes: 3 additions & 0 deletions Tools/Psdz/WebPsdzClient/Hub/PsdzHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,8 @@ public interface IPsdzClient

[HubMethodName("vehicleSend")]
Task VehicleSend(string url, string id, string data);

[HubMethodName("updatePanels")]
Task UpdatePanels(bool header, bool status);
}
}
29 changes: 29 additions & 0 deletions Tools/Psdz/WebPsdzClient/Site.Master
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,35 @@
sendRequest(url, id, formData);
}

psdzVehicleHubProxy.client.updatePanels = function (header, status)
{
var logMessage = "Update Panels: Header=" + header + ", Status=" + status;
console.log(logMessage);
if (header)
{
if (typeof updatePanelHeader === "function")
{
updatePanelHeader();
}
else
{
console.log("updatePanelHeader not existing");
}
}

if (status)
{
if (typeof updatePanelStatus === "function")
{
updatePanelStatus();
}
else
{
console.log("updatePanelStatus not existing");
}
}
}

$.connection.hub.qs = { 'sessionId' : sessionID };
$.connection.hub.start().done(function ()
{
Expand Down

0 comments on commit cd78878

Please sign in to comment.