/// <summary>
        /// Process any synapses that should be loaded.
        /// </summary>
        /// <param name="xmlIn">The XML reader.</param>
        private void HandleSynapses(ReadXML xmlIn)
        {
            String end = xmlIn.LastTag.Name;

            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(BasicNetworkPersistor.TAG_SYNAPSE, true))
                {
                    int from = xmlIn.LastTag.GetAttributeInt(
                        BasicNetworkPersistor.ATTRIBUTE_FROM);
                    int to = xmlIn.LastTag.GetAttributeInt(
                        BasicNetworkPersistor.ATTRIBUTE_TO);
                    xmlIn.ReadToTag();
                    IPersistor persistor = PersistorUtil.CreatePersistor(xmlIn
                                                                         .LastTag.Name);
                    ISynapse synapse = (ISynapse)persistor.Load(xmlIn);
                    synapse.FromLayer = this.index2layer[from];
                    synapse.ToLayer   = this.index2layer[to];
                    synapse.FromLayer.AddSynapse(synapse);
                }
                if (xmlIn.IsIt(end, false))
                {
                    break;
                }
            }
        }
 public UserController()
 //Crea un UserController y carga los usuarios
 {
     this.userPersistor = new TxtPersistor(Constants.Paths.UserProgress);
     this.userFormatter = new TxtUserFormatter(this.userPersistor);
     this.currentUsers  = userFormatter.DeSerialize();
 }
示例#3
0
 public JokeViewModel(JokePage page)
 {
     FetchJokeCommand = new Command(FetchJoke);
     StoreJokeCommand = new Command(StoreJoke);
     _jokeLabel       = page.FindByName <Label>("LabelJoke");
     _restClient      = DependencyService.Get <IRestClient>();
     _persistor       = DependencyService.Get <IPersistor>();
 }
示例#4
0
 public QuoteViewModel(QuotePage page)
 {
     _quoteLabel       = page.FindByName <Label>("QuoteLabel");
     _quoteAuthorLabel = page.FindByName <Label>("QuoteAuthorLabel");
     FetchQuoteCommand = new Command(FetchQuote);
     StoreQuoteCommand = new Command(StoreQuote);
     _restClient       = DependencyService.Get <IRestClient>();
     _persistor        = DependencyService.Get <IPersistor>();
 }
示例#5
0
        /// <summary>
        ///   Initializes a new instance of the WorkTypeManager class.
        /// </summary>
        /// <param name = "repository"></param>
        public WorkFlowBuilder(IEntityRepository repository, IPersistor Persistor, INameManager nameMgr, IWorkTypeManager worktypeManager, IContainer container)
        {
            _repository = repository;

            persistor = Persistor;

            this.nameMgr = nameMgr;

            this.worktypeManager = worktypeManager;

            this.container = container;
        }
示例#6
0
        //    private GuardAgainstNulls nullValidation = new GuardAgainstNulls();
        //Dictionary<string, Guid> TransactionNameSavedTransactions = new Dictionary<string, Guid>();
        //     Dictionary<Guid, Guid> newObjectsSavedTransactions = new Dictionary<Guid, Guid>();


        /// <summary>
        ///   Initializes a new instance of the DynamicPropertyManager class.
        /// </summary>
        /// <param name = "repository"></param>
        public DynamicPropertyManager(IEntityRepository repository, INameManager nameManager, IPersistor Persistor, IPublishService publishService)
        {
            _repository = repository;

            persistor = Persistor;

            this.nameManager = nameManager;

            typeProperties.OnMissing = OnMissingType;

            this.publishService = publishService;
        }
示例#7
0
        public void SetUp()
        {
            var container = new Container(new InMemoryPersistenceRegistry());

            theContext = new SimpleTenantContext {
                CurrentTenant = Guid.NewGuid()
            };
            container.Inject <ITenantContext>(theContext);

            thePersistor = container.GetInstance <IPersistor>();

            theRepository = container.GetInstance <IEntityRepository>();
        }
 /// <summary>
 /// Save the synapses to the specified XML writer.
 /// </summary>
 /// <param name="xmlOut">The XML writer.</param>
 private void SaveSynapses(WriteXML xmlOut)
 {
     foreach (ISynapse synapse in this.currentNetwork.Structure.Synapses)
     {
         xmlOut.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_FROM, ""
                             + this.layer2index[synapse.FromLayer]);
         xmlOut.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_TO, ""
                             + this.layer2index[synapse.ToLayer]);
         xmlOut.BeginTag(BasicNetworkPersistor.TAG_SYNAPSE);
         IPersistor persistor = synapse.CreatePersistor();
         persistor.Save(synapse, xmlOut);
         xmlOut.EndTag();
     }
 }
        /// <summary>
        /// Handle any layers that should be loaded.
        /// </summary>
        /// <param name="xmlIn">The XML reader.</param>
        private void HandleLayers(ReadXML xmlIn)
        {
            String end = xmlIn.LastTag.Name;

            while (xmlIn.ReadToTag())
            {
                if (xmlIn.IsIt(BasicNetworkPersistor.TAG_LAYER, true))
                {
                    int num = xmlIn.LastTag.GetAttributeInt(
                        BasicNetworkPersistor.ATTRIBUTE_ID);
                    String type = xmlIn.LastTag.GetAttributeValue(
                        BasicNetworkPersistor.ATTRIBUTE_TYPE);
                    xmlIn.ReadToTag();
                    IPersistor persistor = PersistorUtil.CreatePersistor(xmlIn
                                                                         .LastTag.Name);
                    ILayer layer = (ILayer)persistor.Load(xmlIn);
                    this.index2layer[num] = layer;

                    // the type attribute is actually "legacy", but if its there
                    // then use it!
                    if (type != null)
                    {
                        if (type.Equals(BasicNetworkPersistor.ATTRIBUTE_TYPE_INPUT))
                        {
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_INPUT,
                                                         layer);
                        }
                        else if (type
                                 .Equals(BasicNetworkPersistor.ATTRIBUTE_TYPE_OUTPUT))
                        {
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_OUTPUT,
                                                         layer);
                        }
                        else if (type
                                 .Equals(BasicNetworkPersistor.ATTRIBUTE_TYPE_BOTH))
                        {
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_INPUT,
                                                         layer);
                            this.currentNetwork.TagLayer(BasicNetwork.TAG_OUTPUT,
                                                         layer);
                        }
                    }
                    // end of legacy processing
                }
                if (xmlIn.IsIt(end, false))
                {
                    break;
                }
            }
        }
示例#10
0
        /// <summary>
        /// Load the contents of a location.
        /// </summary>
        /// <param name="location">The location to load from.</param>
        public void Load(IPersistenceLocation location)
        {
            PersistReader reader = null;

            this.location = location;

            try
            {
                reader = new PersistReader(location);
                IDictionary <String, String> header = reader.ReadHeader();
                if (header != null)
                {
                    this.FileVersion  = int.Parse(header["fileVersion"]);
                    this.EncogVersion = header["encogVersion"];
                    this.Platform     = header["platform"];
                }
                reader.AdvanceObjectsCollection();
                ReadXML xmlIn = reader.XMLInput;
                this.Contents.Clear();

                while (xmlIn.ReadToTag())
                {
                    if (xmlIn.IsIt(PersistReader.TAG_OBJECTS, false))
                    {
                        break;
                    }

                    String type = xmlIn.LastTag.Name;
                    String name = xmlIn.LastTag.Attributes["name"];

                    IPersistor persistor = PersistorUtil
                                           .CreatePersistor(type);

                    if (persistor == null)
                    {
                        throw new PersistError("Do not know how to load: " + type);
                    }
                    IEncogPersistedObject obj = persistor.Load(xmlIn);
                    this.Contents[name] = obj;
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                BuildDirectory();
            }
        }
        /// <summary>
        /// Save the layers to the specified XML writer.
        /// </summary>
        /// <param name="xmlOut">The XML writer.</param>
        private void SaveLayers(WriteXML xmlOut)
        {
            int current = 1;

            foreach (ILayer layer in this.currentNetwork.Structure.Layers)
            {
                xmlOut.AddAttribute(BasicNetworkPersistor.ATTRIBUTE_ID, "" + current);
                xmlOut.BeginTag(BasicNetworkPersistor.TAG_LAYER);
                IPersistor persistor = layer.CreatePersistor();
                persistor.Save(layer, xmlOut);
                xmlOut.EndTag();
                this.layer2index[layer] = current;
                current++;
            }
        }
示例#12
0
        /// <summary>
        /// Write an object.
        /// </summary>
        /// <param name="obj">The object to write.</param>
        public void WriteObject(IEncogPersistedObject obj)
        {
            IPersistor persistor = obj.CreatePersistor();

            if (persistor == null)
            {
                String str = "Can't find a persistor for object of type "
                             + obj.GetType().Name;
#if logging
                if (this.logger.IsErrorEnabled)
                {
                    this.logger.Error(str);
                }
#endif
                throw new PersistError(str);
            }
            persistor.Save(obj, this.xmlOut);
        }
示例#13
0
        public UnitOfWork(IPersistor persistor)
        {
            _persistor = persistor;

            var storage = _persistor.RestoreObject <SummaryStorage>("SUMMARY");
            var brokers = storage != null?RestoreEntities <Broker>(storage.BrokerIds, IBrokerRepository.StoragePrefix)
                              : new Dictionary <string, Broker>();

            BrokerRepo = new BrokerRepository(brokers);
            var sales = storage != null?RestoreEntities <Sale>(storage.SaleIds, ISaleRepository.StoragePrefix)
                            : new Dictionary <string, Sale>();

            SaleRepo = new SaleRepository(sales);
            var policies = storage != null?RestoreEntities <Policy>(storage.PolicyIds, IPolicyRepository.StoragePrefix)
                               : new Dictionary <string, Policy>();

            PolicyRepo = new PolicyRepository(policies);
        }
        public MainViewModel(IViewService viewService, IPersistor persistor, IDirtyService dirtyService, IMessageBoxService messageBoxService)
        {
            _viewService       = viewService;
            _persistor         = persistor;
            _dirtyService      = dirtyService;
            _messageBoxService = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService));

            SaveCommand   = new RelayCommand(() => Save(), CanSave);
            SaveAsCommand = new RelayCommand(() => SaveAs());
            OpenCommand   = new RelayCommand(Open);
            NewCommand    = new RelayCommand(New);
            EditCommand   = new RelayCommand <StateMachineReferenceViewModel>(Edit);
            AboutCommand  = new RelayCommand(About);

            _dirtyService.PropertyChanged += DirtyService_PropertyChanged;

            New();
            MessengerInstance.Register <SaveMessage>(this, Save);
        }
示例#15
0
        /// <summary>
        /// Read the specific object, search through the objects until its found.
        /// </summary>
        /// <param name="name">The name of the object you are looking for.</param>
        /// <returns>The object found, null if not found.</returns>
        public IEncogPersistedObject ReadObject(String name)
        {
            // did we find the object?
            if (Advance(name))
            {
                String     objectType = this.xmlIn.LastTag.Name;
                IPersistor persistor  = PersistorUtil
                                        .CreatePersistor(objectType);

                if (persistor == null)
                {
                    throw new PersistError(
                              "Do not know how to load: " + objectType);
                }
                return(persistor.Load(this.xmlIn));
            }
            else
            {
                return(null);
            }
        }
示例#16
0
        /// <summary>
        /// Create a persistor object.  These objects know how to persist
        /// certain types of classes.
        /// </summary>
        /// <param name="className">The name of the class to create a persistor for.</param>
        /// <returns>The persistor for the specified class.</returns>
        public static IPersistor CreatePersistor(String className)
        {
            // handle any hard coded ones
            if (className.Equals("TrainingData"))
            {
                return(new BasicNeuralDataSetPersistor());
            }

            String     name      = "Encog.Persist.Persistors." + className + "Persistor";
            IPersistor persistor = (IPersistor)Assembly.GetExecutingAssembly().CreateInstance(name);

            // try another way
            if (persistor == null)
            {
                String type = ReflectionUtil.ResolveEncogClass(className);
                IEncogPersistedObject temp =
                    (IEncogPersistedObject)ReflectionUtil.LoadObject(type);

                persistor = temp.CreatePersistor();
            }

            return(persistor);
        }
示例#17
0
        /// <summary>
        /// Perform a deep copy.
        /// Silverlight version.
        /// </summary>
        /// <param name="oldObj">The old object.</param>
        /// <returns>The new object.</returns>
        static public IEncogPersistedObject DeepCopy(IEncogPersistedObject oldObj)
        {
            bool replacedName = false;

            // encog objects won't save without a name
            if (oldObj.Name == null)
            {
                replacedName = true;
                oldObj.Name  = "temp";
            }

            // now make the copy
            MemoryStream mstream   = new MemoryStream();
            WriteXML     xmlOut    = new WriteXML(mstream);
            IPersistor   persistor = oldObj.CreatePersistor();

            xmlOut.BeginDocument();
            persistor.Save(oldObj, xmlOut);
            xmlOut.EndDocument();
            // now read it back
            mstream.Position = 0;
            ReadXML xmlIn = new ReadXML(mstream);

            xmlIn.ReadToTag();
            IEncogPersistedObject result = persistor.Load(xmlIn);

            mstream.Close();

            // put the name back to null if we changed it
            if (replacedName)
            {
                oldObj.Name = null;
                result.Name = null;
            }
            return(result);
        }
示例#18
0
 public StorageFactory(IPersistor persistor, IEnumerable <IEntityStoragePolicy> policies)
 {
     _persistor = persistor;
     _policies  = policies;
 }
示例#19
0
 public TxtUserFormatter(IPersistor persistor)
 //Crea un TxtUserFormatter y asigna un IPersistor
 {
     this.persistor = persistor;
 }
示例#20
0
 public Worker(IConsumer consumption, IPersistor persistor)
 {
     Consumer  = consumption;
     Persistor = persistor;
 }
示例#21
0
 public BlockingDataHandler(IPersistor <T> persistor)
 {
     _persistor   = persistor;
     _datacontext = LoadDataContext();
     Task.Run(ProcessActions);
 }
示例#22
0
 /// <summary>
 /// Save object to persistent storage
 /// </summary>
 /// <param name="persistor"></param>
 /// <param name="storageId">Storage Id, e.g. BrokerState_B101.</param>
 /// <param name="objectToPersist"></param>
 internal static void PersistObject(this IPersistor persistor, string storageId, object objectToPersist)
 {
     persistor.PersistJson(storageId, JsonConvert.SerializeObject(objectToPersist));
 }
示例#23
0
文件: Depot.cs 项目: jysummers/ddd
 public Depot(IPersistor persistor, IRetriever retriever)
 {
     Persistor = persistor;
     Retriever = retriever;
 }
示例#24
0
 public EntityStorage(IPersistor persistor)
 {
     _persistor = persistor;
 }
 public InMemoryPersistenceReset(IPersistor persistor)
 {
     _persistor = persistor.As<InMemoryPersistor>();
 }
示例#26
0
 public StorageController(IPersistor persistor, IUnitOfWork unitOfWork)
 {
     _persistor  = persistor;
     _unitOfWork = unitOfWork;
 }
        public void SetUp()
        {
            var container = new Container(new InMemoryPersistenceRegistry());
            theContext = new SimpleTenantContext {CurrentTenant = Guid.NewGuid()};
            container.Inject<ITenantContext>(theContext);

            thePersistor = container.GetInstance<IPersistor>();

            theRepository = container.GetInstance<IEntityRepository>();
        }
示例#28
0
 public PeriodDataAccess(IPersistor persistor)
 {
     _persistor = persistor ?? throw new ArgumentNullException(nameof(persistor));
 }
 public InMemoryPersistenceReset(IPersistor persistor)
 {
     _persistor = persistor.As <InMemoryPersistor>();
 }
示例#30
0
        /// <summary>
        /// Restore object of given type from persistent storage
        /// </summary>
        /// <typeparam name="T">Type of the object, e.g. Broker.</typeparam>
        /// <param name="persistor"></param>
        /// <param name="storageId">Storage Id, e.g. BrokerState_B101.</param>
        /// <returns>Restored object or null if not found.</returns>
        internal static T RestoreObject <T>(this IPersistor persistor, string storageId) where T : class
        {
            var json = persistor.RetrieveJson(storageId);

            return(json == null ? null : JsonConvert.DeserializeObject <T>(json));
        }