Exemple #1
0
 void OnMouseOver()
 {
     if (Input.GetMouseButtonUp(0))
     {
         InteractionComponent.OnUserClick();
     }
 }
    void OnMouseOver()
    {
        ////if player right-clicks on the tile, toggle passable variable and change the color accordingly
        //if (Input.GetMouseButtonUp(1))
        //{
        //    if (this == GridManager.instance.destTileTB ||
        //        this == GridManager.instance.originTileTB)
        //        return;
        //    tile.Passable = !tile.Passable;
        //    if (!tile.Passable)
        //        changeColor(Color.gray);
        //    else
        //        changeColor(orange);

        //    GridManager.instance.generateAndShowPath();
        //}
        //if user left-clicks the tile
        if (Input.GetMouseButtonUp(0))
        {
            InteractionComponent.UserEndDragOnTile();
        }

        if (Input.GetMouseButtonDown(0))
        {
            InteractionComponent.UserStartDragOnTile();
        }
    }
Exemple #3
0
 void OnTriggerExit2D()
 {
     if (interaction)
     {
         interaction.RemoveInteractable(this.gameObject);
         interaction = null;
     }
 }
Exemple #4
0
 /// <summary>
 /// Creates a new <see cref="MonsterEntity"/> instance.
 /// </summary>
 /// <param name="context"></param>
 public MonsterEntity()
 {
     Moves       = new MovableComponent();
     Timers      = new TimerComponent();
     Follow      = new FollowComponent();
     Interaction = new InteractionComponent();
     Battle      = new BattleComponent();
     Attributes  = new AttributeComponent();
 }
Exemple #5
0
        // ------------------------------------------------------------------------
        // ------------------------------------------------------------------------
        public InteractionComponent CreateChoiceStatement(string choiceID, string choiceDescription)
        {
            InteractionComponent choice = new InteractionComponent();

            choice.id          = choiceID;
            choice.description = new LanguageMap();
            choice.description.Add("en-US", choiceDescription);

            return(choice);
        }
Exemple #6
0
 /// <summary>
 /// Creates a new <see cref="NpcEntity"/> instance.
 /// </summary>
 /// <param name="context"></param>
 public NpcEntity()
 {
     Object.Type = WorldObjectType.Mover;
     Timers      = new TimerComponent();
     Interaction = new InteractionComponent();
     Battle      = new BattleComponent();
     Attributes  = new AttributeComponent();
     Moves       = new MovableComponent();
     Follow      = new FollowComponent();
 }
Exemple #7
0
        /// <summary>
        /// Generates the receipt.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        protected InteractionComponent GenerateReceipt(RockContext rockContext)
        {
            var interactionService = new InteractionService(rockContext);
            var receipt            = new InteractionComponent();

            new InteractionComponentService(rockContext).Add(receipt);

            receipt.ChannelId        = InteractionChannelCache.Get(com.shepherdchurch.CubeDown.SystemGuid.InteractionChannel.CUBE_DOWN_RECEIPTS.AsGuid()).Id;
            receipt.Name             = "Temporary Receipt";
            receipt.ComponentSummary = string.Format("Total {0:c}", Cart.Total);

            if (Customer != null)
            {
                receipt.EntityId = Customer.PrimaryAliasId;
            }

            foreach (var item in Cart.Items)
            {
                var interaction = new Interaction
                {
                    EntityId            = null,
                    Operation           = "Buy",
                    InteractionDateTime = RockDateTime.Now,
                    InteractionData     = item.ToJson()
                };

                if (item.Quantity == 1)
                {
                    interaction.InteractionSummary = item.Name;
                }
                else
                {
                    interaction.InteractionSummary = string.Format("{0} (qty {1})", item.Name, item.Quantity);
                }

                interactionService.Add(interaction);
            }

            rockContext.SaveChanges();

            receipt = new InteractionComponentService(rockContext).Get(receipt.Id);

            var receiptCode = ReceiptHelper.EncodeReceiptCode(receipt);

            Cart.ReceiptCode = receiptCode;

            receipt.Name          = string.Format("Receipt #{0}", receiptCode);
            receipt.ComponentData = Cart.ToJson();

            rockContext.SaveChanges();


            return(receipt);
        }
Exemple #8
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (bCloseInteraction)
     {
         interaction = col.GetComponent <InteractionComponent>();
         if (interaction)
         {
             interaction.AddInteractable(this.gameObject);
         }
     }
 }
Exemple #9
0
        /// <summary>
        /// Returns breadcrumbs specific to the block that should be added to navigation
        /// based on the current page reference.  This function is called during the page's
        /// oninit to load any initial breadcrumbs.
        /// </summary>
        /// <param name="pageReference">The <see cref="T:Rock.Web.PageReference" />.</param>
        /// <returns>
        /// A <see cref="T:System.Collections.Generic.List`1" /> of block related <see cref="T:Rock.Web.UI.BreadCrumb">BreadCrumbs</see>.
        /// </returns>
        public override List <BreadCrumb> GetBreadCrumbs(PageReference pageReference)
        {
            _rockContext      = new RockContext();
            _componentService = new InteractionComponentService(_rockContext);
            _component        = _componentService.Get(PageParameter("ComponentId").AsInteger());

            var breadCrumbs = new List <BreadCrumb>();

            breadCrumbs.Add(new BreadCrumb(_component != null ? _component.Name : "Component", pageReference));
            return(breadCrumbs);
        }
Exemple #10
0
 public Inventory GetIngredientInventory(InteractionComponent _interactionComponent)
 {
     foreach (var entry in ingredientInventories)
     {
         if ((int)_interactionComponent == (int)entry.type)
         {
             return(entry);
         }
         continue;
     }
     return(null);
 }
    private void PerformInteractionAction()
    {
        // Interaction logic - Player -> Object/NPC
        Vector2 targetPosition = Rigidbody2D.position;

        Debug.DrawLine(Rigidbody2D.position, Rigidbody2D.position + playerFacing);
        var hitTarget = Physics2D.Raycast(Rigidbody2D.position, playerFacing, 1.0f);
        InteractionComponent interactionTarget = hitTarget.collider.GetComponent <InteractionComponent>();

        if (interactionTarget != null)
        {
        }
    }
Exemple #12
0
    protected override void Start()
    {
        base.Start();
        if (_substance != null)
        {
            Assert.IsNotNull(_substance);
            _animator = gameObject.GetComponent <Animator>();
        }

        interactionComponent = GameManager.instance.player.GetComponent <InteractionComponent>();
        _main             = Camera.main;
        _playerTransform  = GameManager.instance.player.transform;
        _cameraController = Camera.main.GetComponentInParent <CameraController>();
    }
Exemple #13
0
        /// <summary>
        /// Gets the Component Entity
        /// </summary>
        /// <param name="rockContext">The db context.</param>
        /// <param name="component">The interaction component.</param>
        private IEntity GetComponentEntity(RockContext rockContext, InteractionComponent interactionComponent)
        {
            IEntity  componentEntity     = null;
            var      componentEntityType = EntityTypeCache.Read(interactionComponent.Channel.ComponentEntityTypeId.Value).GetEntityType();
            IService serviceInstance     = Reflection.GetServiceForEntityType(componentEntityType, rockContext);

            if (serviceInstance != null)
            {
                System.Reflection.MethodInfo getMethod = serviceInstance.GetType().GetMethod("Get", new Type[] { typeof(int) });
                componentEntity = getMethod.Invoke(serviceInstance, new object[] { interactionComponent.EntityId.Value }) as Rock.Data.IEntity;
            }

            return(componentEntity);
        }
Exemple #14
0
 /// <summary>
 /// Creates a new <see cref="PlayerEntity"/> instance.
 /// </summary>
 /// <param name="context"></param>
 public PlayerEntity(IPlayerFactory playerFactory)
 {
     Moves          = new MovableComponent();
     PlayerData     = new PlayerDataComponent();
     Taskbar        = new TaskbarComponent();
     Follow         = new FollowComponent();
     Interaction    = new InteractionComponent();
     Battle         = new BattleComponent();
     Timers         = new TimerComponent();
     Attributes     = new AttributeComponent();
     QuestDiary     = new QuestDiaryComponent();
     SkillTree      = new SkillTreeComponent();
     Inventory      = new InventoryContainerComponent();
     _playerFactory = playerFactory;
 }
Exemple #15
0
    private void InitializeInteractionWindow(InteractionComponent _interactionComponent)
    {
        var selectedInventory = GameController.instance._inventoryHolder.GetIngredientInventory(_interactionComponent);
        int x = 0;

        if (selectedInventory.inventoryList.Count == 0)
        {
            Debug.Log("Empty inventory display out of INTERACTIONCOMPONENT");
            return;
        }

        foreach (var entry in selectedInventory.inventoryList)
        {
            if (entry.ingredient.discovered)
            {
                transform.GetChild(x).gameObject.SetActive(true);
                transform.GetChild(x).GetComponent <IngredientSlot>().UpdateSlot(entry.ingredient, entry.amount);
                transform.GetChild(x).GetComponent <IngredientSlot>().OnCloseInteractionWindow += CloseInteractionWindow;
                x++;
            }
        }
        x = 0;
    }
Exemple #16
0
 private void Start()
 {
     interactionComponent = standInteractabledata._interactionComponent;
 }
 void ToggleInteractionWindow(InteractionComponent _interactionComponent, bool _boolean)
 {
     interactionComponent = _interactionComponent;
     interactionWindow.SetActive(_boolean);
 }
Exemple #18
0
 private void Start()
 {
     interactionComponent = GameManager.instance.player.GetComponent <InteractionComponent>();
     _main = Camera.main;
 }
    void Awake()
    {
        _originalPos = transform.localPosition;
        _originalRot = transform.localRotation;

        base.Awake();

        _collider = GetComponent <Collider>();


        m_animator = GetComponentInParent <Animator>();

        foreach (InteractionComponent com in m_interactiveComponents)
        {
            // caching lambda
            InteractionComponent currentComponent = com;

            OnMouseClick onClick = com.collider.gameObject.AddComponent <OnMouseClick>();
            OnMouseOver  onOver  = com.collider.gameObject.AddComponent <OnMouseOver>();
            OnMouseDrag  onDrag  = gameObject.AddComponent <OnMouseDrag>();

            onDrag.onMouseDragBegin += OnComponentDragBegin;
            onDrag.onMouseDrag      += OnComponentDragged;
            onDrag.onMouseDragEnd   += OnComponentDragEnd;

            onClick.onMouseClick += (PointerEventData eventData) =>
            {
                if (eventData.dragging)
                {
                    return;
                }

                if (!IsInteracting)
                {
                    return;
                }

                currentComponent.onInteract.Invoke();
            };

            onOver.onMouseOver += (PointerEventData eventData) =>
            {
                if (!IsInteracting)
                {
                    return;
                }

                m_isMouseOverInteraction = false;

                if (currentComponent.onInteract.GetPersistentEventCount() > 0)
                {
                    m_isMouseOverInteraction = true;
                }

                if (!m_isDragging)
                {
                    Cursor.SetCursor(cursorDrag, hotSpot, cursorMode);
                }

                if (m_isMouseOverInteraction && !m_isDragging)
                {
                    Cursor.SetCursor(cursorClick, hotSpot, cursorMode);
                }

                m_isMouseOver = true;
            };

            onOver.onMouseOut += (PointerEventData data) =>
            {
                if (!IsInteracting)
                {
                    return;
                }

                if (!m_isDragging)
                {
                    Cursor.SetCursor(null, Vector2.zero, cursorMode);
                }

                m_isMouseOver = false;
            };
        }
    }
 /*
  * During the Start, we gather the different component. I usually put my component in children of the pawn, (and then do a GetComponentInChildren)
  * but for this demo, the component will be directly with the pawn.
  */
 void Start()
 {
     interaction = GetComponent <InteractionComponent>();
 }
Exemple #21
0
        /// <summary>
        /// Encodes the receipt code.
        /// </summary>
        /// <param name="receipt">The receipt.</param>
        /// <returns>An encoded string that represents the receipt identifier.</returns>
        public static string EncodeReceiptCode(InteractionComponent receipt)
        {
            var receiptSecret = (ushort)string.Format("{0:00}{0:000}", receipt.CreatedDateTime.Value.Second, receipt.CreatedDateTime.Value.Millisecond).AsInteger();

            return(EncodeReceiptCode(receipt.Id, receiptSecret));
        }
        /// <summary>
        /// Gets the component.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="channel">The channel.</param>
        /// <param name="entityId">The entity identifier.</param>
        /// <param name="identifier">The identifier.</param>
        /// <returns></returns>
        private InteractionComponentCache GetComponent(RockContext rockContext, InteractionChannelCache channel, int?entityId, string identifier)
        {
            if (channel != null)
            {
                if (entityId.HasValue)
                {
                    // Find by the Entity Id
                    int?interactionComponentId = new InteractionComponentService(rockContext)
                                                 .Queryable()
                                                 .AsNoTracking()
                                                 .Where(c => c.EntityId.HasValue && c.InteractionChannelId == channel.Id && c.EntityId.Value == entityId.Value)
                                                 .Select(c => c.Id)
                                                 .Cast <int?>()
                                                 .FirstOrDefault();

                    if (interactionComponentId != null)
                    {
                        return(InteractionComponentCache.Get(interactionComponentId.Value));
                    }
                }

                if (identifier.IsNotNullOrWhiteSpace())
                {
                    // Find by Id
                    int?id = identifier.AsIntegerOrNull();
                    if (id.HasValue)
                    {
                        var component = InteractionComponentCache.Get(id.Value);
                        if (component != null && component.InteractionChannelId == channel.Id)
                        {
                            return(component);
                        }
                    }

                    // Find by Guid
                    Guid?guid = identifier.AsGuidOrNull();
                    if (guid.HasValue)
                    {
                        var component = InteractionComponentCache.Get(guid.Value);
                        if (component != null && component.InteractionChannelId == channel.Id)
                        {
                            return(component);
                        }
                    }

                    if (!id.HasValue && !guid.HasValue)
                    {
                        // Find by Name
                        int?interactionComponentId = new InteractionComponentService(rockContext)
                                                     .Queryable()
                                                     .AsNoTracking()
                                                     .Where(c => c.InteractionChannelId == channel.Id)
                                                     .Where(c => c.Name.Equals(identifier, StringComparison.OrdinalIgnoreCase))
                                                     .Select(c => c.Id)
                                                     .Cast <int?>()
                                                     .FirstOrDefault();

                        if (interactionComponentId != null)
                        {
                            return(InteractionComponentCache.Get(interactionComponentId.Value));
                        }

                        // If still no match, and we have a name, create a new channel
                        using (var newRockContext = new RockContext())
                        {
                            var interactionComponent = new InteractionComponent();
                            interactionComponent.Name = identifier;
                            interactionComponent.InteractionChannelId = channel.Id;
                            new InteractionComponentService(newRockContext).Add(interactionComponent);
                            newRockContext.SaveChanges();

                            return(InteractionComponentCache.Get(interactionComponent.Id));
                        }
                    }
                }
            }

            return(null);
        }
Exemple #23
0
        static Support()
        {
            Agent = new Agent
            {
                Mbox = "mailto:[email protected]"
            };

            Verb = new Verb("http://adlnet.gov/expapi/verbs/experienced")
            {
                Display = new LanguageMap()
            };
            Verb.Display.Add("en-US", "experienced");

            Activity = new Activity
            {
                Id         = "http://tincanapi.com/TinCanCSharp/Test/Unit/0",
                Definition = new ActivityDefinition
                {
                    Type = new Uri("http://id.tincanapi.com/activitytype/unit-test"),
                    Name = new LanguageMap()
                }
            };
            Activity.Definition.Name.Add("en-US", "Tin Can C# Tests: Unit 0");
            Activity.Definition.Description =
                new LanguageMap {
                { "en-US", "Unit test 0 in the test suite for the Tin Can C# library." }
            };

            Activity.Definition.InteractionType = InteractionType.ChoiceType;
            Activity.Definition.Choices         = new List <InteractionComponent>();

            for (int i = 1; i <= 3; i++)
            {
                var interactionComponent = new InteractionComponent
                {
                    Id          = "choice-" + i.ToString(),
                    Description = new LanguageMap()
                };

                interactionComponent.Description.Add("en-US", "Choice " + i.ToString());

                Activity.Definition.Choices.Add(interactionComponent);
            }

            Activity.Definition.CorrectResponsesPattern = new List <string>();

            for (int i = 1; i <= 2; i++)
            {
                Activity.Definition.CorrectResponsesPattern.Add("choice-" + i.ToString());
            }

            Parent = new Activity
            {
                Id         = "http://tincanapi.com/TinCanCSharp/Test",
                Definition = new ActivityDefinition
                {
                    Type = new Uri("http://id.tincanapi.com/activitytype/unit-test-suite"),
                    Name = new LanguageMap()
                }
            };
            Parent.Definition.Name.Add("en-US", "Tin Can C# Tests");
            Parent.Definition.Description = new LanguageMap {
                { "en-US", "Unit test suite for the Tin Can C# library." }
            };

            StatementRef = new StatementRef(Guid.NewGuid());

            Context = new Context
            {
                Registration      = Guid.NewGuid(),
                Statement         = StatementRef,
                ContextActivities = new ContextActivities
                {
                    Parent = new List <Activity>()
                }
            };
            Context.ContextActivities.Parent.Add(Parent);

            Score = new Score
            {
                Raw    = 97,
                Scaled = 0.97,
                Max    = 100,
                Min    = 0
            };

            Result = new Result
            {
                Score      = Score,
                Success    = true,
                Completion = true,
                Duration   = new TimeSpan(1, 2, 16, 43),
                Response   = "choice-2"
            };

            SubStatement = new SubStatement
            {
                Actor  = Agent,
                Verb   = Verb,
                Target = Parent
            };
        }
Exemple #24
0
 // Use this for initialization
 void Start()
 {
     pawn        = GetComponent <PlayerPawn>();
     move        = GetComponent <MoveComponent>();
     interaction = GetComponent <InteractionComponent>();
 }
Exemple #25
0
 public void EnterAttack()
 {
     MoveComponent.StopOnCurrentTile();
     InteractionComponent.SetTauntState();
 }
 void OnMouseEnter()
 {
     InteractionComponent.UserHoverStart();
 }
Exemple #27
0
        /// <summary>
        /// Execute method to write transaction to the database.
        /// </summary>
        public void Execute()
        {
            using ( var rockContext = new RockContext() )
            {

                var userAgent = (this.UserAgent ?? string.Empty).Trim();
                if ( userAgent.Length > 450 )
                {
                    userAgent = userAgent.Substring( 0, 450 ); // trim super long useragents to fit in pageViewUserAgent.UserAgent
                }

                // get user agent info
                var clientType = PageViewUserAgent.GetClientType( userAgent );

                // don't log visits from crawlers
                if ( clientType != "Crawler" )
                {
                    InteractionChannelService interactionChannelService = new InteractionChannelService( rockContext );
                    InteractionComponentService interactionComponentService = new InteractionComponentService( rockContext );
                    InteractionDeviceTypeService interactionDeviceTypeService = new InteractionDeviceTypeService( rockContext );
                    InteractionSessionService interactionSessionService = new InteractionSessionService( rockContext );
                    InteractionService interactionService = new InteractionService( rockContext );

                    ClientInfo client = uaParser.Parse( userAgent );
                    var clientOs = client.OS.ToString();
                    var clientBrowser = client.UserAgent.ToString();

                    // lookup the interactionDeviceType, and create it if it doesn't exist
                    var interactionDeviceType = interactionDeviceTypeService.Queryable().Where( a => a.Application == clientBrowser
                                                && a.OperatingSystem == clientOs && a.ClientType == clientType ).FirstOrDefault();

                    if ( interactionDeviceType == null )
                    {
                        interactionDeviceType = new InteractionDeviceType();
                        interactionDeviceType.DeviceTypeData = userAgent;
                        interactionDeviceType.ClientType = clientType;
                        interactionDeviceType.OperatingSystem = clientOs;
                        interactionDeviceType.Application = clientBrowser;
                        interactionDeviceType.Name = string.Format( "{0} - {1}", clientOs, clientBrowser );
                        interactionDeviceTypeService.Add( interactionDeviceType );
                        rockContext.SaveChanges();
                    }

                    // lookup interactionSession, and create it if it doesn't exist
                    Guid sessionId = this.SessionId.AsGuid();
                    int? interactionSessionId = interactionSessionService.Queryable()
                                                    .Where(
                                                        a => a.DeviceTypeId == interactionDeviceType.Id
                                                        && a.Guid == sessionId )
                                                    .Select( a => (int?)a.Id )
                                                    .FirstOrDefault();

                    if ( !interactionSessionId.HasValue )
                    {
                        var interactionSession = new InteractionSession();
                        interactionSession.DeviceTypeId = interactionDeviceType.Id;
                        interactionSession.IpAddress = this.IPAddress;
                        interactionSession.Guid = sessionId;
                        interactionSessionService.Add( interactionSession );
                        rockContext.SaveChanges();
                        interactionSessionId = interactionSession.Id;
                    }

                    int componentEntityTypeId = EntityTypeCache.Read<Rock.Model.Page>().Id;
                    string siteName = SiteCache.Read( SiteId ?? 1 ).Name;

                    // lookup the interaction channel, and create it if it doesn't exist
                    int channelMediumTypeValueId = DefinedValueCache.Read( SystemGuid.DefinedValue.INTERACTIONCHANNELTYPE_WEBSITE.AsGuid() ).Id;

                    // check that the site exists as a channel
                    var interactionChannel = interactionChannelService.Queryable()
                                                        .Where( a =>
                                                            a.ChannelTypeMediumValueId == channelMediumTypeValueId
                                                            && a.ChannelEntityId == this.SiteId )
                                                        .FirstOrDefault();
                    if ( interactionChannel == null )
                    {
                        interactionChannel = new InteractionChannel();
                        interactionChannel.Name = siteName;
                        interactionChannel.ChannelTypeMediumValueId = channelMediumTypeValueId;
                        interactionChannel.ChannelEntityId = this.SiteId;
                        interactionChannel.ComponentEntityTypeId = componentEntityTypeId;
                        interactionChannelService.Add( interactionChannel );
                        rockContext.SaveChanges();
                    }

                    // check that the page exists as a component
                    var interactionComponent = interactionComponentService.Queryable()
                                                        .Where( a =>
                                                            a.EntityId == PageId
                                                            && a.ChannelId == interactionChannel.Id )
                                                        .FirstOrDefault();
                    if ( interactionComponent == null )
                    {
                        interactionComponent = new InteractionComponent();
                        interactionComponent.Name = PageTitle;
                        interactionComponent.EntityId = PageId;
                        interactionComponent.ChannelId = interactionChannel.Id;
                        interactionComponentService.Add( interactionComponent );
                        rockContext.SaveChanges();
                    }

                    // add the interaction
                    Interaction interaction = new Interaction();
                    interactionService.Add( interaction );

                    // obfuscate rock magic token
                    Regex rgx = new Regex( @"rckipid=([^&]*)" );
                    string cleanUrl = rgx.Replace( this.Url, "rckipid=XXXXXXXXXXXXXXXXXXXXXXXXXXXX" );

                    interaction.InteractionData = cleanUrl;
                    interaction.Operation = "View";
                    interaction.PersonAliasId = this.PersonAliasId;
                    interaction.InteractionDateTime = this.DateViewed;
                    interaction.InteractionSessionId = interactionSessionId;
                    interaction.InteractionComponentId = interactionComponent.Id;
                    rockContext.SaveChanges();
                }
            }
        }
Exemple #28
0
        static Support()
        {
            agent      = new Agent();
            agent.mbox = "mailto:[email protected]";

            verb         = new Verb("http://adlnet.gov/expapi/verbs/experienced");
            verb.display = new LanguageMap();
            verb.display.Add("en-US", "experienced");

            activity                 = new Activity();
            activity.id              = "http://tincanapi.com/TinCanCSharp/Test/Unit/0";
            activity.definition      = new ActivityDefinition();
            activity.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test");
            activity.definition.name = new LanguageMap();
            activity.definition.name.Add("en-US", "Tin Can C# Tests: Unit 0");
            activity.definition.description = new LanguageMap();
            activity.definition.description.Add("en-US", "Unit test 0 in the test suite for the Tin Can C# library.");

            activity.definition.interactionType = InteractionType.Choice;
            activity.definition.choices         = new List <InteractionComponent>();

            for (int i = 1; i <= 3; i++)
            {
                InteractionComponent interactionComponent = new InteractionComponent();

                interactionComponent.id          = "choice-" + i.ToString();
                interactionComponent.description = new LanguageMap();
                interactionComponent.description.Add("en-US", "Choice " + i.ToString());

                activity.definition.choices.Add(interactionComponent);
            }

            activity.definition.correctResponsesPattern = new List <string>();

            for (int i = 1; i <= 2; i++)
            {
                activity.definition.correctResponsesPattern.Add("choice-" + i.ToString());
            }

            parent                 = new Activity();
            parent.id              = "http://tincanapi.com/TinCanCSharp/Test";
            parent.definition      = new ActivityDefinition();
            parent.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test-suite");
            //parent.definition.moreInfo = new Uri("http://rusticisoftware.github.io/TinCanCSharp/");
            parent.definition.name = new LanguageMap();
            parent.definition.name.Add("en-US", "Tin Can C# Tests");
            parent.definition.description = new LanguageMap();
            parent.definition.description.Add("en-US", "Unit test suite for the Tin Can C# library.");

            statementRef = new StatementRef(Guid.NewGuid());

            context = new Context();
            context.registration             = Guid.NewGuid();
            context.statement                = statementRef;
            context.contextActivities        = new ContextActivities();
            context.contextActivities.parent = new List <Activity>();
            context.contextActivities.parent.Add(parent);

            score        = new Score();
            score.raw    = 97;
            score.scaled = 0.97;
            score.max    = 100;
            score.min    = 0;

            result            = new Result();
            result.score      = score;
            result.success    = true;
            result.completion = true;
            result.duration   = new TimeSpan(1, 2, 16, 43);
            result.response   = "choice-2";

            subStatement        = new SubStatement();
            subStatement.actor  = agent;
            subStatement.verb   = verb;
            subStatement.target = parent;
        }
Exemple #29
0
        public HttpResponseMessage Post(List <MACPresence> presenceList)
        {
            using (var rockContext = new RockContext())
            {
                var interactionChannel = new InteractionChannelService(rockContext).Get(Rock.SystemGuid.InteractionChannel.WIFI_PRESENCE.AsGuid());
                if (interactionChannel != null)
                {
                    var interactionComponentIds = new Dictionary <string, int>();

                    var personalDeviceService       = new PersonalDeviceService(rockContext);
                    var interactionService          = new InteractionService(rockContext);
                    var interactionComponentService = new InteractionComponentService(rockContext);

                    // Can't set to local time here as it won't compute DST correctly later.
                    var epochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

                    foreach (var macPresence in presenceList.Where(l => l.Mac != null && l.Mac != ""))
                    {
                        var device = personalDeviceService.GetByMACAddress(macPresence.Mac);
                        if (device == null)
                        {
                            device            = new PersonalDevice();
                            device.MACAddress = macPresence.Mac;
                            personalDeviceService.Add(device);

                            rockContext.SaveChanges();
                        }

                        if (macPresence.Presence != null && macPresence.Presence.Any())
                        {
                            foreach (var presence in macPresence.Presence)
                            {
                                // Calc data needed for new and existing data
                                DateTime interactionStart = epochTime.AddSeconds(presence.Arrive).ToLocalTime();
                                DateTime interactionEnd   = epochTime.AddSeconds(presence.Depart).ToLocalTime();
                                TimeSpan ts       = interactionEnd.Subtract(interactionStart);
                                string   duration = (ts.TotalMinutes >= 60 ? $"{ts:%h} hours and " : "") + $"{ts:%m} minutes";

                                Interaction interaction = interactionService.Queryable().Where(i => i.ForeignKey != null && i.ForeignKey == presence.SessionId).FirstOrDefault();
                                if (interaction == null)
                                {
                                    if (!interactionComponentIds.ContainsKey(presence.Space))
                                    {
                                        var component = interactionComponentService
                                                        .Queryable().AsNoTracking()
                                                        .Where(c =>
                                                               c.InteractionChannelId == interactionChannel.Id &&
                                                               c.Name == presence.Space)
                                                        .FirstOrDefault();
                                        if (component == null)
                                        {
                                            component = new InteractionComponent();
                                            interactionComponentService.Add(component);
                                            component.InteractionChannelId = interactionChannel.Id;
                                            component.Name = presence.Space;
                                            rockContext.SaveChanges();
                                        }

                                        interactionComponentIds.Add(presence.Space, component.Id);
                                    }

                                    interaction = new Interaction();
                                    interaction.InteractionDateTime    = interactionStart;
                                    interaction.InteractionEndDateTime = interactionEnd;
                                    interaction.Operation              = "Present";
                                    interaction.InteractionSummary     = $"Arrived at {presence.Space} on {interactionStart.ToShortDateTimeString()}. Stayed for {duration}.";
                                    interaction.InteractionComponentId = interactionComponentIds[presence.Space];
                                    interaction.InteractionData        = presence.ToJson();
                                    interaction.PersonalDeviceId       = device.Id;
                                    interaction.PersonAliasId          = device.PersonAliasId;
                                    interaction.ForeignKey             = presence.SessionId;

                                    interactionService.Add(interaction);
                                }
                                else
                                {
                                    // Update the existing interaction
                                    interaction.InteractionEndDateTime = interactionEnd;
                                    interaction.InteractionSummary     = $"Arrived at {presence.Space} on {interactionStart.ToShortDateTimeString()}. Stayed for {duration}.";
                                    interaction.InteractionData        = presence.ToJson();
                                }

                                rockContext.SaveChanges();
                            }
                        }
                    }

                    var response = ControllerContext.Request.CreateResponse(HttpStatusCode.Created);
                    return(response);
                }
                else
                {
                    var response = ControllerContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "A WiFi Presense Interaction Channel Was Not Found!");
                    throw new HttpResponseException(response);
                }
            }
        }
        public void Execute()
        {
            if (PageId.HasValue || !string.IsNullOrWhiteSpace(ComponentName))
            {
                using (var rockContext = new RockContext())
                {
                    int channelMediumTypeValueId  = DefinedValueCache.Get(AvalancheUtilities.AppMediumValue.AsGuid()).Id;
                    var interactionChannelService = new InteractionChannelService(rockContext);
                    var interactionService        = new InteractionService(rockContext);
                    var interactionChannel        = interactionChannelService.Queryable()
                                                    .Where(a =>
                                                           a.ChannelTypeMediumValueId == channelMediumTypeValueId &&
                                                           a.ChannelEntityId == this.SiteId)
                                                    .FirstOrDefault();
                    if (interactionChannel == null)
                    {
                        interactionChannel      = new InteractionChannel();
                        interactionChannel.Name = SiteCache.Get(SiteId ?? 1).Name;
                        interactionChannel.ChannelTypeMediumValueId = channelMediumTypeValueId;
                        interactionChannel.ChannelEntityId          = this.SiteId;
                        interactionChannel.ComponentEntityTypeId    = EntityTypeCache.Get <Rock.Model.Page>().Id;
                        interactionChannelService.Add(interactionChannel);
                        rockContext.SaveChanges();
                    }

                    InteractionComponent interactionComponent = null;
                    var interactionComponentService           = new InteractionComponentService(rockContext);

                    if (PageId.HasValue)
                    {
                        interactionComponent = interactionComponentService.GetComponentByEntityId(interactionChannel.Id, PageId.Value, PageTitle);
                    }
                    else
                    {
                        interactionComponent = interactionComponentService.GetComponentByComponentName(interactionChannel.Id, ComponentName);
                    }
                    rockContext.SaveChanges();

                    // Add the interaction
                    if (interactionComponent != null)
                    {
                        var deviceId = Regex.Match(UserAgent, "(?<=-).+(?=\\))").Value.Trim();
                        if (deviceId.Length > 20)
                        {
                            deviceId = deviceId.Substring(0, 20);
                        }
                        var deviceApplication = Regex.Match(UserAgent, "^[\\S]{0,}").Value.Trim() + " " + deviceId;
                        var clientOs          = Regex.Match(UserAgent, "(?<=;).+(?=-)").Value.Trim();
                        var clientType        = Regex.Match(UserAgent, "(?<=\\().+(?=;)").Value.Trim();

                        var deviceType = interactionService.GetInteractionDeviceType(deviceApplication, clientOs, clientType, UserAgent);
                        var interactionSessionService = new InteractionSessionService(rockContext);
                        var interactionSession        = interactionSessionService.Queryable().Where(s => s.IpAddress == IPAddress && s.DeviceTypeId == deviceType.Id).FirstOrDefault();

                        if (interactionSession == null)
                        {
                            interactionSession = new InteractionSession()
                            {
                                DeviceTypeId = deviceType.Id,
                                IpAddress    = TrimString(IPAddress, 25)
                            };
                            interactionSessionService.Add(interactionSession);
                            rockContext.SaveChanges();
                        }

                        Operation          = TrimString(Operation, 25);
                        InteractionSummary = TrimString(InteractionSummary, 500);
                        clientType         = TrimString(clientType, 25);
                        deviceApplication  = TrimString(deviceApplication, 100);
                        clientOs           = TrimString(clientOs, 100);

                        var interaction = new InteractionService(rockContext).AddInteraction(interactionComponent.Id, null, Operation, InteractionData, PersonAliasId, DateViewed,
                                                                                             deviceApplication, clientOs, clientType, UserAgent, IPAddress, interactionSession.Guid);

                        interaction.InteractionSummary = InteractionSummary;

                        PersonalDevice personalDevice = AvalancheUtilities.GetPersonalDevice(deviceId, PersonAliasId, rockContext);
                        if (personalDevice != null)
                        {
                            interaction.PersonalDeviceId = personalDevice.Id;
                        }

                        rockContext.SaveChanges();
                    }
                }
            }
        }
Exemple #31
0
 /// <summary>
 /// Validates the receipt code matches the database receipt.
 /// </summary>
 /// <param name="receipt">The receipt.</param>
 /// <param name="receiptCode">The receipt code.</param>
 /// <returns><c>true</c> if the receipt code is valid.</returns>
 public static bool ValidateReceiptCode(InteractionComponent receipt, string receiptCode)
 {
     return(EncodeReceiptCode(receipt) == receiptCode.ToUpper());
 }