Sorting And Merging Data Returned From Web Service - asp.net

I'm working on a web service using asp.net.
I'm creating a timetable display board like you see in airports, bus stations or train stations.
I am in charge of creating the services for 1 station, and there are other people in charge of the other stations.
I have created my web services and now im trying to consume the others.
I can consume them but everyone else has got their web services returning different values, for example, I'm returning route id, journey id, start location, end location, stops, days running, times. but other peoples web services may return data like route id, start, end, stops, times, platform, journey status. in one table, and the other data that matches up with mine in another web service.
So how do i filter out the data that i do not need, like platform and journey status in the example.
Also, how would I merge everyone's data from web services into 1 grid view so i can display all the trains that pass through my station.
I'm quite new to web services, but I am trying and I have got quite a bit done by myself, im just stuck on this bit.
I hope this isn't a stupid question
Dim allStations As New List(Of ScheduleEntry)
Dim ws1 As New Hull.ArrivaServices()
For Each u1 As Hull.Result In ws1.ShowRouteByStation("hrw")
Dim s As New ScheduleEntry
s.StartTime = u1.Departure
s.StopTime = u1.Arrival
allStations.Add(s)
Next
Dim ws2 As New Heathrow.Heathrow_Airport()
For Each u2 As Heathrow.Result In ws2.GetHeathrowTrains
Dim s As New ScheduleEntry
s.StartTime = u2.BeginTime
s.StopTime = u2.EndTime
allStations.Add(s)
Next
GridView1.DataSource = allStations
GridView1.DataBind()

I converted the datasets to datatables to make it compatable with each other.
DatatableA.Merge(DatatableB)
So now DatatableA also Contains all the DatatableB collumns and rows.
If the column names are the same and the data type is the same, the 2 columns become 1.
So I made sure the data types were the same, if they werent I converted them, then renamed the column name in DatatableB to the column name in DatatableA.
DatatableA.Columns(columnnumber).ColumnName = "NewName"
Remember when counting the columnnumber, its left to right and the first column is 0
If I had to convert the datatype, I made a new column in DatatableB (Same name as corrisponding collumn in DatatableA)
DatatableB.Columns.Add("NewColumnName", GetType(DataType))
Then I created a loop to go through the datatable rows of the collumn with the data I want to convert
Dim i as integer
Dim z as integer
i = 0
z = DatatableB.Rows.Count`
and putting the new converted data in the NewColumn by using
Do until i = z
DatatableB.Rows(i)("ColumnName") = "ConvertedData)
Next
Hope this helps someone

Your problem isn't what we normally call sorting and merging, not really. The largest problem is that you have a number of services which all return similar data formats, but not identical. So your first step will be to make them identical: within your program.
First, decide what you want to display in your grid. Let's say you only want to display start and stop time. So make a class that can hold a start and stop time:
Public Class ScheduleEntry
Public Property Start As DateTime
Public Property Stop As DateTime
End Class
You will use a List(Of ScheduleEntry) to populate your grid.
Now, depending on which service you call, just take the Start and Stop and add them to your list. Assume the case of two services with different return values:
Dim allStations As New List(Of ScheduleEntry)
Dim ws1 As New SERVICE1.CLASS()
For Each u1 As SERVICE1.Result In ws1.METHOD
Dim s As New ScheduleEntry
s.StartTime = u1.Departure
s.StopTime = u1.Arrival
allStations.Add(s)
Next
Dim ws2 As New SERVICE2.CLASS()
For Each u2 As SERVICE2.Result In ws2.METHOD2
Dim s As New ScheduleEntry
s.StartTime = u2.BeginTime
s.StopTime = u2.EndTime
allStations.Add(s)
Next
GridView1.DataSource = allStations
GridView1.DataBind()

Related

Get values from a column having comma separated values using Linq

I am working in a web based application in which i am using lots of Linq query to fetch the data. I am stuck in one issue were in i need to get the rows from a column which has a comma separated values in it. I have a screen shot below :
As you can see that in the above screen shot we have 5 columns. I need data such that in the network column. For eg:
Network column first row has CMT, second row also has CMT and other rows also has CMT respectively.
But in the 8th row there is no CMT.
I need the rows only from networks having CMT values in it. Can anybody help me to write a Linq query?
This should help:
var list = new List<dynamic>
{
new {userid="SIMONE", networks = "CMT,MTT,MVV"},
new {userid="CURTINK", networks = "MTR,NAN,NOG"},
new {userid="JAMESL", networks = "CMT,LOGO,CMDY"},
new {userid="BONDINEG", networks = "TVL,TVLC,NKTN"}
};
var users = String.Join(",", list.Where(d => d.networks.Contains("CMT"))
.Select(u => u.userid));

Getting documents of last 25 minutes with formula and lotusscript

In lotus I have a view with order documents.
I am building an agent to search for all orders which are modified in the last 25 minutes.
For this I have done code like:
strFormule = "Form=""Order"" & #Modified >= #Adjust(#Today;0;0;0;0;-25;0) & Deleted !=""J"""
Set ndcOrder = currentDB.Search( strFormule, Nothing, 0 )
If ndcOrder.Count <> 0 Then
Set doc = ndcOrder.GetFirstDocument
While Not doc Is Nothing
So if it is 11.00 then it need to take orders which are modified today from 10.35
But in the debugger I also get orders which where modified 2 hours earlier.
How is this possible?
I think it's might be because you're using #today which doesn't have a time element. Try #Now instead ?
In the past I used the LotusScript method GetModifiedDocuments which lets you specify a NotesDateTime object to retrieve any document modified since.
Your code could then look like this:
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As notesdocumentcollection
Dim since As New NotesDateTime("")
Set db = session.CurrentDatabase
Call since.SetNow()
Call since.AdjustMinute(-25)
Set dc = db.GetModifiedDocuments(since)
My experience with this method was very good so far. More info on GetModifiedDocuments
Why use formula at all?
I would create a hidden view, first column is last modified date-time, sorted descending.
Then I would write my Lotusscript code to start at the top and work its way down until it encounters a date/time value that is older than 25 minutes ago.
Something like this:
Dim docs List As NotesDocument
Set dt25 = New NotesDateEntry(Now())
Call dt25.AdjustMinutes(-25)
Dim col as NotesViewEntryCollection
Dim entry as NotesViewEntry
Set col = view.AllEntries
Set entry = col.GetFirstEntry
Do Until entry Is Nothing
If Cdat(entry.ColumnValues(0))<Cdat(dt25.LSLocalTime) Then
Exit Loop
End If
Set docs(entry.Document.UniversalID) = entry.Document
Loop
' Now you have a list of documents created in the last 25 minutes.

StackoverflowException while in prod on IIS

I have a serious issue trying to put my Web Application into production.
My application is coded in VB.Net (With Visual Web Developer 2010), and the environment of production is a virtual machine with Microsoft Server 2008 R2, and IIS 7.5, the application is running with Asp.net 4.0. I tried also on my own computer (Windows 7), where I installed IIS, and the same bug occurs.
To limit the charge on SQL server, I put into session a list of rights, which is loaded each time the user wants to have access to any page.
The bug occurs exactly when this list contains more than 178 objects. At 178, the session is created and the page is correctly executed ; but when I add a 179th element or more (and I tried with different elements, so this can't come from the elements themselves), the page just don't execute correctly the code and IIS crash...
It seems that when there is more than 179 elements in this list, IIS just recycle the App, and so, the session is lost...
When I debug the application with Visual Web Developer, it is running well, without bug. But when I try to put it into production, that bug occurs. So, this seems to be linked with IIS.
Another problem is that when IIS recycle my App, it doesn't create any log file. So I have nothing more precise to give you.
I need help to find a solution to this problem. I try for a week, and I found nothing... this is driving me crazy... If someone has any idea or need more information, please tell me, so I can dig deeper...
Thanks to everyone.
EDIT :
I tried something else, I bypassed the sessions, and now, the rights are directly charged from SQL. The problem still occurs. So, it doesn't come from sessions, but SQL.
So, I wonder if there is any limit while doing requests on SQL.
But SQL doesn't seems to have any problem with request that return 3000 elements, and when it returns 179 elements with a lot of joins, it just crash... Well, I have no idea what to do or where search for a solution...
EDIT2 :
But, like I said, the problem doesn't occurs when I try execute the code from Visual Web developer. And, with it or in production environment, it's the same SQL server that execute de SQL requests... So, the problem can't come from SQL finally...
EDIT3 :
I finally found something. In the Windows logs, I have a StackOverflowException... What happy news ! (And we are on stackoverflow.com, is that linked? xD).
EDIT4 :
Here is the error from the windows log. Maybe it can help anyone.
Nom du journal :Application
Source : Windows Error Reporting
Date : 29/04/2014 11:53:11
ID de l’événement :1001
Catégorie de la tâche :Aucun
Niveau : Information
Mots clés : Classique
Utilisateur : N/A
Ordinateur : SRVWEB.DOMMH01.local
Description :
Récipient d’erreurs , type 0
Nom d’événement : CLR20r3
Réponse : Non disponible
ID de CAB : 0
Signature du problème :
P1 : w3wp.exe
P2 : 7.5.7601.17514
P3 : 4ce7afa2
P4 : System.Core
P5 : 4.0.30319.18408
P6 : 5231116c
P7 : 1197
P8 : 0
P9 : System.StackOverflowException
P10 :
Fichiers joints :
Ces fichiers sont peut-être disponibles ici :
C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_w3wp.exe_e41148f8d4e7fcf353a2d93bfe4367a48b981de2_0a6131b2
Symbole d’analyse :
Nouvelle recherche de la solution : 0
ID de rapport : 125b520d-cf84-11e3-912f-00155dc81602
Statut du rapport : 4
EDIT 5 :
I put here the piece of code where I take the rights with LINQ to SQL. I don't think this will be really helpful, but there it is...
A right contains a Username, the id of the rights, the id of a family (a family is a set of "objects"), and a place. So finnaly, I get a list of "Object/Place" associated with rights for a specified user... So I can limit the access for only some "object/place" for each user.
Another thing is the familyJoker, and the placeJoker. When a right is associated with a placeJoker, wee add to the rights of this user any object/place where the object is in the family. It's the same when the family is the familyJoker. Finally, if family and place are both joker, we add all the combinations possible(the combinations possible are in the objectPlace table)
This is the code :
Public Shared Function getListeDroitsUtilisateurSession(ByVal username As String) As List(Of DroitsUtilisateurSession)
Dim db As SINDIDB = New SINDIDB
Dim familleJoker As String = FamilleMetier.famille_Joker
Dim lieuJoker As String = Lieu.lieu_Joker
Dim requeteSansJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join oif In db.ObjetsInFamilleMetiers
On d.ID_Famille Equals oif.ID_Famille
Join f In db.FamilleMetiers
On oif.ID_Famille Equals f.ID_Famille
Where (Not f.Nom_Famille = familleJoker)
Join ol In db.ObjetLieux
On oif.ID_Objet Equals ol.ID_Objet
Where (d.ID_Lieu = ol.ID_Lieu)
Join l In db.Lieux
On ol.ID_Lieu Equals l.ID_Lieu
Where (Not l.Valeur_Lieu = lieuJoker)
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = ol}
Dim requeteFamilleJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join f In db.FamilleMetiers
On d.ID_Famille Equals f.ID_Famille
Where (f.Nom_Famille = familleJoker)
From oCross In db.Objets
Join ol In db.ObjetLieux
On oCross.ID_Objet Equals ol.ID_Objet
Where (d.ID_Lieu = ol.ID_Lieu)
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = ol}
Dim requeteLieuJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join l In db.Lieux
On d.ID_Lieu Equals l.ID_Lieu
Where (l.Valeur_Lieu = lieuJoker)
Join oif In db.ObjetsInFamilleMetiers
On d.ID_Famille Equals oif.ID_Famille
From lCross In db.Lieux
Join ol In db.ObjetLieux
On oif.ID_Objet Equals ol.ID_Objet
Where (lCross.ID_Lieu = ol.ID_Lieu)
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = ol}
Dim requeteFamilleEtLieuJoker = From d In db.DroitsUtilisateurs
Where d.Utilisateur = username
Join r In db.Roles
On d.ID_Role Equals r.ID_Role
Join f In db.FamilleMetiers
On d.ID_Famille Equals f.ID_Famille
Where (f.Nom_Famille = familleJoker)
Join l In db.Lieux
On d.ID_Lieu Equals l.ID_Lieu
Where (l.Valeur_Lieu = lieuJoker)
From olCross In db.ObjetLieux
Select New DroitsUtilisateurSession With {.Role = r, .ObjetLieu = olCross}
Dim requeteTotale = requeteSansJoker.Union(requeteFamilleJoker).Union(requeteLieuJoker).Union(requeteFamilleEtLieuJoker)
Dim resultat As List(Of DroitsUtilisateurSession) = requeteTotale.ToList
Dim listeDroitsUtilisateur As List(Of DroitsUtilisateurSession) = New List(Of DroitsUtilisateurSession)
If (resultat IsNot Nothing) Then
For Each item In resultat
listeDroitsUtilisateur.Add(New DroitsUtilisateurSession With {.Role = item.Role, .ObjetLieu = item.ObjetLieu})
Next
End If
Return listeDroitsUtilisateur
End Function
EDIT 6: I found something about the limit size of the pile of w3wp applications. This can be linked to my problem...
Here is the link :
http://support.microsoft.com/kb/932909
I'm digging.
EDIT 7: So, I made a little change to my code. Now, when it have to calculate the rights, it let another thread do it. This thread has a bigger stack size. So I thought it can change something, but the same problem occurs...
And I don't said it before, but there is NO recursive code in my App.
Here is the code I implemented :
Dim ThreadD As ThreadDroits = New ThreadDroits
ThreadD.Username = User.Identity.Name
Dim t = New Thread(AddressOf ThreadD.ExecuteDroits, 419430400)
t.Start()
t.Join()
Dim listeDroits As List(Of DroitsUtilisateurSession) = ThreadD.ListeDroits
And here is the new class :
Public Class ThreadDroits
Private m_Username As String
Public Property Username As String
Get
Return m_Username
End Get
Set(ByVal value As String)
m_Username = value
End Set
End Property
Private m_listeDroits As List(Of DroitsUtilisateurSession)
Public Property ListeDroits As List(Of DroitsUtilisateurSession)
Get
Return m_listeDroits
End Get
Set(ByVal value As List(Of DroitsUtilisateurSession))
m_listeDroits = value
End Set
End Property
Public Sub ExecuteDroits()
ListeDroits = DroitsUtilisateurSession.getListeDroitsUtilisateurSession(Username)
End Sub
End Class

Linq-to-entities date value in database is string

Personally, I know just enough Linq to be dangerous.
The task at hand is; I need to query the DAL and return a list of objects based on a date range. Sounds simple enough, however the date is a string, and for some reason it needs to stay a string.
I spent some time with this a while ago and got a solution working but I am iterating through a list of objects and selecting individual records by date one at a time, this is badddd! If the date range spans more than a few days its slow and I don't like it, and I've even busted a few of the Sr devs around here for doing iterative queries, so I definitely don't want to be a hypocrite.
Here is the crappy iteration way... each date pegs the database, which I hate doing.
- This works
DateTime start = Convert.ToDateTime(RecipientSearch.TransplantSearchStartDate);
DateTime end = Convert.ToDateTime(RecipientSearch.TransplantSearchEndDate);
var tempselectQuery = selectQuery;
while (start <= end)
{
tempselectQuery = selectQuery;
string sStart = Convert.ToDateTime(start).ToString(ResourceFormatting.DateOnly);
tempselectQuery = (ObjectQuery<DAL.Recipients>)tempselectQuery.Where(item => item.TransplantDate == sStart);
if (tempselectQuery.Count() != 0) TXPlistQueryDAL.AddRange(tempselectQuery.ToList());
start = start.AddDays(1);
}
Here is my attempt at trying to get my query to work in one db call
- This does not work... yet
DateTime start = Convert.ToDateTime(RecipientSearch.TransplantSearchStartDate);
DateTime end = Convert.ToDateTime(RecipientSearch.TransplantSearchEndDate);
List<string> sdates = new List<string>();
// Put my date strings in a list so I can then do a contains in my LINQ statement
// Date format is "11/29/2011"
while (start <= end)
{
string sStart = Convert.ToDateTime(start).ToString(ResourceFormatting.DateOnly);
sdates.Add(sStart);
start = start.AddDays(1);
}
// Below is where I get hung up, to do a .contains i need to pass in string, however x.TransplantDate
// includes time, so i am converting the string to a date, then using the EntityFunction to Truncate
// the time off, then i'd like to end up with a string, hence the .ToString, but, linq to entities
// thinks this is part of the sql query and bombs out... This is where I'm stumped on what to do next.
selectQuery =
(ObjectQuery<DAL.Recipients>)
from x in entities.Recipients
where sdates.Contains(EntityFunctions.TruncateTime(Convert.ToDateTime(x.TransplantDate)).ToString())
select x;
The error i get as follows:
I understand why I get the error, but I don't know the proper LINQ code to be able to acheive what I am trying to do. Any help will be greatly appreciated.
Ughh I feel dumb. I tried a bunch of tricky little things to get x.TransplantDate to just a date only string within my Linq query, E.G. 10/15/2011
where sdates.Contains(EntityFunctions.TruncateTime(Convert.ToDateTime(x.TransplantDate)).ToString())
Turns out it already is in the correct format in the database, and if i simplify it down to just
where sdates.Contains(x.TransplantDate) It works. The reason I wasnt getting any records returned was because I was testing date ranges that didnt have any data for those specific dates... UGHH.
So in conclusion this ended up working fine. And if anyone is doing something similar maybe you can learn from this example.
DateTime start = Convert.ToDateTime(RecipientSearch.TransplantSearchStartDate);
DateTime end = Convert.ToDateTime(RecipientSearch.TransplantSearchEndDate);
List<string> sdates = new List<string>();
while (start <= end)
{
string sStart = Convert.ToDateTime(start).ToString(ResourceFormatting.DateOnly);
sdates.Add(sStart);
start = start.AddDays(1);
}
selectQuery =
(ObjectQuery<DAL.Recipients>)
from x in entities.Recipients
where sdates.Contains(x.TransplantDate)
select x;

how to fix EntityReference error

I'm attempt to commit mostly all new objects to the database, apart from the user. I'm new to entity framework and im not sure how to combat this error.
Error on line _orderDetail.CalenderItems.Add(_newCalendarItem):
The object could not be added or attached because its EntityReference has an EntityKey property value that does not match the EntityKey for this object.
Code:
_db.Orders.AddObject(_order)
For Each n In _namelist
_db.Names.AddObject(n)
Next
For Each n In _namelist
For i As Integer = 1 To _copies
Dim _orderDetail As New OrderDetail
_db.OrderDetails.AddObject(_orderDetail)
_orderDetail.Name = n
_orderDetail.Order = _order
For Each c In _calendarItems
Dim _newCalendarItem As New CalenderItem
_newCalendarItem.Image = c.Image
_newCalendarItem.YearMonth = c.YearMonth
_orderDetail.CalenderItems.Add(_newCalendarItem)
Next
Next
Next
_db.SaveChanges()
I believe I need to add add an entity reference but I'm not sure how. Can anyone point me in the right direction
As dnndeveloper says, your answer is ObjectContext.CreateObject<T>.
So you're gonna want -
Dim ci = _db.CreateObject(Of CalenderItem)()
ci.OrderDetail = _orderDetail
ci.Image = c.image
ci.YearMonth = c.YearMonth
_orderDetail.CalenderItems.Add(ci)
or something along those lines. I've run into this issue a couple of times and this has worked so far.
HTH
Instead of creating a "new calendaritem" you should use _db.OrderDetails.CalendarItem.New() etc... either that or set _newCalendarItem.EntityKey to null.

Resources