//TODO: add detection & resolution of duplicate names public static TypeMember WebApiController(TypeMember middlewareType, WebApiMetadata api) => PUBLIC.CLASS(ID(api.InterfaceType.Name.TrimPrefixFragment("I"), "Controller"), () => { EXTENDS <Controller>(); ATTRIBUTE <RouteAttribute>("api/[controller]"); PRIVATE.READONLY.FIELD(api.InterfaceType, "_service", out var @serviceField); PUBLIC.CONSTRUCTOR(() => { PARAMETER(api.InterfaceType, "service", out var @service); @serviceField.ASSIGN(@service); }); api.ApiMethods.ForEach(apiMethod => { var requestClass = DataTransferObjectGenerator.MethodInvocation(apiMethod); PUBLIC.ASYNC.FUNCTION <Task <IActionResult> >(apiMethod.Name, () => { ATTRIBUTE(middlewareType); ATTRIBUTE <HttpPostAttribute>(apiMethod.Name.ToString(CasingStyle.Camel)); PARAMETER(requestClass, "requestData", out MethodParameter @requestData, () => { ATTRIBUTE <FromBodyAttribute>(); }); LOCAL(apiMethod.ReturnType.GenericArguments[0], "resultValue", out LocalVariable resultValueLocal); resultValueLocal.ASSIGN( AWAIT(THIS.DOT(@serviceField).DOT(apiMethod).INVOKE(() => { apiMethod.Signature.Parameters.ForEach(p => ARGUMENT(@requestData.DOT(p.Name.ToString(CasingStyle.Pascal)))); })) ); DO.RETURN(THIS.DOT("Json").INVOKE(resultValueLocal)); }); });
static void Main(string[] args) { var type = CreateInterfaceImpType <IExample>(new { WriteLine = (Action <IExample, string>)((IExample THIS, string str) => { Console.WriteLine(THIS.GetType().Name + ", " + str); }) }); var instance = (IExample)Activator.CreateInstance(type); instance.WriteLine("XuPeiYao"); Console.ReadKey(); }
bool CashFile(int ID) { bool result = false; divFile = (HtmlElement)THIS.Invoke(GetElement, "d.file." + ID); try { String tmpDir = tmpFolder + File[ID].Path; if (!System.IO.Directory.Exists(tmpDir)) { try { System.IO.Directory.CreateDirectory(tmpDir); } catch { } } if (!cancellationToken.IsCancellationRequested) { System.IO.File.Copy(SourceFolder + File[ID].Path + File[ID].File, System.IO.Path.Combine(tmpDir, File[ID].File), true); result = true; divFile.InnerHtml += "Cash " + HTMLSpanOK(); } } catch (Exception e) { divFile.InnerHtml += "Cash " + HTMLSpanFAULT() + " " + HTMLTagSpan(e.Message, CSS_BaseAlert) + " " + SourceFolder + File[ID].Path + File[ID].File + " " + tmpFolder; } return(result); }
public CopyFilesQueue(string SourceFld, String TargetFld /*, WebBrowser Browser*/, CheckedListBox chkList, CancellationToken cancellationToken, delegateCreateElement c, delegateUpdateElement u, delegateGetElement g, delegateProgressBar PM, delegateProgressBar PV ) { this.SetProgressBarMaximum = PM; this.SetProgressBarValue = PV; this.SourceFolder = SourceFld; this.cancellationToken = cancellationToken; this.CreateElement = c; this.UpdateElement = u; this.GetElement = g; TargetFld = TargetFld.Trim(); if (!TargetFld.EndsWith("\\")) { TargetFld += "\\"; } this.TargetFolder = @"\" + TargetFld.Substring(0, 1) + @"$" + TargetFld.Substring(2); BaseFolderLenght = SourceFolder.Length; divFile = (HtmlElement)THIS.Invoke(CreateElement, "div"); divFile.SetAttribute("id", "div.Files"); StringBuilder Output = new StringBuilder(); GetFolder(SourceFolder, Output); Output.Append("Total " + File.Count + " files<br>"); divFile.InnerHtml = Output.ToString() + _BRLF; THIS.BeginInvoke(UpdateElement, divFile); divHost = (HtmlElement)THIS.Invoke(CreateElement, "div"); divHost.SetAttribute("id", "div.Hosts"); divHost.InnerHtml = HTMLTagSpan("Host list:", CSS_BaseHighLight) + _BRLF; GetHost(chkList); THIS.BeginInvoke(UpdateElement, divHost); THIS.BeginInvoke(UpdateElement, divFile); Host.ForEach(h => h.FCount = File.Count); THIS.BeginInvoke(SetProgressBarMaximum, File.Count * Host.Count); }
public void Copy() { try { //TODO: Если исходные файлв не на локальном ПК #region Temporary folder tmpFolder = Environment.GetEnvironmentVariable("tmp"); if (String.IsNullOrEmpty(tmpFolder)) { tmpFolder = Environment.GetEnvironmentVariable("temp"); if (String.IsNullOrEmpty(tmpFolder)) { tmpFolder = Environment.GetEnvironmentVariable("HOMEDRIVE"); if (String.IsNullOrEmpty(tmpFolder)) { tmpFolder = "C:"; } tmpFolder += @"\TMP"; } } tmpFolder += @"\" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".TMP\\"; HtmlElement htmltmpfolder = (HtmlElement)THIS.Invoke(CreateElement, "span"); htmltmpfolder.SetAttribute("id", "tmpFolder"); htmltmpfolder.InnerHtml = HTMLTagSpan("Temporary folder:", CSS_BaseHighLight) + tmpFolder; try { System.IO.Directory.CreateDirectory(tmpFolder); } catch { htmltmpfolder.InnerHtml += HTMLSpanFAULT() + " " + HTMLTagSpan("Failed to create temporary folder " + tmpFolder, CSS_BaseAlert); } finally { THIS.Invoke(UpdateElement, htmltmpfolder); } if (!System.IO.Directory.Exists(tmpFolder)) { throw new System.Exception("Failed to create temporary folder " + tmpFolder); } #endregion for (int idf = 0; idf != File.Count; idf++)//foreach (FileInfo f in File) { if (cancellationToken.IsCancellationRequested) { break; } if (!CashFile(idf)) { divFile = (HtmlElement)THIS.Invoke(GetElement, "l.file." + idf); divFile.InnerHtml += HTMLSpanFAULT(); THIS.BeginInvoke(SetProgressBarValue, Host.Count); } else { for (int idh = 0; idh != Host.Count; idh++)// foreach (HostInfo h in Host) { THIS.BeginInvoke(SetProgressBarValue, 1); if (cancellationToken.IsCancellationRequested) { break; } divHost = (HtmlElement)THIS.Invoke(GetElement, "d.host." + idh); StringBuilder Output = new StringBuilder(); bool local_result = false; //try{if (Ping(Host[idh].Name))local_result = true;}catch {} //if (!local_result) { // Output.Append("Ping "+HTMLSpanFAULT()+_BRLF); // divHost.InnerHtml += Output.ToString(); // divHost = (HtmlElement)THIS.Invoke(GetElement, "l.host." + idh); // divHost.InnerHtml += HTMLSpanFAULT(); // continue; //} String FullTargetFolder = @"\\" + Host[idh].Name + this.TargetFolder + File[idf].Path; Output.Append("Copy " + this.SourceFolder + File[idf].Path + File[idf].File + " to " + FullTargetFolder + File[idf].File); if (!System.IO.Directory.Exists(FullTargetFolder)) { local_result = false; try { System.IO.Directory.CreateDirectory(FullTargetFolder); local_result = System.IO.Directory.Exists(FullTargetFolder); } catch (Exception e) { Output.Append(HTMLSpanFAULT() + HTMLTagSpan(e.Message, CSS_BaseAlert) + _BRLF); } if (!local_result) { divHost.InnerHtml += Output.ToString(); if (Host[idh].Status == 0) { divHost = (HtmlElement)THIS.Invoke(GetElement, "l.host." + idh); divHost.InnerHtml += HTMLSpanFAULT(); Host[idh].Status = 2; } continue; } } local_result = false; try { System.IO.File.Copy(tmpFolder + File[idf].Path + File[idf].File, FullTargetFolder + File[idf].File, true); local_result = true; Output.Append(HTMLSpanOK()); } catch (Exception e) { Output.Append(HTMLSpanFAULT() + HTMLTagSpan(e.Message, CSS_BaseAlert)); } Output.Append(_BRLF); divHost.InnerHtml += Output.ToString(); if (!local_result) { if (Host[idh].Status == 0) { divHost = (HtmlElement)THIS.Invoke(GetElement, "l.host." + idh); divHost.InnerHtml += HTMLSpanFAULT(); Host[idh].Status = 2; } } else { Host[idh].FCount--; if (Host[idh].FCount == 0 && Host[idh].Status == 0) { divHost = (HtmlElement)THIS.Invoke(GetElement, "l.host." + idh); divHost.InnerHtml += HTMLSpanOK(); Host[idh].Status = 1; } } } } } } catch { } finally { if (System.IO.Directory.Exists(tmpFolder)) { HtmlElement htmltmpfoler = (HtmlElement)THIS.Invoke(GetElement, "tmpFolder"); htmltmpfoler.InnerHtml += " delete"; System.IO.Directory.Delete(tmpFolder, true); if (System.IO.Directory.Exists(tmpFolder)) { htmltmpfoler.InnerHtml += HTMLSpanFAULT(); } else { htmltmpfoler.InnerHtml += HTMLSpanOK(); } } } }
static void HandleDoublePlaceholderTemplateMethod( ref ClassDeclarationSyntax updatedDecl, MethodDeclarationSyntax mtd, EnumerableDetails builtIn, IEnumerable <EnumerableDetails> allBuiltIns, IEnumerable <EnumerableDetails> allEnumerables, string[] outTypeStrs ) { var outTypes = outTypeStrs.Select(t => SyntaxFactory.ParseTypeName(t)).ToArray(); var expanded = ExpandDoubleParameterizedFromPlaceholders(mtd, outTypes, builtIn, allBuiltIns, allEnumerables); var extensions = new List <MethodDeclarationSyntax>(); foreach (var bound in expanded) { var firstParam = bound.ParameterList.Parameters.First(); var withThisStr = THIS.ToFullString() + firstParam.ToFullString(); var withThis = SyntaxFactory.ParseParameterList(withThisStr).Parameters.ElementAt(0); var updated = bound.ReplaceNode(firstParam, withThis); var modifiers = new SyntaxToken[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword).WithTriviaFrom(updated.Modifiers.First()), SyntaxFactory.Token(SyntaxKind.StaticKeyword).WithTrailingTrivia(SyntaxFactory.Whitespace(" ")) }; var modifiersList = SyntaxFactory.TokenList(modifiers); updated = updated.WithModifiers(modifiersList); extensions.Add(updated); } var bridgesReplaced = new List <MethodDeclarationSyntax>(); foreach (var extension in extensions) { var updated = ReplaceBridgeCalls(extension); bridgesReplaced.Add(updated); } var refLocalsReplaced = new List <MethodDeclarationSyntax>(); foreach (var bridged in bridgesReplaced) { var updated = bridged; ReplaceRefLocalCalls(ref updated); refLocalsReplaced.Add(updated); } var refParamsReplaced = new List <MethodDeclarationSyntax>(); foreach (var deLocaled in refLocalsReplaced) { var updated = deLocaled; ReplaceRefParamCalls(ref updated); refParamsReplaced.Add(updated); } updatedDecl = updatedDecl.AddMembers(refParamsReplaced.ToArray()); }