Exemplo n.º 1
0
 public virtual Models.ResultModel BuilderSortingNameDESC(Models.ResultModel model)
 {
     return(new Models.ResultModel
     {
         Status = model.Status,
         Msg = "testdesc",
         Data = new Models.SortingNameModel
         {
             FileName = model.Data.FileName,
             ListName = model.Data.ListName.OrderByDescending(x => x).ToList()
         }
     });
 }
Exemplo n.º 2
0
        public virtual Models.ResultModel CommandforSortingNameDESC(string command)
        {
            var resOrigin = CommandforSortingNameOrigin(command);

            Models.ResultModel resBuilder = new Models.ResultModel();
            if (resOrigin.Status)
            {
                resBuilder = _builder.BuilderSortingNameDESC(resOrigin);
            }
            else
            {
                resBuilder = resOrigin;
            }

            return(resBuilder);
        }
Exemplo n.º 3
0
        // normally sorting ASC without some condition
        public virtual Models.ResultModel CommandforSortingNameOrigin(string command)
        {
            // validate
            var resValidate = _validate.ValidateSortingName(command);

            // build a model
            Models.ResultModel resBuilder = new Models.ResultModel();
            if (resValidate.Status)
            {
                resBuilder = _builder.BuilderSortingName(resValidate);
            }
            else
            {
                resBuilder = resValidate;
            }

            return(resBuilder);
        }
Exemplo n.º 4
0
        public virtual Models.ResultModel ValidateSortingName(string command)
        {
            // process the command
            string isCommand = command.Split(' ').FirstOrDefault().ToString().Trim();
            string isPath    = command.Split(' ').LastOrDefault().ToString().Trim();

            // validation the command
            var s           = false;
            var FailedModel = new Models.ResultModel
            {
                Status = s,
                Msg    = "Please check the Command again!"
            };

            if (string.IsNullOrWhiteSpace(isCommand) || string.IsNullOrWhiteSpace(isPath))
            {
                return(FailedModel);
            }
            if (isCommand != "name-sorter")
            {
                return(FailedModel);
            }
            if (File.Exists(isPath))
            {
                return(new Models.ResultModel {
                    Status = !s, Msg = "",
                    Data = new Models.SortingNameModel
                    {
                        FullPath = isPath,
                        FileName = "file exist",
                    }
                });
            }
            else
            {
                return(new Models.ResultModel
                {
                    Status = s,
                    Msg = "Path Not Found, " + FailedModel.Msg
                });
            }
        }
Exemplo n.º 5
0
        public override Models.ResultModel CommandforSortingNameOrigin(string command)
        {
            var baseResult = base.CommandforSortingNameOrigin(command);

            if (baseResult.Status)
            {
                // several condition in sorting -> sorting by last third of name or by family name
                var _newListNameTemp = baseResult
                                       .Data
                                       .ListName
                                       .Select((Val, Idx) => new {
                    FullName = Val,
                    LastName = Val.Split(' ').Count() > 3 ? Val.Split(' ').ElementAt(2) + Val : Val.Split(' ').Last() + Val,
                    Index    = Idx
                })
                                       .OrderBy(l => l.LastName)
                                       .ToList();
                var newListName = _newListNameTemp.Select(x => x.FullName).ToList();

                var newRes = new Models.ResultModel
                {
                    Status = baseResult.Status,
                    Msg    = "Success Sorting Name",
                    Data   = new Models.SortingNameModel
                    {
                        FileName = "",
                        FullPath = baseResult.Data.FullPath,
                        ListName = newListName
                    }
                };


                return(newRes);
            }
            else
            {
                return(baseResult);
            }
        }
Exemplo n.º 6
0
        public virtual Models.ResultModel BuilderSortingName(Models.ResultModel model)
        {
            // if validate are success
            Models.SortingNameModel ConvertModel = new Models.SortingNameModel();
            foreach (var file in new DirectoryInfo(Path.GetDirectoryName(model.Data.FullPath)).GetFiles())
            {
                if (file.Name.ToLower().Contains("unsorted-"))
                {
                    var getExtension = file.Extension;
                    if (getExtension == ".txt")
                    {
                        if (file.Name.ToLower() == Path.GetFileName(model.Data.FullPath))
                        {
                            using (var stream = new StreamReader(file.FullName))
                            {
                                var content = stream.ReadToEnd();
                                if (!String.IsNullOrWhiteSpace(content))
                                {
                                    string[] stringSeparators = new string[] { "\r\n" };
                                    var      resList          = content.Split(stringSeparators, StringSplitOptions.None);

                                    ConvertModel.FileName = file.Name;
                                    ConvertModel.FullPath = file.FullName;
                                    ConvertModel.ListName = resList.ToList();
                                }
                            }
                        }
                    }
                }
            }

            return(new Models.ResultModel
            {
                Status = ConvertModel.ListName == null ? !model.Status : model.Status,
                Msg = "testorg",
                Data = ConvertModel
            });
        }