Beispiel #1
0
        private void Rename(string oldPath, string newPath)
        {
            FileModelCache.TryRemove(FullPath, out _);

            FullPath   = FullPath.Replace(oldPath, newPath);
            ParentPath = ParentPath.Replace(oldPath, newPath);

            FileModelCache.TryAdd(FullPath, this);

            if (Folders != null)
            {
                foreach (FileModel folder in Folders)
                {
                    folder.Rename(oldPath, newPath);
                }
            }

            if (Files != null)
            {
                foreach (FileModel file in Files)
                {
                    file.Rename(oldPath, newPath);
                }
            }
        }
Beispiel #2
0
 public Presenter(IWinZipUI view, ParentPath parentPath, ParentPathValidator parentPathValidator)
 {
     _view                = view;
     _parentPath          = parentPath;
     _parentPathValidator = parentPathValidator;
     _subFolders          = new List <DirectoryInfo>();
 }
Beispiel #3
0
 public bool Equals(PageStateModel?other)
 {
     return(PageType == other?.PageType &&
            CollectionAlias == other?.CollectionAlias &&
            (ParentPath?.ToPathString() ?? "") == (other?.ParentPath?.ToPathString() ?? "") &&
            Id == other?.Id);
 }
            internal BaseBranchNode CreateRootNode(IDictionary <string, BaseBranchNode> nodes,
                                                   Func <Tree, string, BaseBranchNode> createPathNode)

            {
                if (ParentPath.IsNullOrEmpty())
                {
                    return(this);
                }

                BaseBranchNode parent;
                BaseBranchNode result;

                if (nodes.TryGetValue(ParentPath, out parent))
                {
                    result = null;
                }
                else
                {
                    parent = createPathNode(Tree, ParentPath);
                    nodes.Add(ParentPath, parent);
                    result = parent.CreateRootNode(nodes, createPathNode);
                }

                parent.Nodes.AddNode(this);

                return(result);
            }
        protected override void OnParametersSet()
        {
            State = null;

            var pageType = GetPageType();

            if (pageType == PageType.Dashboard)
            {
                State = new PageStateModel
                {
                    PageType = PageType.Dashboard
                };
            }
            else
            {
                State = new PageStateModel
                {
                    PageType        = pageType,
                    UsageType       = GetUsageType(),
                    CollectionAlias = CollectionAlias,
                    Id           = Id,
                    ParentPath   = ParentPath.TryParse(Path),
                    VariantAlias = VariantAlias
                };
            }

            Mediator.NotifyEvent(this, new NavigationEventArgs(State, false));
        }
Beispiel #6
0
            public IEnumerator GetEnumerator()
            {
                yield return(new object[] {
                    "/collection/edit/person/",
                    "",
                    new NavigationState("person", default(ParentPath), UsageType.Edit)
                });

                yield return(new object[] {
                    "/collection/edit/person/",
                    "?p=1",
                    new NavigationState("person", default(ParentPath), UsageType.Edit)
                    {
                        CollectionState = new CollectionState(null, null, 1, null)
                    }
                });

                yield return(new object[]
                {
                    "/node/edit/person-convention/VNRDry/-/428281356/",
                    "",
                    new NavigationState("person-convention", default(ParentPath), "VNRDry", "428281356", UsageType.Edit)
                });

                yield return(new object[]
                {
                    "/node/edit/person-convention/VNRDry/fdsa:123/428281356/",
                    "",
                    new NavigationState("person-convention", ParentPath.TryParse("fdsa:123"), "VNRDry", "428281356", UsageType.Edit)
                });

                yield return(new object[]
                {
                    "/node/edit/person-convention/VNRDry/fdsa:123;fdsafdsa:12345/428281356/",
                    "",
                    new NavigationState("person-convention", ParentPath.TryParse("fdsa:123;fdsafdsa:12345"), "VNRDry", "428281356", UsageType.Edit)
                });

                yield return(new object[]
                {
                    "node/new/variants/aOkLV_",
                    "",
                    new NavigationState("variants", default(ParentPath), "aOkLV_", default(string), UsageType.New)
                });

                yield return(new object[]
                {
                    "/node/new/person/yY4Nc6/Da9Ic3-Sv5oVVgQDwmEuxhfvCEs7j6maatAe46OuNgA:439326248;Da9Ic3-Sv5oVVgQDwmEuxhfvCEs7j6maatAe46OuNgA:654154684;Da9Ic3-Sv5oVVgQDwmEuxhfvCEs7j6maatAe46OuNgA:1594109173/",
                    "",
                    new NavigationState(
                        "person",
                        ParentPath.TryParse("Da9Ic3-Sv5oVVgQDwmEuxhfvCEs7j6maatAe46OuNgA:439326248;Da9Ic3-Sv5oVVgQDwmEuxhfvCEs7j6maatAe46OuNgA:654154684;Da9Ic3-Sv5oVVgQDwmEuxhfvCEs7j6maatAe46OuNgA:1594109173"),
                        "yY4Nc6",
                        default(string),
                        UsageType.New)
                });
            }
Beispiel #7
0
 public bool IsSimilar(NavigationState?other)
 {
     return(PageType == other?.PageType &&
            // UsageType == other?.UsageType &&
            _collectionAlias == other?._collectionAlias &&
            VariantAlias == other?.VariantAlias &&
            ParentPath?.ToPathString() == other?.ParentPath?.ToPathString() &&
            Related == other?.Related &&
            Id == other?.Id);
 }
        public void BasicPath()
        {
            // arrange

            // act
            var path = ParentPath.TryParse("test:123");

            // assert
            Assert.AreEqual("test:123", path !.ToPathString());
        }
Beispiel #9
0
        public bool Equals(INetworkCommand networkCommand)
        {
            if (!(networkCommand is CreateEntryRequestNetworkCommand <T>))
            {
                return(false);
            }

            CreateEntryRequestNetworkCommand <T> other = (CreateEntryRequestNetworkCommand <T>)networkCommand;

            return(ParentPath.Equals(other.ParentPath) && DocumentName.Equals(other.DocumentName));
        }
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            var parentPath = ParentPath.Get(context);
            var attachment = Attachment.Get(context);
            var overwrite  = OverwriteExistingContent.Get(context);

            var SaveAttachmentDelegate = new Func <string, Attachment, bool, WfContent>(SaveAttachment);

            context.UserState = SaveAttachmentDelegate;
            return(SaveAttachmentDelegate.BeginInvoke(parentPath, attachment, overwrite, callback, state));
        }
        public void AppendPathFromNull()
        {
            // arrange

            // act
            var path    = default(ParentPath);
            var newPath = ParentPath.AddLevel(path, "test2", "1234");

            // assert
            Assert.AreEqual("test2:1234", newPath.ToPathString());
        }
        public void ShouldDetermineThatParentPathDidNotChanged()
        {
            // setup
            var startingPath = Support.Fixture.ParentPath;

            // run
            var SUT       = new ParentPath(startingPath);
            var isChanged = SUT.IsChanged(startingPath);

            // assert
            Assert.That(isChanged, Is.False);
        }
Beispiel #13
0
 public bool Equals(NavigationState?other)
 {
     return(PageType == other?.PageType &&
            UsageType == other?.UsageType &&
            _collectionAlias == other?._collectionAlias &&
            VariantAlias == other?.VariantAlias &&
            ParentPath?.ToPathString() == other?.ParentPath?.ToPathString() &&
            Related == other?.Related &&
            Id == other?.Id &&
            CollectionState.ActiveTab == other?.CollectionState.ActiveTab &&
            CollectionState.CurrentPage == other?.CollectionState.CurrentPage);
 }
        public void AppendPath()
        {
            // arrange

            // act
            var path    = ParentPath.TryParse("test:123");
            var newPath = ParentPath.AddLevel(path, "test2", "1234");

            // assert
            Assert.AreEqual("test:123", path !.ToPathString());
            Assert.AreEqual("test:123;test2:1234", newPath.ToPathString());
        }
Beispiel #15
0
        protected override void Execute(NativeActivityContext context)
        {
            var ext = context.GetExtension <ContentWorkflowExtension>();

            var parent = Node.LoadNode(ParentPath.Get(context));

            if (parent == null)
            {
                throw new ApplicationException("Cannot create content because parent does not exist. Path: " + ParentPath.Get(context));
            }

            var name        = Name.Get(context);
            var displayName = ContentDisplayName.Get(context);

            if (string.IsNullOrEmpty(name))
            {
                name = ContentNamingHelper.GetNameFromDisplayName(displayName);
            }

            var content = ContentManager.CreateContentFromRequest(GetContentTypeName(context), name, ParentPath.Get(context), true);

            if (!string.IsNullOrEmpty(displayName))
            {
                content.DisplayName = displayName;
            }

            var fieldValues = FieldValues.Get(context);

            if (fieldValues != null)
            {
                foreach (var key in fieldValues.Keys)
                {
                    content[key] = fieldValues[key];
                }
            }

            SetContentFields(content, context);

            content.ContentHandler.DisableObserver(typeof(WorkflowNotificationObserver));

            try
            {
                content.Save();
            }
            catch (Exception e)
            {
                throw new ApplicationException(String.Concat("Cannot create content. See inner exception. Expected path: "
                                                             , ParentPath.Get <string>(context), "/", Name.Get(context)), e);
            }

            Result.Set(context, new WfContent(content.ContentHandler));
        }
        public void ShouldResetParentPathToEmptyString()
        {
            // setup
            var startingPath = Support.Fixture.ParentPath;

            // run
            var SUT = new ParentPath(startingPath);

            SUT.Reset();

            // assert
            Assert.That(SUT.Path, Is.Empty);
        }
        public void ShouldDetermineThatParentPathChanged()
        {
            // setup
            var startingPath = Support.Fixture.ParentPath;
            var newPath      = $"{Support.Fixture.ParentPath}new";

            // run
            var SUT       = new ParentPath(startingPath);
            var isChanged = SUT.IsChanged(newPath);

            // assert
            Assert.That(isChanged, Is.True);
        }
        public void ShouldUpdate()
        {
            // setup
            var startingPath = Support.Fixture.ParentPath;
            var newPath      = $"{Support.Fixture.ParentPath}new";

            // run
            var SUT = new ParentPath(startingPath);

            SUT.Update(newPath);

            // assert
            Assert.That(SUT.Path, Is.EqualTo(newPath));
        }
Beispiel #19
0
        public async Task <EntitiesResponseModel> GetAsync(GetEntitiesRequestModel request)
        {
            var subjectRepository = _repositoryResolver.GetRepository(request.RepositoryAlias);

            var parentPath = request is GetEntitiesOfParentRequestModel parentRequest ? parentRequest.ParentPath
                : request is GetEntitiesOfRelationRequestModel relationRequest ? relationRequest.Related.ParentPath
                : default;
            var parent = await _parentService.GetParentAsync(ParentPath.TryParse(parentPath));

            var related = default(IRelated);

            if (request is GetEntitiesOfRelationRequestModel relatedRequest)
            {
                var relatedRepository = _repositoryResolver.GetRepository(relatedRequest.Related.RepositoryAlias ?? throw new ArgumentNullException());
                var relatedEntity     = await relatedRepository.GetByIdAsync(relatedRequest.Related.Id ?? throw new ArgumentNullException(), new ViewContext(null, default))
                                        ?? throw new NotFoundException("Could not find related entity");

                related = new RelatedEntity(parent, relatedEntity, relatedRequest.Related.RepositoryAlias);
            }

            var protoEntity = await subjectRepository.NewAsync(new ViewContext(null, parent), default);

            await _authService.EnsureAuthorizedUserAsync(request.UsageType, protoEntity);

            await _dataViewResolver.ApplyDataViewToViewAsync(request.View);

            var action = (request.UsageType & ~(UsageType.List)) switch
            {
                UsageType.Add when related != null => async() => await subjectRepository.GetAllNonRelatedAsync(new RelatedViewContext(related, null, default), request.View),
                _ when related != null => async() => await subjectRepository.GetAllRelatedAsync(new RelatedViewContext(related, null, default), request.View),
                _ when related == null => async() => await subjectRepository.GetAllAsync(new ViewContext(null, parent), request.View),

                _ => default(Func <Task <IEnumerable <IEntity> > >)
            };

            if (action == default)
            {
                throw new InvalidOperationException($"UsageType {request.UsageType} is invalid for this method");
            }

            var entities = await action.Invoke();

            return(new EntitiesResponseModel
            {
                Entities = entities,
                MoreDataAvailable = request.View.MoreDataAvailable
            });
        }
    }
Beispiel #20
0
        public void SetFolderName(string name)
        {
            var newPath = ParentPath.ConcatPath(name);

            // Update the non-folder objects within this folder:
            TreeModel.ModifyDisplayFolder(Table, Path, newPath, Culture);

            // Update the folder objects within this folder (so the tree does not need to be rebuilt):
            foreach (var f in ChildFolders)
            {
                f.SetDisplayFolder(newPath, Culture, false);
            }

            Path = newPath;
        }
        public async Task <EntitiesResponseModel> GetAsync(GetEntitiesRequestModel request)
        {
            var subjectRepository = _repositoryResolver.GetRepository(request.RepositoryAlias);

            var parentPath = request is GetEntitiesOfParentRequestModel parentRequest ? parentRequest.ParentPath
                : request is GetEntitiesOfRelationRequestModel relationRequest ? relationRequest.Related.ParentPath
                : default;
            var parent = await _parentService.GetParentAsync(ParentPath.TryParse(parentPath));

            var related = default(IRelated);

            if (request is GetEntitiesOfRelationRequestModel relatedRequest)
            {
                var relatedRepository = _repositoryResolver.GetRepository(relatedRequest.Related.RepositoryAlias ?? throw new ArgumentNullException());
                var relatedEntity     = await relatedRepository.GetByIdAsync(relatedRequest.Related.Id ?? throw new ArgumentNullException(), default)
        public void RemoveLevelFromNull()
        {
            // arrange

            // act
            var path = ParentPath.TryParse(null);

            var(newPath, collectionAlias, id) = ParentPath.RemoveLevel(path);

            // assert
            Assert.AreEqual(null, path?.ToPathString());
            Assert.AreEqual("", newPath?.ToPathString());
            Assert.AreEqual(null, collectionAlias);
            Assert.AreEqual(null, id);
        }
        public void RemoveLevel()
        {
            // arrange

            // act
            var path = ParentPath.TryParse("test:123;test2:1234");

            var(newPath, collectionAlias, id) = ParentPath.RemoveLevel(path);

            // assert
            Assert.AreEqual("test:123;test2:1234", path !.ToPathString());
            Assert.AreEqual("test:123", newPath.ToPathString());
            Assert.AreEqual("test2", collectionAlias);
            Assert.AreEqual("1234", id);
        }
Beispiel #24
0
        public NavigationState(string url, string queryString)
        {
            var urlItems = url.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);

            if (urlItems.Length == 0)
            {
                PageType = PageType.Dashboard;
            }
            else
            {
                PageType = Enum.TryParse <PageType>(urlItems[0], true, out var pageType) ? pageType : PageType.Dashboard;

                if (urlItems.Length > 1)
                {
                    switch (PageType)
                    {
                    case PageType.Collection:

                        UsageType        = Enum.TryParse <UsageType>(urlItems.ElementAtOrDefault(1), true, out var usageType1) ? usageType1 : UsageType.View;
                        _collectionAlias = urlItems.ElementAtOrDefault(2);
                        ParentPath       = ParentPath.TryParse(urlItems.ElementAtOrDefault(3));
                        break;

                    case PageType.Node:

                        UsageType        = Enum.TryParse <UsageType>(urlItems.ElementAtOrDefault(1), true, out var usageType2) ? usageType2 : UsageType.View;
                        _collectionAlias = urlItems.ElementAtOrDefault(2);
                        VariantAlias     = urlItems.ElementAtOrDefault(3);
                        ParentPath       = ParentPath.TryParse(urlItems.ElementAtOrDefault(4));
                        Id = urlItems.ElementAtOrDefault(5);
                        break;

                    case PageType.Page:

                        _collectionAlias = urlItems.ElementAtOrDefault(1);

                        break;
                    }
                }
            }

            var qs          = HttpUtility.ParseQueryString(queryString);
            var tab         = int.TryParse(qs.Get("tab"), out var t) ? t : default(int?);
            var searchTerm  = qs.Get("q");
            var currentPage = int.TryParse(qs.Get("p"), out var p) ? p : 1;

            CollectionState = new CollectionState(tab, searchTerm, currentPage);
        }
Beispiel #25
0
        public override int GetHashCode()
        {
            var hc = Path != null?Path.GetHashCode() : 2;

            hc ^= ParentPath != null?ParentPath.GetHashCode() : 4;

            hc ^= _ordinal.HasValue ? _ordinal.Value.GetHashCode() :8;
            hc ^= _type.HasValue ? _type.Value.GetHashCode() : 16;
            hc ^= WorkItemClass != null?WorkItemClass.GetHashCode() : 32;

            hc ^= Title != null?Title.GetHashCode() : 64;

            hc ^= WipLimit.HasValue ? WipLimit.Value.GetHashCode() : 128;

            return(hc);
        }
Beispiel #26
0
 public void initFolder()
 {
     if (!ParentPath.EndsWith("\\"))
     {
         ParentPath += "\\";
     }
     if (!Directory.Exists(ParentPath))
     {
         Directory.CreateDirectory(ParentPath);
     }
     _path = ParentPath + FolderName + "\\";
     if (!Directory.Exists(_path))
     {
         Directory.CreateDirectory(_path);
     }
 }
Beispiel #27
0
        public string ParentFolder()
        {
            if (ParentPath.TrimEnd('\\')
                .EndsWith("Ed-Fi-ODS", StringComparison.InvariantCultureIgnoreCase) ||
                ParentPath.TrimEnd('\\')
                .EndsWith("Ed-Fi-ODS-Implementation", StringComparison.InvariantCultureIgnoreCase))
            {
                return(ParentPath);
            }

            var parent = new DirectoryInfo(ParentPath).Parent;

            return(parent == null
                ? ParentPath
                : parent.FullName);
        }
        private async Task LocationChangedAsync(object sender, NavigationEventArgs args)
        {
            if (sender is NavigationLink || UI == null || args.OldState != null || !args.NewState.HasCollectionAlias)
            {
                return;
            }

            if ((ParentPath?.ToPathString() == args.NewState.ParentPath?.ToPathString() && args.NewState.CollectionAlias == CollectionAlias) ||
                ParentPath.IsBaseOf(args.NewState.ParentPath, UI.RepositoryAlias, default))
            {
                await InvokeAsync(() =>
                {
                    NodesVisible = true;
                    StateHasChanged();
                });
            }
        }
Beispiel #29
0
        public async Task <IEntity> GetAsync(GetEntityRequestModel request)
        {
            if (string.IsNullOrWhiteSpace(request.Subject.Id) && (request.UsageType.HasFlag(UsageType.View) || request.UsageType.HasFlag(UsageType.Edit)))
            {
                throw new InvalidOperationException($"Cannot View/Edit Node when id is null");
            }
            if (!string.IsNullOrWhiteSpace(request.Subject.Id) && request.UsageType.HasFlag(UsageType.New))
            {
                throw new InvalidOperationException($"Cannot New Node when id is not null");
            }

            var repository = _repositoryResolver.GetRepository(request.Subject.RepositoryAlias ?? throw new ArgumentNullException());

            var parent = await _parentService.GetParentAsync(ParentPath.TryParse(request.Subject.ParentPath));

            var entityVariant = request.Subject.VariantAlias == null ? default : _entityVariantResolver.ResolveSetup(request.Subject.VariantAlias);

                                var action = (request.UsageType & ~(UsageType.Node | UsageType.Root | UsageType.NotRoot)) switch
                                {
                                    UsageType.View => () => repository.GetByIdAsync(request.Subject.Id !, parent),
                                    UsageType.Edit => () => repository.GetByIdAsync(request.Subject.Id !, parent),
                                    UsageType.New => () => repository.NewAsync(parent, entityVariant?.Type) !,

                                    _ => default(Func <Task <IEntity?> >)
                                };

                                if (action == default)
                                {
                                    throw new InvalidOperationException($"UsageType {request.UsageType} is invalid for this method");
                                }

                                var entity = await action.Invoke();

                                if (entity == null)
                                {
                                    throw new NotFoundException("Failed to get entity for given id");
                                }

                                await _authService.EnsureAuthorizedUserAsync(request.UsageType, entity);

                                return(entity);
        }
    }
        public IReadOnlyList <ScriptFileVersionLevel> GetAllScriptFiles()
        {
            string scriptNamePrefix = ScriptNamePrefix();

            var allScriptNames = _fileSystemAdapter.GetFiles(ScriptPath, "*.sql", SearchOption.TopDirectoryOnly)
                                 .Select(Path.GetFileName);

            return(allScriptNames.Select(scriptName => new ScriptFileVersionLevel(scriptNamePrefix, scriptName)).ToList());

            string ScriptNamePrefix()
            {
                string parentFolder = ParentFolder();

                string scriptFileNamePrefix = ScriptPath.Remove(0, parentFolder.Length);

                scriptFileNamePrefix = scriptFileNamePrefix.Replace("\\", ".");

                if (scriptFileNamePrefix.StartsWith("."))
                {
                    scriptFileNamePrefix = scriptFileNamePrefix.Remove(0, 1);
                }

                return(scriptFileNamePrefix);
            }

            string ParentFolder()
            {
                if (ParentPath.TrimEnd('\\')
                    .EndsWith("Ed-Fi-ODS", StringComparison.InvariantCultureIgnoreCase) ||
                    ParentPath.TrimEnd('\\')
                    .EndsWith("Ed-Fi-ODS-Implementation", StringComparison.InvariantCultureIgnoreCase))
                {
                    return(ParentPath);
                }

                var parent = new DirectoryInfo(ParentPath).Parent;

                return(parent == null
                    ? ParentPath
                    : parent.FullName);
            }
        }