コード例 #1
0
        private void ApppendLogsTo(string logFileName, LogEventArg e)
        {
            if (logFileName.IsBlank())
            {
                return;
            }
            switch (e.Level)
            {
            case L4j.Off:                   //
            case L4j.Debug:                 //  ignore these levels
            case L4j.Trace: return;         //
            }
            if (e.ShowAs != ShowLogAs.Normal)
            {
                return;
            }

            if (_logFile == null)
            {
                _logFile = _fs.File(_fs.GetAssemblyDir().Bslash(logFileName));
            }

            var line = L.f + TextLog.Format(e.Title, e.Message);

            _logFile.Write(line, EncodeAs.UTF8, false, false);
        }
コード例 #2
0
        public D7File_Out(FileShim fShim,
                          string serverFoldr,
                          bool isPrivate)
        {
            //if (!fShim.Found) Throw.Missing(fShim);
            var defLevl = fShim.DefaultLevel;

            fShim.DefaultLevel = L4j.Off;

            var fPath = isPrivate ? "private://" : "public://";

            fPath = fPath.Slash(serverFoldr).Slash(fShim.Name);

            this.file = new D7File
            {
                file     = fShim.ToBase64,
                filename = fShim.Name,
                filepath = fPath,
                //status   = Constants.FILE_STATUS_PERMANENT,
                //filemime = "application/x-msdos-program"
                //filemime = 149
            };

            fShim.DefaultLevel = defLevl;
        }
コード例 #3
0
        public async Task<int> Post(FileShim file,
                                    CancellationToken cancelToken,
                                    string serverFoldr,
                                    bool isPrivate)
        {
            if (!IsLoggedIn)
                throw Error.BadAct($"‹{this.GetType().Name}› is not logged in.");

            Trace_n("Uploading file to server...", "");
            var req = _auth.Req.POST(URL.Api_FileJson);

            req.Body = new D7File_Out(file,
                            serverFoldr, isPrivate);

            D7File d7f = null; try
            {
                d7f = await _client.Send<D7File>(req, cancelToken, null,
                    "Successfully uploaded “{0}” ({1}) [fid: {2}].",
                        x => file.Name, x => file.Size.KB(), x => x.fid);
            }
            catch (RestServiceException ex) { OnFileUpload.Err(this, ex); }
            catch (Exception ex) { OnUnhandled.Err(this, ex); }


            if (d7f != null && d7f.fid > 0) return d7f.fid;
            else if (d7f == null) return Error_(-1, "Returned null.", "");
            else return Error_(-1, "Unexpected file id: " + d7f.fid, "");
        }
コード例 #4
0
ファイル: SessionAuth.cs プロジェクト: peterson1/ErrH
 public SessionAuth(IFileSystemShim fsShim, ISerializer serializer)
 {
     _fs         = fsShim;
     _serialzr   = serializer;
     var dir     = _fs.GetSpecialDir(SpecialDir.LocalApplicationData)
                                                 .Bslash(ParentDir);
     SessionFile = _fs.File(dir.Bslash("d7.session"));
 }
コード例 #5
0
ファイル: D7FileDownloader.cs プロジェクト: peterson1/ErrH
        private bool RelocateActiveFile(FileShim locF)
        {
            var newF = TempDir.Path.Bslash(locF.Name) + _suffix;

            if (!locF.MoveTo(newF))
                return Error_n("Unable to move currently in-use file.", locF.Path);
            else
                return true;
        }
コード例 #6
0
        public SessionAuth(IFileSystemShim fsShim, ISerializer serializer)
        {
            _fs       = fsShim;
            _serialzr = serializer;
            var dir = _fs.GetSpecialDir(SpecialDir.LocalApplicationData)
                      .Bslash(ParentDir);

            SessionFile = _fs.File(dir.Bslash("d7.session"));
        }
コード例 #7
0
        private void WriteCachedDate(string d7Changed)
        {
            if (_cachedDateFile == null)
            {
                _cachedDateFile = GetCachedDateFile();
            }

            _cachedDateFile.Write(d7Changed, raiseLogEvents: false);
        }
コード例 #8
0
ファイル: JsonNetSerializer.cs プロジェクト: orf53975/ErrH
        public T Read <T>(FileShim fileShim, bool raiseLogEvents)
        {
            var s = raiseLogEvents ? fileShim.ReadUTF8
                                   : fileShim._ReadUTF8;

            if (s.IsBlank())
            {
                return(Warn_(default(T), "Invalid Json format.",
                             "Content of file is blank."));
            }
            return(this.Read <T>(s, raiseLogEvents));
        }
コード例 #9
0
        private string ReadCachedDate()
        {
            if (_cachedDateFile == null)
            {
                _cachedDateFile = GetCachedDateFile();
            }

            if (!_cachedDateFile._Found)
            {
                return(null);
            }
            return(_cachedDateFile._ReadUTF8);
        }
コード例 #10
0
ファイル: D7FileDownloader.cs プロジェクト: orf53975/ErrH
        private bool RelocateActiveFile(FileShim locF)
        {
            var newF = TempDir.Path.Bslash(locF.Name) + _suffix;

            if (!locF.MoveTo(newF))
            {
                return(Error_n("Unable to move currently in-use file.", locF.Path));
            }
            else
            {
                return(true);
            }
        }
コード例 #11
0
        private string ParseArguments(object[] args, out FileShim cacheFile)
        {
            if (args.Length == 0 || !(args[0] is string))
            {
                cacheFile = null;
                return(Error_("", $"Invalid argument for ‹{GetType().Name}›.LoadAsync()",
                              "LoadAsync(args[0]) should be the resource URL"));
            }
            var sufx = args.Length > 1 ? "_" + string.Join("_", args.Skip(1)) : "";

            cacheFile = DefineCacheFile(sufx);
            return(string.Join("/", args));;
        }
コード例 #12
0
ファイル: BatchFileShim.cs プロジェクト: peterson1/ErrH
        public void Run(string batchFilePath)
        {
            File = _fs.File(batchFilePath);

            // if it's just a file name,
            //  - look for it beside the folder
            if (!File.Found)
            {
                var path = _fs.GetAssemblyDir().Bslash(batchFilePath);
                File = _fs.File(path);
            }

            ExecuteCmd(File);
        }
コード例 #13
0
        public void Run(string batchFilePath)
        {
            File = _fs.File(batchFilePath);

            // if it's just a file name,
            //  - look for it beside the folder
            if (!File.Found)
            {
                var path = _fs.GetAssemblyDir().Bslash(batchFilePath);
                File = _fs.File(path);
            }

            ExecuteCmd(File);
        }
コード例 #14
0
ファイル: WindowsFsShim.cs プロジェクト: orf53975/ErrH
        /// <summary>
        /// Creates a temporary file in the system's temp folder.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="encodeAs"></param>
        /// <returns></returns>
        public FileShim TempFile(string content, EncodeAs encodeAs = EncodeAs.UTF8)
        {
            string fPath; string errMsg; FileShim tempF = null;

            Debug_i("Creating temporary file...");

            if (!this.TryCreateNewTempFile(out fPath, out errMsg))
            {
                return(Error_o_(tempF, "Failed to create temporary file." + L.F + errMsg));
            }

            Debug_o("created: " + fPath);
            tempF = this.File(fPath);
            tempF.Write(content, encodeAs);
            return(tempF);
        }
コード例 #15
0
ファイル: LogScrollerVM.cs プロジェクト: peterson1/ErrH
        private void ApppendLogsTo(string logFileName, LogEventArg e)
        {
            if (logFileName.IsBlank()) return;
            switch (e.Level)
            {
                case L4j.Off:               //
                case L4j.Debug:             //  ignore these levels
                case L4j.Trace: return;     //
            }
            if (e.ShowAs != ShowLogAs.Normal) return;

            if (_logFile == null)
                _logFile = _fs.File(_fs.GetAssemblyDir().Bslash(logFileName));

            var line = L.f + TextLog.Format(e.Title, e.Message);
            _logFile.Write(line, EncodeAs.UTF8, false, false);
        }
コード例 #16
0
        private bool SameAs(FileShim file, string json, string msg)
        {
            if (json.Length != file.ReadUTF8.Length)
            {
                RaiseDataChanged();
                return(Warn_n($"Different size for result: {json.Length.KB()}.", msg));
            }

            if (json.SHA1() == file.SHA1)
            {
                return(Debug_n("Resulting file is same as cached content.", msg));
            }
            else
            {
                RaiseDataChanged();
                return(Warn_n("SHA-1 checksum differed from cached file.", msg));
            }
        }
コード例 #17
0
ファイル: LoginCfgFile.cs プロジェクト: orf53975/ErrH
        protected T ReadAs <T>(string fileName) where T : IBasicAuthenticationKey
        {
            _file = _fs.File(_fs.GetAssemblyDir().Bslash(fileName));
            if (!_file.Found)
            {
                return(Warn_(default(T), $"Missing login file “{fileName}”.", _file.Path));
            }

            var ret = _serialr.Read <T>(_file);

            if (ret == null)
            {
                return(Error_(ret, $"Failed to parse ‹{typeof(T).Name}›.", ""));
            }

            UserName = ret.UserName;
            Password = ret.Password;
            BaseUrl  = ret.BaseUrl;

            return(ret);
        }
コード例 #18
0
ファイル: D7FileDownloader.cs プロジェクト: orf53975/ErrH
        private bool VerifyFile(FileShim actual, SyncableFileBase expctd)
        {
            var s = "Downloaded files is corrupted.";

            if (actual.Name != expctd.Name)
            {
                return(Error_n(s, $"expected name: {expctd.Name}  ==>  actual: {actual.Name}"));
            }

            if (actual.Size != expctd.Size)
            {
                return(Error_n(s, $"expected size: {expctd.Size.KB()}  ==>  actual: {actual.Size.KB()}"));
            }

            if (actual.SHA1 != expctd.SHA1)
            {
                return(Error_n(s, $"expected hash: {expctd.SHA1}  ==>  actual: {actual.SHA1}"));
            }

            return(true);
        }
コード例 #19
0
ファイル: D7File_Out.cs プロジェクト: peterson1/ErrH
        public D7File_Out(FileShim fShim,
                          string serverFoldr,
                          bool isPrivate)
        {
            //if (!fShim.Found) Throw.Missing(fShim);
            var defLevl = fShim.DefaultLevel;
            fShim.DefaultLevel = L4j.Off;

            var fPath = isPrivate ? "private://" : "public://";
            fPath = fPath.Slash(serverFoldr).Slash(fShim.Name);

            this.file = new D7File
            {
                file = fShim.ToBase64,
                filename = fShim.Name,
                filepath = fPath,
                //status   = Constants.FILE_STATUS_PERMANENT,
                //filemime = "application/x-msdos-program"
                //filemime = 149
            };

            fShim.DefaultLevel = defLevl;
        }
コード例 #20
0
ファイル: BatchFileShim.cs プロジェクト: peterson1/ErrH
        private void ExecuteCmd(FileShim cmdFile)
        {
            Info_n("Running command from file...", cmdFile.Name);
            if (!cmdFile.Found)
            {
                Warn_n("Batch file not found: " + cmdFile.Name, cmdFile.Path);
                return;
            }

            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/c " + cmdFile.Path;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
            
            Info_n("Standard Output:", p.StandardOutput.ReadToEnd());
            Warn_n("Standard Error:", p.StandardError.ReadToEnd());

            p.WaitForExit();
        }
コード例 #21
0
        private void ExecuteCmd(FileShim cmdFile)
        {
            Info_n("Running command from file...", cmdFile.Name);
            if (!cmdFile.Found)
            {
                Warn_n("Batch file not found: " + cmdFile.Name, cmdFile.Path);
                return;
            }

            Process p = new Process();

            p.StartInfo.FileName               = "cmd.exe";
            p.StartInfo.Arguments              = "/c " + cmdFile.Path;
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.CreateNoWindow         = true;
            p.Start();

            Info_n("Standard Output:", p.StandardOutput.ReadToEnd());
            Warn_n("Standard Error:", p.StandardError.ReadToEnd());

            p.WaitForExit();
        }
コード例 #22
0
ファイル: Throw.cs プロジェクト: orf53975/ErrH
 public static void Missing(FileShim fileShim)
 {
     throw Error.MissingFile(fileShim.Path);
 }
コード例 #23
0
ファイル: D7FileDownloader.cs プロジェクト: peterson1/ErrH
        private bool VerifyFile(FileShim actual, SyncableFileBase expctd)
        {
            var s = "Downloaded files is corrupted.";

            if (actual.Name != expctd.Name)
                return Error_n(s, $"expected name: {expctd.Name}  ==>  actual: {actual.Name}");

            if (actual.Size != expctd.Size)
                return Error_n(s, $"expected size: {expctd.Size.KB()}  ==>  actual: {actual.Size.KB()}");

            if (actual.SHA1 != expctd.SHA1)
                return Error_n(s, $"expected hash: {expctd.SHA1}  ==>  actual: {actual.SHA1}");

            return true;
        }