Esempio n. 1
0
        /// <summary>Fires the notification for a single action.</summary>
        /// <param name="service">Service on which methods should be invoked.</param>
        /// <param name="target">Object to be tracked.</param>
        /// <param name="container">Container in which object is changed.</param>
        /// <param name="action">Action affecting target.</param>
        internal static void FireNotification(IDataService service, object target, ResourceSetWrapper container, UpdateOperations action)
        {
            Debug.Assert(service != null, "service != null");
            AssertActionValues(target, container);

            MethodInfo[] methods = container.ChangeInterceptors;
            if (methods != null)
            {
                object[] parameters = new object[2];
                parameters[0] = target;
                parameters[1] = action;
                for (int i = 0; i < methods.Length; i++)
                {
                    try
                    {
                        methods[i].Invoke(service.Instance, parameters);
                    }
                    catch (TargetInvocationException exception)
                    {
                        ErrorHandler.HandleTargetInvocationException(exception);
                        throw;
                    }
                }
            }
        }
Esempio n. 2
0
 internal void TrackAction(object target, ResourceSetWrapper container, UpdateOperations action)
 {
     if (container.ChangeInterceptors != null)
     {
         Dictionary<object, UpdateOperations> dictionary;
         UpdateOperations operations;
         if (!this.items.TryGetValue(container, out dictionary))
         {
             if (this.service.Provider.IsV1Provider)
             {
                 dictionary = new Dictionary<object, UpdateOperations>(EqualityComparer<object>.Default);
             }
             else
             {
                 dictionary = new Dictionary<object, UpdateOperations>(ReferenceEqualityComparer<object>.Instance);
             }
             this.items.Add(container, dictionary);
         }
         if (dictionary.TryGetValue(target, out operations))
         {
             if ((action | operations) != operations)
             {
                 dictionary[target] = action | operations;
             }
         }
         else
         {
             dictionary.Add(target, action);
         }
     }
 }
Esempio n. 3
0
 internal static void FireNotification(IDataService service, object target, ResourceSetWrapper container, UpdateOperations action)
 {
     MethodInfo[] changeInterceptors = container.ChangeInterceptors;
     if (changeInterceptors != null)
     {
         object[] parameters = new object[] { target, action };
         for (int i = 0; i < changeInterceptors.Length; i++)
         {
             try
             {
                 changeInterceptors[i].Invoke(service.Instance, parameters);
             }
             catch (TargetInvocationException exception)
             {
                 ErrorHandler.HandleTargetInvocationException(exception);
                 throw;
             }
         }
     }
 }
Esempio n. 4
0
 public void AuthorChangeHandler(Author a, UpdateOperations op)
 {
 }
        public virtual void InterceptChange <TEntity>(OrganizationServiceContext context, TEntity entity, UpdateOperations operations) where TEntity : Entity
        {
            var entityName = entity.LogicalName;

            try
            {
                switch (entityName)
                {
                case "adx_contentsnippet":
                    InterceptContentSnippetUpdate(context, entity, operations);
                    break;

                case "adx_webfile":
                    InterceptWebFileUpdate(context, entity, operations);
                    break;

                case "adx_weblink":
                    InterceptWebLinkUpdate(context, entity, operations);
                    break;

                case "adx_weblinkset":
                    InterceptWebLinkSetUpdate(context, entity, operations);
                    break;

                case "adx_webpage":
                    InterceptWebPageUpdate(context, entity, operations);
                    break;

                default:
                    // Let other change interceptors worry about other entity types.
                    break;
                }
            }
            catch (SecurityException)
            {
                throw new DataServiceException(403, "Write permission on entity type {0} is denied.".FormatWith(entity.GetType().FullName));
            }
        }
Esempio n. 6
0
 public void OnChangeJournal(Journal entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
 public void OnChangeOrders(Order order, UpdateOperations operations)
 {
     SendFeedNotification <Order>("Orders", order,
                                  new int[] { order.OrderID }, operations);
 }
Esempio n. 8
0
 public void OnChangeUserInputValue(ScheduledJournalInputValue entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
        private async void SendFeedNotification <TEntity>(
            string feed, TEntity entity, int[] entityKeys, UpdateOperations operations)
        {
            var    entityType      = entity.GetType();
            string baseTypeName    = entityType.BaseType.Name;
            string operationString = string.Empty;

            switch (operations)
            {
            case UpdateOperations.Change:
                operationString = "updated";
                break;

            case UpdateOperations.Add:
                operationString = "added";
                break;

            case UpdateOperations.Delete:
                operationString = "deleted";
                break;
            }
            string keysAsString = string.Empty;

            foreach (int key in entityKeys)
            {
                keysAsString += string.Format("{0},", key);
            }
            keysAsString = keysAsString.TrimEnd(',');
            var entityAsString = string.Format("{0}({1})", baseTypeName, keysAsString);
            var message        = string.Format("The entity '{0}' was {2} in the '{1}' feed.",
                                               entityAsString, feed, operationString);

            // Define the parameters for the notification templates.
            var parameters =
                new Dictionary <string, string>();

            parameters.Add("feed", feed);
            parameters.Add("operation", operationString);
            parameters.Add("entity", entityAsString);
            parameters.Add("message", message); // only used for iOS clients.

            // Send a cross-plaform notification by using templates,
            // including toasts to Windows Store apps.
            await hubClient.SendTemplateNotificationAsync(parameters, feed);

            // Create and send a raw notification to auto-update
            // any Windows Store or Windows Phone apps.
            var payload = await JsonConvert.SerializeObjectAsync(parameters);

            try
            {
                // Create the WNS with the header for a raw notification.
                WindowsNotification wns = new WindowsNotification(payload,
                                                                  new Dictionary <string, string>()
                {
                    { "X-WNS-Type", "wns/raw" }
                }, feed);
                wns.ContentType = "application/octet-stream";
                var result = await hubClient.SendNotificationAsync(wns);

                // Create the MPNS with the header for a raw notification.
                MpnsNotification mpns = new MpnsNotification(payload,
                                                             new Dictionary <string, string>()
                {
                    { "X-NotificationClass", "3" }
                }, feed);
                mpns.ContentType = "text/xml";
                await hubClient.SendNotificationAsync(mpns);
            }
            catch (ArgumentException ex)
            {
                // Send methods return an error response when the notification hub hasn't yet
                // been configured for a particular client platform.
            }
        }
Esempio n. 10
0
 public void OnChange(LedgerTxn entity, UpdateOperations operations)
 {
     //InterceptChange(entity, operations);
     throw new NotSupportedException();
 }
Esempio n. 11
0
 public void OnChangeSequenceNumber(SequenceNumber entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
Esempio n. 12
0
 public void ChangeValues(OpenElement entity, UpdateOperations operation)
 {
     OpenChangeInterceptorServiceState.InterceptorFired = true;
 }
Esempio n. 13
0
 public void OnChangePeople(Person p, UpdateOperations updateOperations)
 {
 }
Esempio n. 14
0
 public void OnChangeCustomer(Customer customer, UpdateOperations operations)
 {
     Console.WriteLine("OnChangeCustomer ChangeInterceptor called");
 }
Esempio n. 15
0
 public void OnChangeApplicationUser(ApplicationUser user, UpdateOperations operations)
 {
 }
Esempio n. 16
0
 public void OnChangeEmployee(Employee emp, UpdateOperations operations)
 {
 }
Esempio n. 17
0
 public void OnChangeWarehouseLocationBinTypes(WarehouseLocationBinCode warehouseCode, UpdateOperations operations)
 {
     if (operations == UpdateOperations.Delete)
     {//update a null to any place the Code was used by its parent record...
         XERP.Server.DAL.WarehouseDAL.DALUtility dalUtility = new DALUtility();
         var context = new WarehouseEntities(dalUtility.EntityConectionString);
         context.WarehouseLocationBins.MergeOption = System.Data.Objects.MergeOption.NoTracking;
         string companyID = warehouseCode.CompanyID;
         string codeID    = warehouseCode.WarehouseLocationBinCodeID;
         string sqlstring = "UPDATE WarehouseLocationBins SET WarehouseLocationBinCodeID = null WHERE CompanyID = '" + companyID + "' and WarehouseLocationBinCodeID = '" + codeID + "'";
         context.ExecuteStoreCommand(sqlstring);
     }
 }
Esempio n. 18
0
 public void OnChangeProviderAccountParticipant(ProviderAccountParticipant entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
Esempio n. 19
0
 public void OnChangeJournalTemplateTxn(JournalTemplateTxn entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
Esempio n. 20
0
 public void OnChangeWorkItem(WorkItemAttachment entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
Esempio n. 21
0
 public void OnChangeUserInput(JournalTemplateInput entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
Esempio n. 22
0
 public void OnChangeAccountingEntity(AccountingEntity entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
Esempio n. 23
0
 public void OnChangeDocumentContent(DocumentContent entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
        public void OnChangeOrder_Details(Order_Detail item, UpdateOperations operations)
        {
            var keys = new int[] { item.OrderID, item.ProductID };

            SendFeedNotification <Order_Detail>("Order_Details", item, keys, operations);
        }
Esempio n. 25
0
 public void OnChangeParty(Party entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
 public ActionResult EmpDeptnoDate()
 {
     DL         = UpdateOperations.getDepts();
     ViewBag.DL = DL;
     return(View());
 }
Esempio n. 27
0
 public void OnChangeContract(Contract entity, UpdateOperations operations)
 {
     InterceptChange(entity, operations);
 }
 public ActionResult SelEmpData()
 {
     EL = UpdateOperations.EmpData();
     return(View(EL));
 }
Esempio n. 29
0
        /// <summary>
        /// Tracks the specified <paramref name="target"/> for a 
        /// given <paramref name="action "/> on the <paramref name="container"/>.
        /// </summary>
        /// <param name="target">Object to be tracked.</param>
        /// <param name="container">Container in which object is changed.</param>
        /// <param name="action">Action affecting target.</param>
        /// <remarks>
        /// If <paramref name="target"/> was already being tracked, the actions are OR'ed together.
        /// </remarks>
        internal void TrackAction(object target, ResourceSetWrapper container, UpdateOperations action)
        {
            AssertActionValues(target, container);
            Debug.Assert(this.items != null, "this.items != null - otherwise FireNotification has already been called");

            // If it won't be necessary for us to fire authorizatio methods,
            // skip tracking altogether.
            if (container.ChangeInterceptors == null)
            {
                return;
            }

            // Get the container for which the change has taken place.
            Dictionary<object, UpdateOperations> changedItems;
            if (!this.items.TryGetValue(container, out changedItems))
            {
                // In order to mantain backwards compatibility, we are going to use default comparer for V1
                // providers. However, for V2 providers we are going to do reference equality comparisons.
                if (this.service.Provider.HasReflectionOrEFProviderQueryBehavior)
                {
                    changedItems = new Dictionary<object, UpdateOperations>(EqualityComparer<object>.Default);
                }
                else
                {
                    changedItems = new Dictionary<object, UpdateOperations>(ReferenceEqualityComparer<object>.Instance);
                }

                this.items.Add(container, changedItems);
            }

            UpdateOperations existingAction;
            if (changedItems.TryGetValue(target, out existingAction))
            {
                if ((action | existingAction) != existingAction)
                {
                    changedItems[target] = action | existingAction;
                }
            }
            else
            {
                changedItems.Add(target, action);
            }
        }
Esempio n. 30
0
 public void OnChangeCustomer(NorthwindModel.Customers c, UpdateOperations operation)
 {
     Interlocked.Increment(ref InterceptorChecker.ChangeInterceptorInvokeCount);
 }
Esempio n. 31
0
        /// <summary>Fires the notification for a single action.</summary>
        /// <param name="service">Service on which methods should be invoked.</param>
        /// <param name="target">Object to be tracked.</param>
        /// <param name="container">Container in which object is changed.</param>
        /// <param name="action">Action affecting target.</param>
        internal static void FireNotification(IDataService service, object target, ResourceSetWrapper container, UpdateOperations action)
        {
            Debug.Assert(service != null, "service != null");
            AssertActionValues(target, container);

            MethodInfo[] methods = container.ChangeInterceptors;
            if (methods != null)
            {
                object[] parameters = new object[2];
                parameters[0] = target;
                parameters[1] = action;
                for (int i = 0; i < methods.Length; i++)
                {
                    try
                    {
                        methods[i].Invoke(service.Instance, parameters);
                    }
                    catch (TargetInvocationException exception)
                    {
                        ErrorHandler.HandleTargetInvocationException(exception);
                        throw;
                    }
                }
            }
        }
Esempio n. 32
0
 public void OnChangeItem(Item p, UpdateOperations operation)
 {
     Interlocked.Increment(ref InterceptorChecker.ChangeInterceptorInvokeCount);
 }
Esempio n. 33
0
 public void ItemsChangeInterceptor(DSPSelfmodifyingResource resource, UpdateOperations operation)
 {
     LastItemsUpdateOperation = operation;
 }
Esempio n. 34
0
        public void ChangeInterceptor <T>(DataService <T> service, string methodName, object o, UpdateOperations action)
        {
            MethodInfo method = service.GetType().GetMethod(methodName);

            if (method == null)
            {
                throw new ArgumentException("Could not find method '" + methodName + "' on service of type '" + service.GetType().FullName + "'");
            }
            Parent.Add(method, Parent.Serialize(o), action.ToString());
        }
        protected virtual void InterceptContentSnippetUpdate(OrganizationServiceContext context, Entity entity, UpdateOperations operations)
        {
            AssertCrmEntityChangeAccess(context, entity);

            SetUpdateTrackingAttributes(entity);
        }
 public void EntitiesChangeInterceptor(DSPResourceWithCollectionProperty resource, UpdateOperations operations)
 {
     if (InterceptorServiceDefinition.Current.EnableChangeInterceptors)
     {
         Assert.IsFalse(InterceptorServiceDefinition.Current.ChangeInterceptorCalledOnEntityId.HasValue, "Change interceptor called more than once.");
         if (operations == UpdateOperations.Add)
         {
             // The new resource has no properties set on it yet, so assume the "new" one - 42
             InterceptorServiceDefinition.Current.ChangeInterceptorCalledOnEntityId = 42;
         }
         else
         {
             InterceptorServiceDefinition.Current.ChangeInterceptorCalledOnEntityId = (int)resource.GetValue("ID");
         }
     }
 }