Beispiel #1
0
        private async void loginsList_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                LoginPanel.Visibility    = Visibility.Collapsed;
                ProgressPanel.Visibility = Visibility.Visible;
                if (await WebApi.Check())
                {
                    var data   = Convert.FromBase64String((e.ClickedItem as LoginViewModel).data);
                    var Result = await Api.Initialization(new MemoryStream(data));

                    if (Result)
                    {
                        LoginPanel.Visibility    = Visibility.Visible;
                        ProgressPanel.Visibility = Visibility.Collapsed;
                        this.Frame.Navigate(typeof(Instagram.Main));
                    }
                    else
                    {
                        await Helper.ShowMessage("خطا در رابطه به حساب", Api.Err);

                        LoginPanel.Visibility    = Visibility.Visible;
                        ProgressPanel.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    //App Exit
                }
            }
            catch (Exception ex)
            {
                await Utility.Helper.ShowMessage("خطا پیش بینی نشده", ex.Message);
            }
        }
Beispiel #2
0
        private async void loginBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                LoginPanel.Visibility    = Visibility.Collapsed;
                ProgressPanel.Visibility = Visibility.Visible;
                if (await WebApi.Check())
                {
                    var IResult = await Api.Login(usernameBox.Text, passwordBox.Password); /*true;*/

                    if (IResult)
                    {
                        var StateData = Api.InstaApi.GetStateDataAsStream();

                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        dic.Add("accounttype", AccountsEnum.Instagram.ToString());
                        dic.Add("username", usernameBox.Text);
                        dic.Add("data", Convert.ToBase64String((StateData as MemoryStream).ToArray()));

                        var WResult = await WebApi.Post(WebApi.WebApiURL + "api/uwp/Add_Account", new HttpFormUrlEncodedContent(dic), new HttpCredentialsHeaderValue("Bearer", WebApi.Token));

                        if (WResult.IsSuccessStatusCode)
                        {
                            await Helper.ShowMessage("حساب با موفقیت افزوده شد", "حساب موردنظر با موفقیت افزوده شد برای ورود روی آن کلیک کنید");
                            await LoadLogins();

                            LoginPanel.Visibility    = Visibility.Visible;
                            ProgressPanel.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            await Helper.ShowMessage("خطا در افزودن حساب", "خطا در افزودن حساب لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید");

                            LoginPanel.Visibility    = Visibility.Visible;
                            ProgressPanel.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        await Helper.ShowMessage("خطا در رابطه به حساب", Api.Err);

                        LoginPanel.Visibility    = Visibility.Visible;
                        ProgressPanel.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    //Exit App
                }
            }
            catch (Exception ex)
            {
                await Utility.Helper.ShowMessage("خطا پیش بینی نشده", ex.Message);
            }
        }
Beispiel #3
0
        private async void DeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            if (await new ContentDialog()
            {
                FlowDirection = FlowDirection.RightToLeft,
                FontFamily = new FontFamily("/Assets/Fonts/IRANSansWeb(FaNum).ttf#IRANSansWeb(FaNum)"),
                Content = "آیا مایل به حذف پست می باشید؟",
                CloseButtonText = "خیر",
                PrimaryButtonText = "بلی"
            }.ShowAsync() == ContentDialogResult.Primary)
            {
                LoginPanel.Visibility    = Visibility.Collapsed;
                ProgressPanel.Visibility = Visibility.Visible;
                if (await WebApi.Check())
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("spid", removeid);
                    dic.Add("acname", Api.Username);

                    var WResult = await WebApi.Post(WebApi.WebApiURL + "api/uwp/Remove_Post", new HttpFormUrlEncodedContent(dic), new HttpCredentialsHeaderValue("Bearer", WebApi.Token));

                    if (WResult.IsSuccessStatusCode)
                    {
                        SPLists.Items.Clear();
                        await Load();

                        await Helper.ShowMessage("پست حذف شد", "پست با موفقیت حذف شد");
                    }
                    else
                    {
                        await Helper.ShowMessage("خطا", "خطا");

                        LoginPanel.Visibility    = Visibility.Visible;
                        ProgressPanel.Visibility = Visibility.Collapsed;
                    }
                }
                else
                {
                    LoginPanel.Visibility    = Visibility.Visible;
                    ProgressPanel.Visibility = Visibility.Collapsed;
                }
            }
        }
Beispiel #4
0
        async Task LoadLogins()
        {
            try
            {
                loginsList.Items.Clear();
                if (await WebApi.Check())
                {
                    var Result = await WebApi.Post(WebApi.WebApiURL + "api/uwp/Accounts_List", null, new HttpCredentialsHeaderValue("Bearer", WebApi.Token));

                    if (Result.IsSuccessStatusCode)
                    {
                        var DataResult = JsonConvert.DeserializeObject <IEnumerable <AccountViewModel> >(Result.Content.ToString());

                        foreach (AccountViewModel Account in DataResult)
                        {
                            if (Account.accounttype == AccountsEnum.Instagram)
                            {
                                //dynamic stuff;
                                //using (System.Net.WebClient wc = new System.Net.WebClient())
                                //{
                                //    stuff = JsonConvert.DeserializeObject(await wc.DownloadStringTaskAsync("https://apinsta.herokuapp.com/u/" + Account.username));
                                //}
                                loginsList.Items.Add(new LoginViewModel()
                                {
                                    id = Account.id, Username = Account.username, data = Account.data, Profilepicture = /*(string)stuff.graphql.user.profile_pic_url*/ "https://static.licdn.com/scds/common/u/images/themes/katy/ghosts/person/ghost_person_200x200_v1.png"
                                });
                            }
                        }
                    }
                }
                else
                {
                    //Exit App
                }
            }
            catch (Exception ex)
            {
                await Utility.Helper.ShowMessage("خطا پیش بینی نشده", ex.Message);
            }
        }
Beispiel #5
0
        async Task Load()
        {
            if (await WebApi.Check())
            {
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("accountusername", Api.Username);
                var WResult = await WebApi.Post(WebApi.WebApiURL + "api/uwp/Posts_List", new HttpFormUrlEncodedContent(dic), new HttpCredentialsHeaderValue("Bearer", WebApi.Token));

                if (WResult.IsSuccessStatusCode)
                {
                    var DataResult = JsonConvert.DeserializeObject <IEnumerable <SPostViewModel> >(WResult.Content.ToString());
                    foreach (var sp in DataResult.OrderBy(x => x.datetime))
                    {
                        PersianCalendar pc          = new PersianCalendar();
                        CultureInfo     cultureInfo = new CultureInfo("fa-IR");
                        switch (sp.type)
                        {
                        case "Image":
                        {
                            var post  = (ImagePostViewModel)(FromByteArray(Convert.FromBase64String(sp.post)));
                            var media = await ImageFromBytes(Convert.FromBase64String(post.images[0]));

                            SPLists.Items.Add(new SPListViewModel()
                                {
                                    type    = sp.type,
                                    id      = sp.id,
                                    image   = media,
                                    caption = post.caption,
                                    date    = (pc.GetYear(sp.datetime) + "/" + pc.GetMonth(sp.datetime) + "/" + pc.GetDayOfMonth(sp.datetime) + "  " + cultureInfo.DateTimeFormat.GetDayName(pc.GetDayOfWeek(sp.datetime))),
                                    time    = sp.datetime.ToLongTimeString()
                                });
                        }
                        break;

                        case "Video":
                        {
                            var post = (VideoPostViewModel)(FromByteArray(Convert.FromBase64String(sp.post)));
                            //var media = await ImageFromBytes(Convert.FromBase64String(post.video));
                            SPLists.Items.Add(new SPListViewModel()
                                {
                                    type = sp.type,
                                    id   = sp.id,
                                    //image = media,
                                    video   = Convert.FromBase64String(post.video),
                                    caption = post.caption,
                                    date    = (pc.GetYear(sp.datetime) + "/" + pc.GetMonth(sp.datetime) + "/" + pc.GetDayOfMonth(sp.datetime) + "  " + cultureInfo.DateTimeFormat.GetDayName(pc.GetDayOfWeek(sp.datetime))),
                                    time    = sp.datetime.ToLongTimeString()
                                });
                        }
                        break;

                        case "Carousel":
                        {
                            var post  = (ImagePostViewModel)(FromByteArray(Convert.FromBase64String(sp.post)));
                            var media = await ImageFromBytes(Convert.FromBase64String(post.images[0]));

                            SPLists.Items.Add(new SPListViewModel()
                                {
                                    carousel = post.images,
                                    type     = sp.type,
                                    id       = sp.id,
                                    image    = media,
                                    caption  = post.caption,
                                    date     = (pc.GetYear(sp.datetime) + "/" + pc.GetMonth(sp.datetime) + "/" + pc.GetDayOfMonth(sp.datetime) + "  " + cultureInfo.DateTimeFormat.GetDayName(pc.GetDayOfWeek(sp.datetime))),
                                    time     = sp.datetime.ToLongTimeString()
                                });
                        }
                        break;
                        }
                    }
                }
                else
                {
                    await Helper.ShowMessage("خطا", "خطا");
                }
            }
            if (SPLists.Items.Count > 0)
            {
                await clicked();

                LoginPanel.Visibility    = Visibility.Visible;
                ProgressPanel.Visibility = Visibility.Collapsed;
            }
            else
            {
                LoginPanel.Visibility    = Visibility.Collapsed;
                ProgressPanel.Visibility = Visibility.Collapsed;
            }
        }
        //Upload Videos
        async Task UploadVideo()
        {
            if (TPicker.Visibility == Visibility.Collapsed)
            {
                var _Target = (await tempFolder.GetFilesAsync()).Where(x => x.DisplayName.StartsWith("_tmpVid")).ToList();
                if (_Target.Count == 1)
                {
                    string PCap = "";
                    PostCaption.Document.GetText(Windows.UI.Text.TextGetOptions.None, out PCap);
                    VideoProperties videoProperties = await _Target[0].Properties.GetVideoPropertiesAsync();

                    var         thumb    = await _Target[0].GetThumbnailAsync(ThumbnailMode.SingleItem);
                    var         cnow     = DateTime.Now.ToFileTime();
                    StorageFile _Target2 = await tempFolder.CreateFileAsync("_tmpVid" + cnow + ".jpg", CreationCollisionOption.ReplaceExisting);

                    IBuffer buf;
                    Windows.Storage.Streams.Buffer inputBuffer = new Windows.Storage.Streams.Buffer(1024);
                    using (var destFileStream = await _Target2.OpenAsync(FileAccessMode.ReadWrite))
                        while ((buf = (await thumb.ReadAsync(inputBuffer, inputBuffer.Capacity, Windows.Storage.Streams.InputStreamOptions.None))).Length > 0)
                        {
                            await destFileStream.WriteAsync(buf);
                        }
                    ImageProperties imageProperties = await _Target2.Properties.GetImagePropertiesAsync();

                    var UpResult = await Api.InstaApi.UploadVideoAsync(new InstaVideo(_Target[0].Path, int.Parse(videoProperties.Width.ToString()), int.Parse(videoProperties.Height.ToString()), 3), new InstaImage(_Target2.Path, int.Parse(imageProperties.Width.ToString()), int.Parse(imageProperties.Height.ToString())), PCap);

                    if (UpResult.Succeeded)
                    {
                        ContentDialog End = new ContentDialog
                        {
                            FlowDirection   = FlowDirection.RightToLeft,
                            FontFamily      = new FontFamily("/Assets/Fonts/IRANSansWeb(FaNum).ttf#IRANSansWeb(FaNum)"),
                            Content         = "ویدئو با موفقیت ارسال شد",
                            CloseButtonText = "باشه"
                        };
                        await End.ShowAsync();
                    }
                    else
                    {
                        ContentDialog End = new ContentDialog
                        {
                            FlowDirection   = FlowDirection.RightToLeft,
                            FontFamily      = new FontFamily("/Assets/Fonts/IRANSansWeb(FaNum).ttf#IRANSansWeb(FaNum)"),
                            Content         = "خطا",
                            CloseButtonText = "باشه"
                        };
                        await End.ShowAsync();
                    }
                }
            }
            {
                if (await WebApi.Check())
                {
                    var _Target = (await tempFolder.GetFilesAsync()).Where(x => x.DisplayName.StartsWith("_tmpVid")).ToList();
                    if (_Target.Count == 1)
                    {
                        string PCap = "";
                        PostCaption.Document.GetText(Windows.UI.Text.TextGetOptions.None, out PCap);
                        VideoPostViewModel videoPostViewModel = new VideoPostViewModel();
                        videoPostViewModel.caption = PCap;

                        var filestream = await _Target[0].OpenStreamForReadAsync();
                        var filebytes  = new byte[(int)filestream.Length];
                        filestream.Read(filebytes, 0, (int)filestream.Length);
                        videoPostViewModel.video = (Convert.ToBase64String(filebytes));

                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        dic.Add("type", InstaMediaType.Video.ToString());
                        dic.Add("accountusername", Api.Username);
                        dic.Add("data", Convert.ToBase64String(ToByteArray(videoPostViewModel)));
                        dic.Add("date", (new DateTime(DPicker.Date.Value.Year, DPicker.Date.Value.Month, DPicker.Date.Value.Day, TPicker.Time.Hours, TPicker.Time.Minutes, TPicker.Time.Seconds)).ToBinary().ToString());

                        var WResult = await WebApi.Post(WebApi.WebApiURL + "api/uwp/Add_Post", new HttpFormUrlEncodedContent(dic), new HttpCredentialsHeaderValue("Bearer", WebApi.Token));

                        if (WResult.IsSuccessStatusCode)
                        {
                            await Helper.ShowMessage("پست به صف افزوده شد", "پست به صف افزوده شد");
                        }
                        else
                        {
                            await Helper.ShowMessage("خطا در ارسال پست", "خطا در ارسال پست");
                        }
                    }
                }
            }
        }
        //Upload Pictures
        async Task UploadPictures()
        {
            if (TPicker.Visibility == Visibility.Collapsed)
            {
                var _Target = (await tempFolder.GetFilesAsync()).Where(x => x.DisplayName.StartsWith("_tmpPic")).ToList();
                if (_Target.Count > 1 && _Target.Count <= 10)
                {
                    InstaSharper.Classes.Models.InstaImage[] imgs = new InstaSharper.Classes.Models.InstaImage[_Target.Count];
                    for (int i = 0; i < imgs.Length; i++)
                    {
                        ImageProperties imageProperties = await _Target[i].Properties.GetImagePropertiesAsync();
                        imgs[i]        = new InstaSharper.Classes.Models.InstaImage();
                        imgs[i].URI    = _Target[i].Path;
                        imgs[i].Width  = int.Parse(imageProperties.Width.ToString());
                        imgs[i].Height = int.Parse(imageProperties.Height.ToString());
                    }
                    string PCap = "";
                    PostCaption.Document.GetText(Windows.UI.Text.TextGetOptions.None, out PCap);
                    var UpResult = await Api.InstaApi.UploadPhotosAlbumAsync(imgs, PCap);

                    ContentDialog End = new ContentDialog
                    {
                        FlowDirection   = FlowDirection.RightToLeft,
                        FontFamily      = new FontFamily("/Assets/Fonts/IRANSansWeb(FaNum).ttf#IRANSansWeb(FaNum)"),
                        Content         = "گالری با موفقیت ارسال شد",
                        CloseButtonText = "باشه"
                    };
                    await End.ShowAsync();
                }
                else if (_Target.Count == 1)
                {
                    string PCap = "";
                    PostCaption.Document.GetText(Windows.UI.Text.TextGetOptions.None, out PCap);
                    ImageProperties imageProperties = await _Target[0].Properties.GetImagePropertiesAsync();
                    var             UpResult        = await Api.InstaApi.UploadPhotoAsync(new InstaSharper.Classes.Models.InstaImage(_Target[0].Path, int.Parse(imageProperties.Width.ToString()), int.Parse(imageProperties.Height.ToString())), PCap);

                    ContentDialog End = new ContentDialog
                    {
                        FlowDirection   = FlowDirection.RightToLeft,
                        FontFamily      = new FontFamily("/Assets/Fonts/IRANSansWeb(FaNum).ttf#IRANSansWeb(FaNum)"),
                        Content         = "پست با موفقیت ارسال شد",
                        CloseButtonText = "باشه"
                    };
                    await End.ShowAsync();
                }
            }
            else
            {
                if (await WebApi.Check())
                {
                    var _Target = (await tempFolder.GetFilesAsync()).Where(x => x.DisplayName.StartsWith("_tmpPic")).ToList();
                    if (_Target.Count > 1 && _Target.Count <= 10)
                    {
                        string PCap = "";
                        PostCaption.Document.GetText(Windows.UI.Text.TextGetOptions.None, out PCap);
                        ImagePostViewModel imagePostViewModel = new ImagePostViewModel();
                        imagePostViewModel.caption = PCap;

                        foreach (var img in _Target)
                        {
                            var filestream = await img.OpenStreamForReadAsync();

                            var filebytes = new byte[(int)filestream.Length];
                            filestream.Read(filebytes, 0, (int)filestream.Length);
                            imagePostViewModel.images.Add(Convert.ToBase64String(filebytes));
                        }

                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        dic.Add("type", InstaMediaType.Carousel.ToString());
                        dic.Add("accountusername", Api.Username);
                        dic.Add("data", Convert.ToBase64String(ToByteArray(imagePostViewModel)));
                        dic.Add("date", (new DateTime(DPicker.Date.Value.Year, DPicker.Date.Value.Month, DPicker.Date.Value.Day, TPicker.Time.Hours, TPicker.Time.Minutes, TPicker.Time.Seconds)).ToBinary().ToString());

                        var WResult = await WebApi.Post(WebApi.WebApiURL + "api/uwp/Add_Post", new HttpFormUrlEncodedContent(dic), new HttpCredentialsHeaderValue("Bearer", WebApi.Token));

                        if (WResult.IsSuccessStatusCode)
                        {
                            await Helper.ShowMessage("پست به صف افزوده شد", "پست به صف افزوده شد");
                        }
                        else
                        {
                            await Helper.ShowMessage("خطا در ارسال پست", "خطا در ارسال پست");
                        }
                    }
                    else if (_Target.Count == 1)
                    {
                        string PCap = "";
                        PostCaption.Document.GetText(Windows.UI.Text.TextGetOptions.None, out PCap);
                        ImagePostViewModel imagePostViewModel = new ImagePostViewModel();
                        imagePostViewModel.caption = PCap;

                        var filestream = await _Target[0].OpenStreamForReadAsync();
                        var filebytes  = new byte[(int)filestream.Length];
                        filestream.Read(filebytes, 0, (int)filestream.Length);
                        imagePostViewModel.images.Add(Convert.ToBase64String(filebytes));

                        Dictionary <string, string> dic = new Dictionary <string, string>();
                        dic.Add("type", InstaMediaType.Image.ToString());
                        dic.Add("accountusername", Api.Username);
                        dic.Add("data", Convert.ToBase64String(ToByteArray(imagePostViewModel)));
                        dic.Add("date", (new DateTime(DPicker.Date.Value.Year, DPicker.Date.Value.Month, DPicker.Date.Value.Day, TPicker.Time.Hours, TPicker.Time.Minutes, TPicker.Time.Seconds)).ToBinary().ToString());

                        var WResult = await WebApi.Post(WebApi.WebApiURL + "api/uwp/Add_Post", new HttpFormUrlEncodedContent(dic), new HttpCredentialsHeaderValue("Bearer", WebApi.Token));

                        if (WResult.IsSuccessStatusCode)
                        {
                            await Helper.ShowMessage("پست به صف افزوده شد", "پست به صف افزوده شد");
                        }
                        else
                        {
                            await Helper.ShowMessage("خطا در ارسال پست", "خطا در ارسال پست");
                        }
                    }
                }
            }
        }