Ejemplo n.º 1
0
        public FileSystemCollector(CollectorOptions?opts = null, Action <CollectObject>?changeHandler = null) : base(opts, changeHandler)
        {
            Roots.AddRange(opts?.SelectedDirectories ?? Array.Empty <string>());

            if (!Roots.Any())
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    foreach (var driveInfo in DriveInfo.GetDrives())
                    {
                        if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed)
                        {
                            Roots.Add(driveInfo.Name);
                        }
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Roots.Add("/");
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    Roots.Add("/");
                }
            }
        }
Ejemplo n.º 2
0
        private void SolveQuadratic(double a, double b)
        {
            var sqrD    = ShitMath.Sqrt(Discriminant);
            var rootVal = (-b + sqrD) / (2 * a);
            var rootStr = _shouldNotReduceFraction ? "" + (-b + sqrD + "/" + 2 * a) : "" + rootVal;

            if (Regex.Match(rootStr, @"\-.+\/\-.+").Success)
            {
                rootStr = rootStr.Replace("-", "");
            }
            Steps.Add(
                $"[Calculating first root]\tx0 = (-b + sqrt(D)) / 2a = ({-b} + {sqrD}) / {2 * a} = {rootStr}");
            Roots.Add(rootStr);

            if (Discriminant > 0)
            {
                rootVal = (-b - sqrD) / (2 * a);
                rootStr = _shouldNotReduceFraction ? "" + (-b - sqrD + "/" + 2 * a) : "" + rootVal;
                if (Regex.Match(rootStr, @"\-.+\/\-.+").Success)
                {
                    rootStr = rootStr.Replace("-", "");
                }
                Steps.Add(
                    $"[Calculating second root]\tx0 = (-b - sqrt(D)) / 2a = ({-b} - {sqrD}) / {2 * a} = {rootStr}");
                Roots.Add(rootStr);
            }
        }
Ejemplo n.º 3
0
        internal static void Build(Menu menu, JObject translations, bool createSaveHandler)
        {
            if (Roots.Exists(root => root.Id == menu.Id))
            {
                throw new InvalidOperationException($"Menu with id \"{menu.Id}\" already exists as root!");
            }

            Roots.Add(menu);

            if (translations != null)
            {
                menu.translations.Add(translations);
            }
            else
            {
                menu.UpdateSizes();
            }

            if (createSaveHandler)
            {
                menu.CreateSaveHandler(Folder.Menu);
            }
            else
            {
                menu.SetToken(null);
            }

            menu.UpdateTranslations();
        }
Ejemplo n.º 4
0
 public void Cut(NodeTree x, NodeTree y)
 {
     y.Childrens.Remove(x);
     y.Degree--;
     Roots.Add(x);
     x.Parent = null;
     x.Mark   = false;
 }
Ejemplo n.º 5
0
        /// <summary> Adds a file  object (with the appropriate divisions and pages) to this tree </summary>
        /// <param name="New_File"> New file object to add </param>
        /// <param name="Label"> Label for the page containing this file, if it is a new page </param>
        /// <remarks> This is generally used to add just a single file.  To add many files, better logic should be implemented </remarks>
        public void Add_File(SobekCM_File_Info New_File, string Label)
        {
            // Determine the upper case name
            string systemname_upper = New_File.File_Name_Sans_Extension;

            // Look for a page/entity which has the same file name, else it will be added to the last division
            foreach (abstract_TreeNode rootNode in Roots)
            {
                if (recursively_add_file(rootNode, New_File, systemname_upper))
                {
                    return;
                }
            }

            // If not found, find the last division
            if (Roots.Count > 0)
            {
                if (!Roots[Roots.Count - 1].Page)
                {
                    // Get his last division
                    Division_TreeNode lastDivision = (Division_TreeNode)Roots[Roots.Count - 1];

                    // Find the last division then
                    while ((lastDivision.Nodes.Count > 0) && (!lastDivision.Nodes[lastDivision.Nodes.Count - 1].Page))
                    {
                        lastDivision = (Division_TreeNode)lastDivision.Nodes[lastDivision.Nodes.Count - 1];
                    }

                    // Add this as a new page on the last division
                    Page_TreeNode newPage = new Page_TreeNode(Label);
                    lastDivision.Add_Child(newPage);

                    // Now, add this file to the page
                    newPage.Files.Add(New_File);
                }
                else
                {
                    // No divisions at all, but pages exist at the top level, which is okay
                    Page_TreeNode pageNode = (Page_TreeNode)Roots[Roots.Count - 1];

                    // Now, add this file to the page
                    pageNode.Files.Add(New_File);
                }
            }
            else
            {
                // No nodes exist, so add a MAIN division node
                Division_TreeNode newDivNode = new Division_TreeNode("Main", String.Empty);
                Roots.Add(newDivNode);

                // Add this as a new page on the new division
                Page_TreeNode newPage = new Page_TreeNode(Label);
                newDivNode.Add_Child(newPage);

                // Now, add this file to the page
                newPage.Files.Add(New_File);
            }
        }
Ejemplo n.º 6
0
        public void AddChild(long?parentId, long id, T data)
        {
            if (Data.ContainsKey(id))
            {
                throw new ArgumentException($"id {id} already exists in tree.");
            }

            if (parentId != null && !Data.ContainsKey((long)parentId))
            {
                throw new ArgumentException($"parentId {parentId} not found in tree.");
            }

            var link = new NodeLink {
                Id = id, Parent = parentId
            };
            var depth = 0;

            if (parentId == null)
            {
                if (Roots.Any())
                {
                    Links[Roots[Roots.Count - 1]].Next = id;
                }

                Roots.Add(id);
            }
            else
            {
                var parentLink = Links[(long)parentId];

                depth = parentLink.Depth + 1;

                if (parentLink.Child != null)
                {
                    link.Next = parentLink.Child;
                }
                else
                {
                    Leaves.Remove((long)parentId);
                }
                parentLink.Child = id;
            }

            // Saves data

            Data.Add(id, data);

            // Saves link

            link.Depth = depth;
            Links.Add(id, link);

            // Registers as leaf

            Leaves.Add(id);
        }
Ejemplo n.º 7
0
        private void Reload()
        {
            Roots.Clear();

            var entities = m_Scene.ToEntityArray(m_EntityManager, Allocator.TempJob);

            try
            {
                using (var pooledDictionary = DictionaryPool <Entity, EntityNode> .GetDisposable())
                    using (var pooledList = ListPool <Entity> .GetDisposable())
                    {
                        var entityCache = pooledDictionary.Dictionary;
                        var allEntities = pooledList.List;
                        for (var i = 0; i < entities.Length; ++i)
                        {
                            var entity     = entities[i];
                            var entityNode = new EntityNode(this, m_Session, entity);
                            allEntities.Add(entity);
                            entityCache.Add(entity, entityNode);
                        }

                        for (var i = 0; i < allEntities.Count; ++i)
                        {
                            var entity = allEntities[i];
                            var node   = entityCache[entity];

                            EntityNode parent = null;

                            // Do we have a transform parent?
                            if (m_EntityManager.HasComponent <Parent>(entity))
                            {
                                var Parent = m_EntityManager.GetComponentData <Parent>(entity);
                                entityCache.TryGetValue(Parent.Value, out parent);
                            }

                            if (null != parent)
                            {
                                node.Parent = parent;
                                parent.Children.Add(node);
                            }
                            else
                            {
                                Roots.Add(node);
                            }
                        }
                    }
            }
            finally
            {
                entities.Dispose();
            }

            SortBySiblingIndex(Roots);
            ForceSiblingIndex(Roots, true);
        }
Ejemplo n.º 8
0
        public void PutRoot(Identifier identifier)
        {
            var stored = getStored(identifier);

            if (!Roots.Contains(stored))
            {
                connection.ExecutePortableSql("insert into :[dbo.nrdo_object] (:[type], :[name]) values (:type, :name)",
                                              cmd => setRootParams(cmd, identifier));
                Roots.Add(stored);
            }
        }
Ejemplo n.º 9
0
        private void SolveLinear(double b, double c)
        {
            var rootVal = -c / b;
            var rootStr = _shouldNotReduceFraction ? -c + "/" + b : "" + rootVal;

            if (Regex.Match(rootStr, @"\-.+\/\-.+").Success)
            {
                rootStr = rootStr.Replace("-", "");
            }
            Steps.Add($"[Calculating root]\t\tx = -c/b = {-c}/{b} = {rootStr}");
            Roots.Add(rootStr);
        }
Ejemplo n.º 10
0
 private void Add(KmlNode parent, KmlItem child)
 {
     if (parent == null)
     {
         Roots.Add(child);
     }
     else
     {
         parent.Add(child);
     }
     Count(parent, child);
 }
Ejemplo n.º 11
0
        public void AddRoot(long id, T data)
        {
            Roots.Add(id);

            Data.Add(id, data);

            Links.Add(id, new NodeLink {
                Id = id
            });

            // set next of the previous last root to the current one id
            Links[Roots[Roots.Count - 1]].Next = id;
        }
Ejemplo n.º 12
0
        private IDisposable BindCommands(IDialogManager dialogManager)
        {
            OpenFolderCommand = ReactiveCommand.CreateFromObservable(
                () => dialogManager.OpenFolder(null), null, RxApp.MainThreadScheduler);

            return(OpenFolderCommand
                   .SubscribeOn(RxApp.TaskpoolScheduler)
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .SubscribeWithLog(directory =>
            {
                var path = Path.GetFullPath(directory);

                if (Roots.All(r => r != path))
                {
                    Roots.Add(path);
                }
            }));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Opens and parses the BVH file at the specifie path.
        /// </summary>
        public BVH(string path)
        {
            var fm = new NSFileManager();

            if (path == null || !fm.FileExists(path))
            {
                throw new Exception($"Could not find file '{Path.GetFileName(path)}'.");
            }
            var data     = fm.Contents(path);
            var contents = new NSString(data, NSStringEncoding.UTF8).ToString();
            var lines    = contents.Split(new[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            var lineCounter = 1;             // start with first line of hierarchy, which should be ROOT

            while (true)
            {
                Roots.Add(ParseNode(lines, ref lineCounter));
                lineCounter++;
                if (!lines[lineCounter].TrimStart(' ').StartsWith("ROOT", StringComparison.InvariantCulture))
                {
                    break;
                }
            }

            if (!string.Equals(lines[lineCounter], "MOTION"))
            {
                throw new Exception($"Expected MOTION but encountered invalid line: {lines[lineCounter]}");
            }

            lineCounter  += 2;            // skip the "Frames: x" line and get "Frame Time: y"
            FrameTimeSecs = double.Parse(lines[lineCounter].Split('\t')[1]);

            lineCounter++;
            for (; lineCounter < lines.Length; lineCounter++)
            {
                var motions = lines[lineCounter]
                              .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                              .Select(double.Parse).ToList();
                for (var i = 0; i < motions.Count; i++)
                {
                    _channels.ElementAt(i).Key.Motions.Add(motions[i]);
                }
            }
        }
Ejemplo n.º 14
0
        public void Solve()
        {
            double a, b, c;

            if (!DegreeCheck())
            {
                return;
            }
            if (Degree == 0)
            {
                SolutionType = SolutionTypes.Any;
                return;
            }

            EquationParser.SetCoefficients(out a, out b, out c, ref _equation);
            Steps.Add($"[Reading coefficients]\t\ta = {a}, b = {b}, c = {c}");

            if (a == 0)
            {
                if (c == 0)
                {
                    Roots.Add("0");
                }
                else
                {
                    SolveLinear(b, c);
                }

                return;
            }

            Discriminant = b * b - 4 * a * c;
            Steps.Add($"[Calculating discriminant]\tD = b^2 - 4ac = {b}^2 - 4 * {a} * {c} = {Discriminant}");
            if (Discriminant >= 0)
            {
                SolveQuadratic(a, b);
            }
            else
            {
                SolveComplex(a, b);
            }
        }
Ejemplo n.º 15
0
        public void Rename(Identifier from, Identifier to)
        {
            if (!object.Equals(from.ObjectType, to.ObjectType))
            {
                throw new ArgumentException("Cannot rename between different object types " + from.ObjectType + " and " + to.ObjectType);
            }

            var storedFrom = getStored(from);
            var storedTo   = getStored(to);

            if (!Roots.Contains(storedFrom))
            {
                throw new ArgumentException("Cannot store rename from " + from + " to " + to + " because " + from + " does not exist in state table");
            }

            if (Roots.Contains(storedTo))
            {
                throw new ArgumentException("Cannot store rename from " + from + " to " + to + " because " + to + " already exists in state table");
            }

            connection.ExecutePortableSql("insert into :[dbo.nrdo_object] (:[type], :[name]) values (:type, :name)",
                                          cmd => setRootParams(cmd, to));
            Roots.Add(storedTo);

            connection.ExecutePortableSql("update :[dbo.nrdo_object_sub] set :[parent_name] = :toname where :[parent_type] = :type and parent_name = :fromname",
                                          cmd =>
            {
                cmd.SetString("toname", "varchar", to.Name);
                cmd.SetString("type", "varchar", from.ObjectType.Name);
                cmd.SetString("fromname", "varchar", from.Name);
            });
            var newSubs = from sub in Subs where identComparer.Equals(sub.Parent, storedFrom) select new StoredSub(storedTo, sub.Child);

            Subs.UnionWith(newSubs.ToImmutableList());
            Subs.RemoveWhere(sub => identComparer.Equals(sub.Parent, storedFrom));

            connection.ExecutePortableSql("delete from :[dbo.nrdo_object] where :[type] = :type and :[name] = :name",
                                          cmd => setRootParams(cmd, from));
            Roots.Remove(storedFrom);
        }
Ejemplo n.º 16
0
        public void RootCalculate()
        {
            if (A == 0)
            {
                throw new Exception("Function is linear, no roots");
            }

            CalculateDelta();
            double divider = 2 * A;

            if (Delta > 0)
            {
                Roots.Add((-B / divider) + (Math.Sqrt(Delta) / divider));
                Roots.Add((-B / divider) - (Math.Sqrt(Delta) / divider));
                return;
            }

            if (Delta == 0)
            {
                Roots.Add(-B / divider);
                return;
            }
        }
Ejemplo n.º 17
0
        private void SolveComplex(double a, double b)
        {
            var sqrD      = ShitMath.Sqrt(-Discriminant);
            var real      = -b / (2 * a);
            var imaginary = ShitMath.Abs(sqrD / (2 * a));
            var rStr      = _shouldNotReduceFraction ? -b + "/" + 2 * a : "" + real;
            var iStr      = _shouldNotReduceFraction ? sqrD + "/" + 2 * a : "" + imaginary;

            Steps.Add($"[Real part of roots]\t\tr = -b / 2a = {-b} / {2 * a} = {rStr}");
            Steps.Add($"[Imaginary part of roots]\ti = sqrt(D) / 2a = {sqrD} / {2 * a} = {iStr}");
            Steps.Add($"[Calculating first root]\tx0 = r - i = {rStr} - {iStr}i");
            Steps.Add($"[Calculating second root]\tx1 = r + i = {rStr} + {iStr}i");
            if (Regex.Match(rStr, @"\-.+\/\-.+").Success)
            {
                rStr = rStr.Replace("-", "");
            }
            if (Regex.Match(iStr, @"\-.+\/\-.+").Success)
            {
                iStr = iStr.Replace("-", "");
            }
            Roots.Add(rStr + " - " + iStr + "i");
            Roots.Add(rStr + " + " + iStr + "i");
        }
Ejemplo n.º 18
0
 public void AddRoot(AstNode node)
 {
     Roots.Add(node);
     if (node is AstForeign)
     {
         Foreigns.Add((AstForeign)node);
     }
     //else if (node is AstExtend)
     //{
     //    Extends.Add((AstExtend)node);
     //}
     else if (node is AstFunc)
     {
         AddFunc((AstFunc)node);
     }
     else if (node is AstStruct)
     {
         Structs.Add((AstStruct)node);
     }
     else
     {
         TopLevelStatements.Add(node);
     }
 }
        public FileSystemCollector(CollectorOptions?opts = null, Action <CollectObject>?changeHandler = null) : base(opts, changeHandler)
        {
            Roots.AddRange(opts?.SelectedDirectories ?? new List <string>());

            if (!Roots.Any())
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    foreach (var driveInfo in DriveInfo.GetDrives())
                    {
                        if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed)
                        {
                            Roots.Add(driveInfo.Name);
                        }
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    foreach (var directory in Directory.EnumerateDirectories("/"))
                    {
                        if (!directory.Equals("/proc") && !directory.Equals("/sys"))
                        {
                            Roots.Add(directory);
                        }
                        else
                        {
                            Log.Debug("Default settings skip directories /proc and /sys because they tend to have non-files which stall the collector.");
                        }
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    Roots.Add("/");
                }
            }
        }
        private void Check(int column)
        {
            from     = column;
            fromPile = FindTableau[from];
            if (fromPile.Count == 0)
            {
                // No cards.
                return;
            }

            // Configure the working tableau.
            WorkingTableau.Variation = Variation;

            // Find roots.
            Roots.Clear();
            int row = fromPile.Count;

            Roots.Add(row);
            while (row > 0)
            {
                int count = fromPile.GetRunUpAnySuit(row);
                row -= count;
                Roots.Add(row);
            }
            int runs = Roots.Count - 1;

            if (runs <= 1)
            {
                // Not at least two runs.
                return;
            }

            // Check first with no uncovering moves.
            best = -1;
            CheckOne(Move.Empty);

            Used.Clear();
            for (int i = 0; i < UncoveringMoves.Count; i++)
            {
                // Make sure the move doesn't interfere.
                Move move = UncoveringMoves[i];
                if (move.From == from || move.To == from)
                {
                    continue;
                }

                // Only need to try an uncovered card once.
                if (Used.Contains(move.From))
                {
                    continue;
                }
                Used.Add(move.From);

                // The uncovered card has to match a root to be useful.
                Card uncoveredCard = FindTableau[move.From][move.FromRow - 1];
                bool matchesRoot   = false;
                for (int j = 1; j < Roots.Count; j++)
                {
                    if (uncoveredCard.IsTargetFor(fromPile[Roots[j]]))
                    {
                        matchesRoot = true;
                        break;
                    }
                }
                if (!matchesRoot)
                {
                    continue;
                }

                // Try again to find a composite single pile move.
                move.ToRow = -1;
                CheckOne(move);
            }
        }
        internal override void ExecuteInternal(CancellationToken cancellationToken)
        {
            if (!string.IsNullOrEmpty(opts.SelectedDirectories))
            {
                Roots.AddRange(opts.SelectedDirectories.Split('^'));
            }

            if (!Roots.Any())
            {
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    foreach (var driveInfo in DriveInfo.GetDrives())
                    {
                        if (driveInfo.IsReady && driveInfo.DriveType == DriveType.Fixed)
                        {
                            Roots.Add(driveInfo.Name);
                        }
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Roots.Add("/");
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    Roots.Add("/");
                }
            }

            foreach (var Root in Roots)
            {
                Log.Information("{0} root {1}", Strings.Get("Scanning"), Root);

                var directories = Directory.EnumerateDirectories(Root, "*", new System.IO.EnumerationOptions()
                {
                    ReturnSpecialDirectories = false,
                    IgnoreInaccessible       = true,
                    RecurseSubdirectories    = true
                });

                // Process files in the root
                TryIterateOnDirectory(Root);

                if (!opts.SingleThread == true)
                {
                    ParallelOptions po = new ParallelOptions()
                    {
                        CancellationToken = cancellationToken
                    };
                    Parallel.ForEach(directories, po, filePath =>
                    {
                        TryIterateOnDirectory(filePath);
                    });
                }
                else
                {
                    foreach (var filePath in directories)
                    {
                        if (cancellationToken.IsCancellationRequested)
                        {
                            break;
                        }
                        TryIterateOnDirectory(filePath);
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public void AddChild(long?parentId, long id, T data)
        {
            if (Data.ContainsKey(id))
            {
                return;
            }

            if (parentId != null && !Data.ContainsKey((long)parentId))
            {
                return;
            }

            var link = new NodeLink {
                Id = id, Parent = parentId
            };
            var depth = 0;

            if (parentId == null)
            {
                if (Roots.Any())
                {
                    Links[Roots[Roots.Count - 1]].Next = id;
                }

                Roots.Add(id);
            }
            else
            {
                var parentLink = Links[(long)parentId];



                if (parentLink.Child != null)
                {
                    link.Next = parentLink.Child;
                }
                else
                {
                    Leaves.Remove((long)parentId);
                }
                parentLink.Child = id;
                if (!(Data[parentLink.Id] is Node))
                {
                    depth = parentLink.Depth + 1;
                }
                else
                {
                    depth = parentLink.Depth;
                }
            }

            // Saves data

            Data.Add(id, data);

            // Saves link

            link.Depth = depth;
            Links.Add(id, link);

            // Registers as leaf

            Leaves.Add(id);
        }
Ejemplo n.º 23
0
 public void setRoot(Node n)
 {
     Roots.Add(n);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Adds an object to the end of the roots.
 /// </summary>
 /// <param name="item"></param>
 public void AddRoot(RootVolume item)
 {
     Roots.Add(item);
     item.VolumeId = $"{VolumePrefix}{Roots.Count}_";
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Adds an object to the end of the roots.
 /// </summary>
 /// <param name="item"></param>
 public void AddRoot(RootVolume item)
 {
     Roots.Add(item);
     item.VolumeId = VolumePrefix + Roots.Count + "_";
 }