Exemplo n.º 1
0
        /// <summary>
        /// Executes the given action, stores the event in event history and notifies the listeners.
        /// </summary>
        private async Task ExecuteActionAsync(ResolvedAction resolvedAction, string beaconPid, BeaconEventType beaconEventType, string location)
        {
            try
            {
                Logger.Debug("SDKEngine: ExecuteActionAsync " + beaconPid + " BeaconEventType: " + beaconEventType + " type: " + resolvedAction?.BeaconAction.Type);
                bool checkOnlyOnce = _eventHistory.CheckSendOnlyOnceAsync(resolvedAction);
                bool shouldSupress = _eventHistory.ShouldSupressAsync(resolvedAction);

                Logger.Trace("SDKEngine: ExecuteActionAsync " + beaconPid + " checkOnlyOnce: " + checkOnlyOnce + " shouldSupress:" + shouldSupress);
                if (!shouldSupress && !checkOnlyOnce && resolvedAction.IsInsideTimeframes(DateTimeOffset.Now))
                {
                    Logger.Trace("SDKEngine: ExecuteActionAsync " + beaconPid + " action resolved");
                    await _eventHistory.SaveExecutedResolvedActionAsync(resolvedAction.BeaconAction, beaconPid, beaconEventType, location);

                    if (resolvedAction.BeaconAction.Type != BeaconActionType.Silent)
                    {
                        BeaconActionResolved?.Invoke(this, resolvedAction.BeaconAction);
                    }
                }
                else
                {
                    Logger.Trace("SDKEngine: ExecuteActionAsync " + beaconPid + " action not resolved");
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error during ExecuteActionAsync", e);
            }
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            List <ResolvedAction> resolvedActions = new List <ResolvedAction>();

            JArray actionsArray = JArray.Load(reader);

            foreach (JObject jobject in actionsArray)
            {
                ResolvedAction resolvedAction = new ResolvedAction();
                serializer.Populate(jobject.CreateReader(), resolvedAction);
                resolvedAction.BeaconAction = new BeaconAction();
                serializer.Populate(jobject.CreateReader(), resolvedAction.BeaconAction);
                if (jobject["content"] != null)
                {
                    serializer.Populate(jobject["content"]?.CreateReader(), resolvedAction.BeaconAction);
                    resolvedAction.BeaconAction.PayloadString = jobject["content"]["payload"]?.ToString();
                    // create json object for fallback
                    if (!string.IsNullOrEmpty(resolvedAction.BeaconAction.PayloadString))
                    {
                        resolvedAction.BeaconAction.Payload = JsonObject.Parse(resolvedAction.BeaconAction.PayloadString);
                    }
                }
                resolvedActions.Add(resolvedAction);
            }

            return(resolvedActions);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            List<ResolvedAction> resolvedActions = new List<ResolvedAction>();

            JArray actionsArray = JArray.Load(reader);
            foreach (JObject jobject in actionsArray)
            {
                ResolvedAction resolvedAction = new ResolvedAction();
                serializer.Populate(jobject.CreateReader(), resolvedAction);
                resolvedAction.BeaconAction = new BeaconAction();
                serializer.Populate(jobject.CreateReader(), resolvedAction.BeaconAction);
                if (jobject["content"] != null)
                {
                    serializer.Populate(jobject["content"]?.CreateReader(), resolvedAction.BeaconAction);
                    resolvedAction.BeaconAction.PayloadString = jobject["content"]["payload"]?.ToString();
                    // create json object for fallback
                    if(!string.IsNullOrEmpty(resolvedAction.BeaconAction.PayloadString))
                    {
                        resolvedAction.BeaconAction.Payload = JsonObject.Parse(resolvedAction.BeaconAction.PayloadString);
                    }
                }
                resolvedActions.Add(resolvedAction);
            }

            return resolvedActions;
        }
Exemplo n.º 4
0
        public void ProjectActionsExecuted_WhenSolutionManagerActionsExecutedEventRaised_IsRaised()
        {
            NuGetUIContext context = CreateNuGetUIContext();
            var            project = new TestNuGetProject();

            var projectAction = NuGetProjectAction.CreateInstallProjectAction(
                PackageIdentity,
                sourceRepository: null,
                project);
            var resolvedActions = new ResolvedAction[] { new ResolvedAction(project, projectAction) };
            var wasEventRaised  = false;

            string[] expectedProjectIds = resolvedActions
                                          .Select(resolvedAction => resolvedAction.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId))
                                          .ToArray();

            context.ProjectActionsExecuted += (object sender, IReadOnlyCollection <string> actualProjectIds) =>
            {
                wasEventRaised = true;

                Assert.Equal(expectedProjectIds, actualProjectIds);
            };

            _solutionManager.Raise(s => s.ActionsExecuted += null, new ActionsExecutedEventArgs(resolvedActions));

            Assert.True(wasEventRaised);
        }
Exemplo n.º 5
0
        public void TestDelayedActionToString()
        {
            ResolvedAction action = new ResolvedAction();

            action.BeaconAction         = new BeaconAction();
            action.BeaconAction.Body    = "body";
            action.BeaconAction.Id      = 1;
            action.BeaconAction.Payload = JsonObject.Parse("{\"pay\":\"load\"}");
            action.BeaconAction.Subject = "Subject";
            action.BeaconAction.Type    = BeaconActionType.InApp;
            action.BeaconAction.Url     = "http://sensorberg.com";
            action.BeaconAction.Uuid    = "uuid";
            action.Delay      = 123;
            action.BeaconPids = new List <string>()
            {
                "1", "2", "3", "4"
            };
            action.EventTypeDetectedByDevice = BeaconEventType.EnterExit;
            action.ReportImmediately         = true;
            action.SendOnlyOnce    = true;
            action.SuppressionTime = 321;
            action.Timeframes      = new List <Timeframe>()
            {
                new Timeframe()
                {
                    End = DateTimeOffset.Parse("2015-04-16T12:00:00.000+0000"), Start = DateTimeOffset.Parse("2015-04-15T12:00:00.000+0000")
                }
            };

            Guid   guid = Guid.NewGuid();
            string s    = FileStorageHelper.DelayedActionToString(action, DateTimeOffset.Parse("2015-04-16T14:00:00.000+0000"), "123", BeaconEventType.Enter, guid, "123");

            Assert.AreEqual(guid + ",1429192800000,False,eyJBY3Rpb24iOnsiQmVhY29uQWN0aW9uIjp7IklkIjoxLCJUeXBlIjozLCJlaWQiOiJ1dWlkIiwiU3ViamVjdCI6IlN1YmplY3QiLCJCb2R5IjoiYm9keSIsIlVybCI6Imh0dHA6Ly9zZW5zb3JiZXJnLmNvbSIsIlBheWxvYWRTdHJpbmciOiJ7XCJwYXlcIjpcImxvYWRcIn0ifSwiYmVhY29ucyI6WyIxIiwiMiIsIjMiLCI0Il0sInRyaWdnZXIiOjMsIkRlbGF5IjoxMjMsIlNlbmRPbmx5T25jZSI6dHJ1ZSwic3VwcHJlc3Npb25UaW1lIjozMjEsIlJlcG9ydEltbWVkaWF0ZWx5Ijp0cnVlLCJUaW1lZnJhbWVzIjpbeyJTdGFydCI6IjIwMTUtMDQtMTVUMTI6MDA6MDArMDA6MDAiLCJFbmQiOiIyMDE1LTA0LTE2VDEyOjAwOjAwKzAwOjAwIn1dfSwiVGltZSI6IjIwMTUtMDQtMTZUMTQ6MDA6MDArMDA6MDAiLCJCZWFjb24iOiIxMjMiLCJFdmVudCI6MX0=,123\n", s);
        }
        public async Task EventHistory_FlushHistory()
        {
            var beacon = new Beacon();
            beacon.Id1 = "7367672374000000ffff0000ffff0007";
            beacon.Id2 = 8008;
            beacon.Id3 = 5;
            beacon.Timestamp = DateTimeOffset.Now;
            var args = new BeaconEventArgs();
            args.Beacon = beacon;
            args.EventType = BeaconEventType.Exit;
            var resolvedActionEventArgs = new ResolvedActionsEventArgs() {BeaconPid = beacon.Pid, BeaconEventType = BeaconEventType.Enter};

            BeaconAction beaconaction1 = new BeaconAction() {Body = "body", Url = "http://www.com", Uuid = "1223"};
            BeaconAction beaconaction2 = new BeaconAction() {Body = "body", Url = "http://www.com", Uuid = "5678"};
            BeaconAction beaconaction3 = new BeaconAction() {Body = "body", Url = "http://www.com", Uuid = "9678"};
            ResolvedAction res1 = new ResolvedAction() {SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction1};
            ResolvedAction res2 = new ResolvedAction() {SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction2};
            ResolvedAction res3 = new ResolvedAction() {SuppressionTime = 1, SendOnlyOnce = true, BeaconAction = beaconaction3};

            EventHistory eventHistory = new EventHistory();

            await eventHistory.SaveBeaconEventAsync(args, null);
            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction1);
            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction3);

            await eventHistory.FlushHistoryAsync();
        }
        public async Task TimeZoneTest()
        {
            var dateTimeOffset = new DateTimeOffset(2015, 04, 16, 12, 34, 22, 627, new TimeSpan());

            ((MockApiConnection)ServiceManager.ApiConnction).LayoutFile = "mock/datetime_layout.json";
            ILayoutManager manager = ServiceManager.LayoutManager;

            Assert.IsTrue(await manager.VerifyLayoutAsync(true), "Verification failed");
            Layout         layout = manager.Layout;
            ResolvedAction action = layout.ResolvedActions.FirstOrDefault(a => a.BeaconAction.Uuid == "9ded63644e424d758b0218f7c70f2473");

            //"2015-04-16T12:34:22.627+0000"
            Assert.AreEqual(dateTimeOffset, action.Timeframes[0].Start.Value, "1 timeslot not correct");


            action = layout.ResolvedActions.FirstOrDefault(a => a.BeaconAction.Uuid == "3f30be2605524f82a9bf0ccb4a81618f");
            //"2015-04-16T14:34:22.627+0200"
            Assert.AreEqual(dateTimeOffset, action.Timeframes[0].Start.Value, "2 timeslot not correct");


            action = layout.ResolvedActions.FirstOrDefault(a => a.BeaconAction.Uuid == "312a8594e07542bd814ecdd17f76538e");
            //"2015-04-16T14:34:22.627"
            Assert.AreEqual(dateTimeOffset, action.Timeframes[0].Start.Value, "3 timeslot not correct");


            action = layout.ResolvedActions.FirstOrDefault(a => a.BeaconAction.Uuid == "312a8594e07542bd814ecsdd17f76538e");
            //"2015-04-16T14:34:22"
            Assert.AreEqual(new DateTimeOffset(2015, 04, 16, 12, 34, 22, new TimeSpan()), action.Timeframes[0].Start.Value, "4 timeslot not correct");


            action = layout.ResolvedActions.FirstOrDefault(a => a.BeaconAction.Uuid == "312a8594e0754asd2bd814ecsdd17f76538e");
            //"14:34:22"
            Assert.AreEqual(new DateTimeOffset(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 12, 34, 22, new TimeSpan()), action.Timeframes[0].Start.Value, "5 timeslot not correct");
        }
Exemplo n.º 8
0
        public static void AddActionToContentCollection(IPolicyResponseObject pro, IAction3 action, bool skipRootContainer, bool triggeredPolicy)
        {
            ResolvedAction resAction = new ResolvedAction();
            PolicyResponseAction pra = new PolicyResponseAction();
            pra.Action = action;
            pra.InternalProperties = new MockActionPropertySet();

            for (int index = 0; index < pro.ContentCollection.Count; ++index)
            {
                ContentItem contentItem = pro.ContentCollection[index] as ContentItem;
                if (null == contentItem)
                    continue;

                if (skipRootContainer && (0 == index) && (contentItem.File.IsCollection))
                    continue;     

                if (resAction.ContentCollection == null)
                    resAction.ContentCollection = new Collection<IContentItem>();

                resAction.ContentCollection.Add(contentItem);
                resAction.ResponseAction = pra;

                if (pro.ResolvedActionCollection == null)
                    (pro as PolicyResponseObject).ResolvedActionCollection = new Collection<IResolvedAction>();
                
                if(!pro.ResolvedActionCollection.Contains(resAction))
                    pro.ResolvedActionCollection.Add(resAction);

                AddActionToContentItem(contentItem, pra, triggeredPolicy);
            }
        }
Exemplo n.º 9
0
        private static ProjectAction CreateProjectAction(ResolvedAction resolvedAction)
        {
            List <ImplicitProjectAction>?implicitActions = null;

            if (resolvedAction.Action is BuildIntegratedProjectAction buildIntegratedAction)
            {
                implicitActions = new List <ImplicitProjectAction>();

                foreach (NuGetProjectAction buildAction in buildIntegratedAction.GetProjectActions())
                {
                    var implicitAction = new ImplicitProjectAction(
                        CreateProjectActionId(),
                        buildAction.PackageIdentity,
                        buildAction.NuGetProjectActionType);

                    implicitActions.Add(implicitAction);
                }
            }

            string projectId     = resolvedAction.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId);
            var    projectAction = new ProjectAction(
                CreateProjectActionId(),
                projectId,
                resolvedAction.Action.PackageIdentity,
                resolvedAction.Action.NuGetProjectActionType,
                implicitActions);

            return(projectAction);
        }
Exemplo n.º 10
0
 public async Task <bool> SaveDelayedAction(ResolvedAction action, DateTimeOffset dueTime, string beaconPid, BeaconEventType eventType, string location)
 {
     DelayedActions.Add(new DelayedActionData()
     {
         BeaconPid = beaconPid, DueTime = dueTime, EventTypeDetectedByDevice = eventType, Id = Guid.NewGuid().ToString(), ResolvedAction = action, Location = location
     });
     return(true);
 }
        public static string DelayedActionToString(ResolvedAction action, DateTimeOffset dueTime, string beaconPid, BeaconEventType beaconEventType, Guid guid, string location)
        {
            string serializeObject = JsonConvert.SerializeObject(new SerializedAction()
            {
                Action = action, Time = dueTime, Beacon = beaconPid, Event = beaconEventType
            });

            return(DelayedActionToString(Convert.ToBase64String(Encoding.UTF8.GetBytes(serializeObject)), dueTime, false, guid.ToString(), location));
        }
Exemplo n.º 12
0
        public async Task <bool> SaveDelayedAction(ResolvedAction action, DateTimeOffset dueTime, string beaconPid, BeaconEventType eventType, string location)
        {
            StorageFolder folder = await GetFolder(Background?BackgroundActionsFolder : ForegroundActionsFolder, true);

            StorageFile file = await folder.CreateFileAsync(DelayedActionsFileName, CreationCollisionOption.OpenIfExists);

            string actionToString = FileStorageHelper.DelayedActionToString(action, dueTime, beaconPid, eventType, location);

            return(await RetryAppending(file, actionToString));
        }
Exemplo n.º 13
0
		public bool HelperToTestHelpers(string name, PreviewResponseActionArgs e, ResolvedAction[] actions)
		{
			if (CreateATempFilename(name).Length == 0)
				return false;
			if (CreateResponseForPreview(e, actions) == null)
				return false;
			if (CreateRequestForPreview(e.DocID) == null)
				return false;

			return true;
		}
Exemplo n.º 14
0
        public async ValueTask <IReadOnlyList <ProjectAction> > GetUninstallActionsAsync(
            string projectId,
            PackageIdentity packageIdentity,
            bool removeDependencies,
            bool forceRemove,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectId);
            Assumes.NotNull(packageIdentity);
            Assumes.False(packageIdentity.HasVersion);
            Assumes.NotNull(_state.SourceCacheContext);
            Assumes.NotNull(_state.ResolvedActions);
            Assumes.Null(_state.PackageIdentity);

            cancellationToken.ThrowIfCancellationRequested();

            return(await CatchAndRethrowExceptionAsync(async() =>
            {
                INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>();
                (bool success, NuGetProject? project) = await TryGetNuGetProjectMatchingProjectIdAsync(projectId);

                Assumes.True(success);
                Assumes.NotNull(project);

                var projectActions = new List <ProjectAction>();
                var uninstallationContext = new UninstallationContext(removeDependencies, forceRemove);

                NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken);
                IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUninstallPackageAsync(
                    project,
                    packageIdentity.Id,
                    uninstallationContext,
                    projectContext,
                    cancellationToken);

                foreach (NuGetProjectAction action in actions)
                {
                    var resolvedAction = new ResolvedAction(project, action);
                    var projectAction = new ProjectAction(
                        CreateProjectActionId(),
                        projectId,
                        action.PackageIdentity,
                        action.NuGetProjectActionType,
                        implicitActions: null);

                    _state.ResolvedActions[projectAction.Id] = resolvedAction;

                    projectActions.Add(projectAction);
                }

                return projectActions;
            }));
        }
Exemplo n.º 15
0
        public async Task EventHistory_FlushHistory()
        {
            var beacon = new Beacon();

            beacon.Id1       = "7367672374000000ffff0000ffff0007";
            beacon.Id2       = 8008;
            beacon.Id3       = 5;
            beacon.Timestamp = DateTimeOffset.Now;
            var args = new BeaconEventArgs();

            args.Beacon    = beacon;
            args.EventType = BeaconEventType.Exit;
            var resolvedActionEventArgs = new ResolvedActionsEventArgs()
            {
                BeaconPid = beacon.Pid, BeaconEventType = BeaconEventType.Enter
            };

            BeaconAction beaconaction1 = new BeaconAction()
            {
                Body = "body", Url = "http://www.com", Uuid = "1223"
            };
            BeaconAction beaconaction2 = new BeaconAction()
            {
                Body = "body", Url = "http://www.com", Uuid = "5678"
            };
            BeaconAction beaconaction3 = new BeaconAction()
            {
                Body = "body", Url = "http://www.com", Uuid = "9678"
            };
            ResolvedAction res1 = new ResolvedAction()
            {
                SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction1
            };
            ResolvedAction res2 = new ResolvedAction()
            {
                SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction2
            };
            ResolvedAction res3 = new ResolvedAction()
            {
                SuppressionTime = 1, SendOnlyOnce = true, BeaconAction = beaconaction3
            };

            EventHistory eventHistory = new EventHistory();

            await eventHistory.SaveBeaconEventAsync(args, null);

            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction1);

            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction3);

            await eventHistory.FlushHistoryAsync();
        }
Exemplo n.º 16
0
        public async Task <List <BeaconAction> > GetActionsForForeground(bool doNotDelete = false)
        {
            List <BeaconAction>  beaconActions  = new List <BeaconAction>();
            List <HistoryAction> historyActions = await Storage.GetActionsForForeground(doNotDelete);

            foreach (HistoryAction historyAction in historyActions)
            {
                ResolvedAction action = ServiceManager.LayoutManager.GetAction(historyAction.EventId);
                beaconActions.Add(action.BeaconAction);
            }

            return(beaconActions);
        }
Exemplo n.º 17
0
        public async ValueTask <IReadOnlyList <ProjectAction> > GetUninstallActionsAsync(
            IReadOnlyCollection <string> projectIds,
            PackageIdentity packageIdentity,
            bool removeDependencies,
            bool forceRemove,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectIds);
            Assumes.NotNull(packageIdentity);
            Assumes.False(packageIdentity.HasVersion);
            Assumes.NotNull(_state.SourceCacheContext);
            Assumes.Null(_state.PackageIdentity);
            Assumes.True(_state.ResolvedActions.Count == 0);

            cancellationToken.ThrowIfCancellationRequested();

            return(await CatchAndRethrowExceptionAsync(async() =>
            {
                INuGetProjectContext projectContext = await ServiceLocator.GetComponentModelServiceAsync <INuGetProjectContext>();
                IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken);

                var projectActions = new List <ProjectAction>();
                var uninstallationContext = new UninstallationContext(removeDependencies, forceRemove);

                NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken);
                IEnumerable <NuGetProjectAction> projectsWithActions = await packageManager.PreviewProjectsUninstallPackageAsync(
                    projects,
                    packageIdentity.Id,
                    uninstallationContext,
                    projectContext,
                    cancellationToken);

                foreach (NuGetProjectAction projectWithActions in projectsWithActions)
                {
                    var resolvedAction = new ResolvedAction(projectWithActions.Project, projectWithActions);
                    var projectAction = new ProjectAction(
                        CreateProjectActionId(),
                        projectWithActions.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId),
                        projectWithActions.PackageIdentity,
                        projectWithActions.NuGetProjectActionType,
                        implicitActions: null);

                    _state.ResolvedActions[projectAction.Id] = resolvedAction;

                    projectActions.Add(projectAction);
                }

                return projectActions;
            }));
        }
Exemplo n.º 18
0
        /// <summary>
        /// If supressionTime is set for the action, fuction will check from the history if the
        /// action is already presented during the supression time.
        /// </summary>
        /// <param name="resolvedAction"></param>
        /// <returns>True only if action should be supressed.</returns>
        public bool ShouldSupressAsync(ResolvedAction resolvedAction)
        {
            Logger.Trace("ShouldSupressAsync {0}", resolvedAction.BeaconAction.Id);
            bool retVal = false;

            if (resolvedAction.SuppressionTime > 0)
            {
                if (lastEvents.Values.ContainsKey(resolvedAction.BeaconAction.Uuid))
                {
                    if ((long)lastEvents.Values[resolvedAction.BeaconAction.Uuid] + resolvedAction.SuppressionTime * 1000 > DateTimeOffset.Now.ToUnixTimeMilliseconds())
                    {
                        retVal = true;
                    }
                }
                lastEvents.Values[resolvedAction.BeaconAction.Uuid] = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            }
            return(retVal);
        }
Exemplo n.º 19
0
        /// <summary>
        /// If sendOnlyOnce is true for resolved action, fuction will check from the history if the
        /// action is already presented for the user.
        /// </summary>
        /// <param name="resolvedAction"></param>
        /// <returns>True ,if action type is SendOnlyOnce, and it has been shown already. Otherwise false.</returns>
        public bool CheckSendOnlyOnceAsync(ResolvedAction resolvedAction)
        {
            Logger.Trace("CheckSendOnlyOnceAsync {0}", resolvedAction.BeaconAction.Id);

            if (resolvedAction.SendOnlyOnce)
            {
                if (firedActions.Values.ContainsKey(resolvedAction.BeaconAction.Uuid))
                {
                    return(true);
                }
                else
                {
                    firedActions.Values[resolvedAction.BeaconAction.Uuid] = true;
                    return(false);
                }
            }

            return(false);
        }
Exemplo n.º 20
0
        public static void PopulateResolvedActionCollection(PolicyResponseObject upi)
        {
            upi.ResolvedActionCollection = new Collection<IResolvedAction>();

            List<IPolicyResponseAction> policyResponseActionCollection = ProInquisitor.GetPolicyResponseActions(upi);

            if (policyResponseActionCollection == null)
                return;

            // if the action collection at this point contains a block action that isnt an exception handler
            // then all other actions will be superseded by it.
            // rally issue DE539
            // Have to iterate in order cause policyResponseActionCollection is ordered!
            IPolicyResponseAction blockingAction = null;
            for(int i = 0; i < policyResponseActionCollection.Count;i++)
            {
                PolicyResponseAction pra = policyResponseActionCollection[i] as PolicyResponseAction;

                Collection<IContentItem> contentItemCollection = ProInquisitor.GetContentItems(upi, pra);
                ResolvedAction resolvedAction = new ResolvedAction();
                resolvedAction.ResponseAction = pra;
                resolvedAction.ContentCollection = contentItemCollection;
                resolvedAction.PopulateContentItemsActionProperties();
                resolvedAction.Sequence = pra.Precedence;
                //if (pra.Action.Blocking && !pra.IsExceptionAction)
                //{
                //    blockingAction = pra;
                //}
                upi.ResolvedActionCollection.Add(resolvedAction);
            }

            if (blockingAction != null)
            {
                foreach (PolicyResponseAction pra in policyResponseActionCollection)
                {
                    if (pra != blockingAction)
                    {
                        pra.SupersededByAction = blockingAction;
                    }
                }
            }
        }
        public async Task EventHistory_ShouldSupress()
        {
            var beacon = new Beacon();
            beacon.Id1 = "7367672374000000ffff0000ffff0007";
            beacon.Id2 = 8008;
            beacon.Id3 = 5;
            beacon.Timestamp = DateTimeOffset.Now;
            var args = new BeaconEventArgs();
            args.Beacon = beacon;
            args.EventType = BeaconEventType.Exit;
            var resolvedActionEventArgs = new ResolvedActionsEventArgs() {BeaconPid = beacon.Pid, BeaconEventType = BeaconEventType.Enter};

            BeaconAction beaconaction1 = new BeaconAction() {Body = "body", Url = "http://www.com", Uuid = "1223"};
            BeaconAction beaconaction2 = new BeaconAction() {Body = "body", Url = "http://www.com", Uuid = "5678"};
            BeaconAction beaconaction3 = new BeaconAction() {Body = "body", Url = "http://www.com", Uuid = "9678"};
            ResolvedAction res1 = new ResolvedAction() {SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction1};
            ResolvedAction res2 = new ResolvedAction() {SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction2};
            ResolvedAction res3 = new ResolvedAction() {SuppressionTime = 1, SendOnlyOnce = true, BeaconAction = beaconaction3};

            EventHistory eventHistory = new EventHistory();

            await eventHistory.SaveBeaconEventAsync(args, null);
            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction1);
            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction3);

            eventHistory.ShouldSupressAsync(res1);
            eventHistory.ShouldSupressAsync(res3);

            await Task.Delay(2000);


            bool shouldSupress1 = eventHistory.ShouldSupressAsync(res1);
            bool shouldSupress2 = eventHistory.ShouldSupressAsync(res2);
            bool shouldSupress3 = eventHistory.ShouldSupressAsync(res3);

            Assert.IsTrue(shouldSupress1);
            Assert.IsFalse(shouldSupress2);
            Assert.IsFalse(shouldSupress3); //Supression time should be over
        }
Exemplo n.º 22
0
 private async Task <bool> SaveDelayedActionsRetry(ResolvedAction action, DateTimeOffset dueTime, string beaconPid, BeaconEventType eventTypeDetectedByDevice, string location, int retry)
 {
     if (retry < 0)
     {
         return(false);
     }
     try
     {
         if (await Storage.SaveDelayedAction(action, dueTime, beaconPid, eventTypeDetectedByDevice, location))
         {
             return(true);
         }
         return(await SaveDelayedActionsRetry(action, dueTime, beaconPid, eventTypeDetectedByDevice, location, --retry));
     }
     catch (UnauthorizedAccessException)
     {
         return(await SaveDelayedActionsRetry(action, dueTime, beaconPid, eventTypeDetectedByDevice, location, --retry));
     }
     catch (FileNotFoundException)
     {
         return(await SaveDelayedActionsRetry(action, dueTime, beaconPid, eventTypeDetectedByDevice, location, --retry));
     }
 }
Exemplo n.º 23
0
        public async ValueTask <IReadOnlyList <ProjectAction> > GetUpdateActionsAsync(
            IReadOnlyCollection <string> projectIds,
            IReadOnlyCollection <PackageIdentity> packageIdentities,
            VersionConstraints versionConstraints,
            bool includePrelease,
            DependencyBehavior dependencyBehavior,
            IReadOnlyList <string> packageSourceNames,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectIds);
            Assumes.NotNullOrEmpty(packageIdentities);
            Assumes.NotNullOrEmpty(packageSourceNames);
            Assumes.NotNull(_state.SourceCacheContext);
            Assumes.NotNull(_state.ResolvedActions);
            Assumes.Null(_state.PackageIdentity);

            return(await CatchAndRethrowExceptionAsync(async() =>
            {
                var primarySources = new List <SourceRepository>();
                var secondarySources = new List <SourceRepository>();

                IEnumerable <SourceRepository> sourceRepositories = _sharedState.SourceRepositoryProvider.GetRepositories();
                var packageSourceNamesSet = new HashSet <string>(packageSourceNames, StringComparer.OrdinalIgnoreCase);

                foreach (SourceRepository sourceRepository in sourceRepositories)
                {
                    if (packageSourceNamesSet.Contains(sourceRepository.PackageSource.Name))
                    {
                        primarySources.Add(sourceRepository);
                    }

                    if (sourceRepository.PackageSource.IsEnabled)
                    {
                        secondarySources.Add(sourceRepository);
                    }
                }

                INuGetProjectContext projectContext = await ServiceLocator.GetComponentModelServiceAsync <INuGetProjectContext>();
                IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken);

                var resolutionContext = new ResolutionContext(
                    dependencyBehavior,
                    includePrelease,
                    includeUnlisted: true,
                    versionConstraints,
                    new GatherCache(),
                    _state.SourceCacheContext);

                NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken);
                IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUpdatePackagesAsync(
                    packageIdentities.ToList(),
                    projects,
                    resolutionContext,
                    projectContext,
                    primarySources,
                    secondarySources,
                    cancellationToken);

                var projectActions = new List <ProjectAction>();

                foreach (NuGetProjectAction action in actions)
                {
                    var resolvedAction = new ResolvedAction(action.Project, action);
                    ProjectAction projectAction = CreateProjectAction(resolvedAction);

                    _state.ResolvedActions[projectAction.Id] = resolvedAction;

                    projectActions.Add(projectAction);
                }

                return projectActions;
            }));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Executes the given action, stores the event in event history and notifies the listeners.
        /// </summary>
        private async Task ExecuteActionAsync(ResolvedAction resolvedAction, string beaconPid, BeaconEventType beaconEventType, string location)
        {
            try
            {
                Logger.Debug("SDKEngine: ExecuteActionAsync " + beaconPid + " BeaconEventType: " + beaconEventType + " type: " + resolvedAction?.BeaconAction.Type);
                bool checkOnlyOnce = _eventHistory.CheckSendOnlyOnceAsync(resolvedAction);
                bool shouldSupress = _eventHistory.ShouldSupressAsync(resolvedAction);

                Logger.Trace("SDKEngine: ExecuteActionAsync " + beaconPid + " checkOnlyOnce: " + checkOnlyOnce + " shouldSupress:" + shouldSupress);
                if (!shouldSupress && !checkOnlyOnce && resolvedAction.IsInsideTimeframes(DateTimeOffset.Now))
                {
                    Logger.Trace("SDKEngine: ExecuteActionAsync " + beaconPid + " action resolved");
                    await _eventHistory.SaveExecutedResolvedActionAsync(resolvedAction.BeaconAction, beaconPid, beaconEventType, location);

                    if (resolvedAction.BeaconAction.Type != BeaconActionType.Silent)
                    {
                        BeaconActionResolved?.Invoke(this, resolvedAction.BeaconAction);
                    }
                }
                else
                {
                    Logger.Trace("SDKEngine: ExecuteActionAsync " + beaconPid + " action not resolved");
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error during ExecuteActionAsync", e);
            }
        }
Exemplo n.º 25
0
        public async ValueTask <IReadOnlyList <ProjectAction> > GetUpdateActionsAsync(
            IReadOnlyCollection <string> projectIds,
            IReadOnlyCollection <PackageIdentity> packageIdentities,
            VersionConstraints versionConstraints,
            bool includePrelease,
            DependencyBehavior dependencyBehavior,
            IReadOnlyList <string> packageSourceNames,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(projectIds);
            Assumes.NotNullOrEmpty(packageIdentities);
            Assumes.NotNullOrEmpty(packageSourceNames);
            Assumes.NotNull(_state.SourceCacheContext);
            Assumes.NotNull(_state.ResolvedActions);
            Assumes.Null(_state.PackageIdentity);

            var primarySources   = new List <SourceRepository>();
            var secondarySources = new List <SourceRepository>();

            ISourceRepositoryProvider sourceRepositoryProvider = await _sharedState.SourceRepositoryProvider.GetValueAsync(cancellationToken);

            IEnumerable <SourceRepository> sourceRepositories = sourceRepositoryProvider.GetRepositories();
            var packageSourceNamesSet = new HashSet <string>(packageSourceNames, StringComparer.OrdinalIgnoreCase);

            foreach (SourceRepository sourceRepository in sourceRepositories)
            {
                if (packageSourceNamesSet.Contains(sourceRepository.PackageSource.Name))
                {
                    primarySources.Add(sourceRepository);
                }

                if (sourceRepository.PackageSource.IsEnabled)
                {
                    secondarySources.Add(sourceRepository);
                }
            }

            INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>();

            var projects = new List <NuGetProject>();

            foreach (string projectId in projectIds)
            {
                (bool success, NuGetProject? project) = await TryGetNuGetProjectMatchingProjectIdAsync(projectId);

                Assumes.True(success);
                Assumes.NotNull(project);

                projects.Add(project);
            }

            var resolutionContext = new ResolutionContext(
                dependencyBehavior,
                includePrelease,
                includeUnlisted: true,
                versionConstraints,
                new GatherCache(),
                _state.SourceCacheContext);

            NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken);

            IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUpdatePackagesAsync(
                packageIdentities.ToList(),
                projects,
                resolutionContext,
                projectContext,
                primarySources,
                secondarySources,
                cancellationToken);

            var projectActions = new List <ProjectAction>();

            foreach (NuGetProjectAction action in actions)
            {
                string projectId      = action.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId);
                var    resolvedAction = new ResolvedAction(action.Project, action);
                var    projectAction  = new ProjectAction(
                    CreateProjectActionId(),
                    projectId,
                    action.PackageIdentity,
                    action.NuGetProjectActionType,
                    implicitActions: null);

                _state.ResolvedActions[projectAction.Id] = resolvedAction;

                projectActions.Add(projectAction);
            }

            return(projectActions);
        }
Exemplo n.º 26
0
        static bool ExecuteAction(ResolvedAction resolvedAction)
        {
            foreach (var actionProperty in resolvedAction.Action.ActionProperties)
            {
                if(String.Compare(actionProperty.Name, "EXECUTE", true) == 0)
                {
                    try
                    {
                        return Convert.ToBoolean(actionProperty.Value);
                    }
                    catch (FormatException)
                    {
                    }
                }
            }

            return false;
        }
        public async Task DeleayedActionTest()
        {
            ResolvedAction action = new ResolvedAction();

            action.BeaconAction         = new BeaconAction();
            action.BeaconAction.Body    = "body";
            action.BeaconAction.Id      = 1;
            action.BeaconAction.Payload = JsonObject.Parse("{\"pay\":\"load\"}");
            action.BeaconAction.Subject = "Subject";
            action.BeaconAction.Type    = BeaconActionType.InApp;
            action.BeaconAction.Url     = "http://sensorberg.com";
            action.BeaconAction.Uuid    = "uuid";
            action.Delay      = 123;
            action.BeaconPids = new List <string>()
            {
                "1", "2", "3", "4"
            };
            action.EventTypeDetectedByDevice = BeaconEventType.EnterExit;
            action.ReportImmediately         = true;
            action.SendOnlyOnce    = true;
            action.SuppressionTime = 321;
            action.Timeframes      = new List <Timeframe>()
            {
                new Timeframe()
                {
                    End = DateTimeOffset.Parse("2015-04-16T12:00:00.000+0000"), Start = DateTimeOffset.Parse("2015-04-15T12:00:00.000+0000")
                }
            };

            await storage.InitStorage();

            Assert.IsTrue(await storage.SaveDelayedAction(action, DateTimeOffset.Parse("2015-04-16T12:00:00.000+0000"), "1", BeaconEventType.Enter, "1"));

            IList <DelayedActionData> delayedActions = await storage.GetDelayedActions();

            Assert.AreEqual(1, delayedActions.Count, "to many actions found");

            DelayedActionData delayAction = delayedActions[0];

            Assert.AreEqual("1", delayAction.BeaconPid, "Not same beacon id");
            Assert.AreEqual(DateTimeOffset.Parse("2015-04-16T12:00:00.000+0000"), delayAction.DueTime, "not same delay time");
            Assert.AreEqual(BeaconEventType.Enter, delayAction.EventTypeDetectedByDevice, "not same event type");

            Assert.AreEqual(action.Delay, delayAction.ResolvedAction.Delay, "not same action delay");
            Assert.AreEqual(action.EventTypeDetectedByDevice, delayAction.ResolvedAction.EventTypeDetectedByDevice, "not same action event type");
            Assert.AreEqual(action.ReportImmediately, delayAction.ResolvedAction.ReportImmediately, "not same ReportImmediately");
            Assert.AreEqual(action.SendOnlyOnce, delayAction.ResolvedAction.SendOnlyOnce, "not same SendOnlyOnce");
            Assert.AreEqual(action.SuppressionTime, delayAction.ResolvedAction.SuppressionTime, "not same SendOnlyOnce");
            Assert.AreEqual(action.Timeframes.Count, delayAction.ResolvedAction.Timeframes.Count, "not same Timeframes count");
            Assert.AreEqual(action.Timeframes[0].Start, delayAction.ResolvedAction.Timeframes[0].Start, "not same Timeframes count");
            Assert.AreEqual(action.Timeframes[0].End, delayAction.ResolvedAction.Timeframes[0].End, "not same Timeframes count");

            Assert.AreEqual(action.BeaconPids.Count, delayAction.ResolvedAction.BeaconPids.Count, "not same beacon count");
            Assert.AreEqual(action.BeaconAction.Body, delayAction.ResolvedAction.BeaconAction.Body, "not same beacon action body");
            Assert.AreEqual(action.BeaconAction.Subject, delayAction.ResolvedAction.BeaconAction.Subject, "not same beacon action Subject");
            Assert.AreEqual(action.BeaconAction.Id, delayAction.ResolvedAction.BeaconAction.Id, "not same beacon action Id");
            Assert.AreEqual(action.BeaconAction.Type, delayAction.ResolvedAction.BeaconAction.Type, "not same beacon action Type");
            Assert.AreEqual(action.BeaconAction.Uuid, delayAction.ResolvedAction.BeaconAction.Uuid, "not same beacon action Uuid");
            Assert.AreEqual(action.BeaconAction.Payload.ToString(), delayAction.ResolvedAction.BeaconAction.Payload.ToString(), "not same beacon action Payload");


            Assert.AreEqual(action, delayAction.ResolvedAction, "not same action");



            ResolvedAction action2 = new ResolvedAction();

            action2.BeaconAction         = new BeaconAction();
            action2.BeaconAction.Body    = "body2";
            action2.BeaconAction.Id      = 2;
            action2.BeaconAction.Payload = JsonObject.Parse("{\"pay\":\"load2\"}");
            action2.BeaconAction.Subject = "Subject2";
            action2.BeaconAction.Type    = BeaconActionType.UrlMessage;
            action2.BeaconAction.Url     = "http://sensorberg.com";
            action2.BeaconAction.Uuid    = "uuid2";
            action2.Delay      = 1234;
            action2.BeaconPids = new List <string>()
            {
                "1", "2", "3", "4", "5"
            };
            action2.EventTypeDetectedByDevice = BeaconEventType.EnterExit;
            action2.ReportImmediately         = false;
            action2.SendOnlyOnce    = false;
            action2.SuppressionTime = 3210;
            action2.Timeframes      = new List <Timeframe>()
            {
                new Timeframe()
                {
                    End = DateTimeOffset.Parse("2016-04-16T12:00:00.000+0000"), Start = DateTimeOffset.Parse("2014-04-15T12:00:00.000+0000")
                }
            };

            Assert.IsTrue(await storage.SaveDelayedAction(action, DateTimeOffset.Parse("2015-05-16T12:00:00.000+0000"), "2", BeaconEventType.EnterExit, null));


            delayedActions = await storage.GetDelayedActions();

            Assert.AreEqual(2, delayedActions.Count, "to many actions found");

            delayAction = delayedActions.FirstOrDefault(d => d.BeaconPid == "1");
            string idToDelete = delayAction.Id;

            Assert.AreEqual("1", delayAction.BeaconPid, "Not same beacon id");
            Assert.AreEqual(DateTimeOffset.Parse("2015-04-16T12:00:00.000+0000"), delayAction.DueTime, "not same delay time");
            Assert.AreEqual(BeaconEventType.Enter, delayAction.EventTypeDetectedByDevice, "not same event type");

            Assert.AreEqual(action.Delay, delayAction.ResolvedAction.Delay, "not same action delay");
            Assert.AreEqual(action.EventTypeDetectedByDevice, delayAction.ResolvedAction.EventTypeDetectedByDevice, "not same action event type");
            Assert.AreEqual(action.ReportImmediately, delayAction.ResolvedAction.ReportImmediately, "not same ReportImmediately");
            Assert.AreEqual(action.SendOnlyOnce, delayAction.ResolvedAction.SendOnlyOnce, "not same SendOnlyOnce");
            Assert.AreEqual(action.SuppressionTime, delayAction.ResolvedAction.SuppressionTime, "not same SendOnlyOnce");
            Assert.AreEqual(action.Timeframes.Count, delayAction.ResolvedAction.Timeframes.Count, "not same Timeframes count");
            Assert.AreEqual(action.Timeframes[0].Start, delayAction.ResolvedAction.Timeframes[0].Start, "not same Timeframes count");
            Assert.AreEqual(action.Timeframes[0].End, delayAction.ResolvedAction.Timeframes[0].End, "not same Timeframes count");

            Assert.AreEqual(action.BeaconPids.Count, delayAction.ResolvedAction.BeaconPids.Count, "not same beacon count");
            Assert.AreEqual(action.BeaconAction.Body, delayAction.ResolvedAction.BeaconAction.Body, "not same beacon action body");
            Assert.AreEqual(action.BeaconAction.Subject, delayAction.ResolvedAction.BeaconAction.Subject, "not same beacon action Subject");
            Assert.AreEqual(action.BeaconAction.Id, delayAction.ResolvedAction.BeaconAction.Id, "not same beacon action Id");
            Assert.AreEqual(action.BeaconAction.Type, delayAction.ResolvedAction.BeaconAction.Type, "not same beacon action Type");
            Assert.AreEqual(action.BeaconAction.Uuid, delayAction.ResolvedAction.BeaconAction.Uuid, "not same beacon action Uuid");
            Assert.AreEqual(action.BeaconAction.Payload.ToString(), delayAction.ResolvedAction.BeaconAction.Payload.ToString(), "not same beacon action Payload");


            Assert.AreEqual(action, delayAction.ResolvedAction, "not same action");



            delayAction = delayedActions.FirstOrDefault(d => d.BeaconPid == "2");
            Assert.AreEqual("2", delayAction.BeaconPid, "Not same beacon id");
            Assert.AreEqual(DateTimeOffset.Parse("2015-05-16T12:00:00.000+0000"), delayAction.DueTime, "not same delay time");
            Assert.AreEqual(BeaconEventType.EnterExit, delayAction.EventTypeDetectedByDevice, "not same event type");

            Assert.AreEqual(action.Delay, delayAction.ResolvedAction.Delay, "not same action delay");
            Assert.AreEqual(action.EventTypeDetectedByDevice, delayAction.ResolvedAction.EventTypeDetectedByDevice, "not same action event type");
            Assert.AreEqual(action.ReportImmediately, delayAction.ResolvedAction.ReportImmediately, "not same ReportImmediately");
            Assert.AreEqual(action.SendOnlyOnce, delayAction.ResolvedAction.SendOnlyOnce, "not same SendOnlyOnce");
            Assert.AreEqual(action.SuppressionTime, delayAction.ResolvedAction.SuppressionTime, "not same SendOnlyOnce");
            Assert.AreEqual(action.Timeframes.Count, delayAction.ResolvedAction.Timeframes.Count, "not same Timeframes count");
            Assert.AreEqual(action.Timeframes[0].Start, delayAction.ResolvedAction.Timeframes[0].Start, "not same Timeframes count");
            Assert.AreEqual(action.Timeframes[0].End, delayAction.ResolvedAction.Timeframes[0].End, "not same Timeframes count");

            Assert.AreEqual(action.BeaconPids.Count, delayAction.ResolvedAction.BeaconPids.Count, "not same beacon count");
            Assert.AreEqual(action.BeaconAction.Body, delayAction.ResolvedAction.BeaconAction.Body, "not same beacon action body");
            Assert.AreEqual(action.BeaconAction.Subject, delayAction.ResolvedAction.BeaconAction.Subject, "not same beacon action Subject");
            Assert.AreEqual(action.BeaconAction.Id, delayAction.ResolvedAction.BeaconAction.Id, "not same beacon action Id");
            Assert.AreEqual(action.BeaconAction.Type, delayAction.ResolvedAction.BeaconAction.Type, "not same beacon action Type");
            Assert.AreEqual(action.BeaconAction.Uuid, delayAction.ResolvedAction.BeaconAction.Uuid, "not same beacon action Uuid");
            Assert.AreEqual(action.BeaconAction.Payload.ToString(), delayAction.ResolvedAction.BeaconAction.Payload.ToString(), "not same beacon action Payload");


            Assert.AreEqual(action, delayAction.ResolvedAction, "not same action");


            await storage.SetDelayedActionAsExecuted(idToDelete);

            delayedActions = await storage.GetDelayedActions();

            Assert.AreEqual(1, delayedActions.Count, "to many actions found after executing action");

            Assert.AreEqual("2", delayedActions[0].BeaconPid, "Not same beacon id");
        }
Exemplo n.º 28
0
        public async Task EventHistory_ShouldSupress()
        {
            var beacon = new Beacon();

            beacon.Id1       = "7367672374000000ffff0000ffff0007";
            beacon.Id2       = 8008;
            beacon.Id3       = 5;
            beacon.Timestamp = DateTimeOffset.Now;
            var args = new BeaconEventArgs();

            args.Beacon    = beacon;
            args.EventType = BeaconEventType.Exit;
            var resolvedActionEventArgs = new ResolvedActionsEventArgs()
            {
                BeaconPid = beacon.Pid, BeaconEventType = BeaconEventType.Enter
            };

            BeaconAction beaconaction1 = new BeaconAction()
            {
                Body = "body", Url = "http://www.com", Uuid = "1223"
            };
            BeaconAction beaconaction2 = new BeaconAction()
            {
                Body = "body", Url = "http://www.com", Uuid = "5678"
            };
            BeaconAction beaconaction3 = new BeaconAction()
            {
                Body = "body", Url = "http://www.com", Uuid = "9678"
            };
            ResolvedAction res1 = new ResolvedAction()
            {
                SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction1
            };
            ResolvedAction res2 = new ResolvedAction()
            {
                SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction2
            };
            ResolvedAction res3 = new ResolvedAction()
            {
                SuppressionTime = 1, SendOnlyOnce = true, BeaconAction = beaconaction3
            };

            EventHistory eventHistory = new EventHistory();

            await eventHistory.SaveBeaconEventAsync(args, null);

            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction1);

            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction3);

            eventHistory.ShouldSupressAsync(res1);
            eventHistory.ShouldSupressAsync(res3);

            await Task.Delay(2000);


            bool shouldSupress1 = eventHistory.ShouldSupressAsync(res1);
            bool shouldSupress2 = eventHistory.ShouldSupressAsync(res2);
            bool shouldSupress3 = eventHistory.ShouldSupressAsync(res3);

            Assert.IsTrue(shouldSupress1);
            Assert.IsFalse(shouldSupress2);
            Assert.IsFalse(shouldSupress3); //Supression time should be over
        }
Exemplo n.º 29
0
		protected void DoActions(ResolvedAction pdfAction, ResolvedAction cleanAction, PreviewResponseActionArgs e)
		{
			Request request = CreateRequestForPreview(e.DocID);
			if (request.Attachments == null)
			{
				string msg = Resources.PREVIEW_ERROR_MESSAGE;
				string title = Resources.PREVIEW_ERROR_TITLE;
				MessageBox.Show(msg, title, MessageBoxButtons.OK);
				return;
			}

			List<ResolvedAction> lActions = new List<ResolvedAction>();
			if (cleanAction != null)
				lActions.Add(cleanAction);
			if (pdfAction != null)
				lActions.Add(pdfAction);
			Response response = CreateResponseForPreview(e, lActions.ToArray());

			IProgressCallback callback = new PreviewActionProgressCallback(m_uiManager, lActions.Count);
			EnforceResponse enforceResponse = CallEnforcerForPreview(callback, request, response);

            if (HasErrors(enforceResponse.Properties))
            {
                string message = TidyErrorMessage(enforceResponse.Properties);
                WsMessage.ShowMessage(IntPtr.Zero, message, MessageButtons.WsOK, MessageBranding.WsProtect, MessageType.WsErrorIcon, Resources.CleaningError, -1);
                return;
            }
            
			Attachment attachment = null;
			foreach (Attachment a in enforceResponse.ModifiedRequest.Attachments)
			{
				if (a.Id == e.DocID)
				{
					attachment = a;
					break;
				}
			}

			ViewDoc(attachment);
		}
Exemplo n.º 30
0
        public static string NativeName(this ResolvedAction action)
        {
            var tag = PahkatApp.Current.Settings.GetLanguage() ?? "en";

            return(action.Name.Get(tag) ?? action.Name.Get("en") ?? action.Action.PackageKey.Id);
        }
Exemplo n.º 31
0
 public async Task <bool> SaveDelayedAction(ResolvedAction action, DateTimeOffset dueTime, string beaconPid, BeaconEventType eventType, string location)
 {
     return(await SaveDelayedActionsRetry(action, dueTime, beaconPid, eventType, location, MaxRetries));
 }
        public static void ValidateMockLayout(Layout layout)
        {
            Assert.IsNotNull(layout, "No Layout avialable");
            Assert.AreEqual(5, layout.AccountBeaconId1S.Count, "Number of proximity beacons not matching");
            Assert.IsTrue(layout.AccountBeaconId1S.Contains("7367672374000000ffff0000ffff0003"), "Beacon 1 not found");
            Assert.IsTrue(layout.AccountBeaconId1S.Contains("7367672374000000ffff0000ffff0006"), "Beacon 2 not found");
            Assert.IsTrue(layout.AccountBeaconId1S.Contains("7367672374000000ffff0000ffff0004"), "Beacon 3 not found");
            Assert.IsTrue(layout.AccountBeaconId1S.Contains("7367672374000000ffff0000ffff0007"), "Beacon 4 not found");
            Assert.AreEqual(9, layout.ResolvedActions.Count, "not 9 actions");

            ResolvedAction a = layout.ResolvedActions.FirstOrDefault(t => t.BeaconAction.Uuid == "9ded63644e424d758b0218f7c70f2473");

            Assert.AreEqual(3, (int)a.EventTypeDetectedByDevice, "beacon 1 - Wrong trigger type");
            Assert.AreEqual(2, a.BeaconPids.Count, "beacon 1 - Beacon count wrong");
            Assert.IsTrue(a.BeaconPids.Contains("7367672374000000ffff0000ffff00043917830929"), "beacon 1 - No Beacon found!");

            Assert.AreEqual(43200, a.SuppressionTime, "beacon 1 - Wrong supression time!");
            Assert.AreEqual(0, a.Delay, "beacon 1 - Different delay is set");

            Assert.AreEqual(string.Empty, a.BeaconAction.Subject, "beacon 1 - Different action subject");
            Assert.AreEqual(string.Empty, a.BeaconAction.Body, "beacon 1 - Different action body");
            Assert.AreEqual("http://www.visitfinland.com/", a.BeaconAction.Url, "beacon 1 - wrong url is set");
            Assert.IsNull(a.BeaconAction.Payload, "beacon 1 - Payload is not null");

            Assert.AreEqual(1, a.Timeframes.Count, "beacon 1 - More timeframes are set");
            Assert.AreEqual(new DateTimeOffset(2015, 04, 16, 12, 46, 19, 627, new TimeSpan()), a.Timeframes[0].Start.Value.DateTime, "beacon 1 - Different timesetting");

            Assert.AreEqual(3, (int)a.BeaconAction.Type, "beacon 1 - Different type");
            Assert.IsFalse(a.SendOnlyOnce, "beacon 1 - Send only once is set");


            a = layout.ResolvedActions.FirstOrDefault(t => t.BeaconAction.Uuid == "3f30be2605524f82a9bf0ccb4a81618f");
            Assert.AreEqual(1, (int)a.EventTypeDetectedByDevice, "beacon 2 - Wrong trigger type");
            Assert.AreEqual(1, a.BeaconPids.Count, "beacon 2 - Beacon count wrong");
            Assert.IsTrue(a.BeaconPids.Contains("7367672374000000ffff0000ffff00034886921321"), "beacon 2 - No Beacon found!");

            Assert.AreEqual(900, a.SuppressionTime, "beacon 2 - Wrong supression time!");
            Assert.AreEqual(0, a.Delay, "beacon 2 - Different delay is set");

            Assert.AreEqual(string.Empty, a.BeaconAction.Subject, "beacon 2 - Different action subject");
            Assert.AreEqual(string.Empty, a.BeaconAction.Body, "beacon 2 - Different action body");
            Assert.AreEqual("http://www.visitfinland.com/", a.BeaconAction.Url, "beacon 2 - wrong url is set");
            Assert.IsNull(a.BeaconAction.Payload, "beacon 2 - Payload is not null");

            Assert.AreEqual(1, a.Timeframes.Count, "beacon 2 - More timeframes are set");
            Assert.AreEqual(new DateTimeOffset(2015, 04, 16, 12, 33, 48, 627, new TimeSpan()), a.Timeframes[0].Start.Value.DateTime, "beacon 2 - Different timesetting");

            Assert.AreEqual(3, (int)a.BeaconAction.Type, "beacon 2 - Different type");
            Assert.IsFalse(a.SendOnlyOnce, "beacon 2 - Send only once is set");


            a = layout.ResolvedActions.FirstOrDefault(t => t.BeaconAction.Uuid == "312a8594e07542bd814ecdd17f76538e");
            Assert.AreEqual(1, (int)a.EventTypeDetectedByDevice, "beacon 3 - Wrong trigger type");
            Assert.AreEqual(1, a.BeaconPids.Count, "beacon 3 - Beacon count wrong");
            Assert.IsTrue(a.BeaconPids.Contains("7367672374000000ffff0000ffff00034886921321"), "beacon 3 - No Beacon found!");

            Assert.AreEqual(900, a.SuppressionTime, "beacon 3 - Wrong supression time!");
            Assert.AreEqual(0, a.Delay, "beacon 3 - Different delay is set");

            Assert.AreEqual(string.Empty, a.BeaconAction.Subject, "beacon 3 - Different action subject");
            Assert.AreEqual(string.Empty, a.BeaconAction.Body, "beacon 3 - Different action body");
            Assert.AreEqual("http://www.visitfinland.com/", a.BeaconAction.Url, "beacon 3 - wrong url is set");
            Assert.IsNull(a.BeaconAction.Payload, "beacon 3 - Payload is not null");

            Assert.AreEqual(1, a.Timeframes.Count, "beacon 3 - More timeframes are set");
            Assert.AreEqual(new DateTimeOffset(2015, 04, 16, 12, 34, 22, 596, new TimeSpan()), a.Timeframes[0].Start.Value.DateTime, "beacon 3 - Different timesetting");

            Assert.AreEqual(3, (int)a.BeaconAction.Type, "beacon 3 - Different type");
            Assert.IsFalse(a.SendOnlyOnce, "beacon 3 - Send only once is set");


            a = layout.ResolvedActions.FirstOrDefault(t => t.BeaconAction.Uuid == "959ea393e3424ab7ad53584a8b789197");
            Assert.AreEqual(1, (int)a.EventTypeDetectedByDevice, "beacon 4 - Wrong trigger type");
            Assert.AreEqual(1, a.BeaconPids.Count, "beacon 4 - Beacon count wrong");
            Assert.IsTrue(a.BeaconPids.Contains("7367672374000000ffff0000ffff00034895330988"), "beacon 4 - No Beacon found!");

            Assert.AreEqual(900, a.SuppressionTime, "beacon 4 - Wrong supression time!");
            Assert.AreEqual(60, a.Delay, "beacon 4 - Different delay is set");

            Assert.AreEqual("Delay 1 minute", a.BeaconAction.Subject, "beacon 4 - Different action subject");
            Assert.AreEqual("Delay 1 minute", a.BeaconAction.Body, "beacon 4 - Different action body");
            Assert.AreEqual("http://www.microsoft.com", a.BeaconAction.Url, "beacon 4 - wrong url is set");
            Assert.IsNull(a.BeaconAction.Payload, "beacon 4 - Payload is not null");

            Assert.AreEqual(1, a.Timeframes.Count, "beacon 4 - More timeframes are set");
            Assert.AreEqual(new DateTimeOffset(2015, 04, 30, 08, 05, 54, 432, new TimeSpan()), a.Timeframes[0].Start.Value.DateTime, "beacon 4 - Different timesetting");

            Assert.AreEqual(1, (int)a.BeaconAction.Type, "beacon 4 - Different type");
            Assert.IsFalse(a.SendOnlyOnce, "beacon 4 - Send only once is set");


            a = layout.ResolvedActions.FirstOrDefault(t => t.BeaconAction.Uuid == "351fd4b8b1c34da6b827e53acd79ff17");
            Assert.AreEqual(1, (int)a.EventTypeDetectedByDevice, "beacon 5 - Wrong trigger type");
            Assert.AreEqual(1, a.BeaconPids.Count, "beacon 5 - Beacon count wrong");
            Assert.IsTrue(a.BeaconPids.Contains("7367672374000000ffff0000ffff00034886921321"), "beacon 5 - No Beacon found!");

            Assert.AreEqual(900, a.SuppressionTime, "beacon 5 - Wrong supression time!");
            Assert.AreEqual(0, a.Delay, "beacon 5 - Different delay is set");

            Assert.AreEqual(string.Empty, a.BeaconAction.Subject, "beacon 5 - Different action subject");
            Assert.AreEqual(string.Empty, a.BeaconAction.Body, "beacon 5 - Different action body");
            Assert.AreEqual("http://www.visitfinland.com/", a.BeaconAction.Url, "beacon 5 - wrong url is set");
            Assert.IsNull(a.BeaconAction.Payload, "beacon 5 - Payload is not null");

            Assert.AreEqual(1, a.Timeframes.Count, "beacon 5 - More timeframes are set");
            Assert.AreEqual(new DateTimeOffset(2015, 04, 16, 12, 33, 28, 264, new TimeSpan()), a.Timeframes[0].Start.Value.DateTime, "beacon 5 - Different timesetting");

            Assert.AreEqual(3, (int)a.BeaconAction.Type, "beacon 5 - Different type");
            Assert.IsFalse(a.SendOnlyOnce, "beacon 5 - Send only once is set");


            a = layout.ResolvedActions.FirstOrDefault(t => t.BeaconAction.Uuid == "a5009f851ded4ce68d9b1b4ff6db6137");
            Assert.AreEqual(1, (int)a.EventTypeDetectedByDevice, "beacon 7- Wrong trigger type");
            Assert.AreEqual(1, a.BeaconPids.Count, "beacon 7 - Beacon count wrong");
            Assert.IsTrue(a.BeaconPids.Contains("7367672374000000ffff0000ffff00073918758763"), "beacon 7 - No Beacon found!");

            Assert.AreEqual(31536000, a.SuppressionTime, "beacon 7 - Wrong supression time!");
            Assert.AreEqual(0, a.Delay, "beacon 7 - Different delay is set");

            Assert.AreEqual("You´re in the year 2017!", a.BeaconAction.Subject, "beacon 7 - Different action subject");
            Assert.AreEqual("It´s a great year", a.BeaconAction.Body, "beacon 7 - Different action body");
            Assert.AreEqual("http://www.visitfinland.com/", a.BeaconAction.Url, "beacon 7 - wrong url is set");
            Assert.IsNull(a.BeaconAction.Payload, "beacon 7 - Payload is not null");

            Assert.AreEqual(1, a.Timeframes.Count, "beacon 7 - More timeframes are set");
            Assert.AreEqual(new DateTimeOffset(2016, 12, 31, 11, 00, 00, 00, new TimeSpan()), a.Timeframes[0].Start.Value.DateTime, "beacon 7 - Different timesetting");
            Assert.AreEqual(new DateTimeOffset(2017, 12, 31, 11, 00, 00, 00, new TimeSpan()), a.Timeframes[0].End.Value.DateTime, "beacon 7 - Different timesetting");

            Assert.AreEqual(1, (int)a.BeaconAction.Type, "beacon 7 - Different type");
            Assert.IsFalse(a.SendOnlyOnce, "beacon 7 - Send only once is set");


            a = layout.ResolvedActions.FirstOrDefault(t => t.BeaconAction.Uuid == "4224871362624826b510141da0d4fc5d");
            Assert.AreEqual(1, (int)a.EventTypeDetectedByDevice, "beacon 8- Wrong trigger type");
            Assert.AreEqual(1, a.BeaconPids.Count, "beacon 8 - Beacon count wrong");
            Assert.IsTrue(a.BeaconPids.Contains("7367672374000000ffff0000ffff00062343028018"), "beacon 8 - No Beacon found!");

            Assert.AreEqual(-1, a.SuppressionTime, "beacon 8 - Wrong supression time!");
            Assert.AreEqual(0, a.Delay, "beacon 8 - Different delay is set");

            Assert.AreEqual(string.Empty, a.BeaconAction.Subject, "beacon 8 - Different action subject");
            Assert.AreEqual(string.Empty, a.BeaconAction.Body, "beacon 8 - Different action body");
            Assert.AreEqual("payload://is.awesome", a.BeaconAction.Url, "beacon 8 - wrong url is set");
            Assert.IsNotNull(a.BeaconAction.Payload, "beacon 8 - Payload is null");
            Assert.AreEqual(a.BeaconAction.Payload.ToString(), JsonObject.Parse("{\"payload\":\"is\",\"awesome\":true}").ToString());

            Assert.AreEqual(1, a.Timeframes.Count, "beacon 8 - More timeframes are set");
            Assert.AreEqual(new DateTimeOffset(2015, 04, 16, 12, 48, 51, 828, new TimeSpan()), a.Timeframes[0].Start.Value.DateTime, "beacon 8 - Different timesetting");

            Assert.AreEqual(3, (int)a.BeaconAction.Type, "beacon 8 - Different type");
            Assert.IsFalse(a.SendOnlyOnce, "beacon 8 - Send only once is set");
        }
Exemplo n.º 33
0
		public UIAction(ResolvedAction resolvedAction)
			: base()
		{
			m_resolvedAction = resolvedAction;
			m_contentItems = new Dictionary<string, UIContentItem>();
		}
Exemplo n.º 34
0
        public void SetupPro()
        {    
            pro = new PolicyResponseObject();

            pro.ContentCollection = new Collection<IContentItem>();

            ContentItem ci = new ContentItem();
            ci.Name = "ContentItem1";
            pro.ContentCollection.Add(ci);

            PolicySetResponse setA = new PolicySetResponse("setA");
            PolicySetResponse setB = new PolicySetResponse("setB");

            ((ContentItem)pro.ContentCollection[0]).PolicySetCollection = new Collection<IPolicySetResponse>();
            pro.ContentCollection[0].PolicySetCollection.Add(setA);
            pro.ContentCollection[0].PolicySetCollection.Add(setB);

            PolicyResponse policyW = new PolicyResponse();
            policyW.Triggered = true;
            PolicyResponse policyX = new PolicyResponse();
            policyX.Triggered = true;
            PolicyResponse policyY = new PolicyResponse();
            policyY.Triggered = true;
            PolicyResponse policyZ = new PolicyResponse();
            policyZ.Triggered = true;

            setA.PolicyReportCollection = new Collection<IPolicyResponse>();
            setA.PolicyReportCollection.Add(policyW);
            setA.PolicyReportCollection.Add(policyX);

            setB.PolicyReportCollection = new Collection<IPolicyResponse>();
            setB.PolicyReportCollection.Add(policyY);
            setB.PolicyReportCollection.Add(policyZ);

            policyW.ActionCollection = new Collection<IPolicyResponseAction>();
            policyW.ActionCollection.Add(new PolicyResponseAction());
            policyX.ActionCollection = new Collection<IPolicyResponseAction>();
            policyX.ActionCollection.Add(new PolicyResponseAction());

            ((PolicyResponseAction)policyW.ActionCollection[0]).Type = ((PolicyResponseAction)policyX.ActionCollection[0]).Type = "1stTypeOfAction";
            
            policyY.ActionCollection = new Collection<IPolicyResponseAction>();
            policyY.ActionCollection.Add(new PolicyResponseAction());
            policyZ.ActionCollection = new Collection<IPolicyResponseAction>();
            policyZ.ActionCollection.Add(new PolicyResponseAction());

            ((PolicyResponseAction)policyY.ActionCollection[0]).Type = ((PolicyResponseAction)policyZ.ActionCollection[0]).Type = "2ndTypeOfAction";

            //Wire up the resolved actions... one of each type.
            ResolvedAction action1 = new ResolvedAction();
            action1.ResponseAction = policyW.ActionCollection[0];

            ResolvedAction action2 = new ResolvedAction();
            action2.ResponseAction = policyY.ActionCollection[0];

            pro.ResolvedActionCollection = new Collection<IResolvedAction>();
            pro.ResolvedActionCollection.Add(action1);
            pro.ResolvedActionCollection.Add(action2);

            //This bit mimics what happens in action resolution - each resolved actions has a list of which content items it will act on.
            action1.ContentCollection = new Collection<IContentItem>();
            action1.ContentCollection.Add(ci);

            action2.ContentCollection = new Collection<IContentItem>();
            action2.ContentCollection.Add(ci);
        }
Exemplo n.º 35
0
		protected Response CreateResponseForPreview(PreviewResponseActionArgs e, ResolvedAction[] actions)
		{
			Response response = new Response();
			response.Contents = new ContentItem[2] { new ContentItem(), new ContentItem() };
			bool foundItem0 = false, foundItem1 = false;
			foreach (ContentItem item in e.UIResponse.Response.Contents)
			{
				if (item.Name == m_emailContentName)
				{
					response.Contents[0] = item;
					foundItem0 = true;
				}
				else if (item.Id == e.DocID)
				{
					response.Contents[1] = item;
					foundItem1 = true;
				}
				if (foundItem0 && foundItem1)
				{
					break;
				}
			}
			response.PolicyType = e.UIResponse.Response.PolicyType;
			response.Properties = e.UIResponse.Response.Properties;
			response.ResolvedActions = actions;
			response.ResponseDate = e.UIResponse.Response.ResponseDate;
			response.Routing = e.UIResponse.Response.Routing;
			return response;
		}
 public static string DelayedActionToString(ResolvedAction action, DateTimeOffset dueTime, string beaconPid, BeaconEventType beaconEventType, string location)
 {
     return(DelayedActionToString(action, dueTime, beaconPid, beaconEventType, Guid.NewGuid(), location));
 }