Beispiel #1
0
        public static void Convert(string legacyFile, string upgradeFile)
        {
            legacySplxApi.SuplexApiClient legacyApi   = new legacySplxApi.SuplexApiClient();
            legacySplxApi.SuplexStore     legacyStore = legacyApi.LoadFile(legacyFile);

            FileSystemDal fsd = new FileSystemDal
            {
                CurrentPath = upgradeFile
            };

            foreach (legacySplxApi.User legacyUser in legacyStore.Users)
            {
                fsd.Store.Users.Add(legacyUser.ToNewUser());
            }
            foreach (legacySplxApi.Group legacyGroup in legacyStore.Groups)
            {
                fsd.Store.Groups.Add(legacyGroup.ToNewGroup());
            }
            foreach (legacySplxApi.GroupMembershipItem legacyGmi in legacyStore.GroupMembership.InnerList.Values)
            {
                fsd.Store.GroupMembership.Add(legacyGmi.ToNewGroupMembership());
            }

            RecurseSecureObjectsForImport(legacyStore.UIElements, fsd.Store.SecureObjects);

            fsd.ToYamlFile();
        }
Beispiel #2
0
        /// <summary>
        /// Loads the specified file into a Suplex FileSystemDal and refreshes the dialog
        /// </summary>
        /// <param name="filestorePath"></param>
        void RefreshSuplex(string filestorePath)
        {
            _suplexDal   = FileSystemDal.LoadFromYamlFile(filestorePath);
            _employeeDal = new EmployeeDataAccessLayer(_suplexDal);

            this.UiThreadHelper(() => lstMessages.Items.Clear());
            this.UiThreadHelper(() => cmbUsers.DataSource = new BindingSource(_suplexDal.Store.Users.OrderBy(u => u.Name).ToList(), null).DataSource);
        }
Beispiel #3
0
        private void tbbRemoteExport_Click(object sender, RoutedEventArgs e)
        {
            FileSystemDal export = new FileSystemDal()
            {
                Store = _dal.Store
            };

            export.Store.GroupMembership =
                new System.Collections.Generic.List <Security.Principal.GroupMembershipItem>(_dal.GetGroupMembership());

            SaveFileAs(export);
        }
Beispiel #4
0
        void SaveFileAs(FileSystemDal fileSystemDal)
        {
            SaveFileDialog dlg = new SaveFileDialog
            {
                Filter = "Suplex File|*.splx|Suplex YAML File|*.yaml"
            };

            if (dlg.ShowDialog(this).Value)
            {
                fileSystemDal.ToYamlFile(dlg.FileName);     //make sure that sets the file context
            }
        }
Beispiel #5
0
        private void tbbRemoteImport_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog
            {
                Filter = _fileFilter
            };

            if (dlg.ShowDialog(this).Value)
            {
                FileSystemDal file = FileSystemDal.LoadFromYamlFile(dlg.FileName);
                _dal.ImportSuplexObjects(file);
                _dal.RefreshStore();
            }
        }
Beispiel #6
0
    public void StartQueueWatcher(FileSystemDal suplexDalInstance)
    {
        if (_dal == null)
        {
            _dal = suplexDalInstance;

            Thread thread = new Thread(() => Instance.DrainQueue())
            {
                IsBackground = true,
                Name         = "SuplexItemThread"
            };
            thread.Start();
        }
    }
Beispiel #7
0
    void DrainQueue()
    {
        while (true)
        {
            if (Instance.Queue.Count == 0)
            {
                Thread.Sleep(500);   //no pending actions available, pause
                //if( _allowExit )
                //    ReadyToExit = true;
                continue;
            }
            _allowExit = true;

            SuplexUpdateItem item = null;
            while (Instance.Queue.TryDequeue(out item))
            {
                FileSystemDal fsd = _dal;
                if (File.Exists(_dal.CurrentPath))
                {
                    fsd = FileSystemDal.LoadFromYamlFile(_dal.CurrentPath);
                }

                if (item.IsSecureObject)
                {
                    fsd.UpsertSecureObject(item.Item as ISecureObject);
                }
                else if (item.IsUser)
                {
                    fsd.UpsertUser(item.Item as User);
                }
                else if (item.IsGroup)
                {
                    fsd.UpsertGroup(item.Item as Group);
                }
                else if (item.IsGroupMembership)
                {
                    fsd.UpsertGroupMembership(item.Item as GroupMembershipItem);
                }
                else
                {
                    throw new Exception($"Unknown type {item.GetType()}");
                }

                fsd.ToYamlFile();
            }
        }
    }
Beispiel #8
0
    public void Initialize()
    {
        switch (Type)
        {
        case SuplexDalConnectionType.File:
        {
            _dal = FileSystemDal.LoadFromYamlFile(Path);
            PathLastWriteTime = File.GetLastWriteTimeUtc(Path);
            break;
        }

        case SuplexDalConnectionType.RestApi:
        {
            _dal = new SuplexSecurityHttpApiClient(Path);
            break;
        }
        }
    }
        public void TestMethod1()
        {
            #region foo
            string foo = @"---
SecureObjects:
- UId: e724bfde-c3d5-424f-a0c6-9497958167f0
  UniqueName: top
  Security:
    DaclAllowInherit: true
    SaclAllowInherit: true
    SaclAuditTypeFilter: SuccessAudit, FailureAudit, Information, Warning, Error
    Dacl:
    - UId: a86dac02-cad3-4a51-9b16-1a3b20dbab37
      RightType: Suplex.Security.AclModel.FileSystemRight, Suplex.Security.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
      Right: FullControl
      Allowed: True
      Inheritable: True
    - UId: 7fb267d9-b4ce-4d56-a052-02aa9e9855d5
      RightType: Suplex.Security.AclModel.FileSystemRight, Suplex.Security.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
      Right: List, Execute
      Allowed: False
      Inheritable: False
    - UId: e7ea73a3-a5ec-4f63-8461-66feec42bb12
      RightType: Suplex.Security.AclModel.UIRight, Suplex.Security.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
      Right: Visible, Operate
      Allowed: True
      Inheritable: True
    Sacl: []
    Results: {}
  Children: []
Users:
- UId: 0bdfe71c-5663-4f7f-be8b-3884373f97be
  Name: x
  IsLocal: true
  IsBuiltIn: true
  IsEnabled: true
- UId: 1bda1876-3281-4a67-b5de-198e9e72ad53
  Name: y
  IsEnabled: true
- UId: 20d134e9-a5ac-46ef-bc7e-fa6dc210e1f9
  Name: z
  IsLocal: true
  IsBuiltIn: true
Groups:
- UId: ff8abe51-116b-4d42-b01a-48f167f71dc7
  Name: gx
  IsEnabled: true
- UId: c05c6deb-6a01-459b-9c87-916003f44429
  Name: gy
  IsEnabled: true
- UId: 66f89524-cc5d-4938-9cd3-b2ce6ec6d75b
  Name: gz
  IsEnabled: true
GroupMembership:
- GroupUId: ff8abe51-116b-4d42-b01a-48f167f71dc7
  MemberUId: 0bdfe71c-5663-4f7f-be8b-3884373f97be
  IsMemberUser: true
- GroupUId: ff8abe51-116b-4d42-b01a-48f167f71dc7
  MemberUId: 1bda1876-3281-4a67-b5de-198e9e72ad53
  IsMemberUser: true
- GroupUId: ff8abe51-116b-4d42-b01a-48f167f71dc7
  MemberUId: c05c6deb-6a01-459b-9c87-916003f44429";
            #endregion

            SecureObject top = new SecureObject()
            {
                UniqueName = "top"
            };
            DiscretionaryAcl topdacl = new DiscretionaryAcl
            {
                new AccessControlEntry <FileSystemRight> {
                    Allowed = true, Right = FileSystemRight.FullControl
                },
                new AccessControlEntry <FileSystemRight> {
                    Allowed = false, Right = FileSystemRight.Execute | FileSystemRight.List, Inheritable = false
                },
                new AccessControlEntry <UIRight> {
                    Right = UIRight.Operate | UIRight.Visible
                }
            };
            top.Security.Dacl             = topdacl;
            top.Security.DaclAllowInherit = false;

            SystemAcl topsacl = new SystemAcl
            {
                new AccessControlEntryAudit <FileSystemRight> {
                    Allowed = true, Denied = true, Right = FileSystemRight.Execute
                }
            };
            top.Security.Sacl                = topsacl;
            top.Security.SaclAllowInherit    = false;
            top.Security.SaclAuditTypeFilter = AuditType.FailureAudit | AuditType.Error;

            List <User> users = new List <User>
            {
                new User {
                    Name = "x", IsBuiltIn = true, IsEnabled = true, IsLocal = true
                },
                new User {
                    Name = "y", IsBuiltIn = false, IsEnabled = true, IsLocal = false
                },
                new User {
                    Name = "z", IsBuiltIn = true, IsEnabled = false, IsLocal = true
                }
            };

            List <Group> groups = new List <Group>
            {
                new Group {
                    Name = "gx", IsEnabled = true, IsLocal = false
                },
                new Group {
                    Name = "gy", IsEnabled = true, IsLocal = false
                },
                new Group {
                    Name = "gz", IsEnabled = true, IsLocal = false
                }
            };

            GroupMembershipItem mx = new GroupMembershipItem
            {
                GroupUId     = groups[0].UId,
                MemberUId    = users[0].UId,
                IsMemberUser = true
            };
            GroupMembershipItem my = new GroupMembershipItem
            {
                GroupUId     = groups[0].UId,
                MemberUId    = users[1].UId,
                IsMemberUser = true
            };
            GroupMembershipItem mz = new GroupMembershipItem
            {
                GroupUId     = groups[0].UId,
                MemberUId    = groups[1].UId,
                IsMemberUser = false
            };
            List <GroupMembershipItem> gm = new List <GroupMembershipItem>
            {
                mx, my, mz
            };



            FileSystemDal dal = new FileSystemDal()
            {
            };
            dal.Store.SecureObjects = new List <SecureObject>()
            {
                top
            };
            dal.Store.Users           = users;
            dal.Store.Groups          = groups;
            dal.Store.GroupMembership = gm;

            User ux = dal.Store.Users.GetByName <User>("x");


            string        x = dal.ToYaml();
            FileSystemDal f = new FileSystemDal();
            f.FromYaml(x);
            f.CurrentPath = "meow.yaml";
            f.AutomaticallyPersistChanges = true;

            bool contains = f.Store.GroupMembership.ContainsItem(mx);

            //bool ok = f.GroupMembership.Resolve( f.Groups, f.Users );

            //FileSystemDal f2 = FileSystemDal.LoadFromYaml( foo );

            User u0 = new User {
                Name = "gurl"
            };
            User u1 = new User {
                Name = "f", UId = u0.UId
            };

            f.Dal.UpsertUser(u0);
            f.Dal.UpsertUser(u1);


            bool parallel = false;
            if (parallel)
            {
                Parallel.For(0, 49, i =>
                {
                    f.UpsertGroup(new Group {
                        Name = $"{i}_{DateTime.Now.Ticks}"
                    });
                });
            }
            else
            {
                for (int i = 0; i < 50; i++)
                {
                    f.UpsertGroup(new Group {
                        Name = $"{i}_{DateTime.Now.Ticks}"
                    });
                }
            }



            //if( f.IsWorking )
            //{
            //    System.Timers.Timer SuplexPoller = new System.Timers.Timer( 1000 )
            //    {
            //        Enabled = true
            //    };
            //    SuplexPoller.Elapsed += (s, e) =>
            //    {
            //        while( f.IsWorking )
            //            System.Threading.Thread.Sleep( 500 );
            //        SuplexPoller.Enabled = false;
            //    };
            //}

            //while( f.IsWorking )
            //    f.WaitForExit();

            Assert.IsTrue(true);
        }
    static void Main(string[] args)
    {
        Stopwatch timer = Stopwatch.StartNew();

        FileSystemDal dal = new FileSystemDal(null, processPlansOnSingleton: false, processActionsOnSingleton: true);

        while (true)
        {
            try
            {
                Plan uie000 = dal.GetPlan("uie000");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Thread.Sleep(1000);
        }


        long ticks = DateTime.Now.Ticks;
        List <Tuple <Plan, ActionItem> > msgs = new List <Tuple <Plan, ActionItem> >();

        for (int i = 0; i < 100; i++)
        {
            ActionItem a1 = new ActionItem()
            {
                Name = "01", InstanceId = 1, ParentInstanceId = 0, Result = new ExecuteResult()
                {
                    Status = StatusType.New
                }
            };
            ActionItem a2 = new ActionItem()
            {
                Name = "02", InstanceId = 2, ParentInstanceId = 1, Result = new ExecuteResult()
                {
                    Status = StatusType.New
                }
            };
            ActionItem a3 = new ActionItem()
            {
                Name = "03", InstanceId = 3, ParentInstanceId = 2, Result = new ExecuteResult()
                {
                    Status = StatusType.New
                }
            };
            ActionItem a4 = new ActionItem()
            {
                Name = "04", InstanceId = 4, ParentInstanceId = 2, Result = new ExecuteResult()
                {
                    Status = StatusType.New
                }
            };
            ActionItem a5 = new ActionItem()
            {
                Name = "05", InstanceId = 5, ParentInstanceId = 4, Result = new ExecuteResult()
                {
                    Status = StatusType.New
                }
            };
            //a1.Actions.Add( a2 );
            //a2.Actions.Add( a3 );
            //a2.Actions.Add( a4 );
            //a4.Actions.Add( a5 );

            Plan plan = new Plan()
            {
                Name       = $"Plan_{ticks}",
                UniqueName = $"Plan_{ticks}",
                InstanceId = ticks++
            };
            //plan.Actions.Add( a1 );

            Tuple <Plan, ActionItem> t01 = new Tuple <Plan, ActionItem>(plan, a1);
            Tuple <Plan, ActionItem> t02 = new Tuple <Plan, ActionItem>(plan, a2);
            Tuple <Plan, ActionItem> t03 = new Tuple <Plan, ActionItem>(plan, a3);
            Tuple <Plan, ActionItem> t04 = new Tuple <Plan, ActionItem>(plan, a4);
            Tuple <Plan, ActionItem> t05 = new Tuple <Plan, ActionItem>(plan, a5);
            Tuple <Plan, ActionItem> t06 = new Tuple <Plan, ActionItem>(plan, new ActionItem()
            {
                Name = "01", InstanceId = 1, ParentInstanceId = 0, Result = new ExecuteResult()
                {
                    Status = StatusType.Complete
                }
            });
            Tuple <Plan, ActionItem> t07 = new Tuple <Plan, ActionItem>(plan, new ActionItem()
            {
                Name = "02", InstanceId = 2, ParentInstanceId = 1, Result = new ExecuteResult()
                {
                    Status = StatusType.Complete
                }
            });
            Tuple <Plan, ActionItem> t08 = new Tuple <Plan, ActionItem>(plan, new ActionItem()
            {
                Name = "03", InstanceId = 3, ParentInstanceId = 2, Result = new ExecuteResult()
                {
                    Status = StatusType.Complete
                }
            });
            Tuple <Plan, ActionItem> t09 = new Tuple <Plan, ActionItem>(plan, new ActionItem()
            {
                Name = "04", InstanceId = 4, ParentInstanceId = 2, Result = new ExecuteResult()
                {
                    Status = StatusType.Complete
                }
            });
            Tuple <Plan, ActionItem> t10 = new Tuple <Plan, ActionItem>(plan, new ActionItem()
            {
                Name = "05", InstanceId = 5, ParentInstanceId = 4, Result = new ExecuteResult()
                {
                    Status = StatusType.Complete
                }
            });

            msgs.Add(t10);
            msgs.Add(t09);
            msgs.Add(t08);
            msgs.Add(t07);
            msgs.Add(t06);
            msgs.Add(t05);
            msgs.Add(t04);
            msgs.Add(t03);
            msgs.Add(t02);
            msgs.Add(t01);
        }

        Parallel.ForEach(msgs, m => {
            dal.UpdatePlanStatus(m.Item1);
        });

        ActionItemSingletonProcessor.Instance.StartQueueWatcher(dal);
        PlanItemSingletonProcessor.Instance.StartQueueWatcher(dal);

        //foreach( Tuple<Plan, ActionItem> m in msgs )
        //    dal.UpdatePlanActionStatus( m.Item1.UniqueName, m.Item1.InstanceId, m.Item2 );

        //Parallel.ForEach( msgs, m => {
        //    dal.UpdatePlanActionStatus( m.Item1.UniqueName, m.Item1.InstanceId, m.Item2 );
        //} );

        //for( int i = msgs.Count - 1; i >= 0; i-- )
        for (int i = 0; i < msgs.Count; i++)
        {
            dal.UpdatePlanActionStatus(msgs[i].Item1.UniqueName, msgs[i].Item1.InstanceId, msgs[i].Item2);
        }


        while (!ActionItemSingletonProcessor.Instance.ReadyToExit)
        {
            Thread.Sleep(500);
        }

        timer.Stop();

        int pe = PlanItemSingletonProcessor.Instance.Queue.Count;

        if (ActionItemSingletonProcessor.Instance.Fatal.Count > 0)
        {
            Console.WriteLine($"Fatal errors: {ActionItemSingletonProcessor.Instance.Fatal.Count}");
        }

        Plan p = dal.GetPlanStatus(msgs[0].Item1.UniqueName, msgs[0].Item1.InstanceId);

        p.Actions[0].Result.Status       = StatusType.Failed;
        p.Actions[0].Result.BranchStatus = StatusType.Cancelled;
        dal.UpdatePlanStatus(p);
        StatusType ps = p.Actions[0].Result.Status;

        p = dal.GetPlanStatus(msgs[0].Item1.UniqueName, msgs[0].Item1.InstanceId);

        Console.WriteLine($"{msgs[0].Item1.UniqueName}: {ps}/{p.Actions[0].Result.Status}");
        Console.WriteLine($"Elapsed seconds: {timer.ElapsedMilliseconds / 1000}");

        Environment.Exit(0);
    }