Ejemplo n.º 1
0
        public async Task <IActionResult> Splitter(SplitterViewModel Model, IFormFile SequenceFile)
        {
            if (Model.Sequence == null && SequenceFile == null)
            {
                return(View("Error", new ErrorViewModel {
                    Message = "You Can't enter an empty sequence", Solution = "You have to enter the sequence or either upload a file contains the sequence"
                }));
            }
            if (SequenceFile != null)
            {
                if (SequenceFile.ContentType != "text/plain")
                {
                    return(View("Error", new ErrorViewModel {
                        Message = "You Can't upload a file of any type rather than txt file format", Solution = "You should upload a file of txt file format"
                    }));
                }
                else
                {
                    Model.Sequence = await Helper.ConvertFileByteToByteStringAsync(SequenceFile);
                }
            }
            if (!Regex.IsMatch(Model.Sequence, @"^[a-zA-Z]+$"))
            {
                return(View("Error", new ErrorViewModel {
                    Message = "Your sequence must contains only characters", Solution = "Send sequence contains only characters"
                }));
            }
            if (Model.Divider >= Model.Sequence.Length || Model.Divider <= 0)
            {
                return(View("Error", new ErrorViewModel {
                    Message = "You Can't split with length greater than the sequence length or less than 0", Solution = "Your splitter must be less than the sequence length and greater than 1"
                }));
            }
            IList <string> Sequences = Helper.SequenceSpliter(Model.Sequence, Model.Divider).ToList();
            StringBuilder  Sb        = new StringBuilder();

            Sb.Append($"Your Sequences count:{Sequences.Count()}, Each sequence is {Model.Divider} length:");
            Sb.Append(Environment.NewLine);
            for (int i = 0; i < Sequences.Count; i++)
            {
                Sb.Append(Sequences[i]);
                Sb.Append(Environment.NewLine);
            }
            return(File(Encoding.UTF8.GetBytes(Sb.ToString()), "text/plain", $"{Guid.NewGuid()}_SplitSequence.txt"));
        }
Ejemplo n.º 2
0
 public SplitterView()
 {
     DataContext = new SplitterViewModel(SplitManager.Instance());
     InitializeComponent();
 }