コード例 #1
0
ファイル: XMLWriter.cs プロジェクト: angad/PeopleBAWX
        //Writes data to a file history XML file
        public static void WriteFileHistory(FileHistory fileHistory, string filePath)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "", "");

            dec.Encoding = "UTF-8";
            xmlDoc.AppendChild(dec);

            XmlElement body = xmlDoc.CreateElement("file_history");

            xmlDoc.AppendChild(body);

            XmlElement curr_folder = xmlDoc.CreateElement("curr_folder");

            body.AppendChild(curr_folder);
            curr_folder.InnerText = fileHistory.Curr_Folder;

            foreach (VideoFile videoFile in fileHistory.VideoFileList)
            {
                XmlElement program = xmlDoc.CreateElement("program");
                body.AppendChild(program);

                XmlElement path = xmlDoc.CreateElement("path");
                program.AppendChild(path);
                path.InnerText = videoFile.Path;

                XmlElement name = xmlDoc.CreateElement("name");
                program.AppendChild(name);
                name.InnerText = videoFile.Name;

                XmlElement ext = xmlDoc.CreateElement("ext");
                program.AppendChild(ext);
                ext.InnerText = videoFile.Ext;

                XmlElement subtitles = xmlDoc.CreateElement("subtitles");
                program.AppendChild(subtitles);
                if (videoFile.Subtitles != "")
                {
                    subtitles.InnerText = videoFile.Subtitles;
                }

                XmlElement length = xmlDoc.CreateElement("length");
                program.AppendChild(length);
                length.InnerText = videoFile.Length;
            }

            xmlDoc.Save(filePath);
        }
コード例 #2
0
ファイル: XMLReader.cs プロジェクト: angad/PeopleBAWX
        //Reads data from a file history XML file
        public static FileHistory ReadFileHistory(string filePath)
        {
            if (!File.Exists(filePath))
            {
                FileHistory fh = new FileHistory();
                XMLWriter.WriteFileHistory(fh, filePath);
            }

            FileHistory      fileHistory   = new FileHistory();
            List <VideoFile> videoFileList = new List <VideoFile>();

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(filePath);
            XmlNodeList xmlNodeList = xmldoc.ChildNodes;
            XmlNode     xmlNode     = xmlNodeList[1];

            if (xmlNode.Name == "file_history")
            {
                xmlNodeList = xmlNode.ChildNodes;

                for (int i = 0; i < xmlNodeList.Count; i++)
                {
                    if (i == 0)
                    {
                        xmlNode = xmlNodeList[0];
                        if (xmlNode.Name == "curr_folder")
                        {
                            fileHistory.Curr_Folder = xmlNode.InnerText;
                        }
                        else
                        {
                            throw new XMLFileFormatException("missing \"curr_folder\" element");
                        }
                    }
                    else
                    {
                        xmlNode = xmlNodeList[i];
                        if (xmlNode.Name == "program")
                        {
                            XmlNodeList xmlNodeList1 = xmlNode.ChildNodes;
                            VideoFile   videoFile    = new VideoFile();
                            foreach (XmlNode xmlNode1 in xmlNodeList1)
                            {
                                if (xmlNode1.Name == "path")
                                {
                                    videoFile.Path = xmlNode1.InnerXml;
                                }
                                else if (xmlNode1.Name == "name")
                                {
                                    videoFile.Name = xmlNode1.InnerXml;
                                }
                                else if (xmlNode1.Name == "ext")
                                {
                                    videoFile.Ext = xmlNode1.InnerXml;
                                }
                                else if (xmlNode1.Name == "length")
                                {
                                    videoFile.Length = xmlNode1.InnerXml;
                                }
                                else if (xmlNode1.Name == "subtitles")
                                {
                                    videoFile.Subtitles = xmlNode1.InnerXml;
                                }
                                else
                                {
                                    throw new XMLFileFormatException("unknown \"" + xmlNode1.Name + "\" element");
                                }
                            }
                            videoFileList.Add(videoFile);
                        }
                        else
                        {
                            throw new XMLFileFormatException("missing \"row\" element");
                        }
                    }
                }
                fileHistory.VideoFileList = videoFileList;
            }
            else
            {
                throw new XMLFileFormatException("missing \"file_history\" element");
            }
            return(fileHistory);
        }
コード例 #3
0
ファイル: XMLReader.cs プロジェクト: angad/PeopleBAWX
        //Reads data from a file history XML file
        public static FileHistory ReadFileHistory(string filePath)
        {
            if (!File.Exists(filePath))
            {
                FileHistory fh = new FileHistory();
                XMLWriter.WriteFileHistory(fh, filePath);
            }

            FileHistory fileHistory = new FileHistory();
            List<VideoFile> videoFileList = new List<VideoFile>();

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(filePath);
            XmlNodeList xmlNodeList = xmldoc.ChildNodes;
            XmlNode xmlNode = xmlNodeList[1];
            if (xmlNode.Name == "file_history")
            {
                xmlNodeList = xmlNode.ChildNodes;

                for (int i = 0; i < xmlNodeList.Count; i++)
                {
                    if (i == 0)
                    {
                        xmlNode = xmlNodeList[0];
                        if (xmlNode.Name == "curr_folder")
                            fileHistory.Curr_Folder = xmlNode.InnerText;
                        else throw new XMLFileFormatException("missing \"curr_folder\" element");
                    }
                    else
                    {
                        xmlNode = xmlNodeList[i];
                        if (xmlNode.Name == "program")
                        {
                            XmlNodeList xmlNodeList1 = xmlNode.ChildNodes;
                            VideoFile videoFile = new VideoFile();
                            foreach (XmlNode xmlNode1 in xmlNodeList1)
                            {
                                if (xmlNode1.Name == "path")
                                    videoFile.Path = xmlNode1.InnerXml;
                                else if (xmlNode1.Name == "name")
                                    videoFile.Name = xmlNode1.InnerXml;
                                else if (xmlNode1.Name == "ext")
                                    videoFile.Ext = xmlNode1.InnerXml;
                                else if (xmlNode1.Name == "length")
                                    videoFile.Length = xmlNode1.InnerXml;
                                else if (xmlNode1.Name == "subtitles")
                                    videoFile.Subtitles = xmlNode1.InnerXml;
                                else throw new XMLFileFormatException("unknown \"" + xmlNode1.Name + "\" element");
                            }
                            videoFileList.Add(videoFile);
                        }
                        else
                        {
                            throw new XMLFileFormatException("missing \"row\" element");
                        }
                    }

                }
                fileHistory.VideoFileList = videoFileList;

            }
            else throw new XMLFileFormatException("missing \"file_history\" element");
            return fileHistory;
        }
コード例 #4
0
ファイル: XMLWriter.cs プロジェクト: angad/PeopleBAWX
        //Writes data to a file history XML file
        public static void WriteFileHistory(FileHistory fileHistory, string filePath)
        {
            XmlDocument xmlDoc = new XmlDocument();

            XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "", "");
            dec.Encoding = "UTF-8";
            xmlDoc.AppendChild(dec);

            XmlElement body = xmlDoc.CreateElement("file_history");
            xmlDoc.AppendChild(body);

            XmlElement curr_folder = xmlDoc.CreateElement("curr_folder");
            body.AppendChild(curr_folder);
            curr_folder.InnerText = fileHistory.Curr_Folder;

            foreach (VideoFile videoFile in fileHistory.VideoFileList)
            {
                XmlElement program = xmlDoc.CreateElement("program");
                body.AppendChild(program);

                XmlElement path = xmlDoc.CreateElement("path");
                program.AppendChild(path);
                path.InnerText = videoFile.Path;

                XmlElement name = xmlDoc.CreateElement("name");
                program.AppendChild(name);
                name.InnerText = videoFile.Name;

                XmlElement ext = xmlDoc.CreateElement("ext");
                program.AppendChild(ext);
                ext.InnerText = videoFile.Ext;

                XmlElement subtitles = xmlDoc.CreateElement("subtitles");
                program.AppendChild(subtitles);
                if (videoFile.Subtitles != "")
                    subtitles.InnerText = videoFile.Subtitles;

                XmlElement length = xmlDoc.CreateElement("length");
                program.AppendChild(length);
                length.InnerText = videoFile.Length;
            }

            xmlDoc.Save(filePath);
        }
コード例 #5
0
ファイル: MainWindow.xaml.cs プロジェクト: angad/PeopleBAWX
        void read_adhistory()
        {
            FileHistory fileHistory = new FileHistory();

            fileHistory = XMLReader.ReadFileHistory("C:\\PeopleBAWX\\ad_log.xml");
            VideoFile[] vf = new VideoFile[1024];

            fileHistory.VideoFileList.CopyTo(vf);

            File_List vfl = new File_List();

            for (int i = 0; vf[i] != null; i++)
            {

                Uri src = get_img_src(vf[i].Path);

                //mediaElement1.Source = new Uri(vf[i].Path.ToString());

                vfl = (new File_List()
                {
                    Name = vf[i].Name,
                    path = vf[i].Path,
                    len = vf[i].Length,
                    img = new BitmapImage(src),
                });

                string dgr_tag = vf[i].Path + "#" + vf[i].Length;

                init_dgr2(vfl, dgr_tag);
            }
        }
コード例 #6
0
ファイル: AdsFiller.cs プロジェクト: angad/PeopleBAWX
        private void fill_ads(TimeSpan ts1, TimeSpan ts2, VideoFile v1, VideoFile v2, DailyVideoFiles[] list)
        {
            TimeSpan diff = ts2.Subtract(ts1);

            FileHistory fileHistory = new FileHistory();
            fileHistory = XMLReader.ReadFileHistory("ad_log.xml");
            VideoFile[] vf = new VideoFile[1024];

            TimeSpan[] lengths = new TimeSpan[vf.Count()];
            fileHistory.VideoFileList.CopyTo(vf);

            TimeSpan max = lengths[0];

            VideoFile ad = new VideoFile();

            for (int i = 0; vf[i] != null; i++)
            {
                //MessageBox.Show(vf[i].Col.ToString());
                String[] length = vf[i].Length.Split(':');
                lengths[i] = new TimeSpan(int.Parse(length[0]), int.Parse(length[1]), int.Parse(length[2]));
                if (lengths[i] > max && lengths[i] < diff)
                {
                    max = lengths[i];
                    ad = vf[i];
                }
            }
            MessageBox.Show(max.ToString());
        }