예제 #1
0
 public XmlFile(XmlFile[] filesArray, string name, string content, DateTime timeStamp)
 {
     this.GenerateID(filesArray);
     this.Name = name;
     this.Content = content;
     this.TimeStamp = timeStamp;
 }
예제 #2
0
 private static void AddXmlsToList()
 {
     //creating list with files content
     for (int i = 1; i < _argFileNames.Count(); ++i)
     {
         XmlFile singleXml = new XmlFile();
         singleXml.Name = Path.GetFileName(_argFileNames[i]);
         if (".xml" != Path.GetExtension(_argFileNames[i]))
         {
             throw new IOException("THE FILE IS NOT AN .XML FILE (BAD EXTENSION)");
         }
         singleXml.Content = File.ReadAllText(_argFileNames[i]);
         singleXml.TimeStamp = File.GetLastWriteTime(_argFileNames[i]);
         singleXml.GenerateID(_xmlList.ToArray());
         _xmlList.Add(singleXml);
     }
 }
예제 #3
0
 public void GenerateID(XmlFile[] filesArray)
 {
     if (filesArray.Count<XmlFile>() == 0)
     {
         Id = 0;
         return;
     }
     int max_id = filesArray[0].Id;
     foreach (XmlFile file in filesArray)
     {
         if (max_id < file.Id)
         {
             max_id = file.Id;
         }
     }
     Id = max_id + 1;
 }
예제 #4
0
 public void LoadXMLs(string fileName)
 {
     if (!XMLsToWorkWith.ContainsKey(fileName))
     {
         XmlFile l_xmlFile = new XmlFile();
         if (xmlFilesListReference.TryGetValue(fileName, out l_xmlFile))
         {
             StringReader strReader = new StringReader(l_xmlFile.Content);
             XMLsToWorkWith.Add(fileName, new XPathDocument(strReader));
         }
     }
 }
예제 #5
0
        /// <summary>
        /// Saves information about XML Files into database
        /// </summary>
        /// <param name="filesArray">List with informations about XML Files</param>
        /// <returns>True if success</returns>
        public bool SaveFiles(XmlFile[] filesArray)
        {
            string strSQL;
            ADODB.Connection con = new ADODB.Connection();
            object obj = new object();

            try
            {
                con.Open(GenerateConnectionString(), "", "", 0);
            }
            catch (Exception)
            {
                return false;
            }

            for (int i = 0; i < filesArray.Length; i++)
            {
                strSQL = string.Format(NEW_XML_FILE,
                    filesArray[i].Id,
                    filesArray[i].Name,
                    filesArray[i].Content,
                    filesArray[i].TimeStamp);

                try
                {
                    con.Execute(strSQL, out obj, 0);
                }
                catch (Exception)
                {
                    //TODO: Error logging
                    con.Close();
                    return false;
                }
            }

            con.Close();
            return true;
        }
예제 #6
0
        public XmlFile[] LoadDataBaseContent()
        {
            string strAccessConn = GenerateConnectionString();
            string strAccessSelect = "SELECT * FROM XML_TABLE";

            // Create the dataset and add the Categories table to it:
            DataSet myDataSet = new DataSet();
            OleDbConnection myAccessConn = null;
            try
            {
                myAccessConn = new OleDbConnection(strAccessConn);
            }
            catch (Exception)
            {
                return null;
            }

            try
            {
                OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn);
                OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);

                myAccessConn.Open();
                myDataAdapter.Fill(myDataSet, "XML_TABLE");
            }
            catch (Exception)
            {
                return null;
            }
            finally
            {
                myAccessConn.Close();
            }

            DataRowCollection dra = myDataSet.Tables["XML_TABLE"].Rows;
            XmlFile[] array = new XmlFile[dra.Count];

            for (int i = 0; i < dra.Count; i++)
            {
                DataRow dr = dra[i];
                array[i] = new XmlFile();
                array[i].Id = (int)(dr.ItemArray[0]);
                array[i].Name = ((string)(dr.ItemArray[1])).Trim();
                array[i].Content = ((string)(dr.ItemArray[2])).Trim();
                array[i].TimeStamp = (DateTime)(dr.ItemArray[3]);
            }
            return array;
        }