Example #1
0
        private static void CreateUrl()
        {
            IRepository repository = new Repository(SessionFactoryProvider);
            var q = (from code in repository.AsQueryable<ResponseCodes>() where code.ResponseCode == 501 select code).Single();

            using (var transaction = new TransactionScope()){
            var ses = new Sesions {
                ExecutionTime = 4525,
                CreationTime = DateTime.Now,
                userIP = "asad"
            };
            repository.Save(ses);
            var url = new URLs {
                url = new Uri("http://www.google.lt"),
                sesion = ses,
            };
            repository.Save(url);
            var response = new Responses {
                ResponseTime = 12345,
                URL = url,
                ResponseCode = q,
                RequestStartTime = DateTime.Now
            };
            repository.Save(response);
            repository.Commit();
            transaction.Complete();
            }
            Sesions q2 = (from ses in repository.AsQueryable<Sesions>() where ses.userIP == "asad" select ses).Single();
            //ISesionToXML s2x = new SesionToXML();
            //s2x.ConvertSesionToXML(q2, "C:/hugas.xml");
        }
        private static SpotifyStatus MapModel(Responses.Status currentStatus, SpotifyStatus status)
        {
            status.Length = currentStatus.track.length;
              status.Album = currentStatus.track.album_resource.name;
              status.Artist = currentStatus.track.artist_resource.name;
              status.Track = currentStatus.track.track_resource.name;
              status.TrackID = currentStatus.track.track_resource.uri;
              status.Position = currentStatus.playing_position;
              status.Playing = currentStatus.playing;

              status.Success = true;

              return status;
        }
        private static void StartResponse(int i, URLs url, IDbBuffer<Responses> buffer)
        {
            IRequests request = new Requests(url.url);
            string response = request.SendRequests();
            var map = new StringCruncher(response);
            map.CrunchString();

            Responses responseEntitie = new Responses();
            responseEntitie.ResponseCode = map.code;
            responseEntitie.ResponseTime = map.timeTaken;
            responseEntitie.RequestStartTime = map.pr;
            responseEntitie.URL = url;
            lock (buffer) {
                buffer.AddToBuffer(responseEntitie);
            }
            responsesGotten++;
        }
        public bool CheckLocation(NameValueCollection args, out Responses.ErrorResponse error,
            out double lat, out double lng)
        {
            error = new Responses.ErrorResponse("invalid location info");
            lat = 0d;
            lng = 0d;

            String latitude = args["lat"] ?? "";
            String longitude = args["lng"] ?? "";

            String timestampStr = args["time"];

            int timestamp;
            if (!int.TryParse(timestampStr, out timestamp)) {
                return false;
            }

            String locationHash = (args["hash"] ?? "").ToLower();

            if (!Account.IsPasswordHashValid(locationHash)) {
                return false;
            }

            var bytes = new byte[latitude.Length + longitude.Length + timestampStr.Length + _sSalt.Length];
            Array.Copy(_sSalt, 0, bytes, 0, 2);
            UnicodeEncoding.UTF8.GetBytes(latitude, 0, latitude.Length, bytes, 2);
            Array.Copy(_sSalt, 2, bytes, 2 + latitude.Length, 2);
            UnicodeEncoding.UTF8.GetBytes(longitude, 0, longitude.Length, bytes, 4 + latitude.Length);
            Array.Copy(_sSalt, 4, bytes, 4 + latitude.Length + longitude.Length, 1);
            UnicodeEncoding.UTF8.GetBytes(timestampStr, 0, timestampStr.Length, bytes, 5 + latitude.Length + longitude.Length);
            Array.Copy(_sSalt, 5, bytes, 5 + latitude.Length + longitude.Length + timestampStr.Length, 2);

            var md5 = new MD5CryptoServiceProvider();
            var hash = String.Join("", md5.ComputeHash(bytes).Select(x => x.ToString("X2"))).ToLower();

            if (hash != locationHash) {
                return false;
            }

            return double.TryParse(latitude, out lat) && double.TryParse(longitude, out lng);
        }
Example #5
0
    // calls the relevant animation and displays a response during the animation
    public void SetResponse(Responses responseType = Responses.IDLERESPONSE, string msg = "")
    {
        if(responseType == Responses.IDLERESPONSE)
        {
            // on first load, just say hi.
            if (firstLoad)
            {
                firstLoad = false;
                text.text = "I'm " + this.name + "! What do you want?";
            }
            else
            {
                int choice = Random.Range(0, idleResponses.Length + 3);
                // otherwise pick one from a random set of messages
                if (choice < idleResponses.Length)
                {
                    text.text = idleResponses[choice];
                }
                else
                {
                    text.text = msg;
                }
            }
        }
        else {
            text.text = msg;

            // call the relevant animation
            switch(responseType)
            {
                case Responses.AGREE:      anim.SetTrigger("agree");      break;
                case Responses.DISAGREE:   anim.SetTrigger("disagree");   break;
                case Responses.MESSAGE:    anim.SetTrigger("message");    break;
                case Responses.ANGRY:      anim.SetTrigger("angry");      break;
                case Responses.HAPPY:      anim.SetTrigger("happy");      break;
                case Responses.DISMISSIVE: anim.SetTrigger("dismissive"); break;
            }
        }
    }
Example #6
0
        public static void PushLeaseBlobResponse(Responses.LeaseBlobResponse lbr)
        {
            SqlDataRecord record = new SqlDataRecord(new SqlMetaData[] {
                new SqlMetaData("LeaseId", System.Data.SqlDbType.UniqueIdentifier),
                new SqlMetaData("Date", System.Data.SqlDbType.DateTime),
                new SqlMetaData("LeaseBreakTimeSeconds", System.Data.SqlDbType.Int),
                new SqlMetaData("RequestId", System.Data.SqlDbType.UniqueIdentifier),
                new SqlMetaData("Version", System.Data.SqlDbType.NVarChar, 4000)
                });

            if (lbr.LeaseId.HasValue)
                record.SetGuid(0, lbr.LeaseId.Value);
            record.SetDateTime(1, lbr.Date);

            if (lbr.LeaseTimeSeconds.HasValue)
                record.SetInt32(2, lbr.LeaseTimeSeconds.Value);
            record.SetGuid(3, lbr.RequestID);
            record.SetString(4, lbr.Version);

            SqlContext.Pipe.SendResultsStart(record);
            SqlContext.Pipe.SendResultsRow(record);
            SqlContext.Pipe.SendResultsEnd();
        }
Example #7
0
 private static string buildreq(Responses.Status stat, string req)
 {
     StringBuilder f = new StringBuilder();
     if (stat.track.track_resource.uri == req)
     {
         f.AppendLine("not_changed");
         f.AppendLine((stat.playing ? 1 : 0).ToString());
         f.AppendLine((stat.repeat ? 1 : 0).ToString());
         f.AppendLine((stat.shuffle ? 1 : 0).ToString());
         f.AppendLine((stat.volume.ToString()));
         f.AppendLine(new DateTime().AddSeconds(stat.playing_position).ToString("HH:mm:ss"));
         f.AppendLine(stat.track.track_resource.uri);
         return f.ToString();
     }
     f.AppendLine((stat.playing ? 1 : 0).ToString());
     f.AppendLine((stat.repeat ? 1 : 0).ToString());
     f.AppendLine((stat.shuffle ? 1 : 0).ToString());
     f.AppendLine((stat.volume.ToString()));
     f.AppendLine(new DateTime().AddSeconds(stat.playing_position).ToString("HH:mm:ss"));
     f.AppendLine(stat.track.track_resource.name);
     f.AppendLine(stat.track.album_resource.name);
     f.AppendLine(stat.track.artist_resource.name);
     f.AppendLine(SpotifyAPI.GetArt(stat.track.album_resource.uri));
     f.AppendLine(stat.track.track_resource.uri);
     return f.ToString();
 }
Example #8
0
 static void processStatus(Responses.Status Status)
 {
     if (Status.track != null)
     {
         if (Status.track.track_type == "ad")
         {
             if (getSettingb("blockAds")) MutifyStatus = "Blocking ad!";
             else MutifyStatus = "Not blocking this ad";
             Out.WriteLine("Ad detected!, blocking it");
             if(getSettingb("blockAds")) Muting.Mute(true);
             API.Wait = -1; //remove waiting time
             bool playing = API.Status.playing;
             while (!playing)
             {
                 Status = API.Resume;
                 playing = Status.playing;
             }
             API.Wait = 60; //set back to default
         }
         else
         {
             if (Muting.Muted)
             {
                 Muting.Mute(false);
             }
         }
     }
     if (StatusChanged != null)
         StatusChanged();
 }
Example #9
0
        public bool CheckAuth(NameValueCollection args, out Account account,
            out Responses.ErrorResponse error, bool acceptSession = true, bool onlyValidated = true)
        {
            error = new Responses.ErrorResponse("auth error");
            account = null;

            String sessionCode = args["session"];
            String passwordHash = args["phash"];
            String username = null;
            int userid = -1;

            if (args["uname"] != null) {
                username = args["uname"];
                if (username.Length == 0) {
                    error = new Responses.ErrorResponse("auth error: no username given");
                    return false;
                }
                if (!Account.IsUsernameValid(username)) {
                    error = new Responses.ErrorResponse("auth error: invalid credentials");
                    return false;
                }
            } else if (args["uid"] != null) {
                if (!Int32.TryParse(args["uid"], out userid)) {
                    error = new Responses.ErrorResponse("auth error: invalid userid");
                    return false;
                }
            } else {
                error = new Responses.ErrorResponse("auth error: no username or user id given");
                return false;
            }

            if (acceptSession && sessionCode != null && sessionCode.Length > 0) {
                if (!AuthSession.IsCodeValid(sessionCode)) {
                    error = new Responses.ErrorResponse("auth error: invalid session code");
                    return false;
                }
            } else if (passwordHash != null && passwordHash.Length > 0) {
                if (!Account.IsPasswordHashValid(passwordHash)) {
                    error = new Responses.ErrorResponse("auth error: invalid credentials");
                    return false;
                }
            } else {
                if (acceptSession)
                    error = new Responses.ErrorResponse("auth error: no password or session code given");
                else
                    error = new Responses.ErrorResponse("auth error: no password given");

                return false;
            }

            if (username != null) {
                account = DatabaseManager.SelectFirst<Account>(x => x.Username == username);
            } else {
                account = DatabaseManager.SelectFirst<Account>(x => x.AccountID == userid);
            }

            if (account == null) {
                error = new Responses.ErrorResponse("auth error: incorrect credentials");
                return false;
            }

            if (passwordHash != null && passwordHash.Length != 0) {
                if (!passwordHash.EqualsCharArray(account.PasswordHash)) {
                    error = new Responses.ErrorResponse("auth error: incorrect credentials");
                    return false;
                }
            } else {
                AuthSession sess = AuthSession.Get(account);

                if (sess == null || !sessionCode.EqualsCharArray(sess.SessionCode)) {
                    error = new Responses.ErrorResponse("auth error: incorrect session code");
                    return false;
                }

                if (sess.IsExpired) {
                    error = new Responses.ErrorResponse("auth error: session expired");
                    return false;
                }

                sess.Refresh();
            }

            if (onlyValidated && account.Rank < Rank.Verified) {
                error = new Responses.ErrorResponse("auth error: account not activated");
                return false;
            }

            return true;
        }
        /// <summary>
        /// Upload progress
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uploadProgress(object sender, Responses.Progress e)
        {
            if (UploadProgress != null)
            {
                CoPilot.Interfaces.Progress progress = new CoPilot.Interfaces.Progress();
                progress.Elapsed = e.Elapsed;
                progress.Eta = e.Eta;
                progress.Percent = e.Percent;
                progress.Speed = e.Speed;
                progress.Status = e.Status;
                progress.TotalSize = e.TotalSize;
                progress.UploadedBytes = e.UploadedBytes;

                ProgressEventArgs args = new ProgressEventArgs();
                args.Progress = progress;
                UploadProgress.Invoke(this, args);
            }
        }
        /// <summary>
        /// Upload complete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uploadComplete(object sender, Responses.UploadDone e)
        {
            if (UploadComplete != null)
            {
                CoPilot.Interfaces.UploadDone upload = new CoPilot.Interfaces.UploadDone();
                upload.DeleteUrl = e.DeleteUrl;
                upload.DownloadUrl = e.DownloadUrl;
                upload.FileId = e.FileId;
                upload.Status = e.Status;

                UploadEventArgs args = new UploadEventArgs();
                args.UploadDone = upload;
                UploadComplete.Invoke(this, args);
            }
        }