Adding missing file.
authorsl
Sun, 31 Aug 2014 16:14:10 +0200
changeset 49eab73d41c9e6
parent 48 9039acfde091
child 50 ba4cad33db58
Adding missing file.
Server/DisplaySettings.cs
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Server/DisplaySettings.cs	Sun Aug 31 16:14:10 2014 +0200
     1.3 @@ -0,0 +1,134 @@
     1.4 +using System;
     1.5 +using System.Collections;
     1.6 +using System.Collections.Generic;
     1.7 +using System.Text;
     1.8 +using System.Configuration;
     1.9 +using System.Xml;
    1.10 +using System.ComponentModel;
    1.11 +using System.Runtime.Serialization;
    1.12 +using System.Runtime.Serialization.Json;
    1.13 +using System.IO;
    1.14 +using System.Drawing;
    1.15 +
    1.16 +namespace SharpDisplayManager
    1.17 +{
    1.18 +    /// <summary>
    1.19 +    /// Display settings a the specified hardware type
    1.20 +    /// </summary>
    1.21 +    [DataContract]
    1.22 +    public class DisplaySettingsEntry
    1.23 +    {
    1.24 +        public DisplaySettingsEntry()
    1.25 +        {
    1.26 +            Brightness = 1;
    1.27 +            DisplayType = 0;
    1.28 +            TimerInterval = 150;
    1.29 +            ReverseScreen = false;
    1.30 +            ShowBorders = false;
    1.31 +            FontName = "Microsoft Sans Serif, 9.75pt";
    1.32 +        }
    1.33 +
    1.34 +        [DataMember]
    1.35 +        public int Brightness { get; set; }
    1.36 +
    1.37 +        [DataMember]
    1.38 +        public int DisplayType { get; set; }
    1.39 +
    1.40 +        [DataMember]
    1.41 +        public int TimerInterval { get; set; }
    1.42 +
    1.43 +        [DataMember]
    1.44 +        public bool ReverseScreen { get; set; }
    1.45 +
    1.46 +        [DataMember]
    1.47 +        public bool ShowBorders { get; set; }
    1.48 +
    1.49 +        [DataMember]
    1.50 +        public string FontName { get; set; }
    1.51 +
    1.52 +        public Font Font
    1.53 +        {
    1.54 +            get
    1.55 +            {
    1.56 +                FontConverter cvt = new FontConverter();
    1.57 +                Font font = cvt.ConvertFromInvariantString(FontName) as Font;
    1.58 +                return font;
    1.59 +            }
    1.60 +
    1.61 +            set
    1.62 +            {
    1.63 +                FontConverter cvt = new FontConverter();
    1.64 +                FontName = cvt.ConvertToInvariantString(value);
    1.65 +            }
    1.66 +        }
    1.67 +    };
    1.68 +
    1.69 +
    1.70 +    [TypeConverter(typeof(DisplaySettingsConverter))]
    1.71 +    [DataContract]
    1.72 +    public class DisplaySettings
    1.73 +    {
    1.74 +        public DisplaySettings()
    1.75 +        {
    1.76 +            Init();
    1.77 +        }
    1.78 +
    1.79 +        public void Init()
    1.80 +        {
    1.81 +            if (Displays == null)
    1.82 +            {
    1.83 +                Displays = new List<DisplaySettingsEntry>();
    1.84 +            }
    1.85 +        }
    1.86 +
    1.87 +        //[DataMember]
    1.88 +        //public int CurrentSettingsIndex { get; set; }
    1.89 +
    1.90 +        [DataMember]
    1.91 +        public List<DisplaySettingsEntry> Displays { get; set; }
    1.92 +
    1.93 +        public override string ToString()
    1.94 +        {
    1.95 +            //Save settings into JSON string
    1.96 +            MemoryStream stream = new MemoryStream();
    1.97 +            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(DisplaySettings));
    1.98 +            ser.WriteObject(stream, this);
    1.99 +            // convert stream to string
   1.100 +            stream.Position = 0;
   1.101 +            StreamReader reader = new StreamReader(stream);
   1.102 +            string text = reader.ReadToEnd();
   1.103 +            return text;
   1.104 +        }
   1.105 +    }
   1.106 +
   1.107 +    public class DisplaySettingsConverter : TypeConverter
   1.108 +    {
   1.109 +        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
   1.110 +        {
   1.111 +            if (sourceType == typeof(string))
   1.112 +                return true;
   1.113 +            else
   1.114 +                return base.CanConvertFrom(context, sourceType);
   1.115 +        }
   1.116 +
   1.117 +        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
   1.118 +        {
   1.119 +            string stringValue = value as string;
   1.120 +            if (stringValue != null)
   1.121 +            {   
   1.122 +                //Load settings form JSON string
   1.123 +                byte[] byteArray = Encoding.UTF8.GetBytes(stringValue);
   1.124 +                MemoryStream stream = new MemoryStream(byteArray);
   1.125 +                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(DisplaySettings));
   1.126 +                DisplaySettings settings = (DisplaySettings)ser.ReadObject(stream);
   1.127 +                settings.Init();
   1.128 +                return settings;
   1.129 +            }
   1.130 +            else
   1.131 +                return base.ConvertFrom(context, culture, value);
   1.132 +        }
   1.133 +    };
   1.134 +
   1.135 +
   1.136 +}
   1.137 +