Is there a way to merge multiple properties and then sort via LINQ? - linq

I'm working on a class that has URL and FileName fields. An object can either have a URL or a FileName, but can't have both at the same time.
Is there any way to merge these two fields via LINQ and then sort them? I know I can't use
OrderBy(i => item.URL).ThenBy(i => item.FileName);
because it would just sort the items via URL first and then by their respective FileNames. I need to sort it as if I'm sorting only one field.
Thank you :)

var sorted = list.OrderBy(x => x.URL + x.FileName);
You can pad the URL if desired, or do just about any other operation you need.

Related

How to fetch all objects in s3 buckets based on dates?

Here is my usecase - objects in my buckets are suffixed with dates eg:
file-2018-10-10 , file-2018-10-15 etc.
If someone were to enter 2018-10-12, then my tool should download the nearest file in future, which in this case would be file-2018-10-15.
For that I first plan to list the bucket and loop through all the S3-Keys.
Is it possible to list the keys 'reverse-sorted'
Is there any shell script example to list the 'reverse-sorted' list?
No you can't list keys in reverse order, but you don't need to. You can specify the start key when you list a bucket's objects. In your case you would specify file-2018-10-12 as --start-after parameter for the list-object-v2 api.
https://docs.aws.amazon.com/cli/latest/reference/s3api/list-objects-v2.html
Basically, it is the answer to your first question.
You use the simple PHP reverse array function to reverse the array after fetching the result array.
$files_name = $s3->listObjects(array('Bucket' => $bucketName, 'Prefix' => $prefix));
$object2 = $files_name['Contents'];
$object2 = array_reverse($object2);

Difference between ListResultDto and List

In my application service, why should I return ListResultDto instead of returning List?
It seems like extra work.
On the frontend, it means I need to access the items property instead of treating the results as an array e.g.
Using ListResultDto
.subscribe((next) => this.entities = next.items);
Using List
.subscrube((next) => this.entities = next);
Using ListResultDto allows you to add additional information about your items in the future without breaking your existing API. If you return items as an array, you are restricting your API.
An example is TotalCount in PagedResultDto, if you want to implement pagination of items.

TYPO3 extbase access sorting

when using the fluid debug array I see a nested array lige this:
building
[+]floor
[+]room
When clicking the + the sub array is expanded sorted by UID and not by the "sorting" as I have specified in my repository.
protected $defaultOrderings = array(
'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
);
Can I either access the sorting value somehow?
Or can I somehow force TYPO3 to sort its own array after sorting?
The sorting field should not be manually set.
If you want to sort the entries please use the DataHandler like the Typo3 Backend.
Here is a solution:
TYPO3 CommandController: How to set table field "sorting" of Extbase Object?
By "clicking the +", you mean that the subobjects aren't sorted the way you specified in the TCA?
The sorting is lost on the subobjects because Extbases PersistenceRepository by default only sorts by the order specified in the object itself. But thats no biggie, you just have to specify to order by the subproperty, either with the defaultOrderings property or when building the query:
class FloorRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
// Order by BE sorting
protected $defaultOrderings = array(
'sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
'room.sorting' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
);
...
}
This should give you the Rooms of a Floor, Ordered by the sorting of the Floors, and in each Floor, the Rooms sorted by their sorting.
You can access the sorting property by defining it as integer in your model and creating the related getter (setter if needed)
protected $sorting

how to sort descending order of ObservableCollection into WP7.?

I want to sort my ObservableCollection into the Descending Order I had tried with different scenario but I am not able to sort it my code is like this.
1>
LeaderboardItems = new ObservableCollection<AEGAPI.clsAEGAPI.Leaderboard>(LeaderboardItems.OrderByDescending(a => a.Points));
2>
LeaderboardItems.OrderByDescending(p => p.Points);
I had tried lots of but I am not able to get my result.
Normally you can't sort a ObservableCollection, because than you are changing the collection. If you only want to show the sorted list:
List<AEGAPI.clsAEGAPI.Leaderboard> list = LeaderboardItems.OrderByDescending(p => p.Points).ToList()
Or you can directly bind the source to a listbox
listbox.ItemsSource = LeaderboardItems.OrderByDescending(p => p.Points)
The list will not react to changes on the observable collection. You have to implement it your self.
In the past i found someone who has made a sortable observable collection, maybe you can go for that option (search for : sortableobservablecollection), but is was a bit complex.
Greets

Removing duplicates from the List-LINQ

I have a situation Where I need to remove the duplicates from the list. This is coming because I have combined some lists togather.
List<Guid> CompleteListOfPeople = firstListGuids.Union(secondListGuids).ToList().Union(thirdListGuids).ToList();
What should I do to filer the list of Guids so that I get only unique Guids?
Thank you
Union should already give you unique values. Note that you don't need the intermediate ToList() call. Just:
List<Guid> completeListOfPeople = firstListGuids.Union(secondListGuids).
.Union(thirdListGuids)
.ToList();

Resources