Exemple #1
0
        private bool IsNameStartedWith(IFileModel file, string searchPattern)
        {
            bool result = file.NameWithExtension.ToLowerInvariant().StartsWith(searchPattern);

            log.Debug("Path: '{0}'; Pattern: '{1}'; Mode: 'NameStartsWith'; Result: '{2}'.", file.Path, searchPattern, result);
            return(result);
        }
        public async Task LoadBuffer(IChannel channel, UploadPartCommand command)
        {
            if (!_uploadPool.ContainsKey(channel))
            {
                throw new InvalidOperationException("尚未准备完毕");
            }
            if (string.IsNullOrEmpty(command.Base64Buffer))
            {
                throw new InvalidOperationException("数据为空");
            }
            byte[]     buffy            = Convert.FromBase64String(command.Base64Buffer);
            IFileModel uploadVideoModel = _uploadPool[channel];

            if (uploadVideoModel == null)
            {
                throw new InvalidOperationException("不存在该文件");
            }
            uploadVideoModel.LoadBuffer(buffy, command.Index);
            if (uploadVideoModel.CanComplete)
            {
                (string _, string path, long _) = await new UploadAccessory().SaveAccessoryAsync(uploadVideoModel.FileContent, $"{AppDomain.CurrentDomain.BaseDirectory}//Backup", uploadVideoModel.FileName, false);
                await UpdateWebFileAsync(path, channel);

                new HttpHandler().ClearCache();
                var @event = new UploadEndEvent();
                await channel.SendJsonEventAsync(@event);

                _uploadPool.Remove(channel);
            }
            else
            {
                var @event = new UploadReadyEvent();
                await channel.SendJsonEventAsync(@event);
            }
        }
Exemple #3
0
 public FilterListViewModel(IFileModel fileModel, Func <int, Owned <IFilterItemViewModel> > filterItemViewModelFactory)
 {
     m_fileModel = fileModel;
     m_filterItemViewModelFactory = filterItemViewModelFactory;
     AddSearchStringCommand       = new RelayCommand(AddSearchString);
     AddSearchString("*All*");
 }
        public async Task <bool> MoveFiles(IFileModel file, string sourcePath, string targetPath)
        {
            Directory.CreateDirectory(file.TargetPath); // creates folder with name of file extension (if it does not exist)
            try { File.Move(file.FullSourcePath, file.FullTargetPath); return(true); }
            catch (Exception e) { File.WriteAllText(Path.Combine(file.TargetPath, "move_log.txt"), e.Message); }

            return(false);
        }
Exemple #5
0
 public FileItemViewModel(IFileModel fileModel,
                          Lazy <IFilterListViewModel> filterListViewModel,
                          Lazy <IGraphViewModel> graphViewModel)
 {
     m_fileModel           = fileModel;
     m_filterListViewModel = filterListViewModel.Value;
     m_graphViewModel      = graphViewModel.Value;
 }
Exemple #6
0
 //https://stackoverflow.com/a/721743
 public FileWatcher(string filePath, IFileModel model, object modelView, bool enabled = true, FileWatcherService service = null)
 {
     Model      = model;
     ModelToken = model?.Token ?? 0;
     ModelView  = modelView;
     FilePath   = filePath;
     Service    = service ?? FileWatcherService.Instance;
     Enabled    = enabled;
 }
Exemple #7
0
        //https://stackoverflow.com/a/721743
        public FileWatcher(string filePath, IFileModel model, IFileModelView modelView, bool enabled = true, FileWatcherService service = null)
        {
            Model = model;
            Stamp = model is IStampKey stamp ? (stamp.Stamp ?? File.GetLastWriteTimeUtc(filePath)) : File.GetLastWriteTimeUtc(filePath);

            ModelView = modelView;
            FilePath  = filePath;
            Service   = service ?? FileWatcherService.Instance;
            Enabled   = enabled;
        }
Exemple #8
0
 protected internal void OnDeleteFile(IFileModel file)
 {
     Urls = Urls.Where(x => x != file.Url).ToArray();
     if (UrlsChanged.HasDelegate)
     {
         _ = UrlsChanged.InvokeAsync(Urls);
     }
     RequireRender = true;
     SetFieldValue(Urls, true);
 }
Exemple #9
0
 public FilePresenter(IFileModel model, IView view, IFile file)
 {
     this.file              = file;
     this.model             = model;
     this.view              = view;
     view.OpenFile_Click   += ViewOpenFile_Click;
     view.SaveFile_Click   += ViewSaveFile_Click;
     view.AddFile_Click    += ViewAddFile_Click;
     view.DeleteFile_Click += ViewDeleteFile_Click;
     view.EditFile_Click   += ViewEditFile_Click;
 }
Exemple #10
0
 internal void DeleteFile(IFileModel file)
 {
     Files.Remove(file);
     RequireRender = true;
     SetFieldValue(Files.ToArray(), true);
     if (!OnDeleteFile.HasDelegate)
     {
         return;
     }
     _ = OnDeleteFile.InvokeAsync(file);
 }
        public FileViewModel(IProjectViewModel parentProject, IFileModel fileData)
        {
            this.project  = parentProject;
            this.fileData = fileData;

            try
            {
                // Try to use specified factory
                var parserFactory = PluginFactory.FindParser(fileData.DataParserType);

                // If not available use any other able to use open that format
                if (parserFactory == null)
                {
                    parserFactory = PluginFactory.FindLogFileParser(fileData.FileName);
                }

                if (parserFactory == null)
                {
                    throw new InvalidOperationException("No parser for " + fileData.FileName + " available.");
                }

                this.LogFile = parserFactory.Open(fileData.FileName, fileData.Settings);
            }
            catch (IOException ioe)
            {
                throw new IOException("Can no open file", ioe);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
                throw;
            }

            this.Icon        = ResourceHelper.SetIconFromBitmap(Properties.Resources.folder);
            signalViewModels = new ObservableCollection <ISignalViewModel>();

            foreach (Signal s in LogFile.Signals)
            {
                SignalViewModel subitem = new SignalViewModel(this, s);
                this.Signals.Add(subitem);
            }

            foreach (IMarkerModel m in fileData.Markers)
            {
                MarkerViewModel markerItem = new MarkerViewModel(m, false);
                this.Markers.Add(markerItem);
            }

            markerViewModels.CollectionChanged += MarkerViewModels_CollectionChanged;
        }
        private bool IsPathSearchMatched(IFileModel file, string[] searchPattern)
        {
            string pathMatch = file.Path.ToLowerInvariant();
            for (int i = 0; i < searchPattern.Length; i++)
            {
                int currentIndex = pathMatch.IndexOf(searchPattern[i]);
                if (currentIndex == -1)
                    return false;

                pathMatch = pathMatch.Substring(currentIndex + searchPattern[i].Length);
            }

            return true;
        }
Exemple #13
0
 public FilterItemViewModel(int index, IFileModel fileModel, IGraphViewModel graphViewModel)
 {
     m_index          = index;
     m_fileModel      = fileModel;
     m_graphViewModel = graphViewModel;
     MatchCount       = 0;
     m_stringSubject.AsObservable()
     .Throttle(TimeSpan.FromMilliseconds(1000))
     .Subscribe(x =>
     {
         m_fileModel.AddOrChangeSearchString(m_index, x);
     });
     m_fileModel.OnSeriesAddedOrChanged += FileModelOnOnSeriesAddedOrChanged;
 }
Exemple #14
0
        private void ReadSummary(StringReader reader, IFileModel fileModel)
        {
#if DEBUG
            this.WriteDebugLine();
#endif
            var    summary = "";
            string line;
            while (!(line = reader.ReadLine()).EndsWith("]]"))
            {
                summary += line.Trim() + Environment.NewLine;
            }

            fileModel.Summary = summary.Trim();
        }
        public static string FilePath(this IFileModel fileModel, string subFolder = null, string extension = null)
        {
            var path = ConfigurationManager.AppSettings[fileModel.GetType().Name];

            if (subFolder != null)
            {
                path = Path.Combine(path, subFolder);
            }

            var fileName = extension is null ?
                           fileModel.Name :
                           fileModel.Name + "." + extension;

            return(Path.Combine(path, fileName));
        }
Exemple #16
0
        private bool IsPathSearchMatched(IFileModel file, string[] searchPattern)
        {
            string pathMatch = file.Path.ToLowerInvariant();

            for (int i = 0; i < searchPattern.Length; i++)
            {
                int currentIndex = pathMatch.IndexOf(searchPattern[i]);
                if (currentIndex == -1)
                {
                    return(false);
                }

                pathMatch = pathMatch.Substring(currentIndex + searchPattern[i].Length);
            }

            return(true);
        }
Exemple #17
0
        /// <summary>
        /// see <see cref="IMdFileParserService.ParseFile{TFileData}(IFileModel)"/>
        /// </summary>
        /// <typeparam name="TFileData"></typeparam>
        /// <param name="fileModel"></param>
        public void ParseFile <TFileData>(IFileModel fileModel)
        {
#if DEBUG
            this.WriteDebugLine();
#endif
            fileModel.IsValid = false;

            using var reader = new StringReader(fileModel.RawContent);
            var line = reader.ReadLine();
            if (line[0] == '#')
            {
                fileModel.Title = line.Substring(1).Trim();
            }
            else
            {
                return;
            }

            do
            {
                line = reader.ReadLine();
            } while (line == "");

            if (line.StartsWith("[[DocumentData"))
            {
                ReadData <TFileData>(reader, fileModel);
            }

            do
            {
                line = reader.ReadLine();
            } while (line == "");


            if (line.StartsWith("[[Summary"))
            {
                ReadSummary(reader, fileModel);
            }

            var markdown = reader.ReadToEnd();

            using var writer      = new StringWriter();
            fileModel.HtmlContent = Markdown.ToHtml(markdown.Trim(), pipeline);

            fileModel.IsValid = true;
        }
Exemple #18
0
        public GraphViewModel(IFileModel fileModel)
        {
            m_fileModel = fileModel;
            m_fileModel.OnSeriesAddedOrChanged += FileModelOnOnSeriesAddedOrChanged;

            InspectDataCommand = new RelayCommand(InspectData);
            MouseMoveCommand   = new RelayCommand(DoMouseMove);

            Formatter = value => new DateTime((long)(value * TimeSpan.FromHours(1).Ticks)).ToString("t");

            var dayConfig = Mappers.Xy <DateModel>()
                            .X(dayModel => (double)dayModel.DateTime.Ticks / TimeSpan.FromHours(1).Ticks)
                            .Y(dayModel => dayModel.Value);

            SeriesCollection = new SeriesCollection(dayConfig);
            CreateSeries("");
        }
Exemple #19
0
        private void ReadData <TFileData>(StringReader reader, IFileModel fileModel)
        {
#if DEBUG
            this.WriteDebugLine();
#endif
            var    yaml = "";
            string line;
            while (!(line = reader.ReadLine()).EndsWith("]]"))
            {
                yaml += line + Environment.NewLine;
            }

            var desrializer = new DeserializerBuilder().Build();

            var fileData = desrializer.Deserialize <TFileData>(yaml);

            foreach (var prop in typeof(TFileData).GetProperties())
            {
                var fileProp = fileModel.GetType().GetProperty(prop.Name);

                if (fileProp is null)
                {
#if DEBUG
                    this.WriteDebugLine(message: string.Format(
                                            "Missing property {0} from data <{1}> in model <{2}>",
                                            prop.Name,
                                            typeof(TFileData).Name,
                                            fileModel.GetType().Name
                                            ));
#endif
                    continue;
                }

                var value = prop.GetValue(fileData);

                if (value is string stringValue)
                {
                    value = stringValue.Trim();
                }

                fileProp.SetValue(fileModel, value);
            }
        }
Exemple #20
0
        private bool IsPathSearchMatched(IFileModel file, string[] searchPattern)
        {
            bool   result    = true;
            string pathMatch = file.Path.ToLowerInvariant();

            for (int i = 0; i < searchPattern.Length; i++)
            {
                int currentIndex = pathMatch.IndexOf(searchPattern[i]);
                if (currentIndex == -1)
                {
                    result = false;
                    break;
                }

                pathMatch = pathMatch.Substring(currentIndex + searchPattern[i].Length);
            }

            log.Debug("Path: '{0}'; Pattern: '{1}'; Mode: 'Contains' Result: '{2}'.", file.Path, String.Join(" ", searchPattern), result);
            return(result);
        }
 public MultipleClassFileTemplate(IEnumerable <IClassGenerator> classGenerators, IFileModel fileModel) : base(fileModel)
 {
     ClassGenerators = classGenerators;
 }
Exemple #22
0
 protected FileTemplate(IFileModel fileModel)
 {
     FileModel = fileModel;
 }
Exemple #23
0
 private bool IsNameStartedWith(IFileModel file, string searchPattern)
 {
     return(file.NameWithExtension.ToLowerInvariant().StartsWith(searchPattern));
 }
 private bool IsNameStartedWith(IFileModel file, string searchPattern)
 {
     return file.NameWithExtension.ToLowerInvariant().StartsWith(searchPattern);
 }
 public FileModelController(IFileModel repository, IHostingEnvironment appEnvironment)
 {
     _accessFile     = repository;
     _appEnvironment = appEnvironment;
 }
Exemple #26
0
 public CSharpMultipleClassFileTemplate(IEnumerable <IClassGenerator> classGenerators, IFileModel fileModel) : base(classGenerators, fileModel)
 {
 }