コード例 #1
0
        public static List <Person> GetPeopleFromFetch(
            OrganizationServiceContext organizationServiceContext,
            IOrganizationService organizationService,
            string findName)
        {
            // Find the correct Fetch XML
            var findResults = organizationServiceContext.CreateQuery <SavedView>()
                              .Where(x => x.Name == findName).ToList();

            if (findResults.Count() != 1)
            {
                throw new Exception(
                          $"Expected exactly one Advanced Find name \"{findName}\", but found {findResults.Count()}");
            }

            SavedView find = findResults.First();

            // Create the request
            ExecuteByIdSavedQueryRequest executeSavedQueryRequest = new ExecuteByIdSavedQueryRequest()
            {
                EntityId = find.Id
            };

            // Execute the request
            var results = organizationService.RetrieveMultiple(new FetchExpression(find.FetchXML))
                          .ToProxies <Person>();

            return(results);
        }
コード例 #2
0
        public void Should_Retrieve_Records_By_Given_Find()
        {
            // Arrange
            var sampleView = new SavedView()
            {
                Name     = "Sample",
                Id       = Guid.NewGuid(),
                FetchXML = @"
<fetch version=""1.0"" output-format=""xml-platform"" mapping=""logical"" distinct=""false"">
  <entity name=""contact"">
    <attribute name=""emailaddress1"" />
    <attribute name=""lastname"" />
    <attribute name=""firstname"" />
    <attribute name=""address1_telephone1"" />
    <attribute name=""contactid"" />
  </entity>
</fetch>",
            };
            var person = new Person()
            {
                Id        = Guid.NewGuid(),
                FirstName = "Billy",
                LastName  = "Bob"
            };

            var fakedContext = new XrmFakedContext();

            fakedContext.Initialize(new List <Entity>()
            {
                person,
                sampleView,
            });

            var service        = fakedContext.GetOrganizationService();
            var serviceContext = new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(service);

            // Act
            var helper  = new CFApiHelper();
            var results = CFApiHelper.GetPeopleFromFetch(
                serviceContext,
                service,
                sampleView.Name);

            // Assert
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(results.FirstOrDefault().Id, person.Id);
        }
コード例 #3
0
        /// <summary>
        /// Инициализирует папку заданными значениями.
        /// </summary>
        /// <param name="Device">Прибор.</param>
        /// <param name="CodeID">ID кода СКБ.</param>
        /// <param name="CodeName">Отобразаемое значение кода СКБ.</param>
        /// <param name="DocumentID">ID документа.</param>
        /// <param name="DocumentName">Название документа.</param>
        /// <param name="FolderID">ID папки.</param>
        public DocumentsFolder(Folder ParentFolder, CardData Document, SavedSearchGroup SearchGroup, SavedView View, FolderCard FolderCard)
        {
            this.ParentFolder = ParentFolder;
            this.Document     = Document;
            DocumentID        = Document.Id;

            SectionData Properties = Document.Sections[CardOrd.Properties.ID];

            DocumentType = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.FileType + "'").GetString("Value");
            RowData Code = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.Code + "'");

            CodeID   = Code.GetGuid("Value").Value;
            CodeName = Code.GetString("DisplayValue");
            RowData Applicable = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.Applicable + "'");

            Applicability = Applicable.GetString("DisplayValue");
            RowData Name = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.DocumentName + "'");

            string ShortType = DocumentType == "СД - Спецификация (не платы)" || DocumentType == "СП - Спецификация платы" ? "" : DocumentType.Remove(DocumentType.IndexOf(" - "));

            DocumentName = CodeName + " " + ShortType + " " + Name.GetString("Value");

            Folder      = FolderCard.CreateFolder(ParentFolder.Id, DocumentName);
            Folder.Type = FolderTypes.Virtual;

            if (!SearchGroup.Queries.Any(row => row.Name == DocumentName))
            {
                SearchQuery   Query    = FolderCard.Session.CreateSearchQuery();
                CardTypeQuery CardType = Query.AttributiveSearch.CardTypeQueries.AddNew(CardOrd.ID);
                SectionQuery  Section  = CardType.SectionQueries.AddNew(CardOrd.MainInfo.ID);
                Section.Operation = SectionQueryOperation.And;
                Section.ConditionGroup.Operation = ConditionGroupOperation.And;
                Section.ConditionGroup.Conditions.AddNew(CardOrd.MainInfo.Type, FieldType.RefId, ConditionOperation.Equals, MyHelper.RefType_CD);

                Section           = CardType.SectionQueries.AddNew(CardOrd.Properties.ID);
                Section.Operation = SectionQueryOperation.And;
                Section.ConditionGroup.Operation = ConditionGroupOperation.And;
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Value, FieldType.Unistring, ConditionOperation.Equals, DocumentType);
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Name, FieldType.Unistring, ConditionOperation.Equals, RefPropertiesCD.Requisities.FileType);

                Section           = CardType.SectionQueries.AddNew(CardOrd.Properties.ID);
                Section.Operation = SectionQueryOperation.And;
                Section.ConditionGroup.Operation = ConditionGroupOperation.And;
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Value, FieldType.RefId, ConditionOperation.Equals, CodeID);
                Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Name, FieldType.Unistring, ConditionOperation.Equals, RefPropertiesCD.Requisities.Code);
                Query.Limit = 0;
                SearchGroup.Queries.AddNew(DocumentName).Import(Query);
            }
            SavedSearchQuery SavedQuery = SearchGroup.Queries.First(row => row.Name == DocumentName);

            Folder.RefId = SavedQuery.Id;

            Folder.CurrentViewId = View.Id;
            Folder.DefaultViewId = View.Id;
        }