Пример #1
0
 /// <summary>
 /// Disposes the provided elements.
 /// </summary>
 public void Dispose(ElementStateCollection elements)
 {
     using (LogGroup logGroup = LogGroup.Start("Disposing the provided elements.", NLog.LogLevel.Debug))
     {
         elements.Clear();
     }
 }
Пример #2
0
        /// <summary>
        /// Updates the provided entity back to the data store.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>A bool value indicating the success of the update. If it fails it's due to the entity being invalid.</returns>
        public virtual bool ExecuteUpdate(IEntity entity)
        {
            bool didSucceed = false;

            using (LogGroup logGroup = LogGroup.Start("Updating the provided entity.", NLog.LogLevel.Debug))
            {
                if (EnsureAuthorised())
                {
                    DataSource = entity;

                    if (entity == null)
                    {
                        throw new ArgumentNullException("entity");
                    }

                    // Update the entity
                    if (Updater.Update(entity))
                    {
                        Result.Display(DynamicLanguage.GetEntityText(EntityUpdatedLanguageKey, Command.TypeName));

                        didSucceed = true;
                    }
                    else
                    {
                        // Add the validation error to the result control
                        Validation.DisplayError(entity);

                        didSucceed = false;
                    }
                }

                LogWriter.Debug("Did succeed: " + didSucceed.ToString());
            }
            return(didSucceed);
        }
        /// <summary>
        /// Initializes the strategies and loads all strategies to state. Note: Skips initialization if already initialized.
        /// </summary>
        public void Initialize(bool includeTestStrategies)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Initializing the business strategies."))
            {
                if (!StrategyState.IsInitialized)
                {
                    StrategyInfo[] strategies = new StrategyInfo[] {};
                    if (IsCached)
                    {
                        LogWriter.Debug("Is cached. Loading from XML.");

                        strategies = LoadStrategies();
                    }
                    else
                    {
                        LogWriter.Debug("Is not cached. Scanning from type attributes.");

                        strategies = FindStrategies(includeTestStrategies);
                        Saver.SaveToFile(strategies);
                    }

                    Initialize(strategies);
                }
                else
                {
                    LogWriter.Debug("Already initialized.");
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Gets the name of the data store that the provided entity is stored in.
        /// </summary>
        /// <param name="entity">The entity to get the data store name for.</param>
        /// <param name="throwErrorIfNotFound">A flag indicating whether an error should be thrown when no data store attribute is found.</param>
        /// <returns>The data store that the provided entity is stored in.</returns>
        static public string GetDataStoreName(IEntity entity, bool throwErrorIfNotFound)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            string dataStoreName = String.Empty;
            Type   type          = entity.GetType();

            using (LogGroup logGroup = LogGroup.Start("Retrieving data store name for entity of type '" + type.ToString() + "'.", LogLevel.Debug))
            {
                if (EntitiesUtilities.IsReference(entity))
                {
                    LogWriter.Debug("Provided entity is an EntityReference");

                    EntityReference reference = (EntityReference)entity;

                    dataStoreName = GetDataStoreName(new string[] { reference.Type1Name, reference.Type2Name });
                }
                else
                {
                    LogWriter.Debug("Provided entity is NOT an EntityReference.");

                    dataStoreName = GetDataStoreName(entity.GetType());
                }

                LogWriter.Debug("Data store name: " + dataStoreName);
            }

            return(dataStoreName);
        }
Пример #5
0
        /// <summary>
        /// Prepares the edit form with the entity specified by the ID or unique key in the query string.
        /// </summary>
        /// <returns>The entity specified in the query string.</returns>
        public virtual IEntity PrepareEdit()
        {
            IEntity entity = null;

            using (LogGroup logGroup = LogGroup.Start("Preparing to edit an entity.", NLog.LogLevel.Debug))
            {
                Guid   id        = GetID();
                string uniqueKey = GetUniqueKey();

                if (id != Guid.Empty)
                {
                    LogWriter.Debug("ID: " + id.ToString());
                    entity = PrepareEdit(id);
                }
                else if (uniqueKey != String.Empty)
                {
                    LogWriter.Debug("Unique key: " + uniqueKey);
                    entity = PrepareEdit(uniqueKey);
                }
                else
                {
                    throw new InvalidOperationException("Cannot edit entity. No identifier found.");
                }
            }
            return(entity);
        }
        /// <summary>
        /// Locates the projection info for performing the specified action with the specified type by looking at the interfaces of the provided type.
        /// </summary>
        /// <param name="action">The action that is to be performed by the projection.</param>
        /// <param name="type">The type that is involved in the action.</param>
        /// <param name="format">The output format of the projection to location.</param>
        /// <returns>The projection info for the specified scenario.</returns>
        public ProjectionInfo LocateFromInterfaces(string action, Type type, ProjectionFormat format)
        {
            ProjectionInfo projectionInfo = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Locating projection from type interfaces."))
            {
                Type[] interfaceTypes = type.GetInterfaces();

                // Loop backwards through the interface types
                for (int i = interfaceTypes.Length - 1; i >= 0; i--)
                {
                    Type interfaceType = interfaceTypes[i];

                    string key = Projections.GetProjectionKey(action, interfaceType.Name, format);

                    if (Projections.ContainsKey(key))
                    {
                        projectionInfo = Projections.GetByKey(key);

                        break;
                    }
                }
            }

            return(projectionInfo);
        }
Пример #7
0
        static public Type GetEntityType(IEntity entity, PropertyInfo property)
        {
            Type type = null;

            using (LogGroup group = LogGroup.Start("Retrieving the type of entity being referenced by the provided property.", LogLevel.Debug))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                if (property == null)
                {
                    throw new ArgumentNullException("property");
                }

                LogWriter.Debug("Entity type: " + entity.GetType().ToString());
                LogWriter.Debug("Property name: " + property.Name);
                LogWriter.Debug("Property type: " + property.PropertyType.Name);

                type = EntitiesUtilities.GetReferenceType(entity, property);
            }

            if (type == null)
            {
                LogWriter.Debug("return type == null");
            }
            else
            {
                LogWriter.Debug("return type == " + type.ToString());
            }

            return(type);
        }
        public void Test_Setup()
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Testing the ApplicationInstaller.Setup function."))
            {
                CreateDummyVersionFile(TestUtilities.GetTestApplicationPath(this, "MockApplication"));

                User admin = new User();
                admin.ID        = Guid.NewGuid();
                admin.Username  = "******";
                admin.Password  = Crypter.EncryptPassword("pass");
                admin.Validator = ValidateStrategy.New(admin);

                ApplicationInstaller installer = new ApplicationInstaller();
                installer.ApplicationPath         = "/MockApplication";
                installer.Administrator           = admin;
                installer.AdministratorRoleName   = "Administrator";
                installer.PathVariation           = "testing";
                installer.FileMapper              = new MockFileMapper(this);
                installer.DataProviderInitializer = new MockDb4oDataProviderInitializer(this);
                installer.EnableTesting           = true;
                installer.Setup();

                User foundAdministrator = DataAccess.Data.Reader.GetEntity <User>("ID", admin.ID);

                DataAccess.Data.Activator.Activate(foundAdministrator);

                Assert.AreEqual(1, foundAdministrator.Roles.Length, "The administrator user isn't in the administrator role.");
            }
        }
Пример #9
0
        /// <summary>
        /// Prepares the provided entity for saving.
        /// </summary>
        /// <param name="entity">The entity to prepare for saving.</param>
        /// <param name="handleReferences">A value indicating whether to delete old references and save new references.</param>
        public override void PreSave(IEntity entity, bool handleReferences)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Preparing entity for saving: " + entity.GetType().ToString()))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                entity.PreStore();

                // If the entity is NOT a reference object (ie. it's a standard entity)
                // then prepare the save.
                // If is IS a reference object the preparation is not needed and should be skipped
                if (!(entity is EntityReference))
                {
                    Type entityType = entity.GetType();

                    LogWriter.Debug("Entity type: " + entityType.ToString());

                    if (handleReferences)
                    {
                        // Maintain the entity references
                        Provider.Referencer.MaintainReferences(entity);
                    }

                    LogWriter.Debug("Presave complete.");
                }
            }
        }
Пример #10
0
        public override void NavigateAfterUpdate()
        {
            using (LogGroup logGroup = LogGroup.Start("Navigating after a update operation.", NLog.LogLevel.Debug))
            {
                if (DataSource == null)
                {
                    throw new InvalidOperationException("The DataSource property isn't set.");
                }

                ISubEntity entity = (ISubEntity)DataSource;

                if (entity.Parent == null)
                {
                    LogWriter.Debug("No parent found. Activating entity.Parent.");

                    ActivateStrategy.New <ISubEntity>().Activate(entity, entity.ParentPropertyName);
                }

                if (entity.Parent == null)
                {
                    throw new Exception("No parent assigned to entity.");
                }

                Navigator.Current.NavigateAfterOperation("View", entity.Parent);
            }
        }
Пример #11
0
            public LogEntry(DebugLogWindow window, ref LogEntryDescription desc)
                : base(0, 0, 120, DefaultHeight)
            {
                AnchorPreset = AnchorPresets.HorizontalStretchTop;
                IsScrollable = true;

                _window = window;
                Desc    = desc;
                switch (desc.Level)
                {
                case LogType.Warning:
                    Group = LogGroup.Warning;
                    Icon  = _window.IconWarning;
                    break;

                case LogType.Info:
                    Group = LogGroup.Info;
                    Icon  = _window.IconInfo;
                    break;

                default:
                    Group = LogGroup.Error;
                    Icon  = _window.IconError;
                    break;
                }
            }
Пример #12
0
        /// <summary>
        /// Checks whether the command applies to the reference provided as a serialized XML document.
        /// </summary>
        /// <param name="document">The serialized reference as an XML document.</param>
        /// <returns>A boolean flag indicating whether the command applies to the provided XML document.</returns>
        public bool AppliesToReference(XmlDocument document)
        {
            bool doesApply = false;

            using (LogGroup logGroup = LogGroup.Start("Checking whether the command applies to the provided XML document.", LogLevel.Debug))
            {
                XmlNode type1Node = document.DocumentElement.SelectSingleNode("Type1Name");

                XmlNode type2Node = document.DocumentElement.SelectSingleNode("Type2Name");

                if (type1Node == null)
                {
                    throw new ArgumentException("The provided document doesn't have a 'Type1Name' node.");
                }

                if (type2Node == null)
                {
                    throw new ArgumentException("The provided document doesn't have a 'Type2Name' node.");
                }

                LogWriter.Debug("Type 1 name: " + type1Node.InnerText);
                LogWriter.Debug("Type 2 name: " + type2Node.InnerText);
                LogWriter.Debug("Expected type name: " + TypeName);

                // The command applies if either of the type nodes match the type on the command
                doesApply = type1Node.InnerText == TypeName ||
                            type2Node.InnerText == TypeName;
            }

            return(doesApply);
        }
Пример #13
0
        public void Test_LocateFromInterfaces()
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Testing the LocateFromInterfaces function."))
            {
                string action   = "Save";
                string typeName = "MockEntity";

                ReactionLocator locator = new ReactionLocator(ReactionState.Reactions);

                ReactionInfo[] reactions = locator.LocateFromInterfaces(action, EntityState.GetType(typeName));

                foreach (ReactionInfo reaction in reactions)
                {
                    Type expectedType = EntityState.GetType(typeName);
                    Type actualType   = EntityState.GetType(reaction.TypeName);

                    bool doMatch = expectedType.Equals(actualType) ||
                                   expectedType.IsAssignableFrom(actualType) ||
                                   actualType.IsAssignableFrom(expectedType);

                    Assert.IsTrue(doMatch, "The type '" + reaction.TypeName + "' on '" + reaction.GetType().FullName + "' reaction does not match expected type '" + typeName + "'.");
                }

                Assert.AreEqual(1, reactions.Length, "Invalid number of reactions found.");
            }
        }
        internal EventBridgeCloudWatchDotnetCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            // CloudWatch Log Group
            var cloudWatchLogGroup = new LogGroup(this, "CloudWatchLogs", new LogGroupProps
            {
                RemovalPolicy = RemovalPolicy.DESTROY,
                Retention     = RetentionDays.ONE_DAY
            });

            // EventBridge Event Bus
            var eventBus = new EventBus(this, "MyCloudWatchEventBus", new EventBusProps
            {
                EventBusName = "MyCloudWatchEventBus"
            });

            // EventBridge Rule
            var cloudWatchLogsRule = new Rule(this, "cloudWatchLogsRule", new RuleProps
            {
                Description  = "CloudWatch Logs Event Bus Rule",
                EventPattern = new EventPattern
                {
                    Source = new[] { "cdk.myapp" }
                },
                EventBus = eventBus
            });

            cloudWatchLogsRule.AddTarget(new CloudWatchLogGroup(cloudWatchLogGroup));

            // CDK Outputs
            new CfnOutput(this, "LogGroupName", new CfnOutputProps
            {
                Value       = cloudWatchLogGroup.LogGroupName !,
                Description = "CloudWatch Log Group Name"
            });
        public void Test_IsMatch()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the ReferenceFilter.IsMatch function.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID = Guid.NewGuid();

                TestCategory category = new TestCategory();
                category.ID = Guid.NewGuid();


                article.Categories = new TestCategory[] { category };

                DataAccess.Data.Saver.Save(category);
                DataAccess.Data.Saver.Save(article);

                ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateFilter(typeof(ReferenceFilter));
                filter.Operator           = FilterOperator.Equal;
                filter.PropertyName       = "Categories";
                filter.ReferencedEntityID = category.ID;
                filter.ReferenceType      = typeof(TestCategory);
                filter.AddType(typeof(TestArticle));


                bool isMatch = filter.IsMatch(article);
                Assert.IsTrue(isMatch, "The IsMatch function returned false when it should have been true.");
            }
        }
Пример #16
0
 public void PostSave(IEntity entity)
 {
     using (LogGroup logGroup = LogGroup.StartDebug("Executing post-save for entity type '" + entity.ShortTypeName + "'."))
     {
         Provider.Referencer.SetMirrorCountProperties(entity);
     }
 }
Пример #17
0
        /// <summary>
        /// Index the entity with a references that matches the provided parameters.
        /// </summary>
        /// <param name="propertyName">The name of the property containing the references.</param>
        /// <param name="referencedEntityType">The type of the entity being referenced.</param>
        /// <param name="referencedEntityID">The ID of the entity being referenced.</param>
        /// <returns>The entity matching the provided parameters.</returns>
        public virtual IEntity[] IndexWithReference(string propertyName, string referencedEntityType, Guid referencedEntityID)
        {
            IEntity[] entities = new IEntity[] {};

            using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Type name: " + TypeName);

                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Reference entity type: " + referencedEntityType);
                LogWriter.Debug("Referenced entity ID: " + referencedEntityID.ToString());

                LogWriter.Debug("Enable paging: " + EnablePaging.ToString());

                LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString());

                entities = (IEntity[])Reflector.InvokeGenericMethod(this,
                                                                    "IndexWithReference",
                                                                    new Type[] { EntityState.Entities[TypeName].GetEntityType() },
                                                                    new object[] { propertyName, referencedEntityType, referencedEntityID });

                if (RequireAuthorisation)
                {
                    AuthoriseIndexStrategy.New(TypeName).EnsureAuthorised(ref entities);
                }

                React(entities);

                LogWriter.Debug("Entity count: " + entities.Length);
            }
            return(entities);
        }
Пример #18
0
 public void PostUpdate(IEntity entity)
 {
     using (LogGroup logGroup = LogGroup.StartDebug("Executing post-update."))
     {
         Provider.Referencer.SetMirrorCountProperties(entity);
     }
 }
Пример #19
0
        /// <summary>
        /// Locates the projection info for performing the specified action with the specified type by looking at the base types of the provided type.
        /// </summary>
        /// <param name="action">The action that is to be performed by the projection.</param>
        /// <param name="type">The type that is involved in the action.</param>
        /// <param name="format">The output format of the projection to locate.</param>
        /// <returns>The projection info for the specified scenario.</returns>
        public ProjectionInfo LocateFromBaseTypes(string action, Type type, ProjectionFormat format)
        {
            ProjectionInfo projectionInfo = null;

            using (LogGroup logGroup = LogGroup.StartDebug("Locating projection from base types."))
            {
                TypeNavigator navigator = new TypeNavigator(type);

                while (navigator.HasNext && projectionInfo == null)
                {
                    Type nextType = navigator.Next();

                    string key = Projections.GetProjectionKey(action, nextType.Name, format);

                    // If a projection exists for the base type then use it
                    if (Projections.ContainsKey(key))
                    {
                        projectionInfo = Projections.GetByKey(key);

                        break;
                    }
                }
            }
            return(projectionInfo);
        }
Пример #20
0
        public virtual void Test_Save_SetsCountPropertyForReference()
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Testing the Save function to ensure it sets the reference count properties."))
            {
                MockEntity entity = new MockEntity();
                entity.ID = Guid.NewGuid();

                MockSyncEntity referencedEntity = new MockSyncEntity();
                referencedEntity.ID = Guid.NewGuid();

                entity.SyncEntities = new MockSyncEntity[] {
                    referencedEntity
                };

                DataAccess.Data.Saver.Save(referencedEntity);
                DataAccess.Data.Saver.Save(entity);

                MockEntity     foundEntity           = DataAccess.Data.Reader.GetEntity <MockEntity>("ID", entity.ID);
                MockSyncEntity foundReferencedEntity = DataAccess.Data.Reader.GetEntity <MockSyncEntity>("ID", referencedEntity.ID);

                DataAccess.Data.Activator.Activate(foundEntity);
                DataAccess.Data.Activator.Activate(foundReferencedEntity);

                Assert.AreEqual(1, foundEntity.TotalSyncEntities, "The TotalSyncEntities property didn't have the expected value.");
                Assert.AreEqual(1, foundEntity.SyncEntities.Length, "The SyncEntities property didn't have the expected length.");

                Assert.AreEqual(1, foundReferencedEntity.TotalEntities, "The TotalEntities property didn't have the expected value.");
                Assert.AreEqual(1, foundReferencedEntity.Entities.Length, "The Entities property didn't have the expected length.");
            }
        }
Пример #21
0
        // TODO: Check if function should be removed
        static public void StripReferences(IEntity entity)
        {
            using (LogGroup logGroup2 = LogGroup.Start("Clearing all the object references so that they don't cascade automatically.", LogLevel.Debug))
            {
                if (entity is EntityReference)
                {
                    ((EntityReference)entity).Deactivate();
                }
                else
                {
                    //  Clear all the references from the entity once they're ready to be saved separately
                    foreach (PropertyInfo property in entity.GetType().GetProperties())
                    {
                        LogWriter.Debug("Property name: " + property.Name);
                        LogWriter.Debug("Property type: " + property.PropertyType.ToString());

                        // If the property is a reference
                        // OR the actual provided entity is a reference AND the property holds an IEntity instance
                        if (EntitiesUtilities.IsReference(entity.GetType(), property.Name, property.PropertyType))
                        {
                            LogWriter.Debug("Cleared property. (Set to null)");
                            Reflector.SetPropertyValue(entity, property.Name, null);
                        }
                    }
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Checks whether the provided type is a element.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public bool IsElement(Type type)
        {
            bool isElement = false;

            using (LogGroup logGroup = LogGroup.Start("Checks whether the provided type is a element.", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Type: " + type.ToString());

                bool matchesInterface = false;
                bool isNotInterface   = false;
                bool isNotAbstract    = false;
                bool hasAttribute     = false;

                matchesInterface = (type.GetInterface("IElement") != null);

                isNotInterface = !type.IsInterface;

                isNotAbstract = !type.IsAbstract;

                hasAttribute = type.GetCustomAttributes(typeof(ElementAttribute), true).Length > 0;

                LogWriter.Debug("Matches interface: " + matchesInterface);
                LogWriter.Debug("Is not element interface: " + isNotInterface);
                LogWriter.Debug("Has attribute: " + isNotAbstract);

                isElement = matchesInterface &&
                            isNotInterface &&
                            isNotAbstract &&
                            hasAttribute;

                LogWriter.Debug("Is element: " + isElement.ToString());
            }

            return(isElement);
        }
Пример #23
0
        public IEntity GetParent(string parentTypeName, Guid parentID, string parentUniqueKey)
        {
            IEntity parent = null;

            using (LogGroup logGroup = LogGroup.Start("Retrieving the parent for entity being created.", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Parent ID: " + parentID.ToString());
                LogWriter.Debug("Parent unique key: " + parentUniqueKey);
                LogWriter.Debug("Parent type: " + parentTypeName);

                IRetrieveStrategy retrieveStrategy = RetrieveStrategy.New(parentTypeName, RequireAuthorisation);

                if (parentUniqueKey != String.Empty)
                {
                    parent = retrieveStrategy.Retrieve("UniqueKey", parentUniqueKey);
                }
                else if (parentID != Guid.Empty)
                {
                    parent = retrieveStrategy.Retrieve("ID", parentID);
                }
                else
                {
                    throw new Exception("No unique key or ID found for the parent.");
                }
            }
            return(parent);
        }
Пример #24
0
        /// <summary>
        /// Creates a new instance of the specified type of entity.
        /// </summary>
        /// <param name="shortTypeName">The short name of the type of entity to create an instance of.</param>
        public override IEntity Create()
        {
            // TODO: Check if needed. Should be unnecessary

            ISubEntity entity = null;

            using (LogGroup logGroup = LogGroup.Start("Creating a new entity of type '" + TypeName + "'.", NLog.LogLevel.Debug))
            {
                if (!EntityState.IsType(TypeName))
                {
                    throw new InvalidOperationException("The TypeName property needs to be set to the type of an entity. Invalid type: " + TypeName);
                }

                Type type = EntityState.GetType(TypeName);

                LogWriter.Debug("Authorisation required: " + RequireAuthorisation.ToString());

                if (RequireAuthorisation)
                {
                    AuthoriseCreateStrategy.New(TypeName).EnsureAuthorised(TypeName);
                }

                entity    = (ISubEntity)base.Create();
                entity.ID = Guid.NewGuid();
            }
            return(entity);
        }
Пример #25
0
            public LogEntry(DebugLogWindow window, ref LogEntryDescription desc)
                : base(0, 0, 120, DefaultHeight)
            {
                DockStyle    = DockStyle.Top;
                IsScrollable = true;

                _window = window;
                Desc    = desc;
                switch (desc.Level)
                {
                case LogType.Warning:
                    Group = LogGroup.Warning;
                    Icon  = _window._iconWarning;
                    break;

                case LogType.Log:
                    Group = LogGroup.Info;
                    Icon  = _window._iconInfo;
                    break;

                default:
                    Group = LogGroup.Error;
                    Icon  = _window._iconError;
                    break;
                }
            }
Пример #26
0
        public virtual int SetNumber(ISubEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Setting the number of the new sub entity.", NLog.LogLevel.Debug))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                if (entity.Parent == null)
                {
                    throw new Exception("No parent is assigned to this item.");
                }

                IEntity parent = entity.Parent;

                ActivateStrategy.New(parent).Activate(parent, entity.ItemsPropertyName);

                ISubEntity[] items = Collection <ISubEntity> .ConvertAll(EntitiesUtilities.GetPropertyValue(parent, entity.ItemsPropertyName));

                LogWriter.Debug("Existing items: " + items.Length.ToString());

                entity.Number = items.Length + 1;

                LogWriter.Debug("Entity number: " + entity.Number.ToString());
            }
            return(entity.Number);
        }
Пример #27
0
        /// <summary>
        /// Creates a filter for the active data source based on the specified type.
        /// </summary>
        public override IDataFilter CreateFilter(Type filterType)
        {
            using (LogGroup logGroup = LogGroup.Start("Creating filter", NLog.LogLevel.Debug))
            {
                LogWriter.Debug("Type: " + filterType.ToString());

                if (filterType.Equals(typeof(PropertyFilter)))
                {
                    LogWriter.Debug("Filter type supported.");

                    return(new Db4oPropertyFilter());
                }
                else if (filterType.Equals(typeof(ReferenceFilter)))
                {
                    LogWriter.Debug("Filter type supported.");

                    return(new Db4oReferenceFilter());
                }
                else
                {
                    LogWriter.Debug("Creation failed. " + filterType.ToString() + " isn't a supported filter.");
                    throw new NotSupportedException(filterType.ToString() + " isn't yet supported.");
                }
            }
        }
 /// <summary>
 /// Saves the info for the provided projections to projections info directory.
 /// </summary>
 /// <param name="projections">The projections to save to file.</param>
 public void SaveInfoToFile(ProjectionInfo[] projections)
 {
     using (LogGroup logGroup = LogGroup.StartDebug("Saving the provided projections to XML."))
     {
         Saver.SaveInfoToFile(projections);
     }
 }
Пример #29
0
        /// <summary>
        /// Counts the specified references.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="entityID"></param>
        /// <param name="propertyName"></param>
        /// <returns>The total number of references counted.</returns>
        public override int CountEntitiesWithReference(Type entityType, Guid entityID, string propertyName, Type referencedEntityType, string mirrorPropertyName)
        {
            int count = 0;

            using (LogGroup logGroup = LogGroup.StartDebug("Querying the data store based on the provided parameters."))
            {
                LogWriter.Debug("Entity type: " + entityType.FullName);
                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Entity ID: " + entityID);
                LogWriter.Debug("Mirror property name: " + mirrorPropertyName);
                LogWriter.Debug("Referenced entity type: " + referencedEntityType.FullName);

                Db4oDataStore store = (Db4oDataStore)GetDataStore(referencedEntityType);

                IObjectContainer container = store.ObjectContainer;

                Predicate matches = new MatchReferencePredicate(Provider, referencedEntityType, mirrorPropertyName, entityType, entityID, propertyName);

                IObjectSet os = store.ObjectContainer.Query(matches);

                count = os.Count;

                LogWriter.Debug("Total objects: " + count);
            }

            return(count);
        }
Пример #30
0
        /// <summary>
        /// Deletes the provided entity.
        /// </summary>
        /// <param name="entity"></param>
        public virtual void ExecuteDelete(IEntity entity)
        {
            using (LogGroup logGroup = LogGroup.Start("Deleting the provided entity.", NLog.LogLevel.Debug))
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }

                if (EnsureAuthorised(entity))
                {
                    if (entity == null)
                    {
                        LogWriter.Debug("Entity: [null]");
                    }
                    else
                    {
                        LogWriter.Debug("Entity: " + entity.GetType().FullName);
                    }

                    Deleter.Delete(entity);

                    LogWriter.Debug("Done");

                    // Display the result
                    Result.Display(DynamicLanguage.GetEntityText("EntityDeleted", entity.ShortTypeName));

                    NavigateAfterDelete(entity);
                }
            }
        }
        public ActionResult GetClientStageData(string startDate = null, string endDate = null)
        {
            DateTime? start = new DateTime(1900, 1, 1); ;
            if(startDate != null)
            {
                DateTime st;
                DateTime.TryParse(startDate, out st);
                if (st.Year > 1)
                    start = st;
            }

            DateTime? end = DateTime.Now;
            if (endDate != null)
            {
                DateTime st;
                DateTime.TryParse(endDate, out st);
                if (st.Year > 1)
                    end = st;
            }

            List<LogGroup> workLogGroups = new List<LogGroup>();
            List<ChildTicket> allChildren = new List<ChildTicket>();
            List<ParentTicket> allParents = new List<ParentTicket>();

            if ((bool)Session["SuccessfulLogin"] && FileWriter.ReadJsonFile() != null)
            {
                var builds = FileWriter.ReadJsonFile();

                foreach(var build in builds)
                {
                    allChildren.AddRange(build.StageColors.Select(x=> x.Value));
                    allParents.Add(build.ParentTicket);
                }
                var groupedChildren = allChildren.Select(x => new { x.Client, x.TicketStage, HoursLogged = x.GetHoursLogged(start, end) })
                                              .GroupBy(s => new { s.Client, s.TicketStage }) //Group by client + Stage to get sum by client/stage.
                                              .Select(g => new
                                              {
                                                  key = g.Key.Client,
                                                  stage = g.Key.TicketStage,
                                                  hours = g.Sum(x => Math.Round(Convert.ToDecimal(x.HoursLogged), 2))
                                              })
                                              .OrderBy(x => BuildProcessConfig.Stages.Where(s => s.Value == x.stage).Select(o => o.Key).FirstOrDefault())
                                              .GroupBy(g2 => new { g2.key }); //Roll up one last time to make it easier to conver to JSON (one series per client).

                var groupedParents = allParents.Select(x => new { x.Client, HoursLogged = x.GetHoursLogged(start, end) })
                                              .GroupBy(s => new { s.Client })
                                              .Select(g => new
                                              {
                                                  key = g.Key.Client,
                                                  hours = g.Sum(x => Math.Round(Convert.ToDecimal(x.HoursLogged), 2))
                                              });

                foreach (var group in groupedChildren)
                {
                    LogGroup logGroup = new LogGroup() { key = group.Key.key, values = new List<StageLog>() };
                    foreach(var stage in group)
                    {
                        logGroup.values.Add(new StageLog() { stage = stage.stage, hours = stage.hours });
                    }

                    var epicTicket = groupedParents.Where(x => x.key == group.Key.key).FirstOrDefault();
                    if (epicTicket != null)
                        logGroup.values.Add(new StageLog() { stage = "Master Ticket", hours = epicTicket.hours });

                    workLogGroups.Add(logGroup);
                }

                var workLogJson = Json(workLogGroups);
                return workLogJson;
            }

                return Json("");
        }
 public LogAudit(LogGroup logGroup,LogType logType)
 {
     this.LogGroup = logGroup;
     this.LogType = logType;
 }
 private void ShowLogFrm(LogGroup logGroup,LogType logType)
 {
     switch (logGroup)
     {
         case LogGroup.TradingLog:
             this.LogContentFrame.Content = new DealingLogControl(logType);
             break;
         case LogGroup.QuotationLog:
             this.LogContentFrame.Content = new SourceManagerLogControl(logType);
             break;
         default:
             this.LogContentFrame.Content = new DealingLogControl(LogType.QuotePrice);
             break;
     }
 }
 private void SetBindingByGroup(LogGroup logGroup)
 {
     //this._LogRibbon.Theme = "IGTheme";
     this.LogTypeComboBox.ItemsSource = this._LogAuditList.Where(P => P.LogGroup == logGroup);
     this.LogTypeComboBox.DisplayMemberPath = "LogName";
     this.LogTypeComboBox.SelectedIndex = 0;
 }