Exemple #1
0
        static void Main(string[] args)
        {
            try {
                // Считываем файлы конфигурации
                string annunciatorsJson = File.ReadAllText("AnnunciatorsSettings.txt");
                string vkSettingsJson   = File.ReadAllText("VkSettings.txt");

                // Преобразуем в JObject
                JObject annunciatorsObject = JObject.Parse(annunciatorsJson);
                JObject vkSettingsObject   = JObject.Parse(vkSettingsJson);

                // Десериализуем объекты
                MultipleAnnunciatorsSettings annunciatorsSettings = JsonConvert.DeserializeObject <MultipleAnnunciatorsSettings>(annunciatorsObject.ToString());
                VkSettings vkSettings = JsonConvert.DeserializeObject <VkSettings>(vkSettingsObject.ToString());

                // Запускаем параллельно сигнализаторы
                Parallel.ForEach(annunciatorsSettings.Annunciators, async a => {
                    ILogger logger            = InitializeFileLogger(a.Id.ToString());
                    VkAnnunciator annunciator = new VkAnnunciator(a, vkSettings, logger);
                    applicationLogger.Log(a.Id + " created " + DateTime.Now.ToLongTimeString());
                    await annunciator.StartAsync();
                });

                // Чтобы программа не завершилась
                while (true)
                {
                    Thread.Sleep(1000000);
                }
            }
            catch (Exception ex) {
                applicationLogger?.Log(ex.Message);
            }
        }
        void Awake()
        {
            VkSetts = Resources.Load <VkSettings> ("VkSettings");
            InitToken();
            DontDestroyOnLoad(transform.gameObject);
            if (VkApiInstance == null)
            {
                VkApiInstance = this;
            }
            if (Downloader == null)
            {
                Downloader = GetComponent <Downloader> ();
            }

#if UNITY_EDITOR
            CheckEditorSetup();
#endif


            if (VKToken.IsValidToken(CurrentToken))
            {
                IsUserLoggedIn = true;
            }
            else
            {
                IsUserLoggedIn = false;
            }
        }
Exemple #3
0
            public void Run(Track track)
            {
                var client = new WebClient();

                client.DownloadProgressChanged += (sender, args) =>
                {
                    DownloadProgress = args.ProgressPercentage;
                    StatusText       = DownloadProgress + "%";
                };
                client.DownloadFileCompleted += (sender, args) =>
                {
                    Downloading = false;
                    Completed   = true;

                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.Message, "An error occurred", MessageBoxButton.OK, MessageBoxImage.Error);
                        StatusText = "Download failed";
                        return;
                    }
                    if (args.Cancelled)
                    {
                        StatusText = "Cancelled";
                        return;
                    }

                    StatusText = "Completed";
                };
                client.DownloadFileAsync(new Uri(track.url), VkSettings.GetInstance().DownloadPath + "\\" + FileUtil.FilterIllegalFilenameCharacters(track.artist + " - " + track.title + ".mp3"));
                Downloading = true;
                StatusText  = "Starting...";
            }
 void Start()
 {
     settings   = VkApi.VkSetts;
     vkApi      = VkApi.VkApiInstance;
     downloader = vkApi.gameObject.GetComponent <Downloader>();
     if (vkApi.IsUserLoggedIn)
     {
         StartWorking();
     }
 }
Exemple #5
0
 public static void SimpleAuthorize(this IVkApi vkApi, VkSettings vkSettings)
 {
     vkApi.Authorize(new VkNet.Model.ApiAuthParams
     {
         ApplicationId = vkSettings.AppId,
         Login         = vkSettings.Login,
         Password      = vkSettings.Password,
         Settings      = VkNet.Enums.Filters.Settings.All
     });
 }
Exemple #6
0
 void Awake()
 {
     DontDestroyOnLoad(transform.gameObject);
     if (VkApiInstance == null)
     {
         VkApiInstance = this;
     }
     if (downloader == null)
     {
         downloader = GetComponent <Downloader> ();
     }
     vsetts = GetComponent <VkSettings>();
 }
    public void Login()
    {
        VkSettings vsetts = VkApi.VkSetts;

        if (vsetts.forceOAuth)
        {
            WSA_WebViewLogin();
            return;
        }
        if (OnWSALogin != null)
        {
            OnWSALogin(vsetts.scope, vsetts.VkAppId, vsetts.forceOAuth);
        }
    }
Exemple #8
0
    // Use this for initialization

    void Start()
    {
        sets  = VkApi.VkSetts;
        vkapi = VkApi.VkApiInstance;
        d     = vkapi.gameObject.GetComponent <Downloader> ();
        if (vkapi.IsUserLoggedIn)
        {
            startWorkingWithVk();
        }
        else
        {
            vkapi.LoggedIn += startWorkingWithVk;
            vkapi.Login();
        }
    }
    public static void CreateVkSettingsItem()
    {
        if (Resources.Load <VkSettings> ("VkSettings") != null)
        {
            EditorUtility.DisplayDialog("Hint", "file Assets/VkApiForMobile/Resources/VkSettings.asset already exists," +
                                        "use this option only if accidentaly deleted", "ok");
            return;
        }
        VkSettings asset = ScriptableObject.CreateInstance <VkSettings> ();

        AssetDatabase.CreateAsset(asset, "Assets/VkApiForMobile/Resources/VkSettings.asset");
        AssetDatabase.SaveAssets();

        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;
    }
    public static void EditVkSettings()
    {
        var winds = Resources.FindObjectsOfTypeAll <EditorWindow> ();

        var inspector = winds.Where(t => t.title == "UnityEditor.InspectorWindow").ToList();

        if (inspector.Count == 0)
        {
            EditorUtility.DisplayDialog("Hint", "In order to edit vk setting open Inspector window", "ok");
        }
        if (Resources.Load <VkSettings> ("VkSettings") == null)
        {
            CreateVkSettingsItem();
        }
        else
        {
            VkSettings asset = Resources.Load <VkSettings> ("VkSettings");
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = asset;
        }
    }
Exemple #11
0
        public VkAnnunciator(AnnunciatorSettings settings, VkSettings vk, ILogger logger)
        {
            this.settings = settings;
            this.vk       = vk;
            this.logger   = logger;

            // Авторизация вк
            ApiAuthParams param = new ApiAuthParams {
                ApplicationId = this.vk.AppId,
                Login         = this.vk.Login,
                Password      = this.vk.Password,
                Settings      = Settings.All
            };

            vkApi.Authorize(param);


            // Проверка формата времени уведомления
            if (settings.AnnunciationFormat.Contains("d"))
            {
                days = new Word("день", "дня", "дней");
            }

            if (settings.AnnunciationFormat.Contains("h"))
            {
                hours = new Word("час", "часа", "часов");
            }

            if (settings.AnnunciationFormat.Contains("m"))
            {
                minutes = new Word("минута", "минуты", "минут");
            }

            // Логируем
            Log($"Initialize annunciator: {this.settings.Id}");
        }
    public override void OnInspectorGUI()
    {
        myScript = (VkSettings)target;
        //DrawDefaultInspector();
        //EditorGUILayout.LabelField("Level", myTarget.Level.ToString());
        myScript.VkAppId=EditorGUILayout.IntField("Vk App Id",myScript.VkAppId);

        if(myScript.VkAppId==0)
            EditorGUILayout.HelpBox("Plese enter you vk app id",MessageType.Warning);
        if (myScript.VkAppId != 0 && !appid_saved)
        {
            appid_saved=true;
            PlayerPrefs.SetString("appid",myScript.VkAppId.ToString());
        }
        EditorGUILayout.HelpBox("Avoids using vk app for auth",MessageType.None);
        myScript.forceOAtuh = EditorGUILayout.Toggle(new GUIContent("ForceOatuh"),myScript.forceOAtuh);

        EditorGUILayout.HelpBox("If checked user will have to confirm scope on each auth",MessageType.None);
        myScript.revoke = EditorGUILayout.Toggle(new GUIContent("Revoke"),myScript.revoke);

        myFold = EditorGUILayout.Foldout(myFold,"Scope");
        if(myFold)
        {
            myScript.ads = EditorGUILayout.Toggle(new GUIContent("Ads"),myScript.ads);
            myScript.audio=EditorGUILayout.Toggle(new GUIContent("Audio"),myScript.audio);
            myScript.docs= EditorGUILayout.Toggle(new GUIContent("Docs"),myScript.docs);
            myScript.friends=EditorGUILayout.Toggle(new GUIContent("Friends"),myScript.friends);
            myScript.groups=EditorGUILayout.Toggle(new GUIContent("Groups"),myScript.groups);
            myScript.messages=EditorGUILayout.Toggle(new GUIContent("Messages"),myScript.messages);
            myScript.nohttps=EditorGUILayout.Toggle(new GUIContent("Nohttps"),myScript.nohttps);
            myScript.notes=EditorGUILayout.Toggle(new GUIContent("Notes"),myScript.notes);
            myScript.notifications=EditorGUILayout.Toggle(new GUIContent("notifications"),myScript.notifications);
            myScript.notify=EditorGUILayout.Toggle(new GUIContent("Notify"),myScript.notify);
            myScript.offers=EditorGUILayout.Toggle(new GUIContent("Offers"),myScript.offers);
            myScript.offline=EditorGUILayout.Toggle(new GUIContent("Offline"),myScript.offline);
            myScript.pages=EditorGUILayout.Toggle(new GUIContent("Pages"),myScript.pages);
            myScript.photos=EditorGUILayout.Toggle(new GUIContent("Photos"),myScript.photos);
            myScript.questions=EditorGUILayout.Toggle(new GUIContent("Questions"),myScript.questions);
            myScript.stats=EditorGUILayout.Toggle(new GUIContent("Stats"),myScript.stats);
            myScript.status=EditorGUILayout.Toggle(new GUIContent("Status"),myScript.status);
            myScript.video=EditorGUILayout.Toggle(new GUIContent("Video"),myScript.video);
            myScript.wall=EditorGUILayout.Toggle(new GUIContent("Wall"),myScript.wall);
        }
        EditorGUILayout.HelpBox("for example 5.33",MessageType.Info);
        myScript.apiVersion=EditorGUILayout.TextField("api version",myScript.apiVersion);

        EditorGUILayout.HelpBox("To make the plugin work in editor you need click to the button below," +
            "it will open the web browser and after you confirm you will be redirected to the blanck page, " +
            "copy the url and paste it to the field \"auth url\"",MessageType.Info);
        myScript.auth_url=EditorGUILayout.TextField("auth url",myScript.auth_url);
        if(GUILayout.Button("Connect editor to vk"))
        {
            if(myScript.VkAppId!=0)
            {
                myScript.generateScope();
                var url="https://oauth.vk.com/authorize?client_id="+myScript.VkAppId +
                    "&scope="+string.Join(",",myScript.scope.ToArray())+"&" +
                    "redirect_uri=https://oauth.vk.com/blank.html&" +
                    "display=popup&" +
                    "v=5.29&" +
                    "response_type=token";
                url=Uri.EscapeUriString(url);
                EditorUtility.DisplayDialog("Connection to vk","If you change scope you need to reconnect","ok");
                Application.OpenURL(url);
            }else
            {
                EditorUtility.DisplayDialog("Error","Please,enter vk app id","ok");
            }
        }

        if(GUILayout.Button("Check if it works"))
        {
            var token=parseToenFromString().access_token;
             var s="https://api.vk.com/method/users.get?fields=photo_200&v=5.29&access_token="+token;
            Application.OpenURL(s);

        }
        if(GUI.changed)
        {
            appid_saved=false;
            EditorUtility.SetDirty(myScript);
        }
    }
Exemple #13
0
 void Awake()
 {
     DontDestroyOnLoad(transform.gameObject);
     if (VkApiInstance == null)
         VkApiInstance = this;
     if(downloader==null)
     downloader = GetComponent<Downloader> ();
     vsetts=GetComponent<VkSettings>();
 }
Exemple #14
0
    public override void OnInspectorGUI()
    {
        myScript = (VkSettings)target;
        //DrawDefaultInspector();
        //EditorGUILayout.LabelField("Level", myTarget.Level.ToString());
        myScript.VkAppId = EditorGUILayout.IntField("Vk App Id", myScript.VkAppId);

        if (myScript.VkAppId == 0)
        {
            EditorGUILayout.HelpBox("Plese enter you vk app id", MessageType.Warning);
        }
        if (myScript.VkAppId != 0 && !appid_saved)
        {
            appid_saved = true;
            PlayerPrefs.SetString("appid", myScript.VkAppId.ToString());
        }
        EditorGUILayout.HelpBox("Avoids using vk app for auth", MessageType.None);
        myScript.forceOAtuh = EditorGUILayout.Toggle(new GUIContent("ForceOatuh"), myScript.forceOAtuh);

        EditorGUILayout.HelpBox("If checked user will have to confirm scope on each auth", MessageType.None);
        myScript.revoke = EditorGUILayout.Toggle(new GUIContent("Revoke"), myScript.revoke);

        myFold = EditorGUILayout.Foldout(myFold, "Scope");
        if (myFold)
        {
            myScript.ads           = EditorGUILayout.Toggle(new GUIContent("Ads"), myScript.ads);
            myScript.audio         = EditorGUILayout.Toggle(new GUIContent("Audio"), myScript.audio);
            myScript.docs          = EditorGUILayout.Toggle(new GUIContent("Docs"), myScript.docs);
            myScript.friends       = EditorGUILayout.Toggle(new GUIContent("Friends"), myScript.friends);
            myScript.groups        = EditorGUILayout.Toggle(new GUIContent("Groups"), myScript.groups);
            myScript.messages      = EditorGUILayout.Toggle(new GUIContent("Messages"), myScript.messages);
            myScript.nohttps       = EditorGUILayout.Toggle(new GUIContent("Nohttps"), myScript.nohttps);
            myScript.notes         = EditorGUILayout.Toggle(new GUIContent("Notes"), myScript.notes);
            myScript.notifications = EditorGUILayout.Toggle(new GUIContent("notifications"), myScript.notifications);
            myScript.notify        = EditorGUILayout.Toggle(new GUIContent("Notify"), myScript.notify);
            myScript.offers        = EditorGUILayout.Toggle(new GUIContent("Offers"), myScript.offers);
            myScript.offline       = EditorGUILayout.Toggle(new GUIContent("Offline"), myScript.offline);
            myScript.pages         = EditorGUILayout.Toggle(new GUIContent("Pages"), myScript.pages);
            myScript.photos        = EditorGUILayout.Toggle(new GUIContent("Photos"), myScript.photos);
            myScript.questions     = EditorGUILayout.Toggle(new GUIContent("Questions"), myScript.questions);
            myScript.stats         = EditorGUILayout.Toggle(new GUIContent("Stats"), myScript.stats);
            myScript.status        = EditorGUILayout.Toggle(new GUIContent("Status"), myScript.status);
            myScript.video         = EditorGUILayout.Toggle(new GUIContent("Video"), myScript.video);
            myScript.wall          = EditorGUILayout.Toggle(new GUIContent("Wall"), myScript.wall);
        }
        EditorGUILayout.HelpBox("for example 5.33", MessageType.Info);
        myScript.apiVersion = EditorGUILayout.TextField("api version", myScript.apiVersion);

        EditorGUILayout.HelpBox("To make the plugin work in editor you need click to the button below," +
                                "it will open the web browser and after you confirm you will be redirected to the blanck page, " +
                                "copy the url and paste it to the field \"auth url\"", MessageType.Info);
        myScript.auth_url = EditorGUILayout.TextField("auth url", myScript.auth_url);
        if (GUILayout.Button("Connect editor to vk"))
        {
            if (myScript.VkAppId != 0)
            {
                myScript.generateScope();
                var url = "https://oauth.vk.com/authorize?client_id=" + myScript.VkAppId +
                          "&scope=" + string.Join(",", myScript.scope.ToArray()) + "&" +
                          "redirect_uri=https://oauth.vk.com/blank.html&" +
                          "display=popup&" +
                          "v=5.29&" +
                          "response_type=token";
                url = Uri.EscapeUriString(url);
                EditorUtility.DisplayDialog("Connection to vk", "If you change scope you need to reconnect", "ok");
                Application.OpenURL(url);
            }
            else
            {
                EditorUtility.DisplayDialog("Error", "Please,enter vk app id", "ok");
            }
        }

        if (GUILayout.Button("Check if it works"))
        {
            var token = parseToenFromString().access_token;
            var s     = "https://api.vk.com/method/users.get?fields=photo_200&v=5.29&access_token=" + token;
            Application.OpenURL(s);
        }
        if (GUI.changed)
        {
            appid_saved = false;
            EditorUtility.SetDirty(myScript);
        }
    }