Esempio n. 1
0
        private ImportFieldsResponse ImportFieldTypes(IDictionary <int, FieldMetadata> metadata, LogController controller,
                                                      CustomisationImportResponse response, IEnumerable <string> createdRecordTypes)
        {
            var importFieldsResponse = new ImportFieldsResponse();

            var numberToDo      = metadata.Count();
            var numberCompleted = 0;

            for (var i = 0; i < metadata.Count(); i++)
            {
                var keyValue = metadata.ElementAt(i);
                var excelRow = keyValue.Key;
                var field    = keyValue.Value;
                try
                {
                    controller.UpdateProgress(numberCompleted++, numberToDo, string.Format("Importing {0}", FieldsTabName));

                    //If this is a primary field and the record type was created this import
                    //then the field has already been created when the record type was created
                    if (field is StringFieldMetadata &&
                        ((StringFieldMetadata)field).IsPrimaryField &&
                        createdRecordTypes.Contains(field.RecordType))
                    {
                        importFieldsResponse.AddCreatedField(field);
                        continue;
                    }

                    var isUpdate = !createdRecordTypes.Contains(field.RecordType) &&
                                   RecordService.FieldExists(field.SchemaName, field.RecordType);

                    RecordService.CreateOrUpdate(field, field.RecordType);
                    response.AddResponseItem(excelRow, field, isUpdate);
                    if (!isUpdate)
                    {
                        importFieldsResponse.AddCreatedField(field);
                    }
                }
                catch (Exception ex)
                {
                    response.AddResponseItem(excelRow, field, ex);
                }
            }
            return(importFieldsResponse);
        }
Esempio n. 2
0
        private ImportFieldsResponse ImportFieldTypes(IDictionary <int, FieldMetadata> metadata, LogController controller,
                                                      CustomisationImportResponse response, IEnumerable <string> createdRecordTypes)
        {
            var importFieldsResponse = new ImportFieldsResponse();

            var lookupFieldsCreated = new Dictionary <int, FieldMetadata>();

            var numberToDo      = metadata.Count();
            var numberCompleted = 0;

            for (var i = 0; i < metadata.Count(); i++)
            {
                var keyValue = metadata.ElementAt(i);
                var excelRow = keyValue.Key;
                var field    = keyValue.Value;
                try
                {
                    controller.UpdateProgress(numberCompleted++, numberToDo, string.Format("Importing {0}", FieldsTabName));

                    //If this is a primary field and the record type was created this import
                    //then the field has already been created when the record type was created
                    if (field is StringFieldMetadata &&
                        ((StringFieldMetadata)field).IsPrimaryField &&
                        createdRecordTypes.Contains(field.RecordType))
                    {
                        importFieldsResponse.AddCreatedField(field);
                        continue;
                    }

                    var isUpdate = !createdRecordTypes.Contains(field.RecordType) &&
                                   RecordService.FieldExists(field.SchemaName, field.RecordType);

                    RecordService.CreateOrUpdate(field, field.RecordType);
                    response.AddImportedItem(excelRow, field, isUpdate);
                    if (!isUpdate)
                    {
                        importFieldsResponse.AddCreatedField(field);
                        if (field is LookupFieldMetadata)
                        {
                            lookupFieldsCreated.Add(excelRow, field);
                        }
                    }
                }
                catch (Exception ex)
                {
                    response.AddResponseItem(excelRow, field, ex);
                }
            }
            if (numberCompleted > 0)
            {
                controller.LogLiteral("Publishing Fields");
                var publishXml = $"<importexportxml><entities>{string.Join("", metadata.Select(m => "<entity>" + m.Value.RecordType + "</entity>").Distinct())}</entities></importexportxml>";
                RecordService.Publish(publishXml);
            }
            numberToDo      = lookupFieldsCreated.Count();
            numberCompleted = 0;
            for (var i = 0; i < lookupFieldsCreated.Count(); i++)
            {
                var keyValue = lookupFieldsCreated.ElementAt(i);
                var excelRow = keyValue.Key;
                var field    = keyValue.Value;
                try
                {
                    controller.UpdateProgress(numberCompleted++, numberToDo, "Delta Updates For New Lookup Fields");
                    RecordService.CreateOrUpdate(field, field.RecordType);
                }
                catch (Exception ex)
                {
                    response.AddResponseItem(excelRow, field, ex);
                }
            }
            if (numberCompleted > 0)
            {
                controller.LogLiteral("Publishing Fields");
                var publishXml = $"<importexportxml><entities>{string.Join("", lookupFieldsCreated.Select(m => "<entity>" + m.Value.RecordType + "</entity>").Distinct())}</entities></importexportxml>";
                RecordService.Publish(publishXml);
            }
            return(importFieldsResponse);
        }