private bool RepeatLock(string data_post_id) { Post[] posts = PostsContainer.ToArray(); foreach (Post post in posts) { if (post.Data_Post_Id == data_post_id) { return(true); } } return(false); }
private void JSON_Write(int file_number) { Post[] PostsToSerialize = PostsContainer.ToArray(); int _size = PostsToSerialize.Length; Authors[] auth = new Authors[_size]; Texts[] text = new Texts[_size]; Link[] links = new Link[_size]; PicVids[] pv = new PicVids[_size]; for (int i = 0; i < _size; i++) { auth[i] = new Authors() { Author = PostsToSerialize[i].Author, Data_Post_Id = PostsToSerialize[i].Data_Post_Id }; text[i] = new Texts() { Text = PostsToSerialize[i].Text, Data_Post_Id = PostsToSerialize[i].Data_Post_Id }; links[i] = new Link() { Links = PostsToSerialize[i].Links, Data_Post_Id = PostsToSerialize[i].Data_Post_Id }; pv[i] = new PicVids() { MainContent = PostsToSerialize[i].MainContent, Data_Post_Id = PostsToSerialize[i].Data_Post_Id }; } //using (FileStream fs = new FileStream("posts" + file_number.ToString() + ".json", FileMode.Append, FileAccess.Write)) using (FileStream fs = new FileStream("T:\\post" + file_number.ToString() + ".json", FileMode.OpenOrCreate)) { switch (file_number) { case 1: { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(Texts[])); jsonFormatter.WriteObject(fs, text); break; } case 2: { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(Link[])); jsonFormatter.WriteObject(fs, links); break; } case 3: { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(PicVids[])); jsonFormatter.WriteObject(fs, pv); break; } case 4: { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(Authors[])); jsonFormatter.WriteObject(fs, auth); break; } } } // MessageBox.Show("Поток записи в файл " + file_number.ToString() + " отработал!"); }