Esempio n. 1
0
        private IEnumerable Execute(BuiltQuery builtQuery)
        {
            if (EntityHelpers.IsConstant(builtQuery.EntityType))
            {
                var constantWrapType = builtQuery.EntityType.BaseType;
                if (constantWrapType == null)
                {
                    throw new InvalidOperationException("assertion failure");
                }
                var constantWrap = (Constant)FormatterServices.GetUninitializedObject(builtQuery.EntityType);
                var constants    = ComHelpers.GetProperty(globalContext.ComObject(), "Константы");
                var constant     = ComHelpers.GetProperty(constants, builtQuery.EntityType.Name);
                var value        = ComHelpers.Invoke(constant, "Получить");
                constantWrap.ЗначениеНетипизированное = comObjectMapper.MapFrom1C(value,
                                                                                  constantWrapType.GetGenericArguments()[0]);
                yield return(constantWrap);

                yield break;
            }
            var queryText  = builtQuery.QueryText;
            var parameters = builtQuery.Parameters;

            parametersConverter.ConvertParametersTo1C(parameters);
            var hasReference = ConfigurationName.Get(builtQuery.EntityType).HasReference;
            var queryResult  = globalContext.Execute(queryText, parameters);

            if (hasReference || builtQuery.Projection != null)
            {
                var projection = builtQuery.Projection != null
                    ? ProjectionMapperFactory.GetMapper(builtQuery.Projection, comObjectMapper)
                    : null;

                var selection = queryResult.Select();
                while (selection.Next())
                {
                    if (projection != null)
                    {
                        yield return(projection(selection.ComObject));
                    }
                    else if (builtQuery.IsCount)
                    {
                        yield return(comObjectMapper.MapFrom1C(selection["src_Count"], typeof(int)));
                    }
                    else
                    {
                        yield return(comObjectMapper.MapFrom1C(selection["Ссылка"], builtQuery.EntityType));
                    }
                }
            }
            else
            {
                var valueTable = queryResult.Unload();
                foreach (var r in valueTable)
                {
                    yield return(comObjectMapper.MapFrom1C(r.ComObject(), builtQuery.EntityType));
                }
            }
        }
Esempio n. 2
0
        private object ConvertParameterValue(object value)
        {
            switch (value)
            {
            case ConvertEnumCmd convertEnum:
                return(comObjectMapper.MapEnumTo1C(convertEnum.valueIndex, convertEnum.enumType));

            case ConvertUniqueIdentifierCmd convertUniqueIdentifier:
            {
                var name          = ConfigurationName.Get(convertUniqueIdentifier.entityType);
                var itemManager   = globalContext.GetManager(name);
                var guidComObject = comObjectMapper.MapGuidTo1C(convertUniqueIdentifier.id);
                return(ComHelpers.Invoke(itemManager, "ПолучитьСсылку", guidComObject));
            }

            default:
                throw new InvalidOperationException("assertion failure");
            }
        }
Esempio n. 3
0
        private object ConvertParameterValue(object value)
        {
            var convertEnum = value as ConvertEnumCmd;

            if (convertEnum != null)
            {
                return(comObjectMapper.MapEnumTo1C(convertEnum.valueIndex, convertEnum.enumType));
            }
            var convertUniqueIdentifier = value as ConvertUniqueIdentifierCmd;

            if (convertUniqueIdentifier != null)
            {
                var name          = ConfigurationName.Get(convertUniqueIdentifier.entityType);
                var itemManager   = globalContext.GetManager(name);
                var guidComObject = comObjectMapper.MapGuidTo1C(convertUniqueIdentifier.id);
                return(ComHelpers.Invoke(itemManager, "ѕолучить—сылку", guidComObject));
            }
            throw new InvalidOperationException("assertion failure");
        }
Esempio n. 4
0
        private void Save(Abstract1CEntity source, object comObject, Stack <object> pending)
        {
            if (!source.Controller.IsDirty)
            {
                return;
            }
            if (pending.Contains(source))
            {
                const string messageFormat = "cycle detected for entity type [{0}]: [{1}]";
                throw new InvalidOperationException(string.Format(messageFormat, source.GetType().FormatName(),
                                                                  pending
                                                                  .Reverse()
                                                                  .Select(x => x is Abstract1CEntity ? x.GetType().FormatName() : x)
                                                                  .JoinStrings("->")));
            }
            pending.Push(source);
            Metadata          metadata;
            ConfigurationName?configurationName;

            if (comObject == null)
            {
                configurationName = ConfigurationName.Get(source.GetType());
                metadata          = metadataAccessor.GetMetadata(configurationName.Value);
                comObject         = GetComObjectForEditing(configurationName.Value, source);
            }
            else
            {
                metadata          = null;
                configurationName = null;
            }
            bool?newPostingValue = null;
            var  changeLog       = source.Controller.Changed;

            if (changeLog != null)
            {
                foreach (var p in changeLog)
                {
                    var value = p.Value;
                    if (p.Key == "Проведен" && configurationName.HasValue &&
                        configurationName.Value.Scope == ConfigurationScope.Документы)
                    {
                        newPostingValue = (bool?)value;
                        continue;
                    }
                    pending.Push(p.Key);
                    SaveProperty(p.Key, p.Value, comObject, pending, metadata);
                    pending.Pop();
                }
            }
            var needPatchWithOriginalValues = configurationName.HasValue &&
                                              configurationName.Value.Scope == ConfigurationScope.егистрыСведений &&
                                              source.Controller.ValueSource != null &&
                                              !source.Controller.ValueSource.Writable &&
                                              changeLog != null;

            if (needPatchWithOriginalValues)
            {
                var backingStorage = source.Controller.ValueSource.GetBackingStorage();
                foreach (var r in metadata.Requisites)
                {
                    if (!changeLog.ContainsKey(r.Name))
                    {
                        pending.Push(r);
                        var value = ComHelpers.GetProperty(backingStorage, r.Name);
                        SaveProperty(r.Name, value, comObject, pending, metadata);
                        pending.Pop();
                    }
                }
            }
            object valueSourceComObject;

            if (configurationName.HasValue)
            {
                if (!newPostingValue.HasValue && configurationName.Value.Scope == ConfigurationScope.Документы)
                {
                    var oldPostingValue = Convert.ToBoolean(ComHelpers.GetProperty(comObject, "Проведен"));
                    if (oldPostingValue)
                    {
                        Write(comObject, configurationName.Value, false);
                        newPostingValue = true;
                    }
                }
                Write(comObject, configurationName.Value, newPostingValue);
                switch (configurationName.Value.Scope)
                {
                case ConfigurationScope.Справочники:
                    UpdateIfExists(source, comObject, "Код");
                    break;

                case ConfigurationScope.Документы:
                    UpdateIfExists(source, comObject, "Номер");
                    break;
                }
                if (configurationName.Value.HasReference)
                {
                    valueSourceComObject = ComHelpers.GetProperty(comObject, "Ссылка");
                    UpdateId(valueSourceComObject, source, configurationName.Value);
                }
                else
                {
                    valueSourceComObject = comObject;
                }
            }
            else
            {
                UpdateIfExists(source, comObject, "НомерСтроки");
                valueSourceComObject = comObject;
            }
            var valueSourceIsWriteable = configurationName.HasValue &&
                                         configurationName.Value.Scope == ConfigurationScope.егистрыСведений;

            source.Controller.ResetDirty(new ComValueSource(valueSourceComObject, comObjectMapper,
                                                            valueSourceIsWriteable));
            pending.Pop();
        }
Esempio n. 5
0
        private InMemoryEntity Save(Abstract1CEntity entity, bool isTableSection)
        {
            if (entity == null)
            {
                return(null);
            }
            var changed = entity.Controller.Changed;

            if (changed != null)
            {
                var keys = changed.Keys.ToArray();
                foreach (var k in keys)
                {
                    var abstract1CEntity = changed[k] as Abstract1CEntity;
                    if (abstract1CEntity != null)
                    {
                        changed[k] = Save(abstract1CEntity, false);
                        continue;
                    }
                    var list = changed[k] as IList;
                    if (list != null)
                    {
                        changed[k] = ConvertList(list);
                        continue;
                    }
                    var syncList = changed[k] as SyncList;
                    if (syncList != null)
                    {
                        changed[k] = ConvertList(syncList.Current);
                    }
                }
            }
            InMemoryEntity inMemoryEntity;

            if (!entity.Controller.IsNew)
            {
                var inmemoryEntityRevision = (InMemoryEntityRevision)entity.Controller.ValueSource;
                inMemoryEntity = inmemoryEntityRevision.inMemoryEntity;
                if (changed != null)
                {
                    inMemoryEntity.revision = new InMemoryEntityRevision(inMemoryEntity, inmemoryEntityRevision, changed);
                    Collection(entity.GetType()).revision++;
                }
            }
            else
            {
                if (changed == null)
                {
                    changed = new Dictionary <string, object>();
                }
                inMemoryEntity = new InMemoryEntity();
                var revision = new InMemoryEntityRevision(inMemoryEntity, null, changed);
                inMemoryEntity.entityType = entity.GetType();
                inMemoryEntity.revision   = revision;
                if (!isTableSection)
                {
                    var configurationName = ConfigurationName.Get(entity.GetType());
                    if (configurationName.Scope == ConfigurationScope.Справочники)
                    {
                        AssignNewGuid(entity, changed, "Код");
                    }
                    else if (configurationName.Scope == ConfigurationScope.Документы)
                    {
                        AssignNewGuid(entity, changed, "Номер");
                    }
                    if (entity.Controller.IsNew && configurationName.HasReference)
                    {
                        var idProperty = entity.GetType().GetProperty(EntityHelpers.idPropertyName);
                        if (idProperty == null)
                        {
                            throw new InvalidOperationException("assertion failure");
                        }
                        AssignValue(entity, changed, idProperty, Guid.NewGuid());
                    }
                    var inMemoryEntityCollection = Collection(entity.GetType());
                    inMemoryEntityCollection.revision++;
                    inMemoryEntityCollection.list.Add(inMemoryEntity);
                }
            }
            entity.Controller.ResetDirty(inMemoryEntity.revision);
            return(inMemoryEntity);
        }