示例#1
0
        public static Message Compress(string target)
        {
            mode = CompressionMode.Compress;
            Target = target;
            Message message = new Message();

            string compressedBase64 = Target;
            int substitutionIndex = 0;
            if (!string.IsNullOrEmpty(Target))
            {
                foreach (string substitudedString in substitutedStrings)
                {
                    compressedBase64 = compressedBase64.Replace(substitudedString, substitutionChars[substitutionIndex]);
                    substitutionIndex++;
                }
            }
            message.Text = compressedBase64;
            return message;
        }
示例#2
0
        private void SendImage()
        {
            this._uri = new Uri(@"/composer/Home/PushMessage", UriKind.Relative);
            this._client = new WebClient();

            // You MUST modify the header fields for this to work otherwise it will respond
            // with regular HTTP headers.
            this._client.Headers["content-type"] = "application/json";

            // This will be fired after the upload is complete.
            this._client.UploadStringCompleted += (sndr, evnt) =>
            {
                if (evnt.Error != null)
                {
                    UploadResponse = string.IsNullOrWhiteSpace(evnt.Error.Message)
                        ? @"An exception occurred."
                        : evnt.Error.Message;
                }
                else if (evnt.Cancelled)
                {
                    UploadResponse = "Operation was cancelled.";
                }
                EA.GetEvent<CreateAndUploadFile>().Publish(string.Empty); //chaining the uploads so only one is happenning at a time for now.
                //TODO: Change later.
            };

            var document = HtmlPage.Document;
            var txtArea1 = document.GetElementById("MainContent_txtPNGBytes");
            if (txtArea1 != null)
            {
                string base64 = txtArea1.GetProperty("value").ToString();
                var myObject = new Message() { CompositionId = Composition.Id.ToString(), CollaborationId = Current.User.Index, Text = base64 };
                string json = Serialization.ToJson<Message>(myObject);
                this._client.UploadStringAsync(this._uri, "POST", json);
            }
        }
示例#3
0
        private void SendFile()
        {
            this._uri = new Uri(@"/composer/Home/CreateFile", UriKind.Relative);
            this._client = new WebClient();

            // You MUST modify the header fields for this to work otherwise it will respond
            // with regular HTTP headers.
            this._client.Headers["content-type"] = "application/json";

            // This will be fired after the upload is complete.
            this._client.UploadStringCompleted += (sndr, evnt) =>
            {
                if (evnt.Error != null)
                {
                    UploadResponse = string.IsNullOrWhiteSpace(evnt.Error.Message)
                        ? @"An exception occurred."
                        : evnt.Error.Message;
                }
                else if (evnt.Cancelled)
                {
                    UploadResponse = "Operation was cancelled.";
                }
            };

            var myObject = new Message() { CompositionId = Composition.Id.ToString(), CollaborationId = Current.User.Index, Text = "", CompositionTitle = Composition.Provenance.TitleLine };
            string json = Serialization.ToJson<Message>(myObject);
            this._client.UploadStringAsync(this._uri, "POST", json);
        }
示例#4
0
        public JsonResult CreateFile(Message data)
        {
            var response = new Message();
            if (data == null)
            {
                response.Text = @"data == null";
            }
            else
            {
                var path = Server.MapPath("/composer/compositionfiles/");
                string fileType = "htm";
                var fileName = data.CompositionId.ToString() + "_" + data.CollaborationId.ToString() + "." + fileType;
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(string.Format("{0}/{1}", path, fileName)))
                {
                    StringWriter stringWriter = new StringWriter();
                    // Put HtmlTextWriter in using block because it needs to call Dispose.
                    using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
                    {

                        writer.RenderBeginTag(HtmlTextWriterTag.Html);

                            writer.AddAttribute("prefix", "og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# wecontrib: http://ogp.me/ns/fb/wecontrib#");

                            writer.RenderBeginTag(HtmlTextWriterTag.Head);

                                writer.AddAttribute("http-equiv", "X-UA-Compatible");
                                writer.AddAttribute("content", "chrome=1, IE=edge");
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); writer.RenderEndTag();

                                writer.AddAttribute("property", "fb:admins");
                                writer.AddAttribute("content", "675485908");
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); writer.RenderEndTag();

                                writer.AddAttribute("property", "fb:app_id");
                                writer.AddAttribute("content", "171096762940671");
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); writer.RenderEndTag();

                                writer.AddAttribute("property", "og:url");
                                writer.AddAttribute("content", @"https://www.wecontrib.com/composer/compositionfiles/" + data.CompositionId.ToString() + "_" + data.CollaborationId.ToString() + ".htm");
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); ; writer.RenderEndTag();

                                writer.AddAttribute("property", "og:description");
                                writer.AddAttribute("content", data.CompositionTitle);
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); writer.RenderEndTag();

                                writer.AddAttribute("property", "og:type");
                                writer.AddAttribute("content", "wecontrib:composition");
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); writer.RenderEndTag();

                                writer.AddAttribute("property", "og:title");
                                writer.AddAttribute("content", data.CompositionTitle);
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); writer.RenderEndTag();

                                writer.AddAttribute("property", "og:image");
                                writer.AddAttribute("content", @"https://www.wecontrib.com/composer/compositionimages/" + data.CompositionId.ToString() + "_" + data.CollaborationId.ToString() + ".bmp");
                                writer.RenderBeginTag(HtmlTextWriterTag.Meta); writer.RenderEndTag();

                                writer.WriteLine("<script type='text/javascript'>");
                                string url = "window.location = 'https://www.wecontrib.com/composer/deck/card?id=" + data.CompositionId.ToString() + "&index=" + data.CollaborationId.ToString() + "';";
                                writer.WriteLine(url);
                                writer.WriteLine("</script>");
                            writer.RenderEndTag();
                            writer.RenderBeginTag(HtmlTextWriterTag.Body);

                            //writer.AddAttribute("src", "https://www.wecontrib.com/composer/compositionimages/" + data.CompositionId.ToString() + "_" + data.CollaborationId.ToString() + ".bmp");
                            //writer.RenderBeginTag(HtmlTextWriterTag.Img);
                            //writer.RenderEndTag();

                            writer.RenderEndTag();

                        writer.RenderEndTag();
                        file.WriteLine(stringWriter.ToString());
                    }
                }
            }
            return Json(response, JsonRequestBehavior.DenyGet);
        }
示例#5
0
 public JsonResult PushMessage(Message data)
 {
     var response = new Message();
     if (data == null)
     {
         response.Text = @"data == null";
     }
     else if (data.Text == null)
     {
         response.Text = @"data.Text == null";
     }
     else
     {
         var base64 = Composer.Messaging.Compression.Decompress(data.Text);
         var bitmapData = Convert.FromBase64String((base64));
         using (System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData))
         {
             using (Bitmap bitImage = new Bitmap((Bitmap)Image.FromStream(streamBitmap)))
             {
                 var path = Server.MapPath("/composer/compositionimages/");
                 string fileType = "bmp";
                 var fileName = data.CompositionId.ToString() + "_" + data.CollaborationId.ToString() + "." + fileType;
                 bitImage.Save(string.Format(@"{0}\{1}", path, fileName));
                 response.Text = string.Format("{0}", "Success");
             }
         }
     }
     return Json(response, JsonRequestBehavior.DenyGet);
 }