Ejemplo n.º 1
0
    public static Variable cb_prune_match(Variable vr)
    {
        Cursor c = (Cursor)vr.Fetch();

        // remove as much as possible - don't call this if you still need
        // the match!
        if (c.feedback != null)
        {
            c.feedback.CommitRule();
            c.feedback.bt  = null;
            c.feedback.st  = new State();
            c.feedback.ast = null;
        }

        for (CapInfo it = c.captures; it != null; it = it.prev)
        {
            if (it.cap != null && it.cap.Fetch() is Cursor)
            {
                cb_prune_match(it.cap);
            }
        }

        c.captures = null;
        c.feedback = null;
        c.ast      = null;
        c.xact     = null;
        c.nstate   = null;
        return(vr);
    }
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="control"></param>
        /// <param name="capInfo"></param>
        private void InitControl(Control control, CapInfo capInfo)
        {
            List <string> capValueList = capInfo.GetDataList();

            if (capValueList == null &&
                (capInfo.CapId != TwCap.ICAP_AUTODISCARDBLANKPAGES &&
                 capInfo.CapId != TwCap.ICAP_AUTOMATICBORDERDETECTION &&
                 capInfo.CapId != TwCap.ICAP_AUTOMATICDESKEW))
            {
                control.IsEnabled = false;
                return;
            }
            else
            {
                control.IsEnabled = true;
            }
            // 初始化下拉列表
            if (control is ComboBox)
            {
                ComboBox comboBox = control as ComboBox;
                comboBox.Items.Clear();

                {
                    foreach (string capValue in capValueList)
                    {
                        AddComboBoxItem(capValue, comboBox, capInfo.CapId);
                    }
                }
            }
        }
        // 空白页反勾选
        private void ICAP_AUTODISCARDBLANKPAGES_Unchecked(object sender, RoutedEventArgs e)
        {
            BlankImageThreshold.IsEnabled = false;
            CapInfo capInfo = twSession.GetScannerCap(TwCap.ICAP_AUTODISCARDBLANKPAGES);

            capInfo.CurrentIntStr = "0";
        }
        // 勾选框被反勾选时的处理
        private void CheckBox_UnChecked(object sender, RoutedEventArgs e)
        {
            if (!initFinishedFlag)
            {
                return;
            }
            CheckBox checkBox = e.Source as CheckBox;
            CapInfo  capInfo  = null;
            int      index    = 0;

            for (int i = 0; i < capList.Length; i++)
            {
                TwCap tempCapId = capList[i];
                if (capToControl[tempCapId] as CheckBox == checkBox)
                {
                    index = i;
                    break;
                }
            }
            TwCap capId = capList[index];

            capInfo = twSession.GetScannerCap(capId);
            capInfo.CurrentIntStr = "0";
            SetOneValue((Control)checkBox, capInfo);
            UpdateConfigUi(index + 1, capList.Length - 1);
        }
        /// <summary>
        /// 设置下拉列表的当前值
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="capInfo"></param>
        /// <returns></returns>
        private bool SetCurrentValueOfComboBox(ComboBox comboBox, CapInfo capInfo)
        {
            if (capInfo.CurrentIntStr == null)
            {
                return(false);
            }
            string enumStr    = twSession.ConvertIntStringToEnumString(capInfo.CapId, capInfo.CurrentIntStr);
            string currentStr = null;
            int    i          = comboBox.Items.Count - 1;

            for (; i >= 0; i--)
            {
                string tempStr = (comboBox.Items[i] as ComboBoxItem).Content.ToString();
                if (tempStr == enumStr)
                {
                    comboBox.SelectedIndex = i;
                    currentStr             = tempStr;
                    break;
                }
            }
            if (i < 0)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Process individual messages that arrive via the EventQueue and convert each indvidual event into a format
        /// suitable for processing by the IMessage system
        /// </summary>
        /// <param name="req"></param>
        /// <param name="stage"></param>
        /// <returns></returns>
        private bool EventQueueGetHandler(CapsRequest req, CapsStage stage)
        {
            if (stage == CapsStage.Response && req.Response is OSDMap)
            {
                OSDMap map = (OSDMap)req.Response;

                if (map.ContainsKey("events"))
                {
                    OSDArray eventsArray = (OSDArray)map["events"];

                    for (int i = 0; i < eventsArray.Count; i++)
                    {
                        OSDMap bodyMap = (OSDMap)eventsArray[i];
                        if (OnEventMessageLog != null)
                        {
                            CapInfo     capInfo = new CapInfo(req.Info.URI, req.Info.Sim, bodyMap["message"].AsString());
                            CapsRequest capReq  = new CapsRequest(capInfo);
                            capReq.RequestHeaders  = req.RequestHeaders;
                            capReq.ResponseHeaders = req.ResponseHeaders;
                            capReq.Request         = null; // req.Request;
                            capReq.RawRequest      = null; // req.RawRequest;
                            capReq.RawResponse     = OSDParser.SerializeLLSDXmlBytes(bodyMap);
                            capReq.Response        = bodyMap;

                            OnEventMessageLog(capReq, CapsStage.Response);
                        }
                    }
                }
            }
            return(false);
        }
        public CapInfo ControlToInfo(TextBox txtMa, TextBox txtTen)
        {
            CapInfo ttp = new CapInfo();

            ttp.MaCap  = Convert.ToInt32(txtMa.Text);
            ttp.TenCap = txtTen.Text;
            return(ttp);
        }
Ejemplo n.º 8
0
 private void btnKetThuc_Click(object sender, EventArgs e)
 {
     if (ctrl.KiemTra(txtMa, txtTen))
     {
         cap = ctrl.ControlToInfo(txtMa, txtTen);
         this.DialogResult = DialogResult.OK;
     }
 }
        public CapInfo ListViewItemToInfo(ListViewItem item)
        {
            CapInfo ttp = new CapInfo();

            ttp.MaCap  = Convert.ToInt32(item.Text);
            ttp.TenCap = item.SubItems[1].Text;
            return(ttp);
        }
        /// <summary>
        /// 设置能力的当前值
        /// </summary>
        /// <param name="control"></param>
        /// <param name="capInfo"></param>
        private void SetCurrentValue(Control control, CapInfo capInfo)
        {
            if (!control.IsEnabled)
            {
                return;
            }

            bool   twOk;
            string enumStr = null;

            if (control is ComboBox)
            {
                ComboBox comboBox = control as ComboBox;
                //对于压缩算法和文件格式
                if (capInfo.CapId == TwCap.ICAP_COMPRESSION || capInfo.CapId == TwCap.ICAP_IMAGEFILEFORMAT)
                {
                    CapInfo xferCapInfo = twSession.GetScannerCap(TwCap.ICAP_XferMech);
                    if (xferCapInfo.CurrentIntStr == "0") // native模式
                    {
                        // 只设置到控件
                        bool OK = SetCurrentValueOfComboBox(comboBox, capInfo);
                        if (!OK)
                        {
                            comboBox.SelectedIndex = 0;
                            enumStr = (comboBox.SelectedItem as ComboBoxItem).Content.ToString();
                            capInfo.CurrentIntStr = twSession.ConvertEnumStringToIntString(capInfo.CapId, enumStr);
                        }
                        return;
                    }
                }

                // 设置用户保存的设置
                twOk = SetOneValue(comboBox, capInfo);
                if (twOk)
                {
                    return;
                }
                // 获取默认值
                capInfo.CurrentIntStr = capInfo.DefaultIntStr;
                // 设置默认值
                twOk = SetOneValue(comboBox, capInfo);
                if (twOk)
                {
                    return;
                }
                // 设置默认值失败,选择一个值进行设置
                comboBox.SelectedIndex = comboBox.Items.Count / 2;
                string enumString = (comboBox.SelectedItem as ComboBoxItem).Content.ToString();
                string intString  = twSession.ConvertEnumStringToIntString(capInfo.CapId, enumString);
                capInfo.CurrentIntStr = intString;
                twOk = SetOneValue(comboBox, capInfo);
            }
            else if (control is CheckBox)
            {
                CheckBox checkBox = control as CheckBox;
                SetOneValue(checkBox, capInfo);
            }
        }
        // 空白页勾选
        private void ICAP_AUTODISCARDBLANKPAGES_Checked(object sender, RoutedEventArgs e)
        {
            BlankImageThreshold.IsEnabled = true;
            UInt32  intValue = UInt32.Parse(BlankImageThreshold.Text) * 1024;
            CapInfo capInfo  = twSession.GetScannerCap(TwCap.ICAP_AUTODISCARDBLANKPAGES);

            capInfo.CurrentIntStr = intValue.ToString();
            capInfo.SetCap();
        }
 // 输入框失去焦点时保存值并设置
 private void BlankImageThreshold_LostFocus(object sender, RoutedEventArgs e)
 {
     // 获取空白页大小
     if (BlankImageThreshold.IsEnabled)
     {
         UInt32  intValue = UInt32.Parse(BlankImageThreshold.Text) * 1024;
         CapInfo capInfo  = twSession.GetScannerCap(TwCap.ICAP_AUTODISCARDBLANKPAGES);
         capInfo.CurrentIntStr = intValue.ToString();
         capInfo.SetCap();
     }
 }
        public ListViewItem DataRowToListViewItem(DataRow row)
        {
            ListViewItem item = new ListViewItem();

            item.Text = row["MACAP"].ToString();
            item.SubItems.Add(row["TENCAP"].ToString());

            CapInfo info = ListViewItemToInfo(item);

            item.Tag = info;
            return(item);
        }
Ejemplo n.º 14
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Bạn có muốn xóa không?", "Hoạt Động", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         if (ctrl.KiemTra(txtMa, txtTen))
         {
             CapInfo phong = ctrl.ControlToInfo(txtMa, txtTen);
             ctrl.Xoa(phong);
             ctrl.LayLenListView(listCap);
         }
     }
 }
Ejemplo n.º 15
0
        private void ListFaceObject_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MyFaceObj      myFaceObj = ListFaceObject.SelectedItem as MyFaceObj;
            List <FaceObj> faceObj   = thirft.QueryFaceObj(myFaceObj.fa_ob_tcUuid);

            for (int i = 0; i < 13; i++)
            {
                CapInfo capInfo = new CapInfo();
                cCViewModel.CapInfoList.Add(capInfo);
            }
            cCViewModel.CapInfoList[0].Key   = "人脸uuidID";
            cCViewModel.CapInfoList[0].Value = faceObj[0].TcUuid.ToString();

            cCViewModel.CapInfoList[1].Key   = "姓名";
            cCViewModel.CapInfoList[1].Value = faceObj[0].TcName.ToString();
            //
            cCViewModel.CapInfoList[2].Key   = "类型";
            cCViewModel.CapInfoList[2].Value = GlobalCache.FaceTypeList.Cast <STypeInfo>().FirstOrDefault(x => x.Type == faceObj[0].NType).Description;
            //
            cCViewModel.CapInfoList[3].Key   = "性别";
            cCViewModel.CapInfoList[3].Value = cCViewModel.Sex[faceObj[0].NSex];

            cCViewModel.CapInfoList[4].Key   = "人脸对象添加时间";
            cCViewModel.CapInfoList[4].Value = faceObj[0].DTm.ToString();

            cCViewModel.CapInfoList[5].Key   = "模板识别的年龄";
            cCViewModel.CapInfoList[5].Value = faceObj[0].NAge.ToString();

            cCViewModel.CapInfoList[6].Key   = "人脸备注";
            cCViewModel.CapInfoList[6].Value = faceObj[0].TcRemarks.ToString();

            cCViewModel.CapInfoList[7].Key   = "模板uuid";
            cCViewModel.CapInfoList[7].Value = faceObj[0].Tmplate[0].TcUuid.ToString();

            cCViewModel.CapInfoList[8].Key   = "所属FaceObj的uuid";
            cCViewModel.CapInfoList[8].Value = faceObj[0].Tmplate[0].TcObjid.ToString();

            cCViewModel.CapInfoList[9].Key   = "模板标识键";
            cCViewModel.CapInfoList[9].Value = faceObj[0].Tmplate[0].TcKey.ToString();

            cCViewModel.CapInfoList[10].Key   = "模板序号";
            cCViewModel.CapInfoList[10].Value = faceObj[0].Tmplate[0].NIndex.ToString();

            cCViewModel.CapInfoList[11].Key   = "模板添加时间";
            cCViewModel.CapInfoList[11].Value = faceObj[0].Tmplate[0].DTm.ToString();

            cCViewModel.CapInfoList[12].Key   = "模板备注";
            cCViewModel.CapInfoList[12].Value = faceObj[0].Tmplate[0].TcRemarks.ToString();

            ListViewRegisterInfo.Items.Refresh();
        }
Ejemplo n.º 16
0
 public bool CapNhatCap(CapInfo qh)
 {
     try
     {
         SqlCommand s = new SqlCommand("UPDATE Cap SET TENCap = N'" + qh.TenCap + "' WHERE MACap=" + qh.MaCap);
         ser.Load(s);
         return(true);
     }
     catch (Exception e)
     {
         e.ToString();
         return(false);;
     }
 }
Ejemplo n.º 17
0
 public bool ThemCap(CapInfo qh)
 {
     try
     {
         SqlCommand s = new SqlCommand("INSERT INTO Cap(MACap,TENCap) values(" + qh.MaCap.ToString() + ",N'" + qh.TenCap + "')");
         ser.Load(s);
         return(true);
     }
     catch (Exception e)
     {
         e.ToString();
         return(false);;
     }
 }
Ejemplo n.º 18
0
 public bool XoaCap(CapInfo qh)
 {
     try
     {
         SqlCommand s = new SqlCommand("DELETE Cap where MACap=" + qh.MaCap.ToString());
         ser.Load(s);
         return(true);
     }
     catch (Exception e)
     {
         e.ToString();
         return(false);;
     }
 }
Ejemplo n.º 19
0
        public bool Xoa(CapInfo cap)
        {
            SqlCommand com = new SqlCommand("Delete CAP where MACAP=@ma");

            com.Parameters.Add("@ma", SqlDbType.Int).Value = cap.MaCap;
            try
            {
                ser.Load(com);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
Ejemplo n.º 20
0
        public bool Them(CapInfo cap)
        {
            SqlCommand com = new SqlCommand("Insert into CAP(MACAP,TENCAP) values(@ma,@ten)");

            com.Parameters.Add("@ma", SqlDbType.Int).Value           = cap.MaCap;
            com.Parameters.Add("@ten", SqlDbType.NVarChar, 30).Value = cap.TenCap;
            try
            {
                ser.Load(com);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
Ejemplo n.º 21
0
        public bool Sua(CapInfo cap)
        {
            SqlCommand com = new SqlCommand("Update CAP set TENCAP=@ten where MACAP=@ma");

            com.Parameters.Add("@ma", SqlDbType.Int).Value           = cap.MaCap;
            com.Parameters.Add("@ten", SqlDbType.NVarChar, 30).Value = cap.TenCap;
            try
            {
                ser.Load(com);
                return(true);
            }
            catch (Exception e)
            {
                e.ToString();
                return(false);
            }
        }
Ejemplo n.º 22
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (!boolThem)//Chua chon
            {
                btnThem.Text = "Lưu";
                QLKTX.Controller.CapCtrl cap = new CapCtrl();
                txtMa.Text     = cap.LayMaMax().ToString();
                txtTen.Enabled = true;

                btnSua.Enabled = false;
                btnXoa.Enabled = false;

                btnKetThuc.Text = "Bỏ qua";
                txtTen.Text     = "";
                txtTen.Focus();
                boolThem = true;
            }
            else
            {
                if (txtTen.Text == "")
                {
                    MessageBox.Show("Nhập Tên! Nhâp lại", "Luu", MessageBoxButtons.OK);
                    txtTen.Focus();
                }
                else
                {
                    //Goi ham cap nhat
                    CapInfo qh = new CapInfo();
                    qh.MaCap  = Convert.ToInt32(txtMa.Text);
                    qh.TenCap = txtTen.Text;

                    //Lưu
                    ctrl.ThemCap(qh);
                    boolThem = false;
                    ctrl.DataTableToListView(listCap);


                    btnThem.Text    = "Thêm";
                    btnSua.Enabled  = true;
                    btnXoa.Enabled  = true;
                    btnKetThuc.Text = "Kết thúc";
                    boolThem        = false;
                }
            }
        }
        // 下拉列表变化的响应事件
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!initFinishedFlag)
            {
                return;
            }
            TwCap   capId;
            int     index   = 0;
            Control control = e.Source as Control;

            for (int i = 0; i < capList.Length; i++)
            {
                capId = capList[i];
                if (capToControl[capId] as Control == control)
                {
                    index = i;
                    break;
                }
            }

            capId = capList[index];
            CapInfo capInfo = twSession.GetScannerCap(capId);

            control = capToControl[capId] as Control;
            string enumString = (((ComboBox)control).SelectedItem as ComboBoxItem).Content.ToString();

            capInfo.CurrentIntStr = twSession.ConvertEnumStringToIntString(capId, enumString);
            SetOneValue(control, capInfo);
            UpdateConfigUi(index + 1, capList.Length - 1);

            if (capId == TwCap.ECAP_PAPERSOURCE)
            {
                ComboBoxItem item = ((ComboBox)ECAP_PAPERSOURCE).SelectedItem as ComboBoxItem;
                if (item.Content.ToString() == PaperSouceString.Platen)
                {
                    CAP_DUPLEXENABLED.IsEnabled = false;
                }
                if (item.Content.ToString() == PaperSouceString.ADF)
                {
                    CAP_DUPLEXENABLED.IsEnabled = true;
                }
            }
        }
        public void DataTableToListView(ListViewEx list)
        {
            list.Items.Clear();
            DataTable table = data.LayDSCap();

            foreach (DataRow r in table.Rows)
            {
                ListViewItem item = new ListViewItem();
                item.Text = r["MACAP"].ToString();
                item.SubItems.Add(r["TENCAP"].ToString());

                CapInfo qh = new CapInfo();
                qh.MaCap  = Convert.ToInt32(r["MACAP"]);
                qh.TenCap = r["TENCAP"].ToString();
                item.Tag  = qh;

                list.Items.Add(item);
            }
        }
        private void SetFileFormatInNative(Control control, CapInfo capInfo)
        {
            if (!control.IsEnabled)
            {
                return;
            }

            if (control is ComboBox)
            {
                ComboBox comboBox = control as ComboBox;

                if (capInfo.CurrentIntStr == null)
                {
                    if (capInfo.DefaultIntStr != null)
                    {
                        capInfo.CurrentIntStr = capInfo.DefaultIntStr;
                    }
                    else
                    {
                        comboBox.SelectedIndex = comboBox.Items.Count / 2;
                        string enumString = (comboBox.SelectedItem as ComboBoxItem).Content.ToString();
                        string intString  = twSession.ConvertEnumStringToIntString(capInfo.CapId, enumString);
                        capInfo.CurrentIntStr = intString;
                    }
                }

                string intStr     = capInfo.CurrentIntStr;
                string enumStr    = twSession.ConvertIntStringToEnumString(capInfo.CapId, intStr);
                string currentStr = null;
                for (int i = 0; i < comboBox.Items.Count; i++)
                {
                    string tempStr = (comboBox.Items[i] as ComboBoxItem).Content.ToString();
                    if (tempStr == enumStr)
                    {
                        comboBox.SelectedIndex = i;
                        currentStr             = tempStr;
                        break;
                    }
                }
                return;
            }
        }
Ejemplo n.º 26
0
    // 자 동 저 장.
    private void AutoSave()
    {
        string       filename = Application.persistentDataPath + "/miners_save.txt";
        StreamWriter sw       = new StreamWriter(filename);

        foreach (KeyValuePair <int, Miner> kv in _miners)
        {
            MinerInfo m = new MinerInfo();
            m.id         = kv.Value._idx;
            m.level      = kv.Value._level;
            m.position   = kv.Value.transform.localPosition;
            m.state      = kv.Value._state;
            m.prev_state = kv.Value._prev_state;
            m.speed      = _cur_miners_speed;
            sw.WriteLine(JsonUtility.ToJson(m));
        }
        sw.Close();

        filename = Application.persistentDataPath + "/cap_save.txt";
        sw       = new StreamWriter(filename);
        CapInfo ci = new CapInfo();

        ci.mountain_level     = _mountain_level;
        ci.miners_speed_level = _miners_speed_level;
        sw.WriteLine(JsonUtility.ToJson(ci));
        sw.Close();

        filename = Application.persistentDataPath + "/item_save.txt";
        sw       = new StreamWriter(filename);
        ItemInfo ii = new ItemInfo();

        ii.stun_protection_time = _protect_stun_potion_time;
        ii.party_time           = _party_ticket_time;
        ii.escalator            = _isget_escalator;
        ii.warp         = _isget_warp;
        ii.add_spd_per  = ADDITIONAL_SPEED_PERCENT;
        ii.add_gold_per = ADDITIONAL_GOLD_PERCENT;
        sw.WriteLine(JsonUtility.ToJson(ii));
        sw.Close();
    }
        /// <summary>
        /// 设置一个值到控件和扫描仪
        /// </summary>
        /// <param name="control"></param>
        /// <param name="capInfo"></param>
        /// <returns></returns>
        private bool SetOneValue(Control control, CapInfo capInfo)
        {
            if (control is ComboBox)
            {
                ComboBox comboBox = control as ComboBox;
                bool     OK       = SetCurrentValueOfComboBox(comboBox, capInfo);

                if (OK) // 列表中有该值
                {
                    // 将该值设置到扫描仪
                    bool twOk = twSession.SetCapability(capInfo);
                    if (twOk)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                CheckBox checkBox = control as CheckBox;
                if (capInfo.CurrentIntStr == null)
                {
                    capInfo.CurrentIntStr = "0";
                }
                if (capInfo.CapId == TwCap.ICAP_AUTODISCARDBLANKPAGES)
                {
                    {
                        Int32 intVal = Int32.Parse(capInfo.CurrentIntStr);
                        BlankImageThreshold.Text = (Math.Round((double)intVal / 1024)).ToString();
                    }
                    checkBox.IsChecked = !(capInfo.CurrentIntStr == "0");
                }
                else
                {
                    checkBox.IsChecked = (capInfo.CurrentIntStr == "1");
                }
                return(capInfo.SetCap());
            }
        }
Ejemplo n.º 28
0
        private void btnLuu_Sua_Click(object sender, EventArgs e)
        {
            if (ctrl.KiemTra(txtMa, txtTen))
            {
                CapInfo phong = ctrl.ControlToInfo(txtMa, txtTen);
                ctrl.Sua(phong);
                ctrl.LayLenListView(listCap);

                Updating            = false;
                btnSua.Text         = "Sửa";
                btnXoa.Enabled      = true;
                btnThem.Enabled     = true;
                btnKetThuc.Visible  = true;
                btnLuu_Them.Visible = false;
                btnLuu_Sua.Visible  = false;

                listCap.Enabled = true;

                txtMa.Enabled  = false;
                txtTen.Enabled = false;
            }
        }
        /// <summary>
        /// 更新配置界面,不更新空白页阈值
        /// </summary>
        /// <param name="beginPos"></param>
        private void UpdateConfigUi(int beginPos, int endPos)
        {
            initFinishedFlag = false;
            //1:设置通用能力
            for (int i = beginPos; i < endPos; i++)
            {
                //  设置当前值
                TwCap capId = capList[i];
                twSession.ReadScannerCap(capId);
                CapInfo capInfo = twSession.GetScannerCap(capId);
                Control control = capToControl[capId] as Control;
                // 根据能力值设置控件能力范围
                InitControl(control, capInfo);
                // 设置控件当前值
                SetCurrentValue(control, capInfo);
                if (capId == TwCap.ECAP_PAPERSOURCE)
                {
                    ECAP_PAPERSOURCE.IsEnabled = capInfo.hasPlaten;
                }
            }

            initFinishedFlag = true;
        }
Ejemplo n.º 30
0
        void LoginResponseHandle(XmlRpcResponse response)
        {
            Console.WriteLine(">> LoginResponse ");
            Hashtable hash = (Hashtable)response.Value;
            //Console.WriteLine(" reply length: " + hash.Count + "; IsError? " + response.IsFault);
            if (hash.Count <= 5)
            {
                Console.WriteLine("[Grider]: Login failed");
                return;
            }

            // successful login

            string key = string.Empty;
            if (hash.Contains("seed_capability"))
            {
                key = (string)hash["seed_capability"];
                key = key.Replace(proxy.loginURI, "");
                CapInfo info = null;
                proxy.KnownCaps.TryGetValue(key, out info);
                if (info == null)
                {
                    Console.WriteLine("SeedCap info not found");
                    info = new CapInfo(key, proxy.activeCircuit, "SeedCapability");
                    proxy.KnownCaps[key] = info;
                }
                else
                    Console.WriteLine("SeedCap info found!");
                info.AddDelegate(new CapsDelegate(SeedCapHandler));
            }

            RestoreName(hash);
            CreateUser(hash);
            CreateAgentCircuitData(hash, key);

            CreateAgentForRegion(hash);

            PostAgentToRegion(hash);

            CleanUpResponse(hash);
        }
Ejemplo n.º 31
0
 public void SynPushCapture(string name, IP6 obj)
 {
     captures = new CapInfo(captures, new string[] { name },
             Kernel.NewROScalar(obj));
 }
Ejemplo n.º 32
0
 public CapsRequest(CapInfo info)
 {
     Info = info;
 }
Ejemplo n.º 33
0
        bool SeedCapHandler(CapsRequest req, CapsStage stage)
        {
            Console.WriteLine(">> SeedCapability " + stage.ToString() + " to " + req.Info.URI);

            if (stage != CapsStage.Response) return false;

            if (req.Response.Type == OSDType.Map)
            {
                OSDMap nm = (OSDMap)req.Response;

                // First, let's fix the EventQueue Cap
                if (nm["EventQueueGet"] != null)
                    Console.WriteLine("[GRIDER]: Original EQGet Cap " + nm["EventQueueGet"].AsString());
                else
                    Console.WriteLine("[GRIDER]: SeedCap response did not have EQGet Cap");

                //Agent.NextEQID = UUID.Random().ToString();
                string eqkey = Agent.LocalEQCAP + Agent.NextEQID + "/";

                nm["EventQueueGet"] = OSD.FromString(proxy.loginURI + eqkey);
                Console.WriteLine("[GRIDFER]: New EQGet Cap " + nm["EventQueueGet"].AsString());

                if (!proxy.KnownCaps.ContainsKey(eqkey))
                {
                    CapInfo newCap = new CapInfo(eqkey, req.Info.Sim, eqkey);
                    newCap.AddDelegate(new CapsDelegate(LocalEQHandler));
                    lock (proxy)
                        proxy.KnownCaps[eqkey] = newCap;
                }

                // Then, let's fix the UpdateScriptAgent Cap
                if (nm["UpdateScriptAgent"] != null)
                    Console.WriteLine("[GRIDER]: Original UpdateScriptAgent Cap " + nm["UpdateScriptAgent"].AsString());
                else
                    Console.WriteLine("[GRIDER]: SeedCap response did not have UpdateScriptAgent Cap");
                if (UserInventory.CapsHandlers.ContainsKey("UpdateScriptAgent"))
                {
                    string newcap = (string)UserInventory.CapsHandlers["UpdateScriptAgent"];
                    nm["UpdateScriptAgent"] = OSD.FromString(proxy.loginURI + newcap);
                    nm["UpdateNotecardAgentInventory"] = OSD.FromString(proxy.loginURI + newcap);
                    nm["UpdateScriptAgentInventory"] = OSD.FromString(proxy.loginURI + newcap);
                    if (!proxy.KnownCaps.ContainsKey(newcap))
                    {
                        CapInfo newCap = new CapInfo(newcap, req.Info.Sim, "UpdateScriptAgent");
                        lock (proxy)
                            proxy.KnownCaps[newcap] = newCap;
                    }
                    nm["UpdateScriptAgent"] = OSD.FromString(newcap);
                    nm["UpdateNotecardAgentInventory"] = OSD.FromString(newcap);
                    nm["UpdateScriptAgentInventory"] = OSD.FromString(newcap);

                    Console.WriteLine("[GRIDER]: New UpdateScriptAgent Cap " + nm["UpdateScriptAgent"].AsString());
                }
                else
                    Console.WriteLine("[GRIDER]: UserInventory does not contain UpdateScriptAgent Cap");
                if (UserInventory.CapsHandlers.ContainsKey("NewFileAgentInventory"))
                {
                    string newcap = (string)UserInventory.CapsHandlers["NewFileAgentInventory"];
                    if (!proxy.KnownCaps.ContainsKey(newcap))
                    {
                        CapInfo newCap = new CapInfo(newcap, req.Info.Sim, "NewFileAgentInventory");
                        lock (proxy)
                            proxy.KnownCaps[newcap] = newCap;
                    }
                    nm["NewFileAgentInventory"] = OSD.FromString(newcap);

                    Console.WriteLine("[GRIDER]: New NewFileAgentInventory Cap " + nm["NewFileAgentInventory"].AsString());
                }
                else
                    Console.WriteLine("[GRIDER]: UserInventory does not contain NewFileAgentInventory Cap");

            }

            //Console.WriteLine("---------------");
            //lock (this)
            //{
            //    foreach (KeyValuePair<string, CapInfo> kvp in KnownCaps)
            //    {
            //        Console.WriteLine(" >> Key: " + kvp.Key + "; Value: " + kvp.Value.CapType);
            //    }
            //}
            //Console.WriteLine("---------------");

            return false;
        }
Ejemplo n.º 34
0
 public Cursor(GState g, DynMetaObject klass, int from, int pos, CapInfo captures)
 {
     this.global = g;
     this.captures = captures;
     this.pos = pos;
     this.from = from;
     this.mo = Kernel.MatchMO;
     this.save_klass = klass;
 }
Ejemplo n.º 35
0
        Packet TeleportHandler(Packet packet, IPEndPoint endPoint)
        {
            Console.WriteLine("\n>> TeleportRequest for agent at " + MainAgent.regionEndPoint.ToString());

            TeleportLocationRequestPacket tppack = (TeleportLocationRequestPacket)packet;
            ulong handle = tppack.Info.RegionHandle;
            if (MainAgent.TheRegion.RegionHandle == handle)
                // Let it pass. Let the region deal with it, it's safe.
                return packet;

            // else we deal with it
            string url = "http://" + MainAgent.TheRegion.ExternalHostName + ":" + MainAgent.TheRegion.HttpPort + "/";
            RegionInfo regInfo = OpenSimComms.GetRegionInfo(url, string.Empty, handle);
            Console.WriteLine("[Grider]: Got region info " + regInfo.RegionName + " in " + regInfo.RegionLocX + "-" + regInfo.RegionLocY);

            Vector3 pos = tppack.Info.Position;
            Vector3 lookat = tppack.Info.LookAt;
            Agent newAgent = new Agent(regInfo, pos, lookat);
            newAgent.Go();

            string capsPathOrig = "http://" + regInfo.ExternalHostName + ":" + regInfo.HttpPort
                + "/CAPS/" + /*Agent.agentCircuitData.CapsPath*/ newAgent.CapsSeed + "0000/";
            string capsPath = proxy.loginURI + capsPathOrig;

            IPEndPoint fakeSim = proxy.ProxySim(newAgent.regionEndPoint);

            CapInfo info = new CapInfo(capsPathOrig, newAgent.regionEndPoint, "SeedCapability");
            info.AddDelegate(new CapsDelegate(SeedCapHandler));
            lock (this)
            {
                proxy.KnownCaps[capsPathOrig] = info;
            }

            EventQueueEvent mapES = LLEvents.EnableSimulator(regInfo.RegionHandle, fakeSim);
            EventQueueEvent mapEAC = LLEvents.EstablishAgentCommunication(Agent.agentCircuitData.AgentID, fakeSim.ToString(), capsPath);
            List<EventQueueEvent> l = new List<EventQueueEvent>();
            l.Add(mapES);
            //l.Add(mapEAC);
            EventQueue eq = MainAgent.EQ;
            Console.WriteLine("    >>> Posting events to queue " + eq.id + " related to agent at " + MainAgent.regionEndPoint.ToString());
            eq.SendEvents(l);

            //Thread.Sleep(5);
            EventQueueEvent mapTF = LLEvents.TeleportFinishEvent(regInfo.RegionHandle, 13, fakeSim, 4, 16, capsPath, Agent.agentCircuitData.AgentID);
            eq.SendEvent(mapTF);

            //Thread.Sleep(7000);
            //DisableSimulatorPacket ds = new DisableSimulatorPacket();
            //proxy.InjectPacket(ds, Direction.Incoming);
            //CloseCircuitPacket cc = new CloseCircuitPacket();
            //proxy.InjectPacket(cc, Direction.Incoming);

            oldAgent = MainAgent;
            MainAgent = newAgent;
            proxy.activeCircuit = MainAgent.regionEndPoint;

            Console.WriteLine("[Grider]: MainAgent now at " + MainAgent.regionEndPoint.ToString());
            return null;
        }
Ejemplo n.º 36
0
 public Cursor(GState g, DynMetaObject klass, NState ns, Choice xact, int pos, CapInfo captures)
 {
     this.mo = klass;
     this.xact = xact;
     this.nstate = ns;
     this.global = g;
     this.pos = pos;
     this.captures = captures;
 }
        public bool SuaCap(CapInfo cap)
        {
            CapData qhdt = new CapData();

            return(qhdt.CapNhatCap(cap));
        }
Ejemplo n.º 38
0
        // GenericCheck: replace the sim address in a packet with our proxy address
        private void GenericCheck(ref uint simIP, ref ushort simPort, ref string simCaps, bool active)
        {
            IPAddress sim_ip = new IPAddress((long)simIP);

            IPEndPoint realSim = new IPEndPoint(sim_ip, Convert.ToInt32(simPort));
             	    IPEndPoint fakeSim = ProxySim(realSim);

            if(simCaps != null && simCaps.Length > 0) {
                KnownCaps[simCaps] = new CapInfo(simCaps,realSim,"SeedCapability");
                simCaps = "http://127.0.0.1:8080/"+simCaps;
            }

            Console.WriteLine("FIXUP: "+realSim.ToString()+" -> "+fakeSim.ToString());

                simPort = (ushort)fakeSim.Port;
                int i = 0;
                byte[] bytes = fakeSim.Address.GetAddressBytes();
                simIP = (uint)(bytes[i++] + (bytes[i++] << 8) + (bytes[i++] << 16) + (bytes[i++] << 24));

                if (active)
                    activeCircuit = realSim;
        }
Ejemplo n.º 39
0
 private byte[] CapsFixup(string uri, byte[] data)
 {
     if(!KnownCaps.ContainsKey(uri)) {
         Console.WriteLine("Unknown caps URI: "+uri);
         return data;
     }
     CapInfo cap = KnownCaps[uri];
     object resp = LLSD.LLSDDeserialize(data);
     if(cap.CapType == "SeedCapability") {
         Hashtable m = (Hashtable)resp;
         Hashtable nm = new Hashtable();
         foreach(string key in m.Keys) {
             string val = (string)m[key];
             if(val != null && val != "") {
                 KnownCaps[val] = new CapInfo(val, cap.Sim, key);
                 nm[key] = "http://127.0.0.1:8080/"+val;
             } else {
                 nm[key] = val;
             }
         }
         resp = nm;
     } else if(cap.CapType == "EventQueueGet") {
         Console.WriteLine(LLSD.LLSDDump(resp,0));
         foreach(Hashtable evt in (ArrayList)((Hashtable)resp)["events"]) {
             string message = (string)evt["message"];
             Hashtable body = (Hashtable)evt["body"];
             if(message == "TeleportFinish" || message == "CrossedRegion") {
                 Hashtable info = null;
                 if(message == "TeleportFinish")
                     info = (Hashtable) body["Info"];
                 else
                     info = (Hashtable) body["RegionData"];
                 byte[] bytes = (byte[]) info["SimIP"];
                 uint simIP = (uint)(bytes[3] + (bytes[2] << 8) + (bytes[1] << 16) + (bytes[0] << 24));
                 ushort simPort = (ushort)(long)info["SimPort"];
                 string capsURL = (string)info["SeedCapability"];
                 GenericCheck(ref simIP, ref simPort, ref capsURL, cap.Sim == activeCircuit);
                 info["SeedCapability"] = capsURL;
                 bytes[3] = (byte)(simIP % 256);
                         bytes[2] = (byte)((simIP >> 8) % 256);
                         bytes[1] = (byte)((simIP >> 16) % 256);
                         bytes[0] = (byte)((simIP >> 24) % 256);
                 info["SimIP"] = bytes;
                 info["SimPort"] = (long)simPort;
             }
         }
     }
     return LLSD.LLSDSerialize(resp);
 }
Ejemplo n.º 40
0
 public static Frame Synthetic(Frame th, Cursor parent, string method,
         int from, int to, Variable caplist)
 {
     VarDeque iter = Builtins.start_iter(caplist);
     CapInfo ci = null;
     while (Kernel.IterHasFlat(iter, true)) {
         P6any pair = iter.Shift().Fetch();
         Variable k = (Variable)pair.GetSlot(Kernel.EnumMO, "$!key");
         Variable v = (Variable)pair.GetSlot(Kernel.EnumMO, "$!value");
         ci = new CapInfo(ci, new string[] {
                 k.Fetch().mo.mro_raw_Str.Get(k) }, v);
     }
     Cursor r = new Cursor(parent.global, parent.save_klass, from, to, ci,
             null, method);
     th.info.dylex["$*match"].Set(th, Kernel.NewROScalar(r));
     if (method == "") {
         return th;
     } else {
         return r.global.CallAction(th, method, r);
     }
 }
Ejemplo n.º 41
0
 public Cursor(GState g, STable klass, RxFrame feedback, NState ns, Choice xact, int pos, CapInfo captures)
 {
     this.mo = this.save_klass = klass;
     this.xact = xact;
     this.nstate = ns;
     this.feedback = feedback;
     this.global = g;
     this.pos = pos;
     this.captures = captures;
 }
Ejemplo n.º 42
0
 public Cursor(GState g, STable klass, int from, int pos, CapInfo captures, P6any ast, string reduced)
 {
     this.global = g;
     this.captures = captures;
     this.pos = pos;
     this.ast = ast;
     this.from = from;
     this.mo = Kernel.MatchMO;
     this.save_klass = klass;
     this.reduced = reduced;
 }
Ejemplo n.º 43
0
 public CapInfo(CapInfo prev, string[] names, Variable cap)
 {
     this.prev = prev; this.names = names; this.cap = cap;
 }
Ejemplo n.º 44
0
        private void ProxyLogin(NetworkStream netStream, byte[] content)
        {
            lock(this) {
            // convert the body into an XML-RPC request
            XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(Encoding.UTF8.GetString(content));

            // call the loginRequestDelegate
            if (loginRequestDelegate != null)
                try {
                    loginRequestDelegate(request);
                } catch (Exception e) {
                    Log("exception in login request deligate: " + e.Message, true);
                    Log(e.StackTrace, true);
                }

            // add our userAgent and author to the request
            Hashtable requestParams = new Hashtable();
            if (proxyConfig.userAgent != null)
                requestParams["user-agent"] = proxyConfig.userAgent;
            if (proxyConfig.author != null)
                requestParams["author"] = proxyConfig.author;
            request.Params.Add(requestParams);

            // forward the XML-RPC request to the server
            XmlRpcResponse response = (XmlRpcResponse)request.Send(proxyConfig.remoteLoginUri.ToString(),60000); //added 60 second timeout -- Andrew
            Hashtable responseData = (Hashtable)response.Value;

            // proxy any simulator address given in the XML-RPC response
            if (responseData.Contains("sim_ip") && responseData.Contains("sim_port")) {
                IPEndPoint realSim = new IPEndPoint(IPAddress.Parse((string)responseData["sim_ip"]), Convert.ToUInt16(responseData["sim_port"]));
                IPEndPoint fakeSim = ProxySim(realSim);
                responseData["sim_ip"] = fakeSim.Address.ToString();
                responseData["sim_port"] = fakeSim.Port;
                activeCircuit = realSim;
            }

            // start a new proxy session
            Reset();

            if(responseData.Contains("seed_capability")) {
                KnownCaps[(string)responseData["seed_capability"]] = new CapInfo((string)responseData["seed_capability"],activeCircuit,"SeedCapability");
                responseData["seed_capability"] = "http://127.0.0.1:8080/"+responseData["seed_capability"];
            }

            // call the loginResponseDelegate
            if (loginResponseDelegate != null) {
                try {
                    loginResponseDelegate(response);
                } catch (Exception e) {
                    Log("exception in login response delegate: " + e.Message, true);
                    Log(e.StackTrace, true);
                }
            }

            // forward the XML-RPC response to the client
            StreamWriter writer = new StreamWriter(netStream);
                writer.WriteLine("HTTP/1.0 200 OK");
                    writer.WriteLine("Content-type: text/xml");
                    writer.WriteLine();

            XmlTextWriter responseWriter = new XmlTextWriter(writer);
            XmlRpcResponseSerializer.Singleton.Serialize(responseWriter, response);
            responseWriter.Close(); writer.Close();
            }
        }