public void PublishNewVersion(ModuleManifest manifest)
        {
            var version = ExternalModuleManifestVersion.FromManifest(manifest);

            Versions.Add(version);
            var byPlatformMajorGroups = Versions.GroupBy(x => x.PlatformSemanticVersion.Major).OrderByDescending(x => x.Key).ToList();

            Versions.Clear();
            foreach (var byPlatformGroup in byPlatformMajorGroups)
            {
                var latestReleaseVersion = byPlatformGroup.Where(x => string.IsNullOrEmpty(x.VersionTag))
                                           .OrderByDescending(x => x.SemanticVersion).FirstOrDefault();
                if (latestReleaseVersion != null)
                {
                    Versions.Add(latestReleaseVersion);
                }

                var latestPreReleaseVersion = byPlatformGroup.Where(x => !string.IsNullOrEmpty(x.VersionTag))
                                              .OrderByDescending(x => x.SemanticVersion)
                                              .ThenByDescending(x => x.VersionTag).FirstOrDefault();

                var addPreRelease = latestPreReleaseVersion != null;
                if (addPreRelease)
                {
                    addPreRelease = latestReleaseVersion == null || (!latestPreReleaseVersion.SemanticVersion.Equals(latestReleaseVersion.SemanticVersion) &&
                                                                     latestReleaseVersion.SemanticVersion.IsCompatibleWithBySemVer(latestPreReleaseVersion.SemanticVersion));
                }
                if (addPreRelease)
                {
                    Versions.Add(latestPreReleaseVersion);
                }
            }
        }
        public ManifestModuleInfo(ModuleManifest manifest)
            : base(manifest.Id, manifest.ModuleType, (manifest.Dependencies ?? new ManifestDependency[0]).Select(d => d.Id).ToArray())
        {
            Id                       = manifest.Id;
            Version                  = new SemanticVersion(new System.Version(manifest.Version));
            PlatformVersion          = new SemanticVersion(new System.Version(manifest.PlatformVersion));
            Title                    = manifest.Title;
            Description              = manifest.Description;
            Authors                  = manifest.Authors;
            Owners                   = manifest.Owners;
            LicenseUrl               = manifest.LicenseUrl;
            ProjectUrl               = manifest.ProjectUrl;
            IconUrl                  = manifest.IconUrl;
            RequireLicenseAcceptance = manifest.RequireLicenseAcceptance;
            ReleaseNotes             = manifest.ReleaseNotes;
            Copyright                = manifest.Copyright;
            Tags                     = manifest.Tags;
            UseFullTypeNameInSwagger = manifest.UseFullTypeNameInSwagger;

            Ref      = manifest.PackageUrl;
            Identity = new ModuleIdentity(Id, Version);

            Errors = new List <string>();


            Dependencies = new List <ModuleIdentity>();
            if (manifest.Dependencies != null)
            {
                Dependencies.AddRange(manifest.Dependencies.Select(x => new ModuleIdentity(x.Id, x.Version)));
            }
            Styles = new List <ManifestBundleItem>();
            if (manifest.Styles != null)
            {
                Styles.AddRange(manifest.Styles);
            }
            Scripts = new List <ManifestBundleItem>();
            if (manifest.Scripts != null)
            {
                Scripts.AddRange(manifest.Scripts);
            }
            Permissions = new List <ModulePermissionGroup>();
            if (manifest.Permissions != null)
            {
                Permissions.AddRange(manifest.Permissions);
            }
            Settings = new List <ModuleSettingsGroup>();
            if (manifest.Settings != null)
            {
                Settings.AddRange(manifest.Settings);
            }
            Groups = new List <string>();
            if (manifest.Groups != null)
            {
                Groups.AddRange(manifest.Groups);
            }
            InitializationMode = InitializationMode.OnDemand;
        }
        public ManifestModuleInfo(ModuleManifest manifest)
            : base(manifest.Id, manifest.ModuleType, (manifest.Dependencies ?? new ManifestDependency[0]).Select(d => d.Id).ToArray())
        {
            Id = manifest.Id;
            Version = new SemanticVersion(new System.Version(manifest.Version));
            PlatformVersion = new SemanticVersion(new System.Version(manifest.PlatformVersion));
            Title = manifest.Title;
            Description = manifest.Description;
            Authors = manifest.Authors;
            Owners = manifest.Owners;
            LicenseUrl = manifest.LicenseUrl;
            ProjectUrl = manifest.ProjectUrl;
            IconUrl = manifest.IconUrl;
            RequireLicenseAcceptance = manifest.RequireLicenseAcceptance;
            ReleaseNotes = manifest.ReleaseNotes;
            Copyright = manifest.Copyright;
            Tags = manifest.Tags;
            UseFullTypeNameInSwagger = manifest.UseFullTypeNameInSwagger;

            Ref = manifest.PackageUrl;
            Identity = new ModuleIdentity(Id, Version);

            Errors = new List<string>();

            Dependencies = new List<ModuleIdentity>();
            if (manifest.Dependencies != null)
            {
                Dependencies.AddRange(manifest.Dependencies.Select(x => new ModuleIdentity(x.Id, x.Version)));
            }
            Styles = new List<ManifestBundleItem>();
            if (manifest.Styles != null)
            {
                Styles.AddRange(manifest.Styles);
            }
            Scripts = new List<ManifestBundleItem>();
            if (manifest.Scripts != null)
            {
                Scripts.AddRange(manifest.Scripts);
            }
            Permissions = new List<ModulePermissionGroup>();
            if (manifest.Permissions != null)
            {
                Permissions.AddRange(manifest.Permissions);
            }
            Settings = new List<ModuleSettingsGroup>();
            if (manifest.Settings != null)
            {
                Settings.AddRange(manifest.Settings);
            }
            Groups = new List<string>();
            if (manifest.Groups != null)
            {
                Groups.AddRange(manifest.Groups);
            }
            InitializationMode = InitializationMode.OnDemand;
        }
        public static ModuleManifest Read(string filePath)
        {
            ModuleManifest retVal = null;

            using (var stream = File.OpenRead(filePath))
            {
                retVal = Read(stream);
            }
            return(retVal);
        }
        public virtual ManifestModuleInfo LoadFromManifest(ModuleManifest manifest)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException(nameof(manifest));
            }

            ModuleName = manifest.Id;

            if (manifest.Dependencies != null)
            {
                foreach (var dependency in manifest.Dependencies)
                {
                    DependsOn.Add(dependency.Id);
                }
            }

            Id              = manifest.Id;
            Version         = SemanticVersion.Parse(string.Join("-", new[] { manifest.Version, manifest.VersionTag }).TrimEnd('-'));
            VersionTag      = manifest.VersionTag;
            PlatformVersion = SemanticVersion.Parse(manifest.PlatformVersion);
            ReleaseNotes    = manifest.ReleaseNotes;
            Ref             = manifest.PackageUrl;
            if (manifest.Dependencies != null)
            {
                Dependencies.AddRange(manifest.Dependencies.Select(x => new ModuleIdentity(x.Id, SemanticVersion.Parse(x.Version))));
            }
            if (manifest.Incompatibilities != null)
            {
                Incompatibilities.AddRange(manifest.Incompatibilities.Select(x => new ModuleIdentity(x.Id, SemanticVersion.Parse(x.Version))));
            }

            Title       = manifest.Title;
            Description = manifest.Description;
            Authors     = manifest.Authors;
            Owners      = manifest.Owners;
            LicenseUrl  = manifest.LicenseUrl;
            ProjectUrl  = manifest.ProjectUrl;
            IconUrl     = manifest.IconUrl;
            RequireLicenseAcceptance = manifest.RequireLicenseAcceptance;
            Copyright = manifest.Copyright;
            Tags      = manifest.Tags;
            Identity  = new ModuleIdentity(Id, Version);
            if (manifest.Groups != null)
            {
                Groups.AddRange(manifest.Groups);
            }
            return(this);
        }
Exemple #6
0
        public static ExternalModuleManifestVersion FromManifest(ModuleManifest manifest)
        {
            var result = new ExternalModuleManifestVersion
            {
                Dependencies      = manifest.Dependencies,
                Incompatibilities = manifest.Incompatibilities,
                PackageUrl        = manifest.PackageUrl,
                PlatformVersion   = manifest.PlatformVersion,
                ReleaseNotes      = manifest.ReleaseNotes,
                Version           = manifest.Version,
                VersionTag        = manifest.VersionTag
            };

            return(result);
        }
        public ManifestModuleInfo(ModuleManifest manifest, string fullPhysicalPath)
            : base(manifest.Id, manifest.ModuleType, (manifest.Dependencies ?? new ManifestDependency[0]).Select(d => d.Id).ToArray())
        {
            InitializationMode = InitializationMode.OnDemand;
            FullPhysicalPath = fullPhysicalPath;

            Styles = new List<ManifestBundleItem>();
            Scripts = new List<ManifestBundleItem>();

            if (manifest.Styles != null)
                manifest.Styles.ForEach(s => Styles.Add(s));

            if (manifest.Scripts != null)
                manifest.Scripts.ForEach(s => Scripts.Add(s));
        }
Exemple #8
0
        public ManifestModuleInfo(ModuleManifest manifest, string fullPhysicalPath)
            : base(manifest.Id, manifest.ModuleType, (manifest.Dependencies ?? new ManifestDependency[0]).Select(d => d.Id).ToArray())
        {
            InitializationMode = InitializationMode.OnDemand;
            FullPhysicalPath   = fullPhysicalPath;

            Styles  = new List <ManifestBundleItem>();
            Scripts = new List <ManifestBundleItem>();

            if (manifest.Styles != null)
            {
                manifest.Styles.ForEach(s => Styles.Add(s));
            }

            if (manifest.Scripts != null)
            {
                manifest.Scripts.ForEach(s => Scripts.Add(s));
            }
        }
        public static ExternalModuleManifest FromManifest(ModuleManifest manifest)
        {
            var result = new ExternalModuleManifest
            {
                Title       = manifest.Title,
                Description = manifest.Description,
                Authors     = manifest.Authors,
                Copyright   = manifest.Copyright,
                Groups      = manifest.Groups,
                IconUrl     = manifest.IconUrl,
                Id          = manifest.Id,
                LicenseUrl  = manifest.LicenseUrl,
                Owners      = manifest.Owners,
                ProjectUrl  = manifest.ProjectUrl,
                RequireLicenseAcceptance = manifest.RequireLicenseAcceptance,
                Tags = manifest.Tags
            };

            result.Versions.Add(ExternalModuleManifestVersion.FromManifest(manifest));
            return(result);
        }
        private static ModuleDescriptor ConvertToModuleDescriptor(ModuleManifest manifest, List<string> installedPackages = null)
        {
            ModuleDescriptor result = null;

            if (manifest != null)
            {
                result = new ModuleDescriptor
                {
                    Id = manifest.Id,
                    Version = manifest.Version,
                    PlatformVersion = manifest.PlatformVersion,
                    Title = manifest.Title,
                    Description = manifest.Description,
                    Authors = manifest.Authors,
                    Owners = manifest.Owners,
                    RequireLicenseAcceptance = manifest.RequireLicenseAcceptance,
                    ReleaseNotes = manifest.ReleaseNotes,
                    Copyright = manifest.Copyright,
                    Tags = manifest.Tags,
                };

                if (manifest.Dependencies != null)
                    result.Dependencies = manifest.Dependencies.Select(d => new ModuleIdentity { Id = d.Id, Version = d.Version });

                if (manifest.LicenseUrl != null)
                    result.LicenseUrl = new Uri(manifest.LicenseUrl);

                if (manifest.ProjectUrl != null)
                    result.ProjectUrl = new Uri(manifest.ProjectUrl);

                if (manifest.IconUrl != null)
                    result.IconUrl = new Uri(manifest.IconUrl);

                if (installedPackages != null && installedPackages.Any())
                {
                    var packageFileName = GetPackageFileName(manifest.Id, manifest.Version);
                    result.IsRemovable = installedPackages.Contains(packageFileName, StringComparer.OrdinalIgnoreCase);
                }
            }

            return result;
        }
        /// <summary>
        /// Publish given module to AppStore catalog
        /// </summary>
        private PublishingResult Publish(ModuleManifest manifest, string zipModulePath, byte[] icon)
        {
            var publishingResult = PublishingResult.None;
            var productCode = manifest.Id;

            productCode = Regex.Replace(productCode, @"[^A-Za-z0-9_]", "_");
            var product = GetProductByCode(productCode, _defaultCategory.Catalog.Id);

            if (product == null)
            {
                //add product
                product = new CatalogProduct
                {
                    Name = manifest.Title,
                    Code = productCode,
                    CategoryId = _defaultCategory.Id,
                    CatalogId = _defaultCategory.CatalogId,
                    IsActive = false,
                    IsBuyable = false
                };

                if (!string.IsNullOrEmpty(manifest.Description))
                {
                    AddProperty(product, "Description", manifest.Description, PropertyValueType.LongText);
                }

                if (!string.IsNullOrEmpty(manifest.IconUrl))
                {
                    AddIcon(product, Path.GetExtension(manifest.IconUrl), icon);
                }

                product = _productService.Create(product);
                publishingResult = PublishingResult.Product;
            }
            return AddVariation(product, manifest, icon, zipModulePath, publishingResult);
        }
        /// <summary>
        /// Add variation to given product + asset + icon + properties
        /// </summary>
        private PublishingResult AddVariation(CatalogProduct product, ModuleManifest manifest, byte[] icon, string zipModulePath, PublishingResult publishingResult)
        {
            //add variation + asset
            var variationCode = string.Format("{0}_{1}", manifest.Id, manifest.Version);
            variationCode = Regex.Replace(variationCode, @"[^A-Za-z0-9_]", "_");
            var variation = product.Variations.Where(x=>x.Code == variationCode).FirstOrDefault();

            if (variation == null)
            {
                variation = new CatalogProduct
                {
                    Name = string.Format("{0} ({1})", manifest.Title, manifest.Version),
                    Code = variationCode,
                    MainProductId = product.Id,
                    CategoryId = product.CategoryId,
                    CatalogId = product.CatalogId,
                };

                AddProperty(variation, "Description", manifest.Description, PropertyValueType.LongText);
                AddProperty(variation, "ReleaseNote", manifest.ReleaseNotes, PropertyValueType.LongText);
                AddProperty(variation, "ReleaseVersion", manifest.Version, PropertyValueType.ShortText);
                AddProperty(variation, "Compatibility", manifest.PlatformVersion, PropertyValueType.ShortText);
                AddProperty(variation, "ReleaseDate", DateTime.UtcNow, PropertyValueType.DateTime);

                AddAsset(variation, zipModulePath);

                if (publishingResult == PublishingResult.None)
                {
                    AddIcon(variation, Path.GetExtension(manifest.IconUrl), icon);
                    publishingResult = PublishingResult.Variation;
                }

                _productService.Create(variation);
            }
            return publishingResult;
        }
Exemple #13
0
        private static void InitializePlatform(IAppBuilder app, IUnityContainer container, string connectionStringName, HangfireLauncher hangfireLauncher, string modulesPath)
        {
            container.RegisterType<ICurrentUser, CurrentUser>(new HttpContextLifetimeManager());
            container.RegisterType<IUserNameResolver, UserNameResolver>();

            #region Setup database

            using (var db = new SecurityDbContext(connectionStringName))
            {
                new IdentityDatabaseInitializer().InitializeDatabase(db);
            }

            using (var context = new PlatformRepository(connectionStringName, container.Resolve<AuditableInterceptor>(), new EntityPrimaryKeyGeneratorInterceptor()))
            {
                new PlatformDatabaseInitializer().InitializeDatabase(context);
            }

            hangfireLauncher.ConfigureDatabase();

            #endregion

            Func<IPlatformRepository> platformRepositoryFactory = () => new PlatformRepository(connectionStringName, container.Resolve<AuditableInterceptor>(), new EntityPrimaryKeyGeneratorInterceptor());
            container.RegisterType<IPlatformRepository>(new InjectionFactory(c => platformRepositoryFactory()));
            container.RegisterInstance(platformRepositoryFactory);
            var moduleCatalog = container.Resolve<IModuleCatalog>();

            #region Caching
            var cacheManager = CacheFactory.Build("platformCache", settings =>
            {
                //Should be aware to using Web cache cache handle because it not worked in native threads. (Hangfire jobs)
                settings
                    .WithUpdateMode(CacheUpdateMode.Up)
                    .WithSystemRuntimeCacheHandle("memCacheHandle")
                        .WithExpiration(ExpirationMode.Absolute, TimeSpan.FromDays(1));
            });
            container.RegisterInstance(cacheManager);
            #endregion

            #region Settings

            var platformModuleManifest = new ModuleManifest
            {
                Id = "VirtoCommerce.Platform",
                Version = PlatformVersion.CurrentVersion.ToString(),
                PlatformVersion = PlatformVersion.CurrentVersion.ToString(),
                Settings = new[]
                {
                    new ModuleSettingsGroup
                    {
                        Name = "Platform|Notifications|SendGrid",
                        Settings = new []
                        {
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Notifications.SendGrid.UserName",
                                ValueType = ModuleSetting.TypeString,
                                Title = "SendGrid UserName",
                                Description = "Your SendGrid account username"
                            },
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Notifications.SendGrid.Secret",
                                ValueType = ModuleSetting.TypeString,
                                Title = "SendGrid Password",
                                Description = "Your SendGrid account password"
                            }
                        }
                    },
                    new ModuleSettingsGroup
                    {
                        Name = "Platform|Notifications|SendingJob",
                        Settings = new []
                        {
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Notifications.SendingJob.TakeCount",
                                ValueType = ModuleSetting.TypeInteger,
                                Title = "Job Take Count",
                                Description = "Take count for sending job"
                            }
                        }
                    },
                    new ModuleSettingsGroup
                    {
                        Name = "Platform|Notifications|SmtpClient",
                        Settings = new []
                        {
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Notifications.SmptClient.Host",
                                ValueType = ModuleSetting.TypeString,
                                Title = "Smtp server host",
                                Description = "Smtp server host"
                            },
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Notifications.SmptClient.Port",
                                ValueType = ModuleSetting.TypeInteger,
                                Title = "Smtp server port",
                                Description = "Smtp server port"
                            },
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Notifications.SmptClient.Login",
                                ValueType = ModuleSetting.TypeString,
                                Title = "Smtp server login",
                                Description = "Smtp server login"
                            },
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Notifications.SmptClient.Password",
                                ValueType = ModuleSetting.TypeString,
                                Title = "Smtp server password",
                                Description = "Smtp server password"
                            }
                        }
                    },
                    new ModuleSettingsGroup
                    {
                        Name = "Platform|Security",
                        Settings = new []
                        {
                            new ModuleSetting
                            {
                                Name = "VirtoCommerce.Platform.Security.AccountTypes",
                                ValueType = ModuleSetting.TypeString,
                                Title = "Account types",
                                Description = "Dictionary for possible account types",
                                IsArray = true,
                                ArrayValues = Enum.GetNames(typeof(AccountType)),
                                DefaultValue = AccountType.Manager.ToString()
                            }
                        }
                    }
                }
            };

            var settingsManager = new SettingsManager(moduleCatalog, platformRepositoryFactory, cacheManager, new[] { new ManifestModuleInfo(platformModuleManifest) });
            container.RegisterInstance<ISettingsManager>(settingsManager);

            #endregion

            #region Dynamic Properties

            container.RegisterType<IDynamicPropertyService, DynamicPropertyService>(new ContainerControlledLifetimeManager());

            #endregion

            #region Notifications

            var hubSignalR = GlobalHost.ConnectionManager.GetHubContext<ClientPushHub>();
            var notifier = new InMemoryPushNotificationManager(hubSignalR);
            container.RegisterInstance<IPushNotificationManager>(notifier);

            var resolver = new LiquidNotificationTemplateResolver();
            var notificationTemplateService = new NotificationTemplateServiceImpl(platformRepositoryFactory);
            var notificationManager = new NotificationManager(resolver, platformRepositoryFactory, notificationTemplateService);

            //var emailNotificationSendingGateway = new DefaultEmailNotificationSendingGateway(settingsManager);
            var emailNotificationSendingGateway = new DefaultSmtpEmailNotificationSendingGateway(settingsManager);

            var defaultSmsNotificationSendingGateway = new DefaultSmsNotificationSendingGateway();

            container.RegisterInstance<INotificationTemplateService>(notificationTemplateService);
            container.RegisterInstance<INotificationManager>(notificationManager);
            container.RegisterInstance<INotificationTemplateResolver>(resolver);
            container.RegisterInstance<IEmailNotificationSendingGateway>(emailNotificationSendingGateway);
            container.RegisterInstance<ISmsNotificationSendingGateway>(defaultSmsNotificationSendingGateway);

            #endregion

            #region Assets

            var blobConnectionString = BlobConnectionString.Parse(ConfigurationManager.ConnectionStrings["AssetsConnectionString"].ConnectionString);

            if (string.Equals(blobConnectionString.Provider, FileSystemBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
            {
                var fileSystemBlobProvider = new FileSystemBlobProvider(NormalizePath(blobConnectionString.RootPath), blobConnectionString.PublicUrl);

                container.RegisterInstance<IBlobStorageProvider>(fileSystemBlobProvider);
                container.RegisterInstance<IBlobUrlResolver>(fileSystemBlobProvider);
            }
            else if (string.Equals(blobConnectionString.Provider, AzureBlobProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
            {
                var azureBlobProvider = new AzureBlobProvider(blobConnectionString.ConnectionString);
                container.RegisterInstance<IBlobStorageProvider>(azureBlobProvider);
                container.RegisterInstance<IBlobUrlResolver>(azureBlobProvider);
            }

            #endregion

            #region Modularity

            var externalModuleCatalog = new ExternalManifestModuleCatalog(moduleCatalog.Modules, ConfigurationManager.AppSettings.GetValues("VirtoCommerce:ModulesDataSources"), container.Resolve<ILog>());
            container.RegisterType<ModulesController>(new InjectionConstructor(externalModuleCatalog, new ModuleInstaller(modulesPath, externalModuleCatalog), notifier, container.Resolve<IUserNameResolver>(), settingsManager));

            #endregion

            #region ChangeLogging

            var changeLogService = new ChangeLogService(platformRepositoryFactory);
            container.RegisterInstance<IChangeLogService>(changeLogService);

            #endregion

            #region Security
            container.RegisterInstance<IPermissionScopeService>(new PermissionScopeService());
            container.RegisterType<IRoleManagementService, RoleManagementService>(new ContainerControlledLifetimeManager());

            var apiAccountProvider = new ApiAccountProvider(platformRepositoryFactory, cacheManager);
            container.RegisterInstance<IApiAccountProvider>(apiAccountProvider);

            container.RegisterType<IClaimsIdentityProvider, ApplicationClaimsIdentityProvider>(new ContainerControlledLifetimeManager());

            container.RegisterInstance(app.GetDataProtectionProvider());
            container.RegisterType<SecurityDbContext>(new InjectionConstructor(connectionStringName));
            container.RegisterType<IUserStore<ApplicationUser>, ApplicationUserStore>();
            container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
            container.RegisterType<ApplicationUserManager>();
            container.RegisterType<ApplicationSignInManager>();

            var nonEditableUsers = ConfigurationManager.AppSettings.GetValue("VirtoCommerce:NonEditableUsers", string.Empty);
            container.RegisterInstance<ISecurityOptions>(new SecurityOptions(nonEditableUsers));

            container.RegisterType<ISecurityService, SecurityService>();

            #endregion

            #region ExportImport
            container.RegisterType<IPlatformExportImportManager, PlatformExportImportManager>();
            #endregion

            #region Serialization

            container.RegisterType<IExpressionSerializer, XmlExpressionSerializer>();

            #endregion
        }