Example #1
0
        /// <summary>
        ///   Deletes a policy
        /// </summary>
        /// <param name = "ou">IOu</param>
        public void DeletePolicy(IOu ou)
        {
            try
            {
                if (_policies == null)
                {
                    BuildPolicyListing();
                }

                var sql = string.Format("delete from policy where p_ou_id='{0}'", ou.GetOuId());

                if (Framework.Database.IsConnected() == false)
                {
                    return;
                }

                Framework.Database.ExecuteNonQuery(sql);

                for (var h = 0; h < _policies.Count; h++)
                {
                    if (_policies[h].GetOuId() == ou.GetOuId())
                    {
                        _policies.RemoveAt(h);
                        return;
                    }
                }
            }
            catch (Exception error)
            {
                Framework.EventBus.Publish(error);
            }
        }
Example #2
0
        /// <summary>
        ///   Gets an ancestor policy
        /// </summary>
        /// <param name = "ou">IOu</param>
        /// <returns>IPolicy</returns>
        public IPolicy GetAncestorPolicy(IOu ou)
        {
            try
            {
                if (_policies == null)
                {
                    BuildPolicyListing();
                }

                var parentou = ou.GetParentOuId();

                for (var h = 0; h < _policies.Count; h++)
                {
                    if (_policies[h].GetOuId() == parentou)
                    {
                        return(_policies[h]);
                    }
                }
            }
            catch (Exception error)
            {
                Framework.EventBus.Publish(error);
            }

            return(null);
        }
Example #3
0
        /// <summary>
        ///   Gets an predecessor policy
        /// </summary>
        /// <param name = "ou">IOu</param>
        /// <returns>IPolicy</returns>
        public IPolicy GetPredecessorPolicy(IOu ou)
        {
            try
            {
                if (_policies == null)
                {
                    BuildPolicyListing();
                }

                var children = OuGateway.GetChildren(ou.GetOuId());

                if (children == null)
                {
                    return(null);
                }

                foreach (var iou in children)
                {
                    for (var h = 0; h < _policies.Count; h++)
                    {
                        if (_policies[h].GetOuId() == iou.GetOuId())
                        {
                            return(_policies[h]);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Framework.EventBus.Publish(error);
            }

            return(null);
        }
Example #4
0
        /// <summary>
        ///   Create a policy for a given ou
        /// </summary>
        /// <param name = "ou">the associated ou</param>
        /// <param name="defaultPolicy">default policy</param>
        /// <returns>IPolicy</returns>
        public IPolicy CreatePolicy(IOu ou, string defaultPolicy)
        {
            try
            {
                if (_policies == null)
                {
                    BuildPolicyListing();
                }

                var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                var sql = string.Format("insert into policy values( null, '{1}' , '{1}' ,'1' ,'{2}' ,'{0}' ,''  )", ou.GetOuId(), now, Framework.Utils.Base64Encode(defaultPolicy));

                if (Framework.Database.IsConnected() == false)
                {
                    return(null);
                }

                if (Framework.Database.ExecuteNonQuery(sql) > 0)
                {
                    var sql2 = string.Format("select * from policy where p_id = ( select MAX(p_id) from policy )");

                    var policies = Framework.Database.ExecuteQuery(sql2);

                    var policiesTable = policies.Tables[0];

                    if (policiesTable.Rows.Count == 0)
                    {
                        return(null);
                    }

                    var row = policiesTable.Rows[0];

                    var          pid     = ( int )row["p_id"];
                    var          created = ( string )row["p_created"];
                    var          edited  = ( string )row["p_edited"];
                    const int    enabled = 1;
                    var          dsl     = defaultPolicy;
                    var          ouid    = ou.GetOuId();
                    const string version = "";
                    var          policy  = new Policy(pid, created, edited, enabled, dsl, ouid, version);
                    _policies.Add(policy);

                    return(_policies[_policies.Count - 1]);
                }

                return(null);
            }
            catch (Exception error)
            {
                Framework.EventBus.Publish(error);
                return(null);
            }
        }
Example #5
0
 /// <summary>
 ///   Update this observer with a refernece to the ou
 /// </summary>
 /// <param name = "ou">Iou</param>
 /// <param name = "source">source observer</param>
 public void Update(IOu ou, IOuObserver source)
 {
     throw new NotImplementedException();
 }