public HttpResponseMessage Get(HttpRequestMessage request) { // 请确保该存储帐户是准备好了. if (Global.StorageAccount == null) { if (!Global.InitializeStorage()) { return(this.CreateStringResponse(HttpStatusCode.BadRequest, "该服务目前不可用.请稍后再试.")); } } try { StoryDataContext storyDataContext = new StoryDataContext(Global.StorageAccount.TableEndpoint.AbsoluteUri, Global.StorageAccount.Credentials); // 查询表存储. var query = from s in storyDataContext.Stories select s; // 将结果转换为一个简化的类,不包含分区/行键. List <Story> stories = new List <Story>(); foreach (StoryDataModel.Story s in query) { stories.Add(new Story() { Name = s.Name, VideoUri = s.VideoUri }); } DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List <Story>)); using (MemoryStream stream = new MemoryStream()) { jsonSerializer.WriteObject(stream, stories); stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { string result = reader.ReadToEnd(); return(this.CreateJsonResponse(HttpStatusCode.OK, result)); } } } catch (StorageClientException ex) { if (ex.StatusCode == HttpStatusCode.NotFound) { return(this.CreateStringResponse(HttpStatusCode.NotFound, "请求的Story不存在")); } // 一般错误,跟踪并返回泛用消息. Trace.Write("处理表服务错误: " + ex.Message, "Error"); return(this.CreateStringResponse(HttpStatusCode.InternalServerError, "该服务目前不可用.请稍后再试.")); } catch (DataServiceQueryException ex2) { Trace.Write("处理表服务错误: " + ex2.Message, "Error"); return(this.CreateStringResponse(HttpStatusCode.InternalServerError, "该服务目前不可用.请稍后再试.")); } }
// Constructor public App() { BugSenseHandler.Instance.InitAndStartSession(new ExceptionManager(Current), RootFrame, "8279d9f3"); Data = new FeedHelper.FeedData(); Data.FeedList = new ObservableCollection <string>(); if (System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Count != 0) { foreach (string key in System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Keys) { Data.FeedList.Add(System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[key].ToString()); Debug.WriteLine(System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[key].ToString()); } } if (Data.FeedList.Count == 0) { App.Data.FeedList.Add("http://smartfiction.ru?json=get_recent_posts&count=4"); } using (StoryDataContext context = ConnectionFactory.GetStoryDataContext()) { //context.DeleteDatabase(); if (context.DatabaseExists() == false) { context.CreateDatabase(); } } ViewModel = new ViewModel.MainViewModel(); //CopyToIsolatedStorage(); //Utilities.hyphenator = OpenLocal("Hyphenator.js"); //ADDED ViewModel.FeedItems = new ObservableCollection <ViewModel.ContentItem>(); UnhandledException += Application_UnhandledException; InitializeComponent(); InitializePhoneApplication(); }
private void TxtSearchHistory_OnTextChanged(object sender, TextChangedEventArgs e) { if (!string.IsNullOrEmpty(txtSearchHistory.Text) && string.Compare(txtSearchHistory.Text, "поиск", StringComparison.InvariantCultureIgnoreCase) != 0) { using (StoryDataContext context = ConnectionFactory.GetStoryDataContext()) { App.ViewModel.History = new ObservableCollection <Story>( context.Stories.Where(s => s.Title.Contains(txtSearchHistory.Text) && !s.IsFavorite) .OrderByDescending(s => s.DateCreated) .ToList()); } } else { using (StoryDataContext context = ConnectionFactory.GetStoryDataContext()) { App.ViewModel.History = new ObservableCollection <Story>(context.Stories.Where(s => !s.IsFavorite).OrderByDescending(s => s.DateCreated).ToList()); } } }
// Constructor public App() { BugSenseHandler.Instance.Init(this, "a9b557af"); Data = new FeedHelper.FeedData(); Data.FeedList = new ObservableCollection <string>(); if (System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Count != 0) { foreach (string key in System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings.Keys) { Data.FeedList.Add(System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[key].ToString()); Debug.WriteLine(System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings[key].ToString()); } } if (Data.FeedList.Count == 0) { App.Data.FeedList.Add("http://smartfiction.ru?json=get_recent_posts&count=4"); } using (StoryDataContext context = ConnectionFactory.GetStoryDataContext()) { //context.DeleteDatabase(); if (context.DatabaseExists() == false) { context.CreateDatabase(); } } ViewModel = new ViewModel.MainViewModel(); //ADDED ViewModel.FeedItems = new ObservableCollection <ViewModel.ContentItem>(); BugSenseHandler.Instance.UnhandledException += Application_UnhandledException; //UnhandledException += Application_UnhandledException; InitializeComponent(); InitializePhoneApplication(); }
public override void Run() { // 这是worker实现示例.请替换为您的逻辑. Trace.WriteLine("VideoEncodingWorkerRole入口点调用", "Information"); // 获取本地存储的路径 . string localStorageRoot = RoleEnvironment.GetLocalResource("PhotoStore").RootPath; string diagnosticsRoot = RoleEnvironment.GetLocalResource("DiagnosticStore").RootPath; while (true) { try { // 从队列中得到一条消息. CloudQueueMessage message = this._queue.GetMessage(TimeSpan.FromMinutes(20d)); if (message != null) { string storyID = message.AsString; // 短影无法编码... if (message.DequeueCount > 3) { Trace.Write("短影" + storyID + "已尝试多次均未能被处理.", "Error"); this._queue.DeleteMessage(message); } else { Trace.Write("开始处理短影" + storyID + ".", "Information"); string storyFolderPath = Path.Combine(localStorageRoot, storyID); Directory.CreateDirectory(storyFolderPath); // 下载Xml 配置文件. CloudBlob blob = this._container.GetBlobReference(storyID + ".xml"); string config = blob.DownloadText(); XDocument xdoc = XDocument.Parse(config); string storyName = xdoc.Root.Attribute("Name").Value; foreach (var photo in xdoc.Root.Elements("Photo")) { // 下载照片,并将其保存在本地存储. string photoBlobUri = photo.Attribute("Uri").Value; CloudBlob photoBlob = this._container.GetBlobReference(photoBlobUri); string localPhotoFilePath = Path.Combine(localStorageRoot, storyID, photo.Attribute("Name").Value); photoBlob.DownloadToFile(localPhotoFilePath); // 修改图片的名称,包括完整路径 . photo.Attribute("Name").Value = localPhotoFilePath; } // 保存配置文件到本地存储. string configFilePath = Path.Combine(localStorageRoot, storyID + ".xml"); xdoc.Save(configFilePath, SaveOptions.None); // 编码视频. string outputFilePath = Path.Combine(localStorageRoot, storyID + ".mp4"); string logFilePath = Path.Combine(diagnosticsRoot, storyID + ".log"); int hr = NativeMethods.EncoderVideo(configFilePath, outputFilePath, logFilePath); if (hr != 0) { Trace.Write("编码短影" + storyID + "时出错. 非托管代码返回的HRESULT: " + hr + ".", "Error"); } else { // 上传结果视频至blob. string blobName = storyID + "/"; blobName += string.IsNullOrEmpty(storyName) ? storyID : storyName; blobName += ".mp4"; CloudBlob outputBlob = this._container.GetBlobReference(blobName); outputBlob.UploadFile(outputFilePath); outputBlob.Properties.ContentType = "video/mp4"; outputBlob.SetProperties(); StoryDataContext storyDataContext = new StoryDataContext( this._storageAccount.TableEndpoint.AbsoluteUri, this._storageAccount.Credentials); storyDataContext.AddObject("Stories", new Story(storyID, storyName, outputBlob.Uri.AbsoluteUri)); storyDataContext.SaveChanges(); // 删除本地文件. File.Delete(configFilePath); File.Delete(outputFilePath); foreach (string fileName in Directory.GetFiles(storyFolderPath)) { File.Delete(fileName); } Directory.Delete(storyFolderPath); this._queue.DeleteMessage(message); // TODO: 我们应该从 blob删除短影的配置文件和照片? Trace.Write("短影 " + storyID + " 成功编码.", "Information"); } } } } catch (Exception ex) { Trace.Write("处理短影错误: " + ex.Message); } Thread.Sleep(10000); } }