Exemplo n.º 1
0
        private void ChangeConfigFiles(CloudServiceInfo serviceInfo)
        {
            _logger.Info("... changing config files");
            string serviceId = serviceInfo.ServiceName.FirstToLower();

            CodeHelper.IncludeLineInSpringConfig(GetCloudSpringConfigFileName(),
                                                 "</objects>",
                                                 "  <object id=\"" + serviceId + "\" type=\"IFS.CloudProxies" + serviceInfo.NamespaceName + "." + serviceInfo.ServiceName + "Proxy, IFS.CloudProxies\" lazy-init=\"true\" />", 0);
            CodeHelper.IncludeLineInSpringConfig(GetCloudSpringConfigDevFileName(),
                                                 "</objects>",
                                                 "  <object id=\"" + serviceId + "\" type=\"IFS.BusinessLayer.CloudServices" + serviceInfo.NamespaceName + "." + serviceInfo.ServiceName + ", IFS.BusinessLayer\" lazy-init=\"true\" />", 0);

            var sb = new StringBuilder();

            sb.AppendLine("  <component name=\"" + serviceInfo.ServiceName + "\">");
            sb.AppendLine("    <class name=\"IFS.BusinessLayer.CloudServices" + serviceInfo.NamespaceName + "." + serviceInfo.ServiceName + ", IFS.BusinessLayer\"/>");
            sb.Append("  </component>");
            CodeHelper.IncludeLineInSpringConfig(GetComponentsFileName(),
                                                 "</dotnet-components>",
                                                 sb.ToString(), 0);

            CodeHelper.IncludeLineInSpringConfig(GetServiceNamesFileName(),
                                                 "public",
                                                 "public static string " + serviceInfo.ServiceName.ConvertToConstName() + "_SPRING_NAME = \"" + serviceInfo.ServiceName.FirstToLower() + "\";");
        }
Exemplo n.º 2
0
        public static List <string> GetServiceCodeFromPattern(string patternName, CloudServiceInfo serviceInfo)
        {
            List <string> code = File.ReadAllLines(GetCodePatternFileName(patternName)).ToList();

            return(code.Select(r => r.Replace(@"%SERVICE_NAME%", serviceInfo.ServiceName)
                               .Replace(@"%NAMESPACE_NAME%", serviceInfo.NamespaceName)).ToList());
        }
Exemplo n.º 3
0
        public void ComplexTest()
        {
            var cloudServiceInfo = new CloudServiceInfo(@"Report\SubReport\SubSubReport\NewService:BaseTradeService");

            Assert.AreEqual(@"Report\SubReport\SubSubReport\", cloudServiceInfo.SubFolderName);
            Assert.AreEqual(".Report.SubReport.SubSubReport", cloudServiceInfo.NamespaceName);
            Assert.AreEqual("NewService", cloudServiceInfo.ServiceName);
            Assert.AreEqual("BaseTradeService", cloudServiceInfo.BaseClassName);
        }
Exemplo n.º 4
0
        public void BaseClassTest()
        {
            var cloudServiceInfo = new CloudServiceInfo("NewService:BaseTradeService");

            Assert.AreEqual(string.Empty, cloudServiceInfo.SubFolderName);
            Assert.AreEqual(string.Empty, cloudServiceInfo.NamespaceName);
            Assert.AreEqual("NewService", cloudServiceInfo.ServiceName);
            Assert.AreEqual("BaseTradeService", cloudServiceInfo.BaseClassName);
        }
Exemplo n.º 5
0
        public void DeepSubfolderTest()
        {
            var cloudServiceInfo = new CloudServiceInfo(@"Report\SubReport\SubSubReport\NewService");

            Assert.AreEqual(@"Report\SubReport\SubSubReport\", cloudServiceInfo.SubFolderName);
            Assert.AreEqual(".Report.SubReport.SubSubReport", cloudServiceInfo.NamespaceName);
            Assert.AreEqual("NewService", cloudServiceInfo.ServiceName);
            Assert.AreEqual(AppConfiguration.CloudServiceMainBaseClass, cloudServiceInfo.BaseClassName);
        }
Exemplo n.º 6
0
        public void SimpleTest()
        {
            var cloudServiceInfo = new CloudServiceInfo("NewService");

            Assert.AreEqual(string.Empty, cloudServiceInfo.SubFolderName);
            Assert.AreEqual(string.Empty, cloudServiceInfo.NamespaceName);
            Assert.AreEqual("NewService", cloudServiceInfo.ServiceName);
            Assert.AreEqual(AppConfiguration.CloudServiceMainBaseClass, cloudServiceInfo.BaseClassName);
        }
Exemplo n.º 7
0
        private string GetInterfaceFileName(CloudServiceInfo serviceInfo)
        {
            string folderName = Path.Combine(_sourceFolder, "IFS.Interfaces", "CloudContracts", serviceInfo.SubFolderName);

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

            return(Path.Combine(folderName, "I" + serviceInfo.ServiceName + ".cs"));
        }
Exemplo n.º 8
0
        private string GetServiceFileName(CloudServiceInfo serviceInfo)
        {
            string folderName = Path.Combine(_sourceFolder, "IFS.BusinessLayer", "CloudServices", serviceInfo.SubFolderName);

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

            return(Path.Combine(folderName, serviceInfo.ServiceName + ".cs"));
        }
Exemplo n.º 9
0
        private string GetServiceProxyFileName(CloudServiceInfo serviceInfo)
        {
            string folderName = Path.Combine(_sourceFolder, "IFS.CloudProxies", serviceInfo.SubFolderName);

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

            return(Path.Combine(folderName, serviceInfo.ServiceName + "Proxy.cs"));
        }
Exemplo n.º 10
0
 private void SafeLaunch(CloudServiceMethod method, CloudServiceInfo serviceInfo)
 {
     try
     {
         method(serviceInfo);
     }
     catch (Exception ex)
     {
         _logger.Error(ex.Message);
     }
 }
Exemplo n.º 11
0
        private void CreateInterface(CloudServiceInfo serviceInfo)
        {
            _logger.Info("... adding interface");
            string fileName = GetInterfaceFileName(serviceInfo);

            if (File.Exists(fileName))
            {
                throw new Exception("File " + fileName + " already exists");
            }
            File.WriteAllLines(fileName, CodeHelper.GetServiceCodeFromPattern("ICloudService", serviceInfo));
            CodeHelper.IncludeInProject(GetInterfacesProjectFileName(), @"CloudContracts\" + serviceInfo.SubFolderName + "I" + serviceInfo.ServiceName + ".cs");
        }
Exemplo n.º 12
0
        private void CreateServiceProxy(CloudServiceInfo serviceInfo)
        {
            _logger.Info("... adding ServiceProxy");
            string fileName = GetServiceProxyFileName(serviceInfo);

            if (File.Exists(fileName))
            {
                throw new Exception("File " + fileName + " already exists");
            }
            File.WriteAllLines(fileName, CodeHelper.GetServiceCodeFromPattern("CloudServiceProxy", serviceInfo));
            CodeHelper.IncludeInProject(GetCloudProxiesProjectFileName(), serviceInfo.SubFolderName + serviceInfo.ServiceName + "Proxy.cs");
        }
Exemplo n.º 13
0
        public static List <string> GetProxyMethod(IMethodData method, CloudServiceInfo serviceInfo)
        {
            string constName = method.MethodName.ConvertToConstName();

            return(new List <string>
            {
                String.Empty,
                "private const string " + constName + " = \"" + serviceInfo.ServiceName + "_" + method.MethodName + "\";",
                "public " + method.FullSignature,
                "{",
                "    return Execute<" + method.ReturnType + ">(" + method.ParametersWithoutTypes + ", " + constName + ");",
                "}"
            });
        }
Exemplo n.º 14
0
        public void AddClass(string serviceName)
        {
            var serviceInfo = new CloudServiceInfo(serviceName);

            if (string.IsNullOrEmpty(serviceInfo.ServiceName))
            {
                _logger.Error(serviceName + " : wrong format");
            }
            if (!serviceName.EndsWith("Service", false, CultureInfo.CurrentCulture))
            {
                _logger.Error(serviceName + " does not end with Service");
                return;
            }

            _logger.Info("Adding " + serviceName + "...");
            SafeLaunch(CreateService, serviceInfo);
            SafeLaunch(CreateServiceProxy, serviceInfo);
            SafeLaunch(CreateInterface, serviceInfo);
            SafeLaunch(ChangeConfigFiles, serviceInfo);
            _logger.Info("completed.");
        }
Exemplo n.º 15
0
        private void AddMethod(string serviceName, string methodSignature)
        {
            IMethodData method = new MethodParser(methodSignature);

            if (!method.IsValid)
            {
                _logger.Error("Method is not valid: " + methodSignature);
                return;
            }
            var serviceInfo = new CloudServiceInfo(serviceName);

            _logger.Info("Adding method " + method.MethodName + " to " + serviceName);
            _logger.Info("... interface");
            SafeLaunch(CodeHelper.AddMethodToClass, GetInterfaceFileName(serviceInfo), CodeHelper.GetInterfaceSignatureForMethod(method));
            _logger.Info("... service");
            SafeLaunch(CodeHelper.AddMethodToClass, GetServiceFileName(serviceInfo), CodeHelper.GetEmptyMethod(method));
            _logger.Info("... service proxy");
            SafeLaunch(CodeHelper.AddMethodToClass, GetServiceProxyFileName(serviceInfo), CodeHelper.GetProxyMethod(method, serviceInfo));
            _logger.Info("... process flow");
            SafeLaunch(r => r.AddProcessFlow(serviceInfo, method.MethodName));
            _logger.Info("completed.");
        }
Exemplo n.º 16
0
        private int AddProcessFlow(CloudServiceInfo serviceInfo, string methodName)
        {
            string folderName = Path.Combine(_sourceFolder, "IFS.BusinessLayer.Appistry", "Appistry", "ProcessFlows",
                                             serviceInfo.SubFolderName, serviceInfo.ServiceName);

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

            string        fileName = Path.Combine(folderName, methodName + ".xml");
            List <string> content  = CodeHelper.GetCodeFromPattern("ProcessFlow").Select(
                r => r.Replace(@"%SERVICE_NAME%", serviceInfo.ServiceName)
                .Replace(@"%METHOD_NAME%", methodName)).ToList();

            File.WriteAllLines(fileName, content);

            CodeHelper.IncludeInProject(GetAppistryProjectFileName(),
                                        Path.Combine("Appistry", "ProcessFlows", serviceInfo.SubFolderName, serviceInfo.ServiceName,
                                                     serviceInfo.ServiceName + "_" + methodName + ".xml"), false);
            return(0);
        }