Example #1
0
        /// <summary>
        /// Handle File Watch Engine events for state changes and failures.
        /// </summary>
        private void fileWatchEngine_EngineEvent(object sender, EngineEventArgs e)
        {
            if (e.NotificationType == EngineNotificationType.Watching ||
                e.NotificationType == EngineNotificationType.Suspended)
            {
                this.Invoke(new AppendToLog(doAppendToLog), "** " + e.NotificationType.ToString() + "\r\n");
            }
            else if (e.NotificationType == EngineNotificationType.Processing)
            {
                this.Invoke(new AppendToLog(doAppendToLog), e.NotificationType.ToString() + ": " + e.FullPath + "...");

                if (currentProtectionPolicy != null &&
                    SafeFileApiNativeMethods.IpcfIsFileEncrypted(e.FullPath) == SafeFileApiNativeMethods.FileEncryptedStatus.IPCF_FILE_STATUS_DECRYPTED)
                {
                    SafeFileApiNativeMethods.IpcfEncryptFile(e.FullPath,
                                                             currentProtectionPolicy.TemplateId,
                                                             SafeFileApiNativeMethods.EncryptFlags.IPCF_EF_FLAG_DEFAULT,
                                                             true,
                                                             false,
                                                             true,
                                                             this);
                }

                this.Invoke(new AppendToLog(doAppendToLog), "Protected!\r\n");
            }
            else
            {
                this.Invoke(new AppendToLog(doAppendToLog), e.NotificationType.ToString() + "\r\n");
            }
        }
Example #2
0
        protected virtual void OnRaiseEngineEvent(EngineEventArgs e)
        {
            EventHandler <EngineEventArgs> handler;

            handler = EngineEvent;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        protected virtual void OnRaiseEngineEvent(EngineEventArgs e)
        {
            EventHandler<EngineEventArgs> handler;

            handler = EngineEvent;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        /// <summary>
        /// Handle File Watch Engine events for state changes and failures.
        /// </summary>
        private void fileWatchEngine_EngineEvent(object sender, EngineEventArgs e)
        {
            if (e.NotificationType == EngineNotificationType.Watching ||
                e.NotificationType == EngineNotificationType.Suspended)
            {
                this.Invoke(new AppendToLog(doAppendToLog), "** " + e.NotificationType.ToString() + "\r\n");
            }
            else if (e.NotificationType == EngineNotificationType.Processing)
            {
                this.Invoke(new AppendToLog(doAppendToLog), e.NotificationType.ToString() + ": " + e.FullPath + "...");

                // append 'p' to file extension to denote as protected
                //String[] outputPath = e.FullPath.Split('.');
                //outputPath[outputPath.Length - 1] = "p" + outputPath[outputPath.Length - 1];
                //String outFile = String.Join(".", outputPath);
                String[] outputPath = e.FullPath.Split('\\');

                // create 'protected' dir if it doesn't exist
                //Directory.CreateDirectory();

                //outputPath[outputPath.Length - 1] = "protected\\" + outputPath[outputPath.Length - 1];
                //String outFile = String.Join("\\", outputPath);

                String tmpFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

                //String outFile = e.FullPath;
                Action.FileOptions options = new Action.FileOptions
                {
                    FileName                 = e.FullPath,
                    OutputName               = tmpFilePath,
                    ActionSource             = ActionSource.Manual,
                    AssignmentMethod         = AssignmentMethod.Standard,
                    DataState                = DataState.Rest,
                    GenerateChangeAuditEvent = true,
                    IsAuditDiscoveryEnabled  = true,
                    LabelId = currentProtectionPolicy.Id
                };

                this.Invoke(new AppendToLog(doAppendToLog), "Checking for existing Label" + "\r\n");

                ContentLabel currLabel = action.GetLabel(options);

                Boolean doProtect = true;
                // determine if this file should be protected or unprotected
                if (listBoxUnprotect.Items.Count > 0)
                {
                    for (int i = 0; i < listBoxUnprotect.Items.Count; i++)
                    {
                        String path = (string)listBoxUnprotect.Items[i];
                        if (e.FullPath.StartsWith(path))
                        {
                            doProtect = false;
                            break;
                        }
                    }
                }

                ////
                if (doProtect)
                {
                    if (currLabel != null)
                    {
                        this.Invoke(new AppendToLog(doAppendToLog), "Already Protected!\r\n");
                    }

                    if (currentProtectionPolicy != null && currLabel == null)
                    {
                        this.Invoke(new AppendToLog(doAppendToLog), "Setting Label and saving to " + tmpFilePath + "\r\n");
                        action.SetLabel(options);
                        this.Invoke(new AppendToLog(doAppendToLog), "Replacing file with protected version" + "\r\n");
                        File.Delete(e.FullPath);
                        this.Invoke(new AppendToLog(doAppendToLog), "Deleted old " + "\r\n");
                        File.Copy(tmpFilePath, e.FullPath);
                        this.Invoke(new AppendToLog(doAppendToLog), "Protected!\r\n");
                    }
                }
                else     // Unprotect the file

                {
                    if (currLabel == null)
                    {
                        this.Invoke(new AppendToLog(doAppendToLog), "Already NOT Protected!\r\n");
                        return;
                    }
                    this.Invoke(new AppendToLog(doAppendToLog), "Unprotect this file \r\n");
                    options.LabelId = null; // remove label??
                    this.Invoke(new AppendToLog(doAppendToLog), "Removing Label and saving to " + tmpFilePath + "\r\n");
                    action.DeleteLabel(options);
                    this.Invoke(new AppendToLog(doAppendToLog), "Replacing file with unprotected version" + "\r\n");
                    File.Delete(e.FullPath);
                    this.Invoke(new AppendToLog(doAppendToLog), "Deleted old " + "\r\n");
                    File.Copy(tmpFilePath, e.FullPath);
                    this.Invoke(new AppendToLog(doAppendToLog), "Protection Removed!\r\n");
                }
            }
            else
            {
                this.Invoke(new AppendToLog(doAppendToLog), e.NotificationType.ToString() + "\r\n");
            }
        }
        /// <summary>
        /// Handle File Watch Engine events for state changes and failures.
        /// </summary>
        private void fileWatchEngine_EngineEvent(object sender, EngineEventArgs e)
        {
            if (e.NotificationType == EngineNotificationType.Watching ||
                e.NotificationType == EngineNotificationType.Suspended)
            {
                this.Invoke(new AppendToLog(doAppendToLog), "** " + e.NotificationType.ToString() + "\r\n");
            }
            else if (e.NotificationType == EngineNotificationType.Processing)
            {
                this.Invoke(new AppendToLog(doAppendToLog), e.NotificationType.ToString() + ": " + e.FullPath + "...");

                if (currentProtectionPolicy != null &&
                    SafeFileApiNativeMethods.IpcfIsFileEncrypted(e.FullPath) == SafeFileApiNativeMethods.FileEncryptedStatus.IPCF_FILE_STATUS_DECRYPTED)
                {
                    SafeFileApiNativeMethods.IpcfEncryptFile(e.FullPath,
                                                             currentProtectionPolicy.TemplateId,
                                                             SafeFileApiNativeMethods.EncryptFlags.IPCF_EF_FLAG_DEFAULT,
                                                             true,
                                                             false,
                                                             true,
                                                             this);
                }

                this.Invoke(new AppendToLog(doAppendToLog), "Protected!\r\n");
            }
            else
            {
                this.Invoke(new AppendToLog(doAppendToLog), e.NotificationType.ToString() + "\r\n");
            }
        }