private void DeleteOldWorkflows()
        {
            using (GlobalInitializerFacade.CoreIsInitializedScope)
            {
                foreach (string filename in C1Directory.GetFiles(SerializedWorkflowsDirectory))
                {
                    DateTime creationTime = C1File.GetLastWriteTime(filename);

                    if (DateTime.Now.Subtract(creationTime) > OldFileExistenceTimeout)
                    {
                        Guid instanceId = new Guid(Path.GetFileNameWithoutExtension(filename));

                        if (Path.GetExtension(filename) == "bin")
                        {
                            try
                            {
                                WorkflowRuntime.GetWorkflow(instanceId);
                                AbortWorkflow(instanceId);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        C1File.Delete(filename);

                        Log.LogVerbose(LogTitle, $"Old workflow instance file deleted {filename}");
                    }
                }
            }
        }
예제 #2
0
        protected override Activity LoadWorkflowInstanceState(Guid instanceId)
        {
            string filename   = GetFileName(instanceId);
            bool   deleteFile = false;

            if (C1File.Exists(filename))
            {
                try
                {
                    object obj = DeserializeActivity(null, instanceId);
                    return((Activity)obj);
                }
                catch (Exception ex)
                {
                    LoggingService.LogCritical(LogTitle, ex);
                    deleteFile = true;
                }
            }

            if (deleteFile)
            {
                Log.LogWarning(LogTitle, $"Failed to load workflow with id '{filename}'. Deleting file.");
                C1File.Delete(filename);

                MarkWorkflowAsAborted(instanceId);
            }

            return(null);
        }
        public void Delete(IEnumerable <DataSourceId> dataSourceIds)
        {
            foreach (DataSourceId dataSourceId in dataSourceIds)
            {
                if (dataSourceId == null)
                {
                    throw new ArgumentException("DataSourceIds must me non-null");
                }
            }

            foreach (DataSourceId dataSourceId in dataSourceIds)
            {
                MediaDataId dataId = dataSourceId.DataId as MediaDataId;

                if (dataId.MediaType == _fileType)
                {
                    if (IsReadOnlyFolder(dataId.Path))
                    {
                        throw new ArgumentException("Cannot delete read only file " + dataId.FileName);
                    }
                    C1File.Delete(GetAbsolutePath(dataId));
                }
                else
                {
                    if (IsReadOnlyFolder(dataId.Path))
                    {
                        throw new ArgumentException("Cannot delete read only folder " + dataId.Path);
                    }
                    C1Directory.Delete(GetAbsolutePath(dataId), true);
                }
            }
        }
예제 #4
0
        public override IEnumerable <XElement> Install()
        {
            if (_files == null && _directories == null)
            {
                throw new InvalidOperationException(GetType().Name + " has not been validated");
            }

            if (_files != null)
            {
                foreach (var file in _files)
                {
                    C1File.Delete(file);
                }
            }

            if (_directories != null)
            {
                foreach (var directory in _directories)
                {
                    C1Directory.Delete(directory, true);
                }
            }

            return(Configuration);
        }
예제 #5
0
        //public static string AttributeValue(this XElement element, XName attributeName)
        //{
        //    return element.Attributes(attributeName).Select(d => d.Value).FirstOrDefault();
        //}

        //public static string ElementValue(this XElement element, XName elementName)
        //{
        //    return element.Elements(elementName).Select(d => d.Value).FirstOrDefault();
        //}

        //public static IEnumerable<T> NotNull<T>(this IEnumerable<T> source)
        //{
        //    return source.Where(d => d != null);
        //}

        public static void DeleteActivity(this DataConnection conn, Guid activityId, DataSourceId dataSourceId)
        {
            try
            {
                var activity = conn.Get <IActivity>().Where(d => d.Id == activityId).FirstOrDefault();

                var activityChanges = conn.Get <IDataChanges>().Where(d => d.ActivityId == activityId).ToList();

                if (dataSourceId != null)
                {
                    if (dataSourceId.InterfaceType == typeof(IMediaFile))
                    {
                        try
                        {
                            var mediaFileId           = dataSourceId.DataId.GetProperty <Guid>("Id");
                            var mediaFileActivityPath = CleanerFacade.GetMediaFileActivityPath(mediaFileId, activityId);
                            C1File.Delete(mediaFileActivityPath);
                        }
                        catch (Exception e)
                        {
                            Log.LogWarning(CleanerFacade.Title, e);
                        }
                    }
                }

                conn.Delete <IDataChanges>(activityChanges);
                conn.Delete(activity);

                Log.LogVerbose(CleanerFacade.Title, "Delete activity '{0}'".Push(activityId));
            }
            catch
            { }
        }
 private static void DeleteTempConfigurationFile(string tempValidationFilePath)
 {
     try
     {
         //                FileConfigurationSource.ResetImplementation(tempValidationFilePath, false); //turn file monitoring off
         C1File.Delete(tempValidationFilePath);
     }
     catch (Exception) { }
 }
예제 #7
0
        internal static void DropStore(string providerName, DataScopeConfigurationElement scopeElement)
        {
            string filename = ResolvePath(scopeElement.Filename, providerName);

            if (C1File.Exists(filename))
            {
                C1File.Delete(filename);
            }
        }
        private void DeleteMediaFile(Guid id)
        {
            string fullPath = Path.Combine(_workingDirectory, id.ToString());

            if (C1File.Exists(fullPath))
            {
                C1File.Delete(fullPath);
            }

            DataFacade.Delete <IMediaFileData>(x => x.Id == id);
        }
예제 #9
0
        public void Delete(IEnumerable <DataSourceId> dataSourceIds)
        {
            foreach (DataSourceId dataSourceId in dataSourceIds)
            {
                FileSystemFileDataId dataId = (FileSystemFileDataId)dataSourceId.DataId;

                FileSystemFileStreamManager.DeleteFile(dataId.FullPath);

                C1File.Delete(dataId.FullPath);
            }
        }
예제 #10
0
        private void DeleteMediaFile(Guid id)
        {
            string fullPath = GetFilePath(id);

            if (C1File.Exists(fullPath))
            {
                C1File.Delete(fullPath);
            }

            DataFacade.Delete <IMediaFileData>(x => x.Id == id);
        }
        /// <exclude />
        public void CancelInstallation()
        {
            if (_zipFilename != null && C1File.Exists(_zipFilename))
            {
                C1File.Delete(_zipFilename);
            }

            if (C1Directory.Exists(_packageInstallDirectory))
            {
                C1Directory.Delete(_packageInstallDirectory, true);
            }
        }
        public static void GenerateFunctionBoxWithPreview(
            HttpContext context,
            string functionTitle,
            Bitmap previewImage,
            bool showEditButton,
            Stream outputStream)
        {
            using (var header = new FunctionHeader(functionTitle, false, showEditButton))
            {
                var headerSize = header.HeaderSize;

                Size totalSize = new Size(Math.Max(header.HeaderSize.Width, previewImage.Width), headerSize.Height + previewImage.Height);

                using (var bitmap = new Bitmap(totalSize.Width, totalSize.Height))
                    using (var graphics = Graphics.FromImage(bitmap))
                    {
                        header.DrawHeader(bitmap, graphics, totalSize.Width);

                        Point previewImageOffset = new Point(
                            (Math.Max(totalSize.Width - 10, previewImage.Width) - previewImage.Width) / 2, headerSize.Height);

                        // Preview image
                        graphics.DrawImage(previewImage, previewImageOffset);

                        // Image outline
                        using (var brush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.FromArgb(190, 190, 190), Color.Transparent))
                            using (var pen = new Pen(brush))
                            {
                                graphics.DrawRectangle(pen, new Rectangle(previewImageOffset,
                                                                          new Size(previewImage.Width - 1, previewImage.Height - 1)));
                            }

                        context.Response.ContentType = "image/png";
                        context.Response.Cache.SetExpires(DateTime.Now.AddDays(10));

                        string tempFileName = Path.GetTempFileName();

                        try
                        {
                            // Saving to a temporary file, as Image.Save() sometimes on a not seekable stream throws
                            // an "A generic error occurred in GDI+." exception
                            bitmap.Save(tempFileName, ImageFormat.Png);

                            context.Response.WriteFile(tempFileName);
                            context.Response.Flush();
                        }
                        finally
                        {
                            C1File.Delete(tempFileName);
                        }
                    }
            }
        }
예제 #13
0
        private void DeleteMediaFiles(IList <IMediaFileData> mediaFiles)
        {
            foreach (var mediaFile in mediaFiles)
            {
                string fullPath = GetFilePath(mediaFile.Id);
                if (C1File.Exists(fullPath))
                {
                    C1File.Delete(fullPath);
                }
            }

            DataFacade.Delete <IMediaFileData>(mediaFiles);
        }
        private void DeletePersistedFormData(Guid instanceId)
        {
            using (GlobalInitializerFacade.CoreIsInitializedScope)
            {
                string filename = GetFormDataFileName(instanceId);

                if (C1File.Exists(filename))
                {
                    C1File.Delete(filename);

                    Log.LogVerbose(LogTitle, $"Persisted FormData deleted for workflow id = {instanceId}");
                }
            }
        }
예제 #15
0
        private static void ClearCacheInt(string folder)
        {
            foreach (var file in C1Directory.GetFiles(folder, "*.*"))
            {
                try
                {
                    C1File.Delete(file);
                }
                catch
                {
                }
            }

            C1Directory.SetCreationTime(folder, DateTime.Now);
        }
        static CaptchaConfiguration()
        {
            string configurationFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CaptchaConfigurationFilePath);

            string password = null;

            if (C1File.Exists(configurationFilePath))
            {
                var doc = new XmlDocument();
                try
                {
                    using (var sr = new C1StreamReader(configurationFilePath))
                    {
                        doc.Load(sr);
                    }

                    var passwordNode = doc.SelectSingleNode("captcha/password");
                    if (!string.IsNullOrEmpty(passwordNode?.InnerText))
                    {
                        password = passwordNode.InnerText;
                    }
                }
                catch (Exception)
                {
                    // Do nothing
                }

                if (password != null)
                {
                    Password = password;
                    return;
                }

                // Deleting configuration file
                C1File.Delete(configurationFilePath);
            }


            password = Guid.NewGuid().ToString();

            string configFile = @"<captcha> <password>{0}</password> </captcha>".FormatWith(password);

            C1File.WriteAllText(configurationFilePath, configFile);

            Password = password;
        }
        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"));
            }
        }
        private static void ClearOldTempFiles()
        {
            DateTime yesterday = DateTime.Now.AddDays(-1);
            var      oldFiles  = C1Directory.GetFiles(TempAssemblyFolderPath, "*.*").Where(filePath => C1File.GetCreationTime(filePath) < yesterday).ToArray();

            foreach (var file in oldFiles)
            {
                try
                {
                    C1File.Delete(file);
                }
                catch
                {
                    // Silent
                }
            }
        }
예제 #19
0
        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 void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            var functionEntityToken = (FileBasedFunctionEntityToken)EntityToken;

            FileBasedFunctionProvider <RazorBasedFunction> provider;
            FileBasedFunction <RazorBasedFunction>         function;

            GetProviderAndFunction(functionEntityToken, out provider, out function);

            string cshtmlFilePath = PathUtil.Resolve(function.VirtualPath);

            C1File.Delete(cshtmlFilePath);

            DeleteEmptyAncestorFolders(cshtmlFilePath);

            provider.ReloadFunctions();

            RefreshFunctionTree();
        }
        private ICollection <PackageFragmentValidationResult> FinalizeProcess(bool install)
        {
            try
            {
                if (_zipFilename != null && C1File.Exists(_zipFilename))
                {
                    C1File.Delete(_zipFilename);
                }

                Func <IList <PackageFragmentValidationResult>, bool> isNotEmpty = list => list != null && list.Count > 0;

                bool installationFailed = isNotEmpty(_preInstallValidationResult) ||
                                          isNotEmpty(_validationResult) ||
                                          isNotEmpty(_installationResult);

                if (installationFailed && C1Directory.Exists(_packageInstallDirectory))
                {
                    C1Directory.Delete(_packageInstallDirectory, true);
                }

                if (!installationFailed && install)
                {
                    Log.LogInformation(LogTitle, "Package successfully installed");

                    C1File.WriteAllText(Path.Combine(_packageInstallDirectory, PackageSystemSettings.InstalledFilename), "");

                    // Moving package files to a proper location, if an newer version of an already installed package is installed
                    if (_originalPackageInstallDirectory != null)
                    {
                        C1Directory.Delete(_originalPackageInstallDirectory, true);

                        C1Directory.Move(_packageInstallDirectory, _originalPackageInstallDirectory);
                    }
                }

                return(new PackageFragmentValidationResult[0]);
            }
            catch (Exception ex)
            {
                return(new [] { new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex) });
            }
        }
예제 #22
0
        private void DeleteFile(IFile file)
        {
            FileSystemFileBase baseFile = file as FileSystemFileBase;

            if (baseFile == null)
            {
                return;
            }

            string filePath = baseFile.SystemPath;

            try
            {
                C1File.Delete(filePath);
            }
            catch
            {
                LoggingService.LogWarning(typeof(DeleteXsltFunctionWorkflow).Name, "Failed to delete file '{0}'".FormatWith(filePath));
            }
        }
예제 #23
0
            public void DeleteTemplate()
            {
                try
                {
                    C1File.Delete(_templateDescriptor.FilePath);
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Failed to delete file " + _templateDescriptor.FilePath);
                }

                try
                {
                    C1File.Delete(_templateDescriptor.CodeBehindFilePath);
                }
                catch (Exception)
                {
                    throw new InvalidOperationException("Failed to delete file " + _templateDescriptor.CodeBehindFilePath);
                }
            }
예제 #24
0
        public bool RemovePersistedWorkflow(Guid instanceId)
        {
            string filename = GetFileName(instanceId);

            if (C1File.Exists(filename))
            {
                try
                {
                    C1File.Delete(filename);

                    Log.LogVerbose(LogTitle, $"Workflow persisted state deleted. Id = {instanceId}");
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
        public bool RemovePersistedWorkflow(Guid instanceId)
        {
            string filename = GetFileName(instanceId);

            if (C1File.Exists(filename))
            {
                try
                {
                    C1File.Delete(filename);

                    LoggingService.LogVerbose("FileWorkFlowPersisetenceService", string.Format("Workflow persisted state deleted. Id = {0}", instanceId));
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #26
0
            public void DeleteTemplate()
            {
                IFile file = IFileServices.GetFile <IPageTemplateFile>(_pageTemplate.PageTemplateFilePath);

                ProcessControllerFacade.FullDelete(_pageTemplate);

                if (file != null && file is FileSystemFileBase)
                {
                    FileSystemFileBase baseFile = file as FileSystemFileBase;
                    C1File.Delete(baseFile.SystemPath);

                    try
                    {
                        C1File.Delete(baseFile.SystemPath);
                    }
                    catch
                    {
                        LoggingService.LogWarning(LogTitle, "Failed to delete page template file: '{0}'".FormatWith(baseFile.SystemPath));
                    }
                }
            }
예제 #27
0
        private void deleteCodeActivity_ExecuteCode(object sender, EventArgs e)
        {
            DeleteTreeRefresher treeRefresher = this.CreateDeleteTreeRefresher(this.EntityToken);

            WebsiteFileElementProviderEntityToken entityToken = (WebsiteFileElementProviderEntityToken)this.EntityToken;

            try
            {
                C1File.Delete(entityToken.Path);

                treeRefresher.PostRefreshMesseges();
            }
            catch (Exception)
            {
                this.ShowMessage(
                    DialogType.Error,
                    StringResourceSystemFacade.GetString("Composite.Plugins.WebsiteFileElementProvider", "DeleteWebsiteFileWorkflow.DeleteErrorTitle"),
                    StringResourceSystemFacade.GetString("Composite.Plugins.WebsiteFileElementProvider", "DeleteWebsiteFileWorkflow.DeleteErrorMessage")
                    );
            }
        }
예제 #28
0
        public void Update(IEnumerable <IData> datas)
        {
            foreach (IData data in datas)
            {
                CheckInterface(data.GetType());

                FileSystemFileDataId id = (FileSystemFileDataId)data.DataSourceId.DataId;
                string oldPath          = id.FullPath;

                FileSystemFile file = (FileSystemFile)data;

                file.SystemPath = CreateSystemPath(file.Path);

                FileSystemFileStreamManager.WriteFileToDisk(file);

                if (file.SystemPath != oldPath)
                {
                    C1File.Delete(oldPath);
                }
            }
        }
예제 #29
0
        /// <exclude />
        public static void OnApplicationEnd()
        {
            // Deleting everything that is older than 24 hours
            string tempDirectoryName = TempDirectoryPath;

            if (!C1Directory.Exists(tempDirectoryName))
            {
                return;
            }



            foreach (string filename in C1Directory.GetFiles(tempDirectoryName))
            {
                try
                {
                    if (DateTime.Now > C1File.GetLastWriteTime(filename) + TemporaryFileExpirationTimeSpan)
                    {
                        C1File.Delete(filename);
                    }
                }
                catch
                {
                }
            }

            foreach (string directoryPath in C1Directory.GetDirectories(tempDirectoryName))
            {
                try
                {
                    if (DateTime.Now > C1Directory.GetCreationTime(directoryPath) + TemporaryFileExpirationTimeSpan)
                    {
                        C1Directory.Delete(directoryPath, true);
                    }
                }
                catch
                {
                }
            }
        }
예제 #30
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!UserValidationFacade.IsLoggedIn())
        {
            Response.Redirect(string.Format("Composite/Login.aspx?ReturnUrl={0}", HttpUtility.HtmlEncode(Request.Url.PathAndQuery)));
        }

        var backupFile = Request[BackupFilename];

        if (backupFile != null)
        {
            TransmitBackup(Path.Combine(BackupDirectory, Path.GetFileName(backupFile)));
        }

        if (Page.IsPostBack)
        {
            string commandName = Request["commandName"];
            if (commandName == "delete")
            {
                string deleteXMLBackupFile = Request["deleteXMLBackupFile"];
                if (!string.IsNullOrWhiteSpace(deleteXMLBackupFile))
                {
                    try
                    {
                        C1File.Delete(Path.Combine(BackupDirectory, deleteXMLBackupFile));
                    }
                    catch (Exception ex)
                    {
                        this.Validators.Add(new ErrorSummary(ex.Message));
                    }
                }
            }

            if (commandName == "create")
            {
                CreateBackup();
            }
        }
    }