Inheritance: IResource
示例#1
0
        public void SaveWebSourceWithExistingSourceExpectedServerWorkspaceUpdated()
        {
            //Initialize test resource, save then change path
            string uniquePathText = Guid.NewGuid().ToString() + "\\test web source";
            var testResource = new Resource { ResourceName = "test web source", ResourcePath = "initialpath\\test web source", ResourceType = ResourceType.WebSource, ResourceID = Guid.NewGuid() };
            new WebSources().Save(testResource.ToString(), GlobalConstants.ServerWorkspaceID, Guid.Empty);
            testResource.ResourcePath = uniquePathText;

            //Execute save again on test resource
            new WebSources().Save(testResource.ToString(), GlobalConstants.ServerWorkspaceID, Guid.Empty);

            //Assert resource saved
            var getSavedResource = Resources.ReadXml(GlobalConstants.ServerWorkspaceID, ResourceType.WebSource, testResource.ResourceID.ToString());
            const string PathStartText = "<Category>";
            int start = getSavedResource.IndexOf(PathStartText, StringComparison.Ordinal);
            if(start > 0)
            {
                start += PathStartText.Length;
                int end = (getSavedResource.IndexOf("</Category>", start, StringComparison.Ordinal));
                var savedPath = getSavedResource.Substring(start, end - start);
                Assert.AreEqual(uniquePathText, savedPath);
            }
            else
            {
                Assert.Fail("Resource xml malformed after save");
            }
        }
 public void ApisJsonBuilder_BuildForPath_NullPath_ShouldBuildForWholeCatalog()
 {
     //------------Setup for test--------------------------
     EnvironmentVariables.DnsName = "http://localhost/";
     EnvironmentVariables.Port = 3142;
     var mockAuthorizationService = new Mock<IAuthorizationService>();
     mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.View, It.IsAny<string>())).Returns(true);
     mockAuthorizationService.Setup(service => service.IsAuthorized(AuthorizationContext.Execute, It.IsAny<string>())).Returns(true);
     var mockResourceCatalog = new Mock<IResourceCatalog>();
     var resources = new List<IResource>();
     var resource1 = new Resource { ResourceName = "Execution Engine Test",ResourcePath = "Acceptance Testing Resources\\Execution Engine\\Execution Engine Test", ResourceType = ResourceType.WorkflowService};
     var resource2 = new Resource { ResourceName = "Hello World", ResourcePath = "Hello World", ResourceType = ResourceType.WorkflowService };
     var resource3 = new Resource { ResourceName = "9139Local", ResourcePath = "Acceptance Testing Resources\\9139Local", ResourceType = ResourceType.WorkflowService };
     
     resources.Add(resource1);
     resources.Add(resource2);
     resources.Add(resource3);
     mockResourceCatalog.Setup(catalog => catalog.GetResourceList(It.IsAny<Guid>())).Returns(resources);
     var apisJsonBuilder = new ApisJsonBuilder(mockAuthorizationService.Object,mockResourceCatalog.Object);
     var exceptedApisJson = GetExceptedApisJsonForServerNoSecurity();
     //------------Execute Test---------------------------
     var apisJson = apisJsonBuilder.BuildForPath(null,false);
     //------------Assert Results-------------------------
     Assert.IsNotNull(apisJson);
     Assert.AreEqual(exceptedApisJson,apisJson);
     Assert.AreEqual(exceptedApisJson.Apis.Count,apisJson.Apis.Count);
     Assert.AreEqual(exceptedApisJson.Apis[0].BaseUrl.Contains("secure"), apisJson.Apis[0].BaseUrl.Contains("secure"));
 }
 public void EqualsWithSameItemKeyExpectedReturnsTrue()
 {
     var key = new Resource();
     var result = key.Equals(key);
     Assert.IsTrue(result);
     result = key.Equals((object)key);
     Assert.IsTrue(result);
 }
 public void EqualsWithNullExpectedReturnsFalse()
 {
     var key = new Resource();
     var result = key.Equals(null);
     Assert.IsFalse(result);
     result = key.Equals((object)null);
     Assert.IsFalse(result);
 }
 public void EqualsWithDifferentItemKeyHavingDifferentPropertiesExpectedReturnsFalse()
 {
     var key = new Resource();
     var other = new Resource { ResourceID = Guid.NewGuid() };
     var result = key.Equals(other);
     Assert.IsFalse(result);
     result = key.Equals((object)other);
     Assert.IsFalse(result);
 }
        public void EqualsWithDifferentItemKeyHavingSamePropertiesExpectedReturnsTrue()
        {
            var key = new Resource();
            var other = new Resource();
            var result = key.Equals(other);
            Assert.IsTrue(result);
            result = key.Equals((object)other);
            Assert.IsTrue(result);

        }
        public void FindResourceHelper_SerializeResourceForStudio_WhenNotNewResource_ExpectValidResource()
        {
            //------------Setup for test--------------------------
            var id = Guid.NewGuid();
            IResource res = new Resource { ResourceID = id, IsNewResource = false };

            //------------Execute Test---------------------------

            var result = new FindResourceHelper().SerializeResourceForStudio(res);

            //------------Assert Results-------------------------

            Assert.IsFalse(result.IsNewResource);
            Assert.AreEqual(id, result.ResourceID);
        }
 public void Resource_LoadDependencies_HasEmailSource_ShouldHaveEmailSourceInDepencyList()
 {
     //------------Setup for test--------------------------
     XElement element = XmlResource.Fetch("EmailTest");
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.IsNotNull(resource.Dependencies);
     Assert.AreEqual(1, resource.Dependencies.Count);
     Assert.AreEqual("TestEmailSource", resource.Dependencies[0].ResourceName);
     Assert.AreEqual("988e1146-ddb8-456d-8a01-4377a707605b", resource.Dependencies[0].ResourceID.ToString());
 }
 public void Construct_UnitTest_LoadDependenciesWhereHasRemoteWorkflowDependency_ExpectedRemoteServerDependencyAdded()
 {
     //------------Setup for test--------------------------
     XElement element = XmlResource.Fetch("say hello remote");
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.IsNotNull(resource.Dependencies);
     Assert.AreEqual(4, resource.Dependencies.Count);
     IResourceForTree serverDependency = resource.Dependencies.First(tree => tree.ResourceID == Guid.Parse("889d3f22-40c5-4466-84bc-d49a5874ae53"));
     Assert.IsNotNull(serverDependency);
     Assert.AreEqual("server - tfs bld", serverDependency.ResourceName);
     Assert.AreEqual(ResourceType.Server, serverDependency.ResourceType);
 }
 public void ConstructWhereValidXMLFromResourceWithOneDependenciesExpectResourceWithOneItemInTree()
 {
     //------------Setup for test--------------------------
     var validXML = GetStringFromResource();
     var textReader = new StringReader(validXML);
     XElement element = XElement.Load(textReader, LoadOptions.None);
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.IsNotNull(resource.Dependencies);
     Assert.AreEqual(1, resource.Dependencies.Count);
     var resourceForTrees = resource.Dependencies.ToList();
     var resourceForTreeRoot = resourceForTrees[0];
     Assert.AreEqual(new Guid("7bce06ec-778d-4a64-9dfe-1a826785f0b0"), resourceForTreeRoot.UniqueID);
 }
        public StringBuilder Execute(Dictionary<string, StringBuilder> values, IWorkspace theWorkspace)
        {
            try
            {


                var res = new ExecuteMessage { HasError = false };

                string serviceId = null;
                StringBuilder tmp;
                values.TryGetValue("ResourceID", out tmp);

                if (tmp != null)
                {
                    serviceId = tmp.ToString();
                }

                Guid resourceId;
                Guid.TryParse(serviceId, out resourceId);
                Dev2Logger.Log.Info("Fetch Resource definition. ResourceId:" + resourceId);
                try
                {
                    var result = ResourceCatalog.Instance.GetResourceContents(theWorkspace.ID, resourceId);
                    var tempResource = new Resource(result.ToXElement());
                    //var resource = ResourceCatalog.Instance.GetResource(theWorkspace.ID, resourceId);
                    var resource = tempResource;

                    if (resource.ResourceType == ResourceType.DbSource)
                    {
                        res.Message.Append(result);
                    }
                    else
                    {
                        var startIdx = result.IndexOf(PayloadStart, 0, false);

                        if (startIdx >= 0)
                        {
                            // remove beginning junk
                            startIdx += PayloadStart.Length;
                            result = result.Remove(0, startIdx);

                            startIdx = result.IndexOf(PayloadEnd, 0, false);

                            if (startIdx > 0)
                            {
                                var len = result.Length - startIdx;
                                result = result.Remove(startIdx, len);

                                res.Message.Append(result.Unescape());
                            }
                        }
                        else
                        {
                            // handle services ;)
                            startIdx = result.IndexOf(AltPayloadStart, 0, false);
                            if (startIdx >= 0)
                            {
                                // remove begging junk
                                startIdx += AltPayloadStart.Length;
                                result = result.Remove(0, startIdx);

                                startIdx = result.IndexOf(AltPayloadEnd, 0, false);

                                if (startIdx > 0)
                                {
                                    var len = result.Length - startIdx;
                                    result = result.Remove(startIdx, len);

                                    res.Message.Append(result.Unescape());
                                }
                            }
                            else
                            {
                                // send the entire thing ;)
                                res.Message.Append(result);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Dev2Logger.Log.Error(string.Format("Error getting resource definition for: {0}", resourceId), e);
                }


                // Finally, clean the definition as per execution hydration rules ;)
                Dev2XamlCleaner dev2XamlCleaner = new Dev2XamlCleaner();
                res.Message = dev2XamlCleaner.StripNaughtyNamespaces(res.Message);

                Dev2JsonSerializer serializer = new Dev2JsonSerializer();
                return serializer.SerializeToBuilder(res);
            }
            catch (Exception err)
            {
                Dev2Logger.Log.Error(err);
                throw;
            }
        }
示例#12
0
        // ReSharper disable InconsistentNaming
        public void Resources_UnitTest_PluginPathsAndNames_WorkflowServicesAreIncluded()
        // ReSharper restore InconsistentNaming
        {
            //Isolate PathsAndNames for workflows as a functional unit
            var workspaceID = Guid.NewGuid();
            var workspacePath = EnvironmentVariables.GetWorkspacePath(workspaceID);
            try
            {
                const int Modulo = 4;
                const int TotalResourceCount = 9;
                for (var i = 0; i < TotalResourceCount; i++)
                {
                    var resource = new Resource
                    {
                        ResourceID = Guid.NewGuid(),
                        ResourceName = string.Format("My Name {0}", i),
                        ResourcePath = string.Format("My Path {0}\\{1}", i, string.Format("My Name {0}", i))
                    };

                    switch (i % Modulo)
                    {
                        case 0:
                            resource.ResourcePath = ResourceType.WorkflowService + "\\" + resource.ResourceName;
                            resource.ResourceType = ResourceType.WorkflowService;
                            break;
                        case 1:
                            resource.ResourcePath = ResourceType.DbService + "\\" + resource.ResourceName;
                            resource.ResourceType = ResourceType.DbService;
                            break;
                        case 2:
                            resource.ResourcePath = ResourceType.PluginService + "\\" + resource.ResourceName;
                            resource.ResourceType = ResourceType.PluginService;
                            break;
                        case 3:
                            resource.ResourcePath = ResourceType.ServerSource + "\\" + resource.ResourceName;
                            resource.ResourceType = ResourceType.ServerSource;
                            break;
                    }
                    ResourceCatalog.Instance.SaveResource(workspaceID, resource);
                }
                var resources = new Resources();
                const string ExpectedJson = "{\"Names\":[\"My Name 3\",\"My Name 7\"],\"Paths\":[\"ServerSource\"]}";

                //Run PathsAndNames
                var actualJson = resources.PathsAndNames("ServerSource", workspaceID,Guid.Empty);

                //Assert CorrectListReturned
                Assert.AreEqual(ExpectedJson, actualJson, "Incorrect list of names and paths for workflow services");
            }
            finally
            {
                if (Directory.Exists(workspacePath))
                {
                    DirectoryHelper.CleanUp(workspacePath);
                }
            }
        }
示例#13
0
        public void SourcesWithValidArgsExpectedReturnsList()
        {
            var workspaceID = Guid.NewGuid();
            var workspacePath = EnvironmentVariables.GetWorkspacePath(workspaceID);
            try
            {
                const int Modulo = 2;
                const int ExpectedCount = 6;
                for(var i = 0; i < ExpectedCount; i++)
                {
                    var resource = new Resource
                    {
                        ResourceID = Guid.NewGuid(),
                        ResourceName = string.Format("My Name {0}", i),
                        ResourcePath = string.Format("My Path {0}", i),
                        ResourceType = (i % Modulo == 0) ? ResourceType.DbSource : ResourceType.Unknown
                    };
                    ResourceCatalog.Instance.SaveResource(workspaceID, resource);
                }
                var resources = new Resources();
                var result = resources.Sources("{\"resourceType\":\"" + ResourceType.DbSource + "\"}", workspaceID, Guid.Empty);

                Assert.AreEqual(ExpectedCount / Modulo, result.Count);
            }
            finally
            {
                if(Directory.Exists(workspacePath))
                {
                    DirectoryHelper.CleanUp(workspacePath);
                }
            }
        }
 static void UpdateCategoryIfRenamed(IResource res, Resource oldResource, XElement xml)
 {
     if(res.ResourcePath != null && res.ResourcePath != res.ResourceName) // we are not in the root folder
     {
         var oldPath = res.ResourcePath.Substring(0, 1 + res.ResourcePath.LastIndexOf("\\", StringComparison.Ordinal));
         var newPath = oldResource.ResourcePath.Substring(0, 1 + res.ResourcePath.LastIndexOf("\\", StringComparison.Ordinal));
         if(oldPath != newPath)
         {
             oldResource.ResourcePath = newPath + oldResource.ResourceName;
             xml.SetAttributeValue("Category", newPath + oldResource.ResourceName);
         }
     }
 }
 void StoreAndDeleteCurrentIfRenamed(IResource res, Resource oldResource)
 {
     if(res.ResourceName != oldResource.ResourceName)
     {
         StoreVersion(res, "unknown", "Rollback", Guid.Empty);
         _catalogue.DeleteResource(Guid.Empty, res.ResourceName, res.ResourceType.ToString(), null, false);
     }
 }
 public IRollbackResult RollbackTo(Guid resourceId, string versionNumber)
 {
     var res = _catalogue.GetResource(Guid.Empty, resourceId);
     var xmlBuilder = GetVersion(new VersionInfo(DateTime.MinValue, "", "", versionNumber, resourceId, res.VersionInfo.VersionId));
     var xml = xmlBuilder.ToXElement();
     Resource oldResource = new Resource(xml);
     UpdateCategoryIfRenamed(res, oldResource, xml);
     StoreAndDeleteCurrentIfRenamed(res, oldResource);
     UpdateVersionInfoIfNotExists(resourceId, xml, res);
     _catalogue.SaveResource(Guid.Empty, xml.ToStringBuilder(),null,"Rollback","Unknown");
     if (oldResource.ResourceName != res.ResourceName)
         _catalogue.GetResource(Guid.Empty, res.ResourceID).ResourceName = oldResource.ResourceName; 
     return new RollbackResult{DisplayName = oldResource.ResourceName, VersionHistory = GetVersions(resourceId)};
 }
示例#17
0
 public Guid ExecuteServiceMethod(Resource resource, ServiceMethod serviceMethod)
 {
     throw new NotImplementedException();
 }
示例#18
0
 public IOutputDescription TestServiceMethod(Resource resource, ServiceMethod serviceMethod)
 {
     throw new NotImplementedException();
 }
示例#19
0
 public ServiceMethodList GetServiceMethods(Resource resource)
 {
     throw new NotImplementedException();
 }
 public void Resource_LoadDependencies_HasDatabaseSourceFromSqlBulkInsertTool_ShouldHaveDatabaseSourceInDepencyList()
 {
     //------------Setup for test--------------------------
     XElement element = XmlResource.Fetch("Big Bulk Testing");
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.IsNotNull(resource.Dependencies);
     Assert.AreEqual(2, resource.Dependencies.Count);
     Assert.AreEqual("GenDev", resource.Dependencies[1].ResourceName);
     Assert.AreEqual("62505a00-b304-4ac0-a55c-50ce85111f16", resource.Dependencies[1].ResourceID.ToString());
 }
 public void Resource_XmlConstructor_Invoked_ShouldLoadDataList()
 {
     #region DataList String
     const string dataList = "<DataList>" +
                             "<result Description=\"\" IsEditable=\"True\" ColumnIODirection=\"Output\" />" +
                             "<Rows Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<res Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<start Description=\"\" IsEditable=\"True\" ColumnIODirection=\"Output\" />" +
                             "<end Description=\"\" IsEditable=\"True\" ColumnIODirection=\"Output\" />" +
                             "<InsertedData Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\">" +
                             "<BigID Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column1 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column2 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column3 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column4 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column5 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column6 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column7 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column8 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column9 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column10 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column11 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column12 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column13 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column14 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column15 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column16 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column17 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column18 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column19 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column20 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column21 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column22 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column23 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column24 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column25 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column26 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column27 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column28 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column29 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column30 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column31 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column32 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column33 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column34 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column35 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column36 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column37 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column38 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column39 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column40 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column41 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column42 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column43 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column44 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column45 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column46 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column47 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column48 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column49 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column50 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column51 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column52 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column53 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column54 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column55 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column56 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column57 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column58 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column59 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column60 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column61 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column62 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column63 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column64 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column65 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column66 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column67 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column68 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column69 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column70 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column71 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column72 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column73 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column74 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column75 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column76 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column77 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column78 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column79 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column80 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column81 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column82 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column83 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column84 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column85 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column86 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column87 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column88 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column89 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column90 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column91 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column92 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column93 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column94 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column95 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column96 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column97 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column98 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column99 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column100 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "</InsertedData>" +
                             "<Row Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\">" +
                             "<BigID Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "<Column100 Description=\"\" IsEditable=\"True\" ColumnIODirection=\"None\" />" +
                             "</Row></DataList>";
     #endregion
     //------------Setup for test--------------------------
     XElement element = XmlResource.Fetch("Big Bulk Testing");
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsFalse(String.IsNullOrEmpty(resource.DataList.ToString()));
     var expected = resource.DataList.Replace(Environment.NewLine, "").Replace(" ", "").ToString();
     var actual = dataList.Replace(" ", "");
     Assert.AreEqual(expected, actual);
 }
 public void ToXMLWhereValidResourceWIthErrorInfoDataIsValidFalse()
 {
     //------------Setup for test--------------------------
     var validXML = GetValidXMLString();
     var textReader = new StringReader(validXML);
     XElement element = XElement.Load(textReader, LoadOptions.None);
     var resource = new Resource(element);
     resource.Errors.Clear();
     resource.IsValid = false;
     resource.Errors.Add(new ErrorInfo { ErrorType = ErrorType.Critical, FixType = FixType.None, Message = "Fix Me", StackTrace = "Line 1" });
     //------------Execute Test---------------------------
     var xElement = resource.ToXml();
     //------------Assert Results-------------------------
     Assert.IsNotNull(xElement);
     var errorMessagesElement = xElement.Element("ErrorMessages");
     Assert.IsNotNull(errorMessagesElement);
     var errorMessageElement = errorMessagesElement.Element("ErrorMessage");
     Assert.IsNotNull(errorMessageElement);
     Assert.AreEqual("Fix Me", errorMessageElement.Attribute("Message").Value);
     Assert.AreEqual("Line 1", errorMessageElement.Attribute("StackTrace").Value);
     Assert.AreEqual("None", errorMessageElement.Attribute("FixType").Value);
     Assert.AreEqual("Critical", errorMessageElement.Attribute("ErrorType").Value);
 }
 public void Resource_XmlConstructor_Invoked_ServiceShouldHaveInputsAndOutputs()
 {
     var inputs = "<Inputs>" +
                           "<Input Name=\"CityName\" Source=\"CityName\" EmptyToNull=\"false\" DefaultValue=\"Paris-Aeroport Charles De Gaulle\" />" +
                           "<Input Name=\"CountryName\" Source=\"CountryName\" EmptyToNull=\"false\" DefaultValue=\"France\" />" +
                           "</Inputs>";
     var outputs = "<Outputs>" +
         "<Output OriginalName=\"Location\" Name=\"Location\" MapsTo=\"Location\" Value=\"[[Location]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" /> " +
         "<Output OriginalName=\"Time\" Name=\"Time\" MapsTo=\"Time\" Value=\"[[Time]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />                 " +
         "<Output OriginalName=\"Wind\" Name=\"Wind\" MapsTo=\"Wind\" Value=\"[[Wind]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />                 " +
        "<Output OriginalName=\"Visibility\" Name=\"Visibility\" MapsTo=\"Visibility\" Value=\"[[Visibility]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />" +
        "<Output OriginalName=\"Temperature\" Name=\"Temperature\" MapsTo=\"Temperature\" Value=\"[[Temperature]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />" +
        "<Output OriginalName=\"DewPoint\" Name=\"DewPoint\" MapsTo=\"DewPoint\" Value=\"[[DewPoint]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />" +
        "<Output OriginalName=\"RelativeHumidity\" Name=\"RelativeHumidity\" MapsTo=\"RelativeHumidity\" Value=\"[[RelativeHumidity]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />" +
        "<Output OriginalName=\"Pressure\" Name=\"Pressure\" MapsTo=\"Pressure\" Value=\"[[Pressure]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />" +
        "<Output OriginalName=\"Status\" Name=\"Status\" MapsTo=\"Status\" Value=\"[[Status]]\" RecordsetName=\"\" RecordsetAlias=\"\" Recordset=\"\" />" +
     "</Outputs>";
     //------------Setup for test--------------------------
     XElement element = XmlResource.Fetch("WebService");
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsFalse(String.IsNullOrEmpty(resource.DataList.ToString()));
     Assert.AreEqual("<DataList />", resource.DataList.ToString());
     inputs = inputs.Replace(Environment.NewLine, "").Replace(" ", "");
     outputs = outputs.Replace(Environment.NewLine, "").Replace(" ", "");
     var actual = resource.Inputs.Replace(Environment.NewLine, "").Replace(" ", "");
     Assert.AreEqual(inputs, actual);
     actual = resource.Outputs.Replace(Environment.NewLine, "").Replace(" ", "");
     Assert.AreEqual(outputs, actual);
 }
 public void EqualsWithObjectExpectedReturnsFalse()
 {
     var key = new Resource();
     var result = key.Equals(new object());
     Assert.IsFalse(result);
 }
 public void Resource_XmlConstructor_Invoked_ServiceNoInputsShouldHaveInputsAndOutputs()
 {
     //------------Setup for test--------------------------
     XElement element = XmlResource.Fetch("WebServiceWithoutInputs");
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsFalse(String.IsNullOrEmpty(resource.DataList.ToString()));
     Assert.AreEqual("<DataList />", resource.DataList.ToString());
     Assert.IsFalse(String.IsNullOrEmpty(resource.Inputs));
     Assert.IsFalse(String.IsNullOrEmpty(resource.Outputs));
 }
 public void ConstructWhereValidXMLWithMultipleServiceDependencyExpectResourceWithServiceDependency()
 {
     //------------Setup for test--------------------------
     var validXML = GetValidXMLStringWithMultipleDependenciesWithServiceDependencies();
     var textReader = new StringReader(validXML);
     XElement element = XElement.Load(textReader, LoadOptions.None);
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.IsNotNull(resource.Dependencies);
     Assert.AreEqual(3, resource.Dependencies.Count);
     var resourceForTrees = resource.Dependencies.ToList();
     var resourceForTreeService = resourceForTrees.Find(tree => tree.UniqueID == new Guid("48869a05-7121-4e45-970e-a40f6a2f8fd9"));
     Assert.IsNotNull(resourceForTreeService);
     Assert.AreEqual(ResourceType.PluginService, resourceForTreeService.ResourceType);
 }
 public void ConstructWhereValidResourceXMLWIthErrorInfoDataIsValidFalse()
 {
     //------------Setup for test--------------------------
     var validXML = GetValidXMLString();
     var textReader = new StringReader(validXML);
     XElement element = XElement.Load(textReader, LoadOptions.None);
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.AreEqual(3, resource.Errors.Count);
     Assert.AreEqual("Line 1", resource.Errors[0].StackTrace);
     Assert.AreEqual(ErrorType.None, resource.Errors[2].ErrorType);
     Assert.AreEqual("Error Message 2", resource.Errors[1].Message);
     Assert.AreEqual(FixType.None, resource.Errors[1].FixType);
 }
        public void BuildCatalogFromWorkspace(string workspacePath, params string[] folders)
        {
            if (string.IsNullOrEmpty(workspacePath))
            {
                throw new ArgumentNullException("workspacePath");
            }
            if (folders == null)
            {
                throw new ArgumentNullException("folders");
            }

            if (folders.Length == 0 || !Directory.Exists(workspacePath))
            {
                return;
            }

            var streams = new List<ResourceBuilderTO>();

            try
            {

                foreach (var path in folders.Where(f => !string.IsNullOrEmpty(f) && !f.EndsWith("VersionControl")).Select(f => Path.Combine(workspacePath, f)))
                {
                    if (!Directory.Exists(path))
                    {
                        continue;
                    }

                    var files = Directory.GetFiles(path, "*.xml");
                    foreach (var file in files)
                    {

                        FileAttributes fa = File.GetAttributes(file);

                        if ((fa & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        {
                            Dev2Logger.Log.Info("Removed READONLY Flag from [ " + file + " ]");
                            File.SetAttributes(file, FileAttributes.Normal);
                        }

                        // Use the FileStream class, which has an option that causes asynchronous I/O to occur at the operating system level.  
                        // In many cases, this will avoid blocking a ThreadPool thread.  
                        var sourceStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 4096, true);
                        streams.Add(new ResourceBuilderTO { FilePath = file, FileStream = sourceStream });

                    }
                }

                // Use the parallel task library to process file system ;)
                streams.ForEach(currentItem =>
                {

                    XElement xml = null;

                    try
                    {
                        xml = XElement.Load(currentItem.FileStream);
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("Resource [ " + currentItem.FilePath + " ] caused " + e.Message);
                    }

                    StringBuilder result = xml.ToStringBuilder();

                    var isValid = xml != null && HostSecurityProvider.Instance.VerifyXml(result);
                    if (isValid)
                    {
                        var resource = new Resource(xml)
                        {
                            FilePath = currentItem.FilePath
                        };

                        //2013.08.26: Prevent duplicate unassigned folder in save dialog and studio explorer tree by interpreting 'unassigned' as blank
                        if (resource.ResourcePath.ToUpper() == "UNASSIGNED")
                        {
                            resource.ResourcePath = string.Empty;
                            // DON'T FORCE A SAVE HERE - EVER!!!!
                        }
                        xml = _resourceUpgrader.UpgradeResource(xml, Assembly.GetExecutingAssembly().GetName().Version, a =>
                        {

                            var fileManager = new TxFileManager();
                            using (TransactionScope tx = new TransactionScope())
                            {
                                try
                                {

                                    StringBuilder updateXml = a.ToStringBuilder();
                                    var signedXml = HostSecurityProvider.Instance.SignXml(updateXml);

                                    signedXml.WriteToFile(currentItem.FilePath, Encoding.UTF8, fileManager);
                                    tx.Complete();
                                }
                                catch 
                                {
                                    try
                                    {
                                        Transaction.Current.Rollback();
                                    }
                                    catch (Exception err)
                                    {
                                        Dev2Logger.Log.Error(err);
                                    }
                                    throw;
                                }
                            }

                        });
                        if (resource.IsUpgraded)
                        {
                            // Must close the source stream first and then add a new target stream 
                            // otherwise the file will be remain locked
                            currentItem.FileStream.Close();

                            xml = resource.UpgradeXml(xml, resource);

                            StringBuilder updateXml = xml.ToStringBuilder();
                            var signedXml = HostSecurityProvider.Instance.SignXml(updateXml);
                             var fileManager = new TxFileManager();
                             using (TransactionScope tx = new TransactionScope())
                             {
                                 try
                                 {
                                     signedXml.WriteToFile(currentItem.FilePath, Encoding.UTF8,fileManager);
                                     tx.Complete();
                                 }
                                 catch
                                 {
                                     Transaction.Current.Rollback();
                                     throw;
                                 }
                             }
                        }
                        if (resource.VersionInfo == null)
                        {

                        }

                        lock (_addLock)
                        {
                            AddResource(resource, currentItem.FilePath);
                        }
                    }
                    else
                    {
                        Dev2Logger.Log.Debug(string.Format("'{0}' wasn't loaded because it isn't signed or has modified since it was signed.", currentItem.FilePath));
                    }
                });
            }
            finally
            {
                // Close all FileStream instances in a finally block after the tasks are complete. 
                // If each FileStream was instead created in a using statement, the FileStream 
                // might be disposed of before the task was complete
                foreach (var stream in streams)
                {
                    stream.FileStream.Close();
                }
            }
        }
 public void ConstructWhereValidXMLExpectResource()
 {
     //------------Setup for test--------------------------
     var validXML = GetValidXMLString();
     var textReader = new StringReader(validXML);
     XElement element = XElement.Load(textReader, LoadOptions.None);
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.AreEqual("1736ca6e-b870-467f-8d25-262972d8c3e8", resource.ResourceID.ToString());
     Assert.AreEqual("Bug6619", resource.ResourceName);
     Assert.AreEqual(ResourceType.WorkflowService, resource.ResourceType);
 }
 public void ConstructWhereValidXMLWithMultipleDependenciesExpectResourceWithGreaterThanOneItemInTree()
 {
     //------------Setup for test--------------------------
     var validXML = GetValidXMLStringWithMultipleDependencies();
     var textReader = new StringReader(validXML);
     XElement element = XElement.Load(textReader, LoadOptions.None);
     //------------Execute Test---------------------------
     var resource = new Resource(element);
     //------------Assert Results-------------------------
     Assert.IsNotNull(resource);
     Assert.IsNotNull(resource.Dependencies);
     Assert.AreEqual(2, resource.Dependencies.Count);
     var resourceForTrees = resource.Dependencies.ToList();
     var resourceForTreeChild1 = resourceForTrees[0];
     var resourceForTreeChild2 = resourceForTrees[1];
     Assert.AreEqual(new Guid("7bce06dc-778d-4b64-9dfe-1a826585f0b0"), resourceForTreeChild2.UniqueID);
     Assert.AreEqual(ResourceType.WorkflowService, resourceForTreeChild2.ResourceType);
     Assert.AreEqual(new Guid("7bce06ec-778d-4a64-9dfe-1a826785f0b0"), resourceForTreeChild1.UniqueID);
     Assert.AreEqual(ResourceType.WorkflowService, resourceForTreeChild1.ResourceType);
 }