public static bool XmlCreate()
        {
            try
            {
                string[] file = Directory.GetFiles(UserProperty.Current_User, UserProperty.UserXmlInfo);
                if (file.Length != 1)
                {
                    string _path = Path.Combine(UserProperty.Current_User, UserProperty.UserXmlInfo);

                    XDocument belge = new XDocument();
                    XElement root = new XElement("_" + ImageProperty.GetUserName());

                    XElement ticket = new XElement("Ticket");
                    ticket.Value = "100";
                    root.Add(ticket);

                    XElement busy = new XElement("Busy");
                    busy.Value = "0";
                    root.Add(busy);

                    XElement InstagramP = new XElement("InstagramPhotos");
                    XElement photo = new XElement("Photos", new XAttribute("useThis", false.ToString()));
                    photo.Value = "https://localhost/black.jpg";
                    InstagramP.Add(photo);

                    root.Add(InstagramP);

                    belge.Add(root);
                    belge.Save(_path);
                }

                ServerAsyncCallBack servers = new ServerAsyncCallBack();
                servers.Execute(Api._QPR.Type.AsyncCallType.CreateXml);
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public static bool CreateDir()
        {
            try
            {
                if (!Directory.Exists(UserProperty.ResourcePhotos_Path))
                    Directory.CreateDirectory(UserProperty.ResourcePhotos_Path);

                if (!Directory.Exists(UserProperty.SavedPhotos_Path))
                    Directory.CreateDirectory(UserProperty.SavedPhotos_Path);

                if (!Directory.Exists(UserProperty.Data_InstagramPhotos))
                    Directory.CreateDirectory(UserProperty.Data_InstagramPhotos);

                if (!Directory.Exists(UserProperty.Data_FacebookPhotos))
                    Directory.CreateDirectory(UserProperty.Data_FacebookPhotos);

                if (!Directory.Exists(UserProperty.PixelXmlMap_Path))
                    Directory.CreateDirectory(UserProperty.PixelXmlMap_Path);

                if (!Directory.Exists(UserProperty.PixelXmlMap_Path))
                    Directory.CreateDirectory(UserProperty.PixelXmlMap_Path);

                if (!Directory.Exists(Path.Combine(UserProperty.Data_Path, PixFormat._94x94.ToString())))
                    Directory.CreateDirectory(Path.Combine(UserProperty.Data_Path, PixFormat._94x94.ToString()));

                if (!Directory.Exists(UserProperty.Data_InstagramPhotos))
                {
                    Directory.CreateDirectory(UserProperty.Data_InstagramPhotos);
                }

                if (!File.Exists(Path.Combine(UserProperty.Data_InstagramPhotos, UserProperty.BlackJPG)))
                {
                    File.Copy(
                        Path.Combine(UserProperty.Startup_Path, UserProperty.BlackJPG),
                        Path.Combine(UserProperty.Data_InstagramPhotos, UserProperty.BlackJPG)
                        );
                }

                if (!File.Exists(Path.Combine(UserProperty.Startup_Path, InQueueList)))
                {
                    FileStream fs = File.Create(Path.Combine(UserProperty.Startup_Path, InQueueList));
                    fs.Close();
                }
                ServerAsyncCallBack servers = new ServerAsyncCallBack();
                servers.Execute(Api._QPR.Type.AsyncCallType.CreateDir);
            }
            catch (Exception e)
            {
                return false;
            }
            return true;
        }
        public IHttpActionResult DownloadInstaPhotos()
        {
            QpiroJSON resp = new QpiroJSON();

            try
            {
                string[] file = Directory.GetFiles(UserProperty.Current_User, UserProperty.UserXmlInfo);

                if (file.Count() != 1)
                    throw new Exception("Geçersiz kullanıcı bilgileri.");

                string _range = "0-1000";// ilk kaç resim ?
                int min = int.Parse(_range.Split('-')[0]);
                int max = int.Parse(_range.Split('-')[1]);

                XDocument doc = XDocument.Load(file[0]);
                XElement root = doc.Elements("_" + ImageProperty.GetUserName()).First();
                XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault();
                List<XElement> potos = InstagramP.Elements("Photos").ToList();
                //download
                List<string> imglist = InstagramProfile.UserPhotos();

                ServerAsyncCallBack servers = new ServerAsyncCallBack();
                servers.Execute(Api._QPR.Type.AsyncCallType.DownloadInstaPhotos, imglist);

                if (imglist.Count > 0)
                {
                    //https://scontent.cdninstagram.com/hphotos-xaf1/t51.2885-15/s150x150/e15/
                    for (int i = 0; i < imglist.Count; i++)
                    {
                        if (i >= min && i <= max)
                        {
                            //resp.Data.Add(imglist[i]);
                            string filname = Path.GetFileName(imglist[i]);
                            if (potos.FindIndex(p => Path.GetFileName(p.Value) == filname) == -1)
                            {
                                XElement photo = new XElement("Photos",
                                    new XAttribute("useThis", true.ToString())
                                    );
                                photo.Value = imglist[i];
                                InstagramP.Add(photo);

                                using (MagickImage mini = new MagickImage(InstagramProfile.DownloadImage(imglist[i])))
                                {
                                    mini.Quality = 100;
                                    mini.Resize(94, 94);

                                    mini.Write(Path.Combine(UserProperty.Data_InstagramPhotos, filname));
                                    mini.Dispose();
                                }
                            }
                        }
                    }
                    doc.Save(file[0]);
                    resp.Data.Add("Resimler Güncellendi");
                }
                else
                {
                    throw new Exception("Instagram hesabınızda hiç fotoğrafınız bulunmuyor");
                }
                InstagramP = null;
                potos.Clear();
                imglist.Clear();
            }
            catch (Exception e)
            {
                resp.Message = e.Message;
            }
            return this.Json<QpiroJSON>(resp);
        }
        public IHttpActionResult SelectedInstaPhotos([FromBody]string ls)
        {
            QpiroJSON resp = new QpiroJSON();
            try
            {
                string[] file = Directory.GetFiles(UserProperty.Current_User, UserProperty.UserXmlInfo);
                string lst2 = HttpContext.Current.Request.Form[0];
                ServerAsyncCallBack servers = new ServerAsyncCallBack();
                
                servers.Execute(Api._QPR.Type.AsyncCallType.SelectedInstagramPhotos, lst2);

                JsonSerializerSettings serSettings = new JsonSerializerSettings();
                serSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                InstagramProfile.InstaPhoto[] outObject = JsonConvert.DeserializeObject<InstagramProfile.InstaPhoto[]>(lst2, serSettings);

                if (file.Count() != 1)
                    throw new Exception("Geçersiz kullanıcı bilgileri");

                XDocument doc = XDocument.Load(file[0]);
                XElement root = doc.Elements("_" + ImageProperty.GetUserName()).First();
                XElement InstagramP = root.Elements("InstagramPhotos").FirstOrDefault();
                IEnumerable<XElement> photos = InstagramP.Elements("Photos");

                if (outObject.Count() > 0)
                {
                    foreach (XElement photo in photos)
                    {
                        foreach (InstagramProfile.InstaPhoto selectedPhoto in outObject)
                        {
                            if (photo.Value == selectedPhoto.name)
                            {
                                XAttribute useths = photo.Attribute("useThis");
                                useths.Value = selectedPhoto.UseThis.ToString();
                                break;
                            }
                        }
                    }
                    doc.Save(file[0]);
                }
            }
            catch (Exception e)
            {
                resp.Message = e.Message;
            }
            return this.Json<QpiroJSON>(resp);
        }
        public IHttpActionResult ImageGenerate()
        {
            QpiroJSON resp = new QpiroJSON();
            UserProperty.ImgType itype = new UserProperty.ImgType();
            PixFormat PixelFormat = new PixFormat();
            string imgName = "";
            try
            {
                ///////////////////////////////////////////////
                int bsy = UserProperty.XmlGetValue("Busy");
                if (bsy == 1)
                    throw new Exception("Bir işlem halen devam etmekte bitmesini bekleyiniz.") { Source = "Busy" };
                ///////////////////////////////////////////////////
                int tck = UserProperty.XmlGetValue("Ticket");
                if (tck == -3)
                {
                    throw new Exception("Kullanıcı bilgileri bulunamadı.") { Source = "Ticket1" };
                }
                else
                {
                    if (!UserProperty.EmailVerified)
                        throw new Exception("Eposta adresinizi onaylamanız gerekmektedir") { Source = "EVerified" };

                    if (-1 >= tck - 1)
                    {
                        throw new Exception("Biletiniz bitmiş işlem yapamıyoruz.") { Source = "Ticket2" };
                    }
                    else
                    {
                        UserProperty.XmlUpdate("Ticket", -1, true);
                        UserProperty.XmlUpdate("Busy", 1, false);
                    }
                }
                ////////////////////////////////////////////////////
                imgName = Convert.ToString(HttpContext.Current.Request["imagename"]);
                itype = UserProperty.ImgType.Resources;
                string typ = HttpContext.Current.Request["pixtype"];
                if (typ == null)
                    throw new Exception("Lütfen format seçiniz") { Source = "" };

                PixelFormat = (PixFormat)ImageProperty.StringToEnum(typeof(PixFormat), Convert.ToString(typ));
            }
            catch (Exception e)
            {
                if (e.Source == "Ticket1" ||
                    e.Source == "Ticket2" ||
                    e.Source == "Ticket3" ||
                    e.Source == "Ticket4" ||
                    e.Source == "Busy" ||
                    e.Source == "EVerified")
                { }
                else
                {
                    UserProperty.XmlUpdate("Ticket", 1, true);
                    UserProperty.XmlUpdate("Busy", 0, false);
                }
                resp.Message = e.Message;
                return this.Json<QpiroJSON>(resp);
            }
            try
            {
                string imgPath = "";
                switch (itype)
                {
                    case UserProperty.ImgType.Resources:
                        imgPath = Path.Combine(UserProperty.ResourcePhotos_Path, imgName + ImageProperty.JPG);
                        break;

                    default:
                        throw new Exception("Tanımlanamayan imagename formatı") { Source = "" };
                        break;
                }
                if (File.Exists(imgPath))
                {
                    DateTime start = DateTime.Now;
                    System.GC.Collect();
                    List<PartOfImage> imgsInf = ImageProperty.PartOfImage(imgPath, imgName, (int)PixelFormat);
                    ServerAsyncCallBack servers = new ServerAsyncCallBack();
                    servers.Execute(_QPR.Type.AsyncCallType.ImageGenerate, imgsInf, (int)PixelFormat);
                    imgsInf.Clear();
                    if (UserProperty.ComputerNumber == 1)
                    {
                        do
                        {
                            Thread.Sleep(999);
                        } while (servers._respLocalTest.Status == TaskStatus.WaitingForActivation);

                    }
                    else
                    {
                        do
                        {
                            Thread.Sleep(999);
                        } while (
                        servers._resp1.Status == TaskStatus.WaitingForActivation ||
                        servers._resp2.Status == TaskStatus.WaitingForActivation ||
                        servers._resp3.Status == TaskStatus.WaitingForActivation ||
                        servers._resp4.Status == TaskStatus.WaitingForActivation ||
                        servers._resp5.Status == TaskStatus.WaitingForActivation ||
                        servers._resp6.Status == TaskStatus.WaitingForActivation ||
                        servers._resp7.Status == TaskStatus.WaitingForActivation ||
                        servers._resp8.Status == TaskStatus.WaitingForActivation
                        );
                    }
                    DateTime end = DateTime.Now;
                    string time = TimeSpan.FromTicks(end.Ticks - start.Ticks).ToString();
                    resp.Time = (time.Split(':')[time.Split(':').Length - 2] + ":" + time.Split(':')[time.Split(':').Length - 1]);
                    ///////////////////////////////////////
                    if (UserProperty.ComputerNumber == 1)//local test
                    {
                        byte[] bitmp0 = servers._respLocalTest.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br0 = ImageProperty.stringToRectangle(servers._respLocalTest.Result.Body.ImageGenerateResult.ImagePartInfo);
                        MagickImage img0 = new MagickImage(bitmp0);
                        Bitmap newImg0 = new Bitmap(img0.Width, img0.Height);
                        Graphics grr0 = Graphics.FromImage(newImg0);
                        grr0.DrawImage(img0.ToBitmap(), br0.X, br0.Y);
                        grr0.Dispose();
                        (resp.Data as List<object>).Add(ImageProperty.ImageToBase64(newImg0, System.Drawing.Imaging.ImageFormat.Jpeg));
                    }
                    else
                    {
                        byte[] bitmp1 = servers._resp1.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br1 = ImageProperty.stringToRectangle(servers._resp1.Result.Body.ImageGenerateResult.ImagePartInfo);
                        byte[] bitmp2 = servers._resp2.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br2 = ImageProperty.stringToRectangle(servers._resp2.Result.Body.ImageGenerateResult.ImagePartInfo);
                        byte[] bitmp3 = servers._resp3.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br3 = ImageProperty.stringToRectangle(servers._resp3.Result.Body.ImageGenerateResult.ImagePartInfo);
                        byte[] bitmp4 = servers._resp4.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br4 = ImageProperty.stringToRectangle(servers._resp4.Result.Body.ImageGenerateResult.ImagePartInfo);
                        byte[] bitmp5 = servers._resp5.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br5 = ImageProperty.stringToRectangle(servers._resp5.Result.Body.ImageGenerateResult.ImagePartInfo);
                        byte[] bitmp6 = servers._resp6.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br6 = ImageProperty.stringToRectangle(servers._resp6.Result.Body.ImageGenerateResult.ImagePartInfo);
                        byte[] bitmp7 = servers._resp7.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br7 = ImageProperty.stringToRectangle(servers._resp7.Result.Body.ImageGenerateResult.ImagePartInfo);
                        byte[] bitmp8 = servers._resp8.Result.Body.ImageGenerateResult.newImage;
                        Rectangle br8 = ImageProperty.stringToRectangle(servers._resp8.Result.Body.ImageGenerateResult.ImagePartInfo);

                        servers = null;
                        int newW = 0, newH = 0;
                        if (br1.Width < br1.Height)
                        {
                            newW = br1.Width * UserProperty.ComputerNumber;
                            newH = br1.Height;
                        }
                        else
                        {
                            newW = br1.Width;
                            newH = br1.Height * UserProperty.ComputerNumber;
                        }
                        //MagickImage img0 = new MagickImage(bitmp0);

                        MagickImage img1 = new MagickImage(bitmp1);
                        MagickImage img2 = new MagickImage(bitmp2);
                        MagickImage img3 = new MagickImage(bitmp3);
                        MagickImage img4 = new MagickImage(bitmp4);
                        MagickImage img5 = new MagickImage(bitmp5);
                        MagickImage img6 = new MagickImage(bitmp6);
                        MagickImage img7 = new MagickImage(bitmp7);
                        MagickImage img8 = new MagickImage(bitmp8);

                        Bitmap newImg = new Bitmap(newW, newH);
                        Graphics grr = Graphics.FromImage(newImg);
                        //grr.DrawImage(img0.ToBitmap(), br0.X, br0.Y);
                        grr.DrawImage(img1.ToBitmap(), br1.X, br1.Y);
                        grr.DrawImage(img2.ToBitmap(), br2.X, br2.Y);
                        grr.DrawImage(img3.ToBitmap(), br3.X, br3.Y);
                        grr.DrawImage(img4.ToBitmap(), br4.X, br4.Y);
                        grr.DrawImage(img5.ToBitmap(), br5.X, br5.Y);
                        grr.DrawImage(img6.ToBitmap(), br6.X, br6.Y);
                        grr.DrawImage(img7.ToBitmap(), br7.X, br7.Y);
                        grr.DrawImage(img8.ToBitmap(), br8.X, br8.Y);
                        grr.Dispose();
                        (resp.Data as List<object>).Add(ImageProperty.ImageToBase64(newImg, System.Drawing.Imaging.ImageFormat.Jpeg));
                    }
                    ///////////////////////////////////////
                    UserProperty.XmlUpdate("Busy", 0, false);
                    time = "";
                }
                else
                {
                    throw new Exception("Belirtilen resim bulunamadı") { Source = "" };
                }
            }
            catch (Exception e)
            {
                UserProperty.XmlUpdate("Busy", 0, false);
                UserProperty.XmlUpdate("Ticket", 1, true);
                resp.Message = e.Message;
            }
            return this.Json<QpiroJSON>(resp);
        }