Exemple #1
0
        private static string Get1CTypeName(Type type)
        {
            if (type == typeof(string))
            {
                return("СТРОКА");
            }
            if (type == typeof(bool))
            {
                return("БУЛЕВО");
            }
            if (type == typeof(int) || type == typeof(uint) || type == typeof(byte) || type == typeof(long) ||
                type == typeof(ulong) || type == typeof(double) || type == typeof(float) || type == typeof(decimal))
            {
                return("ЧИСЛО");
            }
            if (type == typeof(DateTime) || type == typeof(DateTime?))
            {
                return("ДАТА");
            }
            var name = ConfigurationName.GetOrNull(type);

            if (name.HasValue)
            {
                return(name.Value.Fullname);
            }
            const string messageFormat = "can't detect 1C type for [{0}]";

            throw new InvalidOperationException(string.Format(messageFormat, type.Name));
        }
        private UnionLayout CreateSubkontoLayout()
        {
            if (subkontoTypes == null)
            {
                var configurationName = new ConfigurationName(ConfigurationScope.ПланыВидовХарактеристик,
                                                              "ВидыСубконтоХозрасчетные");
                var characteristicsPlan = globalContext.FindMetaByName(configurationName);
                var propertyTypes       = GetConfigurationTypes(characteristicsPlan.ComObject);
                if (propertyTypes == null)
                {
                    throw new InvalidOperationException("can't get characteristics types");
                }
                subkontoTypes = propertyTypes
                                .Where(delegate(string s)
                {
                    var name = ConfigurationName.Parse(s);
                    return(name.Scope == ConfigurationScope.Справочники ||
                           name.Scope == ConfigurationScope.Документы);
                })
                                .ToArray();
            }

            return(new UnionLayout("_Value_TYPE",
                                   "_Value_RTRef",
                                   "_Value_RRRef",
                                   subkontoTypes));
        }
Exemple #3
0
 //---------------------------------------------------------------------
 internal void OpenSolution(
     string startupProjects,
     ConfigurationName configurationName = ConfigurationName.Debug,
     PlatFormName platformName           = PlatFormName.Win32)
 {
     OpenSolution(new string[] { startupProjects }, configurationName, platformName);
 }
Exemple #4
0
        private void EmitConstants(GenerationContext context)
        {
            var constants      = ComHelpers.GetProperty(globalContext.Metadata, "Константы");
            var constantsCount = Call.Количество(constants);

            for (var i = 0; i < constantsCount; i++)
            {
                var constant       = Call.Получить(constants, i);
                var typeDescriptor = ExtractType(constant, context);
                if (!typeDescriptor.HasValue)
                {
                    continue;
                }
                var configurationName = new ConfigurationName(ConfigurationScope.Константы,
                                                              Call.Имя(constant));
                var template = new ConstantFileTemplate
                {
                    Model = new ConstantFileModel
                    {
                        Type      = typeDescriptor.Value.name,
                        Name      = configurationName.Name,
                        Synonym   = GenerateHelpers.EscapeString(Call.Синоним(constant)),
                        Namespace = GetNamespaceName(configurationName.Scope),
                        MaxLength = typeDescriptor.Value.maxLength
                    }
                };
                context.Write(configurationName, template.TransformText());
            }
        }
Exemple #5
0
        private ISqlElement GetSqlOrNull(string value)
        {
            var valueItems = value.Split('.');

            if (valueItems.Length < 3)
            {
                return(null);
            }
            var name = ConfigurationName.ParseOrNull(valueItems[0] + "." + valueItems[1]);

            if (!name.HasValue)
            {
                return(null);
            }
            var objectValue = valueItems[2];

            if (objectValue.EqualsIgnoringCase("ПустаяСсылка"))
            {
                return new LiteralExpression
                       {
                           Value = emptyReference
                       }
            }
            ;
            if (name.Value.Scope == ConfigurationScope.Перечисления)
            {
                return(GetEnumValueSql(name.Value.Fullname, objectValue));
            }
            return(null);
        }
Exemple #6
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         return((ConfigurationName.GetHashCode() * 397) ^ PlatformName.GetHashCode());
     }
 }
        /// <summary>
        /// Gets the configuration full path.
        /// </summary>
        /// <returns>System.String.</returns>
        internal string GetConfigurationFullPath()
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(ConfigurationName))
                {
                    var isWildcard = ConfigurationName.Contains(StringConstants.AsteriskChar);

                    var directory = EnvironmentCore.GetDirectory(ConfigurationDirectory, "Configurations");
                    if (directory.Exists && isWildcard)
                    {
                        return(directory.GetFiles(ConfigurationName).FirstOrDefault()?.FullName);
                    }
                    else
                    {
                        return(Path.Combine(directory.FullName.TrimEnd(StringConstants.BackSlash), ConfigurationName));
                    }
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                throw ex.Handle();
            }
        }
Exemple #8
0
        //---------------------------------------------------------------------
        static public SolutionConfiguration2 SetActiveSolutionConfiguration(
            ConfigurationName configurationName,
            PlatFormName platformName)
        {
            var configurationToActivate = GetSolutionConfiguration(configurationName, platformName);

            configurationToActivate.Activate();

            return(configurationToActivate);
        }
Exemple #9
0
        //---------------------------------------------------------------------
        static public SolutionConfiguration2 GetSolutionConfiguration(
            ConfigurationName configurationName,
            PlatFormName platformName)
        {
            var dte            = VsIdeTestHostContext.Dte;
            var configurations = dte.Solution.SolutionBuild.SolutionConfigurations.Cast <SolutionConfiguration2>();

            return(configurations.First(
                       c => c.Name == configurationName.ToString() && c.PlatformName == platformName.ToString()));
        }
        private ConfigurationItem FindByType(object typeObject)
        {
            var comObject = Call.НайтиПоТипу(globalContext.Metadata, typeObject);
            var fullName  = Call.ПолноеИмя(comObject);
            var name      = ConfigurationName.ParseOrNull(fullName);

            return(name.HasValue
                ? new ConfigurationItem(name.Value, comObject)
                : null);
        }
        private static string ProcessConfigurationName(ConfigurationName configurationName)
        {
            switch (configurationName)
            {
            case ConfigurationName.TokenEncriptKey:
                return("Token Encript Key is not setted in the System!");

            default:
                return("Configuration Missing in the System!");
            }
        }
Exemple #12
0
        //---------------------------------------------------------------------
        EnvDTE80.SolutionConfiguration2 OpenSolution(
            string[] startupProjects,
            ConfigurationName configurationName,
            PlatFormName platformName)
        {
            OpenDefaultSolution();
            var startupProjectObjects = new object[startupProjects.Length];

            Array.Copy(startupProjects, startupProjectObjects, startupProjectObjects.Length);
            VsIdeTestHostContext.Dte.Solution.SolutionBuild.StartupProjects = startupProjectObjects;
            return(SolutionConfigurationHelpers.SetActiveSolutionConfiguration(configurationName, platformName));
        }
Exemple #13
0
        public void Write(ConfigurationName name, string content)
        {
            var fileFullPath      = Path.Combine(rootDirectoryFullPath, name.Scope.ToString(), name.Name) + ".cs";
            var directoryFullPath = PathHelpers.GetDirectoryName(fileFullPath);

            if (!Directory.Exists(directoryFullPath))
            {
                Directory.CreateDirectory(directoryFullPath);
            }
            File.WriteAllText(fileFullPath, content);
            writtenFiles.Add(fileFullPath);
        }
Exemple #14
0
        private static string GetTypePresentation(Type type)
        {
            if (type == typeof(string))
            {
                return("Строка");
            }
            if (type.IsClass)
            {
                var scope = ConfigurationName.GetOrNull(type);
                if (scope != null)
                {
                    var presentation = ObjectPresentation.OfClass(type);
                    return(string.IsNullOrEmpty(presentation)
                        ? Synonym.OfClass(type)
                        : presentation);
                }
            }
            if (type == typeof(bool))
            {
                return("Булево");
            }
            if (type == typeof(DateTime))
            {
                return("Дата");
            }
            if (type == typeof(Guid))
            {
                return("УникальныйИдентификатор");
            }
            if (type == typeof(int) ||
                type == typeof(long) ||
                type == typeof(decimal) ||
                type == typeof(byte) ||
                type == typeof(sbyte) ||
                type == typeof(short) ||
                type == typeof(ushort) ||
                type == typeof(uint) ||
                type == typeof(ulong) ||
                type == typeof(float) ||
                type == typeof(double))
            {
                return("Число");
            }
            var underlyingType = Nullable.GetUnderlyingType(type);

            if (underlyingType != null)
            {
                return(GetTypePresentation(underlyingType));
            }
            const string messageFormat = "can't get ПРЕДСТАВЛЕНИЕ for [typeof({0})]";

            throw new NotSupportedException(string.Format(messageFormat, type.FormatName()));
        }
Exemple #15
0
 public void SetSource(Type type, string name)
 {
     QueryType = type;
     if (!string.IsNullOrEmpty(name))
     {
         sourceName = name;
         SourceType = typeRegistry.GetTypeOrNull(sourceName);
     }
     else
     {
         sourceName = ConfigurationName.Get(type).Fullname;
         SourceType = type;
     }
 }
        private UnionLayout CreateRegistratorLayout()
        {
            //У РегистрыБухгалтерии.Хозрасчетный.Субконто нельзя получить метаданные
            //globalContext.FindMetaByName - кидает исключение
            //Поэтому мы берём метаданные по Регистратору из РегистрыБухгалтерии.Хозрасчетный
            //Т.к. они скорее всего имеют одинаковые метаданные. В силу того, что Региcтратор
            //является частью составного ключа, по которым Субконто матчатся с проводками
            var configurationName   = new ConfigurationName(ConfigurationScope.егистрыБухгалтерии, "Хозрасчетный");
            var configurationItem   = globalContext.FindMetaByName(configurationName);
            var comObject           = configurationItem.ComObject;
            var descriptor          = MetadataHelpers.GetDescriptorOrNull(configurationName.Scope);
            var propertyDescriptors = comObject == null
                ? new Dictionary <string, string[]>()
                : MetadataHelpers.GetAttributes(comObject, descriptor)
                                      .ToDictionary(Call.Имя, GetConfigurationTypes);
            var propertyTypes = propertyDescriptors.GetOrDefault("Регистратор");

            return(new UnionLayout(null, "_RecorderTRef", "_RecorderRRef", propertyTypes));
        }
Exemple #17
0
        public IEnumerable <string> Generate()
        {
            var generationContext = new GenerationContext(targetDirectory);

            foreach (var itemName in itemNames)
            {
                var item = globalContext.FindMetaByName(ConfigurationName.Parse(itemName));
                generationContext.EnqueueIfNeeded(item);
            }
            EmitConstants(generationContext);
            var processedCount = 0;

            while (generationContext.ItemsToProcess.Count > 0)
            {
                var item = generationContext.ItemsToProcess.Dequeue();
                switch (item.Name.Scope)
                {
                case ConfigurationScope.Справочники:
                case ConfigurationScope.Документы:
                case ConfigurationScope.егистрыСведений:
                case ConfigurationScope.ПланыСчетов:
                case ConfigurationScope.ПланыВидовХарактеристик:
                    GenerateClass(item, generationContext);
                    break;

                case ConfigurationScope.Перечисления:
                    EmitEnum(item, generationContext);
                    break;

                default:
                    const string messageFormat = "unexpected scope for [{0}]";
                    throw new InvalidOperationException(string.Format(messageFormat, item.Name));
                }
                processedCount++;
                if (processedCount % 10 == 0)
                {
                    Console.Out.WriteLine("[{0}] items processed, queue length [{1}]",
                                          processedCount, generationContext.ItemsToProcess.Count);
                }
            }
            return(generationContext.GetWrittenFiles());
        }
        private TableMapping CreateDefaultTableMapping(ValueTableRow tableRow,
                                                       Dictionary <string, TableMapping> tableMappingByQueryName)
        {
            var queryTableName = tableRow.GetString("ИмяТаблицы");

            if (string.IsNullOrEmpty(queryTableName))
            {
                return(null);
            }
            var dbTableName = tableRow.GetString("ИмяТаблицыХранения");

            if (string.IsNullOrEmpty(dbTableName))
            {
                return(null);
            }
            var purpose = tableRow.GetString("Назначение");
            ConfigurationItemDescriptor descriptor;
            object    comObject;
            TableType tableType;

            if (purpose == "Основная" || purpose == "Константа")
            {
                var configurationName = ConfigurationName.ParseOrNull(queryTableName);
                if (!configurationName.HasValue)
                {
                    return(null);
                }
                tableType  = TableType.Main;
                descriptor = MetadataHelpers.GetDescriptorOrNull(configurationName.Value.Scope);
                if (descriptor == null)
                {
                    comObject = null;
                }
                else
                {
                    var configurationItem = globalContext.FindMetaByName(configurationName.Value);
                    comObject = configurationItem.ComObject;
                }
            }
            else if (purpose == "ТабличнаяЧасть")
            {
                descriptor = MetadataHelpers.tableSectionDescriptor;
                var fullname = TableSectionQueryNameToFullName(queryTableName);
                comObject = ComHelpers.Invoke(globalContext.Metadata, "НайтиПоПолномуИмени", fullname);
                if (comObject == null)
                {
                    return(null);
                }
                tableType = TableType.TableSection;
            }
            else
            {
                return(null);
            }
            var propertyDescriptors = comObject == null
                ? new Dictionary <string, string[]>()
                : MetadataHelpers.GetAttributes(comObject, descriptor)
                                      .ToDictionary(Call.Имя, GetConfigurationTypes);
            var propertyMappings = new ValueTable(tableRow["Поля"])
                                   .Select(x => new
            {
                queryName = x.GetString("ИмяПоля"),
                dbName    = x.GetString("ИмяПоляХранения")
            })
                                   .Where(x => !string.IsNullOrEmpty(x.queryName))
                                   .Where(x => !string.IsNullOrEmpty(x.dbName))
                                   .GroupBy(x => x.queryName,
                                            (x, y) => new
            {
                queryName = x,
                columns   = y.Select(z => z.dbName).ToArray()
            }, StringComparer.OrdinalIgnoreCase)
                                   .Select(x =>
            {
                var propertyName  = x.queryName.ExcludeSuffix("Кт").ExcludeSuffix("Дт");
                var propertyTypes = propertyName == "Счет"
                        ? new[] { "ПланСчетов.Хозрасчетный" }
                        : propertyDescriptors.GetOrDefault(propertyName);
                if (propertyTypes == null || propertyTypes.Length == 1)
                {
                    if (x.columns.Length != 1)
                    {
                        return(null);
                    }
                    var nestedTableName = propertyTypes == null ? null : propertyTypes[0];
                    var singleLayout    = new SingleLayout(x.columns[0], nestedTableName);
                    return(new PropertyMapping(x.queryName, singleLayout, null));
                }
                var unionLayout = x.queryName == "Регистратор"
                        ? new UnionLayout(
                    null,
                    GetColumnBySuffixOrNull("_RecorderTRef", x.columns),
                    GetColumnBySuffixOrNull("_RecorderRRef", x.columns),
                    propertyTypes)
                        : new UnionLayout(
                    GetColumnBySuffixOrNull("_type", x.columns),
                    GetColumnBySuffixOrNull("_rtref", x.columns),
                    GetColumnBySuffixOrNull("_rrref", x.columns),
                    propertyTypes);
                return(new PropertyMapping(x.queryName, null, unionLayout));
            })
                                   .NotNull()
                                   .ToList();

            if (tableType == TableType.TableSection)
            {
                if (!HasProperty(propertyMappings, PropertyNames.id))
                {
                    var refLayout = new SingleLayout(GetTableSectionIdColumnNameByTableName(dbTableName), null);
                    propertyMappings.Add(new PropertyMapping(PropertyNames.id, refLayout, null));
                }
                if (!HasProperty(propertyMappings, PropertyNames.area))
                {
                    var          mainQueryName = TableMapping.GetMainQueryNameByTableSectionQueryName(queryTableName);
                    TableMapping mainTableMapping;
                    if (!tableMappingByQueryName.TryGetValue(mainQueryName, out mainTableMapping))
                    {
                        return(null);
                    }
                    PropertyMapping mainAreaProperty;
                    if (!mainTableMapping.TryGetProperty(PropertyNames.area, out mainAreaProperty))
                    {
                        return(null);
                    }
                    propertyMappings.Add(mainAreaProperty);
                }
            }
            return(new TableMapping(queryTableName, dbTableName, tableType, propertyMappings.ToArray()));
        }
 public SystemConfigurationMissingException(ConfigurationName configurationName) : base(ProcessConfigurationName(configurationName))
 {
 }
Exemple #20
0
 private string FormatClassName(ConfigurationName name)
 {
     return(GetNamespaceName(name.Scope) + "." + name.Name);
 }
Exemple #21
0
        public BuiltQuery Build()
        {
            var resultBuilder = new StringBuilder();

            resultBuilder.Append("ВЫБРАТЬ ");
            var isCount = Count.HasValue && Count.Value;

            if (isCount)
            {
                resultBuilder.Append("КОЛИЧЕСТВО(");
            }
            if (Take.HasValue)
            {
                resultBuilder.Append("ПЕРВЫЕ ");
                resultBuilder.Append(Take.Value);
                resultBuilder.Append(" ");
            }
            string selection;

            if (isCount)
            {
                selection = "*";
            }
            else if (projection == null)
            {
                selection = ConfigurationName.Get(SourceType).HasReference ? "src.Ссылка" : "*";
            }
            else
            {
                selection = projection.GetSelection();
            }

            resultBuilder.Append(selection);
            if (isCount)
            {
                resultBuilder.Append(") КАК src_Count");
            }
            resultBuilder.Append(" ИЗ ");
            resultBuilder.Append(sourceName);
            if (TableSectionName != null)
            {
                resultBuilder.Append('.');
                resultBuilder.Append(TableSectionName);
            }
            resultBuilder.Append(" КАК src");
            if (whereParts.Count > 0)
            {
                resultBuilder.Append(" ГДЕ ");
                if (whereParts.Count == 1)
                {
                    resultBuilder.Append(whereParts[0]);
                }
                else
                {
                    resultBuilder.Append("(");
                    resultBuilder.Append(whereParts.JoinStrings(" И "));
                    resultBuilder.Append(")");
                }
            }
            if (Orderings != null)
            {
                resultBuilder.Append(" УПОРЯДОЧИТЬ ПО ");
                for (var i = 0; i < Orderings.Length; i++)
                {
                    if (i != 0)
                    {
                        resultBuilder.Append(',');
                    }
                    var ordering = Orderings[i];
                    resultBuilder.Append(ordering.Field.Expression);
                    if (!ordering.IsAsc)
                    {
                        resultBuilder.Append(" УБЫВ");
                    }
                }
            }
            return(new BuiltQuery(SourceType, resultBuilder.ToString(), parameters, projection, isCount));
        }
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ComputerName.Expression != null)
            {
                targetCommand.AddParameter("ComputerName", ComputerName.Get(context));
            }

            if (ApplicationName.Expression != null)
            {
                targetCommand.AddParameter("ApplicationName", ApplicationName.Get(context));
            }

            if (ConnectionUri.Expression != null)
            {
                targetCommand.AddParameter("ConnectionUri", ConnectionUri.Get(context));
            }

            if (ConfigurationName.Expression != null)
            {
                targetCommand.AddParameter("ConfigurationName", ConfigurationName.Get(context));
            }

            if (AllowRedirection.Expression != null)
            {
                targetCommand.AddParameter("AllowRedirection", AllowRedirection.Get(context));
            }

            if (Name.Expression != null)
            {
                targetCommand.AddParameter("Name", Name.Get(context));
            }

            if (InstanceId.Expression != null)
            {
                targetCommand.AddParameter("InstanceId", InstanceId.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (Authentication.Expression != null)
            {
                targetCommand.AddParameter("Authentication", Authentication.Get(context));
            }

            if (CertificateThumbprint.Expression != null)
            {
                targetCommand.AddParameter("CertificateThumbprint", CertificateThumbprint.Get(context));
            }

            if (Port.Expression != null)
            {
                targetCommand.AddParameter("Port", Port.Get(context));
            }

            if (UseSSL.Expression != null)
            {
                targetCommand.AddParameter("UseSSL", UseSSL.Get(context));
            }

            if (ThrottleLimit.Expression != null)
            {
                targetCommand.AddParameter("ThrottleLimit", ThrottleLimit.Get(context));
            }

            if (State.Expression != null)
            {
                targetCommand.AddParameter("State", State.Get(context));
            }

            if (SessionOption.Expression != null)
            {
                targetCommand.AddParameter("SessionOption", SessionOption.Get(context));
            }

            if (PSSessionId.Expression != null)
            {
                targetCommand.AddParameter("Id", PSSessionId.Get(context));
            }

            if (ContainerId.Expression != null)
            {
                targetCommand.AddParameter("ContainerId", ContainerId.Get(context));
            }

            if (VMId.Expression != null)
            {
                targetCommand.AddParameter("VMId", VMId.Get(context));
            }

            if (VMName.Expression != null)
            {
                targetCommand.AddParameter("VMName", VMName.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Exemple #23
0
        protected override Expression VisitConstant(ConstantExpression node)
        {
            var value     = node.Value;
            var type      = node.Type;
            var comparand = binaryExpressionMappings.GetOrDefault(node);

            if (comparand != null)
            {
                if (type == typeof(object) && comparand.Type != typeof(object))
                {
                    type = comparand.Type;
                }
                if (comparand.NodeType == ExpressionType.Convert)
                {
                    type = ((UnaryExpression)comparand).Operand.Type;
                }
            }
            type = Nullable.GetUnderlyingType(type) ?? type;
            if (value == null)
            {
                var name = ConfigurationName.GetOrNull(type);
                if (name == null)
                {
                    filterBuilder.Append("NULL");
                }
                else
                {
                    filterBuilder.AppendFormat("ЗНАЧЕНИЕ({0}.ПустаяСсылка)", name.Value.Fullname);
                }
            }
            else if (value.GetType().FullName == "System.RuntimeType")
            {
                var valueType = (Type)value;
                filterBuilder.Append("ТИП(");
                filterBuilder.Append(Get1CTypeName(valueType));
                filterBuilder.Append(")");
            }
            else
            {
                var xMember = comparand as MemberExpression;
                if (value is Guid && xMember != null && xMember.Member.Name == EntityHelpers.idPropertyName)
                {
                    value = new ConvertUniqueIdentifierCmd
                    {
                        entityType =
                            xMember.Member.DeclaringType == queryBuilder.QueryType
                                ? queryBuilder.SourceType
                                : xMember.Member.DeclaringType,
                        id = (Guid)value
                    }
                }
                ;
                else if (type.IsEnum)
                {
                    value = new ConvertEnumCmd {
                        enumType = type, valueIndex = (int)value
                    }
                }
                ;
                else if (value is Abstract1CEntity)
                {
                    value = ((Abstract1CEntity)value).Controller.ValueSource.GetBackingStorage();
                }
                var parameterName = queryBuilder.AddParameter(value);
                filterBuilder.Append('&');
                filterBuilder.Append(parameterName);
            }
            return(node);
        }
Exemple #24
0
        public static string Представление(object obj)
        {
            //TODO NullabeTypes
            if (obj == null)
            {
                return("");
            }
            var objType        = obj.GetType();
            var underlyingType = Nullable.GetUnderlyingType(objType);

            if (underlyingType != null)
            {
                return(Представление(GetPropertyValue <object>(objType, "Value", obj)));
            }
            var stringObj = obj as string;

            if (stringObj != null)
            {
                return(stringObj);
            }
            var typeObj = obj as Type;

            if (typeObj != null)
            {
                return(GetTypePresentation(typeObj));
            }
            if (objType.IsClass)
            {
                var configurationName = ConfigurationName.Get(objType);
                if (configurationName.Scope == ConfigurationScope.Справочники)
                {
                    return(GetPropertyValue <string>(objType, "Наименование", obj) ?? "");
                }
                if (configurationName.Scope == ConfigurationScope.Документы)
                {
                    var builder = new StringBuilder();
                    builder.Append(Synonym.OfClass(obj));
                    var number = GetPropertyValue <string>(objType, "Номер", obj);
                    if (!string.IsNullOrEmpty(number))
                    {
                        builder.Append(" ");
                        builder.Append(number);
                    }
                    var date = GetPropertyValue <DateTime?>(objType, "Дата", obj);
                    if (date.HasValue)
                    {
                        builder.Append(" от ");
                        builder.Append(date.Value.ToString("dd.MM.yyyy H:mm:ss"));
                    }
                    return(builder.ToString());
                }
                if (configurationName.Scope == ConfigurationScope.ПланыСчетов)
                {
                    return(GetPropertyValue <string>(objType, "Код", obj) ?? "");
                }
            }
            if (objType.IsEnum)
            {
                return(Synonym.OfEnumUnsafe(obj));
            }
            if (obj is int)
            {
                return(((int)obj).ToString(russianCultureInfo));
            }
            if (obj is long)
            {
                return(((long)obj).ToString(russianCultureInfo));
            }
            if (obj is decimal)
            {
                return(((decimal)obj).ToString(russianCultureInfo));
            }
            if (obj is bool)
            {
                return((bool)obj ? "Да" : "Нет");
            }
            if (obj is DateTime)
            {
                return(((DateTime)obj).ToString("dd.MM.yyyy H:mm:ss"));
            }
            if (obj is Guid)
            {
                return(((Guid)obj).ToString());
            }
            if (obj is byte)
            {
                return(((byte)obj).ToString(russianCultureInfo));
            }
            if (obj is sbyte)
            {
                return(((sbyte)obj).ToString(russianCultureInfo));
            }
            if (obj is short)
            {
                return(((short)obj).ToString(russianCultureInfo));
            }
            if (obj is ushort)
            {
                return(((ushort)obj).ToString(russianCultureInfo));
            }
            if (obj is uint)
            {
                return(((uint)obj).ToString(russianCultureInfo));
            }
            if (obj is ulong)
            {
                return(((ulong)obj).ToString(russianCultureInfo));
            }
            if (obj is float)
            {
                return(((float)obj).ToString(russianCultureInfo));
            }
            if (obj is double)
            {
                return(((double)obj).ToString(russianCultureInfo));
            }
            const string messageFormat = "can't get ПРЕДСТАВЛЕНИЕ for object [{0}] of type [{1}]";

            throw new NotSupportedException(string.Format(messageFormat, obj, objType.FormatName()));
        }
Exemple #25
0
 public ConfigurationItem(ConfigurationName name, object comObject)
 {
     Name      = name;
     ComObject = comObject;
 }
Exemple #26
0
 /// <summary>
 /// 扩展项目类,提供修改项目配置的方法(configName的列表参考模型目录下的ProjectProperties.txt)
 /// </summary>
 /// <param name="prj"></param>
 /// <param name="configName">ProjectConfigurationManagerProperties的名称</param>
 /// <param name="configValue">设置的值</param>
 /// <param name="configurationName"></param>
 public static void SetProjectConfig(this Project prj, string configName, string configValue, ConfigurationName configurationName = ConfigurationName.Debug)
 {
     try
     {
         if (null == prj)
         {
             return;
         }
         foreach (Configuration config in prj.ConfigurationManager)
         {
             if (config.ConfigurationName == configurationName.ToString())
             {
                 config.Properties.Item(configName).Value = configValue;
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Validates that all required parameters have been set and are valid values.
        /// Throws a <see cref="GeneratorParameterException"/> exception for invalid values.
        /// </summary>
        public void Validate()
        {
            if (string.IsNullOrEmpty(ItemNamespace))
            {
                throw new GeneratorParameterException("ItemNamespace was not provided.");
            }

            if (string.IsNullOrEmpty(InterfaceNamespace))
            {
                throw new GeneratorParameterException("InterfaceNamespace was not provided.");
            }

            if (InterfaceSuffix == null)
            {
                throw new GeneratorParameterException("InterfaceSuffix was not provided.");
            }

            if (string.IsNullOrEmpty(ItemOutputPath))
            {
                throw new GeneratorParameterException("ItemOutputPath was not provided.");
            }

            if (!ItemOutputPath.EndsWith(".cs"))
            {
                throw new GeneratorParameterException("ItemOutputPath was not a C# file (.cs)");
            }

            if (string.IsNullOrEmpty(InterfaceOutputPath))
            {
                throw new GeneratorParameterException("InterfaceOutputPath was not provided.");
            }

            if (!InterfaceOutputPath.EndsWith(".cs"))
            {
                throw new GeneratorParameterException("InterfaceOutputPath was not a C# file (.cs)");
            }

            if (string.IsNullOrEmpty(SitecoreKernelAssemblyPath) || !File.Exists(SitecoreKernelAssemblyPath))
            {
                throw new GeneratorParameterException("SitecoreKernelAssemblyPath was not provided, or did not exist at the specified path.");
            }

            if (string.IsNullOrEmpty(SynthesisAssemblyPath) || !File.Exists(SynthesisAssemblyPath))
            {
                throw new GeneratorParameterException("SynthesisAssemblyPath was not provided, or did not exist at the specified path.");
            }

            if (ItemBaseClass == null)
            {
                throw new GeneratorParameterException("ItemBaseClass was not provided.");
            }

            if (!typeof(StandardTemplateItem).IsAssignableFrom(ItemBaseClass))
            {
                throw new GeneratorParameterException("ItemBaseClass " + ItemBaseClass.FullName + " did not derive from Synthesis.StandardTemplateItem.");
            }

            if (ItemBaseInterface == null)
            {
                throw new GeneratorParameterException("ItemBaseInterface was not provided.");
            }

            if (!typeof(IStandardTemplateItem).IsAssignableFrom(ItemBaseInterface))
            {
                throw new GeneratorParameterException("ItemBaseInterface " + ItemBaseInterface.FullName + " did not derive from Synthesis.IStandardTemplateItem.");
            }

            if (!ItemBaseInterface.IsAssignableFrom(ItemBaseClass))
            {
                throw new GeneratorParameterException(string.Format("ItemBaseClass {0} did not implement ItemBaseInterface {1}", ItemBaseClass.FullName, ItemBaseInterface.FullName));
            }

            if (ConfigurationName.IsNullOrEmpty())
            {
                throw new GeneratorParameterException("The configuration name was null or empty.");
            }
        }
 public override int GetHashCode()
 {
     return(ConfigurationName.GetHashCode());
 }