Exemple #1
0
        public static IEnumerable <CrmType> ReadFromFetchXml <CrmType>(Func <PagingInformation, List <CrmType> > getBuffer)
        {
            PagingInformation pagingInformation = new PagingInformation();
            List <CrmType>    bufferList;

            while (pagingInformation.FirstRun == true || pagingInformation.MoreRecords == true)
            {
                bufferList = getBuffer(pagingInformation);

                for (int bufferIndex = 0; bufferIndex < bufferList.Count; bufferIndex++)
                {
                    yield return(bufferList.ElementAt(bufferIndex));
                }
            }
        }
Exemple #2
0
        public static List <MaterialeBehovDefinition> FindMaterialeBehovDefinitionPerMateriale(IDynamicsCrmConnection dynamicsCrmConnection, Guid materialeId, Func <string, string> getResourcePath, PagingInformation pagingInformation)
        {
            string path = getResourcePath("Dynamics/Crm/FetchXml/MaterialeBehovDefinition/FindMaterialeBehovDefinitionPerMateriale.xml");

            XDocument xDocument = XDocument.Load(path);

            xDocument.Element("fetch").Element("entity").Element("filter").Element("condition").Attribute("value").Value = materialeId.ToString();

            List <MaterialeBehovDefinition> definitioner = StaticCrm.ReadFromFetchXml(dynamicsCrmConnection, xDocument, (connection, lEntity) => new MaterialeBehovDefinition(connection, lEntity), pagingInformation);

            return(definitioner);
        }
        public static List <MailrelayInformation> GetMailrelayFromContact(IDynamicsCrmConnection dynamicsCrmConnection, Func <string, string> getResourcePath, PagingInformation pagingInformation, int pageSize, Guid?contactId)
        {
            string path = getResourcePath("Dynamics/Crm/FetchXml/Mailrelay/GetMailrelayFromContact.xml");

            XDocument xDocument = XDocument.Load(path);

            xDocument.Element("fetch").Attribute("count").Value = pageSize.ToString();

            if (contactId.HasValue)
            {
                XmlHelper.AddCondition(xDocument, "contactid", "eq", contactId.Value.ToString());
            }

            XmlHelper.AddCondition(xDocument, "new_mailrelaysubscriberid", "not-null");

            List <MailrelayInformation> informations = StaticCrm.ReadFromFetchXml(dynamicsCrmConnection, xDocument, (connection, entity) => new MailrelayInformation(connection, entity), pagingInformation);

            return(informations);
        }
Exemple #4
0
 private void GetAccountsIndsamlingshjaelper(List <MaterialeBehovDefinition> behovDefinitioner, List <Account> accounts, Guid owningbusinessunit, Func <string, string> getResourcePath, PagingInformation pagingInformation)
 {
     if (behovDefinitioner.Any(definition => definition.behovtype == MaterialeBehovDefinition.behovtypeEnum.Indsamlingshjaelper))
     {
         accounts.AddRange(Account.GetIndsamlingshjaelper(Connection, _numberOfAccountsPerMaterialeAssign, owningbusinessunit, getResourcePath, pagingInformation));
     }
 }
Exemple #5
0
        public static MarketingList GetListForMailrelayUpdate(IDynamicsCrmConnection dynamicsCrmConnection, PagingInformation pagingInformation, Guid?crmListId)
        {
            List <string> fields = new List <string>()
            {
                "new_mailrelaygroupid",
                "listname",
                "query",
                "new_mailrelaycheck",
                "createdfromcode",
            };

            Dictionary <string, string> search = new Dictionary <string, string>()
            {
                { "new_controlmailrelaygroup", true.ToString() }
            };

            if (crmListId.HasValue)
            {
                search.Add("listid", crmListId.Value.ToString());
            }

            IEnumerable <MarketingList> lists = StaticCrm.ReadFromFetchXml(dynamicsCrmConnection, "list", fields, search, 1, (connection, entity) => new MarketingList(connection, entity), pagingInformation);

            return(lists.SingleOrDefault());
        }
Exemple #6
0
        public static List <dynamic> ReadFromFetchXml(IDynamicsCrmConnection dynamicsCrmConnection, XDocument xDocument, PagingInformation pagingInformation)
        {
            if (pagingInformation.FirstRun == false)
            {
                if (pagingInformation.MoreRecords == false)
                {
                    return(new List <dynamic>());
                }

                XmlHelper.SetAttributeValue(xDocument, "fetch", "paging-cookie", pagingInformation.PagingCookie);
                XmlHelper.SetAttributeValue(xDocument, "fetch", "page", pagingInformation.Page);
            }

            pagingInformation.FirstRun = false;

            FetchExpression fetchExpression = new FetchExpression(xDocument.ToString());

            EntityCollection entityCollection = dynamicsCrmConnection.Service.RetrieveMultiple(fetchExpression);

            if (entityCollection.Entities.Count == 0)
            {
                return(new List <dynamic>());
            }

            List <dynamic> crmEntities = entityCollection.Entities.Select(entity => GetFromEntity(entity)).ToList();

            pagingInformation.MoreRecords  = entityCollection.MoreRecords;
            pagingInformation.PagingCookie = entityCollection.PagingCookie;
            pagingInformation.Page++;

            return(crmEntities);
        }
Exemple #7
0
        public static List <dynamic> ReadFromFetchXml(IDynamicsCrmConnection dynamicsCrmConnection, string path, PagingInformation pagingInformation)
        {
            XDocument xDocument = XDocument.Load(path);

            return(ReadFromFetchXml(dynamicsCrmConnection, xDocument, pagingInformation));
        }
Exemple #8
0
        public static List <dynamic> ReadFromFetchXml(IDynamicsCrmConnection dynamicsCrmConnection, string entityName, List <string> fields, Dictionary <string, string> keyContent, int?maxCount, PagingInformation pagingInformation)
        {
            XDocument xDocument = new XDocument(
                new XElement("fetch",
                             new XElement("entity", new XAttribute("name", entityName),
                                          new XElement("filter"))));

            if (maxCount.HasValue)
            {
                xDocument.Element("fetch").Add(new XAttribute("count", maxCount.Value));
            }

            xDocument.Element("fetch").Element("entity").Add(StaticCrm.GetAttributeElements(fields.ToList()));
            xDocument.Element("fetch").Element("entity").Element("filter").Add(StaticCrm.GetConditionElements(keyContent));

            List <dynamic> crmObjects = ReadFromFetchXml(dynamicsCrmConnection, xDocument, pagingInformation);

            return(crmObjects);
        }
Exemple #9
0
        public static List <Account> GetIndsamlingshjaelper(IDynamicsCrmConnection dynamicsCrmConnection, int maxCount, Guid owningbusinessunit, Func <string, string> getResourcePath, PagingInformation pagingInformation)
        {
            string path = getResourcePath("Dynamics/Crm/FetchXml/Account/GetIndsamlingshjaelper.xml");

            XDocument xDocument = XDocument.Load(path);

            xDocument.Element("fetch").Element("entity").Element("filter").Elements("condition").
            Where(element => element.Attribute("attribute").Value == "owningbusinessunit").Single().
            Attribute("value").Value = owningbusinessunit.ToString();

            xDocument.Element("fetch").Attribute("count").Value = maxCount.ToString();

            List <Account> accounts = StaticCrm.ReadFromFetchXml(dynamicsCrmConnection, xDocument, (connection, lEntity) => new Account(connection, lEntity), pagingInformation);

            return(accounts);
        }
Exemple #10
0
        public static List <CrmType> ReadFromFetchXml <CrmType>(IDynamicsCrmConnection dynamicsCrmConnection, XDocument xDocument, Func <IDynamicsCrmConnection, Entity, CrmType> CrmTypeConstructor, PagingInformation pagingInformation)
        {
            if (pagingInformation.FirstRun == false)
            {
                if (pagingInformation.MoreRecords == false)
                {
                    return(new List <CrmType>());
                }

                xDocument.Element("fetch").Add(new XAttribute("paging-cookie", pagingInformation.PagingCookie));
                xDocument.Element("fetch").Add(new XAttribute("page", pagingInformation.Page));
            }

            pagingInformation.FirstRun = false;

            FetchExpression fetchExpression = new FetchExpression(xDocument.ToString());

            EntityCollection entityCollection = dynamicsCrmConnection.Service.RetrieveMultiple(fetchExpression);

            if (entityCollection.Entities.Count == 0)
            {
                return(new List <CrmType>());
            }

            List <CrmType> crmEntities = entityCollection.Entities.Select(entity => CrmTypeConstructor(dynamicsCrmConnection, entity)).ToList();

            pagingInformation.MoreRecords  = entityCollection.MoreRecords;
            pagingInformation.PagingCookie = entityCollection.PagingCookie;
            pagingInformation.Page++;

            return(crmEntities);
        }
Exemple #11
0
        public static List <CrmType> ReadFromFetchXml <CrmType>(IDynamicsCrmConnection dynamicsCrmConnection, string path, Func <IDynamicsCrmConnection, Entity, CrmType> CrmTypeConstructor, PagingInformation pagingInformation)
        {
            XDocument xDocument = XDocument.Load(path);

            return(ReadFromFetchXml(dynamicsCrmConnection, xDocument, CrmTypeConstructor, pagingInformation));
        }
Exemple #12
0
        public static List <CrmType> ReadFromFetchXml <CrmType>(IDynamicsCrmConnection dynamicsCrmConnection, string entityName, List <string> fields, Dictionary <string, string> keyContent, int?maxCount, Func <IDynamicsCrmConnection, Entity, CrmType> CrmTypeConstructor, PagingInformation pagingInformation)
        {
            XDocument xDocument = new XDocument(
                new XElement("fetch",
                             new XElement("entity", new XAttribute("name", entityName),
                                          new XElement("filter"))));

            if (maxCount.HasValue)
            {
                XmlHelper.SetCount(xDocument, maxCount.Value);
            }

            xDocument.Element("fetch").Element("entity").Add(GetAttributeElements(fields.ToList()));
            xDocument.Element("fetch").Element("entity").Element("filter").Add(GetConditionElements(keyContent));

            List <CrmType> crmObjects = ReadFromFetchXml(dynamicsCrmConnection, xDocument, CrmTypeConstructor, pagingInformation);

            return(crmObjects);
        }
Exemple #13
0
 public static List <CrmType> ReadFromFetchXml <CrmType>(IDynamicsCrmConnection dynamicsCrmConnection, List <string> fields, Dictionary <string, string> keyContent, int?maxCount, Func <IDynamicsCrmConnection, Entity, CrmType> CrmTypeConstructor, PagingInformation pagingInformation)
 {
     return(ReadFromFetchXml(dynamicsCrmConnection, typeof(CrmType).Name.ToLower(), fields, keyContent, maxCount, CrmTypeConstructor, pagingInformation));
 }