Exemplo n.º 1
0
 public void Remove(NodeResource nr)
 {
     if (nodes.Remove(nr))
     {
         nr.Path = "";
     }
 }
Exemplo n.º 2
0
        public int AddResource(NodeResource resource, HttpPostedFileBase file)
        {
            var node = GetDbContext().Nodes.SingleOrDefault(n => n.Id == resource.NodeId);
            var path = Path.Combine(GetCoursePath(node.CourseId), "Node");

            path = Path.Combine(path, resource.NodeId.Value.ToString());
            path = Path.Combine(path, "Images");

            resource.Path = "Node/" + resource.NodeId + "/Images/" + file.FileName;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            file.SaveAs(Path.Combine(path, file.FileName));

            var db = GetDbContext();

            db.NodeResources.InsertOnSubmit(resource);
            db.SubmitChanges();


            return(resource.Id);
        }
        private async Task RunPowerShellCommand(ServerManagementClient client, NodeResource node,
                                                SessionResource session,
                                                PowerShellSessionResource ps)
        {
            // run a command
            var result =
                await
                client.PowerShell.InvokeCommandAsync(ResourceGroup,
                                                     node.Name,
                                                     session.Name,
                                                     ps.SessionId,
                                                     "dir c:\\");

            Assert.NotNull(result);

            // did the command complete successfully?t
            Assert.True(result.Completed);

            // did we get some results?
            var found = false;

            foreach (var r in result.Results)
            {
                found = true;
                WriteLine(string.Format(" {0}", r.ToJson()));
            }
            Assert.True(found);
        }
Exemplo n.º 4
0
        public void GetResourceValidIdTest()
        {
            NodeResource nodeResource = _Storage.GetResource(0);

            Assert.AreEqual(0, nodeResource.Id);
            Assert.AreEqual("NodeResorces0", nodeResource.Name);
        }
Exemplo n.º 5
0
        protected Node(NodeResource resource)
        {
            // copy data from API object.
            resource.CloneInto(this);

            GatewayName = GatewayId.ExtractFieldFromResourceId("gateways");
            ResourceGroupName = Id.ExtractFieldFromResourceId("resourcegroups");
        }
Exemplo n.º 6
0
        protected Node(NodeResource resource)
        {
            // copy data from API object.
            resource.CloneInto(this);

            GatewayName       = GatewayId.ExtractFieldFromResourceId("gateways");
            ResourceGroupName = Id.ExtractFieldFromResourceId("resourcegroups");
        }
Exemplo n.º 7
0
        public void RemoveResource(BlockchainNode node, NodeResourceType resourceType, ResponseHandler.DispatherCallback dispatherCallback)
        {
            ActionRequest action = new ActionRequest(ActionType.DeleteFile);

            action.FullNodeName = node.NodeEndpoint.FullNodeName;
            NodeResource nodeResource = NodeResourceLocator.NodeResources[resourceType];

            action.Parameters.Add(ActionParameters.Path, ClientConfigReader.Evaluate(nodeResource.ResourceLocation, node.NodeConfig));
            actionQueue.Enqueue(action);
        }
Exemplo n.º 8
0
        public void UpdateResource(int id, NodeResource resource)
        {
            var db = GetDbContext();

            var oldRes = db.NodeResources.Single(n => n.Id == id);

            oldRes.Name = resource.Name;
            oldRes.Type = resource.Type;
            oldRes.Path = resource.Path;

            db.SubmitChanges();
        }
Exemplo n.º 9
0
        public void ClearTables()
        {
            var mockCourseData       = new Course[] { };
            var mockCourseUserData   = new CourseUser[] { };
            var mockNodeData         = new Node[] { };
            var mockNodeResourceData = new NodeResource[] { };

            this._MockDataContext.SetupGet(c => c.Courses).Returns(new MemoryTable <Course>(mockCourseData));
            this._MockDataContext.SetupGet(c => c.Nodes).Returns(new MemoryTable <Node>(mockNodeData));
            this._MockDataContext.SetupGet(c => c.NodeResources).Returns(new MemoryTable <NodeResource>(mockNodeResourceData));
            this._MockDataContext.SetupGet(c => c.CourseUsers).Returns(new MemoryTable <CourseUser>(mockCourseUserData));
        }
Exemplo n.º 10
0
        public void GetResourceInvalidIdTest()
        {
            try
            {
                NodeResource nodeResource = _Storage.GetResource(-30);
            }
            catch (InvalidOperationException)
            {
                Assert.Pass();
            }

            Assert.Fail();
        }
Exemplo n.º 11
0
        private void Item_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                NodeResource src = sender as NodeResource;
                if (Graph != null)
                {
                    Graph.Insert(src.Type);
                }

                CloseView();
            }
        }
        private async Task RunLongPowerShellCommand(ServerManagementClient client, NodeResource node,
                                                    SessionResource session,
                                                    PowerShellSessionResource ps)
        {
            // run a command
            var result = await client.PowerShell.InvokeCommandAsync(ResourceGroup,
                                                                    node.Name,
                                                                    session.Name,
                                                                    ps.SessionId,
                                                                    "dir c:\\ ; sleep 20 ; dir c:\\windows");

            Assert.NotNull(result);

            // this should return false because 20 seconds is too long...
            // did the command complete successfully?
            Assert.False(result.Completed);

            // did we get some results?
            var found = false;

            foreach (var r in result.Results)
            {
                found = true;
                WriteLine(string.Format(" {0}", r.ToJson()));
            }
            Assert.True(found);

            PowerShellCommandStatus more;

            found = false;
            // go back for some more results.
            do
            {
                more = await client.PowerShell.GetCommandStatusAsync(ResourceGroup,
                                                                     node.Name,
                                                                     session.Name,
                                                                     ps.SessionId,
                                                                     PowerShellExpandOption.Output);

                foreach (var r in more.Results)
                {
                    found = true;
                    WriteLine(string.Format(" {0}", r.ToJson()));
                }
            } while (!(more.Completed ?? false));
            Assert.True(found);
            Assert.True(more.Completed);
        }
        private async Task ListPowerShellSessions(ServerManagementClient client, NodeResource node,
                                                  SessionResource session)
        {
            bool found;
            // list the powershell sessions open
            var sessions = await client.PowerShell.ListSessionAsync(ResourceGroup, node.Name, session.Name);

            Assert.NotNull(sessions);
            found = false;
            foreach (var s in sessions.Value)
            {
                found = true;
                WriteLine(string.Format(" {0}", s.ToJson()));
            }
            Assert.True(found);
        }
Exemplo n.º 14
0
        private void Item_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                NodeResource src = sender as NodeResource;
                if (Graph != null)
                {
                    Graph.Insert(src.Type);

                    Keyboard.ClearFocus();
                    Graph.Focus();
                }

                Hide();
            }
        }
Exemplo n.º 15
0
        public void UpdateResources()
        {
            NodeResource newResource = new NodeResource
            {
                Name = "New name",
                Type = 0,
                Path = "New path"
            };

            _Storage.UpdateResource(0, newResource);

            NodeResource resource = _Storage.GetResource(0);

            Assert.AreEqual("New name", resource.Name);
            Assert.AreEqual(0, resource.Type);
            Assert.AreEqual("New path", resource.Path);
        }
Exemplo n.º 16
0
        public void DeleteResource()
        {
            Directory.CreateDirectory(@"d:\Tests\Data\Courses\1\0\somePath0");


            _Storage.DeleteResource(0);

            try
            {
                NodeResource nodeResource = _Storage.GetResource(0);
            }
            catch (InvalidOperationException)
            {
                Assert.Pass();
            }

            Assert.Fail();
        }
Exemplo n.º 17
0
        private void Builder_OnBuildComplete(ShelfBuilder builder)
        {
            var r = builder.Root;
            Stack <ShelfBuilder.ShelfBuilderItem> stack = new Stack <ShelfBuilder.ShelfBuilderItem>();

            stack.Push(r);

            while (stack.Count > 0)
            {
                var n = stack.Pop();
                var c = root.FindChild(n.Path);

                foreach (var resource in n.Nodes)
                {
                    NodeResource nr = new NodeResource();
                    nr.Title   = resource.Title;
                    nr.Path    = resource.Path;
                    nr.Type    = resource.Type;
                    nr.ToolTip = ShelfDescriptions.Get(nr);
                    c.Add(nr);
                }

                List <ShelfBuilder.ShelfBuilderItem> children = n.Children;

                foreach (var child in children)
                {
                    ShelfItem sh = new ShelfItem(child.BaseName);
                    c.Add(sh);
                    stack.Push(child);
                }
            }

            if (IsLoaded)
            {
                if (string.IsNullOrEmpty(selectedPath))
                {
                    PopulateView("Categories");
                }
                else
                {
                    PopulateView(selectedPath);
                }
            }
        }
Exemplo n.º 18
0
        public void AddResourceTest()
        {
            NodeResource newResource = new NodeResource
            {
                Id     = 4,
                Name   = "NodeResorces4",
                Node   = _Storage.GetNode(0),
                NodeId = _Storage.GetNode(0).Id,
                Path   = "somePath4"
            };
            int id = _Storage.AddResource(newResource, _Tests.HttpPostedFileBase);

            Assert.AreEqual(4, id);

            string resourcePath = _Storage.GetResourcePath(4);
            string path         = "1\\0\\Node/0/Images/file";

            Assert.IsTrue(resourcePath.Contains(path));
        }
Exemplo n.º 19
0
        //we eventually will need to save these settings and allow removal
        //from the shelf
        private void UserControl_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] path = (string[])e.Data.GetData(DataFormats.FileDrop);

                foreach (string p in path)
                {
                    string fname = Path.GetFileNameWithoutExtension(p);

                    if (Path.GetExtension(p).Equals(".mtg"))
                    {
                        NodeResource nsr = new NodeResource();
                        nsr.Title = fname;
                        nsr.Type  = p;
                        TreeList.Items.Add(nsr);
                    }
                }
            }
        }
        private async Task GetTabCompletionResults(ServerManagementClient client, NodeResource node,
                                                   SessionResource session,
                                                   PowerShellSessionResource ps)
        {
            bool found;
            // try to get tab command completion
            var results = await client.PowerShell.TabCompletionAsync(ResourceGroup,
                                                                     node.Name,
                                                                     session.Name,
                                                                     ps.SessionId,
                                                                     "dir c:\\");

            Assert.NotNull(results);
            found = false;
            foreach (var s in results.Results)
            {
                found = true;
                WriteLine(string.Format(" {0}", s.ToJson()));
            }
            Assert.True(found);
        }
Exemplo n.º 21
0
        public void DeleteResources()
        {
            List <int> ids = new List <int>();

            ids.Add(0);
            ids.Add(1);
            ids.Add(2);

            _Storage.DeleteResources(ids);

            try
            {
                NodeResource nodeResource = _Storage.GetResource(1);
            }
            catch (InvalidOperationException)
            {
                Assert.Pass();
            }

            Assert.Fail();
        }
Exemplo n.º 22
0
        //we eventually will need to save these settings and allow removal
        //from the shelf
        private void UserControl_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] path = (string[])e.Data.GetData(DataFormats.FileDrop);

                foreach (string p in path)
                {
                    string fname = Path.GetFileNameWithoutExtension(p);
                    string ext   = Path.GetExtension(p);

                    if (ext.Equals(".mtg") || ext.Equals(".mtga"))
                    {
                        NodeResource nsr = new NodeResource();
                        nsr.Title   = fname;
                        nsr.Type    = p;
                        nsr.ToolTip = ShelfDescriptions.Get(nsr);
                        root.Add(nsr);
                    }
                }
            }
        }
Exemplo n.º 23
0
        public static string Get(NodeResource nr)
        {
            string value = null;

            if (nr.Type.Contains("/") || nr.Type.Contains("\\"))
            {
                string filename = Path.GetFileName(nr.Type);

                if (local != null)
                {
                    local.Get(filename, out value);
                }
            }
            else
            {
                if (local != null)
                {
                    local.Get(nr.Type, out value);
                }
            }

            return(value);
        }
Exemplo n.º 24
0
        void LoadShelf()
        {
            string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Shelf");

            if (Directory.Exists(dir))
            {
                string[] path = Directory.GetFiles(dir);

                List <string> sorter = new List <string>();
                Dictionary <string, string> lookup = new Dictionary <string, string>();

                foreach (string p in path)
                {
                    string fname = Path.GetFileNameWithoutExtension(p);

                    if (Path.GetExtension(p).Equals(".mtg"))
                    {
                        sorter.Add(fname);
                        lookup[fname] = p;
                    }
                }

                sorter.Sort();

                foreach (string fname in sorter)
                {
                    string p = null;

                    if (lookup.TryGetValue(fname, out p))
                    {
                        NodeResource nsr = new NodeResource();
                        nsr.Title = fname;
                        nsr.Type  = p;
                        string structure = p.Replace(dir + Path.PathSeparator, "");
                        if (structure.Contains(Path.PathSeparator))
                        {
                            TItem parent = root;

                            string[] split = structure.Split(Path.PathSeparator);

                            for (int i = 0; i < split.Length - 1; i++)
                            {
                                var s = split[i];
                                var t = parent.Get(s);

                                if (t == null)
                                {
                                    TreeViewItem it = new TreeViewItem();
                                    it.Header = s;
                                    t         = new TItem(it);
                                    parent.Add(s, t);
                                }

                                parent = t;
                            }


                            if (parent == root || parent == null)
                            {
                                TreeList.Items.Add(nsr);
                            }
                            else
                            {
                                parent.Item.Items.Add(nsr);
                            }
                        }
                        else
                        {
                            TreeList.Items.Add(nsr);
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
        static ReportFieldNodes()
        {
            var nodeUrl = Create("Uri", (Uri uri) => uri,
                                 Create("AbsolutePath", (Uri uri) => uri.AbsolutePath),
                                 Create("AbsoluteUri", (Uri uri) => uri.AbsoluteUri),
                                 Create("Authority", (Uri uri) => uri.Authority),
                                 Create("Fragment", (Uri uri) => uri.Fragment),
                                 Create("Host", (Uri uri) => uri.Host),
                                 Create("PathAndQuery", (Uri uri) => uri.PathAndQuery),
                                 Create("Query", (Uri uri) => uri.Query),
                                 Create("Scheme", (Uri uri) => uri.Scheme));

            var nodeReference =
                Create("References", (ResourceReferenceCollection r) => r,
                       Create("First", (IEnumerable <ResourceReference> lst) => lst.FirstOrDefault()),
                       Create("Count", (IEnumerable <ResourceReference> lst) => lst.Count()));

            NodeResource  = Create("Resource", (ReportNodeInfos i) => i.Resource);
            NodeReference = Create("Reference", (ReportNodeInfos i) => i.Reference);
            NodeContent   = Create("Content", (ReportNodeInfos i) => i.Content);
            NodeError     = Create("Error", (ReportNodeInfos i) => i.Error);

            var referenceCollection = Create("ReferenceCollection", (IEnumerable <ResourceReference> coll) => coll,
                                             Create("Count", (IEnumerable <ResourceReference> coll) => coll.Count()),
                                             Create("First", (IEnumerable <ResourceReference> coll) => coll.FirstOrDefault()),
                                             Create("First5", (IEnumerable <ResourceReference> coll) => new ReportArray(coll.Take(5).ToArray <object>())),
                                             Create("First10", (IEnumerable <ResourceReference> coll) => new ReportArray(coll.Take(10).ToArray <object>())),
                                             CreateAlias("Items", (IEnumerable <ResourceReference> coll) => new ReportArray(coll.ToArray <object>()), NodeReference));

            NodeResource.AddNodes(
                Create("ProcessingStatus", (Resource res) => res.Status),
                Create("Status", (Resource res) => DescriptionExtractor.GetDescription(res.Status == ResourceStatus.Processed ? (object)res.HttpStatus : res.Status)),
                Create("Content", (Resource res) => res.Content),
                Create("Errors", (Resource res) => res.Errors),
                Create("Redirections", (Resource res) => res,
                       CreateAlias("First", (Resource res) => res.References.FirstOrDefault(x => x.Type == ResourceReferenceTypes.Redirection), NodeReference),
                       Create <Resource, int>("Count", CountRedirections),
                       CreateAlias <Resource, Resource>("Final", FollowRedirections, NodeResource)),
                Create("References", (Resource res) => res.References,
                       CreateAlias("All", (ResourceReferenceCollection res) => res, referenceCollection),
                       CreateAlias("Anchors", (ResourceReferenceCollection res) => res.Where(x => x.Type == ResourceReferenceTypes.Anchor), referenceCollection),
                       CreateAlias("Images", (ResourceReferenceCollection res) => res.Where(x => x.Type == ResourceReferenceTypes.Image), referenceCollection),
                       Create("Links", (ResourceReferenceCollection res) => res,
                              CreateAlias("Canonicals", (ResourceReferenceCollection res) => res.Where(x => x.SubType == ReferenceSubType.Canonical), referenceCollection),
                              CreateAlias("ShortcutIcons", (ResourceReferenceCollection res) => res.Where(x => x.SubType == ReferenceSubType.ShortcutIcon), referenceCollection),
                              CreateAlias("StyleSheets", (ResourceReferenceCollection res) => res.Where(x => x.SubType == ReferenceSubType.StyleSheet), referenceCollection)),
                       CreateAlias("Scripts", (ResourceReferenceCollection res) => res.Where(x => x.Type == ResourceReferenceTypes.Script), referenceCollection)),
                CreateAlias("Referers", (Resource res) => res.ReferencedBy, referenceCollection),
                Create("Request", (Resource res) => res,
                       Create("Behavior", (Resource res) => res.Behavior),
                       Create("TimeStart", (Resource res) => res.TimeStart),
                       CreateAlias("Url", (Resource res) => res.Url, nodeUrl)),
                Create("Response", (Resource res) => res,
                       Create("CompressedSize", (Resource res) => res.CompressedSize),
                       Create("ContentType", (Resource res) => res.ContentType),
                       Create("Headers", (Resource res) => res.Headers,
                              Create("ContentEncoding", (ResourceHeaders h) => h.TryGetValue("content-encoding")),
                              Create("ContentType", (ResourceHeaders h) => h.TryGetValue("content-type")),
                              Create("CacheControl", (ResourceHeaders h) => h.TryGetValue("cache-control")),
                              Create("HasETAG", (ResourceHeaders h) => !String.IsNullOrWhiteSpace(h.TryGetValue("ETag"))),
                              Create("LastModified", (ResourceHeaders h) => TryParseDate(h.TryGetValue("last-modified"))),
                              Create("Expires", (ResourceHeaders h) => TryParseDate(h.TryGetValue("expires")))),
                       Create("HttpStatus", (Resource res) => res.HttpStatus),
                       Create("Size", (Resource res) => res.Size),
                       Create("CompressedSize", (Resource res) => res.CompressedSize),
                       Create("TimeLoading", (Resource res) => res.TimeLoading),
                       Create("TimeProcessing", (Resource res) => res.TimeProcessing),
                       Create("ViewStateSize", (Resource res) => res.ViewStateSize ?? 0)));

            NodeReference.AddNodes(
                CreateAlias("Source", (ResourceReference r) => r.Source, NodeResource),
                CreateAlias("Target", (ResourceReference r) => r.Target, NodeResource),
                Create("Type", (ResourceReference r) => r.Type),
                Create("SubType", (ResourceReference r) => r.SubType),
                Create("RawUrl", (ResourceReference r) => r.Url.OriginalString),
                Create("Count", (ResourceReference r) => r.Count),
                Create("IsRecursive", (ResourceReference r) => r.Source == r.Target || r.Source == FollowRedirections(r.Target)));

            NodeContent.AddNodes(
                Create("Key", (ResourceContent c) => c.Key),
                Create("Value", (ResourceContent c) => c.Value));

            NodeError.AddNodes(
                Create("Type", (ResourceError e) => e.Type),
                Create("Message", (ResourceError e) => e.Message),
                Create("Value", (ResourceError e) => e.Value),
                Create("Line", (ResourceError e) => e.Line));

            Root = Create("Root", (ReportNodeInfos i) => i, NodeResource, NodeReference, NodeContent, NodeError);
        }
Exemplo n.º 26
0
 public void Add(NodeResource nr)
 {
     nr.Path = Path;
     nodes.Add(nr);
 }
Exemplo n.º 27
0
        public void UpdateResources()
        {
            NodeResource newResource = new NodeResource
                                                       {
                                                           Name = "New name",
                                                           Type = 0,
                                                           Path = "New path"
                                                       };
            _Storage.UpdateResource(0,newResource);

            NodeResource resource = _Storage.GetResource(0);
            Assert.AreEqual("New name",resource.Name);
            Assert.AreEqual(0, resource.Type);
            Assert.AreEqual("New path", resource.Path);
        }
Exemplo n.º 28
0
 public static Node Create(NodeResource resource)
 {
     return resource == null ? null : new Node(resource);
 }
Exemplo n.º 29
0
        public int AddResource(NodeResource resource, HttpPostedFileBase file)
        {
            var node = GetDbContext().Nodes.SingleOrDefault(n => n.Id == resource.NodeId);
            var path = Path.Combine(GetCoursePath(node.CourseId), "Node");
            path = Path.Combine(path, resource.NodeId.Value.ToString());
            path = Path.Combine(path, "Images");
            
            resource.Path = "Node/" + resource.NodeId + "/Images/" + file.FileName;

            if(!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            file.SaveAs(Path.Combine(path, file.FileName));
            
            var db = GetDbContext();

            db.NodeResources.InsertOnSubmit(resource);
            db.SubmitChanges();


            return resource.Id;
        }
Exemplo n.º 30
0
        public void UpdateResource(int id, NodeResource resource)
        {
            var db = GetDbContext();

            var oldRes = db.NodeResources.Single(n => n.Id == id);

            oldRes.Name = resource.Name;
            oldRes.Type = resource.Type;
            oldRes.Path = resource.Path;

            db.SubmitChanges();
        }
Exemplo n.º 31
0
      public void ClearTables()
      {
         var mockCourseData = new Course[] { };
         var mockCourseUserData = new CourseUser[] { };
         var mockNodeData = new Node[] { };
         var mockNodeResourceData = new NodeResource[] { };

         this._MockDataContext.SetupGet(c => c.Courses).Returns(new MemoryTable<Course>(mockCourseData));
         this._MockDataContext.SetupGet(c => c.Nodes).Returns(new MemoryTable<Node>(mockNodeData));
         this._MockDataContext.SetupGet(c => c.NodeResources).Returns(new MemoryTable<NodeResource>(mockNodeResourceData));
         this._MockDataContext.SetupGet(c => c.CourseUsers).Returns(new MemoryTable<CourseUser>(mockCourseUserData));
      }
Exemplo n.º 32
0
 public static Node Create(NodeResource resource)
 {
     return(resource == null ? null : new Node(resource));
 }
Exemplo n.º 33
0
        public void AddResourceTest()
        {
            NodeResource newResource = new NodeResource
                                           {
                                               Id = 4,
                                               Name = "NodeResorces4",
                                               Node = _Storage.GetNode(0),
                                               NodeId = _Storage.GetNode(0).Id,
                                               Path = "somePath4"
                                           };
            int id = _Storage.AddResource(newResource, _Tests.HttpPostedFileBase);

            Assert.AreEqual(4,id);

            string resourcePath = _Storage.GetResourcePath(4);
            string path = "d:\\Tests\\Data\\Courses\\1\\0\\Node/0/Images/file";

            Assert.AreEqual(path, resourcePath);
        }