示例#1
0
        public async Task AuthenticateIntent(IDialogContext context, LuisResult result)
        {
            var fetchXml = string.Format(ContactInfo.RetrieveOrderByContact, this.customerContext.CustomerId);
            var salesOrderDetailsList = await DynamicsHelper <SalesOrderDetail> .GetFromCrmFetchXml(fetchXml, "salesorderdetails");

            if (salesOrderDetailsList == null || salesOrderDetailsList.Count() <= 0)
            {
                // No CV known
                await context.PostAsync("No CH known.");

                // TODO: custom cv identificatie
            }
            else if (salesOrderDetailsList.Count() == 1)
            {
                // 1 CV known
                this.customerContext.CustomerCv = salesOrderDetailsList.FirstOrDefault();
                context.Done(this.customerContext);
                return;
            }
            else
            {
                // More then 1 CV known
                PromptDialog.Choice(
                    context: context,
                    resume: this.ResumeAfterCvChoise,
                    options: salesOrderDetailsList,
                    prompt: "We have multiple CH's, about wich one do you have a question?",
                    retry: "Sorry, didn't understand, can you select the right CH.",
                    promptStyle: PromptStyle.Auto);

                return;
            }

            context.Wait(MessageReceived);
        }
        public static void Run([ServiceBusTrigger("entitycreate", access: AccessRights.Listen)] string mySbMsg, ILogger log)
        {
            var startTime = DateTime.Now;

            try
            {
                log.LogInformation($"Function 'DynamicsEntityCreate' executed at: {startTime}");

                if (mySbMsg == null)
                {
                    throw new ArgumentNullException(nameof(mySbMsg));
                }

                _dynamicsService = new DynamicsHelper(_credentials.crmorg, _credentials.user, _credentials.password, log);

                var message = JsonConvert.DeserializeObject <InstanceCreateMessage>(mySbMsg);
                IDictionary <string, object> entityDetails = new Dictionary <string, object>();
                var entityMapper = GetEntityMapper(message.DynamicsEntityName, log);
                if (entityMapper != null)
                {
                    foreach (var k in entityMapper)
                    {
                        if (message.EntityDetails.ContainsKey(k.Key) && !entityDetails.ContainsKey(k.Value))
                        {
                            entityDetails.Add(k.Value, message.EntityDetails[k.Key]);
                        }
                    }
                }

                if (entityDetails.Count == 0)
                {
                    entityDetails = message.EntityDetails;
                }

                if (message.Update && message.Id != Guid.Empty)
                {
                    _dynamicsService.UpdateEntityAttributes(message.DynamicsEntityName, message.Id, entityDetails);
                }
                else
                {
                    _dynamicsService.CreateEntityInstance(message.DynamicsEntityName, message.DynamicsEntityToken, entityDetails, message.Update, message.MissingMappingField);
                }
            }
            catch (Exception exception)
            {
                log.LogError($"Function 'AlertCreate' Exeption: {exception.Message} {exception.InnerException ?? exception.InnerException}");
            }
            finally
            {
                log.LogInformation($"Function 'AlertCreate' finished at: {DateTime.Now}, Timespan = {(DateTime.Now - startTime).TotalSeconds} seconds!");
            }
        }
        public async Task <bool> CreateServiceAppointment(DateTime serviceAppointment)
        {
            var description = string.IsNullOrWhiteSpace(this.customerContext.ErrorCode) ?
                              $"Service appointment for broken CH ({this.customerContext.CustomerCv.ProductName})."
                        : $"Service appointment for broken CH ({this.customerContext.CustomerCv.ProductName}). Error code: {this.customerContext.ErrorCode}.";

            var request = new ServiceRequest()
            {
                CustomerId  = this.customerContext.CustomerId,
                Title       = "Service appointment for " + this.customerContext.CustomerCv.ProductName,
                Description = $"Service appointment for broken CH ({this.customerContext.CustomerCv.ProductName}). Error code: {this.customerContext.ErrorCode}.",
                ScheduledOn = serviceAppointment
            };

            var response = await DynamicsHelper <ServiceRequest> .WriteToCrm(JsonConvert.SerializeObject(request), "incidents");

            JObject createResult = JsonConvert.DeserializeObject <JObject>(await response.Content.ReadAsStringAsync());

            return(createResult == null);
        }
示例#4
0
        public static void SolutionStats()
        {
            System.Collections.Hashtable ht = new System.Collections.Hashtable();
            string fetchXml          = @"<fetch version=""1.0"" mapping=""logical"" distinct=""false"">
                <entity name=""principalobjectaccess"">
                   <attribute name=""principalobjectaccessid""/>
                   <attribute name=""objecttypecode""/>
                </entity>
              </fetch>";
            var    poaOverviewExists = DynamicsHelper.CheckEntityExists(Service, "ita_poaoverview");

            if (!poaOverviewExists)
            {
                LogMessage("Please install the Overview solution first..");
            }
            else
            {
                int    fetchCount   = 4500;
                int    pageNumber   = 1;
                string pagingCookie = null;

                //Delete current POA Overview records
                QueryExpression qs = new QueryExpression("ita_poaoverview");
                qs.ColumnSet = new ColumnSet("ita_poaoverviewid");
                var existing = Service.RetrieveMultiple(qs).Entities;
                foreach (var e in existing)
                {
                    Service.Delete(e.LogicalName, e.Id);
                }

                FetchExpression fe = new FetchExpression(fetchXml);


                while (true)
                {
                    // Build fetchXml string with the placeholders.
                    string xml = DynamicsHelper.CreateXml(fetchXml, pagingCookie, pageNumber, fetchCount);

                    // Excute the fetch query and get the xml result.
                    RetrieveMultipleRequest request = new RetrieveMultipleRequest
                    {
                        Query = new FetchExpression(xml)
                    };

                    EntityCollection returnCollection = ((RetrieveMultipleResponse)Service.Execute(request)).EntityCollection;

                    foreach (var c in returnCollection.Entities)
                    {
                        string objectTypeCode = (string)c["objecttypecode"];
                        if (!ht.ContainsKey(objectTypeCode))
                        {
                            ht[objectTypeCode] = 0;
                        }
                        ht[objectTypeCode] = ((int)ht[objectTypeCode]) + 1;
                    }

                    if (returnCollection.MoreRecords)
                    {
                        System.Threading.Thread.Sleep(10);
                        LogMessage("Loaded 4500 POA records..");
                        pageNumber++;
                        pagingCookie = returnCollection.PagingCookie;
                    }
                    else
                    {
                        break;
                    }
                }
                //Create POA Overview records
                foreach (var key in ht.Keys)
                {
                    Entity ent = new Entity("ita_poaoverview");
                    ent["ita_name"]        = key;
                    ent["ita_recordcount"] = (int)ht[key];
                    Service.Create(ent);
                }

                LogMessage("Done!");
            }
        }