Пример #1
0
        private void runAfterAction(MvcContext ctx)
        {
            List <String> pages = new List <String>();

            List <ActionObserver> actionObservers = ControllerMeta.GetActionObservers(ctx.controller.GetType(), ctx.route.action);

            if (actionObservers == null)
            {
                return;
            }

            List <IPageCache> observedPages = new List <IPageCache>();

            foreach (ActionObserver x in actionObservers)
            {
                logger.Info("run after ActionObserver=>" + x.GetType());
                ActionObserver ob = (ActionObserver)ObjectContext.CreateObject(x.GetType());
                ob.AfterAction(ctx);

                if (ob.GetType().IsSubclassOf(typeof(ActionCache)))
                {
                    loadObservedPage((ActionCache)ob, observedPages);
                }
            }

            foreach (IPageCache pc in observedPages)
            {
                logger.Info("update IPageCache=" + pc.GetType().FullName);
                pc.UpdateCache(ctx);
            }
        }
Пример #2
0
            public void GivenANullEntityThrowArgumentNullException()
            {
                Action <string> callback = str => { };
                var             target   = new ActionObserver <string>(callback);

                Action act = () => target.OnNext(null);
            }
Пример #3
0
            public void GivenAnEntityIsSuppliedThenCallbackIsInvoked()
            {
                var             callbackInvoked = false;
                Action <string> callback        = str => { callbackInvoked = true; };
                var             target          = new ActionObserver <string>(callback);

                target.OnNext("");

                callbackInvoked.Should().BeTrue();
            }
Пример #4
0
            public void GivenOnCompleteHasBeenCalledThenCallbackIsNotInvoked()
            {
                var             callbackInvoked = false;
                Action <string> callback        = str => { callbackInvoked = true; };
                var             target          = new ActionObserver <string>(callback);

                target.OnCompleted();
                target.OnNext("");

                callbackInvoked.Should().BeFalse();
            }
Пример #5
0
        public static IDisposable Subscribe <T> (this IObservable <T> observable, Action <T> onNext, Action onCompleted = null, Action <Exception> onError = null)
        {
            if (observable == null)
            {
                throw new ArgumentNullException("observable");
            }

            var observer = new ActionObserver <T> (onNext, onCompleted, onError);

            return(observable.Subscribe(observer));
        }
Пример #6
0
 public void CopyShareSecurity(NTShare sourceShare, NTShare destShare)
 {
     ActionObserver.NotifyAction("Copying", "Share Security", sourceShare.FullName, destShare.FullName);
     try {
         ShareSecurity sourceSecurity = sourceShare.GetAccessControl();
         NTShare.SetAccessControl(
             destShare.FullName,
             TranslateShareACL(
                 sourceShare.GetAccessControl()
                 )
             );
     } catch (Exception error) {
         ActionObserver.NotifyActionFailed("Copying", "Share Security", sourceShare.FullName, destShare.FullName, error.Message);
     }
 }
Пример #7
0
        public void CopyRemoteGroupMembership(NTLocalGroup sourceRemoteGroup, NTLocalGroup destinationLocalGroup, NTObject[] destinationLocalGroupMembers)
        {
            ActionObserver.NotifyAction("Copy", "Remote Group Membership", sourceRemoteGroup.FullName, destinationLocalGroup.FullName);
            TextBank existingMembers = new TextBank(
                from obj in destinationLocalGroupMembers
                where obj is NTObject
                select(object) obj
                );


            #region debug region
            NTRemoteObject[] tmpObjects = sourceRemoteGroup.GetRemoteMembers();
            if (tmpObjects == null)
            {
                tmpObjects = new NTRemoteObject[0];
            }
            ActionObserver.NotifyInformation("Detected a total of {0} members for remote local group {1}", tmpObjects.Length, sourceRemoteGroup.FullName);
            foreach (NTRemoteObject remoteObject in tmpObjects)
            {
                ActionObserver.NotifyInformation("Member '{0}' its type is {1}", remoteObject.FullName, remoteObject.GetType().FullName);
            }

            #endregion


            NTRemoteObject[] remoteObjects = sourceRemoteGroup.GetRemoteMembers();
            if (remoteObjects == null)
            {
                remoteObjects = new NTRemoteObject[0];
            }
            ActionObserver.NotifyInformation("Detected a total of {0} AD members for remote local group {1}", remoteObjects.Length, sourceRemoteGroup.FullName);
            foreach (NTRemoteObject remoteObject in remoteObjects)
            {
                ActionObserver.NotifyInformation("AD Member '{0}' its is {1}", remoteObject.FullName, remoteObject.GetType().FullName);
            }



            foreach (NTRemoteObject remoteObject in remoteObjects)
            {
                string remoteObjectName = remoteObject.Domain + "\\" + remoteObject.Name;
                if (!existingMembers.ContainsText(remoteObjectName))
                {
                    destinationLocalGroup.AddMember(remoteObjectName);
                }
            }
        }
Пример #8
0
        public NTLocalGroup CopyRemoteGroupToLocalMachine(NTLocalGroup remoteGroup)
        {
            ActionObserver.NotifyAction("Querying", "Group", remoteGroup.Name, string.Empty);
            NTLocalGroup localGroup = null;

            if (!NTHost.CurrentMachine.TryGetLocalGroup(remoteGroup.Name, out localGroup))
            {
                ActionObserver.NotifyAction("Creating", "Group", NTHost.CurrentMachine.Name + '\\' + remoteGroup.Name, string.Empty);
                localGroup = NTHost.CurrentMachine.CreateLocalGroup(
                    remoteGroup.Name,
                    remoteGroup.Description
                    );
            }
            else
            {
                ActionObserver.NotifyAction("Copying", "Group", localGroup.FullName, remoteGroup.FullName);
                localGroup.Description = remoteGroup.Description;
                localGroup.Update();
            }

            Debug.Assert(localGroup != null);

            NTObject[] localMembers = localGroup.GetMembers();
            if (_applyMembershipDeletions)
            {
                foreach (NTObject obj in localMembers)
                {
                    ActionObserver.NotifyAction("Deleting", "Group Membership", localGroup.FullName, obj.FullName);
                    localGroup.DeleteMember(obj);
                }
            }

            if (_copyLocalMembership)
            {
                CopyLocalGroupMembership(remoteGroup, localGroup, localMembers);
            }

            if (_copyDomainMembership)
            {
                CopyRemoteGroupMembership(remoteGroup, localGroup, localMembers);
            }

            return(localGroup);
        }
Пример #9
0
        public void CopyLocalGroupMembership(NTLocalGroup sourceRemoteGroup, NTLocalGroup destinationLocalGroup, NTObject[] destinationLocalGroupMembers)
        {
            ActionObserver.NotifyAction("Copy", "Local Group Membership", sourceRemoteGroup.FullName, destinationLocalGroup.FullName);
            TextBank existingMembers = new TextBank(
                from obj in destinationLocalGroupMembers
                where obj is NTLocalObject
                select(object) obj
                );

            UserCopier userCopier = new UserCopier(
                false,
                false,
                DefaultUserPassword,
                false,
                ActionObserver
                );

            foreach (NTLocalUser remoteUser in sourceRemoteGroup.GetLocalMembers())
            {
                NTLocalUser localUser = null;

                // find a user by the same name of local machine
                if (!NTHost.CurrentMachine.TryGetLocalUser(remoteUser.Name, out localUser))
                {
                    // import the user if required
                    if (_importLocalUsers)
                    {
                        localUser = userCopier.CopyRemoteUserToLocalMachine(remoteUser);
                    }
                }

                if (localUser != null)
                {
                    if (!existingMembers.ContainsText(localUser.Name))
                    {
                        destinationLocalGroup.AddLocalMember(localUser);
                    }
                }
            }
        }
Пример #10
0
        public override void Process(ProcessContext context)
        {
            MvcEventPublisher.Instance.BeginProcessAction(context.ctx);
            if (context.ctx.utils.isSkipCurrentProcessor())
            {
                return;
            }

            MvcContext ctx = context.ctx;

            ControllerBase controller = ctx.controller;


            // 1) 检查 action 缓存
            ActionCacheChecker xChecker     = ActionCacheChecker.InitAction(ctx);
            Object             cacheContent = xChecker.GetCache();

            if (cacheContent != null)
            {
                logger.Info("load from actionCache=" + xChecker.CacheKey);
                context.setContent(cacheContent.ToString());
                setPageMeta_FromCache(ctx, xChecker.CacheKey);
                return;
            }

            // 2) 运行 before action (获取所有的 ActionObserver)
            List <ActionObserver> actionObservers = ControllerMeta.GetActionObservers(controller.GetType(), ctx.route.action);

            if (actionObservers != null)
            {
                foreach (ActionObserver x in actionObservers)
                {
                    ActionObserver ob         = (ActionObserver)ObjectContext.CreateObject(x.GetType());
                    Boolean        isContinue = ob.BeforeAction(ctx);
                    if (!isContinue)
                    {
                        return;
                    }
                }
            }

            // 3) 运行 action
            MethodInfo actionMethod = ctx.ActionMethodInfo; // context.getActionMethod();

            // 设值模板并载入全局变量
            setControllerView(controller, actionMethod);

            // 运行并处理post值
            ActionRunner.runAction(ctx, controller, actionMethod, controller.utils.runAction);
            if (ctx.utils.isEnd())
            {
                afterAction(ctx);
                return;
            }

            String actionContent = controller.utils.getActionResult();

            // 4) 后续缓存处理
            if (xChecker.IsActionCache)
            {
                xChecker.AddCache(actionContent);
                addPageMeta_ToCache(ctx, xChecker.CacheKey);
            }

            actionContent = PostValueProcessor.ProcessPostValue(actionContent, ctx);

            if (ctx.utils.isAjax)
            {
                context.showEnd(actionContent);
            }
            else if (ctx.utils.isFrame())
            {
                int intNoLayout = ctx.utils.getNoLayout();

                if (intNoLayout == 0)
                {
                    String content = MvcUtil.getFrameContent(actionContent);
                    context.showEnd(content);
                }
                else
                {
                    context.setContent(actionContent);
                }
            }
            else
            {
                context.setContent(actionContent);
            }

            afterAction(ctx);
        }
Пример #11
0
        public void CopyShare(CopyableShare copyableShare)
        {
            #region Validation
            if (!Directory.Exists(copyableShare.DestPath))
            {
                ActionObserver.NotifyError("Cannot copy share '{0}' to '{1}' as the destination path does not exist", copyableShare.SourceShare.FullName, copyableShare.DestPath);
                return;
            }
            #endregion

            NTShare sourceShare = copyableShare.SourceShare;
            string  destPath    = copyableShare.DestPath;

            ActionObserver.NotifyAction("Copying", "Share", sourceShare.FullName, destPath);
            try {
                NTShare destShare;

                // try to load share at destination server (assumed to be localhost), by name
                if (!NTHost.CurrentMachine.TryGetShare(sourceShare.Name, out destShare))
                {
                    // one doesn't exist so create one
                    destShare = NTHost.CurrentMachine.CreateShare(
                        sourceShare.Name,
                        sourceShare.Description,
                        sourceShare.Type,
                        destPath
                        );
                }
                else
                {
                    // make sure we loaded one pointing to same directory as we expect
                    if (!Path.Equals(destShare.ServerPath, copyableShare.DestPath))
                    {
                        // in this branch, a different share of the same name already exists
                        if (AutoResolveShareNameConflicts)
                        {
                            string newName = ResolveShareNameConflict(NTHost.CurrentMachine, sourceShare.Name);
                            ActionObserver.NotifyWarning(
                                "Copying share '{0}\\{1}' as '{2}\\{3}' to avoid name conflict",
                                copyableShare.SourceShare.Host,
                                copyableShare.SourceShare.Name,
                                NTHost.CurrentMachine.Host,
                                newName
                                );

                            // we want to auto-create a share name
                            destShare = NTHost.CurrentMachine.CreateShare(
                                newName,
                                sourceShare.Description,
                                sourceShare.Type,
                                destPath
                                );
                        }
                        else
                        {
                            // in this branch, bail out of share copying as share name already taken
                            ActionObserver.NotifyError(
                                "Cannot copy the share '{0}\\{1}' to folder '{2}' as it will conflict with '{3}\\{4}' defined for folder '{5}'",
                                copyableShare.SourceShare.Host,
                                copyableShare.SourceShare.Name,
                                copyableShare.DestPath,
                                destShare.Host,
                                destShare.Name,
                                destShare.ServerPath
                                );
                        }
                        return;
                    }
                }

                // copy details
                destShare.Name        = sourceShare.Name;
                destShare.Description = sourceShare.Description;
                destShare.MaxUses     = sourceShare.MaxUses;
                destShare.Password    = sourceShare.Password;
                destShare.Permissions = sourceShare.Permissions;
                destShare.Reserved    = sourceShare.Reserved;
                destShare.ServerPath  = destPath;
                destShare.Update();

                CopyShareSecurity(sourceShare, destShare);

                // create new share
            } catch (Exception error) {
                ActionObserver.NotifyActionFailed("Copying", "Share", copyableShare.SourceShare.FullName, copyableShare.DestPath, error.Message);
            }
        }
Пример #12
0
        private Dictionary <string, string> AssembleSidTranslationTable(IEnumerable <AuthorizationRule> authorizationRules)
        {
            var danglingSids = new Dictionary <string, string>();

            foreach (var authorizationRule in authorizationRules)
            {
                // if we encounter a SID and not an account name, it means it could not be resolved
                if (authorizationRule.IdentityReference is SecurityIdentifier)
                {
                    // rule references a dangling id, try to resolve it to remote machine name
                    var    remoteSID = authorizationRule.IdentityReference.Value;
                    string remoteName;
                    string remoteHost;
                    WinAPI.ADVAPI32.SidNameUse remoteNameUse;
                    if (Resolver.TryResolve(remoteSID, out remoteHost, out remoteName, out remoteNameUse))
                    {
                        // 2.1 Translate dangling user to equivalent name on local server
                        if (!danglingSids.ContainsKey(remoteSID))
                        {
                            string translatedName;

                            // translate to a local name
                            if (!SidTranslator.TryTranslate(
                                    remoteHost,
                                    remoteName,
                                    remoteNameUse,
                                    out translatedName))
                            {
                                // couldn't translate it, or import anything, so just default to administrators
                                ActionObserver.NotifyWarning("Unable to translate/import remote {0} '{1}\\{2}'", remoteNameUse, remoteHost, remoteName);
                                translatedName = "Administrators";
                            }

                            var localAccount = new NTAccount(
                                translatedName
                                );

                            var translatedUserSid = localAccount.Translate(
                                typeof(SecurityIdentifier)
                                ).Value;

                            ActionObserver.NotifyAction("Translating", "SID", remoteSID, translatedUserSid);
                            if (!danglingSids.ContainsKey(remoteSID))
                            {
                                danglingSids.Add(remoteSID, translatedUserSid);
                            }
                        }
                    }
                    else
                    {
                        // replace this SID with administrators
                        var localAccount      = new NTAccount("Administrators");
                        var translatedUserSid = localAccount.Translate(
                            typeof(SecurityIdentifier)
                            ).Value;


                        ActionObserver.NotifyWarning("Danging SID '{0}' identified, using Administrators group sid", remoteSID);
                        if (!danglingSids.ContainsKey(remoteSID))
                        {
                            danglingSids.Add(remoteSID, translatedUserSid);
                        }
                    }
                }
            }
            return(danglingSids);
        }