Example #1
0
        protected override void OnWorldSelected(World world)
        {
            if (world == World)
            {
                return;
            }

            State?.Dispose();
            GroupingStrategy?.Dispose();
            m_EntityHierarchyDiffer?.Dispose();

            State                   = null;
            GroupingStrategy        = null;
            m_EntityHierarchyDiffer = null;

            World = world;
            if (World != null)
            {
                // TODO: How do we instantiate the correct State/Strategy combination?
                // TODO: Should we even allow the State to be overridable by users?
                State            = new EntityHierarchyState(world);
                GroupingStrategy = new EntityHierarchyDefaultGroupingStrategy(world, State);

                m_EntityHierarchyDiffer = new EntityHierarchyDiffer(this, DisableDifferCooldownPeriod ? 0 : 16);
                m_EntityHierarchy.Refresh(this);
            }
            else
            {
                m_EntityHierarchy.Clear();
            }
        }
Example #2
0
        void OnDisable()
        {
            LiveLinkConfigHelper.LiveLinkEnabledChanged -= UpdateEnableLiveLinkMessage;
            EditorApplication.playModeStateChanged      -= UpdateEnableLiveLinkMessage;
            m_EntityHierarchy.Dispose();

            State?.Dispose();
            GroupingStrategy?.Dispose();
            m_EntityHierarchyDiffer?.Dispose();
        }
Example #3
0
 /// <summary>
 /// Make a list of groups that should be shown according to the given parameters
 /// </summary>
 /// <param name="parms"></param>
 /// <returns></returns>
 protected override IList <OLVGroup> MakeGroups(GroupingParameters parms)
 {
     if (GroupingStrategy == null)
     {
         return(new List <OLVGroup>());
     }
     else
     {
         return(GroupingStrategy.GetGroups(parms));
     }
 }
 private Func <LogGrouping, MainLogSection> flatten(GroupingStrategy groupingStrategy, int dayInLog, int daysInThePast)
 {
     return(day =>
     {
         var items = groupingStrategy(day);
         var title = DateToTitleString.Convert(day.Key, timeService.CurrentDateTime);
         var duration = totalTrackedTime(items).ToFormattedString(durationFormat);
         return new MainLogSection(
             new DaySummaryViewModel(day.Key, title, duration),
             flattenGroups(items, dayInLog, daysInThePast)
             );
     });
 }
Example #5
0
        public ZoneGroups(DependencyZones zones, GroupingStrategy strategy, bool nonZonesOnly, double dependencyThreshold)
        {
            this.zones            = zones;
            this.DUPLICITY_FILTER = this.zones.DUPLICITY_FILTER;
            if (this.DUPLICITY_FILTER == DependencyZone.DuplicityFilter.MultiEgo)
            {
                this.DUPLICITY_FILTER = DependencyZone.DuplicityFilter.All;
            }

            this.AllGroups           = new List <ZoneGroup>();
            this.Strategy            = strategy;
            this.NonZonesOnly        = nonZonesOnly;
            this.DependencyThreshold = dependencyThreshold;

            this.calculateGroups();
            this.CompleteAndFilterDuplicities();
        }
Example #6
0
        /// <summary>
        /// Return the position of the given itemIndex in the list as it currently shown to the user.
        /// If the control is not grouped, the display order is the same as the
        /// sorted list order. But if the list is grouped, the display order is different.
        /// </summary>
        /// <param name="itemIndex"></param>
        /// <returns></returns>
        public virtual int GetItemIndexInDisplayOrder(int itemIndex)
        {
            if (!ShowGroups)
            {
                return(itemIndex);
            }

            int groupIndex   = GroupingStrategy.GetGroup(itemIndex);
            int displayIndex = 0;

            for (int i = 0; i < groupIndex - 1; i++)
            {
                displayIndex += OLVGroups[i].VirtualItemCount;
            }
            displayIndex += GroupingStrategy.GetIndexWithinGroup(OLVGroups[groupIndex], itemIndex);

            return(displayIndex);
        }
Example #7
0
        /// <summary>
        /// Return the ListViewItem that appears immediately before the given item.
        /// If the given item is null, the last item in the list will be returned.
        /// Return null if the given item is the first item.
        /// </summary>
        /// <param name="itemToFind">The item that is before the item that is returned</param>
        /// <returns>A ListViewItem</returns>
        public override OLVListItem GetPreviousItem(OLVListItem itemToFind)
        {
            if (!ShowGroups)
            {
                return(base.GetPreviousItem(itemToFind));
            }

            // Sanity
            if (OLVGroups == null || OLVGroups.Count == 0)
            {
                return(null);
            }

            // If the given items is null, return the last member of the last group
            if (itemToFind == null)
            {
                OLVGroup lastGroup = OLVGroups[OLVGroups.Count - 1];
                return(GetItem(GroupingStrategy.GetGroupMember(lastGroup, lastGroup.VirtualItemCount - 1)));
            }

            // Find where this item occurs (which group and where in that group)
            int groupIndex       = GroupingStrategy.GetGroup(itemToFind.Index);
            int indexWithinGroup = GroupingStrategy.GetIndexWithinGroup(OLVGroups[groupIndex], itemToFind.Index);

            // If it's not the first member of the group, just return the previous member
            if (indexWithinGroup > 0)
            {
                return(GetItem(GroupingStrategy.GetGroupMember(OLVGroups[groupIndex], indexWithinGroup - 1)));
            }

            // The item is the first member of its group. Return the last member of the previous group
            // (if there is one)
            if (groupIndex > 0)
            {
                OLVGroup previousGroup = OLVGroups[groupIndex - 1];
                return(GetItem(GroupingStrategy.GetGroupMember(previousGroup, previousGroup.VirtualItemCount - 1)));
            }

            return(null);
        }
Example #8
0
        /// <summary>
        /// Return the ListViewItem that appears immediately after the given item.
        /// If the given item is null, the first item in the list will be returned.
        /// Return null if the given item is the last item.
        /// </summary>
        /// <param name="itemToFind">The item that is before the item that is returned, or null</param>
        /// <returns>A OLVListItem</returns>
        public override OLVListItem GetNextItem(OLVListItem itemToFind)
        {
            if (!ShowGroups)
            {
                return(base.GetNextItem(itemToFind));
            }

            // Sanity
            if (OLVGroups == null || OLVGroups.Count == 0)
            {
                return(null);
            }

            // If the given item is null, return the first member of the first group
            if (itemToFind == null)
            {
                return(GetItem(GroupingStrategy.GetGroupMember(OLVGroups[0], 0)));
            }

            // Find where this item occurs (which group and where in that group)
            int groupIndex       = GroupingStrategy.GetGroup(itemToFind.Index);
            int indexWithinGroup = GroupingStrategy.GetIndexWithinGroup(OLVGroups[groupIndex], itemToFind.Index);

            // If it's not the last member, just return the next member
            if (indexWithinGroup < OLVGroups[groupIndex].VirtualItemCount - 1)
            {
                return(GetItem(GroupingStrategy.GetGroupMember(OLVGroups[groupIndex], indexWithinGroup + 1)));
            }

            // The item is the last member of its group. Return the first member of the next group
            // (unless there isn't a next group)
            if (groupIndex < OLVGroups.Count - 1)
            {
                return(GetItem(GroupingStrategy.GetGroupMember(OLVGroups[groupIndex + 1], 0)));
            }

            return(null);
        }
Example #9
0
 private static IEnumerable <IGrouping <string, KeyValuePair <string, OpenApiPathItem> > > GetPathGroups(OpenApiPaths paths, GroupingStrategy groupingStrategy)
 {
Example #10
0
        public static WorkItemFilingMetadata CreateWorkItemFilingMetadata(this SarifLog sarifLog, string workItemProjectName, string templateFilePath, GroupingStrategy groupingStrategy)
        {
            WorkItemFilingMetadata metadata = new WorkItemFilingMetadata()
            {
                Object     = sarifLog,
                Attachment = new WorkItemFiling.Attachment
                {
                    Name = "AttachedResults.sarif",
                    Text = JsonConvert.SerializeObject(sarifLog)
                }
            };

            ArtifactLocation artifactLocation = sarifLog.Runs[0].Artifacts[0].Location;

            string organization = artifactLocation.GetProperty("OrganizationName");
            string artifactId   = artifactLocation.GetProperty <int>("ArtifactId").ToString();
            string projectName  = artifactLocation.GetProperty("ProjectName");
            string artifactType = artifactLocation.GetProperty("ArtifactType");

            // BUG: GetProperty doesn't unencode string values
            string areaPath = $@"{workItemProjectName}" + artifactLocation.GetProperty("AreaPath").Replace(@"\\", @"\");

            string artifactName = artifactLocation.GetProperty("ArtifactName");

            List <string> customTags = new List <string>();

            if (artifactLocation.TryGetProperty("CustomTags", out string customTagsString))
            {
                metadata.CustomTags = customTagsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => t.Trim()).ToList();
            }

            Dictionary <string, string> customFields = new Dictionary <string, string>();

            if (artifactLocation.TryGetProperty("CustomFields", out string customFieldsString))
            {
                string[] fieldKvps = customFieldsString.Split(',');

                foreach (string fieldKvp in fieldKvps)
                {
                    string[] kv = fieldKvp.Split(new char[] { ':' }, 2);

                    if (kv.Length == 2)
                    {
                        customFields.Add(kv[0].Trim(), kv[1].Trim());
                    }
                }
            }

            metadata.CustomFields = customFields;

            Result result   = sarifLog.Runs[0].Results[0];
            string ruleName = string.Empty;

            if (groupingStrategy == GroupingStrategy.PerRunPerRule ||
                groupingStrategy == GroupingStrategy.PerRunPerTargetPerRule)
            {
                ruleName = result.ResolvedRuleId(sarifLog.Runs[0]).Split('/')[0];

                if (result.RuleIndex > -1)
                {
                    ruleName = sarifLog.Runs[0].Tool.Driver.Rules[result.RuleIndex].Name + ":" + ruleName;
                }
            }

            string titleEntity = GetArtifactTypeDisplayName(artifactType);

            metadata.Title = $"[{organization}/{projectName}] {ruleName}: Exposed credential(s) in {titleEntity}: '{artifactName}'";

            // TODO: This should come from the SARIF or command line arg in the future.
            metadata.Tags     = new List <string>(new string[] { "Security" });
            metadata.AreaPath = areaPath;

            metadata.Description = InjectArguments(
                File.ReadAllText(templateFilePath),
                organization,
                projectName,
                artifactId,
                artifactType,
                artifactName,
                ruleName,
                sarifLog.Runs[0]
                );

            return(metadata);
        }