Ejemplo n.º 1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var userId = txtUserId.Text;
            var pass = txtPassword.Text;

            var dataModel=new EPGDataModel();
            var dbUser = dataModel.Users.Find(userId);

            if (dbUser != null)
            {
                if (dbUser.Password.Equals(pass))
                {
                    Session.Add("USER_KEY", userId);
                    Session.Add("USR_TYPE",dbUser.UserType.Trim());

                    if (dbUser.UserType.Trim().Equals("Admin"))
                        Response.Redirect("~/Admin/Dashboard.aspx");
                    else if (dbUser.UserType.Trim().Equals("User"))
                        Response.Redirect("~/Secured/index.aspx");
                }
                else
                    divMsg.Style.Add(HtmlTextWriterStyle.Display, "block");
            }
            else
                divMsg.Style.Add(HtmlTextWriterStyle.Display, "block");
        }
Ejemplo n.º 2
0
 protected void gvUsers_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     var userId = Convert.ToString(gvUsers.DataKeys[e.RowIndex].Values[0]);
     using (var dataContext = new EPGDataModel())
     {
         var user = dataContext.Users.Find(userId);
         dataContext.Users.Remove(user);
         dataContext.SaveChanges();
     }
     BindGrid();
 }
Ejemplo n.º 3
0
        protected void OnClick(object sender, EventArgs e)
        {
            using (var dataContext = new EPGDataModel())
            {
                if (!string.IsNullOrEmpty(hidRight.Value))
                {
                    var activeIds = hidRight.Value.Substring(0, hidRight.Value.Length - 1).Split(',');

                    foreach (var item in activeIds)
                    {
                        var id = Convert.ToInt64(item);
                        var dbEntry = dataContext.ActiveChannels.FirstOrDefault(c => c.Srno.Equals(id));

                        if (dbEntry != null)
                        {
                            dbEntry.IsActive = true;
                            dataContext.Entry(dbEntry).State = EntityState.Modified;
                        }
                    }

                    dataContext.SaveChanges();

                    PopulateInactive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    PopulateActive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    lblMsg.Text = "Selection Saved!";
                }

                if (!string.IsNullOrEmpty(hidLeft.Value))
                {
                    var inActiveIds = hidLeft.Value.Substring(0, hidLeft.Value.Length - 1).Split(',');

                    foreach (var item in inActiveIds)
                    {
                        var id = Convert.ToInt64(item);
                        var dbEntry = dataContext.ActiveChannels.FirstOrDefault(c => c.Srno.Equals(id));

                        if (dbEntry != null)
                        {
                            dbEntry.IsActive = false;
                            dataContext.Entry(dbEntry).State = EntityState.Modified;
                        }
                    }

                    dataContext.SaveChanges();

                    PopulateInactive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    PopulateActive(Convert.ToInt64(ddlSourceXml.SelectedValue));
                    lblMsg.Text = "Selection Saved!";
                }

            }
        }
Ejemplo n.º 4
0
        protected void gvUsers_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row = gvUsers.Rows[e.RowIndex];
            var userId = Convert.ToString(gvUsers.DataKeys[e.RowIndex].Values[0]);
            var userName = (row.FindControl("txtName") as TextBox).Text;
            var email = (row.FindControl("txtUserEmailAddress") as TextBox).Text;
            var pass = (row.FindControl("txtPassword") as TextBox).Text;
            var type = (row.FindControl("ddlUserType") as DropDownList).SelectedValue;

            using (var dataContext = new EPGDataModel())
            {
                var user = dataContext.Users.Find(userName);

                user.UserEmailAddress = email;
                user.Password = pass;
                user.PasswordSalt = pass;
                user.UserType = type;
                try
                {
                    dataContext.Entry(user).State = EntityState.Modified;
                    dataContext.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        Console.WriteLine(
                            "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }

            }
            gvUsers.EditIndex = -1;
            BindGrid();
        }
Ejemplo n.º 5
0
        protected void btnAdd_OnClick(object sender, EventArgs e)
        {
            grid.InnerHtml = "";
            lblMsg.Text = "";
            using (var dataContext = new EPGDataModel())
            {
                var source = new SourceURL
                {
                    Url = txtSourceURLAdd.Text,
                    Type=ddlSourceType.SelectedValue,
                    IsActive = true,
                    EntryDate = DateTime.Today,
                    EntryId = Convert.ToString(Session["USER_KEY"]),
                    EntryIP = CommonFunctions.GetIpAddress()
                };
                dataContext.SourceURLs.Add(source);
                dataContext.SaveChanges();
                source.ActiveChannels = GetActiveChannels(source.Url, source.Srno);
                dataContext.SaveChanges();
            }

            lblMsg.Text = "Record added successfully!";
            BindGrid();
        }
Ejemplo n.º 6
0
 private void BindGrid()
 {
     using (var dataContext = new EPGDataModel())
     {
         gvXMLSource.DataSource = dataContext.SourceURLs.ToList();
         gvXMLSource.DataBind();
     }
 }
Ejemplo n.º 7
0
        protected void gvXMLSource_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row = gvXMLSource.Rows[e.RowIndex];
            var srno = Convert.ToInt32(gvXMLSource.DataKeys[e.RowIndex].Values[0]);
            var sourceUrl = (row.FindControl("txtSourceURL") as TextBox).Text;
            var sourceType = (row.FindControl("ddlGridSourceType") as DropDownList).SelectedValue;

            using (var dataContext = new EPGDataModel())
            {
                var source = dataContext.SourceURLs.Find(srno);

                source.Url = sourceUrl;
                source.Type = sourceType;
                source.EntryDate = DateTime.Today;
                source.IsActive = true;
                try
                {
                    dataContext.Entry(source).State = EntityState.Modified;
                    dataContext.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        Console.WriteLine(
                            "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }

            }
            gvXMLSource.EditIndex = -1;
            BindGrid();
        }
Ejemplo n.º 8
0
 protected void gvXMLSource_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     var srno = Convert.ToInt64(gvXMLSource.DataKeys[e.RowIndex].Values[0]);
     using (var dataContext = new EPGDataModel())
     {
         var source = dataContext.SourceURLs.Find(srno);
         dataContext.ActiveChannels.RemoveRange(source.ActiveChannels);
         dataContext.SourceURLs.Remove(source);
         dataContext.SaveChanges();
     }
     BindGrid();
 }
Ejemplo n.º 9
0
        protected void gvXMLSource_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex != gvXMLSource.EditIndex)
            {
                (e.Row.Cells[3].Controls[2] as ImageButton).Attributes["onclick"] =
                    "if(!confirm('Do you want to delete the record?')){ return false; };";

                var hypChannel = (HyperLink)e.Row.FindControl("hypChannel");
                if (hypChannel != null)
                {
                    var srno = Convert.ToInt64(gvXMLSource.DataKeys[e.Row.RowIndex].Values[0]);
                    using (var dataContext=new EPGDataModel())
                    {
                        var channelList =
                            dataContext.ActiveChannels.Where(c => c.SourceId.Equals(srno) && c.IsActive).ToList();

                        if (channelList.Count > 0)
                        {
                            hypChannel.CssClass = "btn btn-success";
                            hypChannel.ToolTip = channelList.Count +" channels active!";
                        }
                        else
                        {

                            ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "blink(\"a[id^='MainContent_gvXMLSource_hypChannel_']\", -1, 1000);", true);

                        }
                    }

                }

            }
        }
Ejemplo n.º 10
0
        protected void btnImport_OnClick(object sender, EventArgs e)
        {
            if (fileUploadCtl.HasFile)
            {
                var fileName = Path.GetFileName(fileUploadCtl.FileName);

                fileUploadCtl.PostedFile.SaveAs(Server.MapPath(@"../ImportedList/"+fileName));

                var lines = File.ReadAllText(Server.MapPath(@"../ImportedList/" + fileName));

                var listOfUrls = lines.Split(',');

                foreach (var url in listOfUrls)
                {
                    string type = string.Empty;

                    switch (url.Substring(url.LastIndexOf('.'), 4).ToLower())
                    {
                        case ".zip":
                            type = "Zip";
                            break;
                        case ".xml":
                            type = "Xml";
                            break;
                    }

                    var sourceUrl = new SourceURL
                    {
                        Url = url,
                        Type = type,
                        EntryIP= CommonFunctions.GetIpAddress(),
                        EntryDate = DateTime.Today,
                        IsActive= true,
                        EntryId = Convert.ToString(Session["USER_KEY"]),
                    };

                    try
                    {
                        using (var dataContext = new EPGDataModel())
                        {
                            dataContext.SourceURLs.Add(sourceUrl);
                            dataContext.SaveChanges();
                            sourceUrl.ActiveChannels = GetActiveChannels(sourceUrl.Url, sourceUrl.Srno);
                            dataContext.SaveChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        lblMsg.Text = "One or more Urls in text files already exsists in database.";
                    }

                }
                lblMsg.Text = "List Imported successfully!";
                BindGrid();
            }
        }
Ejemplo n.º 11
0
        void PopulateSources()
        {
            using (var dataContext=new EPGDataModel())
            {
                ListItem[] sourceList = dataContext.SourceURLs.Select(ct => new ListItem { Value = ct.Srno.ToString(), Text = ct.Url }).ToArray();

                foreach (var item in sourceList)
                {
                    item.Text = item.Text.Substring(item.Text.LastIndexOf("/", StringComparison.Ordinal) + 1);

                    if (item.Text.Contains("?"))
                        item.Text = item.Text.Substring(0, item.Text.LastIndexOf("?", StringComparison.Ordinal));
                }

                ddlSourceXml.Items.Clear();
                ddlSourceXml.Items.AddRange(sourceList);

                ddlSourceXml.ClearSelection();

                if (Request.QueryString["id"] != null)
                {
                    ddlSourceXml.Items.FindByValue(Request.QueryString["id"]).Selected = true;
                    ddlSourceXml.Enabled = false;
                }
                else
                    ddlSourceXml.SelectedIndex = 0;
            }
        }
Ejemplo n.º 12
0
        private void BindGrid()
        {
            var dataContext = new EPGDataModel();

            var searchList = dataContext.XmlImports.OrderByDescending(x => x.ImportDate).ToList();

            if (!string.IsNullOrEmpty(txtChannelName.Text))
                searchList = searchList.Where(c => c.XmlFileName.ToLower().Contains(txtChannelName.Text.ToLower())).ToList();

            if (!string.IsNullOrEmpty(txtImportDtFrom.Text))
            {
                var importDtFrom = Convert.ToDateTime(txtImportDtFrom.Text).Date;
                searchList = searchList.Where(c => c.ImportDate.Date >= importDtFrom).ToList();
            }

            if (!string.IsNullOrEmpty(txtImportDtTo.Text))
            {
                var importDtTo = Convert.ToDateTime(txtImportDtTo.Text).Date;
                searchList = searchList.Where(c => c.ImportDate.Date <= importDtTo).ToList();
            }

            var dtSearch = ToDataTable<XmlImport>(searchList);

            if (dtSearch!=null)
            {
                Session.Add("GetDataTable", dtSearch);
                ucPaging.BindPaging(gvFiles, dtSearch, ucPaging.PageNo, "txt",
                    Convert.ToString(ViewState["sortDirection"]), Convert.ToString(ViewState["sortColumn"]));
                BindBottomPaging(ucPaging, ucPaging1);
            }
        }
Ejemplo n.º 13
0
        public static void ProcessXml()
        {
            XmlConfigurator.Configure();

            SourceXmlList.Clear();
            OutputXmlList.Clear();

            using (var dataContext = new EPGDataModel())
            {
                List<SourceURL> listToProcess=new List<SourceURL>();
                try
                {
                    logger.Info("1.> Getting List of Source from Database");
                    listToProcess = dataContext.SourceURLs.Where(s => s.IsActive).ToList();
                    logger.Info("2.> Retrived List of Source from Database. Total Sources - " + listToProcess.Count);
                }
                catch (Exception exDataException)
                {
                    logger.Error("Error occured while retriving List of Source from Database. Error Message - " + exDataException.Message);

                    if(exDataException.InnerException !=null)
                        logger.Error("Inner Exception - " + exDataException.InnerException.Message);
                }

                foreach (var source in listToProcess)
                {
                    try
                    {
                        logger.Info("ravi");
                        logger.Info("// Proccessing Source - " + source.Url);
                        var extension = source.Type.ToLower().Equals("zip") ? ".zip" : ".xml";
                        logger.Info("// File extension is - " + extension);

                        var fileName = DownloadFile(source.Url, extension);
                        logger.Info("// File Name extension is - " + fileName);

                        if (!string.IsNullOrEmpty(fileName))
                        {
                            if (Path.GetExtension(fileName).Contains(".zip")) //Zip Archive.
                            {
                                logger.Info("// Source is a zip archive.");
                                //extract xmls from zip archive.
                                ExtractFileToDirectory(fileName, SourceXmlFolderPath);

                                logger.Info("// Çompleted extraction of zip archive. Total files extracted - "+ SourceXmlList.Count);

                            }
                            else if (Path.GetExtension(fileName).Contains(".xml")) //Single Xml.
                            {
                                logger.Info("// Source is a xml file.");
                                //ClearDirectory(Environment.CurrentDirectory + @"\SourceXmlFiles\");

                                try
                                {
                                    logger.Info("// Checking if file " + Path.GetFileName(fileName) + " alredy exists in Source Xml Folder.");
                                    if (File.Exists(SourceXmlFolderPath + Path.GetFileName(fileName)))
                                        File.Delete(SourceXmlFolderPath + Path.GetFileName(fileName));

                                    logger.Info("// Copying File " + Path.GetFileName(fileName) + " to Source Xml Folder.");
                                    File.Copy(fileName, SourceXmlFolderPath + Path.GetFileName(fileName));
                                    logger.Info("// Completed Copying File " + Path.GetFileName(fileName) + " to Source Xml Folder.");
                                    SourceXmlList.Add(SourceXmlFolderPath + Path.GetFileName(fileName));
                                    logger.Info("// Çompleted Adding file to SourceXmlList - Total Count is - " + SourceXmlList.Count);
                                }
                                catch (Exception singleXmlException)
                                {
                                     logger.Error("Error occured while copying single xml. Error - " + singleXmlException.Message);

                                    if(singleXmlException.InnerException !=null)
                                        logger.Error("Inner Exception Error - " + singleXmlException.InnerException.Message);
                                }

                            }

                            foreach (var xmlFile in SourceXmlList)
                            {

                                var sourceUri = new Uri(source.Url);
                                var newChannelName = string.Empty;
                                var newOffset = 0;

                                try
                                {
                                    newChannelName = HttpUtility.ParseQueryString(sourceUri.Query).Get("channelname");
                                    int.TryParse(HttpUtility.ParseQueryString(sourceUri.Query).Get("offset"), out newOffset);
                                }
                                catch (Exception)
                                {
                                    // ignored
                                }

                                logger.Info("Calling  GenerateOutputXml(" + xmlFile + ", " + newChannelName + ", " + newOffset + ")");

                                OutputXmlList.AddRange(ParserEngine.GenerateOutputXml(xmlFile, source.Srno, out _startDate, out _stopDate, newChannelName, newOffset));
                                //GenerateOutputXml(xmlFile, newChannelName, newOffset);

                                logger.Info("Completed  GenerateOutputXml(" + xmlFile + ", " + newChannelName + ", " + newOffset + ")");
                            }
                        }

                        SourceXmlList.Clear();
                    }
                    catch (Exception)
                    {

                    }
                }

            }

            Console.WriteLine("Xml Generation Completed");

            if (OutputXmlList != null)
            {
                if (OutputXmlList.Count > 0)
                {
                    logger.Info("Updating Database...");
                    Console.WriteLine("Updating Database");

                    foreach (var outFile in OutputXmlList)
                    {
                        var fileDetails = outFile.Split(',');

                        try
                        {
                            using (var dataContext = new EPGDataModel())
                            {
                                var fileName = Path.GetFileName(fileDetails[0]);
                                var dbEntry =
                                    dataContext.XmlImports.Where(
                                        x => x.XmlFileName.Trim().ToLower().Equals(fileName.Trim().ToLower())).ToList();

                                try
                                {
                                    if (dbEntry != null)
                                    {
                                        if (dbEntry.Count > 0)
                                        {
                                            dataContext.XmlImports.RemoveRange(dbEntry);
                                            dataContext.SaveChanges();
                                        }
                                    }
                                }
                                catch (Exception deleteException)
                                {
                                    logger.Error("Error occured while Deleting. Error Message - " +
                                        deleteException.Message);

                                    if (deleteException.InnerException != null)
                                        logger.Error("Error InnerException - " +
                                                 deleteException.InnerException.Message);
                                }

                                try
                                {
                                    var xmlImport = new XmlImport
                                    {
                                        Url = "../Output/" + Path.GetFileName(fileDetails[0]),
                                        EpgStartDt = _startDate,
                                        EpgEndDt = _stopDate,
                                        ImportDate = DateTime.Now,
                                        XmlFileName = Path.GetFileName(fileDetails[0]),
                                        Url2 = !string.IsNullOrEmpty(fileDetails[3]) ? fileDetails[3] : "",
                                        SourceUrl = !string.IsNullOrEmpty(fileDetails[4]) ? fileDetails[4] : ""
                                    };

                                    dataContext.XmlImports.Add(xmlImport);
                                    dataContext.SaveChanges();
                                }
                                catch (Exception xmlDataImportException)
                                {
                                    logger.Error("Error occured while adding new entry to Database. Error Message - " +
                                        xmlDataImportException.Message);

                                    if (xmlDataImportException.InnerException != null)
                                        logger.Error("Error InnerException - " +
                                                 xmlDataImportException.InnerException.Message);

                                }

                            }
                        }
                        catch (Exception updateException)
                        {
                            logger.Error("Error occured while running UpdatE Database function. Error Message - " +
                            updateException.Message);

                            if (updateException.InnerException != null)
                                logger.Error("Error InnerException - " +
                                         updateException.InnerException.Message);
                        }

                    }

                    Console.WriteLine("Done Updating Database");
                    logger.Info("Done Updating Database");
                }
            }
        }
Ejemplo n.º 14
0
        protected void Insert(object sender, EventArgs e)
        {
            using (var dataContext = new EPGDataModel())
            {
                var dbEntry = dataContext.Users.Where(u => u.UserName.ToLower().Equals(txtName.Text.ToLower())).FirstOrDefault();

                if (dbEntry != null)
                {
                    lblMsg.Text = "User " + txtName.Text + " already exsists!";
                    return;
                }

                var user = new User
                {
                    UserName=txtName.Text,
                    UserEmailAddress=txtUserEmailAddress.Text,
                    Password = txtPassword.Text,
                    UserType= ddlUserType.SelectedValue,
                    IsActive=true,
                    DateCreated=DateTime.Today,
                };
                dataContext.Users.Add(user);
                dataContext.SaveChanges();
            }

            BindGrid();
            lblMsg.Text = "User " + txtName.Text + " added successfully!";
            ClearForm();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Generates main output xml.
        /// </summary>
        /// <param name="sourceXml"></param>
        /// <param name="newChannelName"></param>
        /// <param name="newOffset"></param>
        private void GenerateOutputXml(string sourceXml,long srno, string newChannelName=null, int newOffset=0)
        {
            var document = XDocument.Load(sourceXml);

            var _tv = new tv();
            var channelNode1 = document.Descendants("channel");

            var xElements = channelNode1 as XElement[] ?? channelNode1.ToArray();
            for (var i=0;i<=xElements.Length-1;i++)
            {
                var elementChannel = xElements[i];
                var elementchannelId = elementChannel.Attributes("id").First().Value;

                var progArray = document.Descendants("programme")
                    .Where(x => (string)x.Attribute("channel").Value == elementchannelId);

                #region Channel...
                string id = string.Empty;
                string channelName = string.Empty;
                const string formatString = "yyyyMMddHHmmss";
                var outputFileName = string.Empty;

                #region Channel Name...

                if (!string.IsNullOrEmpty(newChannelName))
                {
                    channelName = newChannelName;
                    try
                    {
                        id = xElements[i].Attributes("id").First().Value;
                        outputFileName = xElements[i].Value;

                        if (string.IsNullOrEmpty(channelName))
                        {
                            outputFileName = xElements[i].Attributes("display-name").First().Value;
                        }
                    }
                    catch (Exception)
                    {
                        var channelNode = document.Descendants("channel").First();
                        outputFileName = channelNode.Value;
                        if (string.IsNullOrEmpty(channelName))
                        {
                            outputFileName = xElements[i].Attributes("display-name").First().Value;
                        }
                    }
                }
                else
                {
                    try
                    {
                        id = xElements[i].Attributes("id").First().Value;

                        channelName = xElements[i].Value;

                        //Nov-19
                        if (channelName.Contains("http://"))
                        {
                            channelName = channelName.Substring(0, channelName.IndexOf("http:", StringComparison.Ordinal));
                        }

                        if (string.IsNullOrEmpty(channelName))
                        {
                            channelName = xElements[i].Attributes("display-name").First().Value;
                        }
                    }
                    catch (Exception)
                    {
                        var channelNode = document.Descendants("channel").First();
                        channelName = channelNode.Value;
                        if (string.IsNullOrEmpty(channelName))
                        {
                            channelName = xElements[i].Attributes("display-name").First().Value;
                        }
                    }

                    outputFileName = channelName;

                }

                #endregion Channel Name...

                 //1.> Nov-19 - Remove any Illegeal characters from filename.
                 //2.> Nov-25 - Task ID:  1647 (duplicate channel bug ).
                if (outputFileName.Contains("http://"))
                {
                    outputFileName = outputFileName.Substring(0, outputFileName.IndexOf("http://", StringComparison.Ordinal));
                }

                outputFileName = GetSafeFilename(outputFileName);

                //Check if current channe is active.
                using (var dataContext=new EPGDataModel())
                {
                    var channelList =
                        dataContext.SourceURLs.Find(srno)
                            .ActiveChannels.FirstOrDefault(c => c.ChannelName.Equals(outputFileName) && c.IsActive);

                    if (channelList == null)
                        continue;
                }
                //End

                var tvChannel = new tvChannel
                {
                   id = id,
                   displayname = channelName,
                };

                _tv.channel = tvChannel;

                #endregion Channel...

                #region Programme Nodes...

                var sourceXElements = progArray.ToList();

                //If no programe nodes move to next channel.
                if (sourceXElements.Count == 0)
                    continue;

                tvProgramme[] _tvProgrammes = new tvProgramme[sourceXElements.Count];

                var iNodeCount = 0;

                foreach (var item in sourceXElements)
                {
                    #region Minutes...

                    var startTime = item.Attributes("start").First().Value;
                    var epgStartOffset = startTime;

                    if (startTime.Contains("+"))
                        startTime = startTime.Substring(0, startTime.IndexOf('+'));

                    var stopTime = item.Attributes("stop").First().Value;

                    if (stopTime.Contains("+"))
                        stopTime = stopTime.Substring(0, stopTime.IndexOf('+'));

                    var duration = DateTime.ParseExact(stopTime.Trim(), formatString, CultureInfo.InvariantCulture).Subtract(DateTime.ParseExact(startTime.Trim(), formatString, CultureInfo.InvariantCulture)).TotalMinutes;

                    #endregion Minutes...

                    #region Credits...

                    tvProgrammeName[] tvProgrammeNames = null;

                    if (item.Element("credits") != null)
                    {

                        XElement creditElement = item.Element("credits");

                        if (creditElement != null)
                        {
                            var  creditsArray = creditElement.Nodes().ToList();

                            tvProgrammeNames = new tvProgrammeName[creditsArray.Count];

                            for (var x=0;x<= creditsArray.Count-1;x++)
                            {
                                XNode node = creditsArray[x];
                                XElement element = (XElement) node;

                                tvProgrammeNames[x] = new tvProgrammeName
                                {

                                    function = element.Name.LocalName,
                                    Value = element.Value
                                };
                            }

                        }
                    }

                    #endregion Credits...

                    #region Image...

                    var imageSrc = "";

                    if (item.Element("icon") != null)
                    {
                        var imgElement = item.Element("icon");

                        if (imgElement != null && imgElement.Attribute("src") != null)
                        {
                            imageSrc = imgElement.Attribute("src").Value;
                        }
                    }

                    #endregion Image...

                    _tvProgrammes[iNodeCount] = new tvProgramme
                    {
                        channel = channelName,
                        start = CommonFunctions.GetDateAddingOffset(item.Attributes("start").First().Value, newOffset),
                        stop = CommonFunctions.GetDateAddingOffset(item.Attributes("stop").First().Value, newOffset),

                        length = new tvProgrammeLength
                        {
                            Value = ushort.Parse(Convert.ToString(duration, CultureInfo.InvariantCulture)),
                            units = "minutes"
                        },
                        title = item.Element("title") != null ? item.Element("title").Value : "",
                        category = item.Element("category") != null ? item.Element("category").Value : "",
                        desc = item.Element("desc") != null ? item.Element("desc").Value : "",
                        credits = tvProgrammeNames,
                        image = imageSrc
                    };

                    iNodeCount++;
                }

                _tv.programme = _tvProgrammes;

                var startDt = _tvProgrammes.First().start;

                if (startDt.Contains("+"))
                    startDt = startDt.Substring(0, startDt.IndexOf('+')).Trim();

                var stopDt = _tvProgrammes.Reverse().First().stop;

                if (stopDt.Contains("+"))
                    stopDt = stopDt.Substring(0, stopDt.IndexOf('+')).Trim();

                try
                {
                    _startDate = DateTime.ParseExact(startDt, formatString, CultureInfo.InvariantCulture);
                    _stopDate = DateTime.ParseExact(stopDt, formatString, CultureInfo.InvariantCulture);
                }
                catch (Exception)
                {
                }

                #endregion Programme Nodes...

                _tv.Save(Server.MapPath("../Output/" + outputFileName + ".xml"));

                #region Generate Additional Xml...

                var _tv2 = new Code.SecondOutput.tv();
                Code.SecondOutput.tvProgramme[] _tvProgrammes2 = new Code.SecondOutput.tvProgramme[sourceXElements.Count];

                iNodeCount = 0;
                foreach (var item in sourceXElements)
                {
                    #region Minutes...

                    var startTime = item.Attributes("start").First().Value;
                    var epgStartOffset = startTime;

                    if (startTime.Contains("+"))
                        startTime = startTime.Substring(0, startTime.IndexOf('+'));

                    var stopTime = item.Attributes("stop").First().Value;

                    if (stopTime.Contains("+"))
                        stopTime = stopTime.Substring(0, stopTime.IndexOf('+'));

                    var duration = DateTime.ParseExact(stopTime.Trim(), formatString, CultureInfo.InvariantCulture).Subtract(DateTime.ParseExact(startTime.Trim(), formatString, CultureInfo.InvariantCulture)).TotalMinutes;

                   // var date = DateTime.ParseExact(startTime, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);

                    #endregion Minutes...

                    _tvProgrammes2[iNodeCount] = new Code.SecondOutput.tvProgramme()
                    {
                        channel = channelName,
                        start = CommonFunctions.GetDateAddingOffset(item.Attributes("start").First().Value, newOffset),
                        stop = CommonFunctions.GetDateAddingOffset(item.Attributes("stop").First().Value, newOffset),
                        title = item.Element("title") != null ? item.Element("title").Value : "",
                        desc = item.Element("desc") != null ? item.Element("desc").Value : "",
                        subTitle = item.Element("sub-title") != null ? item.Element("sub-title").Value : "",
                        date = DateTime.Today,
                        originid = "",//Find
                        reserve = "no"
                    };

                    iNodeCount++;
                }

                _tv2.programme = _tvProgrammes2;

                _tv2.Save(Server.MapPath("../Output/" + outputFileName +"_additional"+ ".xml"));

                #endregion Generate Additional Xml...

                 _outputXmlList.Add("../Output/" + outputFileName + ".xml" + ","
                     + _startDate.Date.ToShortDateString() + ","
                     + _stopDate.Date.ToShortDateString() + ","
                     + "../Output/" + outputFileName + "_additional" + ".xml" + ","
                     + "../SourceXmlFiles/"+ Path.GetFileName(sourceXml)
                     );
            }
        }
Ejemplo n.º 16
0
        void PopulateActive(long srno = 0)
        {
            using (var dataContext = new EPGDataModel())
            {
                var dt = dataContext.ActiveChannels.Where(s => s.IsActive).ToList();

                if (srno != 0)
                    dt = dt.Where(s => s.SourceId.Equals(srno)).ToList();

                undo_redo_to.DataSource = dt;
                undo_redo_to.DataTextField = "ChannelName";
                undo_redo_to.DataValueField = "Srno";
                undo_redo_to.DataBind();
            }
        }
Ejemplo n.º 17
0
        protected void btnGetenerate_OnClick(object sender, EventArgs e)
        {
            _sourceXmlList.Clear();
             _outputXmlList.Clear();
            _additionalOutputXmlList.Clear();
            lblMsg.Text = "";
            grid.InnerHtml = "";

            foreach (GridViewRow row in gvXMLSource.Rows)
            {
                var chk = (row.FindControl("chkSelect") as CheckBox);
                if (chk != null && chk.Checked)
                {
                    var srno = Convert.ToInt32(gvXMLSource.DataKeys[row.RowIndex].Values[0]);

                    using (var dataContext =new EPGDataModel())
                    {
                        var source = dataContext.SourceURLs.Find(srno);
                        if (source != null)
                        {
                            var extension = source.Type.ToLower().Equals("zip") ? ".zip" : ".xml";
                            var fileName = DownloadFile(source.Url, extension);
                            //MODIFY HERE
                            if (!string.IsNullOrEmpty(fileName))
                            {
                                if (Path.GetExtension(fileName).Contains(".zip")) //Zip Archive.
                                {
                                    //extract xmls from zip archive.
                                    ExtractFileToDirectory(fileName, Server.MapPath(@"~/SourceXmlFiles/"));
                                }
                                else if (Path.GetExtension(fileName).Contains(".xml")) //Single Xml.
                                {
                                    //ClearDirectory(Server.MapPath(@"~/SourceXmlFiles/"));

                                    if (File.Exists(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName))))
                                        File.Delete(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));

                                    File.Copy(Server.MapPath(fileName),
                                        Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));

                                    _sourceXmlList.Add(Server.MapPath(@"~/SourceXmlFiles/" + Path.GetFileName(fileName)));
                                }

                                 foreach (var xmlFile in _sourceXmlList)
                                 {

                                     var sourceUri = new Uri(source.Url);
                                     var newChannelName = string.Empty;
                                     var newOffset = 0;

                                     try
                                     {
                                         newChannelName = HttpUtility.ParseQueryString(sourceUri.Query).Get("channelname");
                                         int.TryParse(HttpUtility.ParseQueryString(sourceUri.Query).Get("offset"), out newOffset);
                                     }
                                     catch (Exception)
                                     {
                                         // ignored
                                     }

                                  _outputXmlList.AddRange(ParserEngine.GenerateOutputXml(xmlFile,source.Srno,out _startDate,out _stopDate,  newChannelName, newOffset));
                                   //GenerateOutputXml(xmlFile,source.Srno, newChannelName, newOffset);
                                 }
                            }
                        }
                    }
                }

                _sourceXmlList.Clear();
            }

            if (_outputXmlList != null)
            {
                if (_outputXmlList.Count > 0)
                {
                    grid.InnerHtml += "<span style='text-align:center;' class='alert-danger'>Generated Output Xml(s)</span>";
                    grid.InnerHtml += "<table style='width:50%;' class='table table-striped table-bordered table-hover table-condensed table-mptt'><th class='sortable'>Srno</th><th class='sortable'>Output Xml (click to view xml)</th><th class='sortable'>EPG Start Date</th><th class='sortable'>EPG End Date</th><tbody>";

                    var iCount = 1;
                    foreach (var outFile in _outputXmlList)
                    {
                        var fileDetails = outFile.Split(',');
                        grid.InnerHtml += "<tr><td>" + iCount + "</td><td><a href='XmlTransformation.aspx?file=" + fileDetails[0] + "' target='_blank' class='btn-link'> " + Path.GetFileName(fileDetails[0]) + "</a></td>";
                        grid.InnerHtml += "<td>" + fileDetails[1] + "</td><td>" + fileDetails[2] +"</td></tr>";

                        try
                        {
                            using (var dataContext = new EPGDataModel())
                            {
                                var fileName = Path.GetFileName(fileDetails[0]);
                                var dbEntry =
                                    dataContext.XmlImports.Where(
                                        x => x.XmlFileName.Trim().ToLower().Equals(fileName.Trim().ToLower())).ToList();

                                if (dbEntry != null)
                                {
                                    if (dbEntry.Count > 0)
                                    {
                                        dataContext.Database.ExecuteSqlCommand(
                                            "DELETE FROM XmlImport WHERE XmlFileName='" + fileName + "'");
                                    }
                                }

                                var xmlImport = new XmlImport
                                {
                                    Url = "../Output/" + Path.GetFileName(fileDetails[0]),
                                    EpgStartDt = _startDate,
                                    EpgEndDt = _stopDate,
                                    ImportDate = DateTime.Now,
                                    XmlFileName = Path.GetFileName(fileDetails[0]),
                                    Url2 = !string.IsNullOrEmpty(fileDetails[3])?fileDetails[3]:"",
                                    SourceUrl = !string.IsNullOrEmpty(fileDetails[4]) ? fileDetails[4] : "",
                                };

                                dataContext.XmlImports.Add(xmlImport);
                                dataContext.SaveChanges();
                            }
                        }
                        catch (Exception)
                        {

                        }

                        iCount++;
                    }

                    grid.InnerHtml += "</tbody></table>";
                    lblMsg.Text = "Xml(s) generated successfully!";

                }
            }
        }
Ejemplo n.º 18
0
 private void BindGrid()
 {
     using (var dataContext = new EPGDataModel())
     {
         var currentUser = Convert.ToString(Session["USER_KEY"]).Trim().ToLower();
         gvUsers.DataSource = dataContext.Users.Where(u => u.UserName.Trim().ToLower() != currentUser).ToList();
         gvUsers.DataBind();
     }
 }