Ejemplo n.º 1
0
 private CloudSession(UserInfo user, int projectId, string cloudId)
 {
     User = user;
     ProjectId = projectId;
     CloudId = cloudId;
     Hash = Md5(cloudId);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="CloudSession"/> object.
        /// </summary>
        /// <param name="user">The user to interact with the cloud data.</param>
        /// <param name="projectId">The project id to connect to.</param>
        public static CloudSession Create(UserInfo user, int projectId)
        {
            //Prepare login request
            HttpWebRequest login = (HttpWebRequest)WebRequest.Create("https://scratch.mit.edu/projects/" + projectId + "/cloud-data.js");
            login.Referer = "https://scratch.mit.edu"; // Required by Scratch servers
            login.Headers.Add("Cookie", "scratchcsrftoken=a; scratchlanguage=en; scratchsessionsid=" + user.SessionID + ";");
            login.Headers.Add("X-CSRFToken", "a");
            login.Headers.Add("X-Requested-With", "XMLHttpRequest");
            login.Host = "scratch.mit.edu";
            login.Method = "GET";

            //Get request response
            HttpWebResponse response = (HttpWebResponse)login.GetResponse();

            //Read response data
            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);

            return new CloudSession(user, projectId, reader.ReadToEnd().Substring(1495, 36));
        }