public AppProps ReadAppProps() { AppProps appProps = null; var isLocalDev = false; var streamInfo = Application.GetResourceStream(new Uri(Constants.LocalConfigFileName, UriKind.Relative)); if (null != streamInfo) { isLocalDev = true; } else { streamInfo = Application.GetResourceStream(new Uri(Constants.ConfigFileName, UriKind.Relative)); } if (null != streamInfo) { var sr = new StreamReader(streamInfo.Stream); var fileContent = sr.ReadToEnd(); appProps = JsonConvert.DeserializeObject <AppProps>(fileContent); if (isLocalDev) { appProps.IsLocalDevelopment = true; } } else { throw new IOException("Can not find resource " + Constants.ConfigFileName); } return(appProps); }
// constructors /// <summary> /// /// </summary> /// <param name="moduleInfo"></param> /// <param name="cryptoManager"></param> /// <param name="itemKind"></param> /// <param name="transient"></param> /// <param name="appScope"></param> /// <param name="name"></param> /// <param name="props"></param> /// <param name="data"></param> /// <param name="dataType"></param> /// <param name="serialFormat"></param> /// <param name="lifetime"></param> public ServerItem( IModuleInfo moduleInfo, ICryptoManager cryptoManager, ItemKind itemKind, bool transient, string appScope, string name, NamedValueSet props, object data, Type dataType, SerialFormat serialFormat, TimeSpan lifetime) : base(itemKind, transient, name, appScope) { _moduleInfo = moduleInfo ?? throw new ArgumentNullException(nameof(moduleInfo)); _cryptoManager = cryptoManager ?? throw new ArgumentNullException(nameof(cryptoManager)); if (dataType == null) { throw new ArgumentNullException(nameof(dataType)); } SysProps.Set(SysPropName.SAlg, (int)serialFormat); AppProps.Add(props); _data = data; _dataTypeType = dataType; DataTypeName = dataType.FullName; _lifetime = lifetime; }
private FHConfig(AppProps props, string dest, string uuid) { _appProps = props; _destination = dest; _deviceid = uuid; IsLocalDevelopment = props.IsLocalDevelopment; }
public AppProps ReadAppProps() { if (null == appProps) { bool localDev = false; string path = NSBundle.MainBundle.PathForResource(LOCAL_DEV_APP_PROPS_FILE, "plist"); if (null == path) { path = NSBundle.MainBundle.PathForResource(APP_PROPS_FILE, "plist"); } else { localDev = true; } NSDictionary props = NSDictionary.FromFile(path); appProps = new AppProps(); appProps.host = ((NSString)props["host"]).ToString(); appProps.appid = null == props["appid"]? null : ((NSString)props ["appid"]).ToString(); appProps.appkey = null == props["appkey"]? null : ((NSString)props ["appkey"]).ToString(); appProps.projectid = null == props ["projectid"] ? null : ((NSString)props ["projectid"]).ToString(); appProps.connectiontag = null == props ["connectiontag"] ? null : ((NSString)props ["connectiontag"]).ToString(); appProps.mode = null == props ["mode"] ? null : ((NSString)props ["mode"]).ToString(); if (localDev) { appProps.IsLocalDevelopment = true; } } return(appProps); }
public void Can_initialize_from_string_collection_ctor() { var appProps = new AppProps(new[] { "key1=value1", "key2=value2" }); Assert.AreEqual(2, appProps.Count); Assert.AreEqual("value1", appProps["key1"]); Assert.AreEqual("value2", appProps["key2"]); }
public void Can_initialize_from_items_collection_ctor() { var appProps = new AppProps(new[] { new AppPropsItem("key1=value1"), new AppPropsItem("key2=value2") }); Assert.AreEqual(2, appProps.Count); Assert.AreEqual("value1", appProps["key1"]); Assert.AreEqual("value2", appProps["key2"]); }
public AppProps ReadAppProps() { if (null == appPropsObj) { Properties appProps = new Properties(); Stream input = null; ILogService logger = ServiceFinder.Resolve <ILogService>(); bool foundLocalDevProps = false; try { try { input = Application.Context.Assets.Open(LOCAL_DEV_APP_PROP_FILE); foundLocalDevProps = true; } catch (Exception ex) { input = null; foundLocalDevProps = false; input = Application.Context.Assets.Open(APP_PROP_FILE); } appProps.Load(input); appPropsObj = new AppProps(); appPropsObj.projectid = appProps.GetProperty(PROJECT_ID_PROP); appPropsObj.appid = appProps.GetProperty(APP_ID_PROP); appPropsObj.appkey = appProps.GetProperty(APP_KEY_PROP); appPropsObj.host = appProps.GetProperty(HOST_PROP); appPropsObj.connectiontag = appProps.GetProperty(CONNECTION_TAG_PROP); appPropsObj.mode = appProps.GetProperty(MODE_PROP); if (foundLocalDevProps) { appPropsObj.IsLocalDevelopment = true; } return(appPropsObj); } catch (Exception ex) { if (null != logger) { logger.e(TAG, "Failed to load " + APP_PROP_FILE, ex); } return(null); } finally { if (null != input) { try { input.Close(); } catch (Exception exc) { if (null != logger) { logger.w(TAG, "Failed to close stream", exc); } } } } } return(appPropsObj); }
public void Can_merge_intersecting_props() { var p1 = new AppProps(); p1.Append("key1", "value1"); var p2 = new AppProps(); p2.Append("key1", "value2"); var merged = AppProps.Merge(p1, p2); Assert.AreEqual("value2", merged["key1"]); AssertItemsCountInOutputFile(merged, 1); }
public AppProps ReadAppProps() { if (null == appPropsObj) { Properties appProps = new Properties(); Stream input = null; ILogService logger = ServiceFinder.Resolve<ILogService>(); bool foundLocalDevProps = false; try { try { input = Application.Context.Assets.Open(LOCAL_DEV_APP_PROP_FILE); foundLocalDevProps = true; } catch (Exception ex) { input = null; foundLocalDevProps = false; input = Application.Context.Assets.Open(APP_PROP_FILE); } appProps.Load(input); appPropsObj = new AppProps(); appPropsObj.projectid = appProps.GetProperty(PROJECT_ID_PROP); appPropsObj.appid = appProps.GetProperty(APP_ID_PROP); appPropsObj.appkey = appProps.GetProperty(APP_KEY_PROP); appPropsObj.host = appProps.GetProperty(HOST_PROP); appPropsObj.connectiontag = appProps.GetProperty(CONNECTION_TAG_PROP); appPropsObj.mode = appProps.GetProperty(MODE_PROP); if(foundLocalDevProps){ appPropsObj.IsLocalDevelopment = true; } return appPropsObj; } catch (Exception ex) { if(null != logger) { logger.e(TAG, "Failed to load " + APP_PROP_FILE, ex); } return null; } finally { if(null != input){ try { input.Close(); } catch (Exception exc) { if(null != logger){ logger.w(TAG, "Failed to close stream", exc); } } } } } return appPropsObj; }
public AppProps ReadAppProps() { if (null != _appPropsObj) { return(_appPropsObj); } var appProps = new Properties(); Stream input = null; var logger = ServiceFinder.Resolve <ILogService>(); try { bool foundLocalDevProps; try { input = Application.Context.Assets.Open(LocalDevAppPropFile); foundLocalDevProps = true; } catch (Exception) { input = null; foundLocalDevProps = false; input = Application.Context.Assets.Open(AppPropFile); } appProps.Load(input); _appPropsObj = new AppProps { projectid = appProps.GetProperty(ProjectIdProp), appid = appProps.GetProperty(AppIdProp), appkey = appProps.GetProperty(AppKeyProp), host = appProps.GetProperty(HostProp), connectiontag = appProps.GetProperty(ConnectionTagProp), mode = appProps.GetProperty(ModeProp) }; if (foundLocalDevProps) { _appPropsObj.IsLocalDevelopment = true; } return(_appPropsObj); } catch (Exception ex) { logger?.e(Tag, "Failed to load " + AppPropFile, ex); return(null); } finally { input?.Dispose(); } }
public AppProps ReadAppProps() { var props = new AppProps { host = Host, projectid = ProjectId, appid = AppId, appkey = AppKey, connectiontag = ConnectionTag, IsLocalDevelopment = true }; return(props); }
public AppProps ReadAppProps() { if (null != _appPropsObj) return _appPropsObj; var appProps = new Properties(); Stream input = null; var logger = ServiceFinder.Resolve<ILogService>(); try { bool foundLocalDevProps; try { input = Application.Context.Assets.Open(LocalDevAppPropFile); foundLocalDevProps = true; } catch (Exception) { input = null; foundLocalDevProps = false; input = Application.Context.Assets.Open(AppPropFile); } appProps.Load(input); _appPropsObj = new AppProps { projectid = appProps.GetProperty(ProjectIdProp), appid = appProps.GetProperty(AppIdProp), appkey = appProps.GetProperty(AppKeyProp), host = appProps.GetProperty(HostProp), connectiontag = appProps.GetProperty(ConnectionTagProp), mode = appProps.GetProperty(ModeProp) }; if (foundLocalDevProps) { _appPropsObj.IsLocalDevelopment = true; } return _appPropsObj; } catch (Exception ex) { logger?.e(Tag, "Failed to load " + AppPropFile, ex); return null; } finally { input?.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="itemKind"></param> /// <param name="transient"></param> /// <param name="appScope"></param> /// <param name="name"></param> /// <param name="props"></param> /// <param name="serialisedData"></param> /// <param name="dataTypeName"></param> /// <param name="lifetime"></param> public ServerItem( ItemKind itemKind, bool transient, string appScope, string name, NamedValueSet props, string serialisedData, string dataTypeName, TimeSpan lifetime) : base(itemKind, transient, name, appScope) { AppProps.Add(props); _text = serialisedData; SysProps.Set(SysPropName.SAlg, (int)SerialFormat.Undefined); DataTypeName = dataTypeName; _lifetime = lifetime; }
public AppProps ReadAppProps() { if (null != _appProps) return _appProps; var props = ReadProperties(); _appProps = new AppProps { host = ((NSString) props["host"]).ToString(), appid = ((NSString) props["appid"])?.ToString(), appkey = ((NSString) props["appkey"])?.ToString(), projectid = ((NSString) props["projectid"])?.ToString(), connectiontag = ((NSString) props["connectiontag"])?.ToString(), mode = ((NSString) props["mode"])?.ToString() }; if (_localDev) { _appProps.IsLocalDevelopment = true; } return _appProps; }
public int EstimatedSizeInBytes(bool excludeDataBody) { // the calculated overhead is actually 1745 bytes, but we are allowing for // errors and variations in both the header and body fragments, of up to 250 bytes. const int bytesPerStringChar = 2; // 16-bit Unicode strings int result = 2000; // overhead result += Name?.Length * bytesPerStringChar ?? 0; result += DataTypeName?.Length * bytesPerStringChar ?? 0; result += AppScope?.Length * bytesPerStringChar ?? 0; result += NetScope?.Length * bytesPerStringChar ?? 0; result += (AppProps.Serialise().Length *bytesPerStringChar); // hack - slow - todo - use Text property result += (SysProps.Serialise().Length *bytesPerStringChar); // hack - slow - todo - use Text property if (!excludeDataBody) { result += YData?.Length ?? 0; result += YSign?.Length ?? 0; } const int bufferBytesPerByte = 2; return(result * bufferBytesPerByte); }
public AppProps ReadAppProps() { if (null != _appProps) { return(_appProps); } var props = ReadProperties(); _appProps = new AppProps { host = ((NSString)props["host"]).ToString(), appid = ((NSString)props["appid"])?.ToString(), appkey = ((NSString)props["appkey"])?.ToString(), projectid = ((NSString)props["projectid"])?.ToString(), connectiontag = ((NSString)props["connectiontag"])?.ToString(), mode = ((NSString)props["mode"])?.ToString() }; if (_localDev) { _appProps.IsLocalDevelopment = true; } return(_appProps); }
public AppProps ReadAppProps() { if (null == appProps) { bool localDev = false; string path = NSBundle.MainBundle.PathForResource (LOCAL_DEV_APP_PROPS_FILE, "plist"); if(null == path){ path = NSBundle.MainBundle.PathForResource(APP_PROPS_FILE, "plist"); } else { localDev = true; } NSDictionary props = NSDictionary.FromFile (path); appProps = new AppProps (); appProps.host = ((NSString) props["host"]).ToString(); appProps.appid = null == props["appid"]? null : ((NSString)props ["appid"]).ToString(); appProps.appkey = null == props["appkey"]? null : ((NSString)props ["appkey"]).ToString(); appProps.projectid = null == props ["projectid"] ? null : ((NSString)props ["projectid"]).ToString(); appProps.connectiontag = null == props ["connectiontag"] ? null : ((NSString)props ["connectiontag"]).ToString(); appProps.mode = null == props ["mode"] ? null : ((NSString)props ["mode"]).ToString(); if(localDev){ appProps.IsLocalDevelopment = true; } } return appProps; }
/// <summary> /// Initializer used for unit testing. /// </summary> /// <param name="deviceService"></param> public FHConfig(IDeviceService deviceService) { _appProps = deviceService.ReadAppProps(); _destination = deviceService.GetDeviceDestination(); _deviceid = deviceService.GetDeviceId(); }
private static void AssertItemsCountInOutputFile(AppProps p, int count) { String path = Path.GetTempFileName(); p.SaveToFile(path); try { Assert.AreEqual(count, File.ReadAllLines(path).Length); } finally { File.Delete(path); } }
public void Can_return_existing_value_when_contains_key() { var appProps = new AppProps(new[] { new AppPropsItem("key1=value1"), new AppPropsItem("key2=value2") }); Assert.AreEqual("value1", appProps.GetExistingOrDefault("key1", "defaultValue")); }