internal CallerChainImpl(AnyCredential anyCredential) : this() { Legacy = anyCredential.Legacy; if (Legacy) { core.v2_0.services.access_control.CallChain legacyChain = UnmarshalLegacyCallChain(anyCredential.LegacyChain); BusId = anyCredential.Bus; Target = legacyChain.target; Originators = new LoginInfo[legacyChain.originators.Length]; for (int i = 0; i < legacyChain.originators.Length; i++) { Originators[i] = new LoginInfo(legacyChain.originators[i].id, legacyChain.originators[i].entity); } Caller = new LoginInfo(legacyChain.caller.id, legacyChain.caller.entity); Signed = new AnySignedChain(anyCredential.LegacyChain); } else { CallChain chain = UnmarshalCallChain(anyCredential.Chain); BusId = chain.bus; Target = chain.target; Originators = chain.originators; Caller = chain.caller; Signed = new AnySignedChain(anyCredential.Chain); } }
public void Setup() { var info = new TestRunInformation(); info.Name = "TESTNAME"; var chain = new CallChain("TestRoot", "TestRootR", 1); chain.StartTime = 0; chain.EndTime = 10; var c = new CallChain("TestChild1", "TestChild1R", 2); c.StartTime = 1; c.EndTime = 2; chain.AddChild(c); var c2 = new CallChain("TestChild2", "TestChild2R", 3); c2.StartTime = 3; c2.EndTime = 9; chain.AddChild(c2); var child = new CallChain("TestChild3", "TestChild3R", 4); child.StartTime = 4; child.EndTime = 8; var grandchild = new CallChain("TestGrandChild", "TestGrandChildR", 5); grandchild.StartTime = 5; grandchild.EndTime = 7; child.AddChild(grandchild); chain.AddChild(child); info.TestChain = chain; projection = new CouplingCountAndNameProjection(); projection.Index(info); }
public CalledFunctionAnalysisUnit(IVersioned agg, FunctionAnalysisUnit originalUnit, CallChain callChain, ArgumentSet callArgs) : base(originalUnit.Function, originalUnit._declUnit) { _originalUnit = originalUnit; _agg = agg; CallChain = callChain; var scope = new FunctionScope( Function, Ast, originalUnit.Scope.OuterScope, originalUnit.DeclaringModule.ProjectEntry ); scope.UpdateParameters(this, callArgs, false, originalUnit.Scope as FunctionScope); _scope = scope; var walker = new OverviewWalker(_originalUnit.ProjectEntry, this, Tree); if (Ast.Body != null) { Ast.Body.Walk(walker); } AnalysisLog.NewUnit(this); Enqueue(); }
public CallerChain MakeChainFor(string entity) { ConnectionImpl conn = (ConnectionImpl)GetCurrentConnection(); if (conn == null) { Logger.Error("Não há conexão para executar a chamada MakeChainFor."); throw new NO_PERMISSION(NoLoginCode.ConstVal, CompletionStatus.Completed_No); } LoginInfo?myLogin = conn.Login; if (!myLogin.HasValue) { Logger.Error("Não há login para executar a chamada MakeChainFor."); throw new NO_PERMISSION(NoLoginCode.ConstVal, CompletionStatus.Completed_No); } try { AccessControl acs = conn.Acs; SignedData signedChain = acs.signChainFor(entity); CallChain callChain = CallerChainImpl.UnmarshalCallChain(signedChain); if (conn.Legacy) { SignedCallChain legacySigned = conn.LegacyConverter.signChainFor(entity); return(new CallerChainImpl(callChain.bus, callChain.caller, callChain.target, callChain.originators, signedChain, legacySigned)); } return(new CallerChainImpl(callChain.bus, callChain.caller, callChain.target, callChain.originators, signedChain)); } catch (GenericUserException e) { Logger.Error("Falha inesperada ao criar uma nova cadeia.", e); throw; } }
public void Setup() { var info = new TestRunInformation(); info.Name = "TESTNAME"; var chain = new CallChain("TestRoot", "TestRootR", 1); chain.StartTime = 0; chain.EndTime = 10; var c = new CallChain("TestChild1", "TestChild1R", 2); c.StartTime = 1; c.EndTime = 2; chain.AddChild(c); var c2 = new CallChain("TestChild2", "TestChild2R", 3); c2.StartTime = 3; c2.EndTime = 9; chain.AddChild(c2); var child = new CallChain("TestChild3", "TestChild3R", 4); child.StartTime = 4; child.EndTime = 8; var grandchild = new CallChain("TestGrandChild", "TestGrandChildR", 5); grandchild.StartTime = 5; grandchild.EndTime = 7; child.AddChild(grandchild); chain.AddChild(child); info.TestChain = chain; projection = new CouplingCountAndNameProjection(); projection.Index(info); }
public static CallChain BuildChainWithPrefix(string prefix) { var chain = new CallChain(prefix + "Root", prefix + "RootR", 1) { StartTime = 0, EndTime = 10 }; chain.AddChild(new CallChain(prefix + "Child1", prefix + "Child1R", 2) { StartTime = 1, EndTime = 2 }); chain.AddChild(new CallChain(prefix + "Child2", prefix + "Child2R", 3) { StartTime = 2, EndTime = 3 }); var child = new CallChain(prefix + "Child3", prefix + "Child3R", 4) { StartTime = 4, EndTime = 7 }; child.AddChild(new CallChain(prefix + "GrandChild", prefix + "GrandChildR", 5) { StartTime = 5, EndTime = 6 }); chain.AddChild(child); return(chain); }
public CallerChain DecodeChain(byte[] encoded) { try { VersionedData[] versions = DecodeExportedVersions(encoded, _magicTagCallChain); CallerChainImpl decodedChain = null; for (int i = 0; i < versions.Length; i++) { // Se houver duas versões, a versão atual virá antes da versão legacy. if (versions[i].version == ExportVersion.ConstVal) { TypeCode signedDataTypeCode = ORB.create_tc_for_type(typeof(SignedData)); SignedData exportedChain = (SignedData) _codec.decode_value(versions[i].encoded, signedDataTypeCode); CallChain chain = CallerChainImpl.UnmarshalCallChain(exportedChain); if (decodedChain == null) { decodedChain = new CallerChainImpl(chain.bus, chain.caller, chain.target, chain.originators, exportedChain); } else { decodedChain.Signed.Chain = exportedChain; } } if (versions[i].version == CurrentVersion.ConstVal) { TypeCode exportedChainTypeCode = ORB.create_tc_for_type(typeof(ExportedCallChain)); ExportedCallChain exportedChain = (ExportedCallChain) _codec.decode_value(versions[i].encoded, exportedChainTypeCode); core.v2_0.services.access_control.CallChain chain = CallerChainImpl.UnmarshalLegacyCallChain(exportedChain.signedChain); if (decodedChain == null) { decodedChain = new CallerChainImpl(exportedChain.bus, chain.caller, chain.target, chain.originators, exportedChain.signedChain); } else { decodedChain.Signed.LegacyChain = exportedChain.signedChain; } } } if (decodedChain != null) { return(decodedChain); } } catch (GenericUserException e) { const string message = "Falha inesperada ao decodificar uma cadeia exportada."; Logger.Error(message, e); throw new InvalidEncodedStreamException(message, e); } throw new InvalidEncodedStreamException("Versão de cadeia incompatível."); }
public CallerChain ImportChain(byte[] token, string domain) { ConnectionImpl conn = (ConnectionImpl)GetCurrentConnection(); if (conn == null) { throw new NO_PERMISSION(NoLoginCode.ConstVal, CompletionStatus.Completed_No); } AccessControl acs = conn.Acs; AsymmetricKeyParameter busKey = conn.BusKey; if (busKey == null) { throw new NO_PERMISSION(NoLoginCode.ConstVal, CompletionStatus.Completed_No); } byte[] encryptedToken = Crypto.Encrypt(busKey, token); SignedData signedChain = acs.signChainByToken(encryptedToken, domain); try { CallChain callChain = CallerChainImpl.UnmarshalCallChain(signedChain); return(new CallerChainImpl(callChain.bus, callChain.caller, callChain.target, callChain.originators, signedChain)); } catch (GenericUserException e) { const string message = "Falha inesperada ao importar uma nova cadeia."; Logger.Error(message, e); throw new OpenBusInternalException(message, e); } }
public void ProcessNewEntry(CallChain c) { _timesCalled++; var timeunder = c.EndTime - c.StartTime; _totalTimeUnder += timeunder; if (timeunder > _maxTimeUnder) { _maxTimeUnder = timeunder; } if (timeunder < _minTimeUnder) { _minTimeUnder = timeunder; } var time = timeunder - GetChildrenTime(c); if (time > _maxTime) { _maxTime = time; } if (time < _minTime) { _minTime = time; } _totalTime += time; }
public FunctionAnalysisUnit(FunctionAnalysisUnit originalUnit, CallChain callChain, ArgumentSet callArgs) : base(originalUnit.Ast, null) { _originalUnit = originalUnit; _declUnit = originalUnit._declUnit; Function = originalUnit.Function; CallChain = callChain; var scope = new FunctionScope( Function, Ast, originalUnit.Scope.OuterScope, originalUnit.DeclaringModule.ProjectEntry ); scope.UpdateParameters(this, callArgs, false, originalUnit.Scope as FunctionScope); _scope = scope; var walker = new OverviewWalker(_originalUnit.ProjectEntry, this, Tree); if (Ast.Body != null) { Ast.Body.Walk(walker); } AnalysisLog.NewUnit(this); Enqueue(); }
private int GetDepth(CallChain testChain) { if (testChain == null || testChain.Children == null || testChain.Children.Count == 0) { return(0); } return(GetDepth(testChain.Children[0]) + 1); }
public static CallChain BuildChainWithPrefix(string prefix) { var chain = new CallChain(prefix + "Root", prefix + "RootR", 1) { StartTime=0,EndTime=10}; chain.AddChild(new CallChain(prefix + "Child1", prefix + "Child1R", 2) { StartTime = 1, EndTime = 2 }); chain.AddChild(new CallChain(prefix + "Child2", prefix + "Child2R", 3) { StartTime = 2, EndTime = 3 }); var child = new CallChain(prefix + "Child3", prefix + "Child3R", 4) { StartTime = 4, EndTime = 7 }; child.AddChild(new CallChain(prefix + "GrandChild", prefix + "GrandChildR", 5) { StartTime = 5, EndTime = 6 }); chain.AddChild(child); return chain; }
public void RemoveEntry(CallChain c) { _timesCalled--; if (_timesCalled < 0) _timesCalled = 0; var timeunder = c.EndTime - c.StartTime; _totalTimeUnder -= timeunder; if (_totalTimeUnder < 0) _totalTimeUnder = 0; var time = timeunder - GetChildrenTime(c); _totalTime -= time; if (_totalTime < 0) _totalTime = 0; }
private double GetChildrenTime(CallChain c) { double ret = 0; if(c.Children != null && c.Children.Count > 0) { foreach (var child in c.Children) { if (child.Name == c.Name) continue; ret += child.EndTime - child.StartTime; } } return ret; }
public void ProcessNewEntry(CallChain c) { _timesCalled++; var timeunder = c.EndTime - c.StartTime; _totalTimeUnder += timeunder; if (timeunder > _maxTimeUnder) _maxTimeUnder = timeunder; if (timeunder < _minTimeUnder) _minTimeUnder = timeunder; var time = timeunder - GetChildrenTime(c); if (time > _maxTime) _maxTime = time; if (time < _minTime) _minTime = time; _totalTime += time; }
private static void WriteChainItem(BinaryWriter writer, CallChain chain) { writer.Write((string)chain.Name); //writer.Write((string)chain.Runtime); writer.Write((Int64)chain.FunctionId); writer.Write((int)chain.Children.Count); writer.Write((double)chain.StartTime); writer.Write((double)chain.EndTime); foreach (var child in chain.Children) { WriteChainItem(writer, child); } }
public void SetUp() { var chain = new CallChain("Root", "RootR", 1); var c = new CallChain("Child1", "Child1R", 2); c.AddChild(new CallChain("GrandChild", "GrandChildR", 17)); chain.AddChild(c); chain.AddChild(new CallChain("Child2", "Child2R", 3)); var child = new CallChain("Child3", "Child3R", 4); child.AddChild(new CallChain("GrandChild","GrandChildR", 5)); chain.AddChild(child); var information = new TestRunInformation {Name = "test", TestChain = chain}; _paths = PathFinder.FindPathsTo(information, "GrandChild").ToList(); }
internal FunctionClosureAnalysisUnit(IVersioned agg, FunctionAnalysisUnit originalUnit, CallChain callChain) : base(originalUnit.Function, originalUnit._declUnit, originalUnit._declUnit.Scope, originalUnit.ProjectEntry, true) { _originalUnit = originalUnit; _agg = agg; CallChain = callChain; _originalUnit.Scope.AddLinkedScope(Scope); var node = originalUnit.Function.FunctionDefinition; node.Body.Walk(new OverviewWalker(originalUnit.ProjectEntry, this, originalUnit.Tree)); AnalysisLog.NewUnit(this); }
private static Chain BuildChain(CallChain callChain, bool isSetup, bool isTest, bool isTeardown) { var chain = new Chain(callChain.Runtime, callChain.Name); chain.IsSetup = isSetup; chain.IsTest = isTest; chain.IsTeardown = isTeardown; chain.TimeStart = callChain.StartTime; chain.TimeEnd = callChain.EndTime; foreach (var child in callChain.Children) { chain.Children.Add(BuildChain(child, false, false, false)); } return(chain); }
private double GetChildrenTime(CallChain c) { double ret = 0; if (c.Children != null && c.Children.Count > 0) { foreach (var child in c.Children) { if (child.Name == c.Name) { continue; } ret += child.EndTime - child.StartTime; } } return(ret); }
public void SetUp() { var chain = new CallChain("Root", "RootR", 1); var c = new CallChain("Child1", "Child1R", 2); c.AddChild(new CallChain("GrandChild", "GrandChildR", 17)); chain.AddChild(c); chain.AddChild(new CallChain("Child2", "Child2R", 3)); var child = new CallChain("Child3", "Child3R", 4); child.AddChild(new CallChain("GrandChild", "GrandChildR", 5)); chain.AddChild(child); var information = new TestRunInformation { Name = "test", TestChain = chain }; _paths = PathFinder.FindPathsTo(information, "GrandChild").ToList(); }
public void can_calulate_total_time_properly_for_single_item_with_single_child() { var count = new CountsAndTimes(); var chain = new CallChain("TEST", "TESTR", 1) { StartTime = 0, EndTime = 10 }; chain.Children.Add(new CallChain("TEST1", "TESTR", 3) { StartTime = 3, EndTime = 5 }); count.ProcessNewEntry(chain); Assert.AreEqual(8, count.TotalTime); Assert.AreEqual(8, count.MaxTime); Assert.AreEqual(8, count.MinTime); Assert.AreEqual(8, count.AverageTime); }
private static CallChain ReadChainItem(BinaryReader reader) { var name = string.Intern(reader.ReadString()); //var runtime = reader.ReadString(); var functionId = reader.ReadInt64(); var item = new CallChain(name, "", functionId); var count = reader.ReadInt32(); var start = reader.ReadDouble(); var end = reader.ReadDouble(); item.StartTime = start; item.EndTime = end; for (int i = 0; i < count; i++) { item.AddChild(ReadChainItem(reader)); } return(item); }
public void does_not_include_children_that_are_itself_when_counting_with_multiple_children() { var count = new CountsAndTimes(); var chain = new CallChain("TEST", "TESTR", 3) { StartTime = 0, EndTime = 10 }; chain.Children.Add(new CallChain("TEST", "TESTR", 3) { StartTime = 3, EndTime = 5 }); chain.Children.Add(new CallChain("TEST1", "TESTR", 3) { StartTime = 5, EndTime = 7 }); count.ProcessNewEntry(chain); Assert.AreEqual(8, count.TotalTime); Assert.AreEqual(8, count.MaxTime); Assert.AreEqual(8, count.MinTime); Assert.AreEqual(8, count.AverageTime); }
public void RemoveEntry(CallChain c) { _timesCalled--; if (_timesCalled < 0) { _timesCalled = 0; } var timeunder = c.EndTime - c.StartTime; _totalTimeUnder -= timeunder; if (_totalTimeUnder < 0) { _totalTimeUnder = 0; } var time = timeunder - GetChildrenTime(c); _totalTime -= time; if (_totalTime < 0) { _totalTime = 0; } }
/// <summary> /// Performs all necessary queries to determine whether any violations were found, returning all violation objects as <see cref="CommandLineViolation"/>. /// </summary> /// <returns> /// Returns a collection of <see cref="CommandLineViolation"/> representing the violations, if any violations where found. /// Returns an empty collection if no violations were found. /// </returns> public override IEnumerable <CommandLineViolation> GetViolations() { if (CommandLine.Arguments.Any() && CallChain.Found(CmdLineSearchOptions.None)) { int paramCount = CallChain.GetParams().Count(); if (paramCount < MinParamsAllowed) { yield return new CommandLineViolation() { Violation = nameof(ParameterCountRestriction), Message = string.Join(" ", CallChain.Select(icla => icla.Command)) } } ; else if (paramCount > MaxParamsAllowed) { yield return new CommandLineViolation() { Violation = nameof(ParameterCountRestriction), Message = string.Join(" ", CallChain.Select(icla => icla.Command)) } } ; } } }
public override INamespaceSet Call(Node node, AnalysisUnit unit, INamespaceSet[] args, NameExpression[] keywordArgNames) { var callArgs = ArgumentSet.FromArgs(FunctionDefinition, unit, args, keywordArgNames); if (_allCalls == null) { _allCalls = new Dictionary<CallChain, FunctionAnalysisUnit>(); } FunctionAnalysisUnit calledUnit; bool updateArguments = true; if (callArgs.Count == 0 || (ProjectState.Limits.UnifyCallsToNew && Name == "__new__")) { calledUnit = (FunctionAnalysisUnit)AnalysisUnit; } else { var chain = new CallChain(node, unit, unit.ProjectState.Limits.CallDepth); if (!_allCalls.TryGetValue(chain, out calledUnit)) { if (unit.ForEval) { // Call expressions that weren't analyzed get the union result // of all calls to this function. var res = NamespaceSet.Empty; foreach (var call in _allCalls.Values) { res = res.Union(call.ReturnValue.TypesNoCopy); } return res; } else { _allCalls[chain] = calledUnit = new FunctionAnalysisUnit((FunctionAnalysisUnit)AnalysisUnit, chain, callArgs); updateArguments = false; } } } if (updateArguments && calledUnit.UpdateParameters(callArgs)) { #if DEBUG // Checks whether these arguments can be added ad nauseum. if (calledUnit.UpdateParameters(callArgs) && calledUnit.UpdateParameters(callArgs) && calledUnit.UpdateParameters(callArgs)) { AnalysisLog.Add("BadArgs", calledUnit, callArgs); } #endif AnalysisLog.UpdateUnit(calledUnit); } calledUnit.ReturnValue.AddDependency(unit); return calledUnit.ReturnValue.Types; }
private int GetDepth(CallChain testChain) { if (testChain == null || testChain.Children == null || testChain.Children.Count == 0) return 0; return GetDepth(testChain.Children[0]) + 1; }
private static CallChain ReadChainItem(BinaryReader reader) { var name = string.Intern(reader.ReadString()); //var runtime = reader.ReadString(); var functionId = reader.ReadInt64(); var item = new CallChain(name, "", functionId); var count = reader.ReadInt32(); var start = reader.ReadDouble(); var end = reader.ReadDouble(); item.StartTime = start; item.EndTime = end; for (int i = 0; i < count; i++) { item.AddChild(ReadChainItem(reader)); } return item; }
private static void WriteChainItem(BinaryWriter writer, CallChain chain) { writer.Write((string) chain.Name); //writer.Write((string)chain.Runtime); writer.Write((Int64) chain.FunctionId); writer.Write((int) chain.Children.Count); writer.Write((double)chain.StartTime); writer.Write((double)chain.EndTime); foreach(var child in chain.Children) { WriteChainItem(writer, child); } }