Exemple #1
0
 public SomeHttpBasedResourceBackedDeviceValue(WebClient webClient, string getResourceTemplate, string setResourceTemplate, DeviceValueAccess access)
 {
     this.webClient           = webClient;
     this.getResourceTemplate = getResourceTemplate;
     this.setResourceTemplate = setResourceTemplate;
     this.access = access;
 }
 public static T Deserialize(string s, DeviceValueAccess access)
 {
     if ((access & DeviceValueAccess.Read) == 0)
     {
         throw new DeviceAccessDeniedException(access, DeviceValueAccess.Read);
     }
     else if (typeof(T) == typeof(string))
     {
         return((T)(object)s);
     }
     else if (typeof(T) == typeof(int))
     {
         return((T)(object)int.Parse(s));
     }
     else if (typeof(T) == typeof(float))
     {
         return((T)(object)float.Parse(s));
     }
     else if (typeof(T) == typeof(bool))
     {
         return((T)(object)s.ContainsAny(new[] { "1", "true" }, StringComparison.OrdinalIgnoreCase));
     }
     else
     {
         throw new InvalidOperationException($"Attempted to deserialize unhandled type: {typeof(T)}");
     }
 }
 public static string Serialize(T value, DeviceValueAccess access)
 {
     if ((access & DeviceValueAccess.Write) == 0)
     {
         throw new DeviceAccessDeniedException(access, DeviceValueAccess.Write);
     }
     else if (typeof(T) == typeof(string) || typeof(T) == typeof(int) || typeof(T) == typeof(float))
     {
         return(value.ToString());
     }
     else if (typeof(T) == typeof(bool))
     {
         return((bool)(object)value ? "1" : "0");
     }
     else
     {
         throw new InvalidOperationException($"Attempted to serialize unhandled type: {typeof(T)}");
     }
 }
 public IDeviceValue <T> FromHttpBasedResource <T>(string getResourceTemplate, string setResourceTemplate, DeviceValueAccess access)
 {
     return(new SomeHttpBasedResourceBackedDeviceValue <T>(
                wc,
                getResourceTemplate,
                setResourceTemplate,
                access));
 }
 public IDeviceValue <T> FromFileCached <T>(string path, DeviceValueAccess access)
 {
     return(WithCache(FromFile <T>(path, access)));
 }
 public IDeviceValue <T> FromFile <T>(string path, DeviceValueAccess access)
 {
     return(new FileBackedDeviceValueImpl <T>(path, access, internalFileSystemProxy));
 }
 private static string GetMessage(DeviceValueAccess accessGranted, DeviceValueAccess accessRequired)
 {
     return $"Operation required access {accessRequired} but have granted {accessGranted}.";
 }
 public DeviceAccessDeniedException(DeviceValueAccess accessGranted, DeviceValueAccess accessRequired)
     : base(GetMessage(accessGranted, accessRequired))
 {
     this.accessGranted = accessGranted;
      this.accessRequired = accessRequired;
 }
Exemple #9
0
 public FileBackedDeviceValueImpl(string path, DeviceValueAccess access, IInternalFileSystemProxy internalFileSystemProxy)
 {
     this.path   = path;
     this.access = access;
     this.internalFileSystemProxy = internalFileSystemProxy;
 }
 public DeviceAccessDeniedException(DeviceValueAccess accessGranted, DeviceValueAccess accessRequired)
     : base(GetMessage(accessGranted, accessRequired))
 {
     this.accessGranted  = accessGranted;
     this.accessRequired = accessRequired;
 }
 private static string GetMessage(DeviceValueAccess accessGranted, DeviceValueAccess accessRequired)
 {
     return($"Operation required access {accessRequired} but have granted {accessGranted}.");
 }