Example #1
0
        private static Run CreateRun(
            IEnumerable <string> analysisTargets,
            OptionallyEmittedData dataToInsert,
            IEnumerable <string> invocationTokensToRedact,
            IEnumerable <string> invocationPropertiesToLog,
            string defaultFileEncoding = null)
        {
            var run = new Run
            {
                Invocations         = new List <Invocation>(),
                DefaultFileEncoding = defaultFileEncoding
            };

            if (analysisTargets != null)
            {
                run.Files = new Dictionary <string, FileData>();

                foreach (string target in analysisTargets)
                {
                    string fileDataKey = UriHelper.MakeValidUri(target);

                    var fileData = FileData.Create(
                        new Uri(target, UriKind.RelativeOrAbsolute),
                        dataToInsert);

                    run.Files[fileDataKey] = fileData;
                }
            }

            var invocation = Invocation.Create(dataToInsert.Includes(OptionallyEmittedData.EnvironmentVariables), invocationPropertiesToLog);

            // TODO we should actually redact across the complete log file context
            // by a dedicated rewriting visitor or some other approach.

            if (invocationTokensToRedact != null)
            {
                invocation.CommandLine = Redact(invocation.CommandLine, invocationTokensToRedact);
                invocation.Machine     = Redact(invocation.Machine, invocationTokensToRedact);
                invocation.Account     = Redact(invocation.Account, invocationTokensToRedact);

                if (invocation.WorkingDirectory != null)
                {
                    invocation.WorkingDirectory.Uri = Redact(invocation.WorkingDirectory.Uri, invocationTokensToRedact);
                }

                if (invocation.EnvironmentVariables != null)
                {
                    string[] keys = invocation.EnvironmentVariables.Keys.ToArray();

                    foreach (string key in keys)
                    {
                        string value = invocation.EnvironmentVariables[key];
                        invocation.EnvironmentVariables[key] = Redact(value, invocationTokensToRedact);
                    }
                }
            }

            run.Invocations.Add(invocation);
            return(run);
        }
        public void ManipulationEnded(OpenGLSceneView view)
        {
            Trace.WriteLine("manipulationEnded");
            manipulationFinished = true;

            if (Manipulated == itemsController)
            {
                undo.PrepareUndo("Manipulations",
                                 Invocation.Create(oldManipulations,
                                                   items.CurrentManipulations, SwapManipulations));

                oldManipulations = null;
            }
            else if (Manipulated == meshController)
            {
                undo.PrepareUndo("Mesh Manipulation",
                                 Invocation.Create(oldMeshManipulation,
                                                   items.CurrentMeshManipulation, SwapMeshManipulation));

                oldMeshManipulation = null;
            }

            propertyGrid.Refresh();

            OnEachViewDo(v => { if (v != view)
                                {
                                    v.Invalidate();
                                }
                         });
        }
        private void RemoveItem(MeshType type, uint steps)
        {
            itemsController.ChangeSelection(0);
            items.RemoveAt((int)items.Count - 1);
            OnEachViewDo(view => view.Invalidate());

            // simple test for undo/redo
            undo.PrepareUndo(string.Format("Add {0}", type.ToDisplayString()),
                             Invocation.Create(type, steps, AddItem));
        }
        void FullMeshAction(string actionName, Action action)
        {
            MeshFullState oldState = items.CurrentMeshFull;

            action();

            MeshFullState currentState = items.CurrentMeshFull;

            undo.PrepareUndo(actionName,
                             Invocation.Create(oldState, currentState, actionName, SwapMeshFullState));
        }
        void UndoDeleteSelected(List <IndexedItem> selectedItems)
        {
            Trace.WriteLine("undoDeleteSelected:");
            Manipulated        = itemsController;
            items.CurrentItems = selectedItems;

            undo.PrepareUndo("Delete",
                             Invocation.Create(selectedItems, RedoDeleteSelected));

            itemsController.UpdateSelection();
            OnEachViewDo(view => view.Invalidate());
        }
        void SwapMeshFullState(MeshFullState old, MeshFullState current, string actionName)
        {
            Trace.WriteLine("swapMeshFullStateWithOld:current:actionName:");

            items.CurrentMeshFull = old;

            undo.PrepareUndo(actionName,
                             Invocation.Create(current, old, actionName, SwapMeshFullState));

            itemsController.UpdateSelection();
            meshController.UpdateSelection();
            Manipulated = meshController;
        }
        void SwapManipulations(List <ItemManipulationState> old,
                               List <ItemManipulationState> current)
        {
            Trace.WriteLine("swapManipulationsWithOld:current:");
            Trace.Assert(old.Count == current.Count, "old.Count == current.Count");
            items.CurrentManipulations = old;

            undo.PrepareUndo("Manipulations",
                             Invocation.Create(current, old, SwapManipulations));

            itemsController.UpdateSelection();
            Manipulated = itemsController;
        }
        void UndoCloneSelected(List <uint> selection)
        {
            Trace.WriteLine("undoCloneSelected:");

            Manipulated = itemsController;
            items.RemoveRange((int)items.Count - selection.Count, selection.Count);
            items.CurrentSelection = selection;

            undo.PrepareUndo("Clone",
                             Invocation.Create(selection, RedoCloneSelected));

            itemsController.UpdateSelection();
            OnEachViewDo(view => view.Invalidate());
        }
        void SwapAllItems(List <Item> old, List <Item> current, string actionName)
        {
            Trace.WriteLine("swapAllItemsWithOld:current:actionName:");

            Trace.WriteLine(string.Format("items count before set = {0}", items.Count));
            items.AllItems = old;
            Trace.WriteLine(string.Format("items count after set = {0}", items.Count));

            undo.PrepareUndo(actionName,
                             Invocation.Create(current, old, actionName, SwapAllItems));

            itemsController.UpdateSelection();
            Manipulated = itemsController;
        }
        void SwapMeshManipulation(MeshManipulationState old,
                                  MeshManipulationState current)
        {
            Trace.WriteLine("swapMeshManipulationWithOld:current:");

            items.CurrentMeshManipulation = old;

            undo.PrepareUndo("Mesh Manipulation",
                             Invocation.Create(current, old, SwapMeshManipulation));

            itemsController.UpdateSelection();
            meshController.UpdateSelection();
            Manipulated = meshController;
        }
        void RedoDeleteSelected(List <IndexedItem> selectedItems)
        {
            Trace.WriteLine("redoDeleteSelected:");

            Manipulated = itemsController;
            items.SetSelectionFromIndexedItems(selectedItems);
            Manipulated.RemoveSelected();

            undo.PrepareUndo("Delete",
                             Invocation.Create(selectedItems, UndoDeleteSelected));

            itemsController.UpdateSelection();
            OnEachViewDo(view => view.Invalidate());
        }
        void RedoCloneSelected(List <uint> selection)
        {
            Trace.WriteLine("redoCloneSelected:");

            Manipulated            = itemsController;
            items.CurrentSelection = selection;
            Manipulated.CloneSelected();

            undo.PrepareUndo("Clone",
                             Invocation.Create(selection, UndoCloneSelected));

            itemsController.UpdateSelection();
            OnEachViewDo(view => view.Invalidate());
        }
        private void AddItem(MeshType type, uint steps)
        {
            Item item = new Item();

            item.GetMesh().MakeMesh(type, steps);

            itemsController.ChangeSelection(0);
            item.Selected = 1;
            items.AddItem(item);
            itemsController.UpdateSelection();
            OnEachViewDo(view => view.Invalidate());

            undo.PrepareUndo(string.Format("Add {0}", type.ToDisplayString()),
                             Invocation.Create(type, steps, RemoveItem));
        }
        void AllItemsAction(string actionName, Action action)
        {
            var oldItems = items.AllItems;

            Trace.WriteLine(string.Format("oldItems count = {0}", oldItems.Count));

            action();

            var currentItems = items.AllItems;

            Trace.WriteLine(string.Format("currentItems count = {0}", currentItems.Count));

            undo.PrepareUndo(actionName,
                             Invocation.Create(oldItems, currentItems, actionName, SwapAllItems));
        }
Example #15
0
        private static Run CreateRun(
            IEnumerable <string> analysisTargets,
            LoggingOptions loggingOptions,
            IEnumerable <string> invocationTokensToRedact,
            IEnumerable <string> invocationPropertiesToLog)
        {
            var run = new Run();

            if (analysisTargets != null)
            {
                run.Files = new Dictionary <string, FileData>();

                foreach (string target in analysisTargets)
                {
                    string fileDataKey = UriHelper.MakeValidUri(target);

                    var fileData = FileData.Create(
                        new Uri(target, UriKind.RelativeOrAbsolute),
                        loggingOptions);

                    run.Files.Add(fileDataKey, fileData);
                }
            }

            run.Invocation = Invocation.Create(loggingOptions.Includes(LoggingOptions.PersistEnvironment), invocationPropertiesToLog);

            // TODO we should actually redact across the complete log file context
            // by a dedicated rewriting visitor or some other approach.
            if (invocationTokensToRedact != null)
            {
                run.Invocation.CommandLine      = Redact(run.Invocation.CommandLine, invocationTokensToRedact);
                run.Invocation.Machine          = Redact(run.Invocation.Machine, invocationTokensToRedact);
                run.Invocation.Account          = Redact(run.Invocation.Account, invocationTokensToRedact);
                run.Invocation.WorkingDirectory = Redact(run.Invocation.WorkingDirectory, invocationTokensToRedact);

                if (run.Invocation.EnvironmentVariables != null)
                {
                    string[] keys = run.Invocation.EnvironmentVariables.Keys.ToArray();

                    foreach (string key in keys)
                    {
                        string value = run.Invocation.EnvironmentVariables[key];
                        run.Invocation.EnvironmentVariables[key] = Redact(value, invocationTokensToRedact);
                    }
                }
            }
            return(run);
        }
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Trace.WriteLine("deleteSelected:");
            if (Manipulated.SelectedCount <= 0)
            {
                return;
            }

            if (Manipulated == itemsController)
            {
                var currentItems = items.CurrentItems;
                undo.PrepareUndo("Delete",
                                 Invocation.Create(currentItems, UndoDeleteSelected));

                Manipulated.RemoveSelected();
            }
            else
            {
                FullMeshAction("Delete", () => Manipulated.RemoveSelected());
            }

            OnEachViewDo(view => view.Invalidate());
        }
        private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Trace.WriteLine("cloneSelected:");
            if (Manipulated.SelectedCount <= 0)
            {
                return;
            }

            bool startManipulation = false;

            if (!manipulationFinished)
            {
                startManipulation = true;
                ManipulationEnded(null);
            }

            if (Manipulated == itemsController)
            {
                var selection = items.CurrentSelection;
                undo.PrepareUndo("Clone",
                                 Invocation.Create(selection, UndoCloneSelected));

                Manipulated.CloneSelected();
            }
            else
            {
                FullMeshAction("Clone", () => Manipulated.CloneSelected());
            }

            OnEachViewDo(view => view.Invalidate());

            if (startManipulation)
            {
                ManipulationStarted(null);
            }
        }
Example #18
0
        private void EnhanceRun(
            IEnumerable <string> analysisTargets,
            OptionallyEmittedData dataToInsert,
            OptionallyEmittedData dataToRemove,
            IEnumerable <string> invocationTokensToRedact,
            IEnumerable <string> invocationPropertiesToLog,
            string defaultFileEncoding = null,
            IDictionary <string, HashData> filePathToHashDataMap = null)
        {
            _run.Invocations ??= new List <Invocation>();
            if (defaultFileEncoding != null)
            {
                _run.DefaultEncoding = defaultFileEncoding;
            }

            Encoding encoding = SarifUtilities.GetEncodingFromName(_run.DefaultEncoding);

            if (analysisTargets != null)
            {
                _run.Artifacts ??= new List <Artifact>();

                foreach (string target in analysisTargets)
                {
                    Uri uri = new Uri(UriHelper.MakeValidUri(target), UriKind.RelativeOrAbsolute);

                    HashData hashData = null;
                    if (dataToInsert.HasFlag(OptionallyEmittedData.Hashes))
                    {
                        filePathToHashDataMap?.TryGetValue(target, out hashData);
                    }

                    var artifact = Artifact.Create(
                        new Uri(target, UriKind.RelativeOrAbsolute),
                        dataToInsert,
                        encoding,
                        hashData: hashData);

                    var fileLocation = new ArtifactLocation
                    {
                        Uri = uri
                    };

                    artifact.Location = fileLocation;

                    // This call will insert the file object into run.Files if not already present
                    artifact.Location.Index = _run.GetFileIndex(
                        artifact.Location,
                        addToFilesTableIfNotPresent: true,
                        dataToInsert: dataToInsert,
                        encoding: encoding,
                        hashData: hashData);
                }
            }

            var invocation = Invocation.Create(
                emitMachineEnvironment: dataToInsert.HasFlag(OptionallyEmittedData.EnvironmentVariables),
                emitTimestamps: !dataToRemove.HasFlag(OptionallyEmittedData.NondeterministicProperties),
                invocationPropertiesToLog);

            // TODO we should actually redact across the complete log file context
            // by a dedicated rewriting visitor or some other approach.

            if (invocationTokensToRedact != null)
            {
                invocation.CommandLine = Redact(invocation.CommandLine, invocationTokensToRedact);
                invocation.Machine     = Redact(invocation.Machine, invocationTokensToRedact);
                invocation.Account     = Redact(invocation.Account, invocationTokensToRedact);

                if (invocation.WorkingDirectory != null)
                {
                    invocation.WorkingDirectory.Uri = Redact(invocation.WorkingDirectory.Uri, invocationTokensToRedact);
                }

                if (invocation.EnvironmentVariables != null)
                {
                    string[] keys = invocation.EnvironmentVariables.Keys.ToArray();

                    foreach (string key in keys)
                    {
                        string value = invocation.EnvironmentVariables[key];
                        invocation.EnvironmentVariables[key] = Redact(value, invocationTokensToRedact);
                    }
                }
            }

            _run.Invocations.Add(invocation);
        }
Example #19
0
 public void AnalysisStarted()
 {
     _issueLogJsonWriter.OpenResults();
     _run.Invocation = Invocation.Create();
 }
Example #20
0
        private static Run CreateRun(
            IEnumerable <string> analysisTargets,
            OptionallyEmittedData dataToInsert,
            IEnumerable <string> invocationTokensToRedact,
            IEnumerable <string> invocationPropertiesToLog,
            string defaultFileEncoding = null)
        {
            var run = new Run
            {
                Invocations     = new List <Invocation>(),
                DefaultEncoding = defaultFileEncoding
            };

            if (analysisTargets != null)
            {
                run.Artifacts = new List <Artifact>();

                foreach (string target in analysisTargets)
                {
                    Uri uri = new Uri(UriHelper.MakeValidUri(target), UriKind.RelativeOrAbsolute);

                    var fileData = Artifact.Create(
                        new Uri(target, UriKind.RelativeOrAbsolute),
                        dataToInsert);

                    var fileLocation = new ArtifactLocation
                    {
                        Uri = uri
                    };

                    fileData.Location = fileLocation;

                    // This call will insert the file object into run.Files if not already present
                    fileData.Location.Index = run.GetFileIndex(fileData.Location, addToFilesTableIfNotPresent: true, dataToInsert);
                }
            }

            var invocation = Invocation.Create(dataToInsert.HasFlag(OptionallyEmittedData.EnvironmentVariables), invocationPropertiesToLog);

            // TODO we should actually redact across the complete log file context
            // by a dedicated rewriting visitor or some other approach.

            if (invocationTokensToRedact != null)
            {
                invocation.CommandLine = Redact(invocation.CommandLine, invocationTokensToRedact);
                invocation.Machine     = Redact(invocation.Machine, invocationTokensToRedact);
                invocation.Account     = Redact(invocation.Account, invocationTokensToRedact);

                if (invocation.WorkingDirectory != null)
                {
                    invocation.WorkingDirectory.Uri = Redact(invocation.WorkingDirectory.Uri, invocationTokensToRedact);
                }

                if (invocation.EnvironmentVariables != null)
                {
                    string[] keys = invocation.EnvironmentVariables.Keys.ToArray();

                    foreach (string key in keys)
                    {
                        string value = invocation.EnvironmentVariables[key];
                        invocation.EnvironmentVariables[key] = Redact(value, invocationTokensToRedact);
                    }
                }
            }

            run.Invocations.Add(invocation);
            return(run);
        }
Example #21
0
        private static Run CreateRun(
            IEnumerable <string> analysisTargets,
            bool computeTargetsHash,
            bool logEnvironment,
            IEnumerable <string> invocationTokensToRedact)
        {
            var run = new Run();

            if (analysisTargets != null)
            {
                run.Files = new Dictionary <string, IList <FileData> >();

                foreach (string target in analysisTargets)
                {
                    var fileReference = new FileData();

                    if (computeTargetsHash)
                    {
                        string md5, sha1, sha256;

                        HashUtilities.ComputeHashes(target, out md5, out sha1, out sha256);
                        fileReference.Hashes = new HashSet <Hash>
                        {
                            new Hash()
                            {
                                Value     = md5,
                                Algorithm = AlgorithmKind.MD5,
                            },
                            new Hash()
                            {
                                Value     = sha1,
                                Algorithm = AlgorithmKind.Sha1,
                            },
                            new Hash()
                            {
                                Value     = sha256,
                                Algorithm = AlgorithmKind.Sha256,
                            },
                        };
                    }
                    run.Files.Add(new Uri(target).ToString(), new List <FileData> {
                        fileReference
                    });
                }
            }


            run.Invocation = Invocation.Create(logEnvironment);

            // TODO we should actually redact across the complete log file context
            // by a dedicated rewriting visitor or some other approach.
            if (invocationTokensToRedact != null)
            {
                run.Invocation.Parameters       = Redact(run.Invocation.Parameters, invocationTokensToRedact);
                run.Invocation.Machine          = Redact(run.Invocation.Machine, invocationTokensToRedact);
                run.Invocation.Account          = Redact(run.Invocation.Account, invocationTokensToRedact);
                run.Invocation.Parameters       = Redact(run.Invocation.Parameters, invocationTokensToRedact);
                run.Invocation.WorkingDirectory = Redact(run.Invocation.WorkingDirectory, invocationTokensToRedact);

                if (run.Invocation.EnvironmentVariables != null)
                {
                    string[] keys = run.Invocation.EnvironmentVariables.Keys.ToArray();

                    foreach (string key in keys)
                    {
                        string value = run.Invocation.EnvironmentVariables[key];
                        run.Invocation.EnvironmentVariables[key] = Redact(value, invocationTokensToRedact);
                    }
                }
            }
            return(run);
        }