Exemple #1
0
        /// <summary>
        /// Executes until the agent is cancelled
        /// </summary>
        protected virtual void Spin()
        {
            var MaxSpinnerCount = 5;

            try
            {
                while (!IsAgentCancelling)
                {
                    var submissions = MutableList.Create <WorkPartition>();
                    if (Spinners.Count < MaxSpinnerCount)
                    {
                        submissions.AddRange(SubmitNext());
                        if (HasPendingTasks)
                        {
                            iter(ExecuteQueue(), task => { });
                            if (!DiagnosticMode)
                            {
                                SpinUpSpinner();
                            }
                        }
                    }
                    CompleteRevolution(submissions.Count);
                }
            }
            catch (Exception e)
            {
                Notify(AppMessage.Error(e));
            }
        }
Exemple #2
0
        public Option <FlowOneToMany> ExpandArchive(FilePath Src, FolderPath Dst, bool Overwrite = true)
        {
            try
            {
                Dst.CreateIfMissing().Require();

                var paths = MutableList.Create <FilePath>();
                using (var stream = new FileStream(Src, FileMode.Open))
                {
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Read))
                    {
                        foreach (var entry in archive.Entries)
                        {
                            var dstPath = Dst.GetCombinedFilePath(RelativePath.Parse(entry.FullName));
                            if (dstPath.Exists() && not(Overwrite))
                            {
                                dstPath = dstPath.UniqueName();
                            }
                            else
                            {
                                dstPath.DeleteIfExists().Require();
                            }
                            paths.Add(Expand(entry, dstPath).Target);
                        }
                    }
                }
                return(new FlowOneToMany(Src, paths.ToReadOnlyList()));
            }
            catch (Exception e)
            {
                return(none <FlowOneToMany>(e));
            }
        }
Exemple #3
0
        public static ReadOnlySet <T> Create <T>(params G.IEnumerable <T>[] sequences)
        {
            var list = MutableList.Create <T>();

            sequences.Where(s => s != null).Iterate(s => list.AddRange(s));
            return(new ReadOnlySet <T>(list));
        }
Exemple #4
0
        public JsonDocument ParseDocument(string json)
        {
            var values = MutableList.Create <IJsonValue>();

            foreach (var kvp in JsonConvert.DeserializeObject <JObject>(json, settings))
            {
                TryParse(kvp.Key, kvp.Value).OnSome(v => values.Add(v));
            }
            return(new JsonDocument(values, json));
        }
Exemple #5
0
        static IEnumerable <IJsonValue> ParseChildren(JToken token)
        {
            var children = MutableList.Create <IJsonValue>();

            foreach (var jChild in token.Children())
            {
                TryParse(ParseName(jChild), jChild).OnSome(child => children.Add(child));
            }
            return(children);
        }
Exemple #6
0
        static Option <IJsonValue> TryParseArray(string name, JToken value)
        {
            var result = none <IJsonValue>();

            if (value.Type == JTokenType.Array)
            {
                var jArray = value as JArray;
                var items  = MutableList.Create <IJsonValue>();

                var i = 0;
                foreach (var jItem in jArray.Children())
                {
                    TryParse($"array_item {i++}", jItem).OnSome(item => items.Add(item));
                }
                result = new JsonArrayValue(name, items);
            }
            return(result);
        }
Exemple #7
0
 protected Junction(IEnumerable <IPredicateAplication> Criteria, Junction Parent = null)
 {
     this.Criteria = MutableList.FromItems(Criteria.ToList());
     this.Parent   = Parent;
     this.Children = MutableList.Create <Junction>();
 }