Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Custom Archive Provider - Works ok on my PC not at Customer Site

Hi all,

I have written a couple of Custom Archive Providers and have implemented sorting into them.

All works Ok, sorting is fast but on customer site one of the Archives sorts but extremely slowly. The other just hangs and ramps up the CPU on the Server

NB there are only items in the archive so it's not that I am trying to sort thousands of records

 

Here is the code that I have in the SetOrderBy function

public void SetOrderBy(params ArchiveOrderByInfo[] orderBy)
{
  string sOrderBy = string.Empty;
  if (orderBy != null && orderBy.Length > 0)
  {
    foreach (ArchiveOrderByInfo orderByInfo in orderBy)
    {
      if (sOrderBy.Length > 0)
      {
        sOrderBy += ",";
      }
      sOrderBy += orderByInfo.Name + " " + orderByInfo.Direction.ToString();
     }
     GetRows(sOrderBy);
  }
}

 

And here is the code that I have that sorts the ArchiveRows in the GetRows function to a max of two columns eg, "Order By Name ASC, Number DESC"

 

var filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First());
if (!options.StartsWith("rowcount"))
{
  _sOrderBy = options;
}
if (!string.IsNullOrEmpty(_sOrderBy))
{
  string[] sSplit = _sOrderBy.Split(',');
  List<ArchiveOrderByInfo> orderByInfos = new List<ArchiveOrderByInfo>();
  foreach (string s in sSplit)
  {
    string[] sSplit2 = s.Split(' ');
    ArchiveOrderByInfo orderByInfo = new ArchiveOrderByInfo(sSplit2[0], OrderBySortType.ASC);
    if (sSplit2[1] == "DESC")
    {
      orderByInfo.Direction = OrderBySortType.DESC;
    }
    orderByInfos.Add(orderByInfo);
  }
  if (orderByInfos.Count > 1)
  {
    filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ToList();
    if (orderByInfos[0].Direction == OrderBySortType.ASC && orderByInfos[1].Direction == OrderBySortType.ASC)
    {
      filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenBy(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
    }
    else if (orderByInfos[0].Direction == OrderBySortType.DESC && orderByInfos[1].Direction == OrderBySortType.ASC)
    {
      filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderByDescending(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenBy(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
    }
    else if (orderByInfos[0].Direction == OrderBySortType.ASC && orderByInfos[1].Direction == OrderBySortType.DESC)
    {
      filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenByDescending(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
    }
    else
    {
      filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderByDescending(z => z.ColumnData[orderByInfos[0].Name].RawValue).ThenByDescending(z => z.ColumnData[orderByInfos[1].Name].RawValue).ToList();
    }
 }
 else
 {
  filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderBy(z => z.ColumnData[orderByInfos[0].Name].RawValue).ToList();
  if (orderByInfos[0].Direction == OrderBySortType.DESC)
  {
    filteredAndSorted = archiveRows.GroupBy(x => x.RowKey).Select(y => y.First()).OrderByDescending(z => z.ColumnData[orderByInfos[0].Name].RawValue).ToList();
  }
 }
}

Like I say it all works fine on my Dev PC but not on the Customer Server so I don't think that it is anything particularly wrong with the code and it ending up in a loop when clicking a column header or doing it from the sort columns menu

Has anyone come across something similar before?

Cheers James

RE: Custom Archive Provider - Works ok on my PC not at Customer Site

Hi James,
I am not an archive provider dude but just in case ...
You seem to be calling GetRows in your SetOrderBy override.
That makes no sense to me.
In SetOrderBy you should merely deposit the orderBy info for later use in GetRows.
GetRows is invoked by the archive control and returns an IEnumerable<ArchiveRow> to the control.


/conrad

 

Af: Conrad Weyns 29. sep 2020

RE: Custom Archive Provider - Works ok on my PC not at Customer Site

Hi Conrad,

If I don't call GetRows though and pass in the OrderBy options as string then the list won't refresh when the SetOrderBy function gets fired by either a column header click or the closing of the Set Sort Order menu dialog (unless I am missing something)

PS this is in SOWeb

 

Cheers James

Af: James Carter 29. sep 2020

RE: Custom Archive Provider - Works ok on my PC not at Customer Site

Hi James,
I think you may be missing something. So we have to wake up Tony!
Conrad

 

---------------------------------------------

This is the Win client talking:

I have spend much time adopting the netserver archive providers in the Win client...
And I have fallen flat on my face so many times, it doesn't hirt any more :-)

The sequence of events when an archive control is loading is like this:
- Create the provider instance
- SetDesiredColumns
- SetDesiredEntities
- SetPageInfo
- SetOrderBy
- SetRestrictions
All these prepare the provider then,
- Iterate over GetRows( string options ) and push them out to the control
(Observe  the options param can be anything that the underlying provider understands)

When the user clicks on a column to change to orderBy, this sequence has to be triggered again.
I.o.w. the Archive control, must be triggered to reload. I would expect that this is implicit in a custom archive in Web. (It is in Win)
If it isn't then I you need to dig into the documentation, there must be some other way.

As I see it, GetRows in SetOrderBy starts a database fetch that serves noone.
And it may well disturb your system as it involves threads and Enumerator yielding.

Conrad

Af: Conrad Weyns 29. sep 2020

RE: Custom Archive Provider - Works ok on my PC not at Customer Site

Hi Conrad,

thanks for your time. The SOWin Archive was sorting ok by itself without any coding - must admit i haven't tried it recently

The SOWeb Archives wouldn't sort on column click or close of the Set Sort Order menus - hence the reason that I call GetRows with the options in the SetOrderBy override

We'll see what Tony has to say :)

 

Cheers James

Af: James Carter 29. sep 2020

RE: Custom Archive Provider - Works ok on my PC not at Customer Site

Hi Conrad,

you are correct I don't need to call GetRows myself it does get called but not with the Sort Order so I am now setting a global variable to my value of sOrderBy in SetOrderBy then reading that variable in GetRows rather than trying to use the parameter string options

Hitting the SetOrderBy does seem to fire the rest of the chain of events to cause a refresh - I didn't think this was working as the list was always loading unordered (due to me ignoring the parameter options if it was set to rowcount=true)

 

Thanks for pointing out the series of events  - it helped with problems I was having

 

Cheers James

Af: James Carter 1. okt 2020

RE: Custom Archive Provider - Works ok on my PC not at Customer Site

Hi James,

Good to hear. Thanks.
Most providers will have instance variables for depositing things like requested Columns, Restrictions etc for later use in GetRows.
In Win, I have never used the string param to GetRows.

Also, a provider instance will be used once and then destroyed. It is not designed to keep alive.

(Tony is on vacation this week - autumn shool vacation in the Oslo region)


/conrad

 

 

Af: Conrad Weyns 1. okt 2020