示例#1
0
        public MainWindow()
        {
            InitializeComponent();

            //ContentBackground.Background.Opacity = 1.0;
            new WindowResizer(this,
                              new WindowBorder(BorderPosition.TopLeft, topLeft),
                              new WindowBorder(BorderPosition.Top, top),
                              new WindowBorder(BorderPosition.TopRight, topRight),
                              new WindowBorder(BorderPosition.Right, right),
                              new WindowBorder(BorderPosition.BottomRight, bottomRight),
                              new WindowBorder(BorderPosition.Bottom, bottom),
                              new WindowBorder(BorderPosition.BottomLeft, bottomLeft),
                              new WindowBorder(BorderPosition.Left, left));

            TitleBar.MouseLeftButtonDown       += ((o, e) => DragMove());
            MinimizeButton.MouseLeftButtonDown += ((o, e) => WindowState = WindowState.Minimized);
            CloseButton.MouseLeftButtonDown    += ((o, e) => Close());

            _errorPage             = new ErrorPage();
            _errorPage.ErrorClose += _errorPage_ErrorClose;
            transitionControl.AddPage(_errorPage);

            _loadingPage = new LoadingPage();
            transitionControl.AddPage(_loadingPage);

            _update = new UpdateCheck();

            transitionControl.ShowPage(_loadingPage);

            _config = new Config(_configLocation ?? "");

            if (!_config.LoadConfig())
            {
                _configError = true;
            }
            else
            {
                if (_config.Fields.Proxy_Address != string.Empty)
                {
                    PRequest.SetProxy(_config.Fields.Proxy_Address, _config.Fields.Proxy_Port,
                                      _config.Fields.Proxy_User, _config.Fields.Proxy_Password);
                }

                var loc  = _config.Fields.Elpis_StartupLocation;
                var size = _config.Fields.Elpis_StartupSize;

                if (loc.X != -1 && loc.Y != -1)
                {
                    this.Left = loc.X;
                    this.Top  = loc.Y;
                }

                if (size.Width != 0 && size.Height != 0)
                {
                    this.Width  = size.Width;
                    this.Height = size.Height;
                }
            }
        }
示例#2
0
    internal IEnumerator SendRequest <T>(string section, string action, Action <Dictionary <string, T>, PResponse> callback) where T : GameVar, new()
    {
        var www = PRequest.Prepare(section, action, null);

        yield return(www);

        var response = PRequest.Process(www);

        var data = response.success ? response.json : null;

        Dictionary <string, T> gameVars = new Dictionary <string, T>();

        if (data != null)
        {
            if (data is IDictionary)
            {
                foreach (string key in data.Keys)
                {
                    if (data[key] is IDictionary)
                    {
                        gameVars.Add(key, (T)Activator.CreateInstance(typeof(T), new object[] { data[key] }));
                    }
                }
            }
        }

        callback(gameVars, response);
    }
    /// <summary>
    /// Initializes the API.  You must do this before anything else.
    /// </summary>
    /// <param name="publickey">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="privatekey">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="apiurl">
    /// A <see cref="System.String"/>
    /// </param>
    public static void Initialize(string publickey, string privatekey, string apiurl)
    {
        if (_instance != null)
        {
            return;
        }

        // Add Unity Extentions to LitJson
        LitJson.JsonExtend.AddExtentds();

        GameObject go = new GameObject("playtomic");

        GameObject.DontDestroyOnLoad(go);

        _instance = go.AddComponent("Playtomic") as Playtomic;
        _instance._leaderboards     = new PLeaderboards();
        _instance._playerlevels     = new PPlayerLevels();
        _instance._geoip            = new PGeoIP();
        _instance._gamevars         = new PGameVars();
        _instance._achievements     = new PAchievements();
        _instance._newsletter       = new PNewsletter();
        _instance._playerchallenges = new PPlayerChallenges();
        _instance._playerprofiles   = new PPlayerProfiles();

        PRequest.Initialise(publickey, privatekey, apiurl);
    }
示例#4
0
    internal IEnumerator SendRequest <T>(string name, string section, string action, Action <T, PResponse> callback, Dictionary <string, object> postdata = null) where T : GameVar, new()
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        var data = response.success ? response.json : null;

        T gameVar = new T();

        if (data != null)
        {
            if (data is IDictionary)
            {
                if (data.ContainsKey(name))
                {
                    gameVar = (T)Activator.CreateInstance(typeof(T), new object[] { data[name] });
                }
            }
        }

        callback(gameVar, response);
    }
示例#5
0
 public void DownloadUpdateAsync(string outputPath)
 {
     UpdatePath = outputPath;
     Log.O("Download Elpis Update...");
     Task.Factory.StartNew(() => PRequest.FileRequestAsync(DownloadUrl, outputPath,
                                                           DownloadProgressChanged, DownloadFileCompleted));
 }
    private IEnumerator SendListRequest <T>(Dictionary <string, object> postdata, Action <List <T>, int, PResponse> callback) where T : PlayerLevel, new()
    {
        var www = PRequest.Prepare(SECTION, LIST, postdata);

        yield return(www);

        var      response  = PRequest.Process(www);
        List <T> levels    = null;
        int      numlevels = 0;

        if (response.success)
        {
            var data = response.json;
            levels    = new List <T>();
            numlevels = (int)(double)data["numlevels"];

            var levelarr = (List <object>)data["levels"];

            for (var i = 0; i < levelarr.Count; i++)
            {
                levels.Add((T) new PlayerLevel((Dictionary <string, object>)levelarr[i]));
            }
        }

        callback(levels, numlevels, response);
    }
    private IEnumerator SendListRequest <T>(string section, string action, Dictionary <string, object> postdata, Action <List <T>, int, PResponse> callback) where T : PlayerScore
    {
        WWW www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.json;

        List <T> scores = new List <T>();

        int numscores = 0;

        if (response.success)
        {
            if (data.ContainsKey("numscores"))
            {
                int.TryParse(data["numscores"].ToString(), out numscores);
            }

            if (data.ContainsKey("scores"))
            {
                if (data["scores"] is IList)
                {
                    foreach (IDictionary score in (IList)data["scores"])
                    {
                        scores.Add((T)Activator.CreateInstance(typeof(T), new object[] { score }));
                    }
                }
            }
        }

        callback(scores, numscores, response);
    }
示例#8
0
 public void SetProxy(string address, int port, string user = "", string password = "")
 {
     PRequest.SetProxy(address, port, user, password);
     if (_bass != null)
     {
         _bass.SetProxy(address, port, user, password);
     }
 }
示例#9
0
    internal IEnumerator SendSaveRequest(string section, string action, Action <PResponse> callback, Dictionary <string, object> postdata = null)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
    private IEnumerator SendSaveRequest(string section, string action, Dictionary <string, object> postdata, Action <PResponse> callback)
    {
        WWW www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        PResponse response = PRequest.Process(www);

        callback(response);
    }
示例#11
0
    private IEnumerator SendRequest(string section, string action, Action <PResponse> callback, PNewsletterOptions options)
    {
        var www = PRequest.Prepare(section, action, options);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
    private IEnumerator SendRateRequest(Dictionary <string, object> postdata, Action <PResponse> callback)
    {
        var www = PRequest.Prepare(SECTION, RATE, postdata);

        yield return(www);

        var response = PRequest.Process(www);

        callback(response);
    }
示例#13
0
    private IEnumerator SendListRequest <T>(Dictionary <string, object> postdata,
                                            Action <List <T>, int, PResponse> callback) where T : PlayerChallenge, new()
    {
        var www = PRequest.Prepare(SECTION, LIST, postdata);

        yield return(www);

        List <T> challenges    = null;
        int      numchallenges = 0;
        var      response      = default(QuickResponse <ListChallengeResponse <T> >);

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;

            Thread t = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <ListChallengeResponse <T> >(data);
            });

            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }
        }
        else
        {
            response = new QuickResponse <ListChallengeResponse <T> > {
                success = false, errorcode = 1
            };
        }

        if (response.success)
        {
            var challengeArray = response.ResponseObject.challenges;

            challenges = new List <T>();

            for (int i = 0; i < challengeArray.Length; i++)
            {
                challenges.Add(challengeArray[i]);
            }

            numchallenges = challenges.Count;
        }

        var resp = new PResponse {
            errorcode = response.errorcode, success = response.success
        };

        callback(challenges, numchallenges, resp);
    }
示例#14
0
    private IEnumerator SendRequest(string section, string action, Action <PlayerCountry, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        callback(new PlayerCountry(data), response);
    }
示例#15
0
    private IEnumerator sendReplay(Dictionary <string, object> postdata, Action <bool> callback)
    {
        var www = PRequest.Prepare(SECTION, POSTRESULT, postdata);

        yield return(www);

        // no point threading this one due to tiny ammount of data
        var response = PRequest.FastProcess <ReplaySentResponse>(www);

        callback(response.success);
    }
示例#16
0
文件: Pandora.cs 项目: wade1990/Elpis
 protected internal string RPCRequest(string url, string data)
 {
     try
     {
         return(PRequest.StringRequest(url, data));
     }
     catch (Exception e)
     {
         Log.O(e.ToString());
         throw new PandoraException(ErrorCodes.ERROR_RPC, e);
     }
 }
    private IEnumerator SendSaveLoadRequest <T>(string section, string action, Dictionary <string, object> postdata, Action <T, PResponse> callback) where T : PlayerLevel
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        T   level    = default(T);

        if (response.success)
        {
            level = (T) new PlayerLevel((Dictionary <string, object>)response.json["level"]);
        }

        callback(level, response);
    }
示例#18
0
    private IEnumerator SendSaveLoadRequest(string section, string action, Dictionary <string, object> postdata, Action <PlayerLevel, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var         response = PRequest.Process(www);
        PlayerLevel level    = null;

        if (response.success)
        {
            level = new PlayerLevel((Dictionary <string, object>)response.json["level"]);
        }

        callback(level, response);
    }
示例#19
0
    private IEnumerator SendSaveLoadRequest <T>(string action,
                                                Dictionary <string, object> postdata,
                                                Action <T, PResponse> callback) where T : PlayerChallenge
    {
        var www = PRequest.Prepare(SECTION, action, postdata);

        yield return(www);

        var response  = default(QuickResponse <UpdateChallengeResponse <T> >);
        var challenge = default(T);

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;

            Thread t = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <UpdateChallengeResponse <T> >(data);
            });

            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }
        }
        else
        {
            response = new QuickResponse <UpdateChallengeResponse <T> > {
                success = false, errorcode = 1
            };
        }

        if (response.success)
        {
            challenge = response.ResponseObject.challenge;
        }

        var resp = new PResponse {
            success = response.success, errorcode = response.errorcode
        };

        callback(challenge, resp);
    }
示例#20
0
    private IEnumerator getReplay <T>(string section, string action, Dictionary <string, object> postdata, Action <T, PResponse> callback)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var replay   = default(T);
        var response = new QuickResponse <GetReplayResponse <T> >();

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;

            // spool deserialization off to another thread, allows UI to continue updating in the meantime
            Thread t = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <GetReplayResponse <T> >(data);
            });
            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }

            if (response.success)
            {
                replay = response.ResponseObject.challenge["replay"];
            }
        }
        else
        {
            response = new QuickResponse <GetReplayResponse <T> > {
                success = false, errorcode = 1
            };
        }

        var resp = new PResponse {
            errorcode = response.errorcode, success = response.success
        };

        callback(replay, resp);
    }
示例#21
0
    public static QuickResponse <T> FastProcess <T>(WWW www) where T : ResponseBase
    {
        var response = new QuickResponse <T>();

        if (!PRequest.WWWSuccess(www))
        {
            response.errorcode = 1;
            response.success   = false;
            return(response);
        }

        var results = LitJson.JsonMapper.ToObject <T>(www.text);

        response.success   = results.success;
        response.errorcode = results.errorcode;

        response.ResponseObject = results;
        return(response);
    }
示例#22
0
    private IEnumerator SendPing(Dictionary <string, object> postdata, int attempts)
    {
        while (attempts > 0)
        {
            var www = PRequest.Prepare(SECTION, PING, postdata);
            yield return(www);

            // no point threading this one due to tiny size of response
            var response = PRequest.FastProcess <ResponseBase>(www);

            // if successful exit
            if (response.success)
            {
                break;
            }

            attempts--;
        }
    }
示例#23
0
    /// <summary>
    /// Initializes the API.  You must do this before anything else.
    /// </summary>
    /// <param name="publickey">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="privatekey">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="apiurl">
    /// A <see cref="System.String"/>
    /// </param>
    public static void Initialize(string publickey, string privatekey, string apiurl)
    {
        if (_instance != null)
        {
            return;
        }

        var go = new GameObject("playtomic");

        GameObject.DontDestroyOnLoad(go);

        _instance = go.AddComponent("Playtomic") as Playtomic;
        _instance._leaderboards = new PLeaderboards();
        _instance._playerlevels = new PPlayerLevels();
        _instance._geoip        = new PGeoIP();
        _instance._gamevars     = new PGameVars();
        _instance._achievements = new PAchievements();
        _instance._newsletter   = new PNewsletter();

        PRequest.Initialise(publickey, privatekey, apiurl);
    }
示例#24
0
    internal IEnumerator SendListRequest <T>(string section, string action, Action <List <T>, PResponse> callback, Dictionary <string, object> postdata = null) where T : PlayerAchievement
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        List <T> achievements = new List <T>();

        if (response.success)
        {
            foreach (IDictionary achievment in (IList)data["achievements"])
            {
                achievements.Add((T)Activator.CreateInstance(typeof(T), new object[] { achievment }));
            }
        }

        callback(achievements, response);
    }
示例#25
0
    private IEnumerator SendUpdate <T>(string section,
                                       string action,
                                       Dictionary <string, object> postdata,
                                       Action <bool, PResponse> callback) where T : PlayerChallenge, new()
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = default(QuickResponse <ReplaySentResponse>);

        if (PRequest.WWWSuccess(www))
        {
            string data = www.text;
            Thread t    = new Thread(() =>
            {
                response = PRequest.FastProcessUnityThread <ReplaySentResponse>(data);
            });

            t.Start();

            // wait for thread to finish
            while (t.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }
        }
        else
        {
            response = new QuickResponse <ReplaySentResponse> {
                success = false, errorcode = 1
            };
        }

        var resp = new PResponse {
            errorcode = response.errorcode, success = response.success
        };

        callback(response.success, resp);
    }
示例#26
0
    internal IEnumerator SendStreamRequest(string section, string action, Action <List <PlayerAward>, int, PResponse> callback, Dictionary <string, object> postdata = null)
    {
        var www = PRequest.Prepare(section, action, postdata);

        yield return(www);

        var response = PRequest.Process(www);
        var data     = response.success ? response.json : null;

        int numachievements = 0;

        int.TryParse(data["numachievements"].ToString(), out numachievements);

        var achievements = new List <PlayerAward>();

        if (response.success)
        {
            var acharray = (List <object>)data["achievements"];
            achievements.AddRange(from object t in acharray select new PlayerAward((Dictionary <string, object>)t));
        }

        callback(achievements, numachievements, response);
    }
示例#27
0
        public Station(Pandora p, JToken d)
        {
            SkipLimitReached = false;
            SkipLimitTime    = DateTime.MinValue;

            _pandora = p;

            ID         = d["stationId"].ToString();
            IdToken    = d["stationToken"].ToString();
            IsCreator  = !d["isShared"].ToObject <bool>();
            IsQuickMix = d["isQuickMix"].ToObject <bool>();
            Name       = d["stationName"].ToString();
            InfoUrl    = (string)d["stationDetailUrl"];

            RefreshSeeds();

            if (IsQuickMix)
            {
                Name = "Quick Mix";
                _pandora.QuickMixStationIDs.Clear();
                var qmIDs = d["quickMixStationIds"].ToObject <string[]>();
                foreach (var qmid in qmIDs)
                {
                    _pandora.QuickMixStationIDs.Add((string)qmid);
                }
            }

            bool downloadArt = true;

            if (!_pandora.ImageCachePath.Equals("") && File.Exists(ArtCacheFile))
            {
                try
                {
                    ArtImage = File.ReadAllBytes(ArtCacheFile);
                }
                catch (Exception)
                {
                    Log.O("Error retrieving image cache file: " + ArtCacheFile);
                    downloadArt = true;
                }

                downloadArt = false;
            }

            if (downloadArt)
            {
                var value = d.SelectToken("artUrl");
                if (value != null)
                {
                    ArtUrl = value.ToString();

                    if (ArtUrl != String.Empty)
                    {
                        try
                        {
                            ArtImage = PRequest.ByteRequest(ArtUrl);
                            if (ArtImage.Length > 0)
                            {
                                File.WriteAllBytes(ArtCacheFile, ArtImage);
                            }
                        }
                        catch (Exception)
                        {
                            Log.O("Error saving image cache file: " + ArtCacheFile);
                        }
                    }
                }
                //}
            }
        }
示例#28
0
 public static void SetCredentials(string publickey, string privatekey, string apiurl)
 {
     PRequest.Initialise(publickey, privatekey, apiurl);
 }
示例#29
0
        public Song(Pandora p, JToken song)
        {
            metaDict = new Dictionary <object, object>();

            _pandora = p;

            TrackToken = (string)song["trackToken"];
            Artist     = (string)song["artistName"];
            Album      = (string)song["albumName"];

            AmazonAlbumID = (string)song["amazonAlbumDigitalAsin"];
            AmazonTrackID = (string)song["amazonSongDigitalAsin"];

            var aacUrl = string.Empty;

            try
            {
                aacUrl = (string)song["audioUrlMap"]["highQuality"]["audioUrl"];
            }
            catch { }

            if (_pandora.AudioFormat == PAudioFormat.AACPlus)
            {
                if (aacUrl == string.Empty)
                {
                    throw new PandoraException(ErrorCodes.NO_AUDIO_URLS);
                }

                AudioUrl = aacUrl;
            }
            else
            {
                string[] songUrls = null;
                try
                {
                    if (song["additionalAudioUrl"].HasValues)
                    {
                        songUrls = song["additionalAudioUrl"].ToObject <string[]>();
                    }
                    else
                    {
                        songUrls = new string[] { (string)song["additionalAudioUrl"] }
                    };
                }
                catch { }

                if (songUrls == null || songUrls.Length == 0)
                {
                    if (aacUrl != string.Empty)
                    {
                        AudioUrl = aacUrl;
                    }
                    else
                    {
                        throw new PandoraException(ErrorCodes.NO_AUDIO_URLS);
                    }
                }
                else if (songUrls.Length == 1)
                {
                    AudioUrl = songUrls[0];
                }
                else if (songUrls.Length > 1)
                {
                    if (_pandora.AudioFormat == PAudioFormat.MP3_HIFI)
                    {
                        if (songUrls.Length >= 2)
                        {
                            AudioUrl = songUrls[1];
                        }
                        else
                        {
                            AudioUrl = songUrls[0];
                        }
                    }
                    else //default to PAudioFormat.MP3
                    {
                        AudioUrl = songUrls[0];
                    }
                }
            }

            double gain = 0.0;

            double.TryParse(((string)song["trackGain"]), out gain);
            FileGain = gain;

            Rating          = (((int)song["songRating"]) > 0 ? SongRating.love : SongRating.none);
            StationID       = (string)song["stationId"];
            SongTitle       = (string)song["songName"];
            SongDetailUrl   = (string)song["songDetailUrl"];
            ArtistDetailUrl = (string)song["artistDetailUrl"];
            AlbumDetailUrl  = (string)song["albumDetailUrl"];
            AlbumArtUrl     = (string)song["albumArtUrl"];

            Tired        = false;
            StartTime    = DateTime.MinValue;
            Finished     = false;
            PlaylistTime = Time.Unix();

            if (!AlbumArtUrl.IsNullOrEmpty())
            {
                try
                {
                    AlbumImage = PRequest.ByteRequest(AlbumArtUrl);
                }
                catch { }
            }
        }