Пример #1
0
        public static AppManager GetDefaultApp(Auth auth, EdiSettings _edi = null, ProxySettings _proxy = null, AppSettings _app = null)
        {
            AppManager app = new AppManager();

            app.AuthData = auth;
            app.EdiApi   = EdiManager.GetDefaultApi(_edi, _proxy, _app);
            return(app);
        }
Пример #2
0
        private IEnumerable <object> ProcessDataProperty(EdiDataPropertySettings dataPropertySettings, CultureInfo cultureInfo)
        {
            var offsetRowIndex = 0;
            var loopCount      = 0;
            var endOfFile      = false;
            var dataRecords    = new List <object>();

            if (!(dataPropertySettings.DataProperty.DataProperties?.Any() ?? false))
            {
                return(dataRecords);
            }

            do
            {
                var currentStartRowIndex = dataPropertySettings.StartRowIndex + loopCount * offsetRowIndex;

                if (dataPropertySettings.DataRows.Length > currentStartRowIndex)
                {
                    var dataRecord = Activator.CreateInstance(dataPropertySettings.DataRecordType);
                    offsetRowIndex = CalculateRowIndexOffset(dataPropertySettings.DataProperty, offsetRowIndex);

                    var settings = new EdiSettings
                    {
                        DataRows             = dataPropertySettings.DataRows,
                        DataRecord           = dataRecord,
                        DataType             = dataPropertySettings.DataRecordType,
                        CurrentStartRowIndex = currentStartRowIndex,
                        CultureInfo          = cultureInfo
                    };

                    foreach (var dataProperty in dataPropertySettings.DataProperty.DataProperties)
                    {
                        settings.DataProperty = dataProperty;
                        endOfFile             = ProcessPropertyInfo(settings);
                    }

                    dataRecords.Add(dataRecord);
                }
                else
                {
                    endOfFile = true;
                }

                loopCount++;
            }while (dataPropertySettings.DataProperty.CanRepeatEDI && !endOfFile);

            return(dataRecords);
        }
Пример #3
0
        private void ProcessEnumerableProperty(EdiSettings settings)
        {
            var dataRecordEnumerable = InitDataRecordEnumerable(settings.DataRecord, settings.PropertyInfo);

            var dataPropertySettings = new EdiDataPropertySettings
            {
                DataRows       = settings.DataRows,
                DataProperty   = settings.DataProperty,
                DataRecordType = settings.PropertyInfo.PropertyType.GetGenericArguments()[0],
                StartRowIndex  = settings.CurrentStartRowIndex
            };

            var childs = ProcessDataProperty(dataPropertySettings, settings.CultureInfo);

            ProcessEnumerablePropertyResult(childs, dataRecordEnumerable);
        }
Пример #4
0
        private void ProcessClassProperty(EdiSettings settings)
        {
            var dataPropertySettings = new EdiDataPropertySettings
            {
                DataRows       = settings.DataRows,
                DataProperty   = settings.DataProperty,
                DataRecordType = settings.PropertyInfo.PropertyType,
                StartRowIndex  = settings.CurrentStartRowIndex
            };

            var child = ProcessDataProperty(dataPropertySettings, settings.CultureInfo).FirstOrDefault();

            if (child != null && !(child as IEmpty).IsEmpty)
            {
                SetPropertyValue(settings.PropertyInfo, settings.DataRecord, child, settings.CultureInfo);
            }
        }
Пример #5
0
        private bool ProcessPrimitiveDataTypeProperty(EdiSettings settings)
        {
            var currentRowIndex = settings.CurrentStartRowIndex + settings.DataProperty.LineIndexEDI;
            var endOfFile       = false;

            if (settings.DataRows.Length > currentRowIndex)
            {
                var rawValue = GetValue(settings.DataRows[currentRowIndex], settings.DataProperty.PositionEDI, settings.DataProperty.LengthEDI).Trim();

                if (rawValue.IsNullOrEmpty())
                {
                    return(endOfFile);
                }

                if (settings.DataProperty.ValueMappings != null)
                {
                    var mapping = settings.DataProperty.ValueMappings.FirstOrDefault(m =>
                                                                                     (m.Source.IsNullOrEmpty() && rawValue.IsNullOrEmpty()) ||
                                                                                     (!m.Source.IsNullOrEmpty() && m.Source.Equals(rawValue, StringComparison.InvariantCultureIgnoreCase))
                                                                                     );

                    if (!mapping.Source.IsNullOrEmpty())
                    {
                        rawValue = mapping.Target;
                    }
                }

                SetPropertyValue(settings.PropertyInfo, settings.DataRecord, rawValue, settings.CultureInfo);
            }
            else
            {
                endOfFile = true;
            }

            return(endOfFile);
        }
Пример #6
0
        private bool ProcessPropertyInfo(EdiSettings settings)
        {
            settings.PropertyInfo = settings.DataType.GetProperty(settings.DataProperty.PropertyTarget);
            var endOfFile = false;

            if (settings.DataProperty.HasMapping)
            {
                SetPropertyValue(settings.PropertyInfo, settings.DataRecord, settings.DataProperty.MappedValue, settings.CultureInfo);
            }
            else if (CheckIfIEnumerable(settings.PropertyInfo))
            {
                ProcessEnumerableProperty(settings);
            }
            else if (CheckIfClass(settings.PropertyInfo))
            {
                ProcessClassProperty(settings);
            }
            else
            {
                endOfFile = ProcessPrimitiveDataTypeProperty(settings);
            }

            return(endOfFile);
        }