Exemplo n.º 1
0
        public IEnumerable <OrganeModel> Organes(string parentDir)
        {
            var tmp    = RawOrgane.FromDirectory(Path.Combine(parentDir, "organe"));
            var result = new List <OrganeModel>();

            foreach (var rawOrgane in tmp)
            {
                OrganeModel model;
                if (rawOrgane.CodeType == TypeOrgane.Gp)
                {
                    model = new GroupeParlementaireModel(rawOrgane);
                }
                else
                {
                    model = new OrganeModel(rawOrgane);
                }

                if (rawOrgane.OrganeParent != null && _modelStorage.Contains <OrganeModel>(rawOrgane.OrganeParent))
                {
                    model.Parent = _modelStorage.Get <OrganeModel>(rawOrgane.OrganeParent);
                }

                result.Add(model);
            }

            return(result);
        }
Exemplo n.º 2
0
        public static async Task <T> Get <T>(this IObjectStorage reader, string fileName, Func <Stream, T> readerFn, CancellationToken cancellationToken = default)
        {
            var tsc           = new TaskCompletionSource <T>();
            var readerFnProxy = act((Stream s) => { tsc.SetResult(readerFn(s)); });
            await reader.Get(fileName, readerFnProxy, cancellationToken);

            return(await tsc.Task);
        }
Exemplo n.º 3
0
 public static async Task <T> GetJSON <T>(this IObjectStorage reader, string fileName, CancellationToken cancellationToken = default)
 {
     return(await reader.Get(fileName, stream =>
     {
         using (var sr = new StreamReader(stream))
             using (var jsonReader = new JsonTextReader(sr))
             {
                 return JToken.Load(jsonReader).ToObject <T>();
             }
     }, cancellationToken));
 }
Exemplo n.º 4
0
        private static async Task <T> ReadFromStorage <T>(string key, IObjectStorage strage, JsonConverter converter = null)
        {
            if (converter == null)
            {
                converter = new TreeNodeConverter();
            }

            var treeLeftStream = strage.Get(key);

            using (var textStream = new StreamReader(treeLeftStream))
            {
                var data = await textStream.ReadToEndAsync();

                return(JsonConvert.DeserializeObject <T>(data, converter));
            }
        }
 public void Intercept(Castle.DynamicProxy.IInvocation invocation)
 {
     if (setters.ContainsKey(invocation.Method))
     {
         var prop = setters[invocation.Method];
         storage.Set(prop.Name, invocation.Arguments[0]);
         obs.OnNext(prop.Name);
     }
     else if (getters.ContainsKey(invocation.Method))
     {
         invocation.ReturnValue = storage.Get(getters[invocation.Method].Name);
     }
     else
     {
         invocation.Proceed(); //DataStorageInterceptor only implements properties, not methods
     }
 }