Esempio n. 1
0
 private void PaperHandler_Reporting(object sender, ObjectArgs e)
 {
     //通告 一个用户下的执行情况
     //if (string.IsNullOrEmpty(m_CurUserName))
     //    return;
     OnRaiseMsgReporting(e);
 }
Esempio n. 2
0
 private void M_Calc_Reporting(object sender, ObjectArgs e)
 {
     if (m_CurUserName.Equals(UserPaper.UserName))
     {
         OnRaiseReporting(e.ObjData);
     }
 }
Esempio n. 3
0
        void view_ClickObject(object sender, ObjectArgs e)
        {
            if (e.Button == MouseButton.Right)
            {
                ShowMenu(e.Position);
                return;
            }

            if (e.Object is Character)
            {
                if (fightMode)
                {
                    AttackCharacter(e.Object as Character);
                }
                else
                {
                    ClickCharacter(e.Object as Character);
                }
            }
            else if (!fightMode && e.Object is DroppedItem)
            {
                if (20 > (charOverlay.SelectedCharacter.Position - e.Object.MapPosition).Length)
                {
                    OnMenuInventory();
                }
                else
                {
                    MoveCharacter(e.Object);
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Invokes an Open Object event.
 /// </summary>
 /// <param name="sender">The object that originates the event.</param>
 /// <param name="objectArgs">The argument used to open the object.</param>
 public void OnObjectOpen(object sender, ObjectArgs objectArgs)
 {
     // If there are any listerners, then multicast the request to open a viewer.
     if (this.ObjectOpen != null)
     {
         this.ObjectOpen(this, objectArgs);
     }
 }
Esempio n. 5
0
        private void OnRaiseFinished(ObjectArgs e)
        {
            FinishedEventHandler handler = AllFinished;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 执行的消息告知
        /// </summary>
        /// <param name="args"></param>
        private void OnRaiseMsgReporting(ObjectArgs args)
        {
            MsgReportEventHandler handler = MsgReporting;

            if (handler != null)
            {
                handler.Invoke(this, args);
            }
        }
Esempio n. 7
0
        private void OnRaiseReporting(ObjectArgs e)
        {
            ReportMsgEventHandler handler = Reporting;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 8
0
        private void ReportMsg()
        {
            string     msg = string.Format("成功处理个数:{0}|出现错误:{1}", HandledNum, ErrorNum);
            ObjectArgs arg = new ObjectArgs()
            {
                ObjData = msg
            };

            OnRaiseMsgReporting(arg);
        }
Esempio n. 9
0
        private void OnRaiseReporting(object msg)
        {
            ObjectArgs e = new ObjectArgs()
            {
                ObjData = msg
            };
            ReportEventHandler handler = Reporting;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Starts a drag-and-drop operation on the FolderList.
        /// </summary>
        /// <param name="sender">The control that is the source of the event.</param>
        /// <param name="e">Arguments associated with the event.</param>
        private void treeView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
        {
            // The 'dragNode' is a static value used for drag-and-drop operations within this control.  We set it here as
            // a static value rather than pass it around because an 'ObjectNode' address is no use outside this control.
            // The 'ObjectArgs' is a more generic version of the selected item that has value to other controls.
            ObjectArgs objectArgs = CreateObjectArgs(dragNode = (ObjectNode)e.Item);

            // Extract the parameters that are useful in describing and opening up an object.  This is the value that will
            // be passed around to other controls that can consume a drag-and-drop operation from the Folder List.
            DataObject dataObject = new DataObject("ObjectArgs", objectArgs);

            // Begin the drag-and-drop operation with the element selected.
            this.DoDragDrop(dataObject, DragDropEffects.Copy | DragDropEffects.Move);
        }
Esempio n. 11
0
    /// <summary>
    ///     Constructs a HttpRequestMessage using bucket/object names from Args.
    ///     Calls overloaded CreateRequest method.
    /// </summary>
    /// <param name="args">The direct descendant of ObjectArgs class, args with populated values from Input</param>
    /// <returns>A HttpRequestMessage</returns>
    internal async Task <HttpRequestMessageBuilder> CreateRequest <T>(ObjectArgs <T> args) where T : ObjectArgs <T>
    {
        ArgsCheck(args);

        var contentType = "application/octet-stream";

        args.Headers?.TryGetValue("Content-Type", out contentType);
        var requestMessageBuilder =
            await CreateRequest(args.RequestMethod,
                                args.BucketName,
                                args.ObjectName,
                                args.Headers,
                                contentType,
                                args.RequestBody).ConfigureAwait(false);

        return(args.BuildRequest(requestMessageBuilder));
    }
Esempio n. 12
0
        //one task

        private void Run(object objData)
        {
            try
            {
                //2.线程 跑

                string url = "http://223.223.176.56:8090/foreground/Book/detail.action?tsid=";
                url += objData;

                string html = "";//HTMLHelper.GetHtml(url, LoginCookie, Header);

                if (string.IsNullOrEmpty(html))
                {
                    //未成功获取 重新加入队列中
                    //等待下次从堆栈取出处理
                    m_TaskQue.Push(objData);
                    //System.Threading.Thread.Sleep(5 * 1000);//休息5s
                    return;
                }


                //todo

                //to save data

                lock (m_HandledNumLock)
                {
                    HandledNum++;
                    //to report
                    ReportMsg();
                }
            }
            catch (Exception ex)
            {
                lock (m_ErrorNumLock)
                {
                    ErrorNum++;
                    ReportMsg();
                }
                StringBuilder msg = new StringBuilder();
                msg.AppendLine("当前时间:" + DateTime.Now);
                msg.AppendLine(ex.Message + ex.StackTrace);
                SLogger.Instance.Writer(SLogLevel.Error, msg.ToString());
            }
            finally
            {
                RunOneTask();
                lock (m_FinishLock)
                {
                    string info = string.Format("hanlerNum:{0}|erorrNum:{1}|totalNum:{2}", HandledNum, ErrorNum, TaskTotalCount);
                    if (IsCompleted && !m_OneFinished)
                    {
                        m_OneFinished = true;
                        ObjectArgs arg = new ObjectArgs()
                        {
                            ObjData = info
                        };
                        OnRaiseFinished(arg);
                        m_State = JobState.End;
                    }
                }
            }
        }
Esempio n. 13
0
        public double CalcTFIDFSimilarity(string paperText1, string paperText2)
        {
            ObjectArgs arg = new ObjectArgs();
            //去掉分隔符,。...
            string txt1 = paperText1;

            txt1 = Regex.Replace(txt1, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", "");

            string txt2 = paperText2;

            txt2 = Regex.Replace(txt2, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", "");

            var segmenter = new JiebaSegmenter();

            JiebaNet.Analyser.TfidfExtractor tfd = new TfidfExtractor(segmenter);
            arg.ObjData = "开始分词";
            OnRaiseReporting(arg);
            Console.WriteLine("开始分词");
            Stopwatch sw = new Stopwatch();

            sw.Start();
            IEnumerable <string> segment1 = segmenter.Cut(txt1);

            IEnumerable <string> segment2 = segmenter.Cut(txt2);

            int num1 = segment1.Count();
            int num2 = segment2.Count();

            Console.WriteLine("文档1分词数:" + num1);

            Console.WriteLine("文档2分词数:" + num2);

            arg.ObjData = "文档1分词数:" + num1 + "\r\n文档2分词数: " + num2;
            OnRaiseReporting(arg);

            IEnumerable <string> seg1 = null; //多的
            IEnumerable <string> seg2 = null; //少的

            if (num1 > num2)
            {
                seg1 = segment1;
                seg2 = segment2;
            }
            else
            {
                seg2 = segment1;
                seg1 = segment2;
            }

            int    maxLength = seg1.Count();
            int    minLength = seg2.Count();
            double similar   = 0;

            //Dictionary<string, double> seg2Dic = CalcTF(seg2);
            string str2 = GetText(seg2);

            for (int i = 0; i + minLength <= maxLength; i++)
            {
                //0-interval
                //1-interval+1
                //2-interval+2 ...
                IEnumerable <string> seg = seg1.Where((item, index) => index > i && index < i + minLength);//取i 到 i+minLength
                //从seg1 中截取与seg2相同数量的词集合seg
                //分别计算词频 seg2的词频只需要计算一次
                //计算cos ===相似度
                //Dictionary<string, double> dic = CalcTF(seg);

                //double s = CalcSimilar(dic, seg2Dic);
                string str    = GetText(seg);
                int    topNum = 500;
                IEnumerable <WordWeightPair> tf_a = tfd.ExtractTagsWithWeight(str2, topNum);
                IEnumerable <WordWeightPair> tf_b = tfd.ExtractTagsWithWeight(str, topNum);

                double molecular     = 0; // 分子
                double denominator_a = 0; // 分母
                double denominator_b = 0;

                Dictionary <string, WordWeightPair> dic_a = new Dictionary <string, WordWeightPair>();
                Dictionary <string, WordWeightPair> dic_b = new Dictionary <string, WordWeightPair>();
                foreach (var a in tf_a)
                {
                    dic_a.Add(a.Word, a);
                }

                foreach (var b in tf_b)
                {
                    dic_b.Add(b.Word, b);
                }

                //Console.WriteLine("两篇文档相似的词有:");

                foreach (var k in dic_a.Keys)
                {
                    WordWeightPair a = dic_a[k];
                    WordWeightPair b;
                    dic_b.TryGetValue(k, out b);
                    denominator_a += a.Weight * a.Weight;

                    molecular += a.Weight * (null == b ? 0 : b.Weight);
                    //if (a != null && b != null)
                    //{

                    //    Console.WriteLine(a.Word + "  TF-IDF词频统计 文档一:" + a.Weight + "|文档二:"
                    //            + b.Weight);
                    //}
                }
                foreach (var k in dic_b.Keys)
                {
                    WordWeightPair b = dic_b[k];
                    denominator_b += b.Weight * b.Weight;
                }
                double s = 0;
                if (denominator_a != 0 && denominator_b != 0)
                {
                    s = (molecular / (Math.Sqrt(denominator_a) * Math.Sqrt(denominator_b)));
                }

                //Console.WriteLine("两篇文档相似度:" + s * 100 + "%");
                if ((i + 1) % 50 == 0)
                {
                    Console.WriteLine(string.Format("第{0}次计算出的相似度:{1}", i + 1, s));

                    arg.ObjData = string.Format("第{0}次计算出的相似度:{1}", i + 1, s);
                    OnRaiseReporting(arg);
                }
                if (s > similar)
                {
                    similar = s;
                }
                if (s >= 0.99)
                {
                    //极高相似度
                    Console.WriteLine(string.Format("第{0}次计算出的相似度:{1}", i + 1, s));

                    arg.ObjData = string.Format("第{0}次计算出的相似度:{1}", i + 1, s);
                    OnRaiseReporting(arg);
                }

                //Console.WriteLine("第"+i+"次花费时间:" + sw.ElapsedMilliseconds / 1000 + "秒");
            }
            sw.Stop();
            Console.WriteLine("两篇文章的相似度:" + similar);

            Console.WriteLine("花费时间:" + sw.ElapsedMilliseconds + "ms");
            arg.ObjData = string.Format("两篇文章的相似度:" + similar + "\r\n花费时间:" + sw.ElapsedMilliseconds + "ms");
            OnRaiseReporting(arg);
            return(similar);
        }
Esempio n. 14
0
        /// <summary>
        /// 计算文章1和文章2的相似度
        /// </summary>
        /// <param name="paperText1">文章1的文本</param>
        /// <param name="paperText2">文章2的文本</param>
        /// <returns></returns>
        public double CalcSimilarity(string paperText1, string paperText2)
        {
            ObjectArgs arg = new ObjectArgs();
            //去掉分隔符,。...
            string txt1 = paperText1;

            txt1 = Regex.Replace(txt1, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", "");

            string txt2 = paperText2;

            txt2 = Regex.Replace(txt2, @"[^a-zA-Z0-9\u4e00-\u9fa5\s]", "");

            var segmenter = new JiebaSegmenter();

            arg.ObjData = "开始分词";
            OnRaiseReporting(arg);
            Console.WriteLine("开始分词");
            Stopwatch sw = new Stopwatch();

            sw.Start();
            IEnumerable <string> segment1 = segmenter.Cut(txt1);

            IEnumerable <string> segment2 = segmenter.Cut(txt2);

            int num1 = segment1.Count();
            int num2 = segment2.Count();

            Console.WriteLine("文档1分词数:" + num1);

            Console.WriteLine("文档2分词数:" + num2);

            arg.ObjData = "文档1分词数:" + num1 + "\r\n文档2分词数: " + num2;
            OnRaiseReporting(arg);

            IEnumerable <string> seg1 = null; //多的
            IEnumerable <string> seg2 = null; //少的

            if (num1 > num2)
            {
                seg1 = segment1;
                seg2 = segment2;
            }
            else
            {
                seg2 = segment1;
                seg1 = segment2;
            }

            int    maxLength = seg1.Count();
            int    minLength = seg2.Count();
            double similar   = 0;
            Dictionary <string, double> seg2Dic = CalcTF(seg2);

            for (int i = 0; i + minLength <= maxLength; i++)
            {
                //0-interval
                //1-interval+1
                //2-interval+2 ...
                IEnumerable <string> seg = seg1.Where((item, index) => index > i && index < i + minLength);//取i 到 i+minLength
                //从seg1 中截取与seg2相同数量的词集合seg
                //分别计算词频 seg2的词频只需要计算一次
                //计算cos ===相似度
                Dictionary <string, double> dic = CalcTF(seg);

                double s = CalcSimilar(dic, seg2Dic);
                if ((i + 1) % 50 == 0)
                {
                    Console.WriteLine(string.Format("第{0}次计算出的相似度:{1}", i + 1, s));

                    arg.ObjData = string.Format("第{0}次计算出的相似度:{1}", i + 1, s);
                    OnRaiseReporting(arg);
                }
                if (s > similar)
                {
                    similar = s;
                }
                if (s >= 0.99)
                {
                    //极高相似度
                    Console.WriteLine(string.Format("第{0}次计算出的相似度:{1}", i + 1, s));

                    arg.ObjData = string.Format("第{0}次计算出的相似度:{1}", i + 1, s);
                    OnRaiseReporting(arg);
                }
                //Console.WriteLine("第"+i+"次花费时间:" + sw.ElapsedMilliseconds / 1000 + "秒");
            }
            sw.Stop();
            Console.WriteLine("两篇文章的相似度:" + similar);

            Console.WriteLine("花费时间:" + sw.ElapsedMilliseconds + "ms");
            arg.ObjData = string.Format("两篇文章的相似度:" + similar + "\r\n花费时间:" + sw.ElapsedMilliseconds + "ms");
            OnRaiseReporting(arg);
            return(similar);
        }
Esempio n. 15
0
        public object GetIdleObject(IRoutingEventArgs args)
        {
            ObjectArgs tmpArgs = args as ObjectArgs;

            return(objectPool.GetIdleObject());
        }
Esempio n. 16
0
        public object GetObject(IRoutingEventArgs args)
        {
            ObjectArgs tmpArgs = args as ObjectArgs;

            return(objectContainer.GetObject(tmpArgs.ScriptType, tmpArgs.ScriptToken, tmpArgs.ObjectToken));
        }