示例#1
0
        public async Task Basic_Post_And_Delete_EPub()
        {
            var ePub = new EPub
            {
                Title      = "example0",
                Language   = "en-US",
                Filename   = "filename_example",
                Author     = "author_example",
                Publisher  = "publisher_example",
                SourceId   = "mediaId_example",
                SourceType = ResourceType.Media
            };

            var postResult = await _controller.PostEPub(ePub);

            Assert.IsType <CreatedAtActionResult>(postResult.Result);

            var deleteResult = await _controller.DeleteEPub(ePub.Id);

            Assert.Equal(ePub, deleteResult.Value);

            var getResult = await _controller.GetEPub(ePub.Id);

            Assert.Equal(Status.Deleted, getResult.Value.IsDeletedStatus);
        }
示例#2
0
        public async Task Post_Invalid_and_Valid_EPubs()
        {
            var ePub = new EPub
            {
                Title    = "example0",
                Language = "en-US"
            };

            var postResult = await _controller.PostEPub(ePub);

            Assert.IsType <BadRequestObjectResult>(postResult.Result);

            ePub.Filename = "filename_example";
            ePub.Author   = "author_example";

            postResult = await _controller.PostEPub(ePub);

            Assert.IsType <BadRequestObjectResult>(postResult.Result);

            ePub.Publisher  = "publisher_example";
            ePub.SourceId   = "mediaId_example";
            ePub.SourceType = ResourceType.Media;

            postResult = await _controller.PostEPub(ePub);

            Assert.IsType <CreatedAtActionResult>(postResult.Result);
        }
示例#3
0
        public async Task Basic_Post_Put_Get_EPub()
        {
            var ePub = new EPub
            {
                Title      = "example0",
                Language   = "en-US",
                Filename   = "filename_example",
                Author     = "author_example",
                Publisher  = "publisher_example",
                SourceId   = "mediaId_example",
                SourceType = ResourceType.Media
            };

            var postResult = await _controller.PostEPub(ePub);

            Assert.IsType <CreatedAtActionResult>(postResult.Result);

            var getResult = await _controller.GetEPub(ePub.Id);

            Assert.Equal(ePub, getResult.Value);

            ePub.Title = "new title";

            var putResult = await _controller.PutEPub(ePub.Id, ePub);

            Assert.IsType <NoContentResult>(putResult);

            getResult = await _controller.GetEPub(ePub.Id);

            Assert.Equal(ePub, getResult.Value);
            Assert.Equal(PublishStatus.Published, getResult.Value.PublishStatus);
            Assert.Equal(Visibility.Visible, getResult.Value.Visibility);
        }
示例#4
0
        public List <EProduct> Listar(int local, string tipo)
        {
            List <EProduct> lista = new List <EProduct>();

            string sql = "SELECT PR.ProductId, PR.Name, PR.Description,PR.Price, PR.type, PR.Image, PR.OverallTime, P.PubId, P.Name as Local " +
                         " FROM Products PR INNER JOIN Pubs P ON PR.PubId = P.PubId " +
                         " Where P.PubId = @pubId AND type = @type ";

            try
            {
                using (SqlConnection con = new SqlConnection(cadenaconexion))
                {
                    con.Open();
                    using (SqlCommand com = new SqlCommand(sql, con))
                    {
                        com.Parameters.Add(new SqlParameter("@pubId", local));
                        com.Parameters.Add(new SqlParameter("@type", tipo));

                        using (SqlDataReader dr = com.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                EProduct ve = new EProduct();

                                ve.id          = Convert.ToInt32(dr[0]);
                                ve.name        = dr[1].ToString();
                                ve.description = dr[2].ToString();
                                ve.price       = Convert.ToDouble(dr[3].ToString());
                                ve.type        = dr[4].ToString();
                                ve.image       = dr[5].ToString();
                                ve.overallTime = dr.GetTimeSpan(6);

                                EPub oPub = new EPub()
                                {
                                    id   = Convert.ToInt32(dr[7]),
                                    name = dr[8].ToString()
                                };

                                ve.pub = oPub;
                                lista.Add(ve);
                            }
                            dr.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(lista);
        }
示例#5
0
        public async Task Put_Invalid_EPubs()
        {
            var ePub = new EPub
            {
                Title      = "example0",
                Language   = "en-US",
                Filename   = "filename_example",
                Author     = "author_example",
                Publisher  = "publisher_example",
                SourceId   = "mediaId_example",
                SourceType = ResourceType.Media
            };

            var postResult = await _controller.PostEPub(ePub);

            var createdResult = postResult.Result as CreatedAtActionResult;

            Assert.NotNull(createdResult);

            ePub.Title    = string.Empty;
            ePub.Filename = string.Empty;

            var putResult = await _controller.PutEPub(ePub.Id, ePub);

            var badRequestResult = putResult as BadRequestObjectResult;

            Assert.NotNull(badRequestResult);

            ePub.Title     = "example0";
            ePub.Filename  = "filename_example";
            ePub.Author    = string.Empty;
            ePub.Publisher = string.Empty;

            putResult = await _controller.PutEPub(ePub.Id, ePub);

            badRequestResult = putResult as BadRequestObjectResult;

            Assert.NotNull(badRequestResult);

            ePub.Author    = "author_example";
            ePub.Publisher = "publisher_example";

            putResult = await _controller.PutEPub(ePub.Id, ePub);

            var noContentResult = putResult as NoContentResult;

            Assert.NotNull(noContentResult);
        }
示例#6
0
        public List <EPub> Listar(string name)
        {
            List <EPub> lista = new List <EPub>();

            string sql = "SELECT P.PubId,P.Name,P.Description,P.Ruc,P.Address,P.PhoneNumber,P.Email,P.Latitude,P.Longitude " +
                         "FROM Pubs P Where((@name = '') OR(UPPER(P.Name) like '%' + UPPER(@name))) ";

            try
            {
                using (SqlConnection con = new SqlConnection(cadenaconexion))
                {
                    using (SqlCommand com = new SqlCommand(sql, con))
                    {
                        com.Parameters.Add(new SqlParameter("@name", name));

                        con.Open();
                        using (SqlDataReader dr = com.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                EPub ve = new EPub();

                                ve.id          = Convert.ToInt32(dr[0]);
                                ve.name        = dr[1].ToString();
                                ve.description = dr[2].ToString();
                                ve.ruc         = dr[3].ToString();
                                ve.address     = dr[4].ToString();
                                ve.phoneNumber = dr[5].ToString();
                                ve.email       = dr[6].ToString();
                                ve.latitude    = dr[7].ToString();
                                ve.longitude   = dr[8].ToString();
                                lista.Add(ve);
                            }
                            dr.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(lista);
        }
示例#7
0
        public async Task Put_EPub_Not_Found()
        {
            var ePub = new EPub
            {
                Id         = "not_existing",
                Title      = "example0",
                Language   = "en-US",
                Filename   = "filename_example",
                Author     = "author_example",
                Publisher  = "publisher_example",
                SourceId   = "mediaId_example",
                SourceType = ResourceType.Media
            };

            var putResult = await _controller.PutEPub(ePub.Id, ePub);

            Assert.IsType <NotFoundResult>(putResult);
        }
示例#8
0
        public async Task <ActionResult <List <EPubSceneData> > > GetEpubData(string mediaId, string language)
        {
            var   media = _context.Medias.Find(mediaId);
            Video video = await _context.Videos.FindAsync(media.VideoId);

            if (video.SceneData == null)
            {
                return(NotFound());
            }

            EPub epub = new EPub
            {
                Language   = language,
                SourceType = ResourceType.Media,
                SourceId   = mediaId
            };

            var captions = await _captionQueries.GetCaptionsAsync(media.VideoId, epub.Language);

            return(GetSceneData(video.SceneData["Scenes"] as JArray, captions));
        }
示例#9
0
        public async Task Put_EPub_Bad_Request()
        {
            var ePub = new EPub
            {
                Id         = "not_existing",
                Title      = "example0",
                Language   = "en-US",
                Filename   = "filename_example",
                Author     = "author_example",
                Publisher  = "publisher_example",
                SourceId   = "mediaId_example",
                SourceType = ResourceType.Media
            };

            var putResult = await _controller.PutEPub("not_matching_id", ePub);

            Assert.IsType <BadRequestResult>(putResult);

            putResult = await _controller.PutEPub(null, null);

            Assert.IsType <BadRequestResult>(putResult);
        }
示例#10
0
        public async Task <ActionResult <EPub> > PostEPub(EPub ePub)
        {
            if (ePub == null)
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(ePub.Title) ||
                string.IsNullOrEmpty(ePub.Filename) ||
                string.IsNullOrEmpty(ePub.Language) ||
                string.IsNullOrEmpty(ePub.Author) ||
                string.IsNullOrEmpty(ePub.Publisher) ||
                string.IsNullOrEmpty(ePub.SourceId))
            {
                return(BadRequest("The following fields may not be empty: title, filename, language, author, publisher, sourceId"));
            }

            _context.EPubs.Add(ePub);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetEPub", new { id = ePub.Id }, ePub));
        }
示例#11
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            try
            {
                Control      _control   = (sender as Control);
                FileTypeBase _processor = null;

                if (ConfirmAction(_control.Tag.ToString()))
                {
                    txtLog.Text += "Processing " + _control.Tag.ToString() + " files:\n\n";
                    txtLog.Refresh();
                    Application.DoEvents();

                    switch (_control.Name)
                    {
                    case "btnProcessEPub":
                        _processor = new EPub();

                        break;

                    case "btnProcessMP3":
                        _processor = new MP3();
                        break;

                    default:
                        return;
                    }
                    _processor.ProcessFolder(txtDirSource.Text, chkSubfolders.Checked, chkTra.Checked, txtLog);
                    txtLog.Text += "\n\n";
                    txtLog.Refresh();
                    Application.DoEvents();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + "=================" + ex.ToString());
            }
        }
示例#12
0
        public async Task <IActionResult> PutEPub(string id, EPub ePub)
        {
            if (ePub == null || id != ePub.Id)
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(ePub.Title) ||
                string.IsNullOrEmpty(ePub.Filename) ||
                string.IsNullOrEmpty(ePub.Language) ||
                string.IsNullOrEmpty(ePub.Author) ||
                string.IsNullOrEmpty(ePub.Publisher) ||
                string.IsNullOrEmpty(ePub.SourceId))
            {
                return(BadRequest("The following fields may not be empty: title, filename, language, author, publisher, sourceId"));
            }

            _context.Entry(ePub).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.EPubs.Any(e => e.Id == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#13
0
        public async Task Basic_Post_Put_Get_EPub()
        {
            var ePub = new EPub
            {
                Title      = "example0",
                Language   = "en-US",
                Filename   = "filename_example",
                Author     = "author_example",
                Publisher  = "publisher_example",
                SourceId   = "mediaId_example",
                SourceType = ResourceType.Media
            };

            var postResult = await _controller.PostEPub(ePub);

            var createdResult = postResult.Result as CreatedAtActionResult;

            Assert.NotNull(createdResult);

            var getResult = await _controller.GetEPub(ePub.Id);

            Assert.NotNull(getResult.Value);
            Assert.Equal(ePub, getResult.Value);

            ePub.Title = "new title";

            var putResult = await _controller.PutEPub(ePub.Id, ePub);

            var noContentResult = putResult as NoContentResult;

            Assert.NotNull(noContentResult);

            getResult = await _controller.GetEPub(ePub.Id);

            Assert.NotNull(getResult.Value);
            Assert.Equal(ePub, getResult.Value);
        }
示例#14
0
        static void Main(string[] args)
        {
            LoadSettings();

            if (args.Length > 0)
            {
                //Use comand prompt execution
                try
                {
                    string   _folder        = "";
                    bool     _recursive     = false;
                    bool     _renameFiles   = false;
                    string[] _fileTypes     = new string[2];
                    int      _fileTypeIndex = 0;
                    for (int _i = 0; _i < args.Length; _i++)
                    {
                        switch (args[_i].Replace("/", "").Replace("\\", "").Replace("-", "").ToLower())
                        {
                        case "d":     // directory
                            _folder = args[++_i];
                            break;

                        case "s":     // include subfolders
                            _recursive = true;
                            break;

                        case "r":     // rename files
                            _renameFiles = true;
                            break;

                        case "mp3":
                        case "epub":
                            _fileTypes[_fileTypeIndex++] = args[_i];
                            break;

                        case "?":
                            string _helpMessage = "Syntax: ktanc2e.exe -<switch>\n\n";
                            _helpMessage += "-d <folder>\t- source directory/folder\n";
                            _helpMessage += "-mp3\t\t- process MP3 files\n";
                            _helpMessage += "-epub\t\t- process epub files\n";
                            _helpMessage += "-s\t\t- include subdirectories\n";
                            _helpMessage += "-r\t\t- rename files\n";
                            _helpMessage += "-?\t\t- show this message\n\n";
                            _helpMessage += "Example:\t";
                            _helpMessage += "ktanc2e.exe -d c:\\MyDocs -epub -mp3 -s -r\n";
                            MessageBox.Show(_helpMessage);
                            Environment.Exit(0);
                            break;

                        default:
                            break;
                        }
                    }

                    if (String.IsNullOrEmpty(_folder) && (_fileTypes.Length <= 0))
                    {
                        args = new string[0];
                    }
                    else
                    {
                        foreach (string _fileType in _fileTypes)
                        {
                            FileTypeBase _processor = null;
                            switch (_fileType.ToUpper())
                            {
                            case "EPUB":
                                _processor = new EPub();
                                break;

                            case "MP3":
                                _processor = new MP3();
                                break;

                            default:
                                continue;
                            }
                            _processor.ProcessFolder(_folder, _recursive, _renameFiles, Console.Out);
                            MessageBox.Show("Finished Succesufy.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("==================================");
                    Console.WriteLine(ex.ToString());
                }
            }

            if (args.Length <= 0)
            {
                // Show GUI
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new frmMain());
            }
        }