Example #1
0
        /// <summary>
        /// Files the data structure error.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="folder">The folder.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="ex">The ex.</param>
        /// <param name="instance">The instance.</param>
        public static void FileDataStructureError(String message, folderNode folder, ILogBuilder logger, Exception ex, IFileDataStructure instance)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(message);
            sb.AppendLine(" -- -- -- --");
            if (ex != null)
            {
                sb.AppendLine("Exception [" + ex.GetType().Name + "] " + ex.Message);
                sb.AppendLine(ex.StackTrace);
            }
            sb.AppendLine(" -- -- -- --");
            if (instance != null)
            {
                sb.AppendLine("At instance [" + instance.GetType().Name + "] name: " + instance.name.toStringSafe());
            }
            else
            {
                sb.AppendLine("Instance is null");
            }
            sb.AppendLine(" -- -- -- --");
            sb.AppendLine(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString());

            if (config.imbSCICoreConfig.settings.DoShowFileDataStructureErrors)
            {
                if (logger == null)
                {
                    Console.WriteLine(sb.ToString());
                }
                else
                {
                    logger.log(sb.ToString());
                }
            }
            String path = "";

            if (config.imbSCICoreConfig.settings.DoSaveLogNoteForDataStructureErrors)
            {
                if (folder == null)
                {
                    folderNode fn = new DirectoryInfo("logs" + Path.DirectorySeparatorChar + "error");
                    folder = fn;
                }

                String filename = "filestructure_error_" + DateTime.Now.ToShortTimeString() + "_" + DateTime.Now.ToShortDateString() + "_" + imbStringGenerators.getRandomString(8);
                filename = filename.getFilename(".txt");

                path = folder.pathFor(filename, getWritableFileMode.autoRenameThis);
                File.WriteAllText(path, sb.ToString());
            }

            if (config.imbSCICoreConfig.settings.DoThrowExceptionOnDataStructureErrors)
            {
                sb.AppendLine("[the path supplied is path of error log file]");
                throw new imbFileException(sb.ToString(), ex, folder, path, instance);
            }
        }
        internal void deployDescriptor(IFileDataStructure dataStructure)
        {
            Type type = dataStructure.GetType();

            deployDescriptor(type, dataStructure);
        }
        private String GetFilenameAndSetInstanceFolder(IFileDataStructure instance, folderNode parentFolder = null, ILogBuilder output = null)
        {
            String filename = ""; // GetFilepath("", instance, false);

            try
            {
                switch (mode)
                {
                case fileStructureMode.subdirectory:
                    //parentFolder = Directory.CreateDirectory(parentFolder.path);
                    if (instance.folder == null)
                    {
                        instance.folder = parentFolder.Add(instance.name, instance.name, "Directory for [" + instance.GetType().Name + "]. " + instance.description);
                    }
                    else
                    {
                        if (instance.folder.name != instance.name)
                        {
                            instance.folder = parentFolder.Add(instance.name, instance.name, "Directory for [" + instance.GetType().Name + "]. " + instance.description);
                        }
                    }
                    filename = type.Name.getCleanPropertyName().add(formatMode.GetExtension(), ".");

                    break;

                case fileStructureMode.none:
                    fileDataStructureExtensions.FileDataStructureError("Can't have File Data Structure loaded if no file structure mode specified", parentFolder, output, null, instance);

                    //throw new NotImplementedException("Can't have File Data Structure loaded if no file structure mode specified");
                    break;
                }
            }
            catch (Exception ex)
            {
                fileDataStructureExtensions.FileDataStructureError("SaveDataStructure failed at designating folder and filename: " + ex.Message, parentFolder, output, ex, instance);
            }
            return(filename);
        }