Exemplo n.º 1
0
 /// <summary>Constructor of the class.</summary>
 /// <param name="node">The class node.</param>
 /// <param name="enableHierarchyView">The value if the hierarchy view is enabled.</param>
 /// <param name="autoExpand">The value if nodes should get expanded.</param>
 public ClassTreeNode(ClassNode node, ValueTypeWrapper <bool> enableHierarchyView, ValueTypeWrapper <bool> autoExpand)
     : this(node, enableHierarchyView, autoExpand, null)
 {
     Contract.Requires(node != null);
     Contract.Requires(enableHierarchyView != null);
     Contract.Requires(autoExpand != null);
 }
 public override void Visit(IInvocationExpression entity, ValueTypeWrapper <bool> context)
 {
     if (entity.MethodName.DeclaringType.Namespace.Identifier.StartsWithAny(
             _namespacePrefixes,
             StringComparison.OrdinalIgnoreCase))
     {
         context.Value = true;
     }
 }
Exemplo n.º 3
0
        public void Test_Value_Mapper()
        {
            var testObject = new FourByFour();

            testObject.Price = 250.25m;

            var wrapper = new ValueTypeWrapper <FourByFour>();

            Assert.AreEqual(250.25m, wrapper.GetValue(testObject));
        }
        public static DocumentType GuessDocumentType(IDocumentName docName, ISST context)
        {
            if (docName.Language != "CSharp")
            {
                return(DocumentType.Undefined);
            }

            var finder       = new NamespaceFinderVisitor(TestNamespaces);
            var testWasFound = new ValueTypeWrapper <bool>(false);

            finder.Visit(context, testWasFound);

            if (testWasFound)
            {
                return(DocumentType.Test);
            }

            finder = new NamespaceFinderVisitor(TestFrameworkNamespaces);
            var testFrameworkWasFound = new ValueTypeWrapper <bool>(false);

            finder.Visit(context, testFrameworkWasFound);

            if (testFrameworkWasFound)
            {
                return(DocumentType.TestFramework);
            }

            if (Path.GetFileNameWithoutExtension(docName.FileName).Contains("test", CompareOptions.IgnoreCase))
            {
                return(DocumentType.FilenameTest);
            }

            if (docName.FileName.Contains("test", CompareOptions.IgnoreCase))
            {
                return(DocumentType.PathnameTest);
            }

            return(DocumentType.Production);
        }
Exemplo n.º 5
0
            private ClassTreeNode(ClassNode node, ValueTypeWrapper <bool> enableHierarchyView, ValueTypeWrapper <bool> autoExpand, HashSet <ClassNode> seen)
            {
                Contract.Requires(node != null);
                Contract.Requires(enableHierarchyView != null);
                Contract.Requires(autoExpand != null);

                this.enableHierarchyView = enableHierarchyView;
                this.autoExpand          = autoExpand;

                ClassNode = node;

                node.NameChanged  += NameChanged_Handler;
                node.NodesChanged += NodesChanged_Handler;

                Text = node.Name;

                ImageIndex         = 1;
                SelectedImageIndex = 1;

                RebuildClassHierarchy(seen ?? new HashSet <ClassNode> {
                    ClassNode
                });
            }
Exemplo n.º 6
0
        public ClassNodeView()
        {
            Contract.Ensures(root != null);

            InitializeComponent();

            DoubleBuffered = true;

            enableHierarchyView = new ValueTypeWrapper <bool>(true);
            autoExpand          = new ValueTypeWrapper <bool>(false);

            classesTreeView.ImageList = new ImageList();
            classesTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Text_List_Bullets);
            classesTreeView.ImageList.Images.Add(Properties.Resources.B16x16_Class_Type);

            root = new TreeNode
            {
                Text               = "Classes",
                ImageIndex         = 0,
                SelectedImageIndex = 0
            };

            classesTreeView.Nodes.Add(root);
        }
        public Task StartRunTask()
        {
            var cancellationToken = cancellationTokenSource.Token;
            var processLaunched   = new ValueTypeWrapper <bool> {
                Value = false
            };
            var processExitedEventHappened = new ValueTypeWrapper <bool> {
                Value = false
            };
            var  pid          = new ValueTypeWrapper <int>();
            var  processName  = new ValueTypeWrapper <string>();
            bool IsfirstStart = true;

            Action hostProcess = () =>
            {
                #region hostProcess

                var process = this.CreateProcess();

                process.Exited += (s, a) => processExitedEventHappened.Value = true;

                info(string.Format("Try to launch {0}", process.StartInfo.FileName));

                if (!IsfirstStart && !AllowedToRestart())
                {
                    error("The process was not allowed to restart");
                    return;
                }

                process.Start();
                IsfirstStart = false;
                if (process.StartInfo.RedirectStandardOutput)
                {
                    process.BeginOutputReadLine();
                }
                if (process.StartInfo.RedirectStandardError)
                {
                    process.BeginErrorReadLine();
                }
                pid.Value             = process.Id;
                processLaunched.Value = true;
                processName.Value     = process.StartInfo.FileName;

                info(string.Format("Launched {0} (pid {1})", processName.Value, pid.Value));

                if (cancellationToken.WaitHandle.WaitOne()) // wait infinite
                {
                    warn(string.Format("Killing {0} now", processName.Value));
                    if (!process.HasExited)
                    {
                        process.Kill();
                    }
                }

                #endregion
            };

            var processTask = Task.Factory.StartNew(hostProcess, cancellationToken);

            while (!processLaunched.Value)
            {
                warn("Waiting a until the task is launched...");

                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            Action hostMonitor = () =>
            {
                int i = 0;
                while (true)
                {
                    #region Ensure task didn't crash accidentally, and if so, re-launch

                    bool processFoundInMemory = false;
                    try
                    {
                        var processFromSystem = Process.GetProcessById(pid.Value);
                        processFoundInMemory = true;
                    }
                    catch (ArgumentException) { }

                    bool unexpectedTermination = processExitedEventHappened.Value || !processFoundInMemory;

                    if (processTask.IsCompleted || unexpectedTermination)
                    {
                        if (_onStopRequested)
                        {
                            error(string.Format("Process {0} successfully shut down because of an OnStop() call", processName.Value));
                            return; // Leave the Run() method
                        }
                        else if (unexpectedTermination)
                        {
                            error(string.Format("Process {0} stopped working for unknown reasons... Restarting it", processName.Value));
                            processExitedEventHappened.Value = false;

                            processLaunched.Value = false;
                            processTask           = Task.Factory.StartNew(hostProcess, cancellationToken);
                            while (!processLaunched.Value)
                            {
                                Thread.Sleep(TimeSpan.FromSeconds(1));
                            }
                        }
                    }

                    #endregion

                    Thread.Sleep(TimeSpan.FromMilliseconds(500));

                    if ((i++) % 600 == 0)
                    {
                        info("Running");
                    }
                }
            };

            return(Task.Factory.StartNew(hostMonitor, cancellationToken));
        }