Server/ClientData.cs
author StephaneLenclud
Wed, 03 Feb 2016 16:04:37 +0100
changeset 193 317fdfa4fbb6
parent 176 01c72c29cfaf
child 279 10f0de70b69b
permissions -rw-r--r--
Basic idle client functionality.
StephaneLenclud@140
     1
using System;
StephaneLenclud@140
     2
using System.Collections.Generic;
StephaneLenclud@140
     3
using System.Linq;
StephaneLenclud@140
     4
using System.Text;
StephaneLenclud@140
     5
using System.Threading.Tasks;
StephaneLenclud@140
     6
//
StephaneLenclud@171
     7
using SharpLib.Display;
StephaneLenclud@140
     8
StephaneLenclud@140
     9
namespace SharpDisplayManager
StephaneLenclud@140
    10
{
StephaneLenclud@140
    11
    /// <summary>
StephaneLenclud@140
    12
    /// A UI thread copy of a client relevant data.
StephaneLenclud@140
    13
    /// Keeping this copy in the UI thread helps us deal with threading issues.
StephaneLenclud@140
    14
    /// </summary>
StephaneLenclud@140
    15
    public class ClientData
StephaneLenclud@140
    16
    {
StephaneLenclud@140
    17
        public ClientData(string aSessionId, ICallback aCallback)
StephaneLenclud@140
    18
        {
StephaneLenclud@140
    19
            SessionId = aSessionId;
StephaneLenclud@140
    20
            Name = "";
StephaneLenclud@184
    21
            Priority = Priorities.Default;
StephaneLenclud@140
    22
            Fields = new List<DataField>();
StephaneLenclud@140
    23
            Layout = new TableLayout(1, 2); //Default to one column and two rows
StephaneLenclud@140
    24
            Callback = aCallback;
StephaneLenclud@175
    25
            HasNewLayout = true;            
StephaneLenclud@140
    26
        }
StephaneLenclud@140
    27
StephaneLenclud@140
    28
        public string SessionId { get; set; }
StephaneLenclud@140
    29
        public string Name { get; set; }
StephaneLenclud@184
    30
        public uint Priority { get; set; }
StephaneLenclud@140
    31
        public List<DataField> Fields { get; set; }
StephaneLenclud@140
    32
        public TableLayout Layout { get; set; }
StephaneLenclud@140
    33
        public ICallback Callback { get; set; }
StephaneLenclud@141
    34
StephaneLenclud@175
    35
        public bool HasNewLayout { get; set; }
StephaneLenclud@175
    36
StephaneLenclud@141
    37
        //Client management
StephaneLenclud@141
    38
        public DateTime LastSwitchTime { get; set; }
StephaneLenclud@176
    39
StephaneLenclud@176
    40
        /// <summary>
StephaneLenclud@176
    41
        /// Look up the corresponding field in our field collection.
StephaneLenclud@176
    42
        /// </summary>
StephaneLenclud@176
    43
        /// <param name="aField"></param>
StephaneLenclud@176
    44
        /// <returns></returns>
StephaneLenclud@176
    45
        public DataField FindSameFieldAs(DataField aField)
StephaneLenclud@176
    46
        {
StephaneLenclud@176
    47
            foreach (DataField field in Fields)
StephaneLenclud@176
    48
            {
StephaneLenclud@176
    49
                if (field.IsSameAs(aField))
StephaneLenclud@176
    50
                {
StephaneLenclud@176
    51
                    return field;
StephaneLenclud@176
    52
                }                
StephaneLenclud@176
    53
            }
StephaneLenclud@176
    54
StephaneLenclud@176
    55
            return null;
StephaneLenclud@176
    56
        }
StephaneLenclud@176
    57
StephaneLenclud@176
    58
StephaneLenclud@176
    59
        /// <summary>
StephaneLenclud@176
    60
        /// Look up the corresponding field in our field collection.
StephaneLenclud@176
    61
        /// </summary>
StephaneLenclud@176
    62
        /// <param name="aField"></param>
StephaneLenclud@176
    63
        /// <returns></returns>
StephaneLenclud@176
    64
        public int FindSameFieldIndex(DataField aField)
StephaneLenclud@176
    65
        {
StephaneLenclud@176
    66
            int i = 0;
StephaneLenclud@176
    67
            foreach (DataField field in Fields)
StephaneLenclud@176
    68
            {
StephaneLenclud@176
    69
                if (field.IsSameAs(aField))
StephaneLenclud@176
    70
                {
StephaneLenclud@176
    71
                    return i;
StephaneLenclud@176
    72
                }
StephaneLenclud@176
    73
                i++;
StephaneLenclud@176
    74
            }
StephaneLenclud@176
    75
StephaneLenclud@176
    76
            return -1;
StephaneLenclud@176
    77
        }
StephaneLenclud@176
    78
StephaneLenclud@176
    79
StephaneLenclud@140
    80
    }
StephaneLenclud@140
    81
}