示例#1
0
 public static void AddInstaApi(IInstaApi api)
 {
     if (api != null)
     {
         if (InstaApiList.Count == 0)
         {
             InstaApiList.Add(api);
         }
         else
         {
             try
             {
                 if (InstaApiList.Any(x => x.GetLoggedUser().UserName.ToLower() != api.GetLoggedUser().UserName.ToLower()))
                 {
                     InstaApiList.Add(api);
                 }
             }
             catch { InstaApiList.Add(api); }
         }
     }
 }
示例#2
0
        //public static async Task LoadSession()
        //{
        //    try
        //    {
        //        CreateFolder();
        //        LocalFolder.Path.PrintDebug();
        //        var file = await LocalFolder.GetFileAsync(OldStateFile);
        //        var json = await FileIO.ReadTextAsync(file);
        //        if (string.IsNullOrEmpty(json))
        //            return;
        //        var content = Decrypt(json);
        //        content.PrintDebug();
        //        BuildApi();

        //        //await Task.Delay(350);

        //        await InstaApi.LoadStateDataFromStringAsync(content);

        //        return;
        //    }
        //    catch (Exception ex) { ex.PrintException("LoadSession ex"); }

        //    try
        //    {
        //        var file = await LocalFolder.GetFileAsync(StateFile);
        //        var json = await FileIO.ReadTextAsync(file);
        //        if (string.IsNullOrEmpty(json))
        //            return;
        //        var content = Decrypt(json);
        //        content.PrintDebug();
        //        BuildApi();
        //        await InstaApi.LoadStateDataFromStringAsync(content);

        //        return;
        //    }
        //    catch (Exception ex) { ex.PrintException("LoadSession ex"); }
        //}


        public static async Task LoadSessionsAsync()
        {
            try
            {
                LocalFolder.Path.PrintDebug();
                var files = await LocalFolder.GetFilesAsync();

                if (files?.Count > 0)
                {
                    for (int i = 0; i < files.Count; i++)
                    {
                        var item = files[i];
                        if (item.Path.ToLower().EndsWith(SessionFileType))
                        {
                            try
                            {
                                var json = await FileIO.ReadTextAsync(item);

                                if (!string.IsNullOrEmpty(json))
                                {
                                    var content = Decrypt(json);
                                    content.PrintDebug();
                                    var api = BuildApi();
                                    await api.LoadStateDataFromStringAsync(content);

                                    InstaApiList.Add(api);
                                }
                            }
                            catch { }
                        }
                    }
                    if (InstaApiList.Count > 0)
                    {
                        if (string.IsNullOrEmpty(InstaApiSelectedUsername))
                        {
                            InstaApi = InstaApiList[0];


                            InstaApiSelectedUsername = InstaApi.GetLoggedUser().LoggedInUser.UserName.ToLower();
                        }
                        else
                        {
                            if (InstaApiList.Count == 1)
                            {
                                InstaApi = InstaApiList[0];
                            }
                            else
                            {
                                var first = InstaApiList
                                            .FirstOrDefault(x => x.GetLoggedUser()?.LoggedInUser.UserName.ToLower() ==
                                                            InstaApiSelectedUsername.ToLower());


                                if (first == null)
                                {
                                    InstaApi = InstaApiList[0];
                                }
                                else
                                {
                                    InstaApi = first;
                                }
                            }
                        }

                        "Loaded users:".PrintDebug();
                        foreach (var item in InstaApiList)
                        {
                            item.GetLoggedUser().UserName.ToLower().PrintDebug();
                        }

                        CurrentUser = InstaApi.GetLoggedUser().LoggedInUser.ToUserInfo();
                    }

                    //var apis = InstaApiList.ToList();
                    //if (InstaApi != null)
                    //    apis.AddInstaApiX(Helper.InstaApi);
                    //MultiApiHelper.SetupPushNotification(apis);
                }
            }
            catch (Exception ex) { ex.PrintException("LoadSession ex"); }
        }