Пример #1
0
 /// <summary>
 /// Създава VersionedFile от XElement по подаден Version-елемент и подчинения му INFO-елемент.
 /// </summary>
 /// <param name="inVersionXElement"></param>
 /// <returns></returns>
 public static VersionedFile GetVersionedFile_from_XElement(XElement inVersionXElement)
 {
     VersionedFile _file = new VersionedFile();
     Version _version;
     _file.Version = (Version.TryParse(inVersionXElement.Value, out _version)) ? _version : null;
     XElement _infoElement = inVersionXElement.Elements().First();
     if (_infoElement == null) throw new NullReferenceException("Не е намерен Info-елемент в елемента Version!");
     _file.FileName = _infoElement.Attribute(C_XE_FILENAME).Value;
     _file.FileSize = (_infoElement.Attribute(C_XE_FILESIZE) == null) ? -1 : int.Parse(_infoElement.Attribute(C_XE_FILESIZE).Value);
     _file.CheckSum = _infoElement.Attribute(C_XE_CHECKSUM).Value;
     _file.DateTime = DateTime.ParseExact(_infoElement.Attribute(C_XE_DATETIME).Value, C_BG_DATEFORMAT, CultureInfo.InvariantCulture);
     _file.ApplicationName = inVersionXElement.Parent.Name.LocalName;
     return _file;
 }
Пример #2
0
 public static void Insert_VersionedFile(VersionedFile inFile)
 {
     XElement _newElement = Make_XElement_from_VersionedFile(inFile);
     XElement _appNode = Get_Application_Node(inFile.ApplicationName);
     if (_appNode == null)
     {
         XMLFilesDescr.Root.Add(new XElement(inFile.ApplicationName));
     }
     XMLFilesDescr.Root.Element(inFile.ApplicationName).Add(_newElement);
     XMLFilesDescr.Save(XMLFilePath);
 }
Пример #3
0
 /// <summary>
 /// Прави XElement по подаден VersionedFile-обект.
 /// </summary>
 /// <param name="inVersionedFile"></param>
 /// <returns></returns>
 public static XElement Make_XElement_from_VersionedFile(VersionedFile inVersionedFile)
 {
     XElement _xElement = new XElement(C_XE_VERSION, inVersionedFile.Version.ToString());
     _xElement.RemoveAttributes();
     _xElement.Add(new XElement(C_XE_INFO,
                                new XAttribute(C_XE_FILENAME, inVersionedFile.FileName),
                                new XAttribute(C_XE_FILESIZE, inVersionedFile.FileSize),
                                new XAttribute(C_XE_CHECKSUM, inVersionedFile.CheckSum),
                                new XAttribute(C_XE_DATETIME, inVersionedFile.DateTime.ToString(C_BG_DATEFORMAT))));
     return _xElement;
 }
Пример #4
0
 /// <summary>
 /// Записва файл на файловата система и го добавя в XML-файла
 /// </summary>
 /// <param name="inFileBytes">съдържание на файла</param>
 /// <param name="inFileName">име на файла с разширание, без път. (file.txt)</param>
 /// <param name="inVersion">версия на файла</param>
 /// <param name="inGroup">име на групата на файла </param>
 /// <returns></returns>
 public static VersionedFile UploadFile_to_Storage(byte[] inFileBytes, string inFileName, Version inVersion, string inGroup)
 {
     if (string.IsNullOrWhiteSpace(inFileName)) throw new ArgumentNullException("inFileName", "[UploadFile_to_Storage]: FileName is not supplied.");
     if (string.IsNullOrWhiteSpace(inVersion.ToString())) throw new ArgumentNullException("inVersion", "[UploadFile_to_Storage]: Version is not supplied.");
     if (!Directory.Exists(StoragePath)) Directory.CreateDirectory(StoragePath);
     string _fileName = Get_FilePath_in_Storage(inFileName, inVersion, true);
     using (FileStream _fileStream = new FileStream(_fileName, FileMode.Create))
     {
         _fileStream.Write(inFileBytes, 0, inFileBytes.Length);
         _fileStream.Flush(true);
     }
     VersionedFile _versionedFile = new VersionedFile();
     _versionedFile.ApplicationName = inFileName;
     _versionedFile.Group = inGroup;
     _versionedFile.FileName = _fileName;
     _versionedFile.FileSize = inFileBytes.Length;
     _versionedFile.DateTime = DateTime.Now;
     _versionedFile.Version = inVersion;
     _versionedFile.CheckSum = GetSHA1Checksum(inFileBytes);
     XMLHelper.Insert_VersionedFile(_versionedFile);
     return _versionedFile;
 }