private void OnInsertFileItemClick(object sender, ItemClickEventArgs e)
 {
     using (var openFileDialog = new OpenFileDialog())
     {
         openFileDialog.Title            = "Inser Image or Video file";
         openFileDialog.DefaultExt       = "*.png;*.bmp;*.jpg;*.jpeg;*.mp4;*.avi;*.wmv";
         openFileDialog.Filter           = "Image or Video files|*.png;*.bmp;*.jpg;*.jpeg;*.mp4;*.avi;*.wmv";
         openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             var           filePath      = openFileDialog.FileName;
             ClipartObject clipartObject = null;
             if (FileFormatHelper.IsImageFile(filePath))
             {
                 clipartObject = ImageClipartObject.FromFile(filePath);
             }
             else if (FileFormatHelper.IsVideoFile(filePath))
             {
                 clipartObject = GenererateVideoClipart(filePath);
             }
             if (clipartObject != null)
             {
                 LoadData(clipartObject);
                 EditValueChanged?.Invoke(sender, e);
             }
         }
     }
 }
        private void OnImageDragDrop(object sender, DragEventArgs e)
        {
            if (e.Data != null && e.Data.GetDataPresent(DataFormats.FileDrop, true) &&
                e.Data.GetData(DataFormats.FileDrop, true) is String[])
            {
                var filePath = (e.Data.GetData(DataFormats.FileDrop) as String[] ?? new string[] { }).FirstOrDefault();
                if (filePath == null)
                {
                    return;
                }

                ClipartObject clipartObject = null;
                if (FileFormatHelper.IsImageFile(filePath))
                {
                    clipartObject = ImageClipartObject.FromFile(filePath);
                }
                else if (FileFormatHelper.IsVideoFile(filePath))
                {
                    clipartObject = GenererateVideoClipart(filePath);
                }
                if (clipartObject != null)
                {
                    LoadData(clipartObject);
                    EditValueChanged?.Invoke(sender, e);
                }
            }
        }
Ejemplo n.º 3
0
        public static int GetIndexFromFilename(string filename)
        {
            var match = Regex.Match(filename, "^(normal|soft|drum)-(hit(normal|whistle|finish|clap)|slidertick|sliderslide)");

            var remainder = filename.Substring(match.Index + match.Length);
            int index     = 0;

            if (!string.IsNullOrEmpty(remainder))
            {
                FileFormatHelper.TryParseInt(remainder, out index);
            }

            return(index);
        }
Ejemplo n.º 4
0
        public List <CustomIndex> GetCustomIndices(SampleGeneratingArgsComparer comparer = null)
        {
            if (comparer == null)
            {
                comparer = new SampleGeneratingArgsComparer();
            }

            var customIndices = new Dictionary <int, CustomIndex>();

            foreach (var kvp in this)
            {
                var name = Path.GetFileNameWithoutExtension(kvp.Key);
                if (name == null)
                {
                    continue;
                }

                var match = Regex.Match(name, "^(normal|soft|drum)-hit(normal|whistle|finish|clap)");
                if (!match.Success)
                {
                    continue;
                }

                var hitsound = match.Value;

                var remainder = name.Substring(match.Index + match.Length);
                int index     = 1;
                if (!string.IsNullOrEmpty(remainder))
                {
                    if (!FileFormatHelper.TryParseInt(remainder, out index))
                    {
                        continue;
                    }
                }

                if (customIndices.ContainsKey(index))
                {
                    customIndices[index].Samples[hitsound] = new HashSet <SampleGeneratingArgs>(kvp.Value);
                }
                else
                {
                    var ci = new CustomIndex(index, comparer);
                    customIndices.Add(index, ci);
                    ci.Samples[hitsound] = new HashSet <SampleGeneratingArgs>(kvp.Value, comparer);
                }
            }

            return(customIndices.Values.ToList());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Upload(ICollection <IFormFile> files)
        {
            var configValidation = _storageService.ValidateConfiguration();

            if (!configValidation.IsValid())
            {
                return(BadRequest(configValidation.GetErrors()));
            }

            if (files.Count == 0)
            {
                return(BadRequest("No files received from the upload"));
            }

            foreach (var formFile in files)
            {
                if (!FileFormatHelper.IsImage(formFile))
                {
                    return(new UnsupportedMediaTypeResult());
                }
                if (formFile.Length <= 0)
                {
                    continue;
                }

                _telemetryClient.TrackEvent("UPLOADED_FILE", new Dictionary <string, string>
                {
                    { "FILE_NAME", formFile.FileName },
                    { "CONTENT_LENGTH", formFile.Length.ToString() }
                });

                using (var stream = formFile.OpenReadStream())
                {
                    if (await _storageService.UploadFileToStorage(stream, formFile.FileName))
                    {
                        return(new AcceptedResult());
                    }
                }
            }

            return(BadRequest("Look like the image couldnt upload to the storage"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Upload(ICollection <IFormFile> files)
        {
            var configValidation = _storageService.ValidateConfiguration();

            if (!configValidation.IsValid())
            {
                return(BadRequest(configValidation.GetErrors()));
            }

            if (files.Count == 0)
            {
                return(BadRequest("No files received from the upload"));
            }

            foreach (var formFile in files)
            {
                if (FileFormatHelper.IsImage(formFile))
                {
                    if (formFile.Length > 0)
                    {
                        using (var stream = formFile.OpenReadStream())
                        {
                            if (await _storageService.UploadFileToStorage(stream, formFile.FileName))
                            {
                                //Send message on queue
                                //Make sure to match up the queueName with a trigger and the message body with how
                                //your function reads the message. E.g.:
                                await _queueService.SendQueueMessage("greyimage", formFile.FileName);

                                return(new AcceptedResult());
                            }
                        }
                    }
                }
                else
                {
                    return(new UnsupportedMediaTypeResult());
                }
            }

            return(BadRequest("Look like the image couldnt upload to the storage"));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Upload(ICollection <IFormFile> files)
        {
            var configValidation = _storageService.ValidateConfiguration();

            if (!configValidation.IsValid())
            {
                return(BadRequest(configValidation.GetErrors()));
            }

            if (files.Count == 0)
            {
                return(BadRequest("No files received from the upload"));
            }

            foreach (var formFile in files)
            {
                if (!FileFormatHelper.IsImage(formFile))
                {
                    return(new UnsupportedMediaTypeResult());
                }

                if (formFile.Length <= 0)
                {
                    continue;
                }

                // telemetry client goes here

                using (var stream = formFile.OpenReadStream())
                {
                    if (await _storageService.UploadFileToStorage(stream, formFile.FileName))
                    {
                        return(new AcceptedResult());
                    }
                }
            }

            return(BadRequest("Look like the image couldnt upload to the storage"));
        }
Ejemplo n.º 8
0
        private static string MergeMapsets(MapsetMergerVm arg, BackgroundWorker worker, DoWorkEventArgs _)
        {
            int mapsetsMerged = 0;
            int indexStart    = 1;

            ResolveDuplicateNames(arg.Mapsets);

            var usedNames = new HashSet <string>();

            foreach (var mapset in arg.Mapsets)
            {
                var subf   = mapset.Name;
                var prefix = mapset.Name + " - ";

                var beatmaps    = LoadBeatmaps(mapset);
                var storyboards = LoadStoryboards(mapset);

                // All hitsound indices in the beatmaps. Old index to new index
                var indices = new Dictionary <int, int>();
                // All hitsound files with custom indices
                var usedHsFiles = new HashSet <string>();
                // All explicitly referenced audio files like filename hs, SB samples
                var usedOtherHsFiles = new HashSet <string>();
                // All explicitly referenced image files like storyboard files, background
                var usedImageFiles = new HashSet <string>();
                // All explicitly referenced video files
                var usedVideoFiles = new HashSet <string>();

                // We have to ignore files which are not possible to reference in a distinguishing way
                // such as beatmap skin files and the spinnerspin and spinnerbonus files.

                StoryBoard sharedSb = null;
                if (arg.MoveSbToBeatmap)
                {
                    sharedSb = storyboards.FirstOrDefault()?.Item2;

                    if (sharedSb != null)
                    {
                        GetUsedFilesAndUpdateReferences(sharedSb, subf, usedOtherHsFiles, usedImageFiles, usedVideoFiles);
                    }
                }
                else
                {
                    foreach (var storyboardTuple in storyboards)
                    {
                        var storyboard = storyboardTuple.Item2;

                        GetUsedFilesAndUpdateReferences(storyboard, subf, usedOtherHsFiles, usedImageFiles, usedVideoFiles);

                        // Save storyboard in new location with unique filename
                        Editor.SaveFile(Path.Combine(arg.ExportPath, prefix + Path.GetFileName(storyboardTuple.Item1)),
                                        storyboard.GetLines());
                    }
                }

                // Find all used files and change references
                foreach (var beatmapTuple in beatmaps)
                {
                    var beatmap = beatmapTuple.Item2;

                    GetUsedFilesAndUpdateReferences(beatmap, subf, ref indexStart, indices, usedHsFiles, usedOtherHsFiles, usedImageFiles, usedVideoFiles);

                    if (sharedSb != null)
                    {
                        beatmap.StoryBoard.StoryboardLayerBackground = sharedSb.StoryboardLayerBackground;
                        beatmap.StoryBoard.StoryboardLayerForeground = sharedSb.StoryboardLayerForeground;
                        beatmap.StoryBoard.StoryboardLayerFail       = sharedSb.StoryboardLayerFail;
                        beatmap.StoryBoard.StoryboardLayerPass       = sharedSb.StoryboardLayerPass;
                        beatmap.StoryBoard.StoryboardLayerOverlay    = sharedSb.StoryboardLayerOverlay;
                        beatmap.StoryBoard.StoryboardSoundSamples    = sharedSb.StoryboardSoundSamples;
                    }

                    // Save beatmap in new location with unique diffname
                    var diffname = beatmap.Metadata["Version"].Value;
                    if (usedNames.Contains(diffname))
                    {
                        diffname = prefix + diffname;
                    }

                    usedNames.Add(diffname);
                    beatmap.Metadata["Version"].Value = diffname;

                    Editor.SaveFile(Path.Combine(arg.ExportPath, beatmap.GetFileName()),
                                    beatmap.GetLines());
                }

                // Save assets in new location
                foreach (var filename in usedHsFiles)
                {
                    var filepath = FindAssetFile(filename, mapset.Path, AudioExtensions);

                    if (filepath == null)
                    {
                        continue;
                    }

                    var ext     = Path.GetExtension(filepath);
                    var extLess = Path.GetFileNameWithoutExtension(filepath);

                    var match = Regex.Match(extLess, "^(normal|soft|drum)-(hit(normal|whistle|finish|clap)|slidertick|sliderslide)");

                    var remainder = extLess.Substring(match.Index + match.Length);
                    int index     = 1;
                    if (!string.IsNullOrWhiteSpace(remainder) && !FileFormatHelper.TryParseInt(remainder, out index))
                    {
                        continue;
                    }

                    var newFilename = indices[index] == 1 ?
                                      extLess.Substring(0, match.Length) + ext :
                                      extLess.Substring(0, match.Length) + indices[index] + ext;
                    var newFilepath = Path.Combine(arg.ExportPath, newFilename);

                    Directory.CreateDirectory(Path.GetDirectoryName(newFilepath));
                    File.Copy(filepath, newFilepath, true);
                }

                foreach (var filename in usedOtherHsFiles)
                {
                    SaveAsset(filename, mapset.Path, subf, arg.ExportPath, AudioExtensions2);
                }

                foreach (var filename in usedImageFiles)
                {
                    SaveAsset(filename, mapset.Path, subf, arg.ExportPath, ImageExtensions);
                }

                foreach (var filename in usedVideoFiles)
                {
                    SaveAsset(filename, mapset.Path, subf, arg.ExportPath, VideoExtensions, true);
                }

                UpdateProgressBar(worker, ++mapsetsMerged * 100 / arg.Mapsets.Count);
            }

            // Make an accurate message
            var message = $"Successfully merged {mapsetsMerged} {(mapsetsMerged == 1 ? "mapset" : "mapsets")}!";

            return(message);
        }
Ejemplo n.º 9
0
        public static void PrintFile(string filePath, int currentPage = 0)
        {
            var printProcess = new Process();

            if (FileFormatHelper.IsPowerPointFile(filePath))
            {
                try
                {
                    using (var powerPointProcessor = new PowerPointHidden())
                    {
                        if (!powerPointProcessor.Connect(true))
                        {
                            return;
                        }
                        powerPointProcessor.PrintPresentation(
                            filePath,
                            currentPage,
                            printAction => FormProgress.ShowProgress("Printing...",
                                                                     () =>
                        {
                            try
                            {
                                printAction();
                            }
                            catch
                            {
                            }
                        },
                                                                     false));
                    }
                }
                catch
                {
                }
            }
            else if (FileFormatHelper.IsWordFile(filePath))
            {
                try
                {
                    printProcess.StartInfo.FileName  = "winword.exe";
                    printProcess.StartInfo.Arguments = '"' + filePath + '"' + " /mFilePrint";
                    printProcess.Start();
                }
                catch { }
            }
            else if (FileFormatHelper.IsExcelFile(filePath))
            {
                if (ExcelHelper.Instance.Connect())
                {
                    ExcelHelper.Instance.Print(new FileInfo(filePath));
                    ExcelHelper.Instance.Disconnect();
                }
            }
            else if (FileFormatHelper.IsPdfFile(filePath))
            {
                try
                {
                    printProcess.StartInfo.FileName  = "AcroRd32.exe";
                    printProcess.StartInfo.Arguments = " /p " + '"' + filePath + '"';
                    printProcess.Start();
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 10
0
        public string GenerateReport(StatisticsViewModel statistics, ReportTypeEnum fileType)
        {
            var filename = FileFormatHelper.GenerateXlsx(statistics);

            return(filename);
        }
Ejemplo n.º 11
0
 private FileContentResult ToFileContentResult(UserFile userFile) => File(userFile.Content, FileFormatHelper.GetContentTypeByExtension(userFile.Extension), userFile.FriendlyName ?? userFile.Name);