예제 #1
0
        private XMLHelper()
        {
            XmlDocument objDoc = new XmlDocument();
            string      path   = System.Environment.CurrentDirectory + @"\XMLFileList.xml";

            objDoc.Load(path);
            XmlNodeList xmlFiles = objDoc.DocumentElement.SelectSingleNode("Files").ChildNodes;

            if (xmlFiles != null && xmlFiles.Count > 0)
            {
                foreach (XmlNode voiceItem in xmlFiles)
                {
                    if (voiceItem.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    XmlAttribute keyAttr  = voiceItem.Attributes["key"];
                    XmlAttribute pathAttr = voiceItem.Attributes["path"];
                    if (null != keyAttr && !string.IsNullOrEmpty(keyAttr.Value) &&
                        null != pathAttr && !string.IsNullOrEmpty(pathAttr.Value))
                    {
                        string      pathN   = System.Environment.CurrentDirectory + (pathAttr.Value.StartsWith(@"\") ? pathAttr.Value : @"\" + pathAttr.Value);
                        XmlDocument XmldocN = new XmlDocument();
                        XmldocN.Load(pathN);
                        XmlDocumentEx xmlDocEx = new XmlDocumentEx();
                        xmlDocEx.XmlDoc = XmldocN;
                        XMLFiles.Add(keyAttr.Value, xmlDocEx);
                    }
                }
            }
        }
예제 #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Text            = "当前第0页";
            button8.Enabled = false;
            button9.Enabled = false;
            Thread ddd = new Thread(downThread);

            ddd.IsBackground = true;
            ddd.Start();
            Directory.CreateDirectory($"{Application.StartupPath}\\temp");
            Directory.CreateDirectory($"{Application.StartupPath}\\down");
            XMLFiles xml = new XMLFiles($"{Application.StartupPath}\\set.xml");

            if (!xml.ExistINIFile())
            {
                xml.CreateXmlFile();
                xml.setXmlValue("重试次数", 基本设置.重试次数.ToString());
                xml.setXmlValue("重试毫秒", 基本设置.重试毫秒.ToString());
            }
            else
            {
                基本设置.重试次数 = Convert.ToInt32(xml.getXmlValue("基本设置", "重试次数"));
                基本设置.重试毫秒 = Convert.ToInt32(xml.getXmlValue("基本设置", "重试毫秒"));
            }
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            XMLFiles xml = new XMLFiles($"{Application.StartupPath}\\set.xml");

            if (!xml.ExistINIFile())
            {
                File.Create(xml.xmlName).Close();
            }
            xml.setXmlValue("重试次数", textBox1.Text);
            xml.setXmlValue("重试毫秒", textBox2.Text);
            MessageBox.Show("已经更改,请重启软件以得到更新");
        }
예제 #4
0
        private void Form2_Load(object sender, EventArgs e)
        {
            XMLFiles xml = new XMLFiles($"{Application.StartupPath}\\set.xml");

            if (!xml.ExistINIFile())
            {
                File.Create(xml.xmlName).Close();
                xml.setXmlValue("重试次数", 基本设置.重试次数.ToString());
                xml.setXmlValue("重试毫秒", 基本设置.重试毫秒.ToString());
            }
            textBox1.Text = xml.getXmlValue("基本设置", "重试次数");
            textBox2.Text = xml.getXmlValue("基本设置", "重试毫秒");
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Param"></param>
        /// <param name="MadeChanges"></param>
        public override bool SyncWithFilesAndDB(CScannerBase.CSyncParamBase Param)
        {
            LastException = null;

            CSyncParam SyncParam = Param as CSyncParam;

            if (SyncParam == null ||
                SyncParam.m_Dir == GlobalDefines.DEFAULT_XML_STRING_VAL ||
                !Directory.Exists(SyncParam.m_Dir))
            {
                return(false);
            }

            using (var wrapper = new DisposableWrapper <ShowAsyncResult>(CWaitingWnd.ShowAsync(DBManagerApp.MainWnd.Title,
                                                                                               string.Format(Properties.Resources.resfmtSyncingDir, SyncParam.m_Dir),
                                                                                               DBManagerApp.MainWnd,
                                                                                               true),
                                                                         asyncResult =>
            {
                if (asyncResult?.hFinishedSearchEvent != null)
                {
                    asyncResult.hFinishedSearchEvent.Set();
                }
            }))
            {
                lock (EventsCS)
                {
                    if (State == enScanningThreadState.Worked)
                    {   // Синхронизацию можно проводить только при незапущенном сканировании
                        return(false);
                    }

                    m_PathWatcher.EnableRaisingEvents = false;

                    List <string> ScannedFilesFullPaths = new List <string>();

                    try
                    {
                        if (SyncParam.m_lstFileScannerSettings != null)
                        {
                            bool AllFilesSync = true;

                            foreach (CFileScannerSettings ScannerSettings in SyncParam.m_lstFileScannerSettings)
                            {
                                if (Path.GetDirectoryName(ScannerSettings.FullFilePath) != SyncParam.m_Dir)
                                {   // Файл не находится в просматриваемой папке => он нам не нужен
                                    AllFilesSync = false;
                                    lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
                                        DBManagerApp.m_AppSettings.m_Settings.dictFileScannerSettings.Remove(ScannerSettings.FullFilePath);
                                    continue;
                                }

                                string FullScannerFilePath = Path.Combine(SyncParam.m_Dir, ScannerSettings.FullFilePath);
                                ScannedFilesFullPaths.Add(FullScannerFilePath);

                                CFileScanner Scanner = null;
                                if (m_FileScanners.TryGetValue(FullScannerFilePath, out Scanner))
                                {
                                    m_FileScanners[FullScannerFilePath] =
                                        Scanner = new CFileScanner(ScannerSettings.FullFilePath,
                                                                   this,
                                                                   true,
                                                                   new CFileScanner.CSyncParam(ScannerSettings.GroupId,
                                                                                               FullScannerFilePath));
                                    if (!Scanner.SyncSuccessfully)
                                    {   // Синхронизироваться не удалось
                                        m_FileScanners.Remove(FullScannerFilePath);
                                        AllFilesSync = false;
                                        lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
                                            DBManagerApp.m_AppSettings.m_Settings.dictFileScannerSettings.Remove(ScannerSettings.FullFilePath);
                                    }
                                }
                                else
                                {
                                    Scanner = new CFileScanner(ScannerSettings.FullFilePath,
                                                               this,
                                                               true,
                                                               new CFileScanner.CSyncParam(ScannerSettings.GroupId,
                                                                                           FullScannerFilePath));
                                    if (Scanner.SyncSuccessfully)
                                    {
                                        m_FileScanners.Add(ScannerSettings.FullFilePath, Scanner);
                                    }
                                    else
                                    {   // Синхронизироваться не удалось
                                        AllFilesSync = false;
                                        lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
                                            DBManagerApp.m_AppSettings.m_Settings.dictFileScannerSettings.Remove(ScannerSettings.FullFilePath);
                                    }
                                }
                            }

                            if (!AllFilesSync)
                            {
                                DBManagerApp.m_AppSettings.Write();
                            }
                        }

                        // Пытаемся загрузить данные из всех остальных XML-файлов, имеющихся в папке
                        string[] AllXMLFullFilePaths = Directory.GetFiles(SyncParam.m_Dir, "*.xml");
                        foreach (string FullFilePath in from xmlFileL in AllXMLFullFilePaths
                                 join xmlFileR in ScannedFilesFullPaths on xmlFileL equals xmlFileR into XMLFiles
                                 from scannedFile in XMLFiles.DefaultIfEmpty()
                                 where scannedFile == null
                                 select xmlFileL)
                        {
                            CFileScanner Scanner = null;
                            if (m_FileScanners.TryGetValue(FullFilePath, out Scanner))
                            {
                                m_FileScanners[FullFilePath] =
                                    Scanner = new CFileScanner(FullFilePath,
                                                               this,
                                                               true,
                                                               new CFileScanner.CSyncParam(m_FileScanners[FullFilePath].Group == null ?
                                                                                           GlobalDefines.NO_OUR_COMP_IN_DB :
                                                                                           m_FileScanners[FullFilePath].Group.id_group,
                                                                                           FullFilePath));
                                if (!Scanner.SyncSuccessfully)
                                {   // Синхронизироваться не удалось
                                    m_FileScanners.Remove(FullFilePath);
                                    lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
                                        DBManagerApp.m_AppSettings.m_Settings.dictFileScannerSettings.Remove(FullFilePath);
                                    continue;
                                }
                            }
                            else
                            {
                                Scanner = new CFileScanner(FullFilePath,
                                                           this,
                                                           true,
                                                           new CFileScanner.CSyncParam(GlobalDefines.NO_OUR_COMP_IN_DB,
                                                                                       FullFilePath));

                                if (Scanner.SyncSuccessfully)
                                {   // Удалось синхронизироваться => добавляем сканер в m_FileScanners и в файл настроек
                                    m_FileScanners.Add(FullFilePath, Scanner);
                                }
                            }

                            if (Scanner.Group != null)
                            {
                                CFileScannerSettings ScannerSettings = new CFileScannerSettings()
                                {
                                    FullFilePath = FullFilePath,
                                    GroupId      = Scanner.Group.id_group
                                };
                                lock (DBManagerApp.m_AppSettings.m_SettingsSyncObj)
                                    DBManagerApp.m_AppSettings.m_Settings.dictFileScannerSettings.TryAddValue(FullFilePath, ScannerSettings);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        List <CDataChangedInfo> Changes = new List <CDataChangedInfo>();
                        OnException(ref Changes, ex, CompId);
                    }

                    if (Directory.Exists(m_PathWatcher.Path))
                    {
                        m_PathWatcher.EnableRaisingEvents = true;
                    }
                }
            }

            return(true);
        }