Exemplo n.º 1
0
        /// <summary>
        /// To be overwritten by the corresponding subclass.
        /// </summary>
        /// <param name="rq">The rq.</param>
        /// <param name="rp">The rp.</param>
        /// <remarks>Documented by Dev10, 2008-08-07</remarks>
        /// <remarks>Documented by Dev05, 2009-01-16</remarks>
        public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp)
        {
            Stream responseStream;
            int cardId;
            string ContentTypeString;
            Side side;
            Guid extensionGuid;
            if (IsContent(rq.URL, out cardId, out side, out ContentTypeString))
            {
                string content = (side == Side.Question) ? DequeueQuestion(cardId) : DequeueAnswer(cardId);
                responseStream = new MemoryStream(Encoding.Unicode.GetBytes(content));

                rp.mediaStream = responseStream;
                rp.Headers["Content-Type"] = ContentTypeString + "; charset=UTF-16";
                rp.Headers["Content-Length"] = responseStream.Length;
            }
            else if (IsExtension(rq.URL, out extensionGuid))
            {
                if (extensionconnector.IsStreamAvailable(extensionGuid))
                    responseStream = extensionconnector.GetExtensionStream(extensionGuid);
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithDbAccess)
                    responseStream = direct_extensionconnector.GetExtensionStream(extensionGuid);
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithoutDbAccess || parent.CurrentUser.ConnectionString.SyncType == SyncType.FullSynchronized)
                {
                    lock (webClient)
                    {
                        try
                        {
                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.ExtensionURI, extensionGuid))), extensionGuid, extensionconnector);
                        }
                        catch (WebException exp)
                        {
                            if ((exp.Response as HttpWebResponse).StatusCode != HttpStatusCode.Forbidden)
                                throw exp;

                            string result = webClient.DownloadString(new Uri(string.Format(parent.CurrentUser.ConnectionString.ExtensionURI + "&user={1}&password={2}", -1,
                                parent.CurrentUser.ConnectionString.ServerUser.UserName, parent.CurrentUser.ConnectionString.ServerUser.Password)));

                            if (result != "TRUE")
                                throw new NoValidUserException();

                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.ExtensionURI, extensionGuid))), extensionGuid, extensionconnector);
                        }
                    }
                }
                else
                    throw new ArgumentException();

                rp.mediaStream = responseStream;
                rp.Headers["Content-Type"] = "application/bin";
                rp.Headers["Content-Length"] = responseStream.Length;
            }
            else
            {
                int mediaId = GetMediaID(rq.URL);

                if (connector.IsMediaAvailable(mediaId))
                    responseStream = connector.GetMediaStream(mediaId, null);
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithDbAccess)
                    responseStream = direct_connector.GetMediaStream(mediaId, connector);
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithoutDbAccess || parent.CurrentUser.ConnectionString.SyncType == SyncType.FullSynchronized)
                {
                    lock (webClient)
                    {
                        try
                        {
                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.LearningModuleFolder, mediaId))), mediaId, connector);
                        }
                        catch (WebException exp)
                        {
                            if ((exp.Response as HttpWebResponse).StatusCode != HttpStatusCode.Forbidden)
                                throw exp;

                            string result = webClient.DownloadString(new Uri(string.Format(parent.CurrentUser.ConnectionString.LearningModuleFolder + "&user={1}&password={2}", -1,
                                parent.CurrentUser.ConnectionString.ServerUser.UserName, parent.CurrentUser.ConnectionString.ServerUser.Password)));

                            if (result != "TRUE")
                                throw new NoValidUserException();

                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.LearningModuleFolder, mediaId))), mediaId, connector);
                        }
                    }
                }
                else
                    throw new ArgumentException();

                rp.mediaStream = responseStream;

                ContentTypeString = connector.GetPropertyValue(mediaId, MediaProperty.MimeType);
                if (ContentTypeString == null)
                {
                    Trace.WriteLine("MimeType delivered null, obviously the corresponding DB entry is missing...");
                    ContentTypeString = Helper.UnknownMimeType;
                }
                rp.Headers["Content-Type"] = ContentTypeString;
                rp.Headers["Content-Length"] = responseStream.Length;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// To be overwritten by the corresponding subclass.
        /// </summary>
        /// <param name="rq">The rq.</param>
        /// <param name="rp">The rp.</param>
        /// <remarks>Documented by Dev10, 2008-08-07</remarks>
        /// <remarks>Documented by Dev05, 2009-01-16</remarks>
        public override void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp)
        {
            Stream responseStream;
            int    cardId;
            string ContentTypeString;
            Side   side;
            Guid   extensionGuid;

            if (IsContent(rq.URL, out cardId, out side, out ContentTypeString))
            {
                string content = (side == Side.Question) ? DequeueQuestion(cardId) : DequeueAnswer(cardId);
                responseStream = new MemoryStream(Encoding.Unicode.GetBytes(content));

                rp.mediaStream               = responseStream;
                rp.Headers["Content-Type"]   = ContentTypeString + "; charset=UTF-16";
                rp.Headers["Content-Length"] = responseStream.Length;
            }
            else if (IsExtension(rq.URL, out extensionGuid))
            {
                if (extensionconnector.IsStreamAvailable(extensionGuid))
                {
                    responseStream = extensionconnector.GetExtensionStream(extensionGuid);
                }
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithDbAccess)
                {
                    responseStream = direct_extensionconnector.GetExtensionStream(extensionGuid);
                }
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithoutDbAccess || parent.CurrentUser.ConnectionString.SyncType == SyncType.FullSynchronized)
                {
                    lock (webClient)
                    {
                        try
                        {
                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.ExtensionURI, extensionGuid))), extensionGuid, extensionconnector);
                        }
                        catch (WebException exp)
                        {
                            if ((exp.Response as HttpWebResponse).StatusCode != HttpStatusCode.Forbidden)
                            {
                                throw exp;
                            }

                            string result = webClient.DownloadString(new Uri(string.Format(parent.CurrentUser.ConnectionString.ExtensionURI + "&user={1}&password={2}", -1,
                                                                                           parent.CurrentUser.ConnectionString.ServerUser.UserName, parent.CurrentUser.ConnectionString.ServerUser.Password)));

                            if (result != "TRUE")
                            {
                                throw new NoValidUserException();
                            }

                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.ExtensionURI, extensionGuid))), extensionGuid, extensionconnector);
                        }
                    }
                }
                else
                {
                    throw new ArgumentException();
                }

                rp.mediaStream               = responseStream;
                rp.Headers["Content-Type"]   = "application/bin";
                rp.Headers["Content-Length"] = responseStream.Length;
            }
            else
            {
                int mediaId = GetMediaID(rq.URL);

                if (connector.IsMediaAvailable(mediaId))
                {
                    responseStream = connector.GetMediaStream(mediaId, null);
                }
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithDbAccess)
                {
                    responseStream = direct_connector.GetMediaStream(mediaId, connector);
                }
                else if (parent.CurrentUser.ConnectionString.SyncType == SyncType.HalfSynchronizedWithoutDbAccess || parent.CurrentUser.ConnectionString.SyncType == SyncType.FullSynchronized)
                {
                    lock (webClient)
                    {
                        try
                        {
                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.LearningModuleFolder, mediaId))), mediaId, connector);
                        }
                        catch (WebException exp)
                        {
                            if ((exp.Response as HttpWebResponse).StatusCode != HttpStatusCode.Forbidden)
                            {
                                throw exp;
                            }

                            string result = webClient.DownloadString(new Uri(string.Format(parent.CurrentUser.ConnectionString.LearningModuleFolder + "&user={1}&password={2}", -1,
                                                                                           parent.CurrentUser.ConnectionString.ServerUser.UserName, parent.CurrentUser.ConnectionString.ServerUser.Password)));

                            if (result != "TRUE")
                            {
                                throw new NoValidUserException();
                            }

                            responseStream = new CachingStream(webClient.DownloadData(new Uri(string.Format(parent.CurrentUser.ConnectionString.LearningModuleFolder, mediaId))), mediaId, connector);
                        }
                    }
                }
                else
                {
                    throw new ArgumentException();
                }

                rp.mediaStream = responseStream;

                ContentTypeString = connector.GetPropertyValue(mediaId, MediaProperty.MimeType);
                if (ContentTypeString == null)
                {
                    Trace.WriteLine("MimeType delivered null, obviously the corresponding DB entry is missing...");
                    ContentTypeString = Helper.UnknownMimeType;
                }
                rp.Headers["Content-Type"]   = ContentTypeString;
                rp.Headers["Content-Length"] = responseStream.Length;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// To be overwritten by the corresponding subclass.
 /// </summary>
 /// <param name="rq">The rq.</param>
 /// <param name="rp">The rp.</param>
 /// <remarks>Documented by Dev10, 2008-08-07</remarks>
 public abstract void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp);
Exemplo n.º 4
0
 /// <summary>
 /// To be overwritten by the corresponding subclass.
 /// </summary>
 /// <param name="rq">The rq.</param>
 /// <param name="rp">The rp.</param>
 /// <remarks>Documented by Dev10, 2008-08-07</remarks>
 public abstract void OnResponse(ref HTTPRequestStruct rq, ref HTTPResponseStruct rp);