Example #1
0
        public async Task Agent_API_error()
        {
            var httpClient = new HttpClient();

            var result = await AgentApi.PostAsync(httpClient,
                                                  BaseUrl + "/workspace/v3/initialize-workspace",
                                                  new { },
                                                  CancellationToken.None);
        }
        public void NoRequestUriAttributeInErrorEventWithoutTransaction()
        {
            AgentApi.NoticeError(new Exception("oh no"));

            _compositeTestAgent.Harvest();

            var errorEvent = _compositeTestAgent.ErrorEvents.First();

            Assert.IsFalse(errorEvent.AgentAttributes().ContainsKey("request.uri"));
        }
Example #3
0
 private static void Connect()
 {
     while (true)
     {
         if (AgentPhone.ping > 590)
         {
             if (AgentApi.MornsunSvrConnect("192.168.27.124", 8012) == 0)
             {
                 AgentPhone.ping = 0;
             }
             Thread.Sleep(10000);
         }
     }
 }
        public Task <JObject> PostAsync(string relativeUrl, object json, CancellationToken cancellationToken)
        {
            return(AgentApi.PostAsync(httpClient, ApiBaseUrl + relativeUrl, json, cancellationToken));

            //Debug.WriteLine($"POST {relativeUrl}\n{json}");

            //var result = httpClient.PostAsync(
            //    ApiBaseUrl + relativeUrl,
            //    new StringContent(
            //        json == null ? "" : JsonConvert.SerializeObject(json),
            //        Encoding.UTF8,
            //        "application/json"),
            //    cancellationToken);

            //return result;
        }
Example #5
0
        /// <summary>
        /// 初始化API Client属性
        /// </summary>
        private void Initialize()
        {
            if (string.IsNullOrEmpty(BaseUrl))
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(CorpId))
            {
                throw new ArgumentNullException("CorpId");
            }

            if (string.IsNullOrEmpty(CorpSecret))
            {
                throw new ArgumentNullException("CorpSecret");
            }

            User       = new UserApi(this);
            Department = new DepartmentApi(this);
            Tag        = new TagApi(this);
            CheckIn    = new CheckInApi(this);
            Message    = new MessageApi(this);
            Agent      = new AgentApi(this);
        }
 public void StartAgent()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.StartAgent(), "StartAgent");
 }
 public void RecordCustomEvent()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.RecordCustomEvent("customEvent", null), "RecordCustomEvent");
 }
        public CompositeTestAgent(bool shouldAllowThreads, bool includeAsyncLocalStorage)
        {
            Log.Initialize(new Logger());

            _shouldAllowThreads = shouldAllowThreads;

            // Create the fake classes necessary to construct services

            var mockFactory = Mock.Create <IContextStorageFactory>();

            Mock.Arrange(() => mockFactory.CreateContext <IInternalTransaction>(Arg.AnyString)).Returns(_primaryTransactionContextStorage);
            var transactionContextFactories = new List <IContextStorageFactory> {
                mockFactory
            };

            if (includeAsyncLocalStorage)
            {
                transactionContextFactories.Add(new AsyncLocalStorageFactory());
            }

            var wrappers             = Enumerable.Empty <IWrapper>();
            var mockEnvironment      = Mock.Create <IEnvironment>();
            var dataTransportService = Mock.Create <IDataTransportService>();
            var scheduler            = Mock.Create <IScheduler>();

            NativeMethods   = Mock.Create <INativeMethods>();
            _harvestActions = new List <Action>();
            Mock.Arrange(() => scheduler.ExecuteEvery(Arg.IsAny <Action>(), Arg.IsAny <TimeSpan>(), Arg.IsAny <TimeSpan?>()))
            .DoInstead <Action, TimeSpan, TimeSpan?>((action, _, __) => { lock (_harvestActionsLockObject) { _harvestActions.Add(action); } });
            var threadPoolStatic = Mock.Create <IThreadPoolStatic>();

            _queuedCallbacks = new List <WaitCallback>();
            Mock.Arrange(() => threadPoolStatic.QueueUserWorkItem(Arg.IsAny <WaitCallback>()))
            .DoInstead <WaitCallback>(callback => { lock (_queuedCallbacksLockObject) { _queuedCallbacks.Add(callback); } });

            var configurationManagerStatic = Mock.Create <IConfigurationManagerStatic>();

            Mock.Arrange(() => configurationManagerStatic.GetAppSetting("NewRelic.LicenseKey"))
            .Returns("Composite test license key");

            // Construct services
            _container = AgentServices.GetContainer();
            AgentServices.RegisterServices(_container);

            // Replace existing registrations with mocks before resolving any services
            _container.ReplaceRegistration(mockEnvironment);
            _container.ReplaceRegistration <IEnumerable <IContextStorageFactory> >(transactionContextFactories);
            _container.ReplaceRegistration <ICallStackManagerFactory>(
                new TestCallStackManagerFactory());
            _container.ReplaceRegistration(wrappers);
            _container.ReplaceRegistration(dataTransportService);
            _container.ReplaceRegistration(scheduler);
            _container.ReplaceRegistration(NativeMethods);

            _container.ReplaceRegistration(Mock.Create <ICATSupportabilityMetricCounters>());

            if (!_shouldAllowThreads)
            {
                _container.ReplaceRegistration(threadPoolStatic);
            }

            _container.ReplaceRegistration(configurationManagerStatic);

            InstrumentationService = _container.Resolve <IInstrumentationService>();
            InstrumentationWatcher = _container.Resolve <InstrumentationWatcher>();
            AgentServices.StartServices(_container);

            DisableAgentInitializer();
            InternalApi.SetAgentApiImplementation(_container.Resolve <IAgentApi>());
            AgentApi.SetSupportabilityMetricCounters(_container.Resolve <IApiSupportabilityMetricCounters>());

            // Update configuration (will also start services)
            LocalConfiguration    = GetDefaultTestLocalConfiguration();
            ServerConfiguration   = GetDefaultTestServerConfiguration();
            SecurityConfiguration = GetDefaultSecurityPoliciesConfiguration();
            InstrumentationWatcher.Start();
            PushConfiguration();

            _attribDefSvc = _container.Resolve <IAttributeDefinitionService>();

            // Redirect the mock DataTransportService to capture harvested wire models
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <IEnumerable <MetricWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(Metrics));
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <IEnumerable <CustomEventWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(CustomEvents));
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <IEnumerable <TransactionTraceWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(TransactionTraces));
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <EventHarvestData>(), Arg.IsAny <IEnumerable <TransactionEventWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(AdditionalHarvestData, TransactionEvents));
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <IEnumerable <ErrorTraceWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(ErrorTraces));
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <IEnumerable <SqlTraceWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(SqlTraces));
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <EventHarvestData>(), Arg.IsAny <IEnumerable <ErrorEventWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(AdditionalHarvestData, ErrorEvents));
            Mock.Arrange(() => dataTransportService.Send(Arg.IsAny <EventHarvestData>(), Arg.IsAny <IEnumerable <ISpanEventWireModel> >()))
            .Returns(SaveDataAndReturnSuccess(AdditionalHarvestData, SpanEvents));

            EnableAggregators();
        }
 public void IgnoreTransaction()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.IgnoreTransaction(), "IgnoreTransaction");
 }
 public void RecordMetric()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.RecordMetric("metricName", 1f), "RecordMetric");
 }
        public void NoticeError()
        {
            var exception = new IndexOutOfRangeException();

            CallAgentApiMethodRequiringTransaction(() => AgentApi.NoticeError(exception), "NoticeError");
        }
 public void GetBrowserTimingFooter()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.GetBrowserTimingFooter(), "GetBrowserTimingFooter");
 }
Example #13
0
        public WebOperate Exec(IPhone Phone)
        {
            int i = -1;

            switch (fun)
            {
            case "Connect": i = AgentApi.MornsunSvrConnect(p[0], int.Parse(p[1])); break;

            case "Disconnect": i = AgentApi.MornsunSvrShutdown(); break;

            case "Login": i = AgentApi.MornsunSvrLogin(p[0], p[1], p[2], p[3]);
                if (i == 0)
                {
                    Agent a = new Agent();
                    a.AgentId      = p[0];
                    a.ConnectionId = Phone.ConnectionId;
                    IAgent aa = Phone.List.Add(a);
                    if (aa != null && Phone.User.ContainsKey(aa.ConnectionId))
                    {
                        Phone.User[aa.ConnectionId].RemoveEvent();
                    }
                    else
                    {
                        Phone.AddEvent();
                    }
                }
                break;

            case "Logout": i = AgentApi.MornsunSvrLogout(p[0]);
                if (i == 0)
                {
                    Phone.List.Remove(p[0]);
                }
                break;

            case "AnswerCall": i = AgentApi.MornsunSvrAnswerCall(p[0], int.Parse(p[1])); break;

            case "Cancel": i = AgentApi.MornsunSvrCancel(p[0], int.Parse(p[1]), int.Parse(p[2]), int.Parse(p[3])); break;

            case "ChangeAgentPassword": i = AgentApi.MornsunSvrChangePassword(p[0], p[1], p[2]); break;

            case "SetAgentStatus": i = AgentApi.MornsunSvrChangeAgentStatus(p[0], byte.Parse(p[1]), p[2]); break;

            case "CompleteTransfer": i = AgentApi.MornsunSvrCompleteTransfer(p[0], int.Parse(p[2])); break;

            case "ConferenceCall": i = AgentApi.MornsunSvrConferenceCall(p[0], int.Parse(p[1]), p[2], p[3]); break;

            case "ConsultCall": i = AgentApi.MornsunSvrConsultCall(p[0], int.Parse(p[1]), p[2], p[3], p[4]); break;

            case "HangUp": i = AgentApi.MornsunSvrHangupCall(p[0], int.Parse(p[1])); break;

            case "HoldCall": i = AgentApi.MornsunSvrHoldCall(p[0], int.Parse(p[1])); break;

            case "ReteiveCall": i = AgentApi.MornsunSvrRetrieveCall(p[0], int.Parse(p[1])); break;

            case "MakeCall": i = AgentApi.MornsunSvrMakeCall(p[0], int.Parse(p[1]), p[2], p[3]); break;

            case "TransferCall": i = AgentApi.MornsunSvrTransferCall(p[0], int.Parse(p[1]), p[2], p[3], p[4]); break;

            case "SendTXTMessage": i = AgentApi.MornsunSvrSendTXTMessage(p[0], p[1], p[2]); break;
            }
            this.p   = new string[] { (i > -1).ToString() };
            this.fun = "callback";
            return(this);
        }
 public void RecordResponseTimeMetric()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.RecordResponseTimeMetric("responseTimeMetric", 1234L), "RecordResponseTimeMetric");
 }
 public void SetUserParameters()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.SetUserParameters("userName", "accountName", "productName"), "SetUserParameters");
 }
 public void SetTransactionName()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.SetTransactionName("custom", "transactionName"), "SetTransactionName");
 }
 public void SetApplicationName()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.SetApplicationName("applicationName"), "SetApplicationName");
 }
 public void DisableBrowserMonitoring()
 {
     AgentApi.DisableBrowserMonitoring();
     HarvestAndValidateMetric("DisableBrowserMonitoring");
 }
 public void AddCustomParameter()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.AddCustomParameter("customParameter", "1234"), "AddCustomParameter");
 }
 public void Init()
 {
     instance = new AgentApi();
 }
 public void IncrementCounter()
 {
     CallAgentApiMethodRequiringTransaction(() => AgentApi.IncrementCounter("fred"), "IncrementCounter");
 }