Ejemplo n.º 1
0
        public string GetLocationOfImage(XMLWorker XWorker, string longit, string width)
        {
            string      location  = "";
            string      longitude = longit;
            string      Widthude  = width;
            WebResponse response  = MakeRequest(longitude, Widthude);

            if (response != null)
            {
                location = XWorker.GetAddressFromXML(response);
            }
            else if (response == null)
            {
                location = "undefined";
            }
            return(location);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Choose the Comand.");
            Console.WriteLine("1 to Rename as DataTime");
            Console.WriteLine("2 to Add DataTime");
            Console.WriteLine("3 to Sort by year");
            Console.WriteLine("4 to Sort by location");
            Console.WriteLine("q to Exit");
            Console.WriteLine("Press 1 or 2 or 3 or 4 or q");
            string choosen = Console.ReadLine();

            while (Flag)
            {
                switch (choosen)
                {
                case "1":
                    Console.WriteLine("Enter directory");
                    string DirectoryPath = @"D:\ДЗ\lab\source";     // типо ввожу
                    NewDir    = new DirectoryInfo(DirectoryPath);
                    TargetDir = NewDir.CreateSubdirectory("rename");
                    Metadata  = new MetaDataReceiver();
                    Metadata.GetListImage(NewDir);
                    Metadata.GetData();
                    for (int i = 0; i < Metadata.ImageSet.Count; i++)
                    {
                        List <ImageData> local = Metadata.ImageSet;
                        string           name  = local[i].Date.RemoverInvalidSymbols();
                        string           path  = TargetDir.FullName + @"\" + name + local[i].Extension;
                        if (File.Exists(path) == true)
                        {
                            path = TargetDir.FullName + @"\" + name + i + local[i].Extension;
                        }
                        FileStream fs = File.Create(path);
                        SaveImageCustom(local[i], fs);
                        fs.Flush();
                        fs.Close();
                    }
                    Console.WriteLine("finished");
                    break;

                case "2":
                    Console.WriteLine("Enter directory");
                    string DirectoryPath2 = @"D:\ДЗ\lab\source";     // типо ввожу
                    NewDir    = new DirectoryInfo(DirectoryPath2);
                    TargetDir = NewDir.CreateSubdirectory("drawstring");
                    Drawer drw = new Drawer();
                    Metadata = new MetaDataReceiver(drw);
                    Metadata.GetListImage(NewDir);
                    Metadata.GetData();
                    for (int i = 0; i < Metadata.ImageSet.Count; i++)
                    {
                        Image            StringImage = null;
                        List <ImageData> local       = Metadata.ImageSet;
                        string           path        = TargetDir.FullName + @"\" + local[i].IdImage + local[i].Extension;
                        if (File.Exists(path) == true)
                        {
                            path = TargetDir.FullName + @"\" + local[i].IdImage + i + local[i].Extension;
                        }
                        FileStream fs = File.Create(path);
                        StringImage = Metadata.Drawer.DrawTheString(local[i]);
                        SaveImageCustom(local[i], fs);
                        fs.Flush();
                        fs.Close();
                    }

                    Console.WriteLine("finished");

                    break;

                case "3":
                    Console.WriteLine("Enter directory");
                    string DirectoryPath3 = @"D:\ДЗ\lab\source";     // типо ввожу
                    NewDir    = new DirectoryInfo(DirectoryPath3);
                    TargetDir = NewDir.CreateSubdirectory("sortbyyear");
                    Metadata  = new MetaDataReceiver();
                    Metadata.GetListImage(NewDir);
                    Metadata.GetData();
                    for (int i = 0; i < Metadata.ImageSet.Count; i++)
                    {
                        List <ImageData> local   = Metadata.ImageSet;
                        string           dirpath = TargetDir.FullName + @"\" + local[i].Date.Substring(6, 4);
                        string           path    = TargetDir.FullName + @"\" + local[i].IdImage + local[i].Extension; // тоже не нужно, заменить на  пустую строку
                        if (!Directory.Exists(dirpath))
                        {
                            TargetDir.CreateSubdirectory(local[i].Date.Substring(6, 4));
                            path = dirpath + @"\" + local[i].IdImage + local[i].Extension;
                            FileStream fs = File.Create(path);
                            SaveImageCustom(local[i], fs);
                            fs.Flush();
                            fs.Close();
                        }
                        else if (Directory.Exists(dirpath))
                        {
                            path = dirpath + @"\" + local[i].IdImage + local[i].Extension;
                            if (File.Exists(path) == true)
                            {
                                path = dirpath + @"\" + local[i].IdImage + i + local[i].Extension;
                            }
                            FileStream fs = File.Create(path);
                            SaveImageCustom(local[i], fs);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    Console.WriteLine("finished");
                    break;

                case "4":
                    Console.WriteLine("Enter directory");
                    string DirectoryPath4 = @"D:\ДЗ\lab\source";
                    NewDir    = new DirectoryInfo(DirectoryPath4);
                    TargetDir = NewDir.CreateSubdirectory("location");
                    Requester requester = new Requester();
                    requester.YandexApi = "24e5f3e7-2bb0-4052-b2fc-5254ecd09eea";
                    Metadata            = new MetaDataReceiver();
                    XMLWorker xmlworker = new XMLWorker();
                    Metadata.GetListImage(NewDir);
                    Metadata.GetData();

                    for (int i = 0; i < Metadata.ImageSet.Count; i++)
                    {
                        ImageData img = Metadata.ImageSet[i];
                        Getloc(img, xmlworker, requester);
                    }



                    for (int i = 0; i < Metadata.ImageSet.Count; i++)
                    {
                        List <ImageData> local   = Metadata.ImageSet;
                        string           dirpath = TargetDir.FullName + @"\" + local[i].Location;
                        string           path    = TargetDir.FullName + @"\" + local[i].IdImage + local[i].Extension; //это не нужно
                        if (!Directory.Exists(dirpath))
                        {
                            TargetDir.CreateSubdirectory(local[i].Location);
                            path = dirpath + @"\" + local[i].IdImage + local[i].Extension;
                            FileStream fs = File.Create(path);
                            SaveImageCustom(local[i], fs);
                            fs.Flush();
                            fs.Close();
                        }
                        else if (Directory.Exists(dirpath))
                        {
                            path = dirpath + @"\" + local[i].IdImage + local[i].Extension;
                            if (File.Exists(path) == true)
                            {
                                path = dirpath + @"\" + local[i].IdImage + i + local[i].Extension;
                            }
                            FileStream fs = File.Create(path);
                            SaveImageCustom(local[i], fs);
                            fs.Flush();
                            fs.Close();
                        }
                    }
                    break;

                case "q":
                    Flag = false;
                    break;
                }
                Flag = false;
            }
            Console.WriteLine("END");
            Console.ReadLine();
        }