コード例 #1
0
ファイル: Program.cs プロジェクト: Gjoll/Eir.AutoMate
        void Start(WatchNode node)
        {
            foreach (String watchPath in node.Watch.watchPaths)
            {
                try
                {
                    FileSystemWatcher watcher = new FileSystemWatcher();
                    node.Watchers.Add(watcher);
                    watcher.Path = watchPath;
                    // Watch for changes in LastAccess and LastWrite times, and
                    // the renaming of files or directories.
                    watcher.NotifyFilter = NotifyFilters.LastAccess
                                           | NotifyFilters.LastWrite
                                           | NotifyFilters.FileName
                                           | NotifyFilters.DirectoryName;

                    watcher.Filter = node.Watch.filter;
                    // Add event handlers.
                    watcher.Changed += (sender, args) => NotifyChange(node, watcher);
                    watcher.Created += (sender, args) => NotifyChange(node, watcher);
                    watcher.Deleted += (sender, args) => NotifyChange(node, watcher);
                    watcher.Renamed += (sender, args) => NotifyChange(node, watcher);
                    watcher.IncludeSubdirectories = true;

                    // Begin watching.
                    watcher.EnableRaisingEvents = true;
                }
                catch (Exception err)
                {
                    Message(colorError, -1, $"Error creating watcher on path '{watchPath}'");
                }
            }
        }
コード例 #2
0
            public void ProcessNode(object value, WatchNode node)
            {
                var element = value as Element;
                var id      = element.Id;

                node.Clicked += () => dynRevitSettings.Doc.ShowElements(element);

                node.Link = id.IntegerValue.ToString(CultureInfo.InvariantCulture);
            }
コード例 #3
0
            public void ProcessNode(object value, WatchNode node)
            {
                var element = value as Element;
                var id      = element.Id;

                node.Clicked += delegate
                {
                    dynRevitSettings.Doc.ShowElements(element);
                };

                node.Link = id.ToString();
            }
コード例 #4
0
ファイル: Program.cs プロジェクト: Gjoll/Eir.AutoMate
        void ExecuteCommand(WatchNode node)
        {
            Int32 executionNum = executionCounter++;

            using (Mutex gMtx = new Mutex(false, "AutoMate"))
            {
                DateTime dt = DateTime.Now;
                gMtx.WaitOne(60 * 1000);
                TimeSpan ts = DateTime.Now - dt;
                Trace($"{node.Watch.name}: Waited {ts.TotalSeconds} seconds for access");

                foreach (Options.Command command in node.Watch.commands)
                {
                    Message(ConsoleColor.Green,
                            executionNum,
                            $"{node.Watch.name}: Executing {command.cmdPath} {command.cmdArgs}");
                    this.Execute(executionNum, command.workingDir, command.cmdPath, command.cmdArgs);
                }

                gMtx.ReleaseMutex();
            }
        }
コード例 #5
0
            public void ProcessNode(object value, WatchNode node)
            {
                var element = value as Element;
                var id = element.Id;

                node.Clicked += () => dynRevitSettings.Doc.ShowElements(element);

                node.Link = id.IntegerValue.ToString(CultureInfo.InvariantCulture);
            }
コード例 #6
0
            public void ProcessNode(object value, WatchNode node)
            {
                var element = value as Element;
                var id = element.Id;

                node.Clicked += delegate
                {
                    dynRevitSettings.Doc.ShowElements(element);
                };

                node.Link = id.ToString();
            }
コード例 #7
0
ファイル: dynWatch.cs プロジェクト: hippo811028/Dynamo
        WatchNode Process(Value eIn, ref string content, string prefix, int count)
        {
            content += prefix + string.Format("[{0}]:", count.ToString());

            WatchNode node = null;

            if (eIn.IsContainer)
            {
                if ((eIn as Value.Container).Item != null)
                {
                    //TODO: make clickable hyperlinks to show the element in Revit
                    //http://stackoverflow.com/questions/7890159/programmatically-make-textblock-with-hyperlink-in-between-text

                    content += (eIn as Value.Container).Item.ToString();

                    node = new WatchNode((eIn as Value.Container).Item.ToString());

                    handlerManager.ProcessNode((eIn as Value.Container).Item, node);

                    //node.Link = id;
                }
            }
            else if (eIn.IsFunction)
            {
                content += eIn.ToString() + "\n";
                node = new WatchNode(eIn.ToString());
            }
            else if (eIn.IsList)
            {
                content += eIn.GetType().ToString() + "\n";

                string newPrefix = prefix + "\t";
                int innerCount = 0;

                node = new WatchNode(eIn.GetType().ToString());

                foreach(Value eIn2 in (eIn as Value.List).Item)
                {
                    node.Children.Add(Process(eIn2, ref content, newPrefix, innerCount));
                    innerCount++;
                }
            }
            else if (eIn.IsNumber)
            {
                content += (eIn as Value.Number).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.Number).Item.ToString());
            }
            else if (eIn.IsString)
            {
                content += (eIn as Value.String).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.String).Item.ToString());
            }
            else if (eIn.IsSymbol)
            {
                content += (eIn as Value.Symbol).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.Symbol).Item.ToString());
            }

            return node;
        }
コード例 #8
0
ファイル: dynWatch.cs プロジェクト: kscalvin/Dynamo
        WatchNode Process(Value eIn, string prefix, int count, bool isListMember = false)
        {
            //content += prefix + string.Format("[{0}]:", count.ToString());

            WatchNode node = null;

            if (eIn == null || eIn.IsDummy)
            {
                node = new WatchNode("null");
                return node;
            }

            if (eIn.IsContainer)
            {
                if ((eIn as Value.Container).Item != null)
                {
                    //content += (eIn as Value.Container).Item.ToString();

                    node = new WatchNode((eIn as Value.Container).Item.ToString(), isListMember, count);

                    handlerManager.ProcessNode((eIn as Value.Container).Item, node);

                    //node.Link = id;
                }
            }
            else if (eIn.IsFunction)
            {
                //content += eIn.ToString() + "\n";
                node = new WatchNode("<function>", isListMember, count);
            }
            else if (eIn.IsList)
            {
                //content += "List\n";

                string newPrefix = prefix + "\t";

                var list = (eIn as Value.List).Item;

                node = new WatchNode(list.IsEmpty ? "Empty List" : "List", isListMember, count);

                foreach (var e in list.Select((x, i) => new { Element = x, Index = i }))
                {
                    node.Children.Add( Process(e.Element, newPrefix, e.Index, true) );
                }
            }
            else if (eIn.IsNumber)
            {
                //content += (eIn as Value.Number).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.Number).Item.ToString(), isListMember, count);
            }
            else if (eIn.IsString)
            {
                //content += (eIn as Value.String).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.String).Item.ToString(), isListMember, count);
            }
            else if (eIn.IsSymbol)
            {
                //content += (eIn as Value.Symbol).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.Symbol).Item.ToString(), isListMember, count);
            }

            return node;
        }
コード例 #9
0
            public override System.Collections.IEnumerable GetChildren(TreePath treePath)
            {
                if (this._buffer != null)
                {
                    foreach (UnlockListAction.Watch watch in _buffer)
                    {
                        WatchNode node = new WatchNode(watch.VarName, watch.VarValue);
                        node.Id = watch.Index;
                        node.ParentId = watch.ParentIndex;

                        this._watches[watch.Index] = node;

                        WatchNode parent = null;
                        _watches.TryGetValue(watch.ParentIndex, out parent);

                        if (parent != null)
                        {
                            parent.Nodes.Add(node);
                        }
                        else
                        {
                            this._model.Nodes.Add(node);
                        }
                    }

                    this._buffer = null;

                    this._model.NodesChanged += new EventHandler<TreeModelEventArgs>(TreeNodesChanged);
                    this._model.NodesInserted += new EventHandler<TreeModelEventArgs>(TreeNodesInserted);
                    this._model.NodesRemoved += new EventHandler<TreeModelEventArgs>(TreeNodesRemoved);
                    this._model.StructureChanged += new EventHandler<TreePathEventArgs>(TreeStructureChanged);
                }

                if (treePath.FullPath.Length <= 0)
                {
                    foreach (Node child in _model.Nodes)
                    {
                        yield return child;
                    }
                }
                else
                {
                    Node node = treePath.LastNode as Node;

                    if (node != null)
                    {
                        foreach (Node child in node.Nodes)
                        {
                            yield return child;
                        }
                    }
                }
            }
コード例 #10
0
            private void ProcessThing(WatchNode root, XYZ pt, WatchNode node)
            {
                var um = dynSettings.Controller.UnitsManager;

                if (!root.ShowRawData)
                {
                    ///xyzs will be in feet, but we need to show them
                    ///in the display units of choice

                    var xyzStr = string.Format("{0:f3}, {1:f3}, {2:f3}",
                        new Units.Length(pt.X/SIUnit.ToFoot, um),
                        new Units.Length(pt.Y/SIUnit.ToFoot, um),
                        new Units.Length(pt.Z/SIUnit.ToFoot, um));

                    node.NodeLabel = "{" + xyzStr + "}";
                }
                else
                {
                    node.NodeLabel = pt.ToString();
                }
            }
コード例 #11
0
ファイル: dynWatch.cs プロジェクト: epeter61/Dynamo
        WatchNode Process(Value eIn, ref string content, string prefix, int count)
        {
            content += prefix + string.Format("[{0}]:", count.ToString());

            WatchNode node = null;

            if (eIn.IsContainer)
            {
                if ((eIn as Value.Container).Item != null)
                {
                    //TODO: make clickable hyperlinks to show the element in Revit
                    //http://stackoverflow.com/questions/7890159/programmatically-make-textblock-with-hyperlink-in-between-text

                    content += (eIn as Value.Container).Item.ToString();

                    node = new WatchNode((eIn as Value.Container).Item.ToString());

                    handlerManager.ProcessNode((eIn as Value.Container).Item, node);

                    //node.Link = id;
                }
            }
            else if (eIn.IsFunction)
            {
                content += eIn.ToString() + "\n";
                node = new WatchNode("<function>");
            }
            else if (eIn.IsList)
            {
                content += "List\n";

                string newPrefix = prefix + "\t";

                var list = (eIn as Value.List).Item;

                node = new WatchNode(list.IsEmpty ? "Empty List" : "List");

                foreach (var e in list.Select((x, i) => new { Element = x, Index = i }))
                {
                    node.Children.Add(Process(e.Element, ref content, newPrefix, e.Index));
                }
            }
            else if (eIn.IsNumber)
            {
                content += (eIn as Value.Number).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.Number).Item.ToString());
            }
            else if (eIn.IsString)
            {
                content += (eIn as Value.String).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.String).Item.ToString());
            }
            else if (eIn.IsSymbol)
            {
                content += (eIn as Value.Symbol).Item.ToString() + "\n";
                node = new WatchNode((eIn as Value.Symbol).Item.ToString());
            }

            return node;
        }
コード例 #12
0
 public void ProcessNode(WatchNode root, object value, WatchNode node)
 {
     try
     {
         ProcessThing(root, value as dynamic, node);
     }
     catch(Exception ex)
     {
         node.NodeLabel = value.ToString();
     }
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: Gjoll/Eir.AutoMate
 void NotifyChange(WatchNode node, FileSystemWatcher watcher)
 {
     this.Trace($"{node.Watch.name} '{watcher.Path}' changed.");
     node.RunFlag = true;
     this.wake.Set();
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: Gjoll/Eir.AutoMate
        void Run()
        {
            foreach (Options.Watch watch in this.options.watchs)
            {
                if (String.IsNullOrEmpty(watch.name))
                {
                    throw new Exception("Watch field 'name' must be set");
                }
                if (watch.watchPaths.Length == 0)
                {
                    throw new Exception($"Watch '{watch.name}' field 'watchPaths' is not set");
                }
                if ((watch.commands == null) || (watch.commands.Length == 0))
                {
                    throw new Exception($"Watch '{watch.name}' field no commands defined");
                }
                foreach (Options.Command command in watch.commands)
                {
                    if (String.IsNullOrEmpty(command.cmdPath))
                    {
                        throw new Exception($"Watch '{watch.name}' field 'cmdPath' is not set");
                    }
                }
                WatchNode node = new WatchNode(watch);
                this.watchNodes.Add(node);
                Start(node);
            }

            Task runTask = new Task(() => this.RunCommand());

            runTask.Start();

            void RunAll()
            {
                foreach (WatchNode node in this.watchNodes)
                {
                    node.RunFlag = true;
                }
                this.wake.Set();
            }

            void RunOne(Int32 selection)
            {
                if (selection == 0)
                {
                    RunAll();
                }
                else if ((selection > 0) && (selection <= this.watchNodes.Count))
                {
                    WatchNode node = this.watchNodes[selection - 1];
                    node.RunFlag = true;
                    this.wake.Set();
                }
            }

            foreach (WatchNode node in this.watchNodes)
            {
                node.LastPingTime = DateTime.Now;
            }

            RunAll();
            // Wait for the user to quit the program.
            while (true)
            {
                String s = Console.ReadLine().Trim().ToLower();
                switch (s)
                {
                case "q":
                    return;

                default:
                    Console.Clear();
                    if (Int32.TryParse(s, out Int32 selection))
                    {
                        RunOne(selection);
                    }
                    else
                    {
                        RunAll();
                    }
                    break;
                }
            }
        }
コード例 #15
0
ファイル: dynWatch.cs プロジェクト: parchjs/Dynamo
        WatchNode Process(WatchNode root, Value eIn, string prefix, int count, bool isListMember = false)
        {
            WatchNode node = null;

            if (eIn == null || eIn.IsDummy)
            {
                node = new WatchNode("null");
                return node;
            }

            if (eIn.IsContainer)
            {
                var value = (eIn as Value.Container).Item;
                if (value != null)
                {
                    node = new WatchNode(value.ToString(), isListMember, count);
                    handlerManager.ProcessNode(root, value, node);
                }
            }
            else if (eIn.IsFunction)
            {
                node = new WatchNode("<function>", isListMember, count);
            }
            else if (eIn.IsList)
            {
                string newPrefix = prefix + "\t";

                var list = (eIn as Value.List).Item;

                node = new WatchNode(list.IsEmpty ? "Empty List" : "List", isListMember, count);

                foreach (var e in list.Select((x, i) => new { Element = x, Index = i }))
                {
                    node.Children.Add( Process(root, e.Element, newPrefix, e.Index, true) );
                }
            }
            else if (eIn.IsNumber)
            {
                node = new WatchNode((eIn as Value.Number).Item.ToString(), isListMember, count);
            }
            else if (eIn.IsString)
            {
                node = new WatchNode((eIn as Value.String).Item, isListMember, count);
            }
            else if (eIn.IsSymbol)
            {
                node = new WatchNode((eIn as Value.Symbol).Item, isListMember, count);
            }

            // This is a fix for the following defect. "VirtualizingStackPanel"
            // does not quite work well with "WatchNode" being 'null' value.
            //
            //      https://github.com/ikeough/Dynamo/issues/832
            //
            return node ?? (new WatchNode("null"));
        }
コード例 #16
0
            private void ProcessThing(WatchNode root, Element element, WatchNode node)
            {
                var id = element.Id;

                node.Clicked += () => dynRevitSettings.Doc.ShowElements(element);
                node.Link = id.IntegerValue.ToString(CultureInfo.InvariantCulture);
                node.NodeLabel = element.Name;
            }
コード例 #17
0
ファイル: dynWatch.cs プロジェクト: parchjs/Dynamo
 public void ProcessNode(WatchNode root, object value, WatchNode node)
 {
     foreach (var handler in handlers)   //.Where(x => x.AcceptsValue(value)))
     {
         handler.ProcessNode(root, value, node);
     }
 }
コード例 #18
0
ファイル: dynWatch.cs プロジェクト: Dewb/Dynamo
        WatchNode Process(Expression eIn, ref string content, string prefix, int count)
        {
            content += prefix + string.Format("[{0}]:", count.ToString());

            WatchNode node = null;

            if (eIn.IsContainer)
            {
                if ((eIn as Expression.Container).Item != null)
                {
                    //TODO: make clickable hyperlinks to show the element in Revit
                    //http://stackoverflow.com/questions/7890159/programmatically-make-textblock-with-hyperlink-in-between-text

                    string id = "";
                    Element revitEl = (eIn as Expression.Container).Item as Autodesk.Revit.DB.Element;
                    if (revitEl != null)
                    {
                        id = revitEl.Id.ToString();
                    }

                    content += (eIn as Expression.Container).Item.ToString() + ":" + id + "\n";

                    node = new WatchNode((eIn as Expression.Container).Item.ToString());
                    node.Link = id;
                }
            }
            else if (eIn.IsFunction || eIn.IsSpecial)
            {
                content += eIn.ToString() + "\n";
                node = new WatchNode(eIn.ToString());
            }
            else if (eIn.IsList)
            {
                content += eIn.GetType().ToString() + "\n";

                string newPrefix = prefix + "\t";
                int innerCount = 0;

                node = new WatchNode(eIn.GetType().ToString());

                foreach(Expression eIn2 in (eIn as Expression.List).Item)
                {
                    node.Children.Add(Process(eIn2, ref content, newPrefix, innerCount));
                    innerCount++;
                }
            }
            else if (eIn.IsNumber)
            {
                content += (eIn as Expression.Number).Item.ToString() + "\n";
                node = new WatchNode((eIn as Expression.Number).Item.ToString());
            }
            else if (eIn.IsString)
            {
                content += (eIn as Expression.String).Item.ToString() + "\n";
                node = new WatchNode((eIn as Expression.String).Item.ToString());
            }
            else if (eIn.IsSymbol)
            {
                content += (eIn as Expression.Symbol).Item.ToString() + "\n";
                node = new WatchNode((eIn as Expression.Symbol).Item.ToString());
            }

            return node;
        }