public async Task <IActionResult> CreateGroup([FromBody] WatchGroupForm watchGroupForm)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            UserProfile userProfile = await _ctx.UserProfiles.FindAsync(user.Id);

            if (userProfile != null)
            {
                var watchGroup = new WatchGroup
                {
                    Id          = Guid.NewGuid().ToString(),
                    Title       = watchGroupForm.Title,
                    Description = watchGroupForm.Description,
                    Owner       = userProfile,
                    AddedNames  = watchGroupForm.AddedUsers.ToArray(),
                };

                await _ctx.WatchGroups.AddAsync(watchGroup);

                await _ctx.SaveChangesAsync();

                return(Ok(watchGroup.Id));
            }

            return(StatusCode(500));
        }
        private List <WatchItem> MapWatchItemsOfTitles(List <string> distinctTitles, WatchGroup watchGroup, WatchItem[] watchGroupItems)
        {
            var watchItems = new List <WatchItem>();

            for (int i = 0; i < distinctTitles.Count; i++)
            {
                var watchItem = new WatchItem
                {
                    Title        = distinctTitles[i],
                    WatchGroupId = watchGroup.Id,
                };
                if (watchGroupItems.Contains(watchItem) == false)
                {
                    watchItems.Add(watchItem);
                }
            }

            return(watchItems);
        }
Example #3
0
        static void InitService()
        {
            AutoInit.Init();

            zkAdaptor = new ZkAdaptor();
            amqpAdaptor = new AmqpAdaptor(ConfigManager.MQIP(), ConfigManager.AMQPPort(),
                ConfigManager.MQUser(), ConfigManager.MQPass());

            ServiceImplementStub.Bind<IWatcherServiceNotifyImpl>(amqpAdaptor, new WatcherServiceImpl());

            //dbClientNotifyDelegate = new DbClientNotifyDelegate(zkAdaptor);
            watcherServiceNotifyDelegate = new WatcherServiceNotifyDelegate(amqpAdaptor);

            amqpAdaptor.BeginReceive();
            zkAdaptor.BeginReceive();

            var toWatch = ConfigManager.Instance.Read<int>("WatcherService", "WatchNum");
            var watchGroups = new List<WatchGroup>();

            for (int i = 1; i <= toWatch; i++)
            {
                var group = new WatchGroup()
                {
                    GroupName = ConfigManager.Instance.Read<string>("WatcherService", "WatchName" + i),
                    Quorum = ConfigManager.Instance.Read<int>("WatcherService", "WatchQuorum" + i),
                    DownAfterPeriod = ConfigManager.Instance.Read<int>("WatcherService", "WatchDownAfter" + i),
                    ParallelSync = ConfigManager.Instance.Read<int>("WatcherService", "WatchParallelSync" + i),
                    FailoverTime = ConfigManager.Instance.Read<int>("WatcherService", "WatchFailoverTimeout" + i),
                };

                group.SetCurrentMaster(new MasterInstance(group)
                {
                    EndPoint = ConfigManager.Instance.Read<EndPoint>("WatcherService", "WatchAddr" + i),
                });

                watchGroups.Add(group);
            }

            watcherManager = new WatcherManager(watchGroups);
        }
        private void Awake()
        {
            name = $"[ {Constants.PackageTitle} : WatchManager ]";

            if (!Settings.DebugMode)
            {
                gameObject.hideFlags = HideFlags.HideInHierarchy;
            }

            var monoBehaviours = FindObjectsOfType <MonoBehaviour>();

            foreach (var monoBehaviour in monoBehaviours)
            {
                IEnumerable <FieldInfo> attrFields = Helpers.GetFieldsWithAttribute <WatchAttribute>(monoBehaviour);

                if (!attrFields.Any())
                {
                    continue;
                }

                var watchOptionsAttribute = (WatchOptionsAttribute)Attribute.GetCustomAttribute(
                    monoBehaviour.GetType(), typeof(WatchOptionsAttribute)
                    );

                var displayType = WatchOptionsAttribute.DisplayType.ScreenSpace;

                if (watchOptionsAttribute != null)
                {
                    displayType = watchOptionsAttribute.displayType;
                }

                WatchGroup watchGroup = Helpers.InstantiatePrefab <WatchGroup>("WatchGroup");
                watchGroup.transform.SetParent(GroupContainer, false);

                watchGroup.Init(monoBehaviour, attrFields, displayType: displayType);
            }
        }
        private void Failover(WatchGroup group)
        {
            var toLift = SelectOneSlave(group.Slaves.Values);

            if (toLift == null)
            {
                throw new Exception("no slave selected");
            }

            Console.WriteLine("failover lift {0} to master", toLift.EndPoint);

            toLift.Server.MakeMaster(ReplicationChangeOptions.Broadcast);

            foreach (var slave in group.Slaves.Values)
            {
                if (slave != toLift)
                {
                    slave.Server.SlaveOf(toLift.EndPoint);
                }
            }
        }
 public MasterInstance(WatchGroup @group) : base(@group)
 {
 }
 public RedisInstanceBase(WatchGroup group)
 {
     Group = group;
 }
 public SlaveInstance(WatchGroup @group) : base(@group)
 {
 }