Beispiel #1
0
        public void ReadXML(string pathfile)
        {
            
            if (ListWord.Count() > 0)
                ListWord.Clear();
            if (ListSentence.Count() > 0)
                ListSentence.Clear();

            XDocument myXML = XDocument.Load(pathfile);

            Noidung = (from s in myXML.Descendants("Content") select s.Value).ToList();
            Noidung.Single();
            ListWord = (from s in myXML.Descendants("Item")
                        select new CItem()
                        {
                            type = s.Attribute("type").Value,
                            soundPath = s.Attribute("soundPath").Value,
                            word = s.Value
                        }
                        ).ToList();
            ListSentence = (from s in myXML.Descendants("Sentence") select s.Value).ToList();
        }
        public bool GetMandatoryStatusForBusinessUnit(string businessUnit,List<BusinessUnit> units)
        {
            bool result = false;

            if  (!string.IsNullOrEmpty(businessUnit))
            {
                var unit = units.Single(b => b.Title == businessUnit);                    
                if (unit != null)
                    result = unit.LinkToMandatory;
                else
                    result = false;
            }
            return result;
        }
Beispiel #3
0
        /// <summary>
        /// Helper method to optimize the queue
        /// </summary>
        /// <param name="newRecord"></param>
        /// <param name="requests"></param>
        private static void OptimizeQueue(RequestRecord newRecord, List<RequestRecord> requests)
        {
            // try to find a record for the same entity by the local ID
            try
            {
                var existingRecord = requests.Single(r => r.ID == newRecord.ID);
                existingRecord.DeserializeBody();
                UpdateExistingRecord(requests, existingRecord, newRecord);
            }
            catch (Exception)
            {
                // this is a new record so add the new record at the end
                requests.Add(newRecord);
            }

            // if this is a request to remove a tasklist, need to also remove all the manipulations to tasks inside that list
            if (newRecord.ReqType == RequestRecord.RequestType.Delete &&
                newRecord.BodyTypeName == "TaskList")
            {
                // create a list that holds the task references to delete
                List<RequestRecord> deleteList = new List<RequestRecord>();
                // deserialize the bodies for all the tasks (need TaskListID for all the tasks)
                foreach (var r in requests)
                {
                    if (r.BodyTypeName == "Task")
                    {
                        r.DeserializeBody();
                        Task t;
                        if (r.ReqType == RequestRecord.RequestType.Update)
                            t = ((List<Task>)r.Body)[0];
                        else
                            t = (Task)r.Body;
                        if (t.TaskListID == newRecord.ID)
                            deleteList.Add(r);
                    }
                }
                foreach (var r in deleteList)
                    requests.Remove(r);
            }
        }
        //还原文件
        private void Restore()
        {
            //检查解压到文件中是否有mdb数据库文件
            List<string> tempFileNames = new List<string>();
            tempFileNames.AddRange(Directory.GetFiles(tempExtrctorPath));
            string mdbFile = "";
            try
            {
                mdbFile = tempFileNames.Single(x => x.Substring(x.LastIndexOf(".")) == ".mdb");
                tempFileNames.Remove(mdbFile);
            }
            catch (Exception ee)
            {
                Directory.Delete(tempExtrctorPath, true);
                MessageBox.Show("没有找到数据库文件,该文件不是软件的备份文件!", "系统信息");
                this.Close();
            }
            //还原数据库文件
            File.Copy(mdbFile, Model.AppPath.RootPath + "\\AppData\\DSJLDB.mdb", true);
            //删除旧文件
            if (Directory.Exists(Model.AppPath.XmlDataDirPath))
            {

                string[] oldFileNames = Directory.GetFiles(Model.AppPath.XmlDataDirPath);
                foreach (string oldFileName in oldFileNames)
                {
                    File.Delete(oldFileName);
                }

                //复制新文件
                for (int i = 0; i < tempFileNames.Count; i++) {
                    string xmlFile = tempFileNames[i];

                    string name = xmlFile.Substring(xmlFile.LastIndexOf("\\"));
                    File.Copy(xmlFile, Model.AppPath.XmlDataDirPath + name);
                    this.Dispatcher.Invoke(rui, (double)(i + 1), (double)tempFileNames.Count, "正在还原数据文件...");
                }
            }
            else
            {
                Directory.CreateDirectory(Model.AppPath.XmlDataDirPath);
                //复制新文件
                for (int i = 0; i < tempFileNames.Count; i++)
                {
                    string xmlFile = tempFileNames[i];
                    string name = xmlFile.Substring(xmlFile.LastIndexOf("\\"));
                    File.Copy(xmlFile, Model.AppPath.XmlDataDirPath + name);
                    this.Dispatcher.Invoke(rui, (double)(i + 1), (double)tempFileNames.Count, "正在还原数据文件...");
                }
            }
            Directory.Delete(tempExtrctorPath, true);
            this.Dispatcher.Invoke(rui, 1,1, "还原完成!");

            this.Dispatcher.Invoke(closeWindow);
        }