Ejemplo n.º 1
0
 //public TaskItem TaskObj
 //{
 //    get { return this.m_taskitem; }
 //}
 public TaskSetting(long  itemid,string cmd)
 {
     InitializeComponent();
     m_taskitem = null;
     m_id = itemid;
     m_cmd = cmd;
 }
Ejemplo n.º 2
0
        public bool Init()
        {
            try
            {
                //初始化程序配置数据
                bNeedToSaveCfg = false;
                bIsSetFrmShown = false;
                //sSkinFile = @"skin\PageColor2.ssk";
                //clStyleColor = System.Drawing.SystemColors.Window;

                //初始化通知
                DataSet ds = new DataSet();
                Helper.AddSelect("taskitem", "shortcut,condition,type,fid");
                Helper.AddSelect("notices", "id,info,dur_times,times,condition,is_temp");

                Helper.Fill(ds, "taskitem,notices");

                foreach (DataRow row in ds.Tables["taskitem"].Rows)
                {
                    TaskItem item = new TaskItem();
                    Helper.Row2DbObj(row, item);
                    Trigers.Add(item);
                }
                foreach (DataRow row in ds.Tables["notices"].Rows)
                {
                    Notice item = new Notice();
                    Helper.Row2DbObj(row, item);
                    Trigers.Add(item);
                }

                if (Trigers.Count > 0)
                {
                    TaskThread = new Thread(TaskCallback);
                    //TaskThread.Priority = ThreadPriority.Highest;
                    TaskThread.Start();
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Reads this instance.
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, ConfigData> Read()
        {
            Dictionary<string, ConfigData> datas = null;
            XmlReader reader = null;
            ConfigData data = null;
            SecurityOpr so = null;
            StringReader sr = null;
            try
            {
                datas = new Dictionary<string, ConfigData>();
                so = new SecurityOpr(m_Key);
                //从加密文件中读取出数据,并进行解密
                string buf = so.ReadFromFile(m_Path);
                if (buf.Equals(String.Empty))
                    return datas;
                //去掉XML文件结尾的一些无效的字符,因为在解密过程中,从内存取出的数据为原始字节,
                //因此字节串的长度应该等于2的指数,否则系统会自动在字节串结尾加空字节
                int pos = buf.LastIndexOf('>');
                if (pos != -1)
                    sr = new StringReader(buf.Substring(0, pos + 1));
                else
                    sr = new StringReader(buf);
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.CheckCharacters = false;
                settings.CloseInput = true;
                reader = XmlReader.Create(sr, settings);
                while (reader.Read())
                {
                    if (reader.Name.Equals("program") && reader.IsStartElement())
                    {
                        data = new ConfigData();
                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {
                                Type type = typeof(ConfigData);
                                FieldInfo finfo = type.GetField(reader.Name, BindingFlags.Instance | BindingFlags.NonPublic);

                                if (finfo != null)
                                {
                                    object value = Convert.ChangeType(reader.Value, finfo.FieldType);
                                    finfo.SetValue(data, value);
                                }
                            }
                        }
                    }
                    else if (reader.Name.Equals("path") && reader.IsStartElement())
                    {
                        reader.Read();
                        data.Path = reader.Value.Trim();
                        reader.Read();
                    }
                    else if (reader.Name.Equals("shortcut") && reader.IsStartElement())
                    {
                        reader.Read();
                        data.Shortcut = reader.Value.Trim();
                        reader.Read();
                    }
                    else if ((reader.Name.Equals("notice") || reader.Name.Equals("taskitem"))
                                && reader.IsStartElement())
                    {
                        ITrigerable item;
                        Type type;
                        string name = reader.Name;
                        if (name.Equals("taskitem"))
                        {
                            item = new TaskItem();
                            type = typeof(TaskItem);
                        }
                        else
                        {
                            item = new Notice();
                            type = typeof(Notice);
                        }

                        if (reader.HasAttributes)
                        {
                            while (reader.MoveToNextAttribute())
                            {

                                FieldInfo finfo = type.GetField(reader.Name, BindingFlags.Instance | BindingFlags.NonPublic);

                                if (finfo != null)
                                {
                                    object value = Convert.ChangeType(reader.Value, finfo.FieldType);
                                    finfo.SetValue(item, value);
                                }
                            }
                        }
                        //多一份拷贝,否则在修改运行任务的时候,扫描对象和修改对象为同一个,有可能会造成冲突
                        //虽然冲突没有什么大问题,现在的概率也较小,但这样不太好。
                        //if (name.Equals("taskitem"))
                        //    data.TaskItem = item.Clone() as TaskItem;

                        GlobalVar.Instanse.Trigers.Add(item);
                    }
                    else if (reader.Name.Equals("program") && !reader.IsStartElement())
                    {
                        datas.Add(data.Shortcut, data);
                    }
                }
            }
            catch (FileNotFoundException)
            {

            }
            catch (System.Xml.XmlException)
            {
                GlobalVar.Tip.Error("XML文档格式错误");
            }
            catch (Exception ex)
            {

                GlobalVar.Tip.Error(ex.Message);
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }

            GlobalVar.Helper.AddInsert("programs", "shortcut,path,is_auto_run,title");
                DataTable dt = new DataTable("programs");
                GlobalVar.Helper.MakeSchemaFromObj(dt, typeof(ConfigData));

                foreach (KeyValuePair<string, ConfigData> pair in datas)
                {

                    ConfigData d = pair.Value;
                    GlobalVar.Helper.FillDataFromObj(dt, d);
                }
                GlobalVar.Helper.Update(dt);
            return datas;
        }
Ejemplo n.º 4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string sFld = "shortcut,fid,type,condition";
            GlobalVar.Helper.AddCustomParam("id", m_id);
            DataRowState state = DataRowState.Modified;
            if (cbClose.Checked == true)
            {
                m_taskitem = null;
                this.DialogResult = DialogResult.OK;
                GlobalVar.Helper.ExcuteSQL("delete from taskitem where fid=@id",false);
                GlobalVar.Helper.ExcuteSQL("update programs set has_taskitem=0 where id=@id");
                return;
            }
            if (m_taskitem == null)
            {
                GlobalVar.Helper.AddInsert("taskitem",sFld);
                state = DataRowState.Added;
                m_taskitem = new TaskItem();
            }else
            {
                GlobalVar.Helper.AddUpdate("taskitem", sFld,"fid");
            }
            m_taskitem.Id = m_id;
            m_taskitem.Name = m_cmd;
            if (tcSet.SelectedTab == tpDay)
                AddDayTask();
            else if (tcSet.SelectedTab == tpWeek)
                AddWeekTask();

            DataTable table = new DataTable("taskitem");
            GlobalVar.Helper.FillDataFromObj(table, m_taskitem, state);
            GlobalVar.Helper.Update(table);
            GlobalVar.Helper.ExcuteSQL("update programs set has_taskitem=1 where id=@id");
            //MessageBox.Show(m_sCondition);
        }
Ejemplo n.º 5
0
 private void TaskSetting_Load(object sender, EventArgs e)
 {
     tpDay.BackColor = GlobalVar.Instanse.StyleColor;
     tpWeek.BackColor = GlobalVar.Instanse.StyleColor;
     tpMonth.BackColor = GlobalVar.Instanse.StyleColor;
     tpYear.BackColor = GlobalVar.Instanse.StyleColor;
     GlobalVar.Helper.AddCustomParam("fid", m_id);
     GlobalVar.Helper.AddSelect("taskitem", "fid,condition,type,shortcut","fid");
     DataTable table = new DataTable("taskitem");
     GlobalVar.Helper.Fill(ref table);
     if(table.Rows.Count != 0)
     {
         m_taskitem = new TaskItem();
         GlobalVar.Helper.Row2DbObj(table.Rows[0], m_taskitem);
     }
     //this.Update();
     if (m_taskitem == null)
     {
         SetDefaultValue();
         //cbClose.Checked = true;
     }
     else
     {
         ParseCustomValue();
     }
 }
Ejemplo n.º 6
0
 private void cbClose_CheckedChanged(object sender, EventArgs e)
 {
     if (cbClose.Checked == true)
     {
         tcSet.Enabled = false;
         m_taskitem = null;
     }
     else
     {
         tcSet.Enabled = true;
     }
 }