public void Execute() { if (_missingInputs.Any()) { Logger.Trace("Missing Inputs:"); Logger.Trace("---------------"); _missingInputs.Each(x => Console.WriteLine(x)); ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "MissingInput: " + Exc.Join(",", _missingInputs)); } Logger.Starting(_steps.Count); _substitutions.Trace(Logger); _substitutions.Set(INSTRUCTIONS, GetInstructions().Replace("\"", "'")); _steps.Each(x => { Logger.TraceStep(x); x.Alter(this); }); if (Solution != null) { Logger.Trace("Saving solution to {0}", Solution.Filename); Solution.Save(); } Substitutions.WriteTo(Root.AppendPath(Substitutions.ConfigFile)); WriteNugetImports(); Logger.Finish(); }
private static SlnFolder GetRootFolder(IEnumerable <SlnProject> projects) { List <string> paths = projects.Where(i => !i.IsMainProject).Select(i => Directory.GetParent(i.FullPath).FullName).ToList(); if (!paths.Any()) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), string.Empty); } // TODO: Unit tests, optimize string commonPath = string.Empty; List <string> separatedPath = paths .First(str => str.Length == paths.Max(st2 => st2.Length)) .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries) .ToList(); string nextPath = null; foreach (string pathSegment in separatedPath.AsEnumerable()) { if (commonPath.Length == 0 && paths.All(str => str.StartsWith(pathSegment))) { commonPath = pathSegment + Path.DirectorySeparatorChar; } else if (paths.All(str => str.StartsWith(nextPath = $"{commonPath}{pathSegment}{Path.DirectorySeparatorChar}"))) { commonPath = nextPath; } else { break; } } return(new SlnFolder(commonPath.TrimEnd(Path.DirectorySeparatorChar))); }
public void Close() { if (((_sampleLen * _blockAlign) & 1) == 1) { _bw.Write((byte)0); } try { if (_sampleLen != _finalSampleLen) { if (_canSeek) { uint dataChunkSize = GetDataChunkSize(_sampleLen); _bw.Seek(4, SeekOrigin.Begin); _bw.Write((uint)(dataChunkSize + (dataChunkSize & 1) + 36)); _bw.Seek(40, SeekOrigin.Begin); _bw.Write((uint)dataChunkSize); } else { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(),ExtractionException("Samples written differs from the expected sample count."); } } } finally { _bw.Dispose(); _bw = null; } }
/// <summary> /// Výchozí pro A1 je Microsoft /// </summary> /// <param name="sl"></param> public JavascriptSerialization(SerializationLibrary sl) { this.sl = sl; switch (sl) { case SerializationLibrary.Microsoft: utf8json = JsonUtf8Json.instance; //ThrowExceptionsMicrosoftSerializerNotSupported<object>(); break; case SerializationLibrary.Newtonsoft: utf8json = JsonUtf8Json.instance; break; case SerializationLibrary.SystemTextJson: utf8json = JsonUtf8Json.instance; break; case SerializationLibrary.JsonDanielCrenna: utf8json = JsonUtf8Json.instance; break; case SerializationLibrary.Utf8Json: utf8json = JsonUtf8Json.instance; break; default: ThrowExceptions.NotImplementedCase(Exc.GetStackTrace(), type, Exc.CallingMethod(), sl); break; } }
private async Task ThrowExceptionAsync() { await Task.Delay(1); // Stop working whole app ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), ""); }
public void ExtractStreams() { uint dataOffset; _videoTimeStamps = new List<uint>(); Seek(0); if (_fileLength < 4 || ReadUInt32() != 0x464C5601) { if (_fileLength >= 8 && ReadUInt32() == 0x66747970) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(),ExtractionException("This is a MP4 file. YAMB or MP4Box can be used to extract streams."); } ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(),ExtractionException("This isn't a FLV file."); } ReadUInt8(); dataOffset = ReadUInt32(); Seek(dataOffset); ReadUInt32(); while (_fileOffset < _fileLength) { if (!ReadTag()) break; if ((_fileLength - _fileOffset) < 4) break; ReadUInt32(); double progress = (this._fileOffset * 1.0 / this._fileLength) * 100; if (this.ProgressChanged != null) { this.ProgressChanged(this, new ProgressEventArgs(progress)); } } _averageFrameRate = CalculateAverageFrameRate(); _trueFrameRate = CalculateTrueFrameRate(); CloseOutput(_averageFrameRate); }
public ProjectRequest BuildProjectRequest(TemplateChoices choices) { if (choices.Category.IsEmpty()) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "Category is required"); } if (choices.ProjectName.IsEmpty()) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "ProjectName is required"); } var category = FindCategory(choices.Category); if (category == null) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "Category '{0}' is unknown".ToFormat(choices.Category)); } var project = category.FindTemplate(choices.ProjectType); if (project == null) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "ProjectTemplate '{0}' for category {1} is unknown".ToFormat(choices.ProjectType, choices.Category)); } return(project.BuildProjectRequest(choices)); }
public static SlnProject FromProject(Project project, IReadOnlyDictionary <string, Guid> customProjectTypeGuids, bool isMainProject = false) { if (project == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), nameof(project)); } if (customProjectTypeGuids == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), nameof(customProjectTypeGuids)); } if (!ShouldIncludeInSolution(project)) { return(null); } string name = project.GetPropertyValueOrDefault(SlnConstants.AssemblyName, Path.GetFileNameWithoutExtension(project.FullPath)); bool isUsingMicrosoftNetSdk = project.GetPropertyValue(SlnConstants.UsingMicrosoftNETSdk).Equals("true", StringComparison.OrdinalIgnoreCase); string extension = Path.GetExtension(project.FullPath); Guid projectTypeGuid = GetKnownProjectTypeGuid(extension, isUsingMicrosoftNetSdk, customProjectTypeGuids); IEnumerable <string> configurations = project.GetPossiblePropertyValuesOrDefault("Configuration", "Debug"); IEnumerable <string> platforms = GetPlatforms(project); Guid projectGuid = Guid.NewGuid(); if (!isUsingMicrosoftNetSdk && !Guid.TryParse(project.GetPropertyValueOrDefault(SlnConstants.ProjectGuid, projectGuid.ToString()), out projectGuid)) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), $"property ProjectGuid has an invalid format in {project.FullPath}"); } string isDeployableStr = project.GetPropertyValue("SlnGenIsDeployable"); bool isDeployable = isDeployableStr.Equals("true", StringComparison.OrdinalIgnoreCase) || (string.IsNullOrWhiteSpace(isDeployableStr) && string.Equals(Path.GetExtension(project.FullPath), ".sfproj", StringComparison.OrdinalIgnoreCase)); return(new SlnProject(project.FullPath, name, projectGuid, projectTypeGuid, configurations, platforms, isMainProject, isDeployable)); }
/// <summary> /// Return object is object /// /// </summary> /// <param name="orderId"></param> /// <param name="payment"></param> /// <returns></returns> public object CreatePayment(string orderId, BaseComGatePayment payment, params object[] args) { Payer customer = new Payer(); string buyerMail = null; if (args.Length == 0) { try { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "args was empty. Is used " + CmConsts.Email); } catch (Exception) { } buyerMail = CmConsts.Email; } else { buyerMail = args[0].ToString(); } customer.Contact = new Contact() { Email = buyerMail, Name = buyerMail }; //var payment = CreateBasePayment(orderId); payment.PrepareOnly = true; // CreatePaymentAsync,CreatePayment - working in Cmd // CreatePayment - working in APp, CreatePaymentAsync - not working in APp ApiResponse <PaymentResponse> response = comGateAPI.CreatePayment(payment, customer, CmConsts.api); if (response.Response == null) { var m = response.Message; if (m.StartsWith(ComgateNotTranslateAble.afulStart)) { var uriManage = ComgateNotTranslateAble.uriManage; var ip = m.Replace(ComgateNotTranslateAble.afulStart, string.Empty); ip = ip.Replace(ComgateNotTranslateAble.afulEnd, string.Empty); //Clipboard.SetText(ip); Process.Start(uriManage); Debug.WriteLine("Insert " + ip + " to " + uriManage); //Access from unauthorized location [37. 188.150.241]! } } var pc = new CreatePaymentResult { pc = response.Response, error = response.Message }; // cant here check for null, coz there is not ErrorCapture (webforms) return(pc); }
/// <summary> /// Generates a C# designer class. /// </summary> /// <param name="resXFile">The source resx file.</param> /// <param name="className">The base class name.</param> /// <param name="namespaceName">The namespace for the generated code.</param> /// <param name="publicClass">Specifies if the class has public or public access level.</param> /// <returns>false if generation of at least one property failed.</returns> public static bool GenerateDesignerFile(string resXFile, string className, string namespaceName, bool publicClass) { if (!File.Exists(resXFile)) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), $"The file '{resXFile}' could not be found"); } if (string.IsNullOrEmpty(className)) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), $"The class name must not be empty or null"); } if (string.IsNullOrEmpty(namespaceName)) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), $"The namespace name must not be empty or null"); } string[] unmatchedElements; //System.Resources.Tools. var codeProvider = new Microsoft.CSharp.CSharpCodeProvider(); System.CodeDom.CodeCompileUnit code = StronglyTypedResourceBuilder.Create( resXFile, className, namespaceName, codeProvider, publicClass, out unmatchedElements); var designerFileName = Path.Combine(Path.GetDirectoryName(resXFile), $"{className}.Designer.cs"); using (StreamWriter writer = new StreamWriter(designerFileName, false, System.Text.Encoding.UTF8)) { codeProvider.GenerateCodeFromCompileUnit(code, writer, new System.CodeDom.Compiler.CodeGeneratorOptions()); } return(unmatchedElements.Length == 0); }
public async Task AsyncMethodException() { // This method would do some async call (possible IO). // For the example, we will throw an exception to show as an example how\ // the exception will be swollowed by not calling await. ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), ""); }
/// <summary> /// Initializes a new instance of the <see cref="MSBuildProjectLoader"/> class. /// </summary> /// <param name="globalProperties">Specifies the global properties to use when loading projects.</param> /// <param name="toolsVersion">Specifies the ToolsVersion to use when loading projects.</param> /// <param name="buildEngine">An <see cref="IBuildEngine"/> object to use for logging.</param> /// <param name="projectLoadSettings">Specifies the <see cref="ProjectLoadSettings"/> to use when loading projects.</param> public MSBuildProjectLoader(IDictionary <string, string> globalProperties, string toolsVersion, IBuildEngine buildEngine, ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default) { _globalProperties = globalProperties; _toolsVersion = toolsVersion; _projectLoadSettings = projectLoadSettings; ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), nameof(buildEngine), buildEngine); _buildEngine = buildEngine; }
public DateFilesEnumerator(IEnumerable <FileInfo> filesList) { if (filesList == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "filesList"); } this.filesListOrderedByDate = filesList.OrderBy(f => f.LastWriteTime).ToList(); }
public virtual GeoPoint ConvertTo(Ellipsoid referenceEllipsoid) { if (this.ReferenceEllipsoid == referenceEllipsoid) { return(this); } ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "Conversion between different reference ellipsoids is not yet implemented"); return(null); }
public CollageSaver(DirectoryInfo outputDirectory) { if (outputDirectory == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "outputDirectory"); } this.fileNameCreator = new FileNameCreator(outputDirectory); }
/// <summary> /// Represents a target framework version /// </summary> /// <param name="version">In the form v2.0, v3.5, v4.0, v4.5, v4.5.1 etc...</param> public TargetFrameworkVersion(string version) { if (string.IsNullOrWhiteSpace(version)) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "version"); } this.version = new Version(version.TrimStart(new[] { 'v' })); }
/// <summary> /// Creates a <see cref="FlvExtractor"/> that extracts only the video track. /// </summary> /// <param name="inputStream">The input stream. This is your raw FLV data.</param> /// <param name="outputStream">The video output stream. This is the stream that the video track gets written to.</param> public static FlvExtractor CreateVideoExtractor(Stream inputStream, Stream outputStream) { if (inputStream == null) ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(),ArgumentNullException("inputStream"); if (outputStream == null) ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(),ArgumentNullException("outputStream"); var file = new FLVFile(inputStream, videoOutputStream: outputStream); return new FlvExtractor { file = file, infoFunc = () => new ExtractionInfo(file.VideoFormat) }; }
private void WriteFourCC(string fourCC) { byte[] bytes = General.StringToAscii(fourCC); if (bytes.Length != 4) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(),ExtractionException("Invalid FourCC length."); } _bw.Write(bytes); }
public static string GetAttributeIfExists(XElement node, string name) { if (node == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), (nameof(node))); } var a = node.Attribute(name); return(a != null ? a.Value : string.Empty); }
public static int GetIntAttributeIfExists(XElement node, string name) { if (node == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), nameof(node)); } var a = node.Attribute(name); return(a != null?int.Parse(a.Value) : 0); }
public RandomFilesEnumerator(List <FileInfo> filesList) { if (filesList == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "filesList"); } this.filesList = filesList; this.randomGenerator = new RandomGenerator(); }
private static string ParseText(string tesseractPath, byte[] imageFile, params string[] lang) { foreach (var item in lang) { if (item == "enu") { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "Use right eng, not enu!!!"); return(null); } } string output = string.Empty; var tempOutputFile = Path.GetTempPath() + Guid.NewGuid(); var tempImageFile = Path.GetTempFileName(); try { File.WriteAllBytes(tempImageFile, imageFile); ProcessStartInfo info = new ProcessStartInfo(); info.WorkingDirectory = tesseractPath; info.WindowStyle = ProcessWindowStyle.Hidden; info.UseShellExecute = false; info.FileName = "cmd.exe"; info.Arguments = "/" + "c tesseract.exe" + " " + // Image file. tempImageFile + AllStrings.space + // Output file (tesseract add '.txt' at the end) tempOutputFile + // Languages. " -l " + string.Join("+", lang); // Start tesseract. Process process = Process.Start(info); process.WaitForExit(); if (process.ExitCode == 0) { // Exit code: success. output = FS.ReadAllText(tempOutputFile + ".txt"); } else { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "Error. Tesseract stopped with an error code" + " " + "" + " " + process.ExitCode); } } finally { File.Delete(tempImageFile); File.Delete(tempOutputFile + ".txt"); } return(output); }
public SlnProject(string fullPath, string name, Guid projectGuid, Guid projectTypeGuid, IEnumerable <string> configurations, IEnumerable <string> platforms, bool isMainProject, bool isDeployable) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), nameof(fullPath)); ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), nameof(name)); ProjectGuid = projectGuid; ProjectTypeGuid = projectTypeGuid; IsDeployable = isDeployable; IsMainProject = isMainProject; Configurations = new HashSet <string>(configurations, StringComparer.OrdinalIgnoreCase); Platforms = new HashSet <string>(platforms, StringComparer.OrdinalIgnoreCase); }
private void ValidateValue(int value) { if (value < 0) { ThrowExceptions.ArgumentOutOfRangeException(Exc.GetStackTrace(), type, Exc.CallingMethod(), "value", "Value must be greater or equal 0"); } if (value > 100) { ThrowExceptions.ArgumentOutOfRangeException(Exc.GetStackTrace(), type, Exc.CallingMethod(), "value", "Value must be less or equal 100"); } }
public CodeFileTemplate(string relativePath, string rawText) { if (Path.GetExtension(relativePath) != ".cs") { ThrowExceptions.ArgumentOutOfRangeException(Exc.GetStackTrace(), type, Exc.CallingMethod(), "relativePath", "Relative Path must have the .cs extension"); } _relativePath = relativePath.Replace('\\', '/'); _rawText = rawText; }
/// <summary> /// /// </summary> static Task <IEnumerable <string> > TestTask() { var task = new Task <IEnumerable <string> >(() => { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), ""); return(null); }); task.Start(); Task.Delay(1000); return(task); }
public FileInfo Save(Bitmap bitmap) { if (bitmap == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "bitmap"); } var fileName = this.fileNameCreator.CreateFileName(); bitmap.Save(fileName, ImageFormat.Jpeg); bitmap.Dispose(); return(new FileInfo(fileName)); }
public FileNameCreator(DirectoryInfo outputDirectory) { if (outputDirectory == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "outputDirectory"); } if (!outputDirectory.Exists) { ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "Output directory does not exist"); } this.OutputDirectory = outputDirectory; }
private IAudioWriter GetAudioWriter(uint mediaInfo) { uint format = mediaInfo >> 4; uint rate = (mediaInfo >> 2) & 0x3; uint bits = (mediaInfo >> 1) & 0x1; uint chans = mediaInfo & 0x1; switch (format) { case 14: case 2: return new MP3Writer(this.audioOutputStream, _warnings); case 3: case 0: { // PCM int sampleRate = 0; switch (rate) { case 0: sampleRate = 5512; break; case 1: sampleRate = 11025; break; case 2: sampleRate = 22050; break; case 3: sampleRate = 44100; break; } if (format == 0) { _warnings.Add("PCM byte order unspecified, assuming little endian."); } return new WAVWriter(this.audioOutputStream, (bits == 1) ? 16 : 8, (chans == 1) ? 2 : 1, sampleRate); } case 10: return new AACWriter(this.audioOutputStream); case 11: return new SpeexWriter(this.audioOutputStream, (int)(_fileLength & 0xFFFFFFFF)); } string typeStr; switch (format) { case 1: typeStr = "ADPCM"; break; case 6: case 5: case 4: typeStr = "Nellymoser"; break; default: typeStr = "format=" + format; break; } ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(),ExtractionException("Unable to extract audio (" + typeStr + " is unsupported)."); }
public CollageGenerator(CollageSettings settings) { if (settings == null) { ThrowExceptions.IsNull(Exc.GetStackTrace(), type, Exc.CallingMethod(), "settings"); } this.settings = settings; this.progressCounter = new ProgressCounter(settings.Dimensions.NumberOfRows, settings.Dimensions.NumberOfColumns); this.randomGenerator = new RandomGenerator(); this.tileTransformer = new TileTransformer(); this.filesEnumerator = new DateFilesEnumerator(settings.InputFiles); this.collageSaver = new CollageSaver(settings.OutputDirectory); }