예제 #1
0
        private static void GenerateNHibernateConfiguration(DataLayer ml)
        {
            ConfigurationPart cnfPart = ml.Configurations.Find(delegate(ConfigurationPart conf) { return(conf.Name == "ConnectionStrings"); });
            bool          isOracle    = cnfPart != null && cnfPart.XmlContent != null && cnfPart.XmlContent.ToLower().IndexOf("Oracle") > 0;
            StringBuilder cnf         = new StringBuilder();

            cnf.AppendLine(@"<configuration>");
            cnf.AppendLine(@"<configSections>");
            cnf.AppendLine(@"<section name=""hibernate-configuration"" type=""NHibernate.Cfg.ConfigurationSectionHandler, NHibernate""/>");
            cnf.AppendLine(@"</configSections>");
            cnf.AppendLine(@"<hibernate-configuration xmlns=""urn:nhibernate-configuration-2.0"">");
            cnf.AppendLine(@"<session-factory>");
            cnf.AppendLine(@"<property name=""connection.provider"">NHibernate.Connection.DriverConnectionProvider</property>");
            cnf.AppendLine(@"<property name=""connection.isolation"">ReadCommitted</property>");

            if (!isOracle)
            {
                cnf.AppendLine(@"<property name=""dialect"">NHibernate.Dialect.MsSql2000Dialect</property>");
                cnf.AppendLine(@"<property name=""connection.driver_class"">NHibernate.Driver.SqlClientDriver</property>");
            }
            else
            {
                cnf.AppendLine(@"<property name=""dialect"">NHibernate.Dialect.Oracle9Dialect</property>");
                cnf.AppendLine(@"<property name=""connection.driver_class"">NHibernate.Driver.OracleDataClientDriver</property>");
            }

            cnf.AppendLine(@"<!-- HBM Mapping Files -->");
            cnf.AppendLine(@"<mapping assembly=""" + ml.AssemblyName + @"""/>");
            cnf.AppendLine(@"</session-factory>");
            cnf.AppendLine(@"</hibernate-configuration></configuration>");

            ml.AddXmlConfigurationContent("nhibernateconfig", cnf.ToString());
        }
예제 #2
0
        public List<ApiResponse> Rejections(int id, out ApiRequest request, out ConfigurationPart part) {

            var context = _orchardServices.WorkContext.HttpContext;
            request = new ApiRequest(ApiRequestType.Configuration) { Stopwatch = _stopwatch };
            var response = new List<ApiResponse>();

            if (id == 0) {
                Logger.Error("No Configuration for id 0.  Requested by {1} at {2}.", context.User.Identity.IsAuthenticated ? context.User.Identity.Name : "Anonymous", context.Request.UserHostAddress);
                response.Add(NotFound(request));
                part = null;
                return response;
            }

            part = _orchardServices.ContentManager.Get(id).As<ConfigurationPart>();

            if (part == null) {
                Logger.Error("No Configuration for id {0}.  Requested by {1} at {2}.", id, context.User.Identity.IsAuthenticated ? context.User.Identity.Name : "Anonymous", context.Request.UserHostAddress);
                response.Add(NotFound(request));
                return response;
            }

            if (context.Request.IsLocal || part.IsInAllowedRange(context.Request.UserHostAddress)) {
                return response;
            }

            if (_orchardServices.Authorizer.Authorize(global::Orchard.Core.Contents.Permissions.ViewContent, part)) {
                return response;
            }

            Logger.Error("Not authorized to run {0}.  Requested by {1} at {2}.", part.As<TitlePart>().Title, context.User.Identity.Name, context.Request.UserHostAddress);
            response.Add(Unathorized(request));
            return response;
        }
 public void InitializeFiles(ConfigurationPart part, IDictionary<string, string> query) {
     _filesCreated.Clear();
     if (query.ContainsKey("InputFile") && part.RequiresInputFile() == true)
         InitializeFile(part, query, "InputFile");
     if (query.ContainsKey("OutputFile") && part.RequiresOutputFile() == true)
         InitializeFile(part, query, "OutputFile");
 }
예제 #4
0
        private void InitializeFile(ConfigurationPart part, IDictionary <string, string> query, string key)
        {
            FilePart filePart;
            int      id;

            var file = query[key] ?? "0";

            if (int.TryParse(file, out id))
            {
                if (id > 0)
                {
                    filePart = _fileService.Get(id) ?? CreateOutputFile(part);
                }
                else
                {
                    filePart = CreateOutputFile(part);
                }
            }
            else
            {
                if (file.IndexOfAny(Path.GetInvalidPathChars()) == -1 && _appDataFolder.FileExists(file))
                {
                    filePart = _fileService.Create(file);
                }
                else
                {
                    Logger.Error("File '{0}' passed into process is invalid!", file);
                    return;
                }
            }

            query[key] = filePart.FullPath;
        }
예제 #5
0
        private FilePart CreateOutputFile(ConfigurationPart part)
        {
            var prefix   = Slugify(part.As <TitlePart>().Title);
            var filePart = _fileService.Create(prefix, part.OutputFileExtension);

            _filesCreated.Add(filePart.Id);
            return(filePart);
        }
예제 #6
0
        /// <summary>
        /// Adds the content of the XML configuration.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="xmlContent">Content of the XML.</param>
        /// <param name="scope">The scope.</param>
        public void AddXmlConfigurationContent(string id, string xmlContent, Visibility scope)
        {
            if (xmlContent != null)
            {
                try
                {
                    XmlDocument xdoc = new XmlDocument();
                    xdoc.LoadXml(xmlContent);
                    if (xdoc.DocumentElement == null || xdoc.DocumentElement.LocalName != "configuration")
                    {
                        throw new ArgumentException("Invalid xml content. Root section must be 'configuration')");
                    }
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(String.Format("Invalid xml content for layer {0} id={1} ({2}) - Xml={3} ", this.Name, id, ex.Message, xmlContent));
                }
            }

            using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Add settings"))
            {
                foreach (ConfigurationPart cfg in this.Configurations)
                {
                    if (Utils.StringCompareEquals(cfg.Name, id))
                    {
                        if (cfg.XmlContent != xmlContent || cfg.Visibility != scope)
                        {
                            cfg.Visibility = scope;
                            if (xmlContent != null)
                            {
                                cfg.XmlContent = xmlContent;
                            }
                            else
                            {
                                this.Configurations.Remove(cfg);
                            }
                            transaction.Commit();
                        }
                        return;
                    }
                }

                if (xmlContent != null)
                {
                    ConfigurationPart cfgPart = new ConfigurationPart(this.Store);
                    cfgPart.XmlContent = xmlContent;
                    cfgPart.Name       = id;
                    cfgPart.Enabled    = true;
                    cfgPart.Visibility = scope;
                    this.Configurations.Add(cfgPart);
                    transaction.Commit();
                }
            }
        }
 public TransformalizeRequest(
     ConfigurationPart part,
     Dictionary<string, string> query,
     string modifiedConfiguration,
     ILogger logger,
     TflRoot root = null) {
         Part = part;
         Configuration = modifiedConfiguration ?? part.Configuration;
         Query = query ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
         Options = new Options { Mode = Query["mode"] };
         Root = root ?? new TflRoot(modifiedConfiguration ?? part.Configuration, Query, new CfgNetLogger(logger));
 }
예제 #8
0
 public void InitializeFiles(ConfigurationPart part, IDictionary <string, string> query)
 {
     _filesCreated.Clear();
     if (query.ContainsKey("InputFile") && part.RequiresInputFile() == true)
     {
         InitializeFile(part, query, "InputFile");
     }
     if (query.ContainsKey("OutputFile") && part.RequiresOutputFile() == true)
     {
         InitializeFile(part, query, "OutputFile");
     }
 }
예제 #9
0
        private void HandleInputFile(ConfigurationPart part, IDictionary <string, string> query)
        {
            if (Request.Files == null || Request.Files.Count <= 0 || part.RequiresInputFile() != true)
            {
                return;
            }

            var input = Request.Files.Get(0);

            if (input == null || input.ContentLength <= 0)
            {
                return;
            }

            var filePart = _fileService.Upload(input);

            query["InputFile"] = filePart.Id.ToString(CultureInfo.InvariantCulture);
        }
예제 #10
0
        public List <ApiResponse> Rejections(int id, out ApiRequest request, out ConfigurationPart part)
        {
            var context = _orchardServices.WorkContext.HttpContext;

            request = new ApiRequest(ApiRequestType.Configuration)
            {
                Stopwatch = _stopwatch
            };
            var response = new List <ApiResponse>();

            if (id == 0)
            {
                Logger.Error("No Configuration for id 0.  Requested by {1} at {2}.", context.User.Identity.IsAuthenticated ? context.User.Identity.Name : "Anonymous", context.Request.UserHostAddress);
                response.Add(NotFound(request));
                part = null;
                return(response);
            }

            part = _orchardServices.ContentManager.Get(id).As <ConfigurationPart>();

            if (part == null)
            {
                Logger.Error("No Configuration for id {0}.  Requested by {1} at {2}.", id, context.User.Identity.IsAuthenticated ? context.User.Identity.Name : "Anonymous", context.Request.UserHostAddress);
                response.Add(NotFound(request));
                return(response);
            }

            if (context.Request.IsLocal || part.IsInAllowedRange(context.Request.UserHostAddress))
            {
                return(response);
            }

            if (_orchardServices.Authorizer.Authorize(global::Orchard.Core.Contents.Permissions.ViewContent, part))
            {
                return(response);
            }

            Logger.Error("Not authorized to run {0}.  Requested by {1} at {2}.", part.As <TitlePart>().Title, context.User.Identity.Name, context.Request.UserHostAddress);
            response.Add(Unathorized(request));
            return(response);
        }
예제 #11
0
        /// <summary>
        /// Handles the Click event of the btnOK control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_currentComponent == null)
            {
                return;
            }

            using (
                Transaction transaction =
                    _currentComponent.Store.TransactionManager.BeginTransaction("Set configuration status"))
            {
                bool flag = false;
                foreach (Item item in _items)
                {
                    if (item.InitialEnabled != item.Enabled && !item.IsExternal)
                    {
                        AbstractLayer layer =
                            (AbstractLayer)_currentComponent.Store.ElementDirectory.FindElement(item.LayerId);
                        ConfigurationPart part =
                            layer.Configurations.Find(
                                delegate(ConfigurationPart cp) { return(cp.Name == item.ConfigName); });
                        if (part != null)
                        {
                            part.Visibility = item.Visibility;
                            part.Enabled    = item.Enabled;
                            flag            = true; // Il va falloir commiter
                        }
                    }
                }

                if (flag)
                {
                    transaction.Commit();
                }
            }
        }
예제 #12
0
        public void Save(ConfigurationPart configurationPart)
        {
            var tempFilePath  = this.GetConfigTempFilePath(configurationPart);
            var tempTokenPath = tempFilePath + tokenFileExt;

            using (var fileStream = File.OpenWrite(tempFilePath))
            {
                if (fileStream.Length > configurationPart.StartPosition)
                {
                    fileStream.SetLength(configurationPart.StartPosition);
                }

                fileStream.Seek(configurationPart.StartPosition, SeekOrigin.Begin);

                fileStream.Write(configurationPart.Stream, 0, configurationPart.Stream.Length);

                //configurationResponse.Stream.CopyTo(fileStream);
            }

            if (configurationPart.StartPosition == 0)
            {
                FileSystemHelper.WriteAllText(tempTokenPath, configurationPart.Token);
            }

            if (configurationPart.IsFinal)
            {
                var configPath      = this.GetConfigFilePath(configurationPart);
                var configTokenPath = configPath + tokenFileExt;
                var bakFile         = configPath + ".bak";
                var bakTokenFile    = configTokenPath + ".bak";

                if (File.Exists(configPath))
                {
                    FileSystemHelper.DeleteFile(bakFile);
                    FileSystemHelper.MoveFile(configPath, bakFile);
                }

                FileSystemHelper.DeleteFile(configPath);
                FileSystemHelper.MoveFile(tempFilePath, configPath);
                FileSystemHelper.DeleteFile(tempFilePath);

                if (File.Exists(configTokenPath))
                {
                    FileSystemHelper.DeleteFile(bakTokenFile);
                    FileSystemHelper.MoveFile(configTokenPath, bakTokenFile);
                }

                FileSystemHelper.DeleteFile(configTokenPath);
                FileSystemHelper.MoveFile(tempTokenPath, configTokenPath);
                FileSystemHelper.DeleteFile(tempTokenPath);

                // нотификации
                foreach (var subscriber in subscribers)
                {
                    if (subscriber.ProviderKey == configurationPart.ProviderKey)
                    {
                        try
                        {
                            subscriber.OnUpdate(() => File.OpenRead(configPath));
                        }
                        catch (Exception)
                        {
                            // TODO instrumentation
                            // ignore ?
                            //throw;
                        }
                    }
                }
            }
            else
            {
            }
        }
예제 #13
0
 private string GetConfigFilePath(ConfigurationPart configurationPart)
 {
     return(Path.Combine(this.configsDir, configurationPart.ProviderKey + configExt));
 }
        private void HandleInputFile(ConfigurationPart part, IDictionary<string, string> query) {
            if (Request.Files == null || Request.Files.Count <= 0 || part.RequiresInputFile() != true)
                return;

            var input = Request.Files.Get(0);

            if (input == null || input.ContentLength <= 0)
                return;

            var filePart = _fileService.Upload(input);
            query["InputFile"] = filePart.Id.ToString(CultureInfo.InvariantCulture);
        }
 private FilePart CreateOutputFile(ConfigurationPart part) {
     var prefix = Slugify(part.As<TitlePart>().Title);
     var filePart = _fileService.Create(prefix, part.OutputFileExtension);
     _filesCreated.Add(filePart.Id);
     return filePart;
 }
        private void InitializeFile(ConfigurationPart part, IDictionary<string, string> query, string key) {

            FilePart filePart;
            int id;

            var file = query[key] ?? "0";

            if (int.TryParse(file, out id)) {
                if (id > 0) {
                    filePart = _fileService.Get(id) ?? CreateOutputFile(part);
                } else {
                    filePart = CreateOutputFile(part);
                }
            } else {
                if (file.IndexOfAny(Path.GetInvalidPathChars()) == -1 && _appDataFolder.FileExists(file)) {
                    filePart = _fileService.Create(file);
                } else {
                    Logger.Error("File '{0}' passed into process is invalid!", file);
                    return;
                }
            }

            query[key] = filePart.FullPath;
        }