public ActionResult Index(string data0, string data1, string data2, string data3, int Id, string viewId) { var errors = new List <string>(); var nameCookie = "AdServer" + viewId; try { var selectionRequest = new MultimediaObjectSelection.MultimediaObjectsSelectionParams { ID = Id, Data0 = data0, Data1 = data1, Data2 = data2, Data3 = data3, RequestDate = DateTime.Now, RequestSource = (int)Statistic.RequestSourceType.WWW }; var ips = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; selectionRequest.RequestIP = !string.IsNullOrEmpty(ips) ? ips.Split(',')[0] : Request.ServerVariables["REMOTE_ADDR"]; var sessionId = Request.Cookies.Get(nameCookie) == null?Guid.NewGuid().ToString() : Request.Cookies[nameCookie]["sessionId"]; selectionRequest.SessionId = sessionId; var cookie = new HttpCookie(nameCookie); cookie.Values.Add("sessionId", sessionId); using (var ctx = new AdServContext()) { var repositories = EFRepositorySet.CreateRepositorySet(ctx); try { var mos = new MultimediaObjectSelection(repositories); List <string> err = new List <string>(); const string key = "FILESTREAM_OPTION"; var urlKey = ConfigurationManager.AppSettings[key]; bool filestreamOption = false; if (urlKey != null && !string.IsNullOrEmpty(urlKey)) { bool.TryParse(urlKey, out filestreamOption); } bool add = true; if (Request.UrlReferrer != null) { if (Request.Url.Host == Request.UrlReferrer.Host) { add = false; } } AdFile response = mos.GetMultimediaObject(selectionRequest, filestreamOption, add, out err); cookie.Values.Add("cmp", response.CmpId.ToString()); if (err != null && err.Count > 0) { errors.AddRange(err); } else { cookie.Values.Add("Id", response.ID.ToString()); cookie.Values.Add("StatusCode", response.StatusCode.ToString()); Response.AppendCookie(cookie); return(File(response.Contents, response.MimeType)); } } catch (Exception ex) { var hierarchy = new List <Exception>(); ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(selectionRequest, ex); } } } catch (Exception ex) { var hierarchy = new List <Exception>(); ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(ex); } return(null); }
/// <summary> /// Pobiera obiekt multimedialny, który zostanie zwrócony do klienta /// </summary> /// <param name="request">Parametry, na podtswie których zostanie przeprowadzone wyszukiwanie obiektu multimedialnego</param> /// <param name="errors">Lista komunikaktów błędów - jesli wystąpiły błędy</param> /// <returns>Wyszukany obiekt multimedialny opakowany w obiekt odpowiedniego typu</returns> private static GetMultimediaObject_Response GetMultimediaObject(GetMultimediaObject_Request request, out List <string> errors) { var response = new GetMultimediaObject_Response(); errors = new List <string>(); var hierarchy = new List <Exception>(); try { if (request != null) { var selectionRequest = new MultimediaObjectSelection.MultimediaObjectsSelectionParams { Data0 = request.Data0, Data1 = request.Data1, Data2 = request.Data2, Data3 = request.Data3, ID = request.ID, RequestDate = DateTime.Now, SessionId = request.SessionId, RequestSource = (int) (System.Web.HttpContext.Current.Request.UserAgent == null ? Statistic.RequestSourceType.Desktop : Statistic.RequestSourceType.WWW), RequestIP = HttpContext.Current.Request.UserHostAddress }; using (var ctx = new AdServContext()) { var repositories = EFRepositorySet.CreateRepositorySet(ctx); try { var mos = new MultimediaObjectSelection(repositories); List <string> err; const string key = "FILESTREAM_OPTION"; var urlKey = ConfigurationManager.AppSettings[key]; var filestreamOption = false; if (urlKey != null && !string.IsNullOrEmpty(urlKey)) { bool.TryParse(urlKey, out filestreamOption); } response.File = mos.GetMultimediaObject(selectionRequest, filestreamOption, true, out err); if (err != null && err.Count > 0) { errors.AddRange(err); } } catch (Exception ex) { ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(selectionRequest, ex); } } } else { errors.Add("Parametr requesta nie może być nullem."); } } catch (Exception ex) { ExceptionsHandlingHelper.HierarchizeError(ex, ref hierarchy); if (hierarchy.Count > 0) { errors.AddRange(hierarchy.Select(s => s.Message + Environment.NewLine + s.StackTrace).Distinct().AsEnumerable()); } SaveErrorInLogFile(ex); } return(response); }