lundi 29 juin 2015

Unable to dowload file using generic handler

I am using a generic handler to download csv/excel files. It was working fine until yesterday. Today suddenly it stopped working on deployment on IIS 7.5 (though he same code works well in visual studio debugging mode). Here is my code:

ASPX: This is a content page

<input type="button" class="btn-primary" id="btnDownload" title="Download" value="Download" onclick='return downloadReport(this);' data-toggle="modal" data-target="#myModal" navurl='<%: ResolveUrl("~/Handlers/DownloadData.ashx") %>' />

JS:

function downloadReport(btn) {
//I am using a kendoUI combo box and kendo js + also using bootstrap for design & modal popups & also i have applied bundling to kendo & bootstrap files. They seem to be working fine without any conflicts as all their api's are working.
var $mod = $("#masterModal");
    $mod.modal('show');
    //window.location = "Handlers/DownloadData.ashx?rtp=" + combobox.val();
    window.location.href = $(btn).attr("navurl") + "?rtp=" + combobox.val();
    setTimeout(function () {
        $mod.modal("hide");
    }, 2000);

    return false;
}

Master Page:

I am including the js file containing the above method just before end of body tag.

<script src='<%: ResolveUrl("~/Scripts/DataUploader.js") %>'></script>  
</body>
</html>

Handler: In handler Process Request Method

HttpResponse response = this._context.Response;
            HRReportData hrData = new HRReportData(ConfigMaster.DbProvider, ConfigMaster.ConnectionString, ConfigMaster.DBSchemaName);
            ReportDataManager rdm = null;
            ExcelPackage xlPackage = null;
            try
            {
                rdm = new ReportDataManager();
                DataSet ds = rdm.GetReportData(hrData, report_Type);
                if (ds != null && ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        xlPackage = new ExcelPackage();
                        ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add(report_Type.ToString());
                        worksheet.Cells["A1"].LoadFromDataTable(ds.Tables[0], true, TableStyles.Light1);
                        response.ClearHeaders();
                        response.ClearContent();
                        response.Clear();
                        response.ContentType = "application/octet-stream";
                        response.AppendHeader("content-disposition", "attachment;  filename=" + report_Type.ToString() + ".xlsx");
                        xlPackage.SaveAs(response.OutputStream);
                        response.Flush();
                        //response.Close();
                        //response.End();
                    }
                }
            }
            catch (Exception ex)
            {
                //LogError.MethodLevelError(Convert.ToString(Session["Username"]), ex);
                if (!(ex is System.Threading.ThreadAbortException))
                {
                    //Other error handling code here
                }
            }
            finally
            {
                if (xlPackage != null)
                {
                    xlPackage.Dispose();
                    xlPackage.Dispose();
                }
            }

Bundle config:

bundles.Add(new ScriptBundle("~/Kendo/kendo").Include(
                "~/Scripts/jquery-1.11.3.min.js",
                "~/Kendo/js/kendo.all.min.js"
               // "~/Scripts/DataUploader.js"
            ));
            bundles.Add(new ScriptBundle("~/bootstrap/bootstrap").Include(
                "~/bootstrap/js/holder.js",
                "~/bootstrap/js/ie10-viewport-bug-workaround.js",
                "~/bootstrap/js/ie-emulation-modes-warning.js",
                "~/bootstrap/js/bootstrap.min.js"
            ));

All above code works well in debugging mode and was working well in deployment mode as well. Don't know what has changed that it suddenly stopped working and I am unable to find out any reasons :(

Behaviour on deployment: Instead of staying on same page and downloading file it navigates to Handler and a blank screen is displayed. No file is downloaded.

Behaviour in debuuging mode OR when run using vs2012 express: It stays on same page and downloads the file as expected.

Somebody please help me on this.

Handle error converting {null} to type system.Int32 in input json

Platform : C# IDE : Microsoft Visual Studio 2010

I am new to Json and wondering on how to handle the error converting value {null} to type system.Int32 in an input. Any suggestion?

Regular expression lookhead lookbehind

I need some help with a regular expression for .NET, I have an input field for a telephone number.

I use a regex to format the value (050 33 11 00) to this format:

+32(0)50/33.11.00

But when I insert following value 09 323 23 56 I want to get following result:

+32(0)9/323.23.56

I've been looking at lookahead but can't find a working solution.

I'm using the folowing regex: (\x2B{1}3{1}2{1}\x28{1}\d{1}\x29{1}\d{2}\/\d{2}\.\d{2}\.\d{2}) which works for the first value.

The regex is placed on a textbox as editMask, so i would like instant live sanitizing.

textEdit.Mask.EditMask = editMask;

How to writer "Pointer to a pointer to a list of structured elements" in C# and how to read those poninter values in C#?

How to writer " The Pointer to a pointer to a list of structured elements" in C# and how to read those poninter values in C#?

get code coverage percentage in cruisecontrol.net c#

I am trying to get code coverage in cruisecontrol.net. Using the following NANT script:

<target name="code_coverage" description="finds the code covered with tests">
  <exec program="${vstest_console}">
    <arg value="/Settings:CodeCoverage.runsettings" />
    <arg value="/EnableCodeCoverage" />
    <arg value="Tests.dll"/>
  </exec>
</target>

I am able to get a .coverage file. First of all the name of the .coverage file is coming as user name appended with current date time and under a folder named randomly. In .runsettings file documentation, i was unable to find anything about changing the name of .coverage file. I need to change name of this file. The bigger problem is that a sub-folder with some GUID type name is created into which the coverage file is dumped and it changes every time a test is run with code coverage ON.

Secondly can somebody help me in extracting covered path percentage out of this. I just need to fail the build, if coverage is below a point. Lot of help is available on Google but is of VS 2010 and before. I need help for VS 2012 or VS 2013. Currently am working on VS 2013 Ultimate and am using .runsettings file for code coverage.

pinta software customization for resizing image

i want customize pinta software for implementing tool like a pentool in photo shop and convert resize system in pinta software to resize system like a photoshop and i want Guidance for this work. and show me a solution for this work.

Sequential vs parallel solution memory usage

I have a slight issue with the following scenario: I'm given a list of ID values, I need to run a SELECT query (where the ID is a parameter), then combine all the result sets as one big one and return it to the caller.

Since the query might run for minutes per ID (that's another issue, but at the moment I consider it as a given fact), and there can be 1000s of IDs in the input) I tried to use tasks. With that approach I experience a slow, but solid increase in memory use.

As a test, I made a simple sequential solution too, this has normal memory usage graph, but as expected, very slow. There's an increase while it's running, but then everything drops back to the normal level when it's finished.

Here's the skeleton of code:

public class RowItem
{
    public int ID { get; set; }
    public string Name { get; set; }
    //the rest of the properties
}


public List<RowItem> GetRowItems(List<int> customerIDs)
{
    // this solution has the memory leak
    var tasks = new List<Task<List<RowItem>>>();
    foreach (var customerID in customerIDs)
    {
        var task = Task.Factory.StartNew(() => return ProcessCustomerID(customerID));
        tasks.Add(task);
    }

    while (tasks.Any())
    {
        var index = Task.WaitAny(tasks.ToArray());
        var task = tasks[index];
        rowItems.AddRange(task.Result);
        tasks.RemoveAt(index);
    }

    // this works fine, but slow
    foreach (var customerID in customerIDs)
    {
        rowItems.AddRange(ProcessCustomerID(customerID)));
    }

    return rowItems;
}

private List<RowItem> ProcessCustomerID(int customerID)
{
    var rowItems = new List<RowItem>();
    using (var conn = new OracleConnection("XXX"))
    {
        conn.Open();
        var sql = "SELECT * FROM ...";
        using (var command = new OracleCommand(sql, conn))
        {
            using (var dataReader = command.ExecuteReader())
            {
                using (var dataTable = new DataTable())
                {
                    dataTable.Load(dataReader);
                    rowItems = dataTable
                               .Rows
                               .OfType<DataRow>()
                               .Select(
                                   row => new RowItem
                                   {
                                       ID = Convert.ToInt32(row["ID"]),
                                       Name = row["Name"].ToString(),
                                       //the rest of the properties
                                   })
                               .ToList();
                }
            }
        }
        conn.Close();
    }
    return rowItems;
}

What am I doing wrong when using tasks? According to this MSDN article, I don't need to bother disposing them manually, but there's barely anything else. I guess ProcessCustomerID is OK, as it's called in both variations.

update To log the current memory usage I used Process.GetCurrentProcess().PrivateMemorySize64, but I noticed the problem in Task Manager >> Processes