Esempio n. 1
0
 private void ClearFiles(IIOHelper ioHelper)
 {
     TestHelper.DeleteDirectory(ioHelper.MapPath("media"));
     TestHelper.DeleteDirectory(ioHelper.MapPath("FileSysTests"));
     TestHelper.DeleteDirectory(ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') +
                                                 "ShadowFs"));
 }
        public override PipelineResult <InstallPipelineContext> Execute(PipelineArgs <InstallPipelineContext> args)
        {
            using (var uow = _vendrApi.Uow.Create())
            {
                // Create a store specific order editor config
                var configPath = _ioHelper.MapPath($"~/App_Plugins/Vendr/config/{args.Model.Store.Alias}.order.editor.config.js");
                if (!File.Exists(configPath))
                {
                    File.Copy(_ioHelper.MapPath($"~/App_Plugins/VendrCheckout/config/vendrcheckout.order.editor.config.js"),
                              configPath);
                }

                // Update order confirmation email
                var orderConfirmationEmailId = args.Model.Store.ConfirmationEmailTemplateId;
                if (orderConfirmationEmailId.HasValue)
                {
                    var orderConfirmationEmail = _vendrApi.GetEmailTemplate(orderConfirmationEmailId.Value)
                                                 .AsWritable(uow)
                                                 .SetTemplateView("~/App_Plugins/VendrCheckout/views/emails/VendrCheckoutOrderConfirmationEmail.cshtml");

                    _vendrApi.SaveEmailTemplate(orderConfirmationEmail);
                }

                // Update order confirmation email
                var orderErrorEmailId = args.Model.Store.ErrorEmailTemplateId;
                if (orderErrorEmailId.HasValue)
                {
                    var orderErrorEmail = _vendrApi.GetEmailTemplate(orderErrorEmailId.Value)
                                          .AsWritable(uow)
                                          .SetTemplateView("~/App_Plugins/VendrCheckout/views/emails/VendrCheckoutOrderErrorEmail.cshtml");

                    _vendrApi.SaveEmailTemplate(orderErrorEmail);
                }

                // Update gift card email
                var giftCardEmailId = args.Model.Store.DefaultGiftCardEmailTemplateId;
                if (giftCardEmailId.HasValue)
                {
                    var giftCardEmail = _vendrApi.GetEmailTemplate(giftCardEmailId.Value)
                                        .AsWritable(uow)
                                        .SetTemplateView("~/App_Plugins/VendrCheckout/views/emails/VendrCheckoutGiftCardEmail.cshtml");

                    _vendrApi.SaveEmailTemplate(giftCardEmail);
                }

                uow.Complete();
            }

            // Continue the pipeline
            return(Ok());
        }
        public BuildManagerTypeFinder(IIOHelper ioHelper, ILogger logger, ITypeFinderConfig typeFinderConfig = null) : base(logger, typeFinderConfig)
        {
            if (ioHelper == null)
            {
                throw new ArgumentNullException(nameof(ioHelper));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _allAssemblies = new Lazy <HashSet <Assembly> >(() =>
            {
                var isHosted = ioHelper.IsHosted;
                try
                {
                    if (isHosted)
                    {
                        var assemblies = new HashSet <Assembly>(BuildManager.GetReferencedAssemblies().Cast <Assembly>());

                        //here we are trying to get the App_Code assembly
                        var fileExtensions = new[] { ".cs", ".vb" }; //only vb and cs files are supported
                        var appCodeFolder  = new DirectoryInfo(ioHelper.MapPath(ioHelper.ResolveUrl("~/App_code")));
                        //check if the folder exists and if there are any files in it with the supported file extensions
                        if (appCodeFolder.Exists && fileExtensions.Any(x => appCodeFolder.GetFiles("*" + x).Any()))
                        {
                            try
                            {
                                var appCodeAssembly = Assembly.Load("App_Code");
                                if (assemblies.Contains(appCodeAssembly) == false) // BuildManager will find App_Code already
                                {
                                    assemblies.Add(appCodeAssembly);
                                }
                            }
                            catch (FileNotFoundException ex)
                            {
                                //this will occur if it cannot load the assembly
                                logger.Error(typeof(TypeFinder), ex, "Could not load assembly App_Code");
                            }
                        }
                    }
                }
                catch (InvalidOperationException e)
                {
                    if (e.InnerException is SecurityException == false)
                    {
                        throw;
                    }
                }

                // Not hosted, just use the default implementation
                return(new HashSet <Assembly>(base.AssembliesToScan));
            });
        }
        /// <summary>
        /// Tries to create a directory.
        /// </summary>
        /// <param name="ioHelper">The IOHelper.</param>
        /// <param name="dir">the directory path.</param>
        /// <returns>true if the directory was created, false otherwise.</returns>
        public static bool TryCreateDirectory(this IIOHelper ioHelper, string dir)
        {
            try
            {
                var dirPath = ioHelper.MapPath(dir);

                if (Directory.Exists(dirPath) == false)
                {
                    Directory.CreateDirectory(dirPath);
                }

                var filePath = dirPath + "/" + CreateRandomFileName(ioHelper) + ".tmp";
                File.WriteAllText(filePath, "This is an Umbraco internal test file. It is safe to delete it.");
                File.Delete(filePath);
                return(true);
            }
            catch
            {
                return(false);
            }
        }