Exemple #1
0
        /// <summary>
        /// Method can be invoked in PRISM MEF module registration to register a new document (viewmodel)
        /// type and its default file extension. The result of this call is an <seealso cref="IDocumentType"/>
        /// object and a <seealso cref="RegisterDocumentTypeEvent"/> event to inform listers about the new
        /// arrival of the new document type.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="description"></param>
        /// <param name="fileFilterName"></param>
        /// <param name="defaultFilter"></param>
        /// <param name="fileOpenMethod"></param>
        /// <param name="createDocumentMethod"></param>
        /// <param name="t"></param>
        /// <param name="sortPriority"></param>
        /// <returns></returns>
        public IDocumentType RegisterDocumentType(string key,
                                                  string description,
                                                  string fileFilterName,
                                                  string defaultFilter,
                                                  FileOpenDelegate fileOpenMethod,
                                                  CreateNewDocumentDelegate createDocumentMethod,
                                                  Type t,
                                                  int sortPriority = 0)
        {
            try
            {
                Messaging.Output.Append(string.Format("{0} Registering document type: {1} ...",
                                                      DateTime.Now.ToLongTimeString(), description));

                var newFileType = new DocumentType(key, description, fileFilterName, defaultFilter,
                                                   fileOpenMethod, createDocumentMethod,
                                                   t, sortPriority);

                _DocumentTypes.Add(newFileType);
                _DocumentTypes.Sort(i => i.SortPriority, ListSortDirection.Ascending);

                return(newFileType);
            }
            catch (Exception exp)
            {
                Messaging.Output.AppendLine(exp.Message);
                Messaging.Output.AppendLine(exp.StackTrace);
            }
            finally
            {
                Messaging.Output.AppendLine("Done.");
            }

            return(null);
        }
Exemple #2
0
            public StorageHandler(string dataPath)
            {
                _dataPath      = dataPath;
                openDelegate   = new FileOpenDelegate(FileOpen);
                readDelegate   = new FileReadDelegate(FileRead);
                closeDelegate  = new FileCloseDelegate(FileClose);
                unlinkDelegate = new FileUnlinkDelegate(FileUnlink);
                writeDelegate  = new FileWriteDelegate(FileWrite);
                var h1 = GCHandle.Alloc(openDelegate, GCHandleType.Normal);
                var h2 = GCHandle.Alloc(readDelegate, GCHandleType.Normal);
                var h3 = GCHandle.Alloc(writeDelegate, GCHandleType.Normal);
                var h4 = GCHandle.Alloc(closeDelegate, GCHandleType.Normal);
                var h5 = GCHandle.Alloc(unlinkDelegate, GCHandleType.Normal);

                pinnedDelegates = new GCHandle[] { h1, h2, h3, h4, h5 };

                //Handle = new OCPersistentStorage()
                //{
                //    Open = openDelegate,
                //    Read = readDelegate,
                //    Write = writeDelegate,
                //    Close = closeDelegate,
                //    Unlink = unlinkDelegate,
                //};
                Handle = new OCPersistentStorage()
                {
                    Open   = Marshal.GetFunctionPointerForDelegate(openDelegate),
                    Read   = Marshal.GetFunctionPointerForDelegate(readDelegate),
                    Write  = Marshal.GetFunctionPointerForDelegate(writeDelegate),
                    Close  = Marshal.GetFunctionPointerForDelegate(closeDelegate),
                    Unlink = Marshal.GetFunctionPointerForDelegate(unlinkDelegate),
                };
                pHandle = GCHandle.Alloc(Handle);
            }
Exemple #3
0
        public void GetFileFilterEntries(SortedList <int, IFileFilterEntry> ret, FileOpenDelegate fileOpenMethod)
        {
            foreach (var item in this.FileTypeExtensions)
            {
                string ext = string.Empty, ext1 = string.Empty;

                if (item.DocFileTypeExtensions.Count <= 0)
                {
                    continue;
                }

                ext = ext1 = string.Format("*.{0}", item.DocFileTypeExtensions[0]);

                for (int i = 1; i < item.DocFileTypeExtensions.Count; i++)
                {
                    ext  = string.Format("{0},*.{1}", ext, item.DocFileTypeExtensions[i]);
                    ext1 = string.Format("{0};*.{1}", ext1, item.DocFileTypeExtensions[i]);
                }

                // log4net XML output (*.log4j,*.log,*.txt,*.xml)|*.log4j;*.log;*.txt;*.xml
                var filterString = new FileFilterEntry(string.Format("{0} ({1}) |{2}",
                                                                     item.Description, ext, ext1), fileOpenMethod);

                ret.Add(item.SortPriority, filterString);
            }
        }
Exemple #4
0
        public void GetFileFilterEntries(SortedList <int, IFileFilterEntry> ret, FileOpenDelegate fileOpenMethod)
        {
            foreach (var item in FileTypeExtensions)
            {
                string ext1;

                if (item.DocFileTypeExtensions.Count <= 0)
                {
                    continue;
                }

                var ext = ext1 = $"*.{item.DocFileTypeExtensions[0]}";

                for (int i = 1; i < item.DocFileTypeExtensions.Count; i++)
                {
                    ext  = $"{ext},*.{item.DocFileTypeExtensions[i]}";
                    ext1 = $"{ext1};*.{item.DocFileTypeExtensions[i]}";
                }

                // log4net XML output (*.log4j,*.log,*.txt,*.xml)|*.log4j;*.log;*.txt;*.xml
                var filterString = new FileFilterEntry($"{item.Description} ({ext}) |{ext1}", fileOpenMethod);

                ret.Add(item.SortPriority, filterString);
            }
        }
Exemple #5
0
 internal FileOpenEventArgs(string fileName, FileMode mode, FileAccess access, FileShare share, FileOpenDelegate opener)
 {
     FileName   = fileName;
     FileMode   = mode;
     FileAccess = access;
     FileShare  = share;
     _opener    = opener;
 }
 public static Stream CreateFileStream(string path, bool write, bool append)
 {
     if (s_fileOpen == null)
     {
         s_fileOpen = GetFileOpenFunction();
     }
     int filemode = !write ? FileMode_Open : append ? FileMode_Append : FileMode_Create;
     int fileaccess = write ? FileAccess_Write : FileAccess_Read;
     return s_fileOpen(path, filemode, fileaccess, FileShare_Read);
 }
Exemple #7
0
        public static Stream CreateFileStream(string path, bool write, bool append)
        {
            if (s_fileOpen == null)
            {
                s_fileOpen = GetFileOpenFunction();
            }
            int filemode   = !write ? FileMode_Open : append ? FileMode_Append : FileMode_Create;
            int fileaccess = write ? FileAccess_Write : FileAccess_Read;

            return(s_fileOpen(path, filemode, fileaccess));
        }
Exemple #8
0
        /// <summary>
        /// Method can be invoked in PRISM MEF module registration to register a new document (viewmodel)
        /// type and its default file extension. The result of this call is an <seealso cref="IDocumentType"/>
        /// object and a <seealso cref="RegisterDocumentTypeEvent"/> event to inform listers about the new
        /// arrival of the new document type.
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Description"></param>
        /// <param name="FileFilterName"></param>
        /// <param name="DefaultFilter"></param>
        /// <param name="FileOpenMethod"></param>
        /// <param name="CreateDocumentMethod"></param>
        /// <param name="t"></param>
        /// <param name="sortPriority"></param>
        /// <returns></returns>
        public IDocumentType RegisterDocumentType(string Key,
                                                  string Description,
                                                  string FileFilterName,
                                                  string DefaultFilter,
                                                  FileOpenDelegate FileOpenMethod,
                                                  CreateNewDocumentDelegate CreateDocumentMethod,
                                                  Type t,
                                                  int sortPriority = 0)
        {
            var newFileType = new DocumentType(Key, Description, FileFilterName, DefaultFilter,
                                               FileOpenMethod, CreateDocumentMethod,
                                               t, sortPriority);

            this.mDocumentTypes.Add(newFileType);
            this.mDocumentTypes.Sort(i => i.SortPriority, System.ComponentModel.ListSortDirection.Ascending);

            return(newFileType);
        }
Exemple #9
0
        /// <summary>
        /// Method can be invoked in PRISM MEF module registration to register a new document (viewmodel)
        /// type and its default file extension. The result of this call is an <seealso cref="IDocumentType"/>
        /// object and a <seealso cref="RegisterDocumentTypeEvent"/> event to inform listers about the new
        /// arrival of the new document type.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="description"></param>
        /// <param name="fileFilterName"></param>
        /// <param name="defaultFilter"></param>
        /// <param name="fileOpenMethod"></param>
        /// <param name="createDocumentMethod"></param>
        /// <param name="t"></param>
        /// <param name="sortPriority"></param>
        /// <returns></returns>
        public IDocumentType RegisterDocumentType(string key,
                                                  string description,
                                                  string fileFilterName,
                                                  string defaultFilter,
                                                  FileOpenDelegate fileOpenMethod,
                                                  CreateNewDocumentDelegate createDocumentMethod,
                                                  Type t,
                                                  int sortPriority = 0)
        {
            var newFileType = new DocumentType(key, description, fileFilterName, defaultFilter,
                                               fileOpenMethod, createDocumentMethod,
                                               t, sortPriority);

            _mDocumentTypes.Add(newFileType);
            _mDocumentTypes.Sort(i => i.SortPriority, ListSortDirection.Ascending);

            return(newFileType);
        }
Exemple #10
0
        /// <summary>
        /// Class constructor.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="description"></param>
        /// <param name="fileFilterName"></param>
        /// <param name="defaultFilter"></param>
        /// <param name="fileOpenMethod"></param>
        /// <param name="classType"></param>
        /// <param name="sortPriority"></param>
        public DocumentType(string key,
                            string description,
                            string fileFilterName,
                            string defaultFilter,
                            FileOpenDelegate fileOpenMethod,
                            CreateNewDocumentDelegate createDocumentMethod,
                            Type classType,
                            int sortPriority = 0)
        {
            this.Key                  = key;
            this.Description          = description;
            this.FileFilterName       = fileFilterName;
            this.SortPriority         = sortPriority;
            this.DefaultFilter        = defaultFilter;
            this.FileOpenMethod       = fileOpenMethod;
            this.CreateDocumentMethod = createDocumentMethod;
            this.ClassType            = classType;

            this.FileTypeExtensions = null;
        }
Exemple #11
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="fileFilter"></param>
 /// <param name="fileOpenMethod"></param>
 public FileFilterEntry(string fileFilter, FileOpenDelegate fileOpenMethod)
 {
     FileFilter     = fileFilter;
     FileOpenMethod = fileOpenMethod;
 }