Ejemplo n.º 1
0
            public void With_Different_Ids_Are_NotEqual()
            {
                var             resources   = new ResourceDictionary();
                var             resources2  = new ResourceDictionary();
                ThemeDescriptor descriptor  = new ThemeDescriptor(Guid.NewGuid(), "ABC", resources);
                ThemeDescriptor descriptor2 = new ThemeDescriptor(Guid.NewGuid(), "other name", resources2);

                Assert.IsFalse(descriptor.Equals(descriptor2));
            }
        public async Task <IActionResult> UploadTheme(IFormFile zippedFile)
        {
            if (zippedFile == null || zippedFile.Length == 0)
            {
                ErrorNotification(_localizationService.GetResource("Admin.Common.UploadFile"));
                return(RedirectToAction("GeneralCommon", "Setting"));
            }

            string zipFilePath = "";

            ThemeDescriptor descriptor = new ThemeDescriptor();

            try
            {
                if (!Path.GetExtension(zippedFile.FileName)?.Equals(".zip", StringComparison.InvariantCultureIgnoreCase) ?? true)
                {
                    throw new Exception("Only zip archives are supported");
                }

                //ensure that temp directory is created
                var tempDirectory = CommonHelper.MapPath("~/App_Data/TempUploads");
                System.IO.Directory.CreateDirectory(new DirectoryInfo(tempDirectory).FullName);

                //copy original archive to the temp directory
                zipFilePath = Path.Combine(tempDirectory, zippedFile.FileName);
                using (var fileStream = new FileStream(zipFilePath, FileMode.Create))
                    zippedFile.CopyTo(fileStream);

                descriptor = (ThemeDescriptor)UploadSingleItem(zipFilePath);
                var configs = _themeProvider.GetThemeConfigurations();
                var b       = _themeProvider.ThemeConfigurationExists(descriptor.FriendlyName);

                await _customerActivityService.InsertActivity("UploadNewTheme", "",
                                                              string.Format(_localizationService.GetResource("ActivityLog.UploadNewTheme"), descriptor.FriendlyName));

                await _mediator.Publish(new ThemeUploadedEvent(descriptor));

                var message = _localizationService.GetResource("Admin.Configuration.Themes.Uploaded");
                SuccessNotification(message);
            }
            catch (Exception ex)
            {
                var message = _localizationService.GetResource("Admin.Configuration.Themes.Failed");
                ErrorNotification(message + "\r\n" + ex.Message);
            }
            finally
            {
                //delete temporary file
                if (!string.IsNullOrEmpty(zipFilePath))
                {
                    System.IO.File.Delete(zipFilePath);
                }
            }

            return(RedirectToAction("GeneralCommon", "Setting"));
        }
Ejemplo n.º 3
0
            public void Returns_True_For_Registered_Theme()
            {
                var          mockResourceDictionary = new Mock <ICollection <ResourceDictionary> >();
                ThemeManager manager = new ThemeManager(mockResourceDictionary.Object);

                ThemeDescriptor descriptor = new ThemeDescriptor(Guid.NewGuid(), "Theme name", new ResourceDictionary());

                manager.RegisterTheme(descriptor);

                Assert.IsTrue(manager.IsRegistered(descriptor.Id));
            }
Ejemplo n.º 4
0
            public void With_Same_Id_Are_Equal()
            {
                var             resources   = new ResourceDictionary();
                var             resources2  = new ResourceDictionary();
                Guid            guid        = Guid.NewGuid();
                string          name        = "ABC";
                ThemeDescriptor descriptor  = new ThemeDescriptor(guid, name, resources);
                ThemeDescriptor descriptor2 = new ThemeDescriptor(guid, "other name", resources2);

                Assert.IsTrue(descriptor.Equals(descriptor2));
            }
Ejemplo n.º 5
0
            public void With_Correct_Descriptor_Succed()
            {
                var          mockResourceDictionary = new Mock <ICollection <ResourceDictionary> >();
                ThemeManager manager = new ThemeManager(mockResourceDictionary.Object);

                ThemeDescriptor descriptor = new ThemeDescriptor(Guid.NewGuid(), "Theme name", new ResourceDictionary());

                manager.RegisterTheme(descriptor);

                // Throws if not registered
                manager.RegisteredThemes.Single(t => t.Id == descriptor.Id);
            }
        public ThemeDescriptor GetThemeDescriptorFromText(string text)
        {
            var themeDescriptor = new ThemeDescriptor();

            try
            {
                var themeConfiguration = JsonConvert.DeserializeObject <ThemeConfiguration>(text);
                themeDescriptor.FriendlyName = themeConfiguration.Title;
            }
            catch { }

            return(themeDescriptor);
        }
Ejemplo n.º 7
0
            public void Returns_Correct_CurrentTheme_After_Apply()
            {
                var          mockResourceDictionary = new Mock <ICollection <ResourceDictionary> >();
                ThemeManager manager = new ThemeManager(mockResourceDictionary.Object);

                ThemeDescriptor descriptor = new ThemeDescriptor(Guid.NewGuid(), "Theme name", new ResourceDictionary());

                manager.RegisterTheme(descriptor);

                manager.ApplyTheme(descriptor.Id);

                Assert.AreEqual(manager.CurrentTheme.Id, descriptor.Id);
            }
Ejemplo n.º 8
0
            public void That_Already_Registered_Succed()
            {
                var          mockResourceDictionary = new Mock <ICollection <ResourceDictionary> >();
                ThemeManager manager = new ThemeManager(mockResourceDictionary.Object);

                ThemeDescriptor descriptor = new ThemeDescriptor(Guid.NewGuid(), "Theme name", new ResourceDictionary());

                manager.RegisterTheme(descriptor);
                manager.RegisterTheme(descriptor);
                manager.RegisterTheme(descriptor);

                Assert.AreEqual(1, manager.RegisteredThemes.Count());
            }
Ejemplo n.º 9
0
            public void With_Correct_Parameters_Succed()
            {
                var resources = new ResourceDictionary();

                resources.Add("key", "value");
                Guid            guid       = Guid.NewGuid();
                string          name       = "ABC";
                ThemeDescriptor descriptor = new ThemeDescriptor(guid, name, resources);

                Assert.AreEqual(guid, descriptor.Id);
                Assert.AreEqual(name, descriptor.Name);
                Assert.AreEqual(resources.Count, descriptor.ThemeResources.Count);
            }
Ejemplo n.º 10
0
            public void Removes_All_Other_Items_From_Underlying_Resource_Dictionary()
            {
                var mockResourceDictionary = new Mock <ICollection <ResourceDictionary> >();

                mockResourceDictionary.Setup(c => c.Clear());
                mockResourceDictionary.Setup(c => c.Add(It.IsAny <ResourceDictionary>()));
                ThemeManager manager = new ThemeManager(mockResourceDictionary.Object);

                var             resourceDic = new ResourceDictionary();
                ThemeDescriptor descriptor  = new ThemeDescriptor(Guid.NewGuid(), "Theme name", resourceDic);

                manager.RegisterTheme(descriptor);
                manager.ApplyTheme(descriptor.Id);

                mockResourceDictionary.Verify(c => c.Clear(), Times.Once);
            }
Ejemplo n.º 11
0
        public ThemeDescriptor GetThemeDescriptorFromText(string text)
        {
            ThemeDescriptor themeDescriptor = new ThemeDescriptor();

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(text);

                XmlNodeList Tags = doc.GetElementsByTagName("Theme");
                var         name = Tags[0].Attributes["title"].Value;
                themeDescriptor.FriendlyName = name;
            }
            catch { }

            return(themeDescriptor);
        }
Ejemplo n.º 12
0
        private IThemeDescriptor GetThemeDescriptorFromManifest(
            string rootPath,
            string themeId,
            string themeType,
            string manifestText)
        {
            var manifest = ParseManifest(manifestText);

            var themeDescriptor = new ThemeDescriptor
            {
                Id           = themeId,
                Name         = GetValue(manifest, NameSection) ?? themeType,
                Description  = GetValue(manifest, DescriptionSection),
                Version      = GetValue(manifest, VersionSection),
                PlatoVersion = GetValue(manifest, PlatoVersionSection),
                Author       = GetValue(manifest, AuthorSection),
                WebSite      = GetValue(manifest, WebsiteSection),
                FullPath     = _fileSystem.Combine(rootPath, themeId)
            };

            return(themeDescriptor);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="uploadedTheme">Uploaded themes</param>
 public ThemeUploadedEvent(ThemeDescriptor uploadedTheme)
 {
     this.UploadedTheme = uploadedTheme;
 }
Ejemplo n.º 14
0
 public void With_Null_Resources_Throws()
 {
     ThemeDescriptor descriptor = new ThemeDescriptor(Guid.NewGuid(), "ABC", null);
 }
Ejemplo n.º 15
0
 public void With_Null_Name_Throws()
 {
     var             resources  = new ResourceDictionary();
     ThemeDescriptor descriptor = new ThemeDescriptor(Guid.NewGuid(), null, resources);
 }
Ejemplo n.º 16
0
 public void With_Empty_Id_Throws()
 {
     var             resources  = new ResourceDictionary();
     ThemeDescriptor descriptor = new ThemeDescriptor(Guid.Empty, "ABC", resources);
 }