Exemplo n.º 1
0
        public void changeInfoContent(DirectoryInfo content)
        {
            List <string> txts = new List <string>();

            txts = FILEWORK.GetAllFiles(content.FullName, txts, ".txt");
            string txtFi = txts[0];
            string fc    = FILEWORK.ReadFileContent(txtFi);


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

            imgs = FILEWORK.GetAllFiles(content.FullName, imgs, ".jpg");
            string imgFi = imgs[0];

            FileInfo f     = new FileInfo(imgFi);
            var      d     = File.GetLastWriteTime(imgFi);
            string   tdade = d.ToString("yyyy-MM-dd HH:mm:ss");

            string newContent = tdade + "\n\n" + fc;

            FILEWORK.WriteFileContent(txtFi, newContent);

            //меняем название на info.txt
            FileInfo f2 = new FileInfo(txtFi);

            string newName = content.FullName + "\\info.txt";

            System.IO.File.Move(f2.FullName, newName);
        }
Exemplo n.º 2
0
        private void checkContent(DirectoryInfo content, DirectoryInfo di)
        {
            string ins = new String(' ', 20 - di.Name.Length);

            Console.WriteLine(String.Format("{0}{1}{3}| {2}", CONST._INS, di.Name, content.Name, ins));
            FileInfo[] fileNews = content.GetFiles();



            //не пустой
            if (fileNews.Length == 0)
            {
                throw new Exception(String.Format(" {1} пуста", CONST._INSERR, content.Name));
            }
            //не должно быть вложенных папок
            DirectoryInfo[] diVlog = content.GetDirectories();
            if (diVlog.Length > 0)
            {
                throw new Exception(String.Format(" {1}  содержит вложенные папки", CONST._INSERR, content.Name));
            }
            //должно содержать хотябы одно изображение и описание
            List <string> imgs = new List <string>();

            imgs = FILEWORK.GetAllFiles(content.FullName, imgs, ".jpg");


            if (imgs.Count == 0)
            {
                throw new Exception(String.Format("{1} не содержит изображение", CONST._INSERR, content.Name));
            }
            List <string> txts = new List <string>();

            txts = FILEWORK.GetAllFiles(content.FullName, txts, ".txt");


            if (txts.Count == 0)
            {
                throw new Exception(String.Format(" {1}  не содержит описание (txt)", CONST._INSERR, content.Name));
            }

            if (txts.Count > 1)
            {
                throw new Exception(String.Format(" {1} содержит больше одного описания (txt)", CONST._INSERR, content.Name));
            }

            string opispath = txts[0];
            string fcontent = FILEWORK.ReadFileContent(opispath);

            if (String.IsNullOrEmpty(fcontent))
            {
                throw new Exception(String.Format(" {1}  ПУСТОЕ ОПИСАНИЕ (txt)", CONST._INSERR, content.Name));
            }
        }
Exemplo n.º 3
0
        public override void WORK()
        {
            getProcced();

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

            files = FILEWORK.GetAllFiles(PATH.data, files, ".jpg");
            foreach (String f in files)
            {
                string   fullName = f;
                String[] ll       = f.Split(new string[] { "\\" }, StringSplitOptions.None);
                string   fname    = ll.Last();
                DATA.imageDict.Add(fname, fullName);
                //bool isLong = IMAGEWORKER.isLongImage(fname);
                //DATA.longImgDict.Add(fname, isLong);
                DATA.RevImageDict.Add(fullName, fname);
                if (!proceed.Contains(fname))
                {
                    newproceed.Add(fname);
                }
            }


            foreach (string s in newproceed)
            {
                List <double> res = IMAGEWORKER.lessImageSet(s);
                size1 = size1 + res[0];
                size2 = size2 + res[1];
                added = true;
            }
            setProcced();

            if (added)
            {
                Console.WriteLine("{0} {1}->{2}", CONST._INS, size1, size2);
            }
        }
Exemplo n.º 4
0
        public void createTravel(DirectoryInfo f)
        {
            TRAVEL travel = new TRAVEL();
            string name   = f.Name;

            travel.dataFolderPath = f.FullName;

            travel.Id = Convert.ToInt32(name);
            string content = FILEWORK.ReadFileContent(f.FullName + "//info.txt");

            String[] lines = content.Split(new string[] { "\n" }, StringSplitOptions.None);


            #region parse order.txt
            string   order       = FILEWORK.ReadFileContent(f.FullName + "//order.txt");
            String[] order_lines = order.Split(new string[] { "\n" }, StringSplitOptions.None);
            travel.order = order_lines.ToList();
            #endregion

            #region youtubs.txt

            if (File.Exists(f.FullName + "//youtubs.txt"))
            {
                string   ycontent       = FILEWORK.ReadFileContent(f.FullName + "//youtubs.txt");
                String[] ycontent_lines = ycontent.Split(new string[] { "\n" }, StringSplitOptions.None);
                foreach (var you in ycontent_lines)
                {
                    string syou = parseYoutubs(you);
                    travel.youtubs.Add(syou);
                }
            }
            #endregion



            travel.description = FILEWORK.ReadFileContent(f.FullName + "//description.txt");

            foreach (string line in lines)
            {
                if (String.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (travel.name == null)
                {
                    travel.name = line;
                    continue;
                }

                if (travel.ldate == null)
                {
                    travel.ldate = line;
                    continue;
                }

                if (travel.lcount == null)
                {
                    travel.lcount = line;
                    continue;
                }

                if (line.Contains(".jpg"))
                {
                    travel.mainIng.Add(line);
                    continue;
                }

                if (travel.praceS == null)
                {
                    travel.praceS = line;
                    continue;
                }



                if (travel.praceL == null)
                {
                    travel.praceL = line;
                    continue;
                }
            }



            List <string> imgs = new List <string>();
            travel.imgs = FILEWORK.GetAllFiles(travel.dataFolderPath, imgs, ".jpg");

            List <string> txts = new List <string>();
            txts = FILEWORK.GetAllFiles(travel.dataFolderPath, txts, ".txt");
            foreach (string s in txts)
            {
                FileInfo ff        = new FileInfo(s);
                string   fname     = ff.Name;
                String[] ll        = fname.Split(new string[] { ".txt" }, StringSplitOptions.None);
                string   shortName = ll[0];
                bool     success   = travel.order.Contains(shortName);
                if (success)
                {
                    addLSText(shortName, travel, ff.FullName);
                }
            }

            DATA._TRAVELS.Add(travel);
        }
Exemplo n.º 5
0
        //для парсинга



        public void parse()
        {
            List <string> imgs = new List <string>();

            this.imgs    = FILEWORK.GetAllFiles(dataFolderPath, imgs, ".jpg");
            this.hasImgs = this.imgs.Count > 0;

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

            txts          = FILEWORK.GetAllFiles(dataFolderPath, txts, ".txt");
            this.infoPath = txts[0];

            string content = FILEWORK.ReadFileContent(infoPath);

            String[] lines = content.Split(new string[] { "\n" }, StringSplitOptions.None);
            foreach (string line in lines)
            {
                if (String.IsNullOrEmpty(line))
                {
                    continue;
                }

                DateTime dateTime;
                if (DateTime.TryParse(line, out dateTime))
                {
                    this.date = dateTime;
                    continue;
                }

                if (line.Contains("youtu"))
                {
                    string youtube = parseYoutubs(line);
                    youtubs.Add(youtube);
                    hasYoutube = true;
                    continue;
                }

                if (line.Contains(".jpg"))
                {
                    mainImg = line;
                    continue;
                }

                txtContents.Add(line);
            }

            if (String.IsNullOrEmpty(mainImg) && imgs.Count == 1)
            {
                string firstImg = imgs.First();
                mainImg = DATA.RevImageDict[firstImg];
            }

            //теперь разрешаем title/соntent
            if (txtContents.Count == 1)
            {
                this.title    = this.date.ToString("yyyy-MM-dd");
                this.mainText = txtContents[0];
            }

            if (txtContents.Count == 2)
            {
                txtContents   = txtContents.OrderBy(o => o.Length).ToList();
                this.title    = txtContents[0];
                this.mainText = txtContents[1];
            }


            string        mainIngFullRef = DATA.getImgFullPath(mainImg);
            List <string> otherImg       = imgs.Where(o => o != mainIngFullRef).ToList();
            int           MAXIMG1        = 9;
            int           i = 0;

            youtubeMode = hasYoutube;
            if (!hasYoutube)
            {
                foreach (string s in otherImg)
                {
                    if (i >= MAXIMG1)
                    {
                        break;
                    }
                    img1.Add(s);
                    i++;
                }
            }

            img2 = otherImg.Where(o => !img1.Contains(o)).ToList();

            if (hasYoutube)
            {
                you1.Add(youtubs.First());
            }

            you2 = youtubs.Where(o => !you1.Contains(o)).ToList();
            if (you2.Count > 0)
            {
            }
        }