예제 #1
0
        public void BindChart(OrganizationChart chart, OrganizationChartTypeViews viewType)
        {
            try
            {
                this.customOrgChartDetails.BindData(chart);

                // set chart generation parameters
                ChartGenerationParameters chartParameters = new ChartGenerationParameters()
                {
                    ChartType = viewType
                };

                if (viewType == OrganizationChartTypeViews.InProcess)
                {
                    // get in process chart
                    int chartID = base.CurrentOrgChartID;
                    chartParameters.ID = chartID;

                    this.customDisplayChart.PreviewTitle = this.PreviewTitleInProcess;
                    OrganizationChartPositionCollection positionList = OrganizationChartPositionManager.Instance.GetOrganizationChartPositions(chartID);

                    // pass position list and starting point of the in-process chart
                    this.customDisplayChart.BindChart(chartParameters, positionList.ToList <IChartPosition>(), chart.StartPointWFPPositionID);
                }
                else if (viewType == OrganizationChartTypeViews.Published)
                {
                    int chartLogID = base.CurrentOrgChart.PublishedOrganizationChartLogID;
                    chartParameters.ID = chartLogID;
                    ChartGenerationParametersSessionWrapper.Parameters = chartParameters;

                    this.customDisplayChart.PreviewTitle = this.PreviewTitlePublished;

                    // Load up chart log based on most recent published version
                    OrganizationChartLog chartLog = OrganizationChartLogManager.Instance.GetByID(chartLogID);
                    IList <OrganizationChartPositionLog> positionList = OrganizationChartPositionLogManager.Instance.GetOrganizationChartPositionLogs(chartLogID);

                    // pass position list and starting point OF THE PUBLISHED CHART (not the in-process chart)
                    this.customDisplayChart.BindChart(chartParameters, positionList.ToList <IChartPosition>(), chartLog.StartPointWFPPositionID);
                }
            }
            catch (Exception ex)
            {
                base.HandleException(ex);
            }
        }
예제 #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;
                        }
                    }
                }
            }
        }
예제 #3
0
 public ChartGenerationParameters(int loadID, OrganizationChartTypeViews loadChartType)
 {
     this.ID         = loadID;
     this.ChartType  = loadChartType;
     this.DocumentID = Guid.Empty;
 }