示例#1
0
 protected virtual bool SerializeToStorageFile(Bucket bucket)
 {
     string filePath = this.GetFilePath();
       try
       {
     var parentDirectory = Directory.GetParent(filePath);
     if (!parentDirectory.Exists)
     {
       Directory.CreateDirectory(parentDirectory.FullName);
     }
     using (var streamWriter = new StreamWriter(filePath, false))
     {
       XmlSerializer serializer = this.GetBucketXmlSerializer();
       serializer.Serialize(streamWriter, bucket);
       if (this.EnableDebuggingTraces)
       {
     using (var memStream = new MemoryStream())
     {
       serializer.Serialize(memStream, bucket);
       this.TraceDebugStreamContent(memStream, "SaveOp");
     }
       }
     }
     return true;
       }
       catch (Exception ex)
       {
     Log.Error("Failed to save settings to file", ex, this);
     return false;
       }
 }
示例#2
0
 protected virtual Bucket BuildBucketFromContainer(IContainer rootContainer)
 {
     if (rootContainer == null)
       {
     return null;
       }
       var bucket = new Bucket();
       bucket.Name = rootContainer.Name;
       bucket.Settings =
     rootContainer.GetPresentStringSettingNames().Select(x => new StringStringPair(x, rootContainer.GetStringSetting(x))).ToList();
       bucket.InnerBuckets =
     rootContainer.GetPresentSubContainerNames()
       .Select(x => this.BuildBucketFromContainer(rootContainer.GetNamedSubContainer(x)))
       .ToList();
       return bucket;
 }
示例#3
0
 protected virtual IContainer BuildContainerFromBucket(Bucket rootBucket)
 {
     Dictionary<string, string> settings = rootBucket.Settings.ToDictionary(
     settingPair => settingPair.Key,
     settingPair => settingPair.Value);
       var subcontainers = rootBucket.InnerBuckets.Select(this.BuildContainerFromBucket).ToList();
       var newContainer = this.ContainerFactory.GetPurelyNewObject() as IContainer;
       Assert.IsNotNull(newContainer, "Wrong container factory");
       newContainer.InitializeFromCollections(rootBucket.Name, settings, subcontainers);
       return newContainer;
 }