Ejemplo n.º 1
0
        private static async Task <IEnumerable <string> > ExtractArchive
            (string archivePath, string targetDir)
        {
            var zpr  = GetExtractor(archivePath);
            var tcs  = new TaskCompletionSource <IEnumerable <string> >();
            var list = new List <string>();

            zpr.FileExtractionFinished += (s, e)
                                          => list.Add(Chain(targetDir, e.FileInfo.FileName));

            zpr.ExtractionFinished += (s, e) => tcs.SetResult(list);

            zpr.ExtractArchive(targetDir);

            var contents = await tcs.Task;

            if (contents == null)
            {
                throw
                    Fault.NullRef <List <string> >("Extracted paths list");
            }

            if (contents.Count() == 0)
            {
                throw
                    Fault.NoMember("Archive did not contain any file.");
            }

            return(contents);
        }
Ejemplo n.º 2
0
        private static PropertyInfo GetRuntimePropertyByName(string propName)
        {
            var prop = typeof(T).GetRuntimeProperty(propName);

            if (prop == null)
            {
                prop = typeof(T).GetRuntimeProperties()
                       .SingleOrDefault(x => x.Name == propName);
            }

            if (prop == null)
            {
                var props = typeof(T).GetRuntimeProperties();
                prop = props.SingleOrDefault(x => x.Name == propName);
            }
            if (prop == null)
            {
                throw Fault.NoMember(propName);
            }
            return(prop);
        }
Ejemplo n.º 3
0
        private int GetNodeID(Dictionary <string, object> dict)
        {
            if (Result == null)
            {
                throw
                    Fault.NullRef <Dictionary <string, object> >(nameof(Result));
            }

            object obj;

            if (!Result.TryGetValue("nid", out obj))
            {
                throw Fault.NoMember("nid");
            }

            if (obj == null)
            {
                throw Fault.NullRef <object>("nid");
            }

            var json = obj.ToString();

            if (json.IsBlank())
            {
                throw Fault.BlankText("json nid");
            }

            json = json.Replace("\"", "");

            var numbr = json.Between("[{value:", "}]");

            if (!numbr.IsNumeric())
            {
                throw Fault.BadCast <int>(numbr);
            }

            return(numbr.ToInt());
        }