Esempio n. 1
0
        public ContainerStatus Save(string fileName)
        {
            Logger.Debug("Saving as : " + fileName);
            if (IsEmpty())
            {
                Logger.Warn("No files added cannot save as : " + fileName);
                return(ContainerStatus.Empty);
            }

            if (Template == null || Template.Length != TemplateOperations.TemplateLength)
            {
                Logger.Warn("Template is null cannot save as : " + fileName);
                return(ContainerStatus.NullTemplate);
            }
            byte[] fileStmWithTempAndFile;
            if (!AddPassword)
            {
                TemplateOperations = new NLockTemplateOperationsAes();
                if (!IsLocked)
                {
                    Lock();
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent);
                }
                else
                {
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent);
                }
            }
            else
            {
                TemplateOperations = new NLockTemplateOperationsCommon();
                if (!IsLocked)
                {
                    Lock();
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent,
                                                                                         Password);
                }
                else
                {
                    fileStmWithTempAndFile = TemplateOperations.GenerateNLockFileContent(Template, _lockedContent,
                                                                                         Password);
                }
            }

            if (File.Exists(fileName))
            {
                Logger.Debug(fileName + " already exists so deleting");
                File.Delete(fileName);
            }

            using (var fs2 = File.Create(fileName))
            {
                Logger.Debug(fileName + " is being written");
                fs2.Write(fileStmWithTempAndFile, 0, fileStmWithTempAndFile.Length);
                fs2.Close();
            }
            _container.Dispose();
            return(ContainerStatus.Ok);
        }
Esempio n. 2
0
        private int DecideTemplateOperations(string fileName)
        {
            var type = NLockTemplateOperations.IsNLock(fileName);

            Logger.Debug("DecideTemplateOperations Type : " + type);
            switch (type)
            {
            case 1:
                TemplateOperations = new NLockTemplateOperationsAes();
                break;

            case 2:
                TemplateOperations = new NLockTemplateOperationsCommon();
                break;

            default:
                Logger.Error("Invalid NLock file type");
                break;
            }
            return(type);
        }
Esempio n. 3
0
 public NLockContainerCommons()
 {
     TemplateOperations = new NLockTemplateOperationsAes();
 }