Beispiel #1
0
        private bool HandleTask(Tuple <FactoryTaskType, object[]> taskParams)
        {
            switch (taskParams.Item1)
            {
            case FactoryTaskType.Get:
                // Have to later consider other models than fortresses
                //_xmlDatacache.BuildFortress((string)taskParams.Item2[0], (string)taskParams.Item2[1], (string)taskParams.Item2[2]);

                return(true);

            case FactoryTaskType.Create:
                // Have to later consider other models than fortresses
                _xmlDatacache.WriteFortress((Fortress)taskParams.Item2[0]);
                return(true);

            case FactoryTaskType.Read:
                break;

            case FactoryTaskType.Save:
                break;

            case FactoryTaskType.Load:
                break;

            default:
                break;
            }

            return(false);
        }
        /// <summary>
        /// Builds a new fortress.
        /// </summary>
        /// <param name="fortess"></param>
        public void CreateNewFortress(Fortress fortess)
        {
            _xmlDatacache = new XmlDataCache(fortess.FullPath);

            // Store the example data:
            var rootBranch = new Branch {
                Name = "Example: Projects", ParentBranchId = Guid.Empty
            };
            var rootBranch2 = new Branch {
                Name = "Example: Projects2", ParentBranchId = Guid.Empty
            };
            var subBranch = new Branch {
                Name = "Example: Passwords", ParentBranchId = rootBranch.Id
            };
            var examplePw = ByteHelper.StringToByteArray("thisIsAnExamplePassword");
            var leaf      = new Leaf {
                Name = "Password1", Description = "Here you can describe this entry.", BranchId = subBranch.Id
            };
            var leafPw = new LeafPassword {
                ForeignId = leaf.Id, Value = examplePw
            };

            examplePw = null;
            _xmlDatacache.AddToUnsecureMemoryDC(fortess);
            _xmlDatacache.AddToUnsecureMemoryDC(rootBranch);
            _xmlDatacache.AddToUnsecureMemoryDC(rootBranch2);
            _xmlDatacache.AddToUnsecureMemoryDC(subBranch);
            _xmlDatacache.AddToUnsecureMemoryDC(leaf);
            var leafPwAsBytes = ByteHelper.ObjectToByteArray(leafPw);

            _xmlDatacache.AddToSecureMemoryDC(leafPw.ForeignId, leafPwAsBytes);
            leafPw = null;
            // end exampel data

            _xmlDatacache.WriteFortress(fortess);
        }