Esempio n. 1
0
        private void RunConsumer()
        {
            FQReportingConsumer consumer = new FQReportingConsumer(
                SettingsManager.ConsumerSettings.ApplicationKey,
                SettingsManager.ConsumerSettings.InstanceId,
                SettingsManager.ConsumerSettings.UserToken,
                SettingsManager.ConsumerSettings.SolutionId);

            consumer.Register();
            if (log.IsInfoEnabled)
            {
                log.Info("Registered the Consumer.");
            }

            try
            {
                // Create a new FQ reporting object.
                try
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("*** Create a new FQ reporting object.");
                    }
                    FQReporting createdObject = consumer.Create(CreateFQReporting());
                    if (log.IsInfoEnabled)
                    {
                        log.Info($"Created new FQ reporting object with ID of {createdObject.RefId}.");
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Access to create a new FQ reporting object is rejected.");
                    }
                }

                // Retrieve all FQ reporting objects.
                if (log.IsInfoEnabled)
                {
                    log.Info("*** Retrieve all FQ reporting objects.");
                }
                IEnumerable <FQReporting> retrievedObjects = consumer.Query(1, 2);

                foreach (FQReporting retrievedObject in retrievedObjects)
                {
                    if (log.IsInfoEnabled)
                    {
                        log.Info($"FQ reporting object {retrievedObject.RefId} is for {retrievedObject.EntityName}.");
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                if (log.IsInfoEnabled)
                {
                    log.Info($"Access to query FQ reporting objects is rejected.");
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the Consumer.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                consumer.Unregister();
                if (log.IsInfoEnabled)
                {
                    log.Info("Unregistered the Consumer.");
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Accept a <see cref="QueryNodeVisitor{T}"/> that walks a tree of <see cref="QueryNode"/>s.
 /// </summary>
 /// <typeparam name="T">Type that the visitor will return after visiting this token.</typeparam>
 /// <param name="visitor">An implementation of the visitor interface.</param>
 /// <returns>An object whose type is determined by the type parameter of the visitor.</returns>
 /// <exception cref="System.ArgumentNullException">Throws if the input visitor is null.</exception>
 public override T Accept <T>(QueryNodeVisitor <T> visitor)
 {
     ExceptionUtils.CheckArgumentNotNull(visitor, "visitor");
     return(visitor.Visit(this));
 }
Esempio n. 3
0
 /// <summary>
 /// Translate a <see cref="FilterSegment"/> using an instance of <see cref="PathSegmentTranslator{T}"/>.
 /// </summary>
 /// <typeparam name="T">Type that the translator will return after visiting this token.</typeparam>
 /// <param name="translator">An implementation of the translator interface.</param>
 /// <returns>An object whose type is determined by the type parameter of the translator.</returns>
 /// <exception cref="System.ArgumentNullException">Throws if the input translator is null.</exception>
 public override T TranslateWith <T>(PathSegmentTranslator <T> translator)
 {
     ExceptionUtils.CheckArgumentNotNull(translator, "translator");
     return(translator.Translate(this));
 }
Esempio n. 4
0
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataDeltaWriter"/> for <paramref name="deltalink"/>.
 /// </summary>
 /// <param name="deltalink">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataDeltaLinkBase deltalink, ODataDeltaSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(deltalink, "deltalink");
     deltalink.SerializationInfo = serializationInfo;
 }
Esempio n. 5
0
        /// <summary>
        /// Create a new RangeVariableToken
        /// </summary>
        /// <param name="name">The name of the visitor for the Any/All query.</param>
        public RangeVariableToken(string name)
        {
            ExceptionUtils.CheckArgumentNotNull(name, "visitor");

            this.name = name;
        }
Esempio n. 6
0
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataWriter"/> for <paramref name="property"/>.
 /// </summary>
 /// <param name="property">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataProperty property, ODataPropertySerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(property, "property");
     property.SerializationInfo = serializationInfo;
 }
Esempio n. 7
0
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataDeltaWriter"/> for <paramref name="deltaFeed"/>.
 /// </summary>
 /// <param name="deltaFeed">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataDeltaFeed deltaFeed, ODataDeltaFeedSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(deltaFeed, "deltaFeed");
     deltaFeed.SerializationInfo = serializationInfo;
 }
        protected virtual CommonTransactionStatusCode ProcessSubmitDocument(string transactionId, string docId, out string statusDetail)
        {
            string tempXmlFilePath = _settingsProvider.NewTempFilePath();

            try
            {
                AppendAuditLogEvent("Getting data for document with id \"{0}\"", docId);
                Windsor.Node2008.WNOSDomain.Document document = _documentManager.GetDocument(transactionId, docId, true);
                if (_compressionHelper.IsCompressed(document.Content))
                {
                    AppendAuditLogEvent("Decompressing document to temporary file");
                    _compressionHelper.UncompressDeep(document.Content, tempXmlFilePath);
                }
                else
                {
                    AppendAuditLogEvent("Writing document data to temporary file");
                    File.WriteAllBytes(tempXmlFilePath, document.Content);
                }

                if (_validateXml)
                {
                    ValidateXmlFileAndAttachErrorsAndFileToTransaction(tempXmlFilePath, "xml_schema.xml_schema.zip",
                                                                       null, transactionId);
                }

                AppendAuditLogEvent("Deserializing document data to ICIS data");
                XmlReader reader = new NamespaceSpecifiedXmlTextReader("http://www.exchangenetwork.net/schema/icis/5", tempXmlFilePath);
                Windsor.Node2008.WNOSPlugin.ICISNPDES_50.Document data =
                    _serializationHelper.Deserialize <Windsor.Node2008.WNOSPlugin.ICISNPDES_50.Document>(reader);

                //Windsor.Node2008.WNOSPlugin.ICISNPDES_50.Document data =
                //    _serializationHelper.Deserialize<Windsor.Node2008.WNOSPlugin.ICISNPDES_50.Document>(tempXmlFilePath);

                if (CollectionUtils.IsNullOrEmpty(data.Payload))
                {
                    statusDetail = "Deserialized ICIS does not contain any payload elements, exiting processing thread.";
                    AppendAuditLogEvent(statusDetail);
                    return(CommonTransactionStatusCode.Completed);
                }
                AppendAuditLogEvent("ICIS data contains {0} payloads", data.Payload.Length.ToString());

                Type mappingAttributesType = typeof(Windsor.Node2008.WNOSPlugin.ICISNPDES_50.MappingAttributes);

                _baseDao.TransactionTemplate.Execute(delegate
                {
                    if (_deleteExistingDataBeforeInsert)
                    {
                        AppendAuditLogEvent("Deleting all existing ICIS payload data from the data store");

                        int numRowsDeleted = _objectsToDatabase.DeleteAllFromDatabase(typeof(Windsor.Node2008.WNOSPlugin.ICISNPDES_50.PayloadData),
                                                                                      _baseDao, mappingAttributesType);
                        if (numRowsDeleted > 0)
                        {
                            AppendAuditLogEvent("Deleted {0} existing ICIS payload data rows from the data store",
                                                numRowsDeleted.ToString());
                        }
                        else
                        {
                            AppendAuditLogEvent("Did not find any existing ICIS payload data to delete from the data store");
                        }
                    }

                    AppendAuditLogEvent("Storing ICIS payload data into database");

                    foreach (Windsor.Node2008.WNOSPlugin.ICISNPDES_50.PayloadData payload in data.Payload)
                    {
                        Dictionary <string, int> tableRowCounts = _objectsToDatabase.SaveToDatabase(payload, _baseDao, mappingAttributesType);

                        AppendAuditLogEvent("Stored ICIS payload data for operation \"{0}\" into data store with the following table row counts: {1}",
                                            payload.Operation.ToString(), CreateTableRowCountsString(tableRowCounts));
                    }

                    return(null);
                });

                AttachSubmissionResponseToTransaction(transactionId);

                statusDetail = "Successfully processed the submitted ICIS document.";
                return(CommonTransactionStatusCode.Completed);
            }
            catch (Exception e)
            {
                AppendAuditLogEvent("Failed to process document with id \"{0}\" with error: {1}",
                                    docId.ToString(), ExceptionUtils.GetDeepExceptionMessage(e));
                throw;
            }
            finally
            {
                FileUtils.SafeDeleteFile(tempXmlFilePath);
            }
        }
        /// <summary>
        /// Try to resolve a function from the given inputs.
        /// </summary>
        /// <param name="identifier">The identifier of the function that we're trying to find</param>
        /// <param name="parameterNames">the names of the parameters to search for.</param>
        /// <param name="bindingType">the type of the previous segment</param>
        /// <param name="model">the model to use to look up the operation import</param>
        /// <param name="matchingOperation">The single matching function found.</param>
        /// <param name="resolver">Resolver to be used.</param>
        /// <returns>True if a function was matched, false otherwise. Will throw if the model has illegal operation imports.</returns>
        internal static bool ResolveOperationFromList(string identifier, IEnumerable <string> parameterNames, IEdmType bindingType, IEdmModel model, out IEdmOperation matchingOperation, ODataUriResolver resolver)
        {
            // TODO: update code that is duplicate between operation and operation import, add more tests.
            // If the previous segment is an open type, the service action name is required to be fully qualified or else we always treat it as an open property name.
            if (bindingType != null)
            {
                // TODO: look up actual container names here?
                // When using extension, there may be function call with unqualified name. So loose the restriction here.
                if (bindingType.IsOpen() && !identifier.Contains(".") && resolver.GetType() == typeof(ODataUriResolver))
                {
                    matchingOperation = null;
                    return(false);
                }
            }

            IList <IEdmOperation> candidateMatchingOperations = null;

            // The extension method FindBoundOperations & FindOperations call IEdmModel.FindDeclaredBoundOperations which can be implemented by anyone and it could throw any type of exception
            // so catching all of them and simply putting it in the inner exception.
            try
            {
                if (bindingType != null)
                {
                    candidateMatchingOperations = resolver.ResolveBoundOperations(model, identifier, bindingType).ToList();
                }
                else
                {
                    candidateMatchingOperations = resolver.ResolveUnboundOperations(model, identifier).ToList();
                }
            }
            catch (Exception exc)
            {
                if (ExceptionUtils.IsCatchableExceptionType(exc))
                {
                    throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_FoundInvalidOperation(identifier), exc);
                }

                throw;
            }

            IList <IEdmAction> foundActionsWhenLookingForFunctions = new List <IEdmAction>();
            int parameterNamesCount = parameterNames.Count();

            if (bindingType != null)
            {
                candidateMatchingOperations = candidateMatchingOperations.EnsureOperationsBoundWithBindingParameter().ToList();
            }

            // If the number of parameters > 0 then this has to be a function as actions can't have parameters on the uri only in the payload. Filter further by parameters in this case, otherwise don't.
            if (parameterNamesCount > 0)
            {
                // can only be a function as only functions have parameters on the uri.
                candidateMatchingOperations = candidateMatchingOperations.RemoveActions(out foundActionsWhenLookingForFunctions).FilterFunctionsByParameterNames(parameterNames, resolver.EnableCaseInsensitive).Cast <IEdmOperation>().ToList();
            }
            else if (bindingType != null)
            {
                // Filter out functions with more than one parameter. Actions should not be filtered as the parameters are in the payload not the uri
                candidateMatchingOperations = candidateMatchingOperations.Where(o =>
                                                                                (o.IsFunction() && (o.Parameters.Count() == 1 || o.Parameters.Skip(1).All(p => p is IEdmOptionalParameter))) || o.IsAction()).ToList();
            }
            else
            {
                // Filter out functions with any parameters
                candidateMatchingOperations = candidateMatchingOperations.Where(o => (o.IsFunction() && !o.Parameters.Any()) || o.IsAction()).ToList();
            }

            // Only filter if there is more than one and its needed.
            if (candidateMatchingOperations.Count > 1)
            {
                candidateMatchingOperations = candidateMatchingOperations.FilterBoundOperationsWithSameTypeHierarchyToTypeClosestToBindingType(bindingType).ToList();
            }

            // If any of the things returned are an action, it better be the only thing returned, and there can't be parameters in the URL
            if (candidateMatchingOperations.Any(f => f.IsAction()))
            {
                if (candidateMatchingOperations.Count > 1)
                {
                    if (candidateMatchingOperations.Any(o => o.IsFunction()))
                    {
                        throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_MultipleOperationOverloads(identifier));
                    }
                    else
                    {
                        throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_MultipleActionOverloads(identifier));
                    }
                }

                if (parameterNames.Count() != 0)
                {
                    throw ExceptionUtil.CreateBadRequestError(ODataErrorStrings.RequestUriProcessor_SegmentDoesNotSupportKeyPredicates(identifier));
                }

                matchingOperation = candidateMatchingOperations.Single();
                return(true);
            }

            if (foundActionsWhenLookingForFunctions.Count > 0)
            {
                throw ExceptionUtil.CreateBadRequestError(ODataErrorStrings.RequestUriProcessor_SegmentDoesNotSupportKeyPredicates(identifier));
            }

            // If more than one overload matches, try to select based on optional parameters
            if (candidateMatchingOperations.Count > 1)
            {
                candidateMatchingOperations = candidateMatchingOperations.FindBestOverloadBasedOnParameters(parameterNames).ToList();
            }

            if (candidateMatchingOperations.Count > 1)
            {
                throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_NoSingleMatchFound(identifier, string.Join(",", parameterNames.ToArray())));
            }

            matchingOperation = candidateMatchingOperations.SingleOrDefault();
            return(matchingOperation != null);
        }
Esempio n. 10
0
        /// <summary>
        /// Extension method to get the <see cref="AtomWorkspaceMetadata"/> for an annotatable workspace.
        /// </summary>
        /// <param name="workspace">The workspace to get the annotation from.</param>
        /// <returns>An <see cref="AtomWorkspaceMetadata" /> instance or null if no annotation of that type exists.</returns>
        public static AtomWorkspaceMetadata Atom(this ODataWorkspace workspace)
        {
            ExceptionUtils.CheckArgumentNotNull(workspace, "workspace");

            return(workspace.GetAnnotation <AtomWorkspaceMetadata>());
        }
Esempio n. 11
0
        /// <summary>
        /// Extension method to get the <see cref="AtomResourceCollectionMetadata"/> for an annotatable (resource) collection.
        /// </summary>
        /// <param name="collection">The (resource) collection to get the annotation from.</param>
        /// <returns>An <see cref="AtomResourceCollectionMetadata" /> instance or null if no annotation of that type exists.</returns>
        public static AtomResourceCollectionMetadata Atom(this ODataResourceCollectionInfo collection)
        {
            ExceptionUtils.CheckArgumentNotNull(collection, "collection");

            return(collection.GetAnnotation <AtomResourceCollectionMetadata>());
        }
Esempio n. 12
0
        public static AtomLinkMetadata Atom(this ODataLink link)
        {
            ExceptionUtils.CheckArgumentNotNull(link, "link");

            return(link.GetAnnotation <AtomLinkMetadata>());
        }
Esempio n. 13
0
        public static AtomFeedMetadata Atom(this ODataFeed feed)
        {
            ExceptionUtils.CheckArgumentNotNull(feed, "feed");

            return(feed.GetAnnotation <AtomFeedMetadata>());
        }
Esempio n. 14
0
        public static AtomEntryMetadata Atom(this ODataEntry entry)
        {
            ExceptionUtils.CheckArgumentNotNull(entry, "entry");

            return(entry.GetAnnotation <AtomEntryMetadata>());
        }
Esempio n. 15
0
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataWriter"/> for <paramref name="feed"/>.
 /// </summary>
 /// <param name="feed">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataFeed feed, ODataFeedAndEntrySerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(feed, "feed");
     feed.SerializationInfo = serializationInfo;
 }
        /// <summary>
        /// Try to resolve a function from the given inputs.
        /// </summary>
        /// <param name="identifier">The identifier of the function that we're trying to find</param>
        /// <param name="parameterNames">the names of the parameters to search for.</param>
        /// <param name="model">the model to use to look up the operation import</param>
        /// <param name="matchingOperationImport">The single matching function found.</param>
        /// <param name="resolver">Resolver to be used.</param>
        /// <returns>True if a function was matched, false otherwise. Will throw if the model has illegal operation imports.</returns>
        internal static bool ResolveOperationImportFromList(string identifier, IList <string> parameterNames, IEdmModel model, out IEdmOperationImport matchingOperationImport, ODataUriResolver resolver)
        {
            IList <IEdmOperationImport> candidateMatchingOperationImports         = null;
            IList <IEdmActionImport>    foundActionImportsWhenLookingForFunctions = new List <IEdmActionImport>();

            try
            {
                if (parameterNames.Count > 0)
                {
                    // In this case we have to return a function so filter out actions because the number of parameters > 0.
                    candidateMatchingOperationImports = resolver.ResolveOperationImports(model, identifier).RemoveActionImports(out foundActionImportsWhenLookingForFunctions).FilterFunctionsByParameterNames(parameterNames, resolver.EnableCaseInsensitive).Cast <IEdmOperationImport>().ToList();
                }
                else
                {
                    candidateMatchingOperationImports = resolver.ResolveOperationImports(model, identifier).ToList();
                }
            }
            catch (Exception exc)
            {
                if (!ExceptionUtils.IsCatchableExceptionType(exc))
                {
                    throw;
                }

                throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_FoundInvalidOperationImport(identifier), exc);
            }

            if (foundActionImportsWhenLookingForFunctions.Count > 0)
            {
                throw ExceptionUtil.CreateBadRequestError(ODataErrorStrings.RequestUriProcessor_SegmentDoesNotSupportKeyPredicates(identifier));
            }

            // If any of the things returned are an action, it better be the only thing returned, and there can't be parameters in the URL
            if (candidateMatchingOperationImports.Any(f => f.IsActionImport()))
            {
                if (candidateMatchingOperationImports.Count > 1)
                {
                    if (candidateMatchingOperationImports.Any(o => o.IsFunctionImport()))
                    {
                        throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_MultipleOperationImportOverloads(identifier));
                    }
                    else
                    {
                        throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_MultipleActionImportOverloads(identifier));
                    }
                }

                if (parameterNames.Count() != 0)
                {
                    throw ExceptionUtil.CreateBadRequestError(ODataErrorStrings.RequestUriProcessor_SegmentDoesNotSupportKeyPredicates(identifier));
                }

                matchingOperationImport = candidateMatchingOperationImports.Single();
                return(true);
            }

            // If parameter count is zero and there is one function import whoese parameter count is zero, return this function import.
            if (candidateMatchingOperationImports.Count > 1 && parameterNames.Count == 0)
            {
                candidateMatchingOperationImports = candidateMatchingOperationImports.Where(operationImport => operationImport.Operation.Parameters.Count() == 0).ToList();
            }

            if (candidateMatchingOperationImports.Count == 0)
            {
                matchingOperationImport = null;
                return(false);
            }

            // If more than one overload matches, try to select based on optional parameters
            if (candidateMatchingOperationImports.Count > 1)
            {
                candidateMatchingOperationImports = candidateMatchingOperationImports.FindBestOverloadBasedOnParameters(parameterNames).ToList();
            }

            if (candidateMatchingOperationImports.Count > 1)
            {
                throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_MultipleOperationImportOverloads(identifier));
            }

            matchingOperationImport = candidateMatchingOperationImports.Single();

            return(matchingOperationImport != null);
        }
Esempio n. 17
0
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataWriter"/> for <paramref name="entry"/>.
 /// </summary>
 /// <param name="entry">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataEntry entry, ODataFeedAndEntrySerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(entry, "entry");
     entry.SerializationInfo = serializationInfo;
 }
Esempio n. 18
0
        /// <summary>
        /// Find any related keys from the parent key segment, if it exists, and add them to the raw key values that
        /// we already have from the uri.
        /// </summary>
        /// <param name="rawKeyValuesFromUri">The raw key values as we've parsed them from the uri.</param>
        /// <param name="targetEntityKeyProperties">The list of key properties on the target entity.</param>
        /// <param name="currentNavigationProperty">The current navigation property that we're trying to follow using the raw key values</param>
        /// <param name="keySegmentOfParentEntity">The key segment of the parent entity in this path, if it exists. Null otherwise</param>
        /// <returns>A new SegmentArgumentParser with any keys that were found added to its list of NamedValues.</returns>
        /// <throws>Thorws if the input currentNavigationProperty is null.</throws>
        public static SegmentArgumentParser FindAndUseKeysFromRelatedSegment(SegmentArgumentParser rawKeyValuesFromUri, IEnumerable <IEdmStructuralProperty> targetEntityKeyProperties, IEdmNavigationProperty currentNavigationProperty, KeySegment keySegmentOfParentEntity)
        {
            ExceptionUtils.CheckArgumentNotNull(currentNavigationProperty, "currentNavigationProperty");
            ExceptionUtils.CheckArgumentNotNull(rawKeyValuesFromUri, "rawKeyValuesFromUri");

            ReadOnlyCollection <IEdmStructuralProperty> targetKeyPropertyList = targetEntityKeyProperties != null ? new ReadOnlyCollection <IEdmStructuralProperty>(targetEntityKeyProperties.ToList()) : new ReadOnlyCollection <IEdmStructuralProperty>(new List <IEdmStructuralProperty>());

            // should only get here if the number of raw parameters from the uri is different than the number of key properties for the target entity.
            Debug.Assert(rawKeyValuesFromUri.ValueCount < targetKeyPropertyList.Count(), "rawKeyValuesFromUri.ValueCount < targetEntityKeyProperties.Count()");

            // if the raw key from the uri has positional values, there must be only one of them
            // its important to cache this value here because we'll change it when we add new
            // named values below (the implementation of AreValuesNamed is just namedValues !=null)
            bool hasPositionalValues = !rawKeyValuesFromUri.AreValuesNamed;

            if (hasPositionalValues && rawKeyValuesFromUri.ValueCount > 1)
            {
                return(rawKeyValuesFromUri);
            }

            if (keySegmentOfParentEntity == null)
            {
                return(rawKeyValuesFromUri);
            }

            // TODO: p2 merge the below 2 pieces of codes
            // find out if any target entity key properties have referential constraints that link them to the previous rawKeyValuesFromUri.
            List <EdmReferentialConstraintPropertyPair> keysFromReferentialIntegrityConstraint = ExtractMatchingPropertyPairsFromNavProp(currentNavigationProperty, targetKeyPropertyList).ToList();

            foreach (EdmReferentialConstraintPropertyPair keyFromReferentialIntegrityConstraint in keysFromReferentialIntegrityConstraint)
            {
                KeyValuePair <string, object> valueFromParent = keySegmentOfParentEntity.Keys.SingleOrDefault(x => x.Key == keyFromReferentialIntegrityConstraint.DependentProperty.Name);
                if (valueFromParent.Key != null)
                {
                    // if the key from the referential integrity constraint is one of the target key properties
                    // and that key property isn't already populated in the raw key values from the uri, then
                    // we set that value to the value from the parent key segment.
                    if (targetKeyPropertyList.Any(x => x.Name == keyFromReferentialIntegrityConstraint.PrincipalProperty.Name))
                    {
                        rawKeyValuesFromUri.AddNamedValue(
                            keyFromReferentialIntegrityConstraint.PrincipalProperty.Name,
                            ConvertKeyValueToUriLiteral(valueFromParent.Value, rawKeyValuesFromUri.KeyAsSegment));
                    }
                }
            }

            // also need to look to see if any nav props exist in the target set that refer back to this same set, which might have
            // referential constraints also.
            keysFromReferentialIntegrityConstraint.Clear();
            IEdmNavigationProperty reverseNavProp = currentNavigationProperty.Partner;

            if (reverseNavProp != null)
            {
                keysFromReferentialIntegrityConstraint.AddRange(ExtractMatchingPropertyPairsFromReversedNavProp(reverseNavProp, targetKeyPropertyList));
            }

            foreach (EdmReferentialConstraintPropertyPair keyFromReferentialIntegrityConstraint in keysFromReferentialIntegrityConstraint)
            {
                KeyValuePair <string, object> valueFromParent = keySegmentOfParentEntity.Keys.SingleOrDefault(x => x.Key == keyFromReferentialIntegrityConstraint.PrincipalProperty.Name);
                if (valueFromParent.Key != null)
                {
                    // if the key from the referential integrity constraint is one of the target key properties
                    // and that key property isn't already populated in the raw key values from the uri, then
                    // we set that value to the value from the parent key segment.
                    if (targetKeyPropertyList.Any(x => x.Name == keyFromReferentialIntegrityConstraint.DependentProperty.Name))
                    {
                        rawKeyValuesFromUri.AddNamedValue(
                            keyFromReferentialIntegrityConstraint.DependentProperty.Name,
                            ConvertKeyValueToUriLiteral(valueFromParent.Value, rawKeyValuesFromUri.KeyAsSegment));
                    }
                }
            }

            // if we had a positional value before, then we need to add that value as a new named value.
            // the name that we choose will be the only value from the target entity key properties
            // that isn't already set in the NamedValues list.
            if (hasPositionalValues)
            {
                if (rawKeyValuesFromUri.NamedValues != null)
                {
                    List <IEdmStructuralProperty> unassignedProperties = targetKeyPropertyList.Where(x => !rawKeyValuesFromUri.NamedValues.ContainsKey(x.Name)).ToList();

                    if (unassignedProperties.Count == 1)
                    {
                        rawKeyValuesFromUri.AddNamedValue(unassignedProperties[0].Name, rawKeyValuesFromUri.PositionalValues[0]);
                    }
                    else
                    {
                        return(rawKeyValuesFromUri);
                    }

                    // clear out the positional value so that we keep a consistent state in the
                    // raw keys from uri.
                    rawKeyValuesFromUri.PositionalValues.Clear();
                }
                else
                {
                    return(rawKeyValuesFromUri);
                }
            }

            return(rawKeyValuesFromUri);
        }
Esempio n. 19
0
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataCollectionWriter"/> for <paramref name="collectionStart"/>.
 /// </summary>
 /// <param name="collectionStart">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataCollectionStart collectionStart, ODataCollectionStartSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(collectionStart, "collectionStart");
     collectionStart.SerializationInfo = serializationInfo;
 }
Esempio n. 20
0
        void RunStaffPersonalConsumer()
        {
            StaffPersonalConsumer staffPersonalConsumer = new StaffPersonalConsumer(SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, SettingsManager.ConsumerSettings.SolutionId);

            staffPersonalConsumer.Register();

            try
            {
                EqualCondition condition = new EqualCondition()
                {
                    Left = "TeachingGroups", Right = "597ad3fe-47e7-4b2c-b919-a93c564d19d0"
                };
                IList <EqualCondition> conditions = new List <EqualCondition>();
                conditions.Add(condition);
                IEnumerable <StaffPersonal> staffPersonals = staffPersonalConsumer.QueryByServicePath(conditions);

                if (log.IsInfoEnabled)
                {
                    log.Info("Staff count is " + (staffPersonals == null ? 0 : staffPersonals.Count()));
                }

                if (staffPersonals != null)
                {
                    foreach (StaffPersonal staffPersonal in staffPersonals)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Staff name is " + staffPersonal.PersonInfo.Name.GivenName + " " + staffPersonal.PersonInfo.Name.FamilyName);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the StaffPersonal Consumer against HITS.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                staffPersonalConsumer.Unregister();
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataDeltaWriter"/> for <paramref name="deltaDeletedEntry"/>.
 /// </summary>
 /// <param name="deltaDeletedEntry">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataDeltaDeletedEntry deltaDeletedEntry, ODataDeltaSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(deltaDeletedEntry, "deltaDeletedEntry");
     deltaDeletedEntry.SerializationInfo = serializationInfo;
 }
Esempio n. 22
0
        void RunStudentContactRelationshipConsumer()
        {
            StudentContactRelationshipConsumer consumer = new StudentContactRelationshipConsumer(SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, SettingsManager.ConsumerSettings.SolutionId);

            consumer.Register();

            try
            {
                IEnumerable <StudentContactRelationship> relationships = consumer.Query(1, 2);

                if (log.IsInfoEnabled)
                {
                    log.Info($"Student contact relationship count is {(relationships == null ? 0 : relationships.Count())}.");
                }

                if (relationships != null)
                {
                    foreach (StudentContactRelationship relationship in relationships)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info($"Student {relationship.StudentPersonalRefId} has {relationship.StudentContactPersonalRefId} as a registered contact.");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the StudentContactRelationship Consumer against HITS.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                consumer.Unregister();
            }
        }
Esempio n. 23
0
 /// <summary>
 /// Accept a <see cref="QueryNodeVisitor{T}"/> that walks a tree of <see cref="QueryNode"/>s.
 /// </summary>
 /// <typeparam name="T">Type that the visitor will return after visiting this token.</typeparam>
 /// <param name="visitor">An implementation of the visitor interface.</param>
 /// <returns>An object whose type is determined by the type parameter of the visitor.</returns>
 /// <exception cref="System.ArgumentNullException">Throws if the input visitor is null.</exception>
 public override T Accept <T>(QueryNodeVisitor <T> visitor)
 {
     DebugUtils.CheckNoExternalCallers();
     ExceptionUtils.CheckArgumentNotNull(visitor, "visitor");
     return(visitor.Visit(this));
 }
Esempio n. 24
0
        void RunStudentPersonalConsumer()
        {
            StudentPersonalConsumer studentPersonalConsumer = new StudentPersonalConsumer(SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, SettingsManager.ConsumerSettings.SolutionId);

            studentPersonalConsumer.Register();

            try
            {
                IEnumerable <StudentPersonal> studentPersonals = studentPersonalConsumer.Query(1, 2);

                if (log.IsInfoEnabled)
                {
                    log.Info("Student count is " + (studentPersonals == null ? 0 : studentPersonals.Count()));
                }

                if (studentPersonals != null)
                {
                    foreach (StudentPersonal studentPersonal in studentPersonals)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("Student name is " + studentPersonal.PersonInfo.Name.GivenName + " " + studentPersonal.PersonInfo.Name.FamilyName);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the StudentPersonal Consumer against HITS.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                studentPersonalConsumer.Unregister();
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Create a AggregateTransformationNode.
        /// </summary>
        /// <param name="expressions">A list of <see cref="AggregateExpression"/>.</param>
        public AggregateTransformationNode(IEnumerable <AggregateExpression> expressions)
        {
            ExceptionUtils.CheckArgumentNotNull(expressions, "expressions");

            this.expressions = expressions;
        }
Esempio n. 26
0
        void RunWellbeingCharacteristicConsumer()
        {
            WellbeingCharacteristicConsumer consumer = new WellbeingCharacteristicConsumer(SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, SettingsManager.ConsumerSettings.SolutionId);

            consumer.Register();

            try
            {
                IEnumerable <WellbeingCharacteristic> characteristics = consumer.Query(1, 2);

                if (log.IsInfoEnabled)
                {
                    log.Info($"Wellbeing characteristic count is {(characteristics == null ? 0 : characteristics.Count())}.");
                }

                if (characteristics != null)
                {
                    foreach (WellbeingCharacteristic characteristic in characteristics)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info($"Wellbeing characteristic is for student {characteristic.StudentPersonalRefId}.");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the WellbeingCharacteristic Consumer against HITS.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                consumer.Unregister();
            }
        }
Esempio n. 27
0
 /// <summary>
 /// Check if this segment is equal to another segment.
 /// </summary>
 /// <param name="other">the other segment to check.</param>
 /// <returns>true if the other segment is equal.</returns>
 /// <exception cref="System.ArgumentNullException">throws if the input other is null.</exception>
 internal override bool Equals(ODataPathSegment other)
 {
     ExceptionUtils.CheckArgumentNotNull(other, "other");
     return(other is CountSegment);
 }
Esempio n. 28
0
        void RunSchoolInfoConsumer()
        {
            SchoolInfoConsumer schoolInfoConsumer = new SchoolInfoConsumer(SettingsManager.ConsumerSettings.ApplicationKey, SettingsManager.ConsumerSettings.InstanceId, SettingsManager.ConsumerSettings.UserToken, SettingsManager.ConsumerSettings.SolutionId);

            schoolInfoConsumer.Register();

            try
            {
                // Query all schools.
                IEnumerable <SchoolInfo> allSchools = schoolInfoConsumer.Query(1, 10);

                if (log.IsInfoEnabled)
                {
                    log.Info("School count is " + (allSchools == null ? 0 : allSchools.Count()));
                }

                if (allSchools != null)
                {
                    foreach (SchoolInfo school in allSchools)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("School " + school.SchoolName + " has a RefId of " + school.RefId + ".");
                        }
                    }
                }

                // Create multiple schools.
                MultipleCreateResponse createResponse = schoolInfoConsumer.Create(CreateSchools());

                foreach (CreateStatus status in createResponse.StatusRecords)
                {
                    SchoolInfo school = schoolInfoConsumer.Query(status.Id);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("New school " + school.SchoolName + " has a RefId of " + school.RefId + ".");
                    }
                }

                // Update multiple schools.
                List <SchoolInfo> schoolsToUpdate = new List <SchoolInfo>();

                foreach (CreateStatus status in createResponse.StatusRecords)
                {
                    SchoolInfo school = schoolInfoConsumer.Query(status.Id);
                    school.SchoolName += "x";
                    schoolsToUpdate.Add(school);
                }

                MultipleUpdateResponse updateResponse = schoolInfoConsumer.Update(schoolsToUpdate);

                foreach (UpdateStatus status in updateResponse.StatusRecords)
                {
                    SchoolInfo school = schoolInfoConsumer.Query(status.Id);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Updated school " + school.SchoolName + " has a RefId of " + school.RefId + ".");
                    }
                }

                // Delete multiple schools.
                ICollection <string> schoolsToDelete = new List <string>();

                foreach (CreateStatus status in createResponse.StatusRecords)
                {
                    schoolsToDelete.Add(status.Id);
                }

                MultipleDeleteResponse deleteResponse = schoolInfoConsumer.Delete(schoolsToDelete);

                foreach (DeleteStatus status in deleteResponse.StatusRecords)
                {
                    SchoolInfo school = schoolInfoConsumer.Query(status.Id);

                    if (school == null)
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("School with RefId of " + status.Id + " has been deleted.");
                        }
                    }
                    else
                    {
                        if (log.IsInfoEnabled)
                        {
                            log.Info("School " + school.SchoolName + " with RefId of " + school.RefId + " FAILED deletion.");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Error running the SchoolInfo Consumer against HITS.\n" + ExceptionUtils.InferErrorResponseMessage(e), e);
                }
            }
            finally
            {
                schoolInfoConsumer.Unregister();
            }
        }
Esempio n. 29
0
 /// <summary>
 /// Handle a <see cref="FilterSegment"/> using an instance of <see cref="PathSegmentHandler"/>.
 /// </summary>
 /// <param name="handler">An implementation of the handler interface.</param>
 /// <exception cref="System.ArgumentNullException">Throws if the input handler is null.</exception>
 public override void HandleWith(PathSegmentHandler handler)
 {
     ExceptionUtils.CheckArgumentNotNull(handler, "handler");
     handler.Handle(this);
 }
Esempio n. 30
0
 public static void Show(Exception exception)
 {
     MessageBox.Show(ExceptionUtils.Get(exception), AssemblyUtils.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
 }