Exemplo n.º 1
0
        public void TemporaryDocumentRepository_GetByID()
        {
            TemporaryDocument document = TemporaryDocumentRepository.Instance.GetByID(Guid.Parse("A46E69CB-93BD-499A-90D4-93F0164762BD"), 1);

            Assert.IsNotNull(document);
            Assert.IsTrue(document.DocumentID != Guid.Empty);
        }
Exemplo n.º 2
0
        public void Upload(int chartID, int type, string imageData)
        {
            try
            {
                // base.LogExceptionOnly(Session["CurrentUserID"] == null ? "IMAGEPROCESSOR SERVICE -- SESSION IS NULL" : string.Format("IMAGEPROCESSOR SERVICE -- SESSION == {0}", Session["CurrentUserID"]));
                int currentUserID = UserSessionWrapper.CurrentUserID;

                if (currentUserID == -1)
                {
                    throw new Exception("App Timeout");
                }
                else
                {
                    // we only check to see if it is "In Process" and if it is not -- default to published
                    OrganizationChartTypeViews selectedChartView = (type == (int)OrganizationChartTypeViews.InProcess) ? OrganizationChartTypeViews.InProcess : OrganizationChartTypeViews.Published;

                    byte[] imageByteData = Convert.FromBase64String(imageData);          // convert from base64
                    using (MemoryStream ms = new MemoryStream(imageByteData))
                    {
                        //////------------------------------------------------------------------------------
                        ////// FOR TESTING PURPOSES ONLY: Temporarily save image for offline review
                        ////using (Image chartImage = Image.FromStream(ms))
                        ////{
                        ////    // save image to generated directory
                        ////    chartImage.Save(@"C:\HCMS\HCMS.OrgChart\Processing\Generated\" + string.Format("testImage_{0}_{1}_{2}.png", chartImage.Width, chartImage.Height, chartImage.PixelFormat.ToString()));
                        ////}
                        //////------------------------------------------------------------------------------

                        using (Bitmap bmp = new Bitmap(ms))
                        {
                            PixelFormat selectedPixelFormat = PixelFormat.Format32bppArgb;

                            using (Bitmap trimmedBMP = ImageManager.CropWhitespaceAndAlpha(bmp, selectedPixelFormat))
                            {
                                byte[] trimmedByteData = ImageManager.ConvertToByteArray(trimmedBMP, ImageFormat.Png);

                                // store in database -- cleaner than file system
                                // allows it to work in load-balanced environments with no issues
                                TemporaryDocument newDocument = new TemporaryDocument()
                                {
                                    UserID       = currentUserID,
                                    DocumentData = trimmedByteData
                                };

                                Guid newGuidValue = TemporaryDocumentRepository.Instance.Save(newDocument);
                                ChartGenerationParametersSessionWrapper.Parameters = new ChartGenerationParameters()
                                {
                                    ID         = chartID,
                                    ChartType  = selectedChartView,
                                    DocumentID = newGuidValue
                                };
                            }
                        }
                    }

                    // Normally, we would allow garbage collection to happen as dictated by the sytem
                    // We need to call it now due to the vast amount of memory used in the previous operation
                    // Test and monitor the following
                    GC.Collect();
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    if (ex is OutOfMemoryException)
                    {
                        throw new Exception("MemoryException");
                    }
                    else
                    {
                        if (ex.Message == "App Timeout")
                        {
                            throw ex;
                        }
                        else
                        {
                            if (ex.InnerException == null)
                            {
                                base.LogExceptionOnly(ex);
                            }
                            else
                            {
                                base.LogExceptionOnly(ex.InnerException);
                            }

                            // throw new Exception("We've encountered an error while processing your request.  Please contact the system administrator.");
                            throw;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                ChartGenerationParameters chartParameters = ChartGenerationParametersSessionWrapper.Parameters;

                if (UserSessionWrapper.CurrentUserID == -1 || chartParameters.ID == -1 || chartParameters.DocumentID == Guid.Empty || chartParameters.ChartType == OrganizationChartTypeViews.None)
                {
                    context.Response.Redirect(MyTrackerURL, false);
                }
                else
                {
                    int currentUserID = UserSessionWrapper.CurrentUserID;

                    // get TemporaryDocument by documentID and userID
                    TemporaryDocument currentDocument = TemporaryDocumentRepository.Instance.GetByID(chartParameters.DocumentID, currentUserID);

                    if (currentDocument.DocumentID == Guid.Empty)
                    {
                        context.Response.Redirect(MyTrackerURL, false);
                    }
                    else
                    {
                        // Get IOrganizationChart
                        IOrganizationChart chart = null;

                        if (chartParameters.ChartType == OrganizationChartTypeViews.InProcess)
                        {
                            // In-Process
                            chart = OrganizationChartManager.Instance.GetByID(chartParameters.ID);
                        }
                        else
                        {
                            // Published Chart -- This will have the "ApprovedBy", "OnBehalfOf" and "ApprovedDate"
                            chart = OrganizationChartLogManager.Instance.GetByID(chartParameters.ID);
                        }

                        // Pass to PDF Builder
                        OrganizationChartPDFBuilder builder = new OrganizationChartPDFBuilder(context, context.Server.MapPath(ConfigWrapper.OrgChartTemplateFilePath));
                        builder.BuildChart(chart, currentDocument);

                        try
                        {
                            // Delete temporary document from database
                            TemporaryDocumentRepository.Instance.Delete(chartParameters.DocumentID, currentUserID);
                        }
                        catch (Exception ex)
                        {
                            // log if there is an error, but don't prevent execution
                            base.LogExceptionOnly(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    base.LogExceptionOnly(ex);
                }
                else
                {
                    base.LogExceptionOnly(ex.InnerException);
                }

                // throw new Exception("Error Encountered");
                throw new Exception(ex.ToString());
            }

            context.Response.End();
        }