public void When(ProjectionVersionRequestTimedout e)
 {
     Id = e.Id;
     Versions.Add(e.Version);
     LastVersionRequestTimebox = LastVersionRequestTimebox.Reset();
 }
 public void When(NewProjectionVersionIsNowLive e)
 {
     Id = e.Id;
     Versions.Add(e.ProjectionVersion);
     LastVersionRequestTimebox = LastVersionRequestTimebox.Reset();
 }
 public void When(ProjectionVersionRequested e)
 {
     Id = e.Id;
     Versions.Add(e.ProjectionVersion);
     LastVersionRequestTimebox = e.Timebox;
 }
 public void When(ProjectionVersionRequestCanceled e)
 {
     Id = e.Id;
     Versions.Add(e.ProjectionVersion);
 }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemType"></param>
        /// <param name="value"></param>
        private void AddItem(ItemType itemType, object value)
        {
            if (value.ToString().Length == 0)
            {
                return;
            }

            switch (itemType)
            {
            case ItemType.IpAddress:
                var ipAddresses = from ipAddress in IpAddresses where ipAddress.Text.ToUpper() == ((string)value).ToUpper() select ipAddress;
                if (ipAddresses.Count() == 0)
                {
                    IpAddress ipAddress = new IpAddress();
                    ipAddress.Text = (string)value;
                    IpAddresses.Add(ipAddress);
                }
                break;

            case ItemType.HostName:
                var hosts = from host in HostNames where host.ToUpper() == ((string)value).ToUpper() select host;
                if (hosts.Count() == 0)
                {
                    HostNames.Add((string)value);
                }
                break;

            case ItemType.Port:
                var ports = from port in Ports where port == (int)value select port;
                if (ports.Count() == 0)
                {
                    Ports.Add((int)value);
                }
                break;

            case ItemType.Protocol:
                var protocols = from protocol in Protocols where protocol.ToUpper() == ((string)value).ToUpper() select protocol;
                if (protocols.Count() == 0)
                {
                    Protocols.Add(((string)value).ToUpper());
                }
                break;

            case ItemType.Service:
                var services = from service in Services where service.ToUpper() == ((string)value).ToUpper() select service;
                if (services.Count() == 0)
                {
                    Services.Add((string)value);
                }
                break;

            case ItemType.State:
                var states = from state in States where state.ToUpper() == ((string)value).ToUpper() select state;
                if (states.Count() == 0)
                {
                    States.Add((string)value);
                }
                break;

            case ItemType.Severities:
                var severities = from severity in Severities where severity.ToUpper() == ((string)value).ToUpper() select severity;
                if (severities.Count() == 0)
                {
                    Severities.Add((string)value);
                }
                break;

            case ItemType.PluginFamily:
                var pluginFamilies = from pluginFamily in PluginFamilys where pluginFamily.ToUpper() == ((string)value).ToUpper() select pluginFamily;
                if (pluginFamilies.Count() == 0)
                {
                    PluginFamilys.Add((string)value);
                }
                break;

            case ItemType.PluginId:
                var pluginIds = from pluginId in PluginIds where pluginId.ToString().ToUpper() == ((string)value).ToUpper() select pluginId;
                if (pluginIds.Count() == 0)
                {
                    PluginIds.Add(int.Parse(value.ToString()));
                }
                break;

            case ItemType.PluginName:
                var pluginNames = from pluginName in PluginNames where pluginName.ToUpper() == ((string)value).ToUpper() select pluginName;
                if (pluginNames.Count() == 0)
                {
                    PluginNames.Add((string)value);
                }
                break;

            case ItemType.Product:
                var products = from product in Products where product.ToUpper() == ((string)value).ToUpper() select product;
                if (products.Count() == 0)
                {
                    Products.Add((string)value);
                }
                break;

            case ItemType.Versions:
                var versions = from version in Versions where version.ToUpper() == ((string)value).ToUpper() select version;
                if (versions.Count() == 0)
                {
                    Versions.Add((string)value);
                }
                break;

            case ItemType.ExploitAvailable:
                var exploitAvailable = from e in ExploitAvailable where e.ToUpper() == ((string)value).ToUpper() select e;
                if (exploitAvailable.Count() == 0)
                {
                    ExploitAvailable.Add((string)value);
                }
                break;

            default:
                break;
            }
        }
예제 #6
0
        // update constants in User database to current version defined in EntityConstants
        public bool VersionConstants(string me)
        {
            try
            {
                bool updateDB = false;
                if (Versions.Any(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == UserConstants.ConstantsVersion) == false)
                {   // no database - create and lock the new version entry
                    TraceLog.TraceInfo(String.Format("User database version {0} not found", UserConstants.ConstantsVersion));

                    // remove an existing database version (there should never be more than one)
                    foreach (var existingVersion in Versions.Where(v => v.VersionType == DatabaseVersion.Constants).ToList())
                    {
                        Versions.Remove(existingVersion);
                    }
                    SaveChanges();

                    // create the new version entry
                    DatabaseVersion ver = new DatabaseVersion()
                    {
                        VersionType   = DatabaseVersion.Constants,
                        VersionString = UserConstants.ConstantsVersion,
                        Status        = me
                    };
                    Versions.Add(ver);
                    SaveChanges();
                    updateDB = true;
                }
                else
                {
                    var dbVersion = Versions.Single(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == UserConstants.ConstantsVersion);
                    if (dbVersion.Status == DatabaseVersion.Corrupted)
                    {   // try to update the database again - take a lock
                        TraceLog.TraceInfo("User database corrupted");
                        dbVersion.Status = me;
                        SaveChanges();
                        updateDB = true;
                    }
                }
                if (updateDB == false)
                {
                    TraceLog.TraceInfo(String.Format("User database version {0} is up to date", UserConstants.ConstantsVersion));
                    return(true);
                }
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("Could not find database version", ex);
                return(false);
            }

            // update the default database values
            DatabaseVersion    version        = null;
            UserStorageContext versionContext = Storage.NewUserContext;

            try
            {   // verify that this unit of execution owns the update lock for the database version
                version = versionContext.Versions.Single(v => v.VersionType == DatabaseVersion.Constants && v.VersionString == UserConstants.ConstantsVersion);
                if (version.Status != me)
                {
                    return(true);
                }

                TraceLog.TraceInfo(String.Format("{0} updating User datatbase to version {1}", me, UserConstants.ConstantsVersion));

                // update existing action types, add new action types
                foreach (var entity in UserConstants.DefaultActionTypes())
                {
                    if (ActionTypes.Any(e => e.ActionTypeID == entity.ActionTypeID))
                    {
                        ActionTypes.Single(e => e.ActionTypeID == entity.ActionTypeID).Copy(entity);
                    }
                    else
                    {
                        ActionTypes.Add(entity);
                    }
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced action types");

                // update existing colors, add new colors
                foreach (var entity in UserConstants.DefaultColors())
                {
                    if (Colors.Any(e => e.ColorID == entity.ColorID))
                    {
                        Colors.Single(e => e.ColorID == entity.ColorID).Copy(entity);
                    }
                    else
                    {
                        Colors.Add(entity);
                    }
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced colors");

                // update existing permissions, add new permissions
                foreach (var entity in UserConstants.DefaultPermissions())
                {
                    if (Permissions.Any(e => e.PermissionID == entity.PermissionID))
                    {
                        Permissions.Single(e => e.PermissionID == entity.PermissionID).Copy(entity);
                    }
                    else
                    {
                        Permissions.Add(entity);
                    }
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced permissions");

                // update existing priorities, add new priorities
                foreach (var entity in UserConstants.DefaultPriorities())
                {
                    if (Priorities.Any(e => e.PriorityID == entity.PriorityID))
                    {
                        Priorities.Single(e => e.PriorityID == entity.PriorityID).Copy(entity);
                    }
                    else
                    {
                        Priorities.Add(entity);
                    }
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced priorities");

                // update existing or add new built-in users
                foreach (var user in UserConstants.DefaultUsers())
                {
                    if (Users.Any(u => u.ID == user.ID))
                    {
                        var existing = Users.Single(u => u.ID == user.ID);
                        existing.Name       = user.Name;
                        existing.Email      = user.Email;
                        existing.CreateDate = user.CreateDate;
                    }
                    else
                    {
                        Users.Add(user);
                    }
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced users");

                // update existing or add new built-in itemtypes and fields
                foreach (var itemType in UserConstants.DefaultItemTypes())
                {
                    if (ItemTypes.Any(it => it.ID == itemType.ID))
                    {
                        var existing = ItemTypes.Include("Fields").Single(it => it.ID == itemType.ID);
                        existing.Copy(itemType);
                        if (itemType.Fields == null)
                        {
                            continue;
                        }
                        foreach (var field in itemType.Fields)
                        {
                            if (existing.Fields.Any(f => f.ID == field.ID))
                            {
                                var existingField = existing.Fields.Single(f => f.ID == field.ID);
                                existingField.Copy(field);
                            }
                            else
                            {
                                existing.Fields.Add(field);
                            }
                        }
                    }
                    else
                    {
                        ItemTypes.Add(itemType);
                    }
                }
                SaveChanges();
                TraceLog.TraceInfo("Replaced item types and fields");

                // save the new version number
                version.Status = DatabaseVersion.OK;
                versionContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                TraceLog.TraceException("VersionConstants failed", ex);

                // mark the version as corrupted
                version.Status = DatabaseVersion.Corrupted;
                versionContext.SaveChanges();
                return(false);
            }
        }