コード例 #1
0
        internal static void CloseSlides()
        {
            try
            {
                if (_PowerPointProcess != null && !_PowerPointProcess.HasExited)
                {
                    if (!_PowerPointProcess.CloseMainWindow())
                    {
                        _PowerPointProcess.Kill();
                    }
                }
                else
                {
                    Win32CloseWindow();
                }

                PPTInteropSlides.Close();
            }
            catch (Exception ex)
            {
                AppLogging.Instance.Error("Error: Closing PowerPoint ", ex);
            }
        }
コード例 #2
0
        public virtual async Task <bool> UpdateSlideInfo()
        {
            var ServerSlidesInfo = await this.GetSlideInfo();

            if (ServerSlidesInfo.lastUpdated > this.lastUpdated)
            {
                HttpResponseMessage response = null;
                HttpClientHandler   handler  = new HttpClientHandler();

                handler.UseDefaultCredentials = true;

                using (var client = new HttpClient(handler))
                {
                    try
                    {
                        client.BaseAddress = new Uri(PPTScreenSaver.Properties.Settings.Default.ClientConfigConnectionString);

                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                        // New code:
                        response = await client.GetAsync("api/SlideDeck/Slides/?id=" + ServerSlidesInfo.Id);

                        if (response.IsSuccessStatusCode)
                        {
                            var path = SlideShowPath + "\\" + "Slides.pptx";
                            using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
                            {
                                ServerSlidesInfo = (SlideInfo)await response.Content.ReadAsAsync <SlideInfo>();

                                await stream.WriteAsync(ServerSlidesInfo.SlideData, 0, ServerSlidesInfo.SlideData.Length);

                                this.Id          = ServerSlidesInfo.Id;
                                this.lastUpdated = ServerSlidesInfo.lastUpdated;
                                this.PPTFilePath = path;
                            }
                            this.Save();
                        }
                        else
                        {
                            throw new HttpRequestException("Web Service returned " + response.StatusCode, new Exception(response.ReasonPhrase));
                        }
                    }
                    catch (Exception ex)
                    {
                        AppLogging.Instance.Error("Error: Connecting to Config service ", ex);
                    }
                }

                try
                {
                    PPTInteropSlides.CreateSlides(this.PPTFilePath);
                }
                catch (Exception ex)
                {
                    AppLogging.Instance.Error("Error: Unable to save PowerPoint Slides as images ", ex);
                }

                return(true);
            }

            return(false);
        }