public async void GetIncidentsShouldReturnArrayOfIncidents(string userParam, string response)
        {
            //Arrange
            var client = new CRMClient(_baseUri, _httpClient);

            //Act
            try
            {
                var result = await client.IncidentAsync(new IncidentSearchInput { User = userParam });

                //Assert
                result.ShouldNotBeNull();
                result.ShouldBeOfType <List <IncidentDto> >("Wrong object");
            }
            catch (ApiException <ProblemDetails> exception)
            {
                //Could not connect- Actively refuses-Server down
                if (exception.StatusCode == 400)
                {
                    exception.Result.AdditionalProperties.Count.ShouldBeGreaterThanOrEqualTo(1, $"{exception.Result.AdditionalProperties.Count} errors found");

                    exception.Message.ShouldContain(response);
                    return;
                }
                if (exception.StatusCode == 406)
                {
                    exception.Message.ShouldBe(SwaggerResponseMessages.Status406);
                }
                if (exception.StatusCode == 409)
                {
                    exception.Message.ShouldBe("Conflict");
                }
                throw;
            }
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            eRSA = Creater.GetADConnector(Configuration.GetSection("AD"));
            services.AddSingleton <IADSearcher>(eRSA);
            try
            {
                CRMClient crmClient = new CRMClient(Configuration["Dynamics:Authority"], Configuration["Dynamics:Resource"],
                                                    Configuration["Dynamics:ClientId"], Configuration["Dynamics:ClientSecret"], Configuration["Dynamics:Version"]);
                services.AddSingleton <ITokenConsumer>(crmClient);
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.ToString());
                throw new ApplicationException("Cannot continue because saved token file is not found.");
            }

            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .CreateLogger();
            services.AddLogging(loggingBuilder =>
                                loggingBuilder.AddSerilog(dispose: true));
            Log.Logger.Debug("All services have been set up.");
        }
예제 #3
0
파일: UnitTest.cs 프로젝트: binchu/Code
        public void TestAccount()
        {
            Random ran       = new Random();
            int    name      = ran.Next(2000000);
            Guid   accountId = Guid.Empty;

            CRMClient crmClient = new CRMClient(AuthenticationHelper.AuthToken(), ConfigurationManager.AppSettings["ida:CrmResourceURL"]);
            var       task      = crmClient.ReadData("Account", "Name", "microsoft", "AccountId");

            task.Wait();
            string result = task.Result;

            if (result.IndexOf("guid") != -1)
            {
                accountId = new Guid(result.Substring(result.IndexOf("guid") + 5, 36));
                Assert.AreNotEqual(Guid.Empty, accountId);
            }
            accountId = Guid.NewGuid();
            string jsonData = "{\"AccountId\":\"" + accountId.ToString() + "\",\"Name\":\"" + name.ToString() + "\"}";

            task = crmClient.CreateData(jsonData, "Account");
            task.Wait();
            result = task.Result;
            task   = crmClient.ReadData("Account", "Name", name.ToString(), "AccountId");
            task.Wait();
            result = task.Result;
            Assert.AreNotEqual(-1, result.IndexOf("guid"));
            Guid guid = new Guid(result.Substring(result.IndexOf("guid") + 5, 36));

            Assert.IsNotNull(guid);
            Assert.AreEqual(accountId, guid);
        }
예제 #4
0
        public static bool NewUpdateActivity(string activityName, DateTime startTime, DateTime endTime, string webUrl, string activityRules, string sourceId, CRMSourceType sourceName, string user)
        {
            var result = false;

            try
            {
                using (var client = new CRMClient())
                {
                    var getResult = client.NewUpdateActivity(new Service.CallCenter.Models.Activity()
                    {
                        ActivityName = activityName,
                        StartTime    = startTime,
                        EndTime      = endTime,
                        SellingPoint = webUrl,
                        Detail       = activityRules,
                        SourceId     = sourceId + sourceName.ToString(),
                        UpdateUser   = user
                    });
                    result = getResult.Result.IsSuccess;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result);
        }
예제 #5
0
        public async Task <IActionResult> OnGet(Guid id)
        {
            Console.WriteLine($"You requested {id}");
            Stream response = await _crmClient.GetStreamAsync($"contacts({id})");

            if (response == null)
            {
                return(NotFound("Contact does not exist."));
            }
            Contact = CRMClient.DeserializeObject <Client.Types.Contact>(response);
            return(Page());
        }
예제 #6
0
        public void CRMTest()
        {
            var    authType = "Office365";
            string url      = "https://<instance name>.api.crm6.dynamics.com";
            string username = "******";
            string password = "******";

            string cs      = $"ServiceUri={url};AuthType={authType};UserName={username};Password={password}";
            var    crm     = CRMClient.GetConnection(cs);
            var    version = crm.GetVersion();

            Assert.IsNotNull(version);
        }
예제 #7
0
 /// <summary>
 /// Get a list of T
 /// </summary>
 /// <returns>a list with 0 or more records</returns>
 public async Task <List <T> > List <T>(string query)
 {
     try
     {
         return(CRMClient.DeserializeObject <Types.OData <T> >(await GetAsync(query)).Value);
     }
     catch (NullReferenceException)
     {
         // If GetAsync returns null, DeserializeObject returns null so we do the same
         // This was likely caused by something wrong the set up code: wrong end point etc
         return(null);
     }
 }
예제 #8
0
        public async Task <IActionResult> OnGetAsync()
        {
            Stream response = await _crmClient.GetStreamAsync(Product.List());

            if (response == null)
            {
                return(NotFound("Strangely no product is available."));
            }
            OData <Product> wrapper = CRMClient.DeserializeObject <OData <Product> >(response);

            Products = wrapper.Value;
            return(Page());
        }
예제 #9
0
 public string AddTask(JObject task)
 {
     try
     {
         string    result   = string.Empty;
         dynamic   jsonData = task;
         JObject   conJson  = jsonData.task;
         Task      con      = conJson.ToObject <Task>();
         CRMClient obj      = new CRMClient();
         result = obj.AddTask(con);
         return(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #10
0
 public string AddContact(JObject contact)
 {
     try
     {
         string    result   = string.Empty;
         dynamic   jsonData = contact;
         JObject   conJson  = jsonData.contact;
         Contact   con      = conJson.ToObject <Contact>();
         CRMClient obj      = new CRMClient();
         result = obj.AddContact(con);
         return(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #11
0
 public JsonResult <DataSet> GetTasks()
 {
     try
     {
         var       result = string.Empty;
         CRMClient obj    = new CRMClient();
         DataSet   ds     = obj.GetTasks();
         if (ds != null & ds.Tables.Count > 0)
         {
             //result = JsonConvert.SerializeObject(ds);
         }
         return(Json(ds));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #12
0
 public JsonResult <DataSet> GetContactById(string id)
 {
     try
     {
         string    result = string.Empty;
         CRMClient obj    = new CRMClient();
         DataSet   ds     = obj.GetContactById(Convert.ToInt32(id));
         if (ds != null & ds.Tables.Count > 0)
         {
             result = JsonConvert.SerializeObject(ds);
         }
         return(Json(ds));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #13
0
 public JsonResult <DataSet> callspWithoutParams(string spName)
 {
     try
     {
         var       result = string.Empty;
         CRMClient obj    = new CRMClient();
         DataSet   ds     = obj.callspWithoutParams(spName);
         if (ds != null & ds.Tables.Count > 0)
         {
             //result = JsonConvert.SerializeObject(ds);
         }
         return(Json(ds));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #14
0
        public static bool NewDeleteActivityBySourceId(string sourceId, CRMSourceType sourceName, string user)
        {
            var result = false;

            try
            {
                using (var client = new CRMClient())
                {
                    var getResult = client.NewDeleteActivityBySourceId(sourceId + sourceName.ToString(), user);
                    result = getResult.Result.IsSuccess;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(result);
        }
예제 #15
0
        private string GetCrmMetadata()
        {
            string    modelString = string.Empty;
            CRMClient crmClient;

            if (ConfigurationManager.AppSettings["CRMVersion"] == "online")
            {
                crmClient = new CRMClient(AuthenticationHelper.AuthToken(), ConfigurationManager.AppSettings["ida:CrmResourceURL"]);
            }
            else
            {
                crmClient = new CRMClient(AuthenticationHelper.GetHandler(), ConfigurationManager.AppSettings["ida:CrmResourceURL"]);
            }

            //need to spin up a new thread to get the metadata
            Thread thread = new Thread(new ThreadStart(() => modelString = crmClient.GetMetaData().Result));

            thread.Start();
            thread.Join(95000 * 4);

            return(modelString);
        }
예제 #16
0
 public Program(IConfiguration configuration)
 {
     _crmClient = new CRMClient(configuration["Dynamics:Authority"], configuration["Dynamics:Resource"],
                                configuration["Dynamics:ClientId"], configuration["Dynamics:ClientSecret"], configuration["Dynamics:Version"],
                                configuration["Dynamics:TokenCache"]);
 }
예제 #17
0
 public Orderdetail(CRMClient conn) : base(conn)
 {
     ENDPOINT = "salesorderdetails";
 }
예제 #18
0
        protected string ENDPOINT = "";  // Entities end point

        public Base(CRMClient conn)
        {
            _connector = conn;
        }
예제 #19
0
 public Account(CRMClient conn) : base(conn)
 {
     ENDPOINT = "accounts";
 }
예제 #20
0
 /// <summary>
 /// Run a query against Dynamics and return an Entity
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task <T> GetEntityAsync <T>(string query)
 {
     return(CRMClient.DeserializeObject <T>(await GetAsync(query)));
 }
예제 #21
0
 /// <summary>
 /// Run a query against Dynamics and return a JSON string of the response
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 public async Task <string> GetJsonStringAsync(string query)
 {
     return(CRMClient.StreamToJSONString(await GetAsync(query)));
 }
예제 #22
0
 public Order(CRMClient conn) : base(conn)
 {
     ENDPOINT = "salesorders";
 }
예제 #23
0
 public Contact(CRMClient conn) : base(conn)
 {
     ENDPOINT = "contacts";
 }