Пример #1
0
        public bool UpsertProfile(CoreProfile profile)
        {
            var doc = new Document <CoreProfile>()
            {
                Id      = profile.ProfileKey,
                Content = profile
            };


            return(helper.Upsert <CoreProfile>(doc));
        }
Пример #2
0
        public JsonResult StartConsumer(FormCollection collection)
        {
            List <Contain> tasklist = HttpContext.Application["TaskList"] as List <Contain>;

            if (tasklist != null)
            {
                string key  = collection["key"];
                string pkey = collection["pkey"];

                ProfileBL   pbl     = new ProfileBL();
                CoreProfile profile = pbl.GetProfile(pkey);

                switch (key)
                {
                case "system":
                    for (int i = 0; i < profile.SystemConsumerNum; i++)
                    {
                        CreateConsumer("mq_system_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveSystem));
                    }
                    break;

                case "operate":
                    for (int i = 0; i < profile.OperateConsumerNum; i++)
                    {
                        CreateConsumer("mq_operate_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveOperate));
                    }
                    break;

                case "exception":
                    for (int i = 0; i < profile.ExceptionConsumerNum; i++)
                    {
                        CreateConsumer("mq_exception_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveException));
                    }
                    break;

                case "normal":
                    for (int i = 0; i < profile.NormalConsumerNum; i++)
                    {
                        CreateConsumer("mq_normal_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveNormal));
                    }
                    break;
                }
            }

            return(Json(new ResultDTO()
            {
                Status = "Success",
                Message = "",
                Data = ""
            }));
            //
        }
Пример #3
0
        // GET: Core/Edit/5
        public ActionResult Edit(string key)
        {
            CoreProfile profile = null;

            if (!string.IsNullOrEmpty(key))
            {
                ProfileBL bl = new ProfileBL();

                profile = bl.GetProfile(key);
            }

            return(View("ProfileDetail", profile));
        }
Пример #4
0
        // POST: Core/Delete/5

        public ActionResult Delete(string key)
        {
            ProfileBL bl = new ProfileBL();

            CoreProfile profile = bl.GetProfile(key);

            StopConsumer(profile.ProjectKey, null);

            bl.RemoveProfile(key);


            List <CoreProfile> profiles = bl.GetProfileList();

            return(View("Profiles", profiles));
        }
Пример #5
0
        private void CreateMQ(CoreProfile profile)
        {
            string[] types = Enum.GetNames(typeof(LogType));


            foreach (string type in types)
            {
                string queue = "", severity = "";

                switch (type)
                {
                case "ExceptionLog":
                    queue    = "mq_exception_" + profile.ProjectKey;
                    severity = "exception";
                    break;

                case "OperateLog":
                    queue    = "mq_operate_" + profile.ProjectKey;
                    severity = "operate";
                    break;

                case "SystemLog":
                    queue    = "mq_system_" + profile.ProjectKey;
                    severity = "system";
                    break;

                case "Normal":
                    queue    = "mq_normal_" + profile.ProjectKey;
                    severity = "normal";
                    break;
                }


                MQInfo info = new MQInfo()
                {
                    HostName     = profile.MQServer,
                    ExchangeName = "direct_" + profile.ProjectKey.ToLower(),
                    ExchangeType = "direct",
                    QueueName    = queue,
                    RoutingKey   = severity
                };


                RabbitMQHelper.CreateMQ(info);
            }
        }
Пример #6
0
        public JsonResult RemoveConsumer(FormCollection collection)
        {
            string profileKey = collection["pkey"];
            string key        = collection["key"];

            ProfileBL   bl      = new ProfileBL();
            CoreProfile profile = bl.GetProfile(profileKey);

            StopConsumer(profile.ProjectKey, key);


            return(Json(new ResultDTO()
            {
                Status = "Success",
                Message = "",
                Data = ""
            }, JsonRequestBehavior.AllowGet));
        }
Пример #7
0
        public JsonResult Upsert(CoreProfile profile)
        {
            try
            {
                profile.ModifyTime = DateTime.Now;
                string key = "";

                if (string.IsNullOrEmpty(profile.ProfileKey))
                {
                    key = profile.ProjectKey + "_profile_" + profile.ModifyTime.ToString("yyyyMMddHHmmssfff");

                    profile.ProfileKey = key;
                }

                ProfileBL bl = new ProfileBL();

                bl.UpsertProfile(profile);


                return(Json(new ResultDTO()
                {
                    Status = "Success",
                    Message = "",
                    Data = ""
                }));
            }
            catch (Exception e)
            {
                return(Json(new ResultDTO()
                {
                    Status = "Fail",
                    Message = "",
                    Data = ""
                }));
            }
        }
Пример #8
0
        public ActionResult InitProfile(string key)
        {
            try
            {
                ProfileBL bl = new ProfileBL();

                CoreProfile profile = bl.GetProfile(key);


                StopConsumer(profile.ProjectKey, null);

                CreateMQ(profile);

                InitHeartData(profile.ProjectKey);

                string[] types = Enum.GetNames(typeof(LogType));

                foreach (string type in types)
                {
                    switch (type)
                    {
                    case "ExceptionLog":

                        for (int i = 0; i < profile.ExceptionConsumerNum; i++)
                        {
                            CreateConsumer("mq_exception_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveException));
                        }

                        break;

                    case "OperateLog":

                        for (int i = 0; i < profile.OperateConsumerNum; i++)
                        {
                            CreateConsumer("mq_operate_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveOperate));
                        }

                        break;

                    case "SystemLog":

                        for (int i = 0; i < profile.SystemConsumerNum; i++)
                        {
                            CreateConsumer("mq_system_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveSystem));
                        }

                        break;

                    case "Normal":

                        for (int i = 0; i < profile.NormalConsumerNum; i++)
                        {
                            CreateConsumer("mq_normal_" + profile.ProjectKey, profile.MQServer, profile.ProjectKey, i, new EventHandler <BasicDeliverEventArgs>(new TrackLogBL(SendHeartData).ResolveNormal));
                        }

                        break;
                    }
                }


                List <CoreProfile> profiles = bl.GetProfileList();

                return(View("Profiles", profiles));
            }
            catch (Exception e)
            {
                return(View("Profiles"));
            }
        }
Пример #9
0
        internal void SyncProfileToDeltas()
        {
            if (CoreProfile.ContainsKey(CoreProfileAttributeName.PublicProfile_ResourceId))
            {
                if (NSMessageHandler.ContactService.Deltas.Profile == null)
                {
                    NSMessageHandler.ContactService.Deltas.Profile = new OwnerProfile();
                }

                NSMessageHandler.ContactService.Deltas.Profile.ResourceID = CoreProfile[CoreProfileAttributeName.PublicProfile_ResourceId].ToString();

                if (CoreProfile.ContainsKey(CoreProfileAttributeName.LastModified))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.DateModified = CoreProfile[CoreProfileAttributeName.LastModified].ToString();
                }
            }


            if (CoreProfile.ContainsKey(CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId))
            {
                NSMessageHandler.ContactService.Deltas.Profile.Photo.ResourceID = CoreProfile[CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId].ToString();
            }

            if (CoreProfile.ContainsKey(CoreProfileAttributeName.UserTileStaticUrl))
            {
                NSMessageHandler.ContactService.Deltas.Profile.Photo.PreAthURL = CoreProfile[CoreProfileAttributeName.UserTileStaticUrl].ToString();
            }



            if (CoreProfile.ContainsKey(CoreProfileAttributeName.ExpressionProfile_ResourceId))
            {
                NSMessageHandler.ContactService.Deltas.Profile.HasExpressionProfile = true;
                if (NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile == null)
                {
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile = new ProfileResource();
                }
                NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.ResourceID = CoreProfile[CoreProfileAttributeName.ExpressionProfile_ResourceId].ToString();

                if (CoreProfile.ContainsKey(CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.Photo.ResourceID = CoreProfile[CoreProfileAttributeName.PictureProfile_UserTileStatic_ResourceId].ToString();
                }



                if (CoreProfile.ContainsKey(CoreProfileAttributeName.ExpressionProfile_DisplayName_LastModified))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.ExpressionProfile.DateModified = CoreProfile[CoreProfileAttributeName.ExpressionProfile_DisplayName_LastModified].ToString();
                }

                if (CoreProfile.ContainsKey(CoreProfileAttributeName.ExpressionProfile_PersonalStatus))
                {
                    NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage = CoreProfile[CoreProfileAttributeName.ExpressionProfile_PersonalStatus].ToString();
                    PersonalMessage newPersonalMessage = PersonalMessage == null ? new PersonalMessage(NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage) : PersonalMessage;
                    newPersonalMessage.Message = NSMessageHandler.ContactService.Deltas.Profile.PersonalMessage;
                    PersonalMessage            = newPersonalMessage;
                }
            }

            NSMessageHandler.ContactService.Deltas.Profile.DisplayName = Name;
            NSMessageHandler.ContactService.Deltas.Save(true);

            if (CoreProfile.ContainsKey(CoreProfileAttributeName.UserTileStaticUrl))
            {
                NSMessageHandler.StorageService.SyncUserTile(CoreProfile[CoreProfileAttributeName.UserTileStaticUrl].ToString(), true,
                                                             delegate(object param)
                {
                    SerializableMemoryStream ms = param as SerializableMemoryStream;
                    if (ms != null)
                    {
                        NSMessageHandler.ContactService.Deltas.Profile.Photo.DisplayImage = ms;
                        NSMessageHandler.ContactService.Deltas.Save(true);
                    }

                    Trace.WriteLineIf(Settings.TraceSwitch.TraceInfo, "Get owner's display image from: " + CoreProfile[CoreProfileAttributeName.UserTileStaticUrl] +
                                      " succeeded.");
                },
                                                             delegate(object param)
                {
                    Exception ex = param as Exception;
                    if (ex != null)
                    {
                        Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "An error occurred while getting owner's display image from:" +
                                          CoreProfile[CoreProfileAttributeName.UserTileStaticUrl] + "\r\n" +
                                          ex.Message);
                    }
                }
                                                             );
            }

            if (Name != PreferredName)
            {
                try
                {
                    NSMessageHandler.SetScreenName(PreferredName);
                    SetName(PreferredName);
                }
                catch (Exception ex)
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, ex.Message);
                }
            }
        }