예제 #1
0
    private IEnumerator StartSession()
    {
        yield return(new WaitForSeconds(2f));

        RTSession.Connect();
        lobbyManager.gameObject.SetActive(false);
    }
예제 #2
0
 private IEnumerator SendPackets()
 {
     for (var i = 1; i <= 150; i++)
     {
         RTSession.SendData(1, GameSparksRT.DeliveryIntent.RELIABLE, new RTData().SetInt(1, i));
         yield return(new WaitForSeconds(2f));
     }
 }
예제 #3
0
    public void OnEndChat()
    {
        chatManager.gameObject.SetActive(false);

        lobbyManager.gameObject.SetActive(true);
        lobbyManager.UpdatePlayersCount(0);

        RTSession.Disconnect();
        FindPlayers();
    }
예제 #4
0
    private void OnMatchFoundMessage(MatchFoundMessage msg)
    {
        players.Clear();
        players.AddRange(msg.Participants.Where(p => p.PeerId != null).Select(p => new PlayerInfo {
            DisplaName = p.DisplayName, Id = p.Id, Peer = (int)p.PeerId, OnLine = true
        }));

        RTSession.Configure(msg, OnPlayerConnect, OnPlayerDisconnect, OnReady, OnRTPacket);

        lobbyManager.UpdatePlayersCount(players.Count);

        StartCoroutine(StartSession());
    }
        private RTSessionGroup FindSessionGroupForConflictedAction(
            RuntimeEntityModel context,
            RTSession rtSession)
        {
            // find the change group that contains the session
            var sessionGroupQuery =
                from s in context.RTSessionSet
                where s.SessionUniqueId.Equals(rtSession.SessionUniqueId)
                select s.SessionGroup;

            Debug.Assert(sessionGroupQuery.Count() != 0, "session has no parent session group");
            Debug.Assert(sessionGroupQuery.Count() == 1, "session has multiple parent session group");
            return(sessionGroupQuery.First());
        }
        private Session FindSession(Guid sessionGuid, SessionTypeEnum expectedSessionType)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                var sessionQuery =
                    (from rts in context.RTSessionSet
                     where rts.SessionUniqueId == sessionGuid
                     select rts);

                if (sessionQuery.Count() == 0)
                {
                    return(null);
                }

                RTSession rtSession = sessionQuery.First();
                rtSession.SessionGroupReference.Load();
                return(GetSessionFromSessionGroup(rtSession.SessionGroup.GroupUniqueId, expectedSessionType));
            }
        }
예제 #7
0
        /// <summary>
        /// Marks a non-syncworkflow session to be completed
        /// and the parent session group to be completed if all its child
        /// sessions are in "completed (3)" status
        /// </summary>
        private void MigrationSessionCompleted()
        {
            // update the session state to Completed
            //
            // NOTE:
            // The sproc called here through EDM sets the Session *Group* to
            // be completed if all the sibling sessions of the current session (inclusively)
            // are completed.
            var updatedRTSessions = m_context.UpdateMigrationSessionStatusToCompleted(SessionId);

            if (updatedRTSessions.Count() > 0 &&
                WorkFlowType.Frequency == Frequency.OneTime)
            {
                // mark Session Group to be OneTimeCompleted (value: 4)

                // Note: updatedRTSessions has already been enumerated in the EDM imported function UpdateMigrationSessionStatusToCompleted
                // We have to ask the Context for a new instance of the RTSession, rather than enumerating on updatedRTSessions
                RTSession rtSession = m_context.RTSessionSet.Where(s => s.SessionUniqueId.Equals(SessionId)).First();
                rtSession.SessionGroupReference.Load();
                if (rtSession.SessionGroup.State == (int)BusinessModelManager.SessionStateEnum.Completed)
                {
                    rtSession.SessionGroup.State = (int)BusinessModelManager.SessionStateEnum.OneTimeCompleted;
                    m_context.TrySaveChanges();
                }
            }

            // update the session sync orchestration state
            if (m_syncStateMachine.TryTransit(PipelineSyncCommand.STOP))
            {
                m_syncStateMachine.CommandTransitFinished(PipelineSyncCommand.STOP);
            }

            var rtSessionRun = m_context.RTSessionRunSet.Where(r => r.Id == m_sessionRunId).FirstOrDefault();

            if (null != rtSessionRun)
            {
                rtSessionRun.State = (int)BusinessModelManager.SessionStateEnum.Completed;
                m_context.TrySaveChanges();
            }
        }
예제 #8
0
        /// <summary>
        /// Gets the current state of the state machine.
        /// </summary>
        /// <param name="ownerType">The type, session or session group, that this state machine represents.</param>
        /// <param name="ownerUniqueId">The GUID used as the unique Id for the subject session or session group.</param>
        /// <returns>The current state of the subject session or session group.</returns>
        public PipelineState GetCurrentState(OwnerType ownerType, Guid ownerUniqueId)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                switch (ownerType)
                {
                case OwnerType.Session:
                    var       sessionQuery = context.RTSessionSet.Where(s => s.SessionUniqueId.Equals(ownerUniqueId));
                    RTSession session      = sessionQuery.FirstOrDefault();

                    if (session != null && session.OrchestrationStatus.HasValue)
                    {
                        return((PipelineState)session.OrchestrationStatus.Value);
                    }
                    else
                    {
                        return(PipelineState.Default);
                    }

                case OwnerType.SessionGroup:
                    var            sessionGroupQuery = context.RTSessionGroupSet.Where(sg => sg.GroupUniqueId.Equals(ownerUniqueId));
                    RTSessionGroup sessionGroup      = sessionGroupQuery.FirstOrDefault();

                    if (sessionGroup != null && sessionGroup.OrchestrationStatus.HasValue)
                    {
                        return((PipelineState)sessionGroupQuery.First().OrchestrationStatus.Value);
                    }
                    else
                    {
                        return(PipelineState.Default);
                    }

                default:
                    Debug.Assert(false, "Invalid OwnerType");
                    throw new InvalidOperationException("Invalid OwnerType");
                }
            }
        }
예제 #9
0
        private IQueryable <RTForceSyncItem> GetRTForceSyncItems(RuntimeEntityModel context)
        {
            var sessionQuery =
                (from session in context.RTSessionSet
                 where session.SessionUniqueId == SessionId
                 select session);

            if (sessionQuery.Count() > 0)
            {
                RTSession rtSession = sessionQuery.First();

                var forceSyncItemQuery =
                    (from forceSyncItem in context.RTForceSyncItemSet
                     where forceSyncItem.SessionId == rtSession.Id &&
                     forceSyncItem.MigrationSource.UniqueId == MigrationSourceid &&
                     ((!(forceSyncItem.Status.HasValue)) || forceSyncItem.Status != (int)ForceSyncItemStatus.Complete)
                     select forceSyncItem);
                return(forceSyncItemQuery);
            }
            else
            {
                return(null);
            }
        }
예제 #10
0
        public Endpoint(
            MonitorWatcher watcher,
            RuntimeEntityModel context,
            RTSession rtSession,
            RTMigrationSource rtMigrationSource,
            bool isRightMigrationSource,
            RTMigrationSource peerMigrationSource)
        {
            m_monitorWatcher = watcher;

            // TODO: Consider moving all of this initialization code to a new EndpointContext class that contains everything that the
            // Poll() method needs to do its job, and then have MonitorWatcher.GetEndpoints() pass the EndpointContext object as the single
            // arg to this constructor.

            this.Context                = context;
            this.RTMigrationSource      = rtMigrationSource;
            this.IsRightMigrationSource = isRightMigrationSource;
            this.PeerRTMigrationSource  = peerMigrationSource;

            BusinessModelManager businessModelManager = new BusinessModelManager();

            if (rtSession.SessionGroup == null)
            {
                rtSession.SessionGroupReference.Load();
            }

            Config = businessModelManager.LoadConfiguration(rtSession.SessionGroup.GroupUniqueId);
            if (Config == null)
            {
                throw new ApplicationException(
                          String.Format(CultureInfo.InvariantCulture, MigrationToolkitResources.SessionGroupNotFound,
                                        rtSession.SessionGroup.GroupUniqueId.ToString()));
            }

            // TODO: Modify ProdviderManager to take a constructor that does not require a Config and that just loads
            // all providers in the Plugins directory, then move this code up to the MonitorWatcher constructor and pass the
            // providerHandlers down as another argument to this constructor
            ProviderManager providerManager = new ProviderManager(Config);
            Dictionary <Guid, ProviderHandler> providerHandlers = providerManager.LoadProvider(new DirectoryInfo(Constants.PluginsFolderName));

            ProviderHandler providerHandler;

            if (!providerHandlers.TryGetValue(this.RTMigrationSource.UniqueId, out providerHandler))
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture,
                                                  MigrationToolkitResources.ProviderHandlerNotLoadedForMigrationSouce,
                                                  this.RTMigrationSource.FriendlyName));
            }

            Debug.Assert(providerHandler.Provider != null);
            SyncMonitorProvider = providerHandler.Provider.GetService(typeof(ISyncMonitorProvider)) as ISyncMonitorProvider;
            if (SyncMonitorProvider == null)
            {
                throw new NotImplementedException(string.Format(CultureInfo.InvariantCulture,
                                                                MigrationToolkitResources.ProviderDoesNotImplementISyncMonitor,
                                                                providerHandler.ProviderName));
            }

            // Find the Session object corresponding to the RTSession
            if (Config.SessionGroup != null && Config.SessionGroup.Sessions != null)
            {
                foreach (var aSession in Config.SessionGroup.Sessions.Session)
                {
                    if (string.Equals(aSession.SessionUniqueId, rtSession.SessionUniqueId.ToString(), StringComparison.Ordinal))
                    {
                        Session = aSession;
                        break;
                    }
                }
            }
            if (Session == null)
            {
                throw new Exception(string.Format(CultureInfo.InvariantCulture,
                                                  MigrationToolkitResources.SessionNotFoundForMigrationSource,
                                                  rtSession.SessionGroup.GroupUniqueId.ToString(), RTMigrationSource.FriendlyName));
            }

            Guid migrationSourceGuid = new Guid(isRightMigrationSource ? Session.RightMigrationSourceUniqueId : Session.LeftMigrationSourceUniqueId);

            Microsoft.TeamFoundation.Migration.BusinessModel.MigrationSource migrationSource = Config.GetMigrationSource(migrationSourceGuid);
            Session.MigrationSources.Add(migrationSourceGuid, migrationSource);

            var serviceContainer = new ServiceContainer();

            serviceContainer.AddService(typeof(ITranslationService), new SyncMonitorTranslationService(Session));
            // We pass null for the global Configuration to the ConfigurationService constructor because its not handy and not needed in this context
            serviceContainer.AddService(typeof(ConfigurationService), new ConfigurationService(null, Session, migrationSourceGuid));
            SyncMonitorProvider.InitializeServices(serviceContainer);
            SyncMonitorProvider.InitializeClient(migrationSource);

            int filterPairIndex = IsRightMigrationSource ? 1 : 0;

            foreach (var filterPair in Session.Filters.FilterPair)
            {
                if (!filterPair.Neglect)
                {
                    m_filterStrings.Add(VCTranslationService.TrimTrailingPathSeparator(filterPair.FilterItem[filterPairIndex].FilterString));
                }
            }
        }
        private ConflictResolutionResult ResolveBySubmitMissingChanges(
            IServiceContainer serviceContainer,
            MigrationConflict conflict,
            ConflictResolutionRule rule,
            out List <MigrationAction> actions)
        {
            actions = null;
            var retVal = new ConflictResolutionResult(false, ConflictResolutionType.Other);

            WITTranslationService translationService = serviceContainer.GetService(typeof(ITranslationService)) as WITTranslationService;

            Debug.Assert(null != translationService, "translationService is not initialized or not a wit translation service");

            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                RTSessionGroup rtSessionGroup = FindSessionGroupForConflictedAction(conflict, context);
                if (null == rtSessionGroup)
                {
                    return(retVal);
                }

                BM.BusinessModelManager bmm = new BM.BusinessModelManager();
                BM.Configuration        sessionGroupConfig = bmm.LoadConfiguration(rtSessionGroup.GroupUniqueId);

                // find target-side migration source config
                var  parentChangeGroup       = FindChangeGroupForConflictedAction(conflict, context);
                Guid targetMigrationSourceId = parentChangeGroup.SourceUniqueId;
                BM.MigrationSource targetMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[targetMigrationSourceId];
                if (null == targetMigrationSourceConfig)
                {
                    return(retVal);
                }

                // find source-side migration source config
                RTSession  rtSession     = FindSessionForConflictedAction(conflict, context);
                BM.Session parentSession = null;
                foreach (BM.Session s in sessionGroupConfig.SessionGroup.Sessions.Session)
                {
                    if (new Guid(s.SessionUniqueId).Equals(rtSession.SessionUniqueId))
                    {
                        parentSession = s;
                        break;
                    }
                }
                if (parentSession == null)
                {
                    return(retVal);
                }
                Guid sourceMigrationSourceId = ((new Guid(parentSession.LeftMigrationSourceUniqueId)).Equals(targetMigrationSourceId))
                    ? new Guid(parentSession.RightMigrationSourceUniqueId) : new Guid(parentSession.LeftMigrationSourceUniqueId);
                BM.MigrationSource sourceMigrationSourceConfig = sessionGroupConfig.SessionGroup.MigrationSources[sourceMigrationSourceId];
                if (null == sourceMigrationSourceConfig)
                {
                    return(retVal);
                }

                string sourceServerUrl   = sourceMigrationSourceConfig.ServerUrl;
                string sourceTeamProject = sourceMigrationSourceConfig.SourceIdentifier;
                string targetServerUrl   = targetMigrationSourceConfig.ServerUrl;
                string targetTeamProject = targetMigrationSourceConfig.SourceIdentifier;

                string srcWorkItemIdStr = TfsMigrationWorkItemStore.GetSourceWorkItemId(conflict.ConflictedChangeAction);
                Debug.Assert(!string.IsNullOrEmpty(srcWorkItemIdStr), "srcWorkItemId is null or empty");
                int srcWorkItemId;
                if (!int.TryParse(srcWorkItemIdStr, out srcWorkItemId))
                {
                    return(retVal);
                }

                string srcRevRanges    = rule.DataFieldDictionary[HistoryNotFoundSubmitMissingChangesAction.DATAKEY_REVISION_RANGE];
                int[]  sourceRevToSync = new int[0];
                if (string.IsNullOrEmpty(srcRevRanges))
                {
                    sourceRevToSync = ExtractMissingRevs(conflict.ConflictedChangeAction);
                }
                else
                {
                    if (!IntegerRange.TryParseRangeString(srcRevRanges, out sourceRevToSync))
                    {
                        return(retVal);
                    }
                }
                if (sourceRevToSync.Length == 0)
                {
                    return(retVal);
                }

                try
                {
                    // compute delta from source side
                    TfsWITAnalysisProvider analysisProvider = new TfsWITAnalysisProvider(sourceServerUrl, sourceTeamProject);
                    WorkItem sourceWorkItem = analysisProvider.GetWorkItem(srcWorkItemId);

                    Hist.MigrationAction[] sourceRevDetails = new Hist.MigrationAction[sourceRevToSync.Length];
                    for (int revIndex = 0; revIndex < sourceRevToSync.Length; ++revIndex)
                    {
                        var details = new TfsWITRecordDetails(sourceWorkItem, sourceRevToSync[revIndex]);
                        SanitizeDetails(details);
                        translationService.MapWorkItemTypeFieldValues(
                            sourceWorkItem.Id.ToString(), details.DetailsDocument, sourceMigrationSourceId);

                        TfsConstants.ChangeActionId actionId = (sourceRevToSync[revIndex] == 1 ? TfsConstants.ChangeActionId.Add : TfsConstants.ChangeActionId.Edit);
                        sourceRevDetails[revIndex] = new Hist.MigrationAction(sourceWorkItem.Id.ToString(), details, actionId);
                    }

                    // migrate to target side
                    TfsWITMigrationProvider migrationProvider = new TfsWITMigrationProvider(targetServerUrl, targetTeamProject, string.Empty);
                    Hist.ConversionResult   conversionResult  = migrationProvider.ProcessChangeGroup(sourceRevDetails);

                    // update conversion history
                    ConversionResult convRslt = new ConversionResult(sourceMigrationSourceId, targetMigrationSourceId);
                    convRslt.ChangeId           = HistoryNotFoundResolutionChangeId;
                    convRslt.ContinueProcessing = true;

                    foreach (var itemConvHist in conversionResult.ItemConversionHistory)
                    {
                        convRslt.ItemConversionHistory.Add(new ItemConversionHistory(
                                                               itemConvHist.SourceItemId, itemConvHist.SourceItemVersion, itemConvHist.TargetItemId, itemConvHist.TargetItemVersion));
                    }

                    parentChangeGroup.SessionRunReference.Load();
                    int sessionRunId = parentChangeGroup.SessionRun.Id;
                    convRslt.Save(sessionRunId, sourceMigrationSourceId);
                }
                catch (Exception ex)
                {
                    TraceManager.TraceException(ex);
                    retVal.Comment = ex.ToString();
                    return(retVal);
                }
            }

            retVal.Resolved = true;
            return(retVal);
        }