Пример #1
0
        static public async Task WriteVideoModelToFile(VideoModel videoData)
        {
            string strData = videoData.ToString();

            // Get the text data from the textbox.
            byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(strData.ToCharArray());

            // Get the local folder.
            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

            // Create a new folder name DataFolder.
            var dataFolder = await local.CreateFolderAsync("DataFolder",
                                                           CreationCollisionOption.OpenIfExists);

            // Create a new file named DataFile.txt.
            videoData.Name = videoData.Name.Replace("$", "[etot_simvol]");
            var fileData = await dataFolder.CreateFileAsync("DataFile$" + videoData.Name + "$.txt",
                                                            CreationCollisionOption.ReplaceExisting);

            var filePath = await dataFolder.CreateFileAsync("PathFile$" + videoData.Name + "$.txt",
                                                            CreationCollisionOption.ReplaceExisting);

            // Write the data from the textbox.
            using (var s = await fileData.OpenStreamForWriteAsync())
            {
                s.Write(fileBytes, 0, fileBytes.Length);
            }
            using (var s = await filePath.OpenStreamForWriteAsync())
            {
                s.Write(videoData.HeadPiece, 0, videoData.HeadPiece.Length);
            }
        }
Пример #2
0
        public int CompareTo(object obj)
        {
            string[] dt       = this.DateCreated.Split(' ');
            string[] dt1      = dt[0].Split('.'); // день месяц год
            string[] dt2      = dt[1].Split(':'); //час минута секунда
            DateTime thisData = new DateTime(int.Parse(dt1[2]), int.Parse(dt1[1]), int.Parse(dt1[0]), int.Parse(dt2[0]), int.Parse(dt2[1]), int.Parse(dt2[2]));

            VideoModel newModel = obj as VideoModel;

            dt  = newModel.DateCreated.Split(' ');
            dt1 = dt[0].Split('.'); // день месяц год
            dt2 = dt[1].Split(':'); //час минута секунда
            DateTime newData = new DateTime(int.Parse(dt1[2]), int.Parse(dt1[1]), int.Parse(dt1[0]), int.Parse(dt2[0]), int.Parse(dt2[1]), int.Parse(dt2[2]));

            return(newData.CompareTo(thisData));
        }
Пример #3
0
        static public async Task <VideoModel[]> ReadFilesInLocalFolder()
        {
            // Get the local folder.
            StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
            // Get the DataFolder folder.
            var dataFolder = await local.GetFolderAsync("DataFolder");

            var files = await dataFolder.GetFilesAsync();

            List <string> membs = new List <string>();

            string[] lines = new string[3];
            string   str;// считываемая строка

            foreach (StorageFile file in files)
            {
                str      = file.Name;
                lines    = str.Split('$');
                lines[1] = lines[1].Replace("[etot_simvol]", "$");
                str      = lines[1];
                if (lines[0].Contains("Data"))
                {
                    membs.Add(str);
                }
            }
            int count = membs.Count;
            List <VideoModel> models = new List <VideoModel>();

            byte[] imageBytes;

            for (int i = 0; i < count; i++)
            {
                var fileData = await dataFolder.GetFileAsync("DataFile$" + membs[i] + "$.txt");

                using (var fileDataStream = await fileData.OpenStreamForReadAsync())
                {
                    using (StreamReader streamReader = new StreamReader(fileDataStream))
                    {
                        str = streamReader.ReadToEnd();
                    }
                }
                lines = str.Split('$');
                string name        = lines[0].Replace("[etot_simvol]", "$");
                string dataCreated = lines[1].Replace("[etot_simvol]", "$");

                // Get the filePath.
                StorageFile filePath = await dataFolder.GetFileAsync("PathFile$" + membs[i] + "$.txt");

                IBuffer buffer = await FileIO.ReadBufferAsync(filePath);

                imageBytes = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.ToArray(buffer);


                //If this videoFile not exists , localfiles connected with it will be deleted

                if (await VideoFileExists(name))
                {
                    VideoModel model = new VideoModel()
                    {
                        DateCreated = dataCreated, Name = name, HeadPiece = imageBytes
                    };
                    models.Add(model);
                }
                else
                {
                    await filePath.DeleteAsync();

                    await fileData.DeleteAsync();
                }
            }
            return(models.ToArray());
        }