Esempio n. 1
0
        /// <summary>
        /// Adds a structure to the circuit that tries to guarantee a minimum
        /// </summary>
        /// <param name="circuit">The circuit.</param>
        /// <param name="name">A unique name for the elements.</param>
        /// <param name="lowest">The lowest node.</param>
        /// <param name="highest">The highest node.</param>
        /// <param name="minimum">The minimum between the two.</param>
        public static void AddMinimum(IEntityCollection circuit, string name, string lowest, string highest, double minimum, double weight = 1e-3)
        {
            string i = $"{name}.i";

            circuit.Add(new Resistor($"R{name}", highest, lowest, 1.0 / weight));
            circuit.Add(new VoltageSource($"V{name}", i, lowest, minimum));
            AddRectifyingElement(circuit, $"D{name}", i, highest);
        }
        /// <summary>
        /// Adds a structure to the circuit that tries to guarantee an offset between two nodes.
        /// </summary>
        /// <param name="circuit">The circuit.</param>
        /// <param name="name">A unique name for the elements.</param>
        /// <param name="lowest">The lowest node.</param>
        /// <param name="highest">The highest node.</param>
        /// <param name="offset">The offset.</param>
        public static void AddOffset(IEntityCollection circuit, string name, string lowest, string highest, double offset)
        {
            // string i = $"{name}.i";
            // circuit.Add(new Resistor($"R{name}", i, highest, 1e-6));
            // circuit.Add(new VoltageSource($"V{name}", i, lowest, offset));

            // Northon equivalent has less unknowns to solve
            circuit.Add(new Resistor($"R{name}", highest, lowest, 1e-6));
            circuit.Add(new CurrentSource($"I{name}", lowest, highest, offset * 1e6));
        }
        private static void AddControlledMinimum(IEntityCollection ckt, string name, string lowX, string highX, string lowY, string highY, Vector2 direction)
        {
            string i = $"{name}.xc";

            MinimumConstraint.AddRectifyingElement(ckt, $"D{i}", i, highX);
            ckt.Add(new VoltageControlledVoltageSource($"E{i}", i, lowX, highY, lowY, direction.X / direction.Y));

            i = $"{name}.yc";
            MinimumConstraint.AddRectifyingElement(ckt, $"D{i}", i, highY);
            ckt.Add(new VoltageControlledVoltageSource($"E{i}", i, lowY, highX, lowX, direction.Y / direction.X));
        }
Esempio n. 4
0
 internal void SetValue(string name, object value, Type propertyType)
 {
     if (EntityCtx.DynamicProperties.IsNotNull())
     {
         IEnumerable <Entity> entities = this[EntityCtx.DynamicProperties.Property.Name] as IEnumerable <Entity>;
         if (entities.IsNotNull())
         {
             Entity entity = entities.FirstOrDefault(e => e[EntityCtx.DynamicProperties.CodeProperty].IsNotNull() && e[EntityCtx.DynamicProperties.CodeProperty].Equals(name));
             if (entity.IsNotNull())
             {
                 if (EntityCtx.DynamicProperties.ValuesProperties.ContainsKey(propertyType))
                 {
                     entity[EntityCtx.DynamicProperties.ValuesProperties[propertyType]] = value;
                 }
             }
             else
             {
                 IEntityCollection collection = entities as IEntityCollection;
                 if (collection.IsNotNull())
                 {
                     entity = collection.CreateInstance(EntityCtx.DynamicProperties.Property.ReletedEntity.RelatedEntity.EntityType, true, null) as Entity;
                     if (entity.IsNotNull())
                     {
                         if (EntityCtx.DynamicProperties.ValuesProperties.ContainsKey(propertyType))
                         {
                             entity[EntityCtx.DynamicProperties.ValuesProperties[propertyType]] = value;
                         }
                         entity[EntityCtx.DynamicProperties.CodeProperty] = name;
                         collection.Add(entity);
                     }
                 }
             }
         }
     }
 }
Esempio n. 5
0
 public void FillContext(WorksheetContext ctx)
 {
     ctx.Context.Entites.ForEach((e) =>
     {
         Attribute attribute = e.Attributes.FirstOrDefault(a => a.IsTypeOf <Table>());
         if (attribute.IsNotNull())
         {
             Table table = attribute.CastToType <Table>();
             if (_dataSet.Tables.Contains(table.TableName))
             {
                 IEntityCollection collection = e.Entities as IEntityCollection;
                 if (collection.IsNotNull())
                 {
                     foreach (DataRow row in _dataSet.Tables[table.TableName].Rows)
                     {
                         Entity entity = collection.CreateInstance(e.EntityType, true, new object[] { row }) as Entity;
                         if (entity.IsNotNull())
                         {
                             collection.Add(entity);
                         }
                     }
                 }
             }
         }
     });
     ctx.AcceptChanges();
 }
Esempio n. 6
0
        /// <summary>
        /// Constructor injection.
        /// </summary>
        /// <param name="analyticsService">Analytics service.</param>
        /// <param name="dataContext">Data context.</param>
        /// <param name="anilibriaApiService">Anilibria restful service.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public OnlinePlayerViewModel(IAnalyticsService analyticsService, IDataContext dataContext, IAnilibriaApiService anilibriaApiService)
        {
            m_AnalyticsService    = analyticsService ?? throw new ArgumentNullException(nameof(analyticsService));
            m_AnilibriaApiService = anilibriaApiService ?? throw new ArgumentNullException(nameof(anilibriaApiService));
            m_DataContext         = dataContext ?? throw new ArgumentNullException(nameof(dataContext));
            m_IsSD   = true;
            m_Volume = .8;

            RestoreSettings();

            UpdateVolumeState(m_Volume);

            CreateCommands();

            m_RestoreCollection   = m_DataContext.GetCollection <PlayerRestoreEntity> ();
            m_PlayerRestoreEntity = m_RestoreCollection.FirstOrDefault();
            if (m_PlayerRestoreEntity == null)
            {
                m_PlayerRestoreEntity = new PlayerRestoreEntity {
                    ReleaseId     = -1,
                    VideoId       = -1,
                    VideoPosition = 0
                };
                m_RestoreCollection.Add(m_PlayerRestoreEntity);
            }

            m_ReleaseStateCollection    = m_DataContext.GetCollection <ReleaseVideoStateEntity> ();
            m_IsSupportedCompactOverlay = ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay);
        }
Esempio n. 7
0
 /// <summary>
 /// Creates a subcircuit definition with a component in parallel and series.
 /// </summary>
 public static void ParallelSeries(IEntityCollection ckt, Func <string, IComponent> factory, string ca, string cb, int m, int n)
 {
     for (var j = 0; j < m; j++)
     {
         for (var i = 0; i < n; i++)
         {
             var    clone = factory("entity" + j.ToString() + "_" + i.ToString());
             string a, b;
             if (i == 0)
             {
                 a = ca;
             }
             else
             {
                 a = "n" + j.ToString() + "_" + (i - 1).ToString();
             }
             if (i == n - 1)
             {
                 b = cb;
             }
             else
             {
                 b = "n" + j.ToString() + "_" + i.ToString();
             }
             clone.Connect(a, b);
             ckt.Add(clone);
         }
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Adds or replaces an entity in the given collection.
 /// </summary>
 public static void AddOrReplace <T>(this IEntityCollection <T> collection, T entity)
     where T : Entities.GTFSEntity
 {
     if (!collection.Contains(entity))
     {
         collection.Add(entity);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Creates an <see cref="IEntity"/> and places it in the given <paramref name="entityCollection"/>.
        /// </summary>
        /// <typeparam name="TAllowedType"></typeparam>
        /// <param name="alias">The alias.</param>
        /// <param name="name">The name.</param>
        /// <param name="entityCollection">The entity collection.</param>
        /// <returns></returns>
        public static T CreateIn <T>(string alias, string name, IEntityCollection <T> entityCollection)
            where T : class, IEntity, IReferenceByAlias, new()
        {
            var entity = Create <T>(alias, name);

            entityCollection.Add(entity);
            return(entity);
        }
        /// <summary>
        /// Save player restore state.
        /// </summary>
        public void SavePlayerRestoreState()
        {
            if (SelectedOnlineVideo == null)
            {
                return;
            }

            var isNotNeedUpdatePosition = m_PlayerRestoreEntity?.ReleaseId == SelectedRelease?.Id && m_PlayerRestoreEntity?.VideoPosition > 0 && Position == 0;

            m_PlayerRestoreEntity.ReleaseId = SelectedRelease.Id;
            m_PlayerRestoreEntity.VideoId   = SelectedOnlineVideo.Order;
            if (!isNotNeedUpdatePosition)
            {
                m_PlayerRestoreEntity.VideoPosition = Position;
            }
            m_RestoreCollection.Update(m_PlayerRestoreEntity);

            if (m_ReleaseVideoStateEntity == null || m_ReleaseVideoStateEntity.ReleaseId != SelectedRelease.Id)
            {
                m_ReleaseVideoStateEntity = m_ReleaseStateCollection.FirstOrDefault(a => a.ReleaseId == SelectedRelease.Id);
                if (m_ReleaseVideoStateEntity == null)
                {
                    m_ReleaseVideoStateEntity = new ReleaseVideoStateEntity {
                        ReleaseId   = SelectedRelease.Id,
                        VideoStates = new List <VideoStateEntity> ()
                    };
                    m_ReleaseStateCollection.Add(m_ReleaseVideoStateEntity);
                }
            }

            if (m_ReleaseVideoStateEntity.VideoStates == null)
            {
                m_ReleaseVideoStateEntity.VideoStates = new List <VideoStateEntity> ();
            }

            var videoState = m_ReleaseVideoStateEntity.VideoStates.FirstOrDefault(a => a.Id == SelectedOnlineVideo.Order);

            if (videoState == null)
            {
                m_ReleaseVideoStateEntity.VideoStates.Add(
                    new VideoStateEntity {
                    Id           = SelectedOnlineVideo.Order,
                    LastPosition = Position
                }
                    );
            }
            else
            {
                videoState.LastPosition = Position == 0 && videoState.LastPosition > 0 ? videoState.LastPosition : Position;

                if (!videoState.IsSeen && PositionPercent >= 90 && PositionPercent <= 100)
                {
                    videoState.IsSeen = true;
                }
            }

            m_ReleaseStateCollection.Update(m_ReleaseVideoStateEntity);
        }
Esempio n. 11
0
        /// <summary>
        /// Fills the specified destination collection using data coming from the given source
        /// and adapting the source data to the destination format using the speficied adapter
        /// delegate.
        /// </summary>
        /// <typeparam name="TSource">The type of the source.</typeparam>
        /// <typeparam name="TDest">The type of the destination.</typeparam>
        /// <param name="source">The source data.</param>
        /// <param name="destination">The destination container.</param>
        /// <param name="adapter">The adapter.</param>
        /// <returns>
        /// The a reference to the supplied destination container to allow fluent interface usage.
        /// </returns>
        public static IEntityCollection <TDest> Fill <TSource, TDest>(this IQueryable <TSource> source, IEntityCollection <TDest> destination, Func <TSource, IEntityCollection <TDest>, TDest> adapter)
            where TDest : class
        {
            destination.BeginInit();
            source.ForEach(element => destination.Add(adapter(element, destination)));
            destination.EndInit();

            return(destination);
        }
        public static IEntityCollection <T> BulkLoad <T, TSource>(this IEntityCollection <T> list, IEnumerable <TSource> data, Func <TSource, T> adapter)
            where T : class
        {
            list.BeginInit();
            foreach (var item in data)
            {
                list.Add(adapter(item));
            }
            list.EndInit(true);

            return(list);
        }
Esempio n. 13
0
        private static void AddExits(IEntityCollection <ExitPoint> exitPoints, string[] exits)
        {
            bool isFirstExit = true;

            foreach (var exit in exits)
            {
                var ep = Entity.Create <ExitPoint>();
                ep.Name = exit;
                ep.IsDefaultExitPoint = isFirstExit;
                exitPoints.Add(ep);
                isFirstExit = false;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Adds the diode model that can be used to define minimum constraints.
        /// </summary>
        /// <param name="circuit">The circuit.</param>
        public static void AddRectifyingModel(IEntityCollection circuit)
        {
            if (circuit.Contains(DiodeModelName))
            {
                return;
            }
            var model = new VoltageSwitchModel(DiodeModelName);

            model.Parameters.OnResistance  = 1e-6;
            model.Parameters.OffResistance = 1e9;
            model.Parameters.Hysteresis    = 1e-3;
            model.Parameters.Threshold     = 0.0;
            circuit.Add(model);
        }
Esempio n. 15
0
        public DownloadService(IDataContext dataContext)
        {
            m_DataContext = dataContext;
            m_Collection  = m_DataContext.GetCollection <DownloadFileEntity> ();

            m_Entity = m_Collection.FirstOrDefault();
            if (m_Entity == null)
            {
                m_Entity = new DownloadFileEntity {
                    DownloadingReleases = new List <DownloadReleaseEntity> ()
                };
                m_Collection.Add(m_Entity);
            }
            m_SpeedTimer.Interval = TimeSpan.FromSeconds(1);
            m_SpeedTimer.Tick    += SpeedTimerTick;
        }
Esempio n. 16
0
        private ChangesEntity GetChanges(IEntityCollection <ChangesEntity> changesCollection)
        {
            var changes = changesCollection.FirstOrDefault();

            if (changes == null)
            {
                changes = new ChangesEntity {
                    NewOnlineSeries  = new Dictionary <long, int> (),
                    NewReleases      = new List <long> (),
                    NewTorrents      = new Dictionary <long, int> (),
                    NewTorrentSeries = new Dictionary <long, IDictionary <long, string> > ()
                };
                changesCollection.Add(changes);
            }

            return(changes);
        }
Esempio n. 17
0
        private void FillReleaseVideoState()
        {
            if (m_ReleaseVideoStateEntity == null || m_ReleaseVideoStateEntity.ReleaseId != SelectedRelease.Id)
            {
                m_ReleaseVideoStateEntity = m_ReleaseStateCollection.FirstOrDefault(a => a.ReleaseId == SelectedRelease.Id);
                if (m_ReleaseVideoStateEntity == null)
                {
                    m_ReleaseVideoStateEntity = new ReleaseVideoStateEntity {
                        ReleaseId   = SelectedRelease.Id,
                        VideoStates = new List <VideoStateEntity> ()
                    };
                    m_ReleaseStateCollection.Add(m_ReleaseVideoStateEntity);
                }
            }

            if (m_ReleaseVideoStateEntity.VideoStates == null)
            {
                m_ReleaseVideoStateEntity.VideoStates = new List <VideoStateEntity> ();
            }
        }
Esempio n. 18
0
 private static void SplitCollectionForInsertUpdateAndDeleteOperations(IEntityCollection entitiesToSave, out IEntityCollection newEntities, out IEntityCollection changedEntities, out IEntityCollection removedEntities)
 {
     IDbTable table = entitiesToSave.IDbTable;
     newEntities = table.NewEntityCollection();
     changedEntities = table.NewEntityCollection();
     removedEntities = table.NewEntityCollection();
     foreach (IEntity entity in entitiesToSave)
     {
         switch (entity.EntityState)
         {
             case EntityState.New:
                 newEntities.Add(entity);
                 break;
             case EntityState.OutOfSync:
                 changedEntities.Add(entity);
                 break;
             case EntityState.PendingDeletion:
                 removedEntities.Add(entity);
                 break;
         }
     }
 }
 public void Setup()
 {
     entityCollection = new EntityCollection();
     entity = new Entity(new VariableCollection());
     entityCollection.Add(entity);
 }
Esempio n. 20
0
 /// <summary>
 /// Adds an item to the <see cref="ICollection{T}" />.
 /// </summary>
 /// <param name="item">The object to add to the <see cref="ICollection{T}" />.</param>
 public void Add(IEntity item) => _entities.Add(item);
Esempio n. 21
0
 public void Setup()
 {
     entityCollection = new EntityCollection();
     entity           = new Entity(new VariableCollection());
     entityCollection.Add(entity);
 }
Esempio n. 22
0
 /// <summary>
 /// Adds an idealized diode. I.e. an element that conducts if <paramref name="from"/> is
 /// higher than <paramref name="to"/>.
 /// </summary>
 /// <remarks>
 /// This isn't really a diode, but a voltage-controlled switch. But for thinking it helps to look at it
 /// like a diode.
 /// </remarks>
 /// <param name="circuit">The circuit to add the diode to.</param>
 /// <param name="name">The name of the diode.</param>
 /// <param name="from">The name of the node where currents flows away.</param>
 /// <param name="to">The name of the node where current flows into.</param>
 public static void AddRectifyingElement(IEntityCollection circuit, string name, string from, string to)
 {
     AddRectifyingModel(circuit);
     circuit.Add(new VoltageSwitch(name, from, to, from, to, DiodeModelName));
 }