Пример #1
0
        private void AddHistory(StoryHistoryItem item)
        {
            pinnedToEnd = false;
            History.Add(item);

            if (item.OutputArgs != null)
            {
                CurrentState = new StoryState(item.OutputArgs);
                RaisePropertyChanged("CurrentState");
            }
        }
Пример #2
0
        private void Transcript(object sender, RoutedEventArgs e)
        {
            var transcript = History.ToArray();

            var request = HttpWebRequest.Create(new Uri(baseUrl + "/UploadTranscript.ashx", UriKind.Absolute));

            request.Method = "POST";

            request.BeginGetRequestStream(delegate(IAsyncResult requestResult)
            {
                try
                {
                    using (var stream = request.EndGetRequestStream(requestResult))
                    {
                        var settings = new XmlWriterSettings {
                            Indent = true, IndentChars = "\t"
                        };
                        using (var writer = XmlWriter.Create(stream, settings))
                        {
//							writer.WriteProcessingInstruction( "xml-stylesheet", "type=\"text/xsl\" encoding=\"UTF-8\" href=\"Transcript.xslt\" version=\"1.0\"" );

                            writer.WriteStartElement("Transcript");
                            writer.WriteAttributeString("storyUrl", Uri.UnescapeDataString("ShadowDemo"));

                            foreach (var item in transcript)
                            {
                                if (item.HasInput)
                                {
                                    writer.WriteElementString("Input", item.Input);
                                }

                                if (item.HasOutput)
                                {
                                    writer.WriteStartElement("Output");

                                    foreach (var channel in item.OutputArgs.Package)
                                    {
                                        writer.WriteStartElement(channel.Key.ToString());

                                        if (channel.Value.IsXml())
                                        {
                                            writer.WriteRaw(StoryHistoryItem.EnsureXml(channel.Value));
                                        }
                                        else
                                        {
                                            writer.WriteString(channel.Value);
                                        }

                                        writer.WriteEndElement();
                                    }

                                    writer.WriteEndElement();
                                }
                            }

                            writer.WriteEndElement();
                        }
                    }

                    request.BeginGetResponse(delegate(IAsyncResult responseResult)
                    {
                        try
                        {
                            var response = request.EndGetResponse(responseResult);
                            var buffer   = new byte[response.ContentLength];
                            response.GetResponseStream().Read(buffer, 0, buffer.Length);

                            Dispatcher.BeginInvoke(delegate
                            {
                                HtmlPage.Window.Navigate(
                                    new Uri(string.Format("{0}/Transcript.aspx?k={1}",
                                                          baseUrl,
                                                          Encoding.UTF8.GetString(buffer, 0, buffer.Length))),
                                    "_blank");
                            });
                        }
                        // TODO: Handle this...
                        catch { }
                    }, null);
                }
                // TODO: Handle this...
                catch { }
            }, null);
        }