Esempio n. 1
0
        public static void AddSocialMediaChannelTheme(string theme)
        {
            string        themesPath   = HttpContext.Current.Server.MapPath(SOCIAL_MEDIA_CHANNELS_FOLDER);
            string        newThemePath = Path.Combine(themesPath, theme);
            DirectoryInfo newThemeDir  = new DirectoryInfo(newThemePath);

            MediaService mediaService = (MediaService)ApplicationContext.Current.Services.MediaService;

            var rootFolderId = mediaService.GetMediaOfMediaType(1031).Where(x => x.Name == SOCIAL_MEDIA_THEME_FOLDER_NAME).FirstOrDefault().Id;

            //Get the media type id
            ContentTypeService cts = (ContentTypeService)ApplicationContext.Current.Services.ContentTypeService;
            int mediaTypeId        = cts.GetMediaType(SOCIAL_MEDIA_THEME_ALIAS).Id;


            FileInfo infoFile = newThemeDir.GetFiles("info.txt")[0];
            string   themeDir = newThemeDir.Name;
            string   thumbnailPath = Path.Combine(newThemeDir.Parent.FullName, themeDir + ".jpg");
            string   themeNick, themeName, themeUrl, themeCreatedBy, themeCreatedDate;

            using (StreamReader reader = new StreamReader(infoFile.FullName))
            {
                themeNick        = reader.ReadLine();
                themeName        = reader.ReadLine();
                themeCreatedBy   = reader.ReadLine();
                themeUrl         = reader.ReadLine();
                themeCreatedDate = reader.ReadLine();
            }

            bool newTheme = mediaService.GetMediaOfMediaType(mediaTypeId).Where(x => x.GetValue("themeName").ToString() == themeName).Count() == 0;

            if (newTheme)//only add if it's new
            {
                var themePck  = mediaService.CreateMedia(themeNick, rootFolderId, SOCIAL_MEDIA_THEME_ALIAS);
                var thumbnail = new FileStream(thumbnailPath, FileMode.Open);
                themePck.SetValue("umbracoFile", Path.GetFileName(thumbnailPath), thumbnail);
                themePck.SetValue("themeName", themeName);
                themePck.SetValue("themeUrl", themeUrl);
                themePck.SetValue("createdBy", themeCreatedBy);
                themePck.SetValue("createdDate", themeCreatedDate);

                mediaService.Save(themePck);
                int currThemeId = mediaService.GetMediaOfMediaType(mediaTypeId).Where(x => x.GetValue("themeName").ToString() == themeName).FirstOrDefault().Id;

                foreach (FileInfo image in newThemeDir.EnumerateFiles())
                {
                    if (!image.Extension.Equals(".txt") && !image.Extension.Equals(".xml"))
                    {
                        var media   = mediaService.CreateMedia(image.Name, currThemeId, "Image");
                        var channel = new FileStream(image.FullName, FileMode.Open);

                        media.SetValue("umbracoFile", Path.GetFileName(image.FullName), channel);
                        mediaService.Save(media);
                    }
                }
            }
        }
Esempio n. 2
0
        protected override IMedia CreateNew(MediaRepresentation content)
        {
            //we cannot continue here if the mandatory items are empty (i.e. name, etc...)
            if (!ModelState.IsValid)
            {
                throw ValidationException(ModelState, content);
            }

            var contentType = Services.ContentTypeService.GetMediaType(content.ContentTypeAlias);

            if (contentType == null)
            {
                ModelState.AddModelError("content.contentTypeAlias", "No media type found with alias " + content.ContentTypeAlias);
                throw ValidationException(ModelState, content);
            }

            //create an item before persisting of the correct content type
            var created = MediaService.CreateMedia(content.Name, content.ParentId, content.ContentTypeAlias, Security.CurrentUser.Id);

            //Validate properties
            var validator = new ContentPropertyValidator <IMedia>(ModelState, Services.DataTypeService);

            validator.ValidateItem(content, created);

            if (!ModelState.IsValid)
            {
                throw ValidationException(ModelState, content);
            }

            Mapper.Map(content, created);

            MediaService.Save(created);

            return(created);
        }
Esempio n. 3
0
        public void Run(DirectoryInfo indir, Shelf outShelf)
        {
            if (!indir.Exists)
            {
                MessageBox.Show(String.Format("{0} existiert nicht.", indir.FullName));
                return;
            }

            Game game = new Game();

            game.GameDiscs = new List <GameDisc>();
            game.Name      = String.Format("Batch-Import {0}", DateTime.Now.ToString());

            FileInfo[]      fileInfos = indir.GetFiles();
            List <FileInfo> ibgFiles  = new List <FileInfo>();

            foreach (FileInfo fileInfo in fileInfos)
            {
                string   extension = fileInfo.Extension.ToLowerInvariant();
                string   name      = Path.GetFileNameWithoutExtension(fileInfo.Name);
                GameDisc gameDisc;
                switch (extension)
                {
                case ".iso":        //yes
                    gameDisc         = game.GetDiscByName(name);
                    gameDisc.BinFile = fileInfo;
                    break;

                case ".dvd":        //yes
                    gameDisc            = game.GetDiscByName(name);
                    gameDisc.CueFile    = fileInfo;
                    gameDisc.CueContent = File.ReadAllText(fileInfo.FullName);
                    break;

                case ".md5":        //yes
                    gameDisc            = game.GetDiscByName(name);
                    gameDisc.Md5File    = fileInfo;
                    gameDisc.Md5Content = File.ReadAllText(fileInfo.FullName);
                    break;

                case ".mds":        //yes
                    gameDisc            = game.GetDiscByName(name);
                    gameDisc.MdsFile    = fileInfo;
                    gameDisc.MdsContent = File.ReadAllBytes(fileInfo.FullName);
                    break;

                case ".ibg":        //eyes
                    ibgFiles.Add(fileInfo);
                    break;

                default:
                    MessageBox.Show(String.Format("Don't know about {0}...", extension));
                    return;
                }
            }

            foreach (FileInfo ibgInfo in ibgFiles)
            {
                long     lookFor  = ibgInfo.LastWriteTime.ToUnixMinute();
                GameDisc gameDisc = game.GetByUnixMinute(lookFor);
                gameDisc.IbgContent = File.ReadAllText(ibgInfo.FullName);
            }

            game.GameDiscs.Sort(new OrderByIsoDate());

            for (int i = 0; i < game.GameDiscs.Count; i++)
            {
                game.GameDiscs[i].Name = String.Format("Disc {0}", i + 1);
            }

            int     productId = ProductService.CreateProduct(game.Name, outShelf);
            Product product   = ProductService.GetProduct(productId);

            product.Complete   = true;
            product.Consistent = true;
            product.NSFW       = false;
            ProductService.UpdateProduct(product);

            foreach (GameDisc gameDisc in game.GameDiscs)
            {
                int   mediaId = MediaService.CreateMedia(product, gameDisc.Name);
                Media media   = MediaService.GetSpecificMedia(mediaId);
                media.ChecksumContent  = gameDisc.Md5Content;
                media.CueSheetContent  = gameDisc.CueContent;
                media.GraphDataContent = gameDisc.IbgContent;
                media.MdsContent       = gameDisc.MdsContent;
                media.MediaTypeId      = 1;
                media.isSealed         = false;

                MediaService.UpdateMedia(media);

                Stream binStream = gameDisc.BinFile.OpenRead();
                media.SetFilesystemMetadata(binStream);
                binStream.Close();
            }

            Console.WriteLine("Great!");
        }
Esempio n. 4
0
        public void Run(DirectoryInfo indir, Shelf outShelf, double potprice)
        {
            if (!indir.Exists)
            {
                MessageBox.Show(String.Format("{0} existiert nicht.", indir.FullName));
                return;
            }

            DirectoryInfo[] directoryInfos = indir.GetDirectories();
            Game[]          games          = new Game[directoryInfos.Length];

            for (int i = 0; i < directoryInfos.Length; i++)
            {
                games[i]           = new Game();
                games[i].GameDiscs = new List <GameDisc>();
                games[i].Name      = directoryInfos[i].Name;

                FileInfo[]      fileInfos = directoryInfos[i].GetFiles();
                List <FileInfo> ibgFiles  = new List <FileInfo>();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    string   extension = fileInfo.Extension.ToLowerInvariant();
                    string   name      = Path.GetFileNameWithoutExtension(fileInfo.Name);
                    GameDisc gameDisc;
                    switch (extension)
                    {
                    case ".bin":
                        gameDisc         = games[i].GetDiscByName(name);
                        gameDisc.BinFile = fileInfo;
                        break;

                    case ".cue":
                        gameDisc            = games[i].GetDiscByName(name);
                        gameDisc.CueFile    = fileInfo;
                        gameDisc.CueContent = File.ReadAllText(fileInfo.FullName);
                        break;

                    case ".md5":
                        gameDisc            = games[i].GetDiscByName(name);
                        gameDisc.Md5File    = fileInfo;
                        gameDisc.Md5Content = File.ReadAllText(fileInfo.FullName);
                        break;

                    case ".jpg":
                        games[i].Cover = File.ReadAllBytes(fileInfo.FullName);
                        break;

                    case ".ibg":
                        ibgFiles.Add(fileInfo);
                        break;

                    default:
                        MessageBox.Show(String.Format("Don't know about {0}...", extension));
                        return;
                    }
                }

                foreach (FileInfo ibgInfo in ibgFiles)
                {
                    long     lookFor  = ibgInfo.LastWriteTime.ToUnixMinute();
                    GameDisc gameDisc = games[i].GetByUnixMinute(lookFor);
                    gameDisc.IbgContent = File.ReadAllText(ibgInfo.FullName);
                }
            }

            for (int i = 0; i < games.Length; i++)
            {
                int     productId = ProductService.CreateProduct(games[i].Name, outShelf);
                Product product   = ProductService.GetProduct(productId);
                product.BoughtOn          = PurchaseDate;
                product.Complete          = true;
                product.CountryOfOriginId = CountryId;
                product.Consistent        = true;
                product.NSFW       = false;
                product.Picture    = games[i].Cover;
                product.PlatformId = PlatformId;
                product.Price      = Math.Round(potprice / games.Length, 2);
                product.SupplierId = SupplierId;
                ProductService.UpdateProduct(product);
                ProductService.SetCover(product);

                foreach (GameDisc gameDisc in games[i].GameDiscs)
                {
                    int   mediaId = MediaService.CreateMedia(product, gameDisc.Name);
                    Media media   = MediaService.GetSpecificMedia(mediaId);
                    media.ChecksumContent  = gameDisc.Md5Content;
                    media.CueSheetContent  = gameDisc.CueContent;
                    media.GraphDataContent = gameDisc.IbgContent;
                    media.MediaTypeId      = 0;
                    media.MetaFileContent  = gameDisc.CueContent;
                    media.SKU      = gameDisc.GuessSku();
                    media.isSealed = false;

                    FileInfo createdCue = CopyFile(gameDisc.CueFile);
                    media.SetDumpFile(createdCue);
                    MediaService.UpdateMedia(media);

                    FileInfo createdBin = CopyFile(gameDisc.BinFile);
                    Stream   binStream  = createdBin.OpenRead();
                    media.SetFilesystemMetadata(binStream);
                    binStream.Close();
                }
            }

            Console.WriteLine("Great!");
        }