Esempio n. 1
0
        /// <summary>
        ///     Gets the field type parser.
        /// </summary>
        /// <param name="fieldType">Type of the field.</param>
        /// <returns></returns>
        private static Func <string, object> GetFieldTypeParser(Entity fieldType)
        {
            // Note: can't use entity model during bootstrap

            switch (fieldType.Alias.Value)
            {
            case "aliasField":
            case "stringField":
            case "emailField":
            case "uriField":
            case "phoneField":
            case "xmlField":
                return(s => ( object )s);

            case "dateField":
                // No UTC adjustment
                return(s => ( object )DateTime.Parse(s, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal));

            case "timeField":
                // No UTC adjustment
                return(s => ( object )DateTime.Parse(s, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal));

            case "dateTimeField":
                // yyyy-mm-ddTHH:MM:SS to specify input as local time, or use yyyy-mm-ddTHH:MM:SSZ to specify input at UTC.
                return(s => ( object )DateTime.Parse(s, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal | DateTimeStyles.AdjustToUniversal));

            case "intField":
                return(s => ( object )int.Parse(s));

            case "boolField":
                return(s => ( object )bool.Parse(s));

            case "guidField":
                return(s => ( object )Guid.Parse(s));

            case "decimalField":
            case "percentField":
            case "currencyField":
                return(s => ( object )decimal.Parse(s));

            default:
                string fieldName = fieldType.Alias.Value;
                return(s =>
                {
                    throw new Exception("No bootstrap field parser defined for field type: " + fieldName);
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Gets the member value.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="nameSpace">The name space.</param>
        /// <param name="alias">The alias.</param>
        /// <returns></returns>
        private string GetMemberValue(Entity entity, string nameSpace, string alias)
        {
            /////
            // Return the default value if any of the input arguments are incorrect.
            /////
            if (entity != null && !string.IsNullOrEmpty(nameSpace) && !string.IsNullOrEmpty(alias))
            {
                Member member = entity.Members.FirstOrDefault(m => m.MemberDefinition.Alias.Namespace == nameSpace && m.MemberDefinition.Alias.Value == alias);

                if (member != null)
                {
                    return(member.Value);
                }
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        ///     Sets the solution version.
        /// </summary>
        /// <param name="version">The version.</param>
        public void SetSolutionVersions(string version)
        {
            if (string.IsNullOrEmpty(version) || AvailableSolutions == null || !AvailableSolutions.Any( ))
            {
                return;
            }

            foreach (string solutionAlias in AvailableSolutions)
            {
                Entity solution = Entities.FirstOrDefault(e => e.Alias.Value == solutionAlias && e.Type.Alias.Namespace == "core" && e.Type.Alias.Value == "solution");

                Member solutionVersionString = solution?.Members.FirstOrDefault(m => m.MemberDefinition.Alias.Namespace == "core" && m.MemberDefinition.Alias.Value == "solutionVersionString");

                if (solutionVersionString != null)
                {
                    solutionVersionString.Value = version;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        ///     Gets the fields with defaults.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        private IEnumerable <FieldData> GetFieldsWithDefaults(Entity type)
        {
            List <FieldData> result;

            if (!_defaultsOnType.TryGetValue(type, out result))
            {
                Alias defaultValueAlias = Aliases.CoreAlias("defaultValue");

                result =
                    (from ancType in SchemaResolver.GetAncestors(type)
                     from field in SchemaResolver.GetDeclaredFields(ancType)
                     let defaultValue = SchemaResolver.GetStringFieldValue(field, defaultValueAlias)
                                        where defaultValue != null
                                        select new FieldData
                {
                    Field = field,
                    Value = defaultValue
                }).ToList( );

                _defaultsOnType[type] = result;
            }
            return(result);
        }
Esempio n. 5
0
        /// <summary>
        ///     Loads the application metadata.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Metadata GetMetadata(IProcessingContext context)
        {
            Entity solutionEntity = GetActiveSolutionEntity( );

            string   name         = null;
            string   description  = null;
            string   publisher    = null;
            string   publisherUrl = null;
            Guid     appId        = Guid.Empty;
            DateTime releaseDate  = DateTime.UtcNow;
            string   version      = null;

            if (solutionEntity != null)
            {
                /////
                // Get the member values.
                /////
                name         = GetMemberValue(solutionEntity, "core", "name");
                description  = GetMemberValue(solutionEntity, "core", "description");
                publisher    = GetMemberValue(solutionEntity, "core", "solutionPublisher");
                publisherUrl = GetMemberValue(solutionEntity, "core", "solutionPublisherUrl");
                version      = GetMemberValue(solutionEntity, "core", "solutionVersionString");

                string releaseDateString = GetMemberValue(solutionEntity, "core", "solutionReleaseDate");

                if (!string.IsNullOrEmpty(releaseDateString))
                {
                    releaseDate = DateTime.Parse(releaseDateString);
                }

                appId = solutionEntity.Guid;
            }

            /////
            // Calculate the fallback values.
            /////
            if (string.IsNullOrEmpty(name))
            {
                name = SolutionDocument.ReadString("/resource/name");
            }

            if (appId == Guid.Empty)
            {
                appId = SolutionDocument.ReadGuid("/resource/solutionId");
            }

            if (string.IsNullOrEmpty(version))
            {
                version = SolutionDocument.ReadString("/resource/version", "1.0");
            }

            Guid dependentApplicationGuid  = new Guid("{8f2ed791-a613-4e9c-a6d4-694a8c56dba1}");
            Guid dependencyApplicationGuid = new Guid("{d7fe48a6-3ad9-494d-8740-086f432aaaa4}");
            Guid nameGuid               = new Guid("{f8def406-90a1-4580-94f4-1b08beac87af}");
            Guid minimumVersionGuid     = new Guid("{f2c90c9e-92a0-4461-a49c-ee601776f468}");
            Guid maximumVersionnameGuid = new Guid("{f00f048e-6aab-479e-9981-19a7506c20db}");
            Guid isRequiredGuid         = new Guid("{1f7dd780-a123-4ec6-9722-5189d107eb8f}");

            List <SolutionDependency> dependencies = new List <SolutionDependency>( );

            List <Relationship> dependentRelationships = Relationships.Where(r => r.SolutionEntity.Guid == appId && r.Type.Guid == dependentApplicationGuid && r.To.Guid == appId).ToList( );

            foreach (Relationship relationship in dependentRelationships)
            {
                List <Relationship> dependencyRelationships = Relationships.Where(r => r.SolutionEntity.Guid == appId && r.Type.Guid == dependencyApplicationGuid && r.From.Guid == relationship.From.Guid).ToList( );

                foreach (Relationship dependencyRelationship in dependencyRelationships)
                {
                    Entity details = Entities.FirstOrDefault(e => e.Guid == dependencyRelationship.From.Guid);

                    Member nameMember           = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == nameGuid);
                    Member minimumVersionMember = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == minimumVersionGuid);
                    Member maximumVersionMember = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == maximumVersionnameGuid);
                    Member isRequiredMember     = details.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == isRequiredGuid);

                    Entity dependencyApplication = Entities.FirstOrDefault(e => e.Guid == dependencyRelationship.To.Guid);

                    Member dependencyNameMember = null;

                    if (dependencyApplication != null)
                    {
                        dependencyNameMember = dependencyApplication.Members.FirstOrDefault(m => m.MemberDefinition.Entity.Guid == nameGuid);
                    }

                    Version minVersion;

                    if (string.IsNullOrEmpty(minimumVersionMember?.Value) || minimumVersionMember.Value.Equals("any", StringComparison.InvariantCultureIgnoreCase) || !Version.TryParse(minimumVersionMember.Value, out minVersion))
                    {
                        minVersion = null;
                    }

                    Version maxVersion;

                    if (string.IsNullOrEmpty(maximumVersionMember?.Value) || maximumVersionMember.Value.Equals("any", StringComparison.InvariantCultureIgnoreCase) || !Version.TryParse(maximumVersionMember.Value, out maxVersion))
                    {
                        maxVersion = null;
                    }

                    bool required;

                    if (string.IsNullOrEmpty(isRequiredMember?.Value) || !bool.TryParse(isRequiredMember.Value, out required))
                    {
                        required = true;
                    }

                    SolutionDependency dependency = new SolutionDependency(dependencyRelationship.To.Guid, nameMember?.Value, dependencyNameMember?.Value, minVersion, maxVersion, required);

                    dependencies.Add(dependency);
                }
            }

            _packageId = GenerateAppVerId(name, version);

            /////
            // Return the metadata.
            /////
            return(new Metadata
            {
                AppId = appId,
                AppName = name,
                AppVerId = _packageId,
                Description = description,
                Dependencies = dependencies,
                Name = name,
                Publisher = publisher,
                PublisherUrl = publisherUrl,
                ReleaseDate = releaseDate,
                Version = version,
                Type = SourceType.AppPackage,
                PlatformVersion = null
            });
        }
Esempio n. 6
0
        /// <summary>
        ///     Expands the binary source.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="entity">The entity.</param>
        private List <KeyValuePair <string, object> > ExpandBinarySource(XElement element, Entity entity)
        {
            if (element == null || entity == null)
            {
                return(null);
            }

            XAttribute sourceAttribute = element.Attribute("source");

            if (sourceAttribute != null)
            {
                try
                {
                    // Find the entity source formatter for this alias
                    string typeName = string.Format(CultureInfo.InvariantCulture, "EDC.SoftwarePlatform.Migration.SourceFormatters.{0}SourceFormatter", entity.Type.Alias.Value.ToPascalCase( ));
                    Type   type     = Type.GetType(typeName, false);

                    if (type != null)
                    {
                        object instance = Activator.CreateInstance(type);

                        var results = new List <KeyValuePair <string, object> >( );

                        var typeFormatter = instance as IEntityContainerSourceFormatter;

                        if (typeFormatter != null)
                        {
                            string referencePath = Path.GetDirectoryName(element.BaseUri);

                            if (referencePath != null)
                            {
                                var uri = new Uri(Path.Combine(referencePath, sourceAttribute.Value));

                                results.AddRange(typeFormatter.Format(Path.GetFullPath(uri.AbsolutePath)));
                            }
                        }

                        return(results);
                    }
                }
                catch (Exception exc)
                {
                    EventLog.Application.WriteError("Failed to expand binary source. " + exc.Message);
                }
            }

            return(null);
        }