static CodeGenerationManager() { string assemblyTempPath = null; try { assemblyTempPath = PathUtil.Resolve(GlobalSettingsFacade.GeneratedAssembliesDirectory); } catch { // NOTE: We don't want this static constructor fail if GlobalSettingsFacade failed to load. } if (assemblyTempPath != null) { if (!C1Directory.Exists(assemblyTempPath)) { C1Directory.CreateDirectory(assemblyTempPath); } } GlobalEventSystemFacade.SubscribeToFlushEvent(args => Flush()); GlobalEventSystemFacade.SubscribeToShutDownEvent(args => ClearOldTempFiles()); }
private void SaveTypesCache(List <AssemblyInfo> cachedTypesInfo) { SubscribedTypesCache root = null; if (cachedTypesInfo.Count > 0) { root = new SubscribedTypesCache { Assemblies = cachedTypesInfo.ToArray() }; } try { if (root == null) { File.Delete(CacheFilePath); } else { if (!C1Directory.Exists(CacheDirectoryPath)) { C1Directory.CreateDirectory(CacheDirectoryPath); } using (var fileStream = File.Open(CacheFilePath, FileMode.Create)) { GetSerializer().Serialize(fileStream, root); } } } catch (Exception) { Log.LogWarning(LogTitle, $"Failed to open file '{CacheFilePath}' for writing - this may lead to slower start up times, if this issue persist. In that case, check that this file is accessible to the web application for writes."); } }
private void SaveTypesCache(List <AssemblyInfo> cachedTypesInfo) { SubscribedTypesCache root = null; if (cachedTypesInfo.Count > 0) { root = new SubscribedTypesCache { Assemblies = cachedTypesInfo.ToArray() }; } try { if (root == null) { File.Delete(CacheFilePath); } else { if (!C1Directory.Exists(CacheDirectoryPath)) { C1Directory.CreateDirectory(CacheDirectoryPath); } using (var fileStream = File.Open(CacheFilePath, FileMode.Create)) { GetSerializer().Serialize(fileStream, root); } } } catch (UnauthorizedAccessException) { Log.LogWarning(LogTitle, "Failed to open file '{0}'".FormatWith(CacheFilePath)); } }
private static void MoveRenderingLayoutToFormsFolder(string baseFolder) { var layoutsFolder = Path.Combine(baseFolder, "FormRenderingLayouts"); if (!C1Directory.Exists(layoutsFolder)) { return; } foreach (var file in C1Directory.GetFiles(layoutsFolder, "*.xml")) { var fileName = Path.GetFileNameWithoutExtension(file); if (fileName == null) { continue; } var folder = Path.Combine(baseFolder, fileName); if (!C1Directory.Exists(folder)) { C1Directory.CreateDirectory(folder); } var newFilePath = Path.Combine(folder, "RenderingLayout.xml"); File.Move(file, newFilePath); } C1Directory.Delete(layoutsFolder); }
/// <exclude /> public static string CreateTempDirectory() { string directory = Path.Combine(TempDirectoryPath, UrlUtils.CompressGuid(Guid.NewGuid())); C1Directory.CreateDirectory(directory); return(directory); }
/// <exclude /> public static void OnApplicationStart() { string tempDirectoryName = TempDirectoryPath; if (!C1Directory.Exists(tempDirectoryName)) { C1Directory.CreateDirectory(tempDirectoryName); } }
static ModelsFacade() { Providers = CompositionContainerFacade.GetExportedValues <IModelsProvider>().ToList(); if (!C1Directory.Exists(RootPath)) { C1Directory.CreateDirectory(RootPath); } }
/// <summary> /// Renders a url and return a full path to a rendered image, or <value>null</value> when rendering process is failing or inaccessible. /// </summary> public static async Task <RenderingResult> RenderUrlAsync(HttpContext context, string url, string mode) { string dropFolder = GetCacheFolder(mode); if (!C1Directory.Exists(dropFolder)) { C1Directory.CreateDirectory(dropFolder); } string urlHash = Convert.ToBase64String(BitConverter.GetBytes(url.GetHashCode())).Substring(0, 6).Replace('+', '-').Replace('/', '_'); string outputImageFileName = Path.Combine(dropFolder, urlHash + ".png"); string outputFileName = Path.Combine(dropFolder, urlHash + ".output"); string redirectLogFileName = Path.Combine(dropFolder, urlHash + ".redirect"); string errorFileName = Path.Combine(dropFolder, urlHash + ".error"); if (C1File.Exists(outputImageFileName) || C1File.Exists(outputFileName)) { #if BrowserRender_NoCache File.Delete(outputFileName); #else string[] output = C1File.Exists(outputFileName) ? C1File.ReadAllLines(outputFileName) : null; return(new RenderingResult { FilePath = outputImageFileName, Output = output, Status = RenderingResultStatus.Success }); #endif } if (!Enabled) { return(null); } var result = await MakePreviewRequestAsync(context, url, outputImageFileName, mode); if (result.Status >= RenderingResultStatus.Error) { C1File.WriteAllLines(errorFileName, result.Output); } if (!Enabled) { return(null); } if (result.Status == RenderingResultStatus.Success) { C1File.WriteAllLines(outputFileName, result.Output); } else if (result.Status == RenderingResultStatus.Redirect) { C1File.WriteAllLines(redirectLogFileName, result.Output); } return(result); }
private static void Init() { if (!C1Directory.Exists(ModelsFacade.RootPath)) { C1Directory.CreateDirectory(ModelsFacade.RootPath); } MoveRenderingLayoutToFormsFolder(ModelsFacade.RootPath); MoveSubfoldersToRoot(ModelsFacade.RootPath); }
public WorkflowFacadeImpl() { string serializedWorkflowsDirectory = PathUtil.Resolve(GlobalSettingsFacade.SerializedWorkflowsDirectory); string parentDirectory = Path.GetDirectoryName(serializedWorkflowsDirectory); string lockFileDirectory = Path.Combine(parentDirectory, "LockFiles"); if (!C1Directory.Exists(lockFileDirectory)) { C1Directory.CreateDirectory(lockFileDirectory); } }
public static DateTime GetLastCacheUpdateTime(string mode) { string folderPath = GetCacheFolder(mode); if (!C1Directory.Exists(folderPath)) { C1Directory.CreateDirectory(folderPath); } return(C1Directory.GetCreationTime(folderPath)); }
static LicenseDefinitionManager() { _packageLicenseDirectory = PathUtil.Resolve(GlobalSettingsFacade.PackageLicenseDirectory); if (!C1Directory.Exists(_packageLicenseDirectory)) { C1Directory.CreateDirectory(_packageLicenseDirectory); } _maximumProductNameLength = 255 - (GlobalSettingsFacade.MaximumRootPathLength + (GlobalSettingsFacade.PackageLicenseDirectory.Length - 1) + LicenseFileExtension.Length); }
static DataMetaDataFacade() { GlobalEventSystemFacade.SubscribeToFlushEvent(args => Flush()); _metaDataPath = PathUtil.Resolve(GlobalSettingsFacade.DataMetaDataDirectory); if (!C1Directory.Exists(_metaDataPath)) { C1Directory.CreateDirectory(_metaDataPath); } UpdateFilenames(); }
public FileLogger(string logDirectoryPath, bool flushImmediately) { Verify.ArgumentNotNull(logDirectoryPath, "logDirectoryPath"); _logDirectoryPath = Path.Combine(PathUtil.BaseDirectory, logDirectoryPath); if (!C1Directory.Exists(_logDirectoryPath)) { C1Directory.CreateDirectory(_logDirectoryPath); } _flushImmediately = flushImmediately; TouchLockFile(); }
/// <exclude /> public static void SetFunctinoCode(this IInlineFunction function, string content) { string directoryPath = PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory); if (C1Directory.Exists(directoryPath) == false) { C1Directory.CreateDirectory(directoryPath); } string filepath = Path.Combine(directoryPath, function.CodePath); C1File.WriteAllText(filepath, content); }
private static void CreateDirectoryIfNotExists(string path) { if (!C1Directory.Exists(path)) { lock (SyncRoot) { if (!C1Directory.Exists(path)) { C1Directory.CreateDirectory(path); } } } }
/// <summary> /// This method is used to record the very first time the system is started. /// Ths time can later be used to several things like finding files that have been written to etc. /// </summary> public static void SetFirstTimeStart() { if (!C1File.Exists(FirstTimeStartFilePath)) { string directory = Path.GetDirectoryName(FirstTimeStartFilePath); if (!C1Directory.Exists(directory)) { C1Directory.CreateDirectory(directory); } var doc = new XDocument(new XElement("Root", new XAttribute("time", DateTime.Now))); doc.SaveToFile(FirstTimeStartFilePath); } }
public ConsoleMessageQueue(int secondsForItemToLive) { string directory = PathUtil.Resolve(GlobalSettingsFacade.SerializedConsoleMessagesDirectory); if (!C1Directory.Exists(directory)) { C1Directory.CreateDirectory(directory); } MessageQueueFilePath = Path.Combine(directory, MessageQueueFileName); _timeInterval = new TimeSpan(0, 0, secondsForItemToLive); DeserializeMessagesFromFileSystem(); _timer = new Timer(OnWeed, null, new TimeSpan(0, 0, 0), _timeInterval); }
private void IfFeatureNameFree(object sender, System.Workflow.Activities.ConditionalEventArgs e) { string name = this.GetBinding <string>("Name"); if (name.Length > 50) { e.Result = false; this.ShowFieldMessage("Name", StringResourceSystemFacade.GetString("Composite.Plugins.PageTemplateFeatureElementProvider", "AddWorkflow.NameTooLong")); return; } if (!C1Directory.Exists(PathUtil.Resolve(GlobalSettingsFacade.PageTemplateFeaturesDirectory))) { try { C1Directory.CreateDirectory(PathUtil.Resolve(GlobalSettingsFacade.PageTemplateFeaturesDirectory)); } catch (Exception) { e.Result = false; this.ShowFieldMessage("Name", string.Format("Can not create directory '{0}'", GlobalSettingsFacade.PageTemplateFeaturesDirectory)); } } string xmlFilename = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PageTemplateFeaturesDirectory), name + ".xml"); string htmlFilename = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PageTemplateFeaturesDirectory), name + ".html"); e.Result = !C1File.Exists(xmlFilename) && !C1File.Exists(htmlFilename); if (!e.Result) { this.ShowFieldMessage("Name", StringResourceSystemFacade.GetString("Composite.Plugins.PageTemplateFeatureElementProvider", "AddWorkflow.NameInUse")); return; } try { C1File.WriteAllText(xmlFilename, "tmp"); C1File.Delete(xmlFilename); } catch (Exception) { e.Result = false; this.ShowFieldMessage("Name", StringResourceSystemFacade.GetString("Composite.Plugins.PageTemplateFeatureElementProvider", "AddWorkflow.NameNotValidInFilename")); } }
public FileLogger(string logDirectoryPath, bool flushImmediately) { Verify.ArgumentNotNull(logDirectoryPath, "logDirectoryPath"); _logDirectoryPath = Path.Combine(PathUtil.BaseDirectory, logDirectoryPath); if (!C1Directory.Exists(_logDirectoryPath)) { C1Directory.CreateDirectory(_logDirectoryPath); } _flushImmediately = flushImmediately; _flushOnIdleTask = Task.Factory.StartNew(FlushOnIdle); #if UseLockFiles TouchLockFile(); #endif }
internal MediaFileProvider(string rootDirectory, string storeId, string storeDescription, string storeTitle) { _workingDirectory = PathUtil.Resolve(rootDirectory); if (!C1Directory.Exists(_workingDirectory)) { C1Directory.CreateDirectory(_workingDirectory); } _storeId = storeId; _storeTitle = storeTitle; _storeDescription = storeDescription; DataEventSystemFacade.SubscribeToStoreChanged <IMediaFileData>(ClearQueryCache, false); DataEventSystemFacade.SubscribeToStoreChanged <IMediaFolderData>(ClearQueryCache, false); _mediaUrlProvider = new DefaultMediaUrlProvider(storeId); MediaUrls.RegisterMediaUrlProvider(storeId, _mediaUrlProvider); }
private static XElement GetPredefinedResizingOptions() { XElement xel = HttpRuntime.Cache.Get("ResizedImageKeys") as XElement; //If it's not there, load the xml document and then add it to the cache if (xel == null) { if (_resizedImageKeysFilePath == null) { _resizedImageKeysFilePath = PathUtil.Resolve(ResizedImageKeys); } if (!C1File.Exists(_resizedImageKeysFilePath)) { string directoryPath = Path.GetDirectoryName(_resizedImageKeysFilePath); if (!C1Directory.Exists(directoryPath)) { C1Directory.CreateDirectory(directoryPath); } var config = new XElement("ResizedImages", new XElement("image", new XAttribute("name", "thumbnail"), new XAttribute("maxwidth", "100"), new XAttribute("maxheight", "100")), new XElement("image", new XAttribute("name", "normal"), new XAttribute("maxwidth", "200")), new XElement("image", new XAttribute("name", "large"), new XAttribute("maxheight", "300")) ); config.SaveToPath(_resizedImageKeysFilePath); } xel = XElementUtils.Load(_resizedImageKeysFilePath); var cd = new CacheDependency(_resizedImageKeysFilePath); var cacheExpirationTimeSpan = new TimeSpan(24, 0, 0); HttpRuntime.Cache.Add("ResizedImageKeys", xel, cd, Cache.NoAbsoluteExpiration, cacheExpirationTimeSpan, CacheItemPriority.Default, null); } return(xel); }
private void finalizecodeActivity_ExecuteCode(object sender, EventArgs e) { var provider = GetFunctionProvider <RazorFunctionProvider>(); string functionName = this.GetBinding <string>(Binding_Name); string functionNamespace = ChangeNamespaceAccordingToExistingFolders(provider, this.GetBinding <string>(Binding_Namespace)); string functionFullName = functionNamespace + "." + functionName; AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken); string fileName = functionName + ".cshtml"; string folder = Path.Combine(provider.PhysicalPath, functionNamespace.Replace('.', '\\')); string cshtmlFilePath = Path.Combine(folder, fileName); string code; string copyFromFunction = this.GetBinding <string>(Binding_CopyFromFunctionName); if (string.IsNullOrEmpty(copyFromFunction)) { code = NewRazorFunction_CSHTML; } else { code = GetFunctionCode(copyFromFunction); } C1Directory.CreateDirectory(folder); C1File.WriteAllText(cshtmlFilePath, code); UserSettings.LastSpecifiedNamespace = functionNamespace; provider.ReloadFunctions(); var newFunctionEntityToken = new FileBasedFunctionEntityToken(provider.Name, functionFullName); addNewTreeRefresher.PostRefreshMesseges(newFunctionEntityToken); var container = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); var executionService = container.GetService <IActionExecutionService>(); executionService.Execute(newFunctionEntityToken, new WorkflowActionToken(typeof(EditRazorFunctionWorkflow)), null); }
internal static void CreateStore(string providerName, DataScopeConfigurationElement scopeElement) { string filename = ResolvePath(scopeElement.Filename, providerName); string directoryPath = Path.GetDirectoryName(filename); if (!C1Directory.Exists(directoryPath)) { C1Directory.CreateDirectory(directoryPath); } bool keepExistingFile = false; string rootLocalName = XmlDataProviderDocumentWriter.GetRootElementName(scopeElement.ElementName); string obsoleteRootElementName = scopeElement.ElementName + "s"; if (C1File.Exists(filename)) { try { XDocument existingDocument = XDocumentUtils.Load(filename); if (existingDocument.Root.Name.LocalName == rootLocalName || existingDocument.Root.Name.LocalName == obsoleteRootElementName) { keepExistingFile = true; } } catch (Exception) { keepExistingFile = false; } if (!keepExistingFile) { C1File.Delete(filename); } } if (!keepExistingFile) { var document = new XDocument(); document.Add(new XElement(rootLocalName)); XDocumentUtils.Save(document, filename); } }
private static void InitializeNewFile(string filepath) { _installationId = Guid.NewGuid(); string directory = Path.GetDirectoryName(filepath); if (C1Directory.Exists(directory) == false) { C1Directory.CreateDirectory(directory); } XDocument doc = new XDocument( new XElement("InstallationInformation", new XAttribute("installationId", _installationId) ) ); doc.SaveToFile(filepath); }
private void finalizecodeActivity_ExecuteCode(object sender, EventArgs e) { string functionName = this.GetBinding <string>(Binding_Name); string functionNamespace = this.GetBinding <string>(Binding_Namespace); string copyFromFunctionName = this.GetBinding <string>(Binding_CopyFromFunctionName); string functionFullName = functionNamespace + "." + functionName; var provider = GetFunctionProvider <UserControlFunctionProvider>(); AddNewTreeRefresher addNewTreeRefresher = this.CreateAddNewTreeRefresher(this.EntityToken); string fileName = functionName + ".ascx"; string folder = Path.Combine(provider.PhysicalPath, functionNamespace.Replace('.', '\\')); string markupFilePath = Path.Combine(folder, fileName); string codeFilePath = markupFilePath + ".cs"; string markupTemplate = NewUserControl_Markup; string code = NewUserControl_CodeFile; if (!copyFromFunctionName.IsNullOrEmpty()) { GetFunctionCode(copyFromFunctionName, out markupTemplate, out code); } C1Directory.CreateDirectory(folder); C1File.WriteAllText(codeFilePath, code); C1File.WriteAllText(markupFilePath, markupTemplate.Replace(Marker_CodeFile, functionName + ".ascx.cs")); UserSettings.LastSpecifiedNamespace = functionNamespace; provider.ReloadFunctions(); var newFunctionEntityToken = new FileBasedFunctionEntityToken(provider.Name, functionFullName); addNewTreeRefresher.PostRefreshMesseges(newFunctionEntityToken); var container = WorkflowFacade.GetFlowControllerServicesContainer(WorkflowEnvironment.WorkflowInstanceId); var executionService = container.GetService <IActionExecutionService>(); executionService.Execute(newFunctionEntityToken, new WorkflowActionToken(typeof(EditUserControlFunctionWorkflow)), null); }
/// <summary> /// Initializes a new instance of the <see cref="FileRelatedDataCache{T}" /> class. /// </summary> /// <param name="cacheDirectoryName">Name of the folder to which cached files will be put.</param> /// <param name="cacheName">Name of the cache, used in the naming of cached files.</param> /// <param name="toFileSerializer">To file serializer.</param> /// <param name="fromFileDeserializer">From file deserializer.</param> public FileRelatedDataCache(string cacheDirectoryName, string cacheName, Action <CachedData, string> toFileSerializer, Func <string, CachedData> fromFileDeserializer) { _cacheName = cacheName; _serializer = toFileSerializer; _deserializer = fromFileDeserializer; string path = PathUtil.Resolve(GlobalSettingsFacade.CacheDirectory); if (!string.IsNullOrEmpty(cacheDirectoryName)) { path = Path.Combine(path, cacheDirectoryName); } _cachefolder = path; if (!C1Directory.Exists(_cachefolder)) { C1Directory.CreateDirectory(_cachefolder); } }
private void finalizeCodeActivity_ExecuteCode(object sender, EventArgs e) { string currentPath = GetCurrentPath(); string newFolderName = this.GetBinding <string>("NewFolderName"); string newFolderPath = Path.Combine(currentPath, newFolderName); C1Directory.CreateDirectory(newFolderPath); SpecificTreeRefresher specificTreeRefresher = this.CreateSpecificTreeRefresher(); specificTreeRefresher.PostRefreshMesseges(this.EntityToken); if (this.EntityToken is WebsiteFileElementProviderEntityToken) { WebsiteFileElementProviderEntityToken folderToken = (WebsiteFileElementProviderEntityToken)this.EntityToken; var newFileToken = new WebsiteFileElementProviderEntityToken(folderToken.ProviderName, newFolderPath, folderToken.RootPath); SelectElement(newFileToken); } }
public List <T> AddNew <T>(IEnumerable <T> datas) where T : class, IData { List <T> result = new List <T>(); foreach (IData data in datas) { if (data == null) { throw new ArgumentException("Data in list to add must be non-null"); } CheckInterface(typeof(T)); } foreach (IData data in datas) { if (typeof(T) == typeof(IMediaFile)) { IMediaFile file = (IMediaFile)data; string fullPath = Path.Combine(Path.Combine(_rootDir, file.FolderPath.Remove(0, 1)), file.FileName); using (Stream readStream = file.GetReadStream()) { using (Stream writeStream = C1File.Open(fullPath, FileMode.CreateNew)) { readStream.CopyTo(writeStream); } } result.Add(CreateFile(fullPath) as T); } else if (typeof(T) == typeof(IMediaFileFolder)) { IMediaFileFolder folder = (IMediaFileFolder)data; string fullPath = Path.Combine(_rootDir, folder.Path.Remove(0, 1)); C1Directory.CreateDirectory(fullPath); result.Add(CreateFolder(fullPath) as T); } } return(result); }
private static PackageFragmentValidationResult SaveZipFile(Stream zipFileStream, out string zipFilename) { zipFilename = null; try { zipFilename = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.PackageDirectory), PackageSystemSettings.ZipFilename); if (C1File.Exists(zipFilename)) { C1File.Delete(zipFilename); } if (C1Directory.Exists(Path.GetDirectoryName(zipFilename)) == false) { C1Directory.CreateDirectory(Path.GetDirectoryName(zipFilename)); } using (Stream readStream = zipFileStream) { using (C1FileStream fileStream = new C1FileStream(zipFilename, FileMode.Create)) { byte[] buffer = new byte[4096]; int readBytes; while ((readBytes = readStream.Read(buffer, 0, 4096)) > 0) { fileStream.Write(buffer, 0, readBytes); } } } return(null); } catch (Exception ex) { return(new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex)); } }