Пример #1
0
        private void WriteCodeToComponent(object sender, GH_SolutionEventArgs e)
        {
            if (!ShouldContinue())
            {
                return;
            }
            if (!(sender is GH_Document doc))
            {
                return;
            }

            doc.SolutionEnd -= WriteCodeToComponent;
            WriteScriptToComponent(TargetComponent, FileNameSafe);
            TargetComponent.ExpireSolution(true);
            IsBusy = false;
        }
Пример #2
0
        public void OnFileChanged(Object sender, FileSystemEventArgs e)
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            try
            {
                if (!ShouldContinue())
                {
                    Cleanup();
                    return;
                }

                // Visual studio will rename a file to a temp file,
                // Then write new contents to the original file
                // So here we check if a file that stopped existing, starts existing again..
                if (!File.Exists(FileNameSafe))
                {
                    Thread.Sleep(200);
                    if (!File.Exists(FileNameSafe))
                    {
                        Cleanup();
                        return;
                    }
                }

                // Modify the script at the end of the solution, rather than now
                // so we know for sure that nothing is in the middle of a
                // solution, and could botch up things.
                OnPingDocument().SolutionEnd += WriteCodeToComponent;

                OnPingDocument().ScheduleSolution(10, doc =>
                {
                    // expire the script in the next solution, so it will recompute.
                    TargetComponent.ExpireSolution(false);
                });
            }
            catch (Exception exp)
            {
                RhinoApp.WriteLine($"Error in filehandler:{exp.Message}\\n{exp.StackTrace}");
            }
        }