/// <summary>
        /// Gets or create the future context that is linked to the underlying <see cref="ObjectContext"/>.
        /// </summary>
        /// <param name="objectQuery">The query source to get the future context from.</param>
        /// <returns>An instance of <see cref="IFutureContext"/> to store waiting future queries.</returns>
        public IFutureContext GetOrCreate(ObjectQuery objectQuery)
        {
            if (objectQuery == null)
                throw new ArgumentNullException("objectQuery");

            var objectContext = objectQuery.Context;
            if (objectContext == null)
                throw new ArgumentException("The source ObjectContext can not be null.", "objectQuery");

            MaybeCleanup();

            int key = RuntimeHelpers.GetHashCode(objectContext);
            return _futureContext.GetOrAdd(key, k => new FutureContext(objectContext));
        }
        /// <summary>
        /// Applies the current filter settings to an esql object query dynamically.
        /// </summary>
        /// <param name="filters">The filters.</param>
        /// <param name="baseQuery">The base object query.</param>
        /// <returns>ObjectQuery{Ticket}.</returns>
        public static ObjectQuery<Ticket> ApplyToQuery(this ICollection<UserTicketListFilterColumn> filters, ObjectQuery<Ticket> baseQuery)
        {
            var filterColumns = filters.ToList();
            if (filterColumns.Count > 0)
            {
                var fkeys = new string[filterColumns.Count];
                var fParams = new ObjectParameter[filterColumns.Count];
                for (var i = 0; i < filterColumns.Count; i++)
                {
                    string optr;
                    var filterColumn = filterColumns[i];

                    if (filterColumn.ColumnValue == DBNull.Value)
                    {
                        optr = (filterColumn.UseEqualityComparison.HasValue && !filterColumn.UseEqualityComparison.Value)
                            ? "IS NOT"
                            : "IS";
                    }
                    else
                    {
                        optr = (filterColumn.UseEqualityComparison.HasValue && !filterColumn.UseEqualityComparison.Value)
                            ? "!="
                            : "=";
                    }

                    fkeys[i] = string.Format("it.{0} {1} {2}", filterColumn.ColumnName, optr, "@" + filterColumn.ColumnName);

                    //most of the time esql works with whatever type of param value you pass in, but
                    // enums in our collection are serialized to/from json as integers.
                    // Check if enum, and explicitly convert int value to the correct enum value
                    if (filterColumn.ColumnValueType != null && filterColumn.ColumnValueType.IsEnum)
                    {
                        filterColumn.ColumnValue = Enum.Parse(filterColumn.ColumnValueType, filterColumn.ColumnValue.ToString());
                    }
                    //assigning the type in ctor, then value directly as a param works around issues when the colum val is null.

                    fParams[i] = new ObjectParameter(filterColumn.ColumnName, filterColumn.ColumnValueType)
                    {
                        Value = filterColumn.ColumnValue
                    };

                }

                var wString = string.Join(" and ", fkeys);
                baseQuery = baseQuery.Where(wString, fParams);
            }
            return baseQuery;
        }
        /// <summary>
        /// Applies the current sort column settings to an esql object query dynamically.
        /// </summary>
        /// <param name="sorts">The sorts.</param>
        /// <param name="baseQuery">The base object query.</param>
        /// <returns>ObjectQuery{Ticket}.</returns>
        public static ObjectQuery<Ticket> ApplyToQuery(this ICollection<UserTicketListSortColumn> sorts, ObjectQuery<Ticket> baseQuery)
        {
            var sortColumns = sorts.ToList();
            if (sortColumns.Count > 0)
            {
                var skeys = new string[sortColumns.Count];
                for (var i = 0; i < sortColumns.Count; i++)
                {
                    var sortColumn = sortColumns[i];
                    var appd = (sortColumn.SortDirection == ColumnSortDirection.Ascending) ? string.Empty : "DESC";
                    skeys[i] = string.Format("it.{0} {1}", sortColumn.ColumnName, appd);
                }

                var kString = string.Join(",", skeys);
                baseQuery = baseQuery.OrderBy(kString);

            }
            return baseQuery;
        }
Example #4
0
        // what is the scenario about image level query 
        // TODO add support in Image Level Query 
        private void OnReceiveImageLevelQuery(DicomServer server, byte presentationId, DicomMessage message)
        {
            var tagList = new List<DicomTag>();

            using (var pacsContext = new PacsContext())
            {
                var adapter = (IObjectContextAdapter)pacsContext;
                var query = new ObjectQuery<Instance>("Instances", adapter.ObjectContext);

                DicomAttributeCollection data = message.DataSet;
                string studyInstanceUid = data[DicomTags.StudyInstanceUid].GetString(0, String.Empty);
                string seriesInstanceUid = data[DicomTags.SeriesInstanceUid].GetString(0, String.Empty);

                foreach (DicomAttribute attrib in data)
                {
                    if (attrib.Tag.TagValue.Equals(DicomTags.SpecificCharacterSet)
                        || attrib.Tag.TagValue.Equals(DicomTags.QueryRetrieveLevel))
                        continue;

                    tagList.Add(attrib.Tag);
                    if (!attrib.IsNull)
                    {
                        switch (attrib.Tag.TagValue)
                        {

                        }
                    }
                }

                int resultCount = 0;
                try
                {
                    foreach (Instance instance in query)
                    {
                        if (_cancelReceived)
                        {
                            throw new DicomException("DICOM C-Cancel Received");
                        }

                        resultCount++;
                        if (DicomSetting.Default.MaxQueryResponses != -1 &&
                            DicomSetting.Default.MaxQueryResponses < resultCount)
                        {
                            SendBufferedResponses(server, presentationId, message);
                            throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
                        }

                        var response = new DicomMessage();
                        PopuldateInstance(message, response, tagList, instance);
                        _responseQueue.Enqueue(response);

                        if (_responseQueue.Count >= DicomSetting.Default.BufferedQueryResponses)
                        {
                            SendBufferedResponses(server, presentationId, message);
                        }
                    }

                    SendBufferedResponses(server, presentationId, message);
                }
                catch (Exception e)
                {
                    if (_cancelReceived)
                    {
                        var errorResponse = new DicomMessage();
                        server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
                                                 DicomStatuses.Cancel);
                    }
                }
            }

            var finalResponse = new DicomMessage();
            server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success);
        }
Example #5
0
 private static void FunWithEntitySQL() {
     using (AutoLotEntities context = new AutoLotEntities()) {
         Console.WriteLine(context.Cars.ToString());
         string queryString = "SELECT VALUE car from AutoLotEntities.Cars as car WHERE car.Color='Black'";
         ObjectQuery<Car> contactQuery = new ObjectQuery<Car>(queryString, ((IObjectContextAdapter)context).ObjectContext);            
         foreach (var item in contactQuery) {
             Console.WriteLine(item);
         }
     }
 }
Example #6
0
        private void OnReceiveSeriesLevelQuery(DicomServer server, byte presentationId, DicomMessage message)
        {
            var tagList = new List<DicomTag>();

            using (var pacsContext = new PacsContext())
            {
                var adapter = (IObjectContextAdapter)pacsContext;
                var query = new ObjectQuery<Series>("Series", adapter.ObjectContext);

                DicomAttributeCollection data = message.DataSet;
                foreach (DicomAttribute attrib in data)
                {
                    tagList.Add(attrib.Tag);
                    if (!attrib.IsNull)
                    {
                        switch (attrib.Tag.TagValue)
                        {
                            case DicomTags.StudyInstanceUid:
                                {
                                    var uids = data[DicomTags.StudyInstanceUid].GetString(0, string.Empty);
                                    IQueryable<int> studyQuery = from s in pacsContext.Studies
                                                                 where uids.Contains(s.StudyUid)
                                                                 select s.Id;
                                    var result = studyQuery.ToArray();
                                    if (result.Length == 0)
                                    {
                                        server.SendCFindResponse(presentationId, message.MessageId, new DicomMessage(),
                                                             DicomStatuses.Success);
                                        return;
                                    }

                                    query = query.Where(QueryHelper.SetIntArrayCondition("StudyForeignKey", result));
                                }
                                break;
                            case DicomTags.SeriesInstanceUid:
                                {
                                    var cond = QueryHelper.SetStringArrayCondition("SeriesUid",
                                                                                   (string[])
                                                                                   data[DicomTags.SeriesInstanceUid]
                                                                                       .Values);
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.Modality:
                                {
                                    var cond = QueryHelper.SetStringCondition("Modality",
                                                                              data[DicomTags.Modality].GetString(0,
                                                                                                                 string
                                                                                                                     .Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.SeriesNumber:
                                {
                                    var cond = QueryHelper.SetStringCondition("SeriesNumber",
                                                                              data[DicomTags.SeriesNumber].GetString(0,
                                                                                                                     string
                                                                                                                         .Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.SeriesDescription:
                                {
                                    var cond = QueryHelper.SetStringCondition("SeriesDescription",
                                                                              data[DicomTags.StudyDescription].GetString
                                                                                  (0, string.Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.PerformedProcedureStepStartDate:
                                {
                                    var cond = QueryHelper.SetRangeCondition("PerformedProcedureStepStartDate",
                                                                             data[
                                                                                 DicomTags
                                                                                     .PerformedProcedureStepStartDate]
                                                                                 .GetString(0, string.Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.PerformedProcedureStepStartTime:
                                {
                                    var cond = QueryHelper.SetRangeCondition("PerformedProcedureStepStartTime",
                                                                             data[
                                                                                 DicomTags
                                                                                     .PerformedProcedureStepStartTime]
                                                                                 .GetString(0, string.Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.RequestAttributesSequence: // todo
                                break;
                            default:
                                break;
                        }
                    }
                }

                int resultCount = 0;
                try
                {
                    foreach (Series series in query)
                    {
                        if (_cancelReceived)
                        {
                            throw new DicomException("DICOM C-Cancel Received");
                        }

                        resultCount++;
                        if (DicomSetting.Default.MaxQueryResponses != -1 &&
                            DicomSetting.Default.MaxQueryResponses < resultCount)
                        {
                            SendBufferedResponses(server, presentationId, message);
                            throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
                        }

                        var response = new DicomMessage();
                        PopulateSeries(message, response, tagList, series);
                        _responseQueue.Enqueue(response);

                        if (_responseQueue.Count >= DicomSetting.Default.BufferedQueryResponses)
                        {
                            SendBufferedResponses(server, presentationId, message);
                        }
                    }

                    SendBufferedResponses(server, presentationId, message);
                }
                catch (Exception e)
                {
                    if (_cancelReceived)
                    {
                        var errorResponse = new DicomMessage();
                        server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
                                                 DicomStatuses.Cancel);
                    }
                }
            }

            var finalResponse = new DicomMessage();
            server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success);
        }
Example #7
0
        private void OnReceiveStudyLevelQuery(DicomServer server, byte presentationId, DicomMessage message)
        {
            var tagList = new List<DicomTag>();

            using (var pacsContext = new PacsContext())
            {
                var adapter = (IObjectContextAdapter)pacsContext;
                var query = new ObjectQuery<Study>("Studies", adapter.ObjectContext);

                DicomAttributeCollection data = message.DataSet;
                foreach (DicomAttribute attrib in message.DataSet)
                {
                    tagList.Add(attrib.Tag);

                    if (!attrib.IsNull)
                    {
                        switch (attrib.Tag.TagValue)
                        {
                            case DicomTags.StudyInstanceUid:
                                {
                                    var cond = QueryHelper.SetStringArrayCondition("StudyInstanceUid",
                                                                                   (string[])data[DicomTags.StudyInstanceUid].Values);
                                    if (!string.IsNullOrEmpty(cond))
                                    {
                                        query = query.Where(cond);
                                    }    
                                }
                                
                                break;
                            case DicomTags.PatientsName:
                                {
                                    var cond = QueryHelper.SetStringCondition("PatientName",
                                                                              data[DicomTags.PatientsName].GetString(0,
                                                                                                                     string
                                                                                                                         .Empty));
                                    if (!string.IsNullOrEmpty(cond))
                                    {
                                        query = query.Where(cond);
                                    }
                                    
                                    break;
                                }
                            case DicomTags.PatientId:
                                {
                                    var cond = QueryHelper.SetStringCondition("PatientId",
                                                                              data[DicomTags.PatientId].GetString(0,
                                                                                                                  string
                                                                                                                      .Empty));
                                    break;
                                }
                            case DicomTags.PatientsBirthDate:
                                {
                                    var cond = QueryHelper.SetRangeCondition("PatientBirthDate",
                                                                             data[DicomTags.PatientsBirthDate].GetString
                                                                                 (0, string.Empty));
                                    query = query.Where(cond);
                                    break;
                                }

                            case DicomTags.PatientsSex:
                                {
                                    var cond = QueryHelper.SetStringCondition("PatientSex",
                                                                              data[DicomTags.PatientsSex].GetString(0,
                                                                                                                    string
                                                                                                                        .Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.StudyDate:
                                {
                                    var cond = QueryHelper.SetRangeCondition("StudyDate",
                                                                              data[DicomTags.StudyDate].GetString(0,
                                                                                                                  string
                                                                                                                      .Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.StudyTime:
                                {
                                    var cond = QueryHelper.SetRangeCondition("StudyTime",
                                                                              data[DicomTags.StudyTime].GetString(0,
                                                                                                                  string
                                                                                                                      .Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.AccessionNumber:
                                {
                                    var cond = QueryHelper.SetStringCondition("AccessionNumber",
                                                                              data[DicomTags.AccessionNumber].GetString(
                                                                                  0, string.Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.StudyId:
                                {
                                    var cond = QueryHelper.SetStringCondition("StudyId",
                                        data[DicomTags.StudyId].GetString(0, string.Empty));

                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.StudyDescription:
                                {
                                    var cond = QueryHelper.SetStringCondition("StudyDescription",
                                        data[DicomTags.StudyDescription].GetString(0, string.Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.ReferringPhysiciansName:
                                {
                                    var cond = QueryHelper.SetStringCondition("RefPhysician",
                                                                              data[DicomTags.ReferringPhysiciansName]
                                                                                  .GetString(0, string.Empty));
                                    query = query.Where(cond);
                                }
                                break;
                            case DicomTags.ModalitiesInStudy:
                                break;
                            default:
                                break;
                        }
                    }
                }
                int resultCount = 0;
                try
                {
                    foreach (Study study in query)
                    {
                        if (_cancelReceived)
                        {
                            throw new DicomException("DICOM C-Cancel Received");
                        }

                        resultCount++;
                        if (DicomSetting.Default.MaxQueryResponses != -1 &&
                            DicomSetting.Default.MaxQueryResponses < resultCount)
                        {
                            SendBufferedResponses(server, presentationId, message);
                            throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
                        }

                        var response = new DicomMessage();
                        PopulateStudy(response, tagList, study);
                        _responseQueue.Enqueue(response);

                        if (_responseQueue.Count >= DicomSetting.Default.BufferedQueryResponses)
                        {
                            SendBufferedResponses(server, presentationId, message);
                        }
                    }

                    SendBufferedResponses(server, presentationId, message);
                }
                catch (Exception e)
                {
                    if (_cancelReceived)
                    {
                        var errorResponse = new DicomMessage();
                        server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
                                                 DicomStatuses.Cancel);
                    }

                    return;
                }
            }

            var finalResponse = new DicomMessage();
            server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success);
        }
Example #8
0
        private void OnReceivePatientQuery(DicomServer server, byte presentationId, DicomMessage message)
        {
            var tagList = new List<DicomTag>();

            using (var pacsContext = new PacsContext())
            {
                var adapter = (IObjectContextAdapter)pacsContext;
                var query = new ObjectQuery<Patient>("Patients", adapter.ObjectContext);

                DicomAttributeCollection data = message.DataSet;

                foreach (DicomAttribute attribute in data)
                {
                    tagList.Add(attribute.Tag);
                    if (!attribute.IsNull)
                    {
                        switch (attribute.Tag.TagValue)
                        {
                            case DicomTags.PatientsName:
                                {
                                    var cond = QueryHelper.SetStringCondition("PatientName",
                                                                   data[DicomTags.PatientsName].GetString(0, string.Empty));
                                    query = query.Where(cond);
                                    break;
                                }

                            case DicomTags.PatientId:
                                {
                                    var cond = QueryHelper.SetStringCondition("PatientId",
                                                               data[DicomTags.PatientId].GetString(0, string.Empty));
                                    query = query.Where(cond);
                                    break;
                                }

                            case DicomTags.IssuerOfPatientId:
                                {
                                    var cond = QueryHelper.SetStringCondition("Issuer",
                                                                              data[DicomTags.IssuerOfPatientId]
                                                                                  .GetString(0, string.Empty));
                                }
                                break;
                            case DicomTags.PatientsSex:
                                break;
                            case DicomTags.PatientsBirthDate:
                                {
                                    var cond = QueryHelper.SetStringArrayCondition("PatientBirthDate",
                                                                                   (string[])
                                                                                   data[DicomTags.PatientsBirthDate]
                                                                                       .Values);
                                    query = query.Where(cond);
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }

                int resultCount = 0;
                try
                {
                    foreach (Patient patient in query)
                    {
                        if (_cancelReceived)
                        {
                            throw new DicomException("DICOM C-Cancel Received");
                        }

                        resultCount++;
                        if (DicomSetting.Default.MaxQueryResponses != -1 &&
                            DicomSetting.Default.MaxQueryResponses < resultCount)
                        {
                            SendBufferedResponses(server, presentationId, message);
                            throw new DicomException("Maximum Configured Query Responses Exceeded: " + resultCount);
                        }

                        var response = new DicomMessage();
                        PopulatePatient(response, tagList, patient);
                        _responseQueue.Enqueue(response);

                        if (_responseQueue.Count >= DicomSetting.Default.BufferedQueryResponses)
                        {
                            SendBufferedResponses(server, presentationId, message);
                        }
                    }

                    SendBufferedResponses(server, presentationId, message);
                }
                catch (Exception e)
                {
                    if (_cancelReceived)
                    {
                        var errorResponse = new DicomMessage();
                        server.SendCFindResponse(presentationId, message.MessageId, errorResponse,
                                                 DicomStatuses.Cancel);
                    }
                }
            }

            var finalResponse = new DicomMessage();
            server.SendCFindResponse(presentationId, message.MessageId, finalResponse, DicomStatuses.Success);
        }
        /// <summary>
        ///     This query-builder method creates a new query whose results are all of
        ///     the results of this query, plus all of the results of the other query,
        ///     including any duplicates (i.e., results are not necessarily unique).
        /// </summary>
        /// <param name="query"> A query representing the results to add. </param>
        /// <returns> a new ObjectQuery instance. </returns>
        /// <exception cref="ArgumentNullException">If the query parameter is null.</exception>
        public ObjectQuery <T> UnionAll(ObjectQuery <T> query)
        {
            Check.NotNull(query, "query");

            return(new ObjectQuery <T>(EntitySqlQueryBuilder.UnionAll(QueryState, query.QueryState)));
        }
Example #10
0
 private static bool IsLinqQuery(ObjectQuery query)
 {
     return(query.QueryState is ELinqQueryState);
 }