Esempio n. 1
0
        /// <summary>
        /// Deletes a event from the database
        /// </summary>
        /// <param name="id">The Id of the event</param>
        public void DeleteEvent(int id)
        {
            // Getting the item
            EventBlock singleEvent = Db.Events.Find(id);

            // Deleting the item
            Db.Events.Remove(singleEvent);
            Db.SaveChanges();
        }
 public void StartEventBlock(string eventName)
 {
     if (this.installedRobotSourceCode.IsEventBlockExist(eventName))
     {
         EventBlock eventBlock = this.installedRobotSourceCode.GetEventBlock(eventName); // Set EventBlock To WaitingBlock
         if (eventBlock != null)
         {
             this.PushToBlockCallStack(eventBlock);
         }
     }
 }
Esempio n. 3
0
 //スタックの追加
 public void AddStack(EventBlock block)
 {
     if (EventStack.Count <= 0)
     {
         EventStack.Push(new StackEndBlock(block.GetCaster()));
     }
     EventStack.Push(block);
     isStackResolved = false;
     StartCoroutine(CallTrigger(block));
     //Debug.Log(block);
 }
Esempio n. 4
0
    private void StateInit(Player caster, Card card, EffectState state, EventBlock trigger = null)
    {
        _caster = caster;
        _card   = card;
        if (trigger != null)
        {
            this.trigger = trigger;
            Debug.Log(trigger.GetType());
        }

        //this.state = state;
    }
Esempio n. 5
0
    //블럭 배열 생성----------------------------------------------
    void CreateBlock()
    {
        shuffleB = new EventBlock[blockLine, blockLine];
        //초기 번호 배열
        targetArray = gameObject.AddComponent <NumArray>();
        targetArray.MakeLine(blockLine);
        for (int y = 0; y < blockLine; y++)
        {
            for (int x = 0; x < blockLine; x++)
            {
                int myNum = x + (blockLine * y) + 1;
                targetArray.MakeArray(x, y, myNum);
            }
        }
        numArray = gameObject.AddComponent <NumArray>();
        numArray.MakeLine(blockLine);

        //분할 이미지
        Texture2D[,] Image = SetImage.ImageBlock(myImage, blockLine);

        for (int y = 0; y < blockLine; y++)
        {
            for (int x = 0; x < blockLine; x++)
            {
                //Quad로 블럭 생성
                GameObject myBlock = GameObject.CreatePrimitive(PrimitiveType.Quad);
                myBlock.transform.localPosition = new Vector2(-0.5f * (blockLine - 1), -0.5f * (blockLine - 1) - 1) + new Vector2(x, y);

                //이벤트 설정
                eventBlock = myBlock.AddComponent <EventBlock>();
                //좌표, 이미지 설정
                eventBlock.Init(new Vector2(x, y), Image[x, y]);
                //셔플 배열에 블럭 넣기
                shuffleB[x, y] = eventBlock;

                //번호 배열 정보
                int myNum = x + (blockLine * y) + 1;
                //변화하는 번호 배열
                numArray.MakeArray(x, y, myNum);

                //초기 비어있는 블럭
                if (x == blockLine - 1 && y == 0)
                {
                    myBlock.SetActive(false);
                    emptyBlock = eventBlock;
                }

                //마우스 입력이 일어나면
                eventBlock.BlockPressed += MoveBlock;
            }
        }
    }
Esempio n. 6
0
    /// <summary>
    /// 各種イベント発生時に呼び出される誘発イベント確認処理
    /// </summary>
    /// <param name="type"></param>
    /// <param name="caster"></param>
    public IEnumerator CallTrigger(EventBlock block)
    {
        List <TriggerBlock> triggers = block.GetTrigger();

        //誘発効果を確認
        foreach (TriggerBlock t in triggers)
        {
            yield return(StartCoroutine(TriggerCheck(t.trigger, t.caster, block)));
            //Debug.Log(t + "確認");
        }
        //ResolveBlock();
        ResolveStack(block);
        //Debug.Log(block + "終了");
    }
Esempio n. 7
0
        /// <summary>
        /// Retuns a Event View model to be used directly
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Event View Model</returns>
        public EventListingViewModel GetSingleEventListingViewModel(int id)
        {
            // Searches for the event
            EventBlock singleEvent = Db.Events.Find(id);

            // Converts the event to a View Model
            EventListingViewModel model = new EventListingViewModel
            {
                EventName = singleEvent.EventName,
                EventDate = singleEvent.EventDateAndTime
            };

            return(model);
        }
Esempio n. 8
0
    protected EventBlock GetBlock(int priority)
    {
        foreach (EventBlock b in eventBlocks)
        {
            if (b.priority == priority)
            {
                return(b);
            }
        }
        EventBlock newBlock = new EventBlock(priority);

        eventBlocks.Add(newBlock);
        eventBlocks.Sort();
        return(newBlock);
    }
Esempio n. 9
0
    public bool RemoveFromStoredEventBlockList(EventBlock eventBlock)
    {
        if (this.IsEditing == false)
        {
            Debug.LogError("Cant Change StoredEventBlockList, Because Source Code Editing Completely Finished");
            return(false);
        }

        if (eventBlock == null)
        {
            return(false);
        }

        this.StoredEventBlockDictonary.Remove(eventBlock.Input1.GetReporterStringValue());
        return(true);
    }
Esempio n. 10
0
        public ActionResult Edit(int eventId)
        {
            var detail = EventBlockService.GetEventById(eventId);
            var model  =
                new EventBlock
            {
                EventId     = detail.EventId,
                Title       = detail.Title,
                Description = detail.Description,
                Start       = detail.Start,
                End         = detail.End,
                IsAllDay    = detail.IsAllDay
            };

            return(View(model));
        }
Esempio n. 11
0
        /// <summary>
        /// Adds a event to the database
        /// </summary>
        /// <param name="model">The model data</param>
        public void AddEvent(EventBlock model)
        {
            EventBlock singleEvent = new EventBlock
            {
                EventName        = model.EventName,
                EventDateAndTime = model.EventDateAndTime,
                Game             = model.Game,
                Description      = model.Description,
                ImageLocation    = model.ImageLocation,
                Location         = model.Location,
                User             = GetCurrenctUser()
            };

            // Add the entry to the database
            Db.Events.Add(singleEvent);
            Db.SaveChanges();
        }
Esempio n. 12
0
        public static IReadOnlyList <IBlock> GetBlocks(IList <string> lines)
        {
            var blocks     = new List <IBlock>();
            var blockLines = new List <string>();

            foreach (var currentLine in lines)
            {
                if (string.IsNullOrEmpty(currentLine))
                {
                    continue;
                }
                var line = currentLine.TrimStart(CR, LF);
                if (!line.ToUpper().StartsWith("<END "))
                {
                    blockLines.Add(line + CRLF);
                    continue;
                }

                blockLines.Add(line + CRLF);

                var    firstLine = blockLines[0].ToUpper();
                IBlock instance;
                if (firstLine.StartsWith("<EVENT "))
                {
                    instance = new EventBlock();
                }
                else if (firstLine.StartsWith("<REPLY "))
                {
                    instance = new ReplyBlock();
                }
                else
                {
                    continue;
                }

                if (!instance.Parse(blockLines))
                {
                    return(null);
                }
                blocks.Add(instance);
                blockLines.Clear();
            }

            return(blocks);
        }
Esempio n. 13
0
 //スタックの解決
 public void ResolveStack(EventBlock block = null)
 {
     if (EventStack.Count == 0)
     {
         return;
     }
     if (block != null && EventStack.Peek() != block)
     {
         //Debug.LogAssertion("スタック順が正しく処理されていません");
     }
     ResolvedBlock = EventStack.Peek();
     StartCoroutine(EventStack.Pop().ResolveBlock());
     if (EventStack.Count <= 0)
     {
         Refresh();
     }
     //isStackResolved = false;
 }
Esempio n. 14
0
        /// <summary>
        /// Edits a event in the database
        /// </summary>
        /// <param name="model">A event block</param>
        public void UpdateEvent(EventBlock model)
        {
            // Setting the varibles
            Db.Events.Find(model.Id).EventName        = model.EventName;
            Db.Events.Find(model.Id).EventDateAndTime = model.EventDateAndTime;

            // Also saves the name of the last person who edited the event
            Db.Events.Find(model.Id).LastPersonToEdit = GetCurrenctUser();
            Db.Events.Find(model.Id).ImageLocation    = model.ImageLocation;

            // We dont care about this now
            //Db.Events.Find(model.Id).Location = model.Location;
            //Db.Events.Find(model.Id).Game = model.Game;
            //Db.Events.Find(model.Id).User = model.User;
            //Db.Events.Find(model.Id).LastPersonToEdit = model.LastPersonToEdit;

            // Saving this to the database
            Db.SaveChanges();
        }
Esempio n. 15
0
    /// <summary>
    /// カードの誘発条件となり得るイベントが発生した時、それに対する誘発効果や罠の発動を呼び出す処理
    /// </summary>
    /// <param name="type">誘発イベントの種類</param>
    /// <param name="caster">誘発イベントの発動者</param>
    private IEnumerator TriggerCheck(TriggerType type, Player caster = null, EventBlock block = null)
    {
        //支援カードの破棄条件等、効果発動より先に発動するルール効果
        //Debug.Log("ルール効果確認");
        yield return(StartCoroutine(SupportDestTriggerCheck(type, caster)));

        //発動済みカードの誘発効果等、プレイヤーの承認を待たない誘発効果
        if (caster != null)
        {
            yield return(StartCoroutine(caster.GetSupportZone().EffectTriggerCheck(type, block)));
        }


        //Debug.Log("罠カード発動確認");
        //罠カードの発動等、プレイヤーの承認を待つ効果
        yield return(StartCoroutine(TrapPlayTime(type, caster, block)));

        //効果を解決
        //Debug.Log("トリガー確認終了");
    }
Esempio n. 16
0
        protected override void Warmup(MessageDispatcher dispatcher)
        {
            var    warmupCount    = 10L;
            var    warmupsThusFar = 0L;
            Action warmupWork     = () =>
            {
                if (Interlocked.Increment(ref warmupsThusFar) == warmupCount)
                {
                    EventBlock.Set();
                }
            };


            for (var i = 0; i < warmupCount;)
            {
                dispatcher.Schedule(warmupWork);
                ++i;
            }
            EventBlock.Wait();
            EventBlock.Reset();
        }
Esempio n. 17
0
    /// <summary>
    /// 発動済みカードの常駐誘発効果を確認し、発動する処理
    /// </summary>
    /// <returns></returns>
    public IEnumerator EffectTriggerCheck(TriggerType type, EventBlock block)
    {
        Card        target = null;
        List <Card> cards  = new List <Card>(Cards);//処理中にCardsから離れる(破壊される)ので、別の場所でデータ保持

        foreach (Card card in cards)
        {
            target = card.GetComponent <Support>();
            if (target != null)
            {
                foreach (CardEffect effect in target.State.Effect)
                {
                    TriggerEffect te = effect as TriggerEffect;
                    if (te != null && te.TriggerType == type)
                    {
                        te.TriggerBlock = block;
                        yield return(StartCoroutine(effect.EffectCall(Constants.BATTLE.FindCardZoneHolder(this), target)));
                    }
                }
                target = null;
            }
        }
    }
Esempio n. 18
0
    //블럭 교환----------------------------------------------
    void MoveBlock(EventBlock eventBlock)
    {
        //인접블럭만 처리
        if ((eventBlock.coord - emptyBlock.coord).sqrMagnitude == 1.0f)
        {
            //변화하는 셔플 블럭 배열
            if (remainShuffle > 0)
            {
                shuffleB[(int)eventBlock.coord.x, (int)eventBlock.coord.y] = emptyBlock;
                shuffleB[(int)emptyBlock.coord.x, (int)emptyBlock.coord.y] = eventBlock;
            }

            //좌표 교환
            Vector2 tempCoord = emptyBlock.coord;
            emptyBlock.coord = eventBlock.coord;
            eventBlock.coord = tempCoord;

            //이미지 교환
            Vector2 tempPosition = emptyBlock.transform.position;
            emptyBlock.transform.position = eventBlock.transform.position;
            eventBlock.SmoothMove(tempPosition, 0.3f);

            //블럭 번호 교환
            int tempNum = numArray.myArray[(int)emptyBlock.coord.x, (int)emptyBlock.coord.y];
            numArray.myArray[(int)emptyBlock.coord.x, (int)emptyBlock.coord.y] = numArray.myArray[(int)eventBlock.coord.x, (int)eventBlock.coord.y];
            numArray.myArray[(int)eventBlock.coord.x, (int)eventBlock.coord.y] = tempNum;

            //움직인 블럭 번호 출력
            print(numArray.myArray[(int)eventBlock.coord.x, (int)eventBlock.coord.y]);
            print(numArray.myArray[(int)emptyBlock.coord.x, (int)emptyBlock.coord.y]);
        }
        if (remainShuffle > 0)
        {
            Invoke("ShuffleBlock", 0.3f);
        }
    }
Esempio n. 19
0
        private EventBlock CreateEventTextBlocks(EventModel eventModel)
        {
            var eventBlock = new EventBlock();
            var username   = eventModel.User != null ? eventModel.User.Username : null;

            // Insert the actor
            eventBlock.Header.Add(new AnchorBlock(username, () => GoToUser(username)));


            if (eventModel.Event == EventModel.Type.Pushed)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }

                var data    = JsonConvert.DeserializeObject <PushedEventDescriptionModel>(eventModel.Description);
                var commits = data.Commits.Count;

                if (eventModel.Repository != null)
                {
                    eventBlock.Tapped = () => GoToCommits(eventModel.Repository, null);
                }

                eventBlock.Header.Add(new TextBlock(" pushed " + commits + " commit" + (commits > 1 ? "s" : string.Empty)));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" to "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }

                if (data.Commits != null)
                {
                    foreach (var commit in data.Commits)
                    {
                        var desc         = (commit.Description ?? "");
                        var sha          = commit.Hash;
                        var firstNewLine = desc.IndexOf("\n", StringComparison.Ordinal);
                        if (firstNewLine <= 0)
                        {
                            firstNewLine = desc.Length;
                        }

                        desc = desc.Substring(0, firstNewLine);
                        var shortSha = commit.Hash;
                        if (shortSha.Length > 6)
                        {
                            shortSha = shortSha.Substring(0, 6);
                        }

                        eventBlock.Body.Add(new AnchorBlock(shortSha, () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Slug, sha)));
                        eventBlock.Body.Add(new TextBlock(" - " + desc + "\n"));
                    }

                    eventBlock.Multilined = true;
                }
                return(eventBlock);
            }

            if (eventModel.Event == EventModel.Type.Commit)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }

                var node = eventModel.Node.Substring(0, eventModel.Node.Length > 6 ? 6 : eventModel.Node.Length);
                eventBlock.Tapped = () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Slug, eventModel.Node);
                eventBlock.Header.Add(new TextBlock(" commited "));
                eventBlock.Header.Add(new AnchorBlock(node, eventBlock.Tapped));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
                var desc = string.IsNullOrEmpty(eventModel.Description) ? "" : eventModel.Description.Replace("\n", " ").Trim();
                eventBlock.Body.Add(new TextBlock(desc));
            }
            else if (eventModel.Event == EventModel.Type.ChangeSetCommentCreated || eventModel.Event == EventModel.Type.ChangeSetCommentDeleted ||
                     eventModel.Event == EventModel.Type.ChangeSetCommentUpdated || eventModel.Event == EventModel.Type.ChangeSetLike || eventModel.Event == EventModel.Type.ChangeSetUnlike)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Tapped = () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Slug, eventModel.Node);
                var nodeBlock = CommitBlock(eventModel);

                if (eventModel.Event == EventModel.Type.ChangeSetCommentCreated)
                {
                    eventBlock.Header.Add(new TextBlock(" commented on commit "));
                }
                else if (eventModel.Event == EventModel.Type.ChangeSetCommentDeleted)
                {
                    eventBlock.Header.Add(new TextBlock(" deleted a comment on commit "));
                }
                else if (eventModel.Event == EventModel.Type.ChangeSetCommentUpdated)
                {
                    eventBlock.Header.Add(new TextBlock(" updated a comment on commit "));
                }
                else if (eventModel.Event == EventModel.Type.ChangeSetLike)
                {
                    eventBlock.Header.Add(new TextBlock(" approved commit "));
                }
                else if (eventModel.Event == EventModel.Type.ChangeSetUnlike)
                {
                    eventBlock.Header.Add(new TextBlock(" unapproved commit "));
                }

                eventBlock.Header.Add(nodeBlock);

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.PullRequestCreated || eventModel.Event == EventModel.Type.PullRequestRejected || eventModel.Event == EventModel.Type.PullRequestSuperseded ||
                     eventModel.Event == EventModel.Type.PullRequestUpdated || eventModel.Event == EventModel.Type.PullRequestFulfilled || eventModel.Event == EventModel.Type.PullRequestLike || eventModel.Event == EventModel.Type.PullRequestUnlike)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Tapped = () => GoToPullRequests(eventModel.Repository);

                if (eventModel.Event == EventModel.Type.PullRequestCreated)
                {
                    eventBlock.Header.Add(new TextBlock(" created pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestRejected)
                {
                    eventBlock.Header.Add(new TextBlock(" rejected pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestSuperseded)
                {
                    eventBlock.Header.Add(new TextBlock(" superseded pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestFulfilled)
                {
                    eventBlock.Header.Add(new TextBlock(" fulfilled pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestUpdated)
                {
                    eventBlock.Header.Add(new TextBlock(" updated pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestLike)
                {
                    eventBlock.Header.Add(new TextBlock(" liked pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestUnlike)
                {
                    eventBlock.Header.Add(new TextBlock(" unliked pull request"));
                }

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.PullRequestCommentCreated || eventModel.Event == EventModel.Type.PullRequestCommentUpdated || eventModel.Event == EventModel.Type.PullRequestCommentDeleted)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Tapped = () => GoToPullRequests(eventModel.Repository);

                if (eventModel.Event == EventModel.Type.PullRequestCommentCreated)
                {
                    eventBlock.Header.Add(new TextBlock(" commented on pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestCommentUpdated)
                {
                    eventBlock.Header.Add(new TextBlock(" updated comment in pull request"));
                }
                else if (eventModel.Event == EventModel.Type.PullRequestCommentDeleted)
                {
                    eventBlock.Header.Add(new TextBlock(" deleted comment in pull request"));
                }

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.IssueComment)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" commented on issue"));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
                eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository);
            }
            else if (eventModel.Event == EventModel.Type.IssueUpdated)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" updated issue"));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
                eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository);
            }
            else if (eventModel.Event == EventModel.Type.IssueReported)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" reported issue"));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }

                eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository);
            }
            else if (eventModel.Event == EventModel.Type.StartFollowUser)
            {
                eventBlock.Header.Add(new TextBlock(" started following a user"));
            }
            else if (eventModel.Event == EventModel.Type.StopFollowUser)
            {
                eventBlock.Header.Add(new TextBlock(" stopped following a user"));
            }
            else if (eventModel.Event == EventModel.Type.StartFollowIssue)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" started following an issue"));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.StopFollowIssue)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" stopped following an issue"));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.StartFollowRepo)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" started following "));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
                eventBlock.Tapped = () => GoToRepository(eventModel.Repository);
            }
            else if (eventModel.Event == EventModel.Type.StopFollowRepo)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" stopped following "));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
                eventBlock.Tapped = () => GoToRepository(eventModel.Repository);
            }
            else if (eventModel.Event == EventModel.Type.CreateRepo)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" created repository "));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
                eventBlock.Tapped = () => GoToRepository(eventModel.Repository);
            }
            else if (eventModel.Event == EventModel.Type.DeleteRepo)
            {
                eventBlock.Header.Add(new TextBlock(" deleted a repository"));
            }
            else if (eventModel.Event == EventModel.Type.WikiUpdated)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Tapped = () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description);
                eventBlock.Header.Add(new TextBlock(" updated wiki page "));
                eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description)));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.WikiCreated)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Tapped = () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description);
                eventBlock.Header.Add(new TextBlock(" created wiki page "));
                eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description)));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.WikiDeleted)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }
                eventBlock.Header.Add(new TextBlock(" deleted wiki page "));
                eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description)));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
            }
            else if (eventModel.Event == EventModel.Type.ForkRepo)
            {
                if (eventModel.Repository == null)
                {
                    return(null);
                }

                eventBlock.Header.Add(new TextBlock(" forked "));
                eventBlock.Tapped = () => GoToRepository(eventModel.Repository);

                if (ReportRepository)
                {
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }
                else
                {
                    eventBlock.Header.Add(new TextBlock("this repository"));
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("No such event handler for " + eventModel.Event);
                return(null);
            }

            return(eventBlock);
        }
Esempio n. 20
0
 /// <summary>
 /// Deletes a event from the database
 /// </summary>
 /// <param name="singleEvent">The event that need to be deleted As EventBlock</param>
 public void DeleteEvent(EventBlock singleEvent)
 {
     // Deleting the event
     Db.Events.Remove(singleEvent);
     Db.SaveChanges();
 }
Esempio n. 21
0
        private EventBlock CreateEventTextBlocks(EventModel eventModel)
        {
            var eventBlock = new EventBlock();
            var repoId     = eventModel.Repo != null ? new RepositoryIdentifier(eventModel.Repo.Name) : new RepositoryIdentifier();
            var username   = eventModel.Actor != null ? eventModel.Actor.Login : null;

            // Insert the actor
            eventBlock.Header.Add(new AnchorBlock(username, () => GoToUser(username)));

            var commitCommentEvent = eventModel.PayloadObject as EventModel.CommitCommentEvent;

            if (commitCommentEvent != null)
            {
                var node = commitCommentEvent.Comment.CommitId.Substring(0, commitCommentEvent.Comment.CommitId.Length > 6 ? 6 : commitCommentEvent.Comment.CommitId.Length);
                eventBlock.Tapped = () => GoToChangeset(repoId, commitCommentEvent.Comment.CommitId);
                eventBlock.Header.Add(new TextBlock(" commented on commit "));
                eventBlock.Header.Add(new AnchorBlock(node, eventBlock.Tapped));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }

                eventBlock.Body.Add(new TextBlock(commitCommentEvent.Comment.Body));
                return(eventBlock);
            }

            var createEvent = eventModel.PayloadObject as EventModel.CreateEvent;

            if (createEvent != null)
            {
                if (createEvent.RefType.Equals("repository"))
                {
                    if (ReportRepository)
                    {
                        eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                        eventBlock.Header.Add(new TextBlock(" created repository "));
                        eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                    }
                    else
                    {
                        eventBlock.Header.Add(new TextBlock(" created this repository"));
                    }
                }
                else if (createEvent.RefType.Equals("branch"))
                {
                    eventBlock.Tapped = () => GoToBranches(repoId);
                    eventBlock.Header.Add(new TextBlock(" created branch "));
                    eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped));

                    if (ReportRepository)
                    {
                        eventBlock.Header.Add(new TextBlock(" in "));
                        eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                    }
                }
                else if (createEvent.RefType.Equals("tag"))
                {
                    eventBlock.Tapped = () => GoToTags(eventModel.Repo);
                    eventBlock.Header.Add(new TextBlock(" created tag "));
                    eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped));

                    if (ReportRepository)
                    {
                        eventBlock.Header.Add(new TextBlock(" in "));
                        eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                    }
                }
            }


            var deleteEvent = eventModel.PayloadObject as EventModel.DeleteEvent;

            if (deleteEvent != null)
            {
                if (deleteEvent.RefType.Equals("branch"))
                {
                    eventBlock.Tapped = () => GoToBranches(repoId);
                    eventBlock.Header.Add(new TextBlock(" deleted branch "));
                }
                else if (deleteEvent.RefType.Equals("tag"))
                {
                    eventBlock.Tapped = () => GoToTags(eventModel.Repo);
                    eventBlock.Header.Add(new TextBlock(" deleted tag "));
                }
                else
                {
                    return(null);
                }

                eventBlock.Header.Add(new AnchorBlock(deleteEvent.Ref, eventBlock.Tapped));
                if (!ReportRepository)
                {
                    return(eventBlock);
                }
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                return(eventBlock);
            }


            if (eventModel.PayloadObject is EventModel.DownloadEvent)
            {
                // Don't show the download event for now...
                return(null);
            }


            var followEvent = eventModel.PayloadObject as EventModel.FollowEvent;

            if (followEvent != null)
            {
                eventBlock.Tapped = () => GoToUser(followEvent.Target.Login);
                eventBlock.Header.Add(new TextBlock(" started following "));
                eventBlock.Header.Add(new AnchorBlock(followEvent.Target.Login, eventBlock.Tapped));
                return(eventBlock);
            }

            /*
             * FORK EVENT
             */
            else if (eventModel.PayloadObject is EventModel.ForkEvent)
            {
                var forkEvent  = (EventModel.ForkEvent)eventModel.PayloadObject;
                var forkedRepo = new EventModel.RepoModel {
                    Id = forkEvent.Forkee.Id, Name = forkEvent.Forkee.FullName, Url = forkEvent.Forkee.Url
                };
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(forkedRepo);
                eventBlock.Header.Add(new TextBlock(" forked "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                eventBlock.Header.Add(new TextBlock(" to "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(forkedRepo));
            }

            /*
             * FORK APPLY EVENT
             */
            else if (eventModel.PayloadObject is EventModel.ForkApplyEvent)
            {
                var forkEvent = (EventModel.ForkApplyEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                eventBlock.Header.Add(new TextBlock(" applied fork to "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                eventBlock.Header.Add(new TextBlock(" on branch "));
                eventBlock.Header.Add(new AnchorBlock(forkEvent.Head, () => GoToBranches(repoId)));
            }

            /*
             * GIST EVENT
             */
            else if (eventModel.PayloadObject is EventModel.GistEvent)
            {
                var gistEvent = (EventModel.GistEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToGistCommand.Execute(gistEvent);

                if (string.Equals(gistEvent.Action, "create", StringComparison.OrdinalIgnoreCase))
                {
                    eventBlock.Header.Add(new TextBlock(" created Gist #"));
                }
                else if (string.Equals(gistEvent.Action, "update", StringComparison.OrdinalIgnoreCase))
                {
                    eventBlock.Header.Add(new TextBlock(" updated Gist #"));
                }
                else if (string.Equals(gistEvent.Action, "fork", StringComparison.OrdinalIgnoreCase))
                {
                    eventBlock.Header.Add(new TextBlock(" forked Gist #"));
                }

                eventBlock.Header.Add(new AnchorBlock(gistEvent.Gist.Id, eventBlock.Tapped));
                eventBlock.Body.Add(new TextBlock(gistEvent.Gist.Description.Replace('\n', ' ').Replace("\r", "").Trim()));
            }

            /*
             * GOLLUM EVENT (WIKI)
             */
            else if (eventModel.PayloadObject is EventModel.GollumEvent)
            {
                var gollumEvent = eventModel.PayloadObject as EventModel.GollumEvent;
                eventBlock.Header.Add(new TextBlock(" modified the wiki in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));

                if (gollumEvent != null && gollumEvent.Pages != null)
                {
                    foreach (var page in gollumEvent.Pages)
                    {
                        var p = page;
                        eventBlock.Body.Add(new AnchorBlock(page.PageName, () => GoToUrlCommand.Execute(p.HtmlUrl)));
                        eventBlock.Body.Add(new TextBlock(" - " + page.Action + "\n"));
                    }

                    eventBlock.Multilined = true;
                }
            }

            /*
             * ISSUE COMMENT EVENT
             */
            else if (eventModel.PayloadObject is EventModel.IssueCommentEvent)
            {
                var commentEvent = (EventModel.IssueCommentEvent)eventModel.PayloadObject;

                if (commentEvent.Issue.PullRequest != null && !string.IsNullOrEmpty(commentEvent.Issue.PullRequest.HtmlUrl))
                {
                    eventBlock.Tapped = () => GoToPullRequest(repoId, commentEvent.Issue.Number);
                    eventBlock.Header.Add(new TextBlock(" commented on pull request "));
                }
                else
                {
                    eventBlock.Tapped = () => GoToIssue(repoId, commentEvent.Issue.Number);
                    eventBlock.Header.Add(new TextBlock(" commented on issue "));
                }

                eventBlock.Header.Add(new AnchorBlock("#" + commentEvent.Issue.Number, eventBlock.Tapped));
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));

                eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim()));
            }

            /*
             * ISSUES EVENT
             */
            else if (eventModel.PayloadObject is EventModel.IssuesEvent)
            {
                var issueEvent = (EventModel.IssuesEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToIssue(repoId, issueEvent.Issue.Number);

                if (string.Equals(issueEvent.Action, "opened", StringComparison.OrdinalIgnoreCase))
                {
                    eventBlock.Header.Add(new TextBlock(" opened issue "));
                }
                else if (string.Equals(issueEvent.Action, "closed", StringComparison.OrdinalIgnoreCase))
                {
                    eventBlock.Header.Add(new TextBlock(" closed issue "));
                }
                else if (string.Equals(issueEvent.Action, "reopened", StringComparison.OrdinalIgnoreCase))
                {
                    eventBlock.Header.Add(new TextBlock(" reopened issue "));
                }

                eventBlock.Header.Add(new AnchorBlock("#" + issueEvent.Issue.Number, eventBlock.Tapped));
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                eventBlock.Body.Add(new TextBlock(issueEvent.Issue.Title.Trim()));
            }

            /*
             * MEMBER EVENT
             */
            else if (eventModel.PayloadObject is EventModel.MemberEvent)
            {
                var memberEvent = (EventModel.MemberEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);

                if (memberEvent.Action.Equals("added"))
                {
                    eventBlock.Header.Add(new TextBlock(" added as a collaborator"));
                }
                else if (memberEvent.Action.Equals("removed"))
                {
                    eventBlock.Header.Add(new TextBlock(" removed as a collaborator"));
                }

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" to "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }
            }

            /*
             * PUBLIC EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PublicEvent)
            {
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" has open sourced "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }
                else
                {
                    eventBlock.Header.Add(new TextBlock(" has been open sourced this repository!"));
                }
            }

            /*
             * PULL REQUEST EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PullRequestEvent)
            {
                var pullEvent = (EventModel.PullRequestEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToPullRequest(repoId, pullEvent.Number);

                if (pullEvent.Action.Equals("closed"))
                {
                    eventBlock.Header.Add(new TextBlock(" closed pull request "));
                }
                else if (pullEvent.Action.Equals("opened"))
                {
                    eventBlock.Header.Add(new TextBlock(" opened pull request "));
                }
                else if (pullEvent.Action.Equals("synchronize"))
                {
                    eventBlock.Header.Add(new TextBlock(" synchronized pull request "));
                }
                else if (pullEvent.Action.Equals("reopened"))
                {
                    eventBlock.Header.Add(new TextBlock(" reopened pull request "));
                }

                eventBlock.Header.Add(new AnchorBlock("#" + pullEvent.PullRequest.Number, eventBlock.Tapped));
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));

                eventBlock.Body.Add(new TextBlock(pullEvent.PullRequest.Title));
            }

            /*
             * PULL REQUEST REVIEW COMMENT EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PullRequestReviewCommentEvent)
            {
                var commentEvent = (EventModel.PullRequestReviewCommentEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToPullRequests(repoId);
                eventBlock.Header.Add(new TextBlock(" commented on pull request "));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }

                eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim()));
            }

            /*
             * PUSH EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PushEvent)
            {
                var pushEvent = (EventModel.PushEvent)eventModel.PayloadObject;

                string branchRef = null;
                if (!string.IsNullOrEmpty(pushEvent.Ref))
                {
                    var lastSlash = pushEvent.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1;
                    branchRef = pushEvent.Ref.Substring(lastSlash);
                }

                if (eventModel.Repo != null)
                {
                    eventBlock.Tapped = () => GoToCommits(eventModel.Repo, pushEvent.Ref);
                }

                eventBlock.Header.Add(new TextBlock(" pushed to "));
                if (branchRef != null)
                {
                    eventBlock.Header.Add(new AnchorBlock(branchRef, () => GoToBranches(repoId)));
                }

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" at "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }

                if (pushEvent.Commits != null)
                {
                    foreach (var commit in pushEvent.Commits)
                    {
                        var desc         = (commit.Message ?? "");
                        var sha          = commit.Sha;
                        var firstNewLine = desc.IndexOf("\n");
                        if (firstNewLine <= 0)
                        {
                            firstNewLine = desc.Length;
                        }

                        desc = desc.Substring(0, firstNewLine);
                        var shortSha = commit.Sha;
                        if (shortSha.Length > 6)
                        {
                            shortSha = shortSha.Substring(0, 6);
                        }

                        eventBlock.Body.Add(new AnchorBlock(shortSha, () => GoToChangeset(repoId, sha)));
                        eventBlock.Body.Add(new TextBlock(" - " + desc + "\n"));
                        eventBlock.Multilined = true;
                    }
                }
            }


            var teamAddEvent = eventModel.PayloadObject as EventModel.TeamAddEvent;

            if (teamAddEvent != null)
            {
                eventBlock.Header.Add(new TextBlock(" added "));

                if (teamAddEvent.User != null)
                {
                    eventBlock.Header.Add(new AnchorBlock(teamAddEvent.User.Login, () => GoToUser(teamAddEvent.User.Login)));
                }
                else if (teamAddEvent.Repo != null)
                {
                    eventBlock.Header.Add(CreateRepositoryTextBlock(new EventModel.RepoModel {
                        Id = teamAddEvent.Repo.Id, Name = teamAddEvent.Repo.FullName, Url = teamAddEvent.Repo.Url
                    }));
                }
                else
                {
                    return(null);
                }

                if (teamAddEvent.Team == null)
                {
                    return(eventBlock);
                }
                eventBlock.Header.Add(new TextBlock(" to team "));
                eventBlock.Header.Add(new AnchorBlock(teamAddEvent.Team.Name, () => { }));
                return(eventBlock);
            }


            var watchEvent = eventModel.PayloadObject as EventModel.WatchEvent;

            if (watchEvent != null)
            {
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                eventBlock.Header.Add(watchEvent.Action.Equals("started") ?
                                      new TextBlock(" starred ") : new TextBlock(" unstarred "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                return(eventBlock);
            }

            var releaseEvent = eventModel.PayloadObject as EventModel.ReleaseEvent;

            if (releaseEvent != null)
            {
                eventBlock.Tapped = () => GoToUrlCommand.Execute(releaseEvent.Release.HtmlUrl);
                eventBlock.Header.Add(new TextBlock(" " + releaseEvent.Action + " release " + releaseEvent.Release.Name));
                return(eventBlock);
            }

            return(eventBlock);
        }
Esempio n. 22
0
    void CheckItem(int idx, EventBlock item, GNewUI.AimEventType evt_type, ref System.Text.StringBuilder err_msg)
    {
        if (string.IsNullOrEmpty(item.Name))
        {
            err_msg.AppendFormat("A setting with no name appears in {0} [{1}] ", evt_type.ToString(), idx.ToString());
        }
        else if (_UIAnim.IsEventBlockExisted(item.Name, idx, evt_type))
        {
            err_msg.AppendFormat("Name {0} duplicated, in {1} [{2}] \n", item.Name, evt_type.ToString(), idx.ToString());
        }

        if (evt_type == AimEventType.Anim)
        {
            AnimEventBlock aeb = item as AnimEventBlock;
            if (aeb != null)
            {
                if (string.IsNullOrEmpty(aeb.AnimName))
                {
                    err_msg.AppendFormat("Anim Name not set in {0} : {1} \n", evt_type.ToString(), aeb.Name);
                }
                if (aeb.Anim == null)
                {
                    err_msg.AppendFormat("Animation not set in {0} : {1} \n", evt_type.ToString(), aeb.Name);
                }
            }
        }
        if (evt_type == AimEventType.Sound)
        {
            SoundEventBlock seb = item as SoundEventBlock;
            if (seb != null)
            {
                if (string.IsNullOrEmpty(seb.SndPath))
                {
                    err_msg.AppendFormat("Sound Path not set in {0} : {1} \n", evt_type.ToString(), seb.Name);
                }
                if (seb.Node == null)
                {
                    err_msg.AppendFormat("Sound Node not set in {0} : {1} \n", evt_type.ToString(), seb.Name);
                }
            }
        }
        else if (evt_type == AimEventType.Fx)
        {
            FxEventBlock fb = item as FxEventBlock;
            if (fb != null)
            {
                if (string.IsNullOrEmpty(fb.FxPath))
                {
                    err_msg.AppendFormat("Fx Path not set in {0} : {1} \n", evt_type.ToString(), fb.Name);
                }
                if (fb.Hook == null)
                {
                    err_msg.AppendFormat("Fx Hook not set in {0} : {1} \n", evt_type.ToString(), fb.Name);
                }
            }
        }
        else if (evt_type == AimEventType.AnimTransition)
        {
            AnimTransition at = item as AnimTransition;
            if (at.Froms.Length != at.CrossFadeTimes.Length)
            {
                err_msg.AppendFormat("AnimTransition data error ->{0} \n", item.Name);
            }
            if (at != null)
            {
                for (int i = 0; i < at.Froms.Length; i++)
                {
                    if (string.IsNullOrEmpty(at.Froms[i]))
                    {
                        err_msg.AppendFormat("Incomplete AnimTransition appears ? ->{0} \n", item.Name);
                        continue;
                    }

                    for (int k = i + 1; k < at.Froms.Length; k++)
                    {
                        if (at.Froms[k] == at.Froms[i])
                        {
                            err_msg.AppendFormat("AnimTransition {0}->{1} duplicated \n", at.Froms[k], item.Name);
                            break;
                        }
                    }
                }
            }
        }
    }
Esempio n. 23
0
        private EventBlock CreateEventTextBlocks(EventModel eventModel)
        {
            var eventBlock = new EventBlock();
			var username = eventModel.User != null ? eventModel.User.Username : null;

            // Insert the actor
			eventBlock.Header.Add(new AnchorBlock(username, () => GoToUser(username)));


			if (eventModel.Event == EventModel.Type.Pushed)
			{
                if (eventModel.Repository == null)
                    return null;

				var data = GetService<CodeFramework.Core.Services.IJsonSerializationService>().Deserialize<PushedEventDescriptionModel>(eventModel.Description);

				if (eventModel.Repository != null)
					eventBlock.Tapped = () => GoToCommits(eventModel.Repository, null);

				eventBlock.Header.Add(new TextBlock(" pushed " + data.TotalCommits + " commit" + (data.TotalCommits > 1 ? "s" : string.Empty)));

                if (ReportRepository)
                {
					eventBlock.Header.Add(new TextBlock(" to "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
                }

				if (data.Commits != null)
				{
					foreach (var commit in data.Commits)
					{
						var desc = (commit.Description ?? "");
						var sha = commit.Hash;
						var firstNewLine = desc.IndexOf("\n", StringComparison.Ordinal);
						if (firstNewLine <= 0)
							firstNewLine = desc.Length;

						desc = desc.Substring(0, firstNewLine);
						var shortSha = commit.Hash;
						if (shortSha.Length > 6)
							shortSha = shortSha.Substring(0, 6);

						eventBlock.Body.Add(new AnchorBlock(shortSha, () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Name, sha)));
						eventBlock.Body.Add(new TextBlock(" - " + desc + "\n"));
					}
				}
				return eventBlock;
			}

			if (eventModel.Event == EventModel.Type.Commit)
			{
                if (eventModel.Repository == null)
                    return null;

				var node = eventModel.Node.Substring(0, eventModel.Node.Length > 6 ? 6 : eventModel.Node.Length);
				eventBlock.Tapped = () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Name, eventModel.Node);
				eventBlock.Header.Add(new TextBlock(" commited "));
				eventBlock.Header.Add(new AnchorBlock(node, eventBlock.Tapped));

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
				var desc = string.IsNullOrEmpty(eventModel.Description) ? "" : eventModel.Description.Replace("\n", " ").Trim();
				eventBlock.Body.Add(new TextBlock(desc));
			}
			else if (eventModel.Event == EventModel.Type.ChangeSetCommentCreated || eventModel.Event == EventModel.Type.ChangeSetCommentDeleted ||
			         eventModel.Event == EventModel.Type.ChangeSetCommentUpdated || eventModel.Event == EventModel.Type.ChangeSetLike || eventModel.Event == EventModel.Type.ChangeSetUnlike)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Tapped = () => GoToChangeset(eventModel.Repository.Owner, eventModel.Repository.Slug, eventModel.Node);
				var nodeBlock = CommitBlock(eventModel);

				if (eventModel.Event == EventModel.Type.ChangeSetCommentCreated)
				{
					eventBlock.Header.Add(new TextBlock(" commented on commit "));
				}
				else if (eventModel.Event == EventModel.Type.ChangeSetCommentDeleted)
				{
					eventBlock.Header.Add(new TextBlock(" deleted a comment on commit "));
				}
				else if (eventModel.Event == EventModel.Type.ChangeSetCommentUpdated)
				{
					eventBlock.Header.Add(new TextBlock(" updated a comment on commit "));
				}
				else if (eventModel.Event == EventModel.Type.ChangeSetLike)
				{
					eventBlock.Header.Add(new TextBlock(" approved commit "));
				}
				else if (eventModel.Event == EventModel.Type.ChangeSetUnlike)
				{
					eventBlock.Header.Add(new TextBlock(" unapproved commit "));
				}

				eventBlock.Header.Add(nodeBlock);

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.PullRequestCreated || eventModel.Event == EventModel.Type.PullRequestRejected || eventModel.Event == EventModel.Type.PullRequestSuperseded ||
			         eventModel.Event == EventModel.Type.PullRequestUpdated || eventModel.Event == EventModel.Type.PullRequestFulfilled || eventModel.Event == EventModel.Type.PullRequestLike || eventModel.Event == EventModel.Type.PullRequestUnlike)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Tapped = () => GoToPullRequests(eventModel.Repository);

				if (eventModel.Event == EventModel.Type.PullRequestCreated)
					eventBlock.Header.Add(new TextBlock(" created pull request"));
				else if (eventModel.Event == EventModel.Type.PullRequestRejected)
					eventBlock.Header.Add(new TextBlock(" rejected pull request"));
				else if (eventModel.Event == EventModel.Type.PullRequestSuperseded)
					eventBlock.Header.Add(new TextBlock(" superseded pull request"));
				else if (eventModel.Event == EventModel.Type.PullRequestFulfilled)
					eventBlock.Header.Add(new TextBlock(" fulfilled pull request"));
				else if (eventModel.Event == EventModel.Type.PullRequestUpdated)
					eventBlock.Header.Add(new TextBlock(" updated pull request"));
				else if (eventModel.Event == EventModel.Type.PullRequestLike)
					eventBlock.Header.Add(new TextBlock(" liked pull request"));
				else if (eventModel.Event == EventModel.Type.PullRequestUnlike)
					eventBlock.Header.Add(new TextBlock(" unliked pull request"));

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.PullRequestCommentCreated || eventModel.Event == EventModel.Type.PullRequestCommentUpdated || eventModel.Event == EventModel.Type.PullRequestCommentDeleted)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Tapped = () => GoToPullRequests(eventModel.Repository);

				if (eventModel.Event == EventModel.Type.PullRequestCommentCreated)
				{
					eventBlock.Header.Add(new TextBlock(" commented on pull request"));
				}
				else if (eventModel.Event == EventModel.Type.PullRequestCommentUpdated)
				{
					eventBlock.Header.Add(new TextBlock(" updated comment in pull request"));
				}
				else if (eventModel.Event == EventModel.Type.PullRequestCommentDeleted)
				{
					eventBlock.Header.Add(new TextBlock(" deleted comment in pull request"));
				}

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.IssueComment)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" commented on issue"));
				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
				eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository);
			}
			else if (eventModel.Event == EventModel.Type.IssueUpdated)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" updated issue"));
				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
				eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository);
			}
			else if (eventModel.Event == EventModel.Type.IssueReported)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" reported issue"));

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}

				eventBlock.Tapped = () => GoToRepositoryIssues(eventModel.Repository);
			}
			else if (eventModel.Event == EventModel.Type.StartFollowUser)
			{
				eventBlock.Header.Add(new TextBlock(" started following a user"));
			}
			else if (eventModel.Event == EventModel.Type.StopFollowUser)
			{
				eventBlock.Header.Add(new TextBlock(" stopped following a user"));
			}
			else if (eventModel.Event == EventModel.Type.StartFollowIssue)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" started following an issue"));
				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.StopFollowIssue)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" stopped following an issue"));
				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.StartFollowRepo)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" started following "));
				if (ReportRepository)
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				eventBlock.Tapped = () => GoToRepository(eventModel.Repository);
			}
			else if (eventModel.Event == EventModel.Type.StopFollowRepo)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" stopped following "));
				if (ReportRepository)
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				eventBlock.Tapped = () => GoToRepository(eventModel.Repository);
			}
			else if (eventModel.Event == EventModel.Type.CreateRepo)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" created repository "));
				if (ReportRepository)
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				eventBlock.Tapped = () => GoToRepository(eventModel.Repository);
			}
			else if (eventModel.Event == EventModel.Type.DeleteRepo)
			{
				eventBlock.Header.Add(new TextBlock(" deleted a repository"));
			}
			else if (eventModel.Event == EventModel.Type.WikiUpdated)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Tapped = () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description);
				eventBlock.Header.Add(new TextBlock(" updated wiki page "));
				eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description)));

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.WikiCreated)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Tapped = () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description);
				eventBlock.Header.Add(new TextBlock(" created wiki page "));
				eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description)));

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.WikiDeleted)
			{
                if (eventModel.Repository == null)
                    return null;
				eventBlock.Header.Add(new TextBlock(" deleted wiki page "));
				eventBlock.Header.Add(new AnchorBlock(eventModel.Description.TrimStart('/'), () => GoToRepositoryWiki(eventModel.Repository, eventModel.Description)));

				if (ReportRepository)
				{
					eventBlock.Header.Add(new TextBlock(" in "));
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				}
			}
			else if (eventModel.Event == EventModel.Type.ForkRepo)
			{
                if (eventModel.Repository == null)
                    return null;

				eventBlock.Header.Add(new TextBlock(" forked "));
				eventBlock.Tapped = () => GoToRepository(eventModel.Repository);

				if (ReportRepository)
					eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repository));
				else
					eventBlock.Header.Add(new TextBlock("this repository"));
			}
			else
			{
				System.Diagnostics.Debug.WriteLine("No such event handler for " + eventModel.Event);
				return null;
			}

			return eventBlock;
        }
Esempio n. 24
0
        private EventBlock CreateEventTextBlocks(EventModel eventModel)
        {
            var eventBlock = new EventBlock();
            var repoId = eventModel.Repo != null ? RepositoryIdentifier.FromFullName(eventModel.Repo.Name) 
                : new RepositoryIdentifier(string.Empty, string.Empty);
            var username = eventModel.Actor != null ? eventModel.Actor.Login : null;

            // Insert the actor
            eventBlock.Header.Add(new AnchorBlock(username, () => GoToUser(username)));

            var commitCommentEvent = eventModel.PayloadObject as EventModel.CommitCommentEvent;
            if (commitCommentEvent != null)
            {
                var node = commitCommentEvent.Comment.CommitId.Substring(0, commitCommentEvent.Comment.CommitId.Length > 6 ? 6 : commitCommentEvent.Comment.CommitId.Length);
                eventBlock.Tapped = () => GoToChangeset(repoId, commitCommentEvent.Comment.CommitId);
                eventBlock.Header.Add(new TextBlock(" commented on commit "));
                eventBlock.Header.Add(new AnchorBlock(node, eventBlock.Tapped));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }

                eventBlock.Body.Add(new TextBlock(commitCommentEvent.Comment.Body));
                return eventBlock;
            }

            var createEvent = eventModel.PayloadObject as EventModel.CreateEvent;
            if (createEvent != null)
            {
                if (createEvent.RefType.Equals("repository"))
                {
                    if (ReportRepository)
                    {
                        eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                        eventBlock.Header.Add(new TextBlock(" created repository "));
                        eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                    }
                    else
                        eventBlock.Header.Add(new TextBlock(" created this repository"));
                }
                else if (createEvent.RefType.Equals("branch"))
                {
                    eventBlock.Tapped = () => GoToBranches(repoId);
                    eventBlock.Header.Add(new TextBlock(" created branch "));
                    eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped));

                    if (ReportRepository)
                    {
                        eventBlock.Header.Add(new TextBlock(" in "));
                        eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                    }
                }
                else if (createEvent.RefType.Equals("tag"))
                {
                    eventBlock.Tapped = () => GoToTags(eventModel.Repo);
                    eventBlock.Header.Add(new TextBlock(" created tag "));
                    eventBlock.Header.Add(new AnchorBlock(createEvent.Ref, eventBlock.Tapped));

                    if (ReportRepository)
                    {
                        eventBlock.Header.Add(new TextBlock(" in "));
                        eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                    }
                }
            }


            var deleteEvent = eventModel.PayloadObject as EventModel.DeleteEvent;
            if (deleteEvent != null)
            {
                if (deleteEvent.RefType.Equals("branch"))
                {
                    eventBlock.Tapped = () => GoToBranches(repoId);
                    eventBlock.Header.Add(new TextBlock(" deleted branch "));
                }
                else if (deleteEvent.RefType.Equals("tag"))
                {
                    eventBlock.Tapped = () => GoToTags(eventModel.Repo);
                    eventBlock.Header.Add(new TextBlock(" deleted tag "));
                }
                else
                    return null;

                eventBlock.Header.Add(new AnchorBlock(deleteEvent.Ref, eventBlock.Tapped));
                if (!ReportRepository) return eventBlock;
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                return eventBlock;
            }


            if (eventModel.PayloadObject is EventModel.DownloadEvent)
            {
                // Don't show the download event for now...
                return null;
            }


            var followEvent = eventModel.PayloadObject as EventModel.FollowEvent;
            if (followEvent != null)
            {
                eventBlock.Tapped = () => GoToUser(followEvent.Target.Login);
                eventBlock.Header.Add(new TextBlock(" started following "));
                eventBlock.Header.Add(new AnchorBlock(followEvent.Target.Login, eventBlock.Tapped));
                return eventBlock;
            }
            /*
             * FORK EVENT
             */
            else if (eventModel.PayloadObject is EventModel.ForkEvent)
            {
                var forkEvent = (EventModel.ForkEvent)eventModel.PayloadObject;
                var forkedRepo = new EventModel.RepoModel {Id = forkEvent.Forkee.Id, Name = forkEvent.Forkee.FullName, Url = forkEvent.Forkee.Url};
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(forkedRepo);
                eventBlock.Header.Add(new TextBlock(" forked "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                eventBlock.Header.Add(new TextBlock(" to "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(forkedRepo));
            }
            /*
             * FORK APPLY EVENT
             */
            else if (eventModel.PayloadObject is EventModel.ForkApplyEvent)
            {
                var forkEvent = (EventModel.ForkApplyEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                eventBlock.Header.Add(new TextBlock(" applied fork to "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                eventBlock.Header.Add(new TextBlock(" on branch "));
                eventBlock.Header.Add(new AnchorBlock(forkEvent.Head, () => GoToBranches(repoId)));
            }
            /*
             * GIST EVENT
             */
            else if (eventModel.PayloadObject is EventModel.GistEvent)
            {
                var gistEvent = (EventModel.GistEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToGistCommand.Execute(gistEvent);

                if (string.Equals(gistEvent.Action, "create", StringComparison.OrdinalIgnoreCase))
                    eventBlock.Header.Add(new TextBlock(" created Gist #"));
                else if (string.Equals(gistEvent.Action, "update", StringComparison.OrdinalIgnoreCase))
                    eventBlock.Header.Add(new TextBlock(" updated Gist #"));
                else if (string.Equals(gistEvent.Action, "fork", StringComparison.OrdinalIgnoreCase))
                    eventBlock.Header.Add(new TextBlock(" forked Gist #"));

                eventBlock.Header.Add(new AnchorBlock(gistEvent.Gist.Id, eventBlock.Tapped));
                eventBlock.Body.Add(new TextBlock(gistEvent.Gist.Description.Replace('\n', ' ').Replace("\r", "").Trim()));
            }
            /*
             * GOLLUM EVENT (WIKI)
             */
            else if (eventModel.PayloadObject is EventModel.GollumEvent)
            {
                var gollumEvent = eventModel.PayloadObject as EventModel.GollumEvent;
                eventBlock.Header.Add(new TextBlock(" modified the wiki in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));

                if (gollumEvent != null && gollumEvent.Pages != null)
                {
                    foreach (var page in gollumEvent.Pages)
                    {
                        var p = page;
                        eventBlock.Body.Add(new AnchorBlock(page.PageName, () => GoToUrlCommand.Execute(p.HtmlUrl)));
                        eventBlock.Body.Add(new TextBlock(" - " + page.Action + "\n"));
                    }

                    eventBlock.Multilined = true;
                }
            }
            /*
             * ISSUE COMMENT EVENT
             */
            else if (eventModel.PayloadObject is EventModel.IssueCommentEvent)
            {
                var commentEvent = (EventModel.IssueCommentEvent)eventModel.PayloadObject;

                if (commentEvent.Issue.PullRequest != null && !string.IsNullOrEmpty(commentEvent.Issue.PullRequest.HtmlUrl))
                {
                    eventBlock.Tapped = () => GoToPullRequest(repoId, commentEvent.Issue.Number);
                    eventBlock.Header.Add(new TextBlock(" commented on pull request "));
                }
                else
                {
                    eventBlock.Tapped = () => GoToIssue(repoId, commentEvent.Issue.Number);
                    eventBlock.Header.Add(new TextBlock(" commented on issue "));
                }

                eventBlock.Header.Add(new AnchorBlock("#" + commentEvent.Issue.Number, eventBlock.Tapped));
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));

                eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim()));
            }
            /*
             * ISSUES EVENT
             */
            else if (eventModel.PayloadObject is EventModel.IssuesEvent)
            {
                var issueEvent = (EventModel.IssuesEvent)eventModel.PayloadObject;
                eventBlock.Tapped  = () => GoToIssue(repoId, issueEvent.Issue.Number);

                if (string.Equals(issueEvent.Action, "opened", StringComparison.OrdinalIgnoreCase))
                    eventBlock.Header.Add(new TextBlock(" opened issue "));
                else if (string.Equals(issueEvent.Action, "closed", StringComparison.OrdinalIgnoreCase))
                    eventBlock.Header.Add(new TextBlock(" closed issue "));
                else if (string.Equals(issueEvent.Action, "reopened", StringComparison.OrdinalIgnoreCase))
                    eventBlock.Header.Add(new TextBlock(" reopened issue "));

                eventBlock.Header.Add(new AnchorBlock("#" + issueEvent.Issue.Number, eventBlock.Tapped));
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                eventBlock.Body.Add(new TextBlock(issueEvent.Issue.Title.Trim()));
            }
            /*
             * MEMBER EVENT
             */
            else if (eventModel.PayloadObject is EventModel.MemberEvent)
            {
                var memberEvent = (EventModel.MemberEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);

                if (memberEvent.Action.Equals("added"))
                    eventBlock.Header.Add(new TextBlock(" added as a collaborator"));
                else if (memberEvent.Action.Equals("removed"))
                    eventBlock.Header.Add(new TextBlock(" removed as a collaborator"));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" to "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }
            }
            /*
             * PUBLIC EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PublicEvent)
            {
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" has open sourced "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }
                else
                    eventBlock.Header.Add(new TextBlock(" has been open sourced this repository!"));
            }
            /*
             * PULL REQUEST EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PullRequestEvent)
            {
                var pullEvent = (EventModel.PullRequestEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToPullRequest(repoId, pullEvent.Number);

                if (pullEvent.Action.Equals("closed"))
                    eventBlock.Header.Add(new TextBlock(" closed pull request "));
                else if (pullEvent.Action.Equals("opened"))
                    eventBlock.Header.Add(new TextBlock(" opened pull request "));
                else if (pullEvent.Action.Equals("synchronize"))
                    eventBlock.Header.Add(new TextBlock(" synchronized pull request "));
                else if (pullEvent.Action.Equals("reopened"))
                    eventBlock.Header.Add(new TextBlock(" reopened pull request "));

                eventBlock.Header.Add(new AnchorBlock("#" + pullEvent.PullRequest.Number, eventBlock.Tapped));
                eventBlock.Header.Add(new TextBlock(" in "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));

                eventBlock.Body.Add(new TextBlock(pullEvent.PullRequest.Title));
            }
            /*
             * PULL REQUEST REVIEW COMMENT EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PullRequestReviewCommentEvent)
            {
                var commentEvent = (EventModel.PullRequestReviewCommentEvent)eventModel.PayloadObject;
                eventBlock.Tapped = () => GoToPullRequests(repoId);
                eventBlock.Header.Add(new TextBlock(" commented on pull request "));
                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" in "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }

                eventBlock.Body.Add(new TextBlock(commentEvent.Comment.Body.Replace('\n', ' ').Replace("\r", "").Trim()));
            }
            /*
             * PUSH EVENT
             */
            else if (eventModel.PayloadObject is EventModel.PushEvent)
            {
                var pushEvent = (EventModel.PushEvent)eventModel.PayloadObject;

                string branchRef = null;
                if (!string.IsNullOrEmpty(pushEvent.Ref))
                {
                    var lastSlash = pushEvent.Ref.LastIndexOf("/", StringComparison.Ordinal) + 1;
                    branchRef = pushEvent.Ref.Substring(lastSlash);
                }

                if (eventModel.Repo != null)
                    eventBlock.Tapped = () => GoToCommits(eventModel.Repo, pushEvent.Ref);

                eventBlock.Header.Add(new TextBlock(" pushed to "));
                if (branchRef != null)
                    eventBlock.Header.Add(new AnchorBlock(branchRef, () => GoToBranches(repoId)));

                if (ReportRepository)
                {
                    eventBlock.Header.Add(new TextBlock(" at "));
                    eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                }

                if (pushEvent.Commits != null)
                {
                    foreach (var commit in pushEvent.Commits)
                    {
                        var desc = (commit.Message ?? "");
                        var sha = commit.Sha;
                        var firstNewLine = desc.IndexOf("\n");
                        if (firstNewLine <= 0)
                            firstNewLine = desc.Length;

                        desc = desc.Substring(0, firstNewLine);
                        var shortSha = commit.Sha;
                        if (shortSha.Length > 6)
                            shortSha = shortSha.Substring(0, 6);

                        eventBlock.Body.Add(new AnchorBlock(shortSha, () => GoToChangeset(repoId, sha)));
                        eventBlock.Body.Add(new TextBlock(" - " + desc + "\n"));
                        eventBlock.Multilined = true;
                    }
                }
            }


            var teamAddEvent = eventModel.PayloadObject as EventModel.TeamAddEvent;
            if (teamAddEvent != null)
            {
                eventBlock.Header.Add(new TextBlock(" added "));

                if (teamAddEvent.User != null)
                    eventBlock.Header.Add(new AnchorBlock(teamAddEvent.User.Login, () => GoToUser(teamAddEvent.User.Login)));
                else if (teamAddEvent.Repo != null)
                    eventBlock.Header.Add(CreateRepositoryTextBlock(new EventModel.RepoModel { Id = teamAddEvent.Repo.Id, Name = teamAddEvent.Repo.FullName, Url = teamAddEvent.Repo.Url }));
                else
                    return null;

                if (teamAddEvent.Team == null) return eventBlock;
                eventBlock.Header.Add(new TextBlock(" to team "));
                eventBlock.Header.Add(new AnchorBlock(teamAddEvent.Team.Name, () => { }));
                return eventBlock;
            }


            var watchEvent = eventModel.PayloadObject as EventModel.WatchEvent;
            if (watchEvent != null)
            {
                eventBlock.Tapped = () => GoToRepositoryCommand.Execute(eventModel.Repo);
                eventBlock.Header.Add(watchEvent.Action.Equals("started") ? 
                    new TextBlock(" starred ") : new TextBlock(" unstarred "));
                eventBlock.Header.Add(CreateRepositoryTextBlock(eventModel.Repo));
                return eventBlock;
            }

            var releaseEvent = eventModel.PayloadObject as EventModel.ReleaseEvent;
            if (releaseEvent != null)
            {
                eventBlock.Tapped = () => GoToUrlCommand.Execute(releaseEvent.Release.HtmlUrl);
                eventBlock.Header.Add(new TextBlock(" " + releaseEvent.Action + " release " + releaseEvent.Release.Name));
                return eventBlock;
            }

            return eventBlock;
        }
Esempio n. 25
0
    /// <summary>
    /// 罠カードの発動待機
    /// </summary>
    /// <param name="trigger">発動できる罠カードの発動条件</param>
    /// <param name="caster">カードの発動権を持つプレイヤー</param>
    /// <returns></returns>
    public IEnumerator TrapPlayTime(TriggerType trigger, Player caster, EventBlock block)
    {
        //Debug.Log("Trap wait... as " + trigger);
        List <Card> cards = caster.GetCanPlayTrapCards(trigger);
        string      text  = "";

        switch (trigger)
        {
        case TriggerType.TakeAttack:
            AttackBlock atkBlock   = block as AttackBlock;
            string      targetName = "";
            GameObject  target     = atkBlock.GetTarget();
            if (target.GetComponent <Player>())
            {
                targetName = "あなた";
            }
            else
            {
                targetName = target.GetComponent <Card>().State.cardName;
            }
            text = "相手が" + targetName + "に攻撃しました";
            break;

        case TriggerType.TakeSkill:
            CardPlayBlock playBlock       = block as CardPlayBlock;
            string        skillName       = playBlock.GetCards()[0].State.cardName;
            string        skillTargetName = "";
            if (playBlock.GetTarget())
            {
                if (playBlock.GetTarget().GetComponent <Player>())
                {
                    skillTargetName = "あなた";
                }
                else
                {
                    skillTargetName = playBlock.GetTarget().GetComponent <Card>().State.cardName;
                }
                skillTargetName += "に";
            }

            text = "相手が" + skillTargetName + skillName + "を発動しました";
            break;

        case TriggerType.DraftStart:
            text = "相手ターン開始時です";
            break;

        case TriggerType.TakeDispCard:
            CardDispBlock dispBlock  = block as CardDispBlock;
            Card          targetCard = dispBlock.GetCards()[0];
            foreach (Card c in cards)
            {
                foreach (CardEffect ce in c.State.Effect)
                {
                    foreach (EffectState es in ce.effectState)
                    {
                        es.SetTarget(targetCard.gameObject);
                    }
                }
            }
            string dispCardName = dispBlock.GetCards()[0].State.cardName;
            text = "相手が" + dispCardName + "を捨てました";
            break;
        }
        text += "\n罠カードを発動しますか?";
        //発動可能なカードがあれば発動確認ウィンドウを出す
        if (cards.Count > 0)
        {
            if (!caster.isAI)
            {
                yield return(StartCoroutine(CardPlayWindow.CPW.CallWindow(text, cards, OnSelectedTrapCard)));
            }
            else
            {
                yield return(StartCoroutine(caster.GetComponent <Scond_AIScript>().Trap(trigger, cards, block)));
            }
        }
    }
        private void WriteLogs(string callerAcctNum, LogType logType, ServiceLogLevel logLevel, string connectorName,
                               string connectorVersion, string docCode,
                               string operation, string serviceUrl, string source, int lineCount, EventBlock eventBlock,
                               string functionName, TimeType timeType, string licenseKey, string message, Boolean writeToLocalFile, Boolean writeToLogEntries, string folderPath)
        {
            try
            {
                string msg = string.Empty;
                if (message == string.Empty)
                {
                    msg = string.Format("LINECOUNT - {0} :: {1} : {2} - {3}",
                                        lineCount,
                                        (eventBlock == EventBlock.InternalFunction) ? functionName : eventBlock.ToString(),
                                        timeType.ToString(),
                                        DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz")
                                        );
                }
                else
                {
                    msg = message;
                }

                string logMessage = string.Empty;
                logMessage = "[";
                logMessage = logMessage + "{\"" + "CallerAcctNum" + "\"" + ":" + "\"" + callerAcctNum + "\"}";
                logMessage = logMessage + "{\"" + "LogType" + "\"" + ":" + "\"" + GetLogTypeAsString(logType) + "\"}";
                logMessage = logMessage + "{\"" + "LogLevel" + "\"" + ":" + "\"" + GetLogLevelAsString(logLevel) + "\"}";
                logMessage = logMessage + "{\"" + "ConnectorName" + "\"" + ":" + "\"" + connectorName + "\"}";
                logMessage = logMessage + "{\"" + "ConnectorVersion" + "\"" + ":" + "\"" + connectorVersion + "\"}";
                logMessage = logMessage + "{\"" + "Operation" + "\"" + ":" + "\"" + operation + "\"}";
                logMessage = logMessage + "{\"" + "ServiceURL" + "\"" + ":" + "\"" + serviceUrl + "\"}";
                logMessage = logMessage + "{\"" + "Source" + "\"" + ":" + "\"" + source + "\"}";
                logMessage = logMessage + "{\"" + "DocCode" + "\"" + ":" + "\"" + docCode + "\"}";
                logMessage = logMessage + "{\"" + "Message" + "\"" + ":" + "\"" + msg + "\"}";
                logMessage = logMessage + "]";

                LogToLogEntries(logMessage);
            }
            catch (Exception ex)
            {
                LogMessages("-----------------------------------------");
                LogMessages("Error while writing logs ");
                LogMessages(ex.Message);
                LogMessages(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    LogMessages(ex.InnerException.ToString());
                }
            }
        }
Esempio n. 27
0
 /// <summary>
 /// 効果の発動
 /// </summary>
 public void AddStack(Player caster, Card card, EffectState state, EventBlock trigger = null)
 {
     StateInit(caster, card, state, trigger);
     new CardEffectBlock(this, card, caster).AddBlock();
     //Constants.BATTLE.AddStack((new CardEffectBlock(this, card)));
 }
Esempio n. 28
0
    public IEnumerator Trap(TriggerType trigger, List <Card> cards, EventBlock block)
    {
        yield return(null);

        Card openTrap = null;

        switch (trigger)
        {
        case TriggerType.TakeAttack:
            AttackBlock atkBlock = block as AttackBlock;
            if (atkBlock == null)
            {
                yield break;
            }
            int damage    = block.GetCaster().AttackPower;
            int needValue = 0;    //必要な最低値
            if (atkBlock.GetTarget().GetComponent <Player>())
            {
                damage -= player.Defence;
                if (damage >= player.Life)
                {
                    needValue = damage - player.Life;
                }
                else if (damage > 0)
                {
                    needValue = 1;
                }
            }
            else
            {
                damage   -= atkBlock.GetTarget().GetComponent <Card>().State.defence;
                needValue = damage + 1;
            }
            foreach (Card c in cards)
            {
                foreach (CardEffect ce in c.State.Effect)
                {
                    foreach (EffectState es in ce.effectState)
                    {
                        if (es.effectType == EffectType.AttackAdd && es.value >= -needValue)
                        {
                            if (openTrap == null || openTrap.State.Cost > c.State.Cost)
                            {
                                openTrap = c;
                            }
                        }
                    }
                }
            }
            break;

        case TriggerType.TakeSkill:
            openTrap = cards[0];
            break;

        case TriggerType.TakeDispCard:
            CardDispBlock disp = block as CardDispBlock;
            if (disp.GetCards()[0].State.cardAligment == player.cardAligment)
            {
                openTrap = cards[0];
            }
            break;

        default:
            openTrap = cards[0];
            break;
        }

        if (openTrap)
        {
            yield return(new WaitForSeconds(0.5f));

            Constants.BATTLE.CardOpen(openTrap);
        }
    }
 public void UsageLog(LogType logType, ServiceLogLevel logLevel, string connectorName, string connectorVersion,
                      string docCode, string operation, string serviceUrl, string source, int lineCount, EventBlock eventBlock, string functionName, TimeType timeType, string callerAcctNum, string licenseKey, String message, Boolean writeToLocalFile, Boolean writeToLogEntries, string folderPath = "")
 {
     try
     {
         InitializeAppender(writeToLocalFile, writeToLogEntries, callerAcctNum, licenseKey, connectorName, folderPath);
         ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state)
         {
             WriteLogs(callerAcctNum, logType, logLevel, connectorName, connectorVersion,
                       docCode, operation, serviceUrl, source, lineCount, eventBlock, functionName, timeType, licenseKey, message,
                       writeToLocalFile, writeToLogEntries, folderPath);
         }), null);
     }
     catch (Exception ex)
     {
         try
         {
             LogMessages("Error in Logging.");
             LogMessages(ex.Message.ToString());
             if (ex.InnerException != null)
             {
                 LogMessages(ex.InnerException.ToString());
             }
         }
         catch (Exception)
         {
         }
     }
 }
Esempio n. 30
0
 /// <summary>
 /// Default constructor
 /// </summary>
 protected AccumulatorBase()
 {
     processor       = new InternalRungeProcessor(this);
     timeMeasurement = new TimeMeasurement(new Func <object>(GetTime));
     children[0]     = new EventBlock();
 }