public void LoadModelMapping()
 {
     PersistenceHelper.CreateDatabaseSchema();
     using (var pc = PersistenceHelper.CreatePersistenceContext())
     {
     }
 }
        public static FileDetailsHolderService Load(string path)
        {
            PersistenceHelper <FileDetailsHolderService> ph = new PersistenceHelper <FileDetailsHolderService>(path);
            FileDetailsHolderService tf = ph.LoadDataSingle(path + @"\eWolfFileDuplicates.dat");

            return(tf);
        }
Beispiel #3
0
        public void TestImagePersistence()
        {
            // Setup the test
            Bitmap bitmap1 = FrameGenerator.GenerateRandomBitmap(48, 37, 0);
            Bitmap bitmap2 = FrameGenerator.GenerateRandomBitmap(12, 45, 0);

            Stream stream = new MemoryStream();

            // Test the methods
            PersistenceHelper.SaveImageToStream(bitmap1, stream);
            PersistenceHelper.SaveImageToStream(bitmap2, stream);

            // Reset stream
            stream.Position = 0;

            // Load the bitmaps back up again one at a time
            Bitmap loadedBitmap1 = PersistenceHelper.LoadImageFromStream(stream);
            Bitmap loadedBitmap2 = PersistenceHelper.LoadImageFromStream(stream);

            // Compare images
            Assert.IsTrue(ImageUtilities.ImagesAreIdentical(bitmap1, loadedBitmap1), "An image loaded from a stream must match completely the image that was saved");
            Assert.IsTrue(ImageUtilities.ImagesAreIdentical(bitmap2, loadedBitmap2), "An image loaded from a stream must match completely the image that was saved");

            // Try to edit the loaded bitmaps to verify editability
            loadedBitmap1.SetPixel(0, 0, Color.Black);
            loadedBitmap2.SetPixel(0, 0, Color.Black);
        }
Beispiel #4
0
        /// <summary>
        /// Saves the given Frame into a stream
        /// </summary>
        /// <param name="frame">The frame to write to the stream</param>
        /// <param name="stream">The stream to write the frame to</param>
        protected void SaveFrameToStream(IFrame frame, Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            var castFrame = frame as Frame;

            if (castFrame != null)
            {
                SaveLayersToStream(castFrame, stream);
            }
            else
            {
                using (Bitmap bitmap = frame.GetComposedBitmap())
                {
                    PersistenceHelper.SaveImageToStream(bitmap, stream);
                }
            }

            // Write the frame ID
            writer.Write(frame.ID);

            // Write the hash now
            writer.Write(frame.Hash.Length);
            writer.Write(frame.Hash, 0, frame.Hash.Length);
        }
Beispiel #5
0
 private TopicService SetupTopicService(
     ContentDbContext contentContext       = null,
     StatisticsDbContext statisticsContext = null,
     PersistenceHelper <ContentDbContext> persistenceHelper = null,
     IMapper mapper           = null,
     IUserService userService = null,
     IReleaseSubjectRepository releaseSubjectRepository = null,
     IReleaseDataFileService releaseDataFileService     = null,
     IReleaseFileService releaseFileService             = null,
     IPublishingService publishingService   = null,
     IMethodologyService methodologyService = null)
 {
     return(new TopicService(
                Mock.Of <IConfiguration>(),
                contentContext ?? Mock.Of <ContentDbContext>(),
                statisticsContext ?? Mock.Of <StatisticsDbContext>(),
                persistenceHelper ?? MockUtils.MockPersistenceHelper <ContentDbContext, Topic>(_topic.Id, _topic).Object,
                mapper ?? AdminMapper(),
                userService ?? MockUtils.AlwaysTrueUserService().Object,
                releaseSubjectRepository ?? Mock.Of <IReleaseSubjectRepository>(),
                releaseDataFileService ?? Mock.Of <IReleaseDataFileService>(),
                releaseFileService ?? Mock.Of <IReleaseFileService>(),
                publishingService ?? Mock.Of <IPublishingService>(),
                methodologyService ?? Mock.Of <IMethodologyService>(),
                Mock.Of <IBlobCacheService>()
                ));
 }
 public void CreatePersistenceContext()
 {
     using (var persistenceContext = PersistenceHelper.CreatePersistenceContext())
     {
         Assert.IsNotNull(persistenceContext);
     }
 }
        private SaveTextPresenter CreatePresenter(IContext context)
        {
            var entityRepository = PersistenceHelper.CreateRepository <IEntityRepository>(context);
            var presenter        = new SaveTextPresenter(entityRepository);

            return(presenter);
        }
Beispiel #8
0
        void IPersistable.Serialize(IntermediateFormatWriter writer)
        {
            writer.RegisterDeclaration(RuntimeDataRowSortHierarchyObj.m_declaration);
            PersistenceHelper persistenceHelper = writer.PersistenceHelper;

            while (writer.NextMember())
            {
                switch (writer.CurrentMember.MemberName)
                {
                case MemberName.HierarchyRoot:
                    writer.Write(this.m_hierarchyRoot);
                    break;

                case MemberName.DataRowHolder:
                    writer.Write(this.m_dataRowHolder);
                    break;

                case MemberName.Expression:
                    writer.Write(this.m_sortExpression);
                    break;

                case MemberName.SortTree:
                    writer.Write(this.m_sortTree);
                    break;

                default:
                    Global.Tracer.Assert(false);
                    break;
                }
            }
        }
Beispiel #9
0
        public static void ClassInit(TestContext context)
        {
            PersistenceHelper.UpdateDatabaseSchema();
            Bootstrapper.With.AutoMapper().And.StartupTasks().Start();

            service = new ProductService();
        }
Beispiel #10
0
        void IPersistable.Deserialize(IntermediateFormatReader reader)
        {
            reader.RegisterDeclaration(RuntimeDataRowSortHierarchyObj.m_declaration);
            PersistenceHelper persistenceHelper = reader.PersistenceHelper;

            while (reader.NextMember())
            {
                switch (reader.CurrentMember.MemberName)
                {
                case MemberName.HierarchyRoot:
                    this.m_hierarchyRoot = (IReference <IHierarchyObj>)reader.ReadRIFObject();
                    break;

                case MemberName.DataRowHolder:
                    this.m_dataRowHolder = (RuntimeSortDataHolder)reader.ReadRIFObject();
                    break;

                case MemberName.Expression:
                    this.m_sortExpression = (RuntimeExpressionInfo)reader.ReadRIFObject();
                    break;

                case MemberName.SortTree:
                    this.m_sortTree = (BTree)reader.ReadRIFObject();
                    break;

                default:
                    Global.Tracer.Assert(false);
                    break;
                }
            }
        }
Beispiel #11
0
        public void ShouldSaveTwoFile()
        {
            RemoveTempFolder();

            TempSaveable tempSaveable = new TempSaveable()
            {
                Modifyed = true
            };
            TempSaveableAnotherName tempSaveableB = new TempSaveableAnotherName()
            {
                Modifyed = true
            };
            PersistenceHelper <ISaveable> ph = new PersistenceHelper <ISaveable>(GetOutputFolder());
            bool results = ph.SaveData(new List <ISaveable>()
            {
                tempSaveable, tempSaveableB
            });

            results.Should().BeTrue();
            string finalName = Path.Combine(GetOutputFolder(), "TestSave.data");

            File.Exists(finalName).Should().BeTrue();

            finalName = Path.Combine(GetOutputFolder(), "TestSave2.data");
            File.Exists(finalName).Should().BeTrue();
        }
Beispiel #12
0
 public void Save()
 {
     lock (_shows)
     {
         PersistenceHelper <ShowControl> ph = new PersistenceHelper <ShowControl>(_outputFolder);
         ph.SaveData(_shows);
     }
 }
 public static void Save(FileDetailsHolderService fileDetailsHolderService, string path)
 {
     lock (fileDetailsHolderService.Details)
     {
         PersistenceHelper <FileDetailsHolderService> ph = new PersistenceHelper <FileDetailsHolderService>(path);
         ph.SaveDataSingle(fileDetailsHolderService);
     }
 }
Beispiel #14
0
 /// <summary>
 /// Remove self from DB.
 /// </summary>
 public void DeleteFromPersistence()
 {
     lock (this)
     {
         PersistenceHelper.Delete <PlatformComponent>(new MatchExpression("PlatformId", this.Id));
         PersistenceHelper.Delete <Platform>(new MatchExpression("Name", this.Name));
     }
 }
Beispiel #15
0
 private void Save()
 {
     lock (Tags)
     {
         PersistenceHelper <GlobalTagStore> ph = new PersistenceHelper <GlobalTagStore>(GetOutputFolder());
         ph.SaveDataSingle(this);
     }
 }
Beispiel #16
0
        public OAuthToken()
        {
            var spotManRegistry = PersistenceHelper.GetKeys();

            AccessToken  = spotManRegistry[nameof(AccessToken)];
            RefreshToken = spotManRegistry[nameof(RefreshToken)];
            Expiry       = DateTimeOffset.Parse(spotManRegistry[nameof(Expiry)]);
        }
Beispiel #17
0
 public void ApplyToSaveFile()
 {
     foreach (var kvp in _snapshotHandlersByFileName)
     {
         var data = kvp.Value.TakeSnapshot();
         File.WriteAllText(PersistenceHelper.GetPath(_persistentDataPath, kvp.Key), data);
     }
 }
Beispiel #18
0
        public void DiscoverNewPackages()
        {
            var discovery = new PackageDiscoveryWorker();

            using (var pc = PersistenceHelper.CreatePersistenceContext())
            {
                discovery.ProcessPackageConfigurations();
            }
        }
        public void UploadStory()
        {
            // 建立和上传story配置文件.
            XDocument storyConfig = PersistenceHelper.SerializeStory();
            WebClient webClient   = new WebClient();

            webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadConfigCompleted);
            webClient.UploadStringAsync(new Uri(this._baseServiceUri), storyConfig.ToString());
        }
        public NoteRepositoryIntegrationTests()
        {
            _options = PersistenceHelper.BuildOptions("TestDbConnectionString");
            var context = new NexusContext(PersistenceHelper.BuildOptions("TestDbConnectionString"));

            context.Database.EnsureDeleted();
            context.Database.Migrate();
            context.Dispose();
        }
 private void Save()
 {
     lock (SoundItems)
     {
         PersistenceHelper <SoundHolder> ph = new PersistenceHelper <SoundHolder>(_outputFolder);
         ph.SaveDataSingle(this);
     }
     _modified = false;
 }
Beispiel #22
0
 public bool RemovePersistedComponentById(long componentId)
 {
     if (PersistenceHelper.Delete <PlatformComponent>(new MatchExpression("Id", componentId)) != 1)
     {
         SystemMonitor.Error("Failed to remove persisted component [" + componentId + "].");
         return(false);
     }
     return(true);
 }
Beispiel #23
0
        void HandleComponentPersistenceDataUpdatedEvent(IDBPersistent dbComponent)
        {
            PlatformComponent component = (PlatformComponent)dbComponent;

            if (component.IsPersistableToDB)
            {
                PersistenceHelper.UpdateToDB <PlatformComponent>((PlatformComponent)component);
            }
        }
Beispiel #24
0
        /// <summary>
        /// Saves the contents of a layer to a stream
        /// </summary>
        /// <param name="layer">The layer to save</param>
        /// <param name="stream">The stream to save the layer to</param>
        private void SaveLayerToStream(IFrameLayer layer, Stream stream)
        {
            // Save the layer's name
            BinaryWriter writer = new BinaryWriter(stream, Encoding.UTF8);

            writer.Write(layer.Name);

            PersistenceHelper.SaveImageToStream(layer.LayerBitmap, stream);
        }
Beispiel #25
0
        public void RemoveShow(ShowControl itemToRemove)
        {
            lock (_shows)
            {
                _shows.Remove(itemToRemove);

                PersistenceHelper <ShowControl> ph = new PersistenceHelper <ShowControl>(_outputFolder);
                ph.DeleteFile(itemToRemove);
            }
        }
Beispiel #26
0
        public void Load(string outputFolder)
        {
            _outputFolder = outputFolder;

            PersistenceHelper <ShowControl> ph = new PersistenceHelper <ShowControl>(outputFolder);

            _shows = ph.LoadData();

            FixPath();
        }
        public void CreateRootEntity()
        {
            using (var persistenceContext = PersistenceHelper.CreatePersistenceContext())
            {
                RootEntity rootEntity = new RootEntity();
                rootEntity.Name = "First Root Entity";

                rootEntity.SaveOrUpdate();
            }
        }
 public ActionResult Index(SaveTextViewModel viewModel)
 {
     using (IContext ormContext = PersistenceHelper.CreateContext())
     {
         SaveTextPresenter presenter  = CreatePresenter(ormContext);
         SaveTextViewModel viewModel2 = presenter.Save(viewModel);
         TempData[nameof(TempDataKeys.ViewModel)] = viewModel2;
         return(RedirectToAction(nameof(ActionNames.Index)));
     }
 }
Beispiel #29
0
        /// <summary>
        ///
        /// </summary>
        protected bool DoRegisterComponent(PlatformComponent component, bool isInitial)
        {
            TracerHelper.Trace(component.Name);

            if (CanAcceptComponent(component.GetType()) == false)
            {
                SystemMonitor.Error("Failed to add component instance since only one instance of this type allowed.");
                return(false);
            }

            if (component.SubscriptionClientID.Id.Guid == Guid.Empty)
            {
                SystemMonitor.Error("Component [" + component.GetType().Name + "] has no valid Guid Id assigned.");
                return(false);
            }

            if (InitializeComponent(component) == false)
            {
                return(false);
            }

            lock (this)
            {
                if (_components.ContainsValue(component))
                {
                    SystemMonitor.OperationWarning("Component [" + component.GetType().Name + "] already added.");
                    return(true);
                }

                if (_components.ContainsKey(component.SubscriptionClientID.Id))
                {
                    SystemMonitor.Error("Component with this Id [" + component.SubscriptionClientID.Id.Name + ", " + component.SubscriptionClientID.Id.ToString() + "] already added.");
                    return(false);
                }

                _components.Add(component.SubscriptionClientID.Id, component);
            }

            component.OperationalStateChangedEvent += new OperationalStateChangedDelegate(component_OperationalStatusChangedEvent);

            if (component.IsPersistableToDB && PersistenceHelper.IsPersisted <PlatformComponent>(component) == false)
            {// New component not present in DB, persist.
                if (PersistenceHelper.Insert <PlatformComponent>(component, new KeyValuePair <string, object>("PlatformId", this.Id)) == false)
                {
                    SystemMonitor.Error("Failed to insert component [" + component.Name + "] to DB.");
                }
            }

            if (ActiveComponentAddedEvent != null)
            {
                ActiveComponentAddedEvent(component, isInitial);
            }

            return(true);
        }
        public void AddParamterTest()
        {
            using (var pc = PersistenceHelper.CreatePersistenceContext())
            {
                var parameter = new Parameter {
                    Name = "TestParameter", Value = "dev"
                };

                parameter.SaveOrUpdate();
            }
        }