public async Task <IActionResult> syncMachineService(string postmethod) { string json = null; try { Request.EnableBuffering(); using (var stream = Request.Body) { using (var reader = new StreamReader(stream)) { json = await reader.ReadToEndAsync(); } } var service = JSON.Deserialize <Message>(json); if (service.id == "" || service.name == "") { return(Http.ResponseAjax(400, 400, "id or name not is not allowed!", Config.Instance)); } else { RDS.recvSync(service, postmethod); return(Http.ResponseAjax(200, 200, "Sync Write Service successful!", Config.Instance)); } } catch (Exception e) { LogHelper.Error(e, Config.logName); return(Http.ResponseAjax(500, 500, e.Message.ToString(), Config.Instance)); } }
public async Task <IActionResult> heartService() { string json = null; try { Request.EnableBuffering(); using (var stream = Request.Body) { using (var reader = new StreamReader(stream)) { json = await reader.ReadToEndAsync(); } } var service = JSON.Deserialize <Message>(json); if (service.id == "" || service.name == "") { return(Http.ResponseAjax(400, 400, "id or name not is not allowed!", Config.Instance)); } else { RDS.heartBeatPackage(service); Http.Send(service, "heartBeatPackage"); return(Http.ResponseAjax(200, 200, "The service is alive", Config.Instance)); } } catch (Exception e) { LogHelper.Error(e, Config.logName); return(Http.ResponseAjax(500, 500, e.Message.ToString(), Config.Instance)); } }
/// <summary> Change to the destination state. /// previously called ChangeDest /// </summary> /// <returns> /// </returns> private ErrorRtf changeDestState() { if (_destState == RDS.SKIP) { /* if we're skipping text, */ return(ErrorRtf.OK); /* don't do anything */ } _destState = RDS.SKIP; /* when in doubt, skip it... */ return(ErrorRtf.OK); }
/// <summary> Step 3. Search rgsymRtf for szKeyword and evaluate it appropriately. /// /// </summary> /// <param name="szKeyword"> /// </param> /// <param name="outputTxt"> /// </param> /// <returns> /// </returns> private ErrorRtf TranslateKeyword(String szKeyword, StringBuilder outputTxt) { int isym; ErrorRtf ret = ErrorRtf.OK; /* search for szKeyword in rgsymRtf */ for (isym = 0; isym < rgsymRtf.Length; isym++) { if (String.CompareOrdinal(szKeyword, rgsymRtf[isym].szKeyword) == 0) { break; } } if (isym == rgsymRtf.Length) /* control word not found */ { if (_skipDestIfUnk) { /* if this is a new destination */ _destState = RDS.SKIP; /* skip the destination */ } /* else just discard it */ _skipDestIfUnk = false; } else { ret = ErrorRtf.BAD_TABLE; /* found it! use kwd and idxInRgprop to determine what to do with it. */ _skipDestIfUnk = false; if (rgsymRtf[isym].kwd == KWD.PROP) { ret = validateProp((IPROP)rgsymRtf[isym].idxInRgprop); } else if (rgsymRtf[isym].kwd == KWD.CHAR) { ret = ParseChar(((char)((RtfChar)rgsymRtf[isym].idxInRgprop)), outputTxt); } else if (rgsymRtf[isym].kwd == KWD.DEST) { ret = changeDestState(); } else if (rgsymRtf[isym].kwd == KWD.SPEC) { ret = ParseSpecialKeyword((IPFN)rgsymRtf[isym].idxInRgprop); } } return(ret); }
/// <summary> Always restore relevant info from the top of the SAVE list. /// /// </summary> /// <returns> /// </returns> private ErrorRtf PopState() { StackSave savedPop = (StackSave)_stack.Pop(); if (savedPop == null) { return(ErrorRtf.STACK_UNDERFLOW); } _destState = RDS.getObj(savedPop.rds); _internalState = RIS.getObj(savedPop.ris); _group--; return(ErrorRtf.OK); }
/// <summary> Constructor /// /// </summary> public Rtf() { _stack = new Stack(); _group = 0; _cbBin = 0; _lParam = 0; _outputOnce = false; _skipDestIfUnk = false; _processCrlfSpecial = false; _destState = RDS.NORM; _internalState = RIS.NORM; _fontNum = 0; if (UtilStrByteMode.isLocaleDefLangDBCS()) { setCodePageTable(); } }
/// <summary> Save relevant info on a linked list of SAVE structures. /// /// </summary> /// <returns> /// </returns> private ErrorRtf PushState() { StackSave saveNew = new StackSave(); if (saveNew == null) { return(ErrorRtf.STACK_OVERFLOW); } saveNew.rds = RDS.getObj(_destState); saveNew.ris = RIS.getObj(_internalState); _internalState = RIS.NORM; _stack.Push(saveNew); _group++; return(ErrorRtf.OK); }
private static void BuildEnvironmentPage(AWSEnvironment environment) { try { if (!string.IsNullOrEmpty(environment.AccessKeyID) && !string.IsNullOrEmpty(environment.SecretAccessKey)) { foreach (var region in RegionEndpoint.EnumerableAllRegions) { if (string.Equals(region.SystemName, environment.Region)) { var allInstances = new List <AWSInstance>(); var rdsInstances = RDS.GetAllRDSInstances(environment, region); securityGroups = EC2.GetAllSecurityGroups(environment, region); allSubnets = EC2.GetAllAWSSubnets(environment, region); privateSubnets = SplitSubnets(false); publicSubnets = SplitSubnets(true); privateSubnets.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name)); publicSubnets.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name)); var ec2Instances = EC2.GetAllEC2Instances(environment, region); allInstances.AddRange(ec2Instances); allInstances.AddRange(rdsInstances); if (allInstances.Count > 0) { allInstances.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name)); foreach (var server in allInstances) { server.Icon = GetIconFromRole(server.Role); } BuildHTMLPage(environment, region, allInstances); } } } } else { Display.Error("AWS credentials are blank, unable to proceed with " + environment.Name); } } catch (Exception ex) { Logger.Log(LogLevel.Error, ex, "Exception in BuildEnvironmentPage()"); } }
public async Task <IActionResult> Register() { string json = null; try { Request.EnableBuffering(); using (var stream = Request.Body) { using (var reader = new StreamReader(stream)) { json = await reader.ReadToEndAsync(); } } //1、数据验证 if (string.IsNullOrEmpty(json)) { return(Http.ResponseAjax(400, 400, "The data is incomplete,Fail plaese again", Config.Instance, null)); } //2、接收请求数据并转化成为自己所需要的数据格式struct var service = JSON.Deserialize <Message>(json); if (service.id == "" || service.name == "") { return(Http.ResponseAjax(400, 400, "id or name not is not allowed!", Config.Instance)); } else { RDS.Register(service); Http.Send(service, "Register"); //这里data:不需要返回 return(Http.ResponseAjax(200, 200, "register service successful", Config.Instance, null)); } } catch (Exception e) { LogHelper.Error(e, Config.logName); return(Http.ResponseAjax(400, 400, e.Message.ToString(), Config.Instance, null)); } }
public static RDS getObj(RDS copyFrom) { if (copyFrom == NORM) { return(NORM); } else if (copyFrom == COLOR) { return(COLOR); } else if (copyFrom == SKIP) { return(SKIP); } else if (copyFrom == NEW) { return(NEW); } else { return(null); } }
/// <summary> Converts Rtf Text to Plain Text /// Step 1: Isolate RTF keywords and send them to ParseKeyword; Push and pop state at the start and end of /// RTF groups Send text to ParseChar for further processing. /// /// </summary> /// <param name="rtfTxt"> /// </param> /// <param name="outputTxt"> /// </param> /// <returns> /// </returns> public ErrorRtf toTxt(String rtfTxt, StringBuilder outputTxt) { long cNibble = 2; long b = 0; int currPos = 0; bool skipNewline = false; long blobStrLen; char blobChar; ErrorRtf ec; byte[] dbcsBytes = new byte[2]; bool skipParseChar = false; int charset = 0; int codePage = 0; _outputOnce = false; _processCrlfSpecial = false; blobStrLen = rtfTxt.Length; _index = 0; _destState = RDS.NORM; if (rtfTxt == null || blobStrLen == 0 || !isRtf(rtfTxt)) { return(ErrorRtf.OK); } while (_index < blobStrLen) { blobChar = rtfTxt[_index]; _index++; if (_group < 0) { return(ErrorRtf.STACK_UNDERFLOW); } /* if we're parsing binary data, handle it directly */ if (_internalState == RIS.BIN) { if ((ec = ParseChar(blobChar, outputTxt)) != ErrorRtf.OK) { return(ec); } } else { switch (blobChar) { case '{': skipNewline = false; if ((ec = PushState()) != ErrorRtf.OK) { return(ec); } break; case '}': skipNewline = true; if ((ec = PopState()) != ErrorRtf.OK) { return(ec); } break; case '\\': skipNewline = false; if ((ec = ParseKeyword(rtfTxt, outputTxt)) != ErrorRtf.OK) { return(ec); } break; case (char)RtfChar.LF: case (char)RtfChar.CR: /* cr and lf are noise characters... */ if (_processCrlfSpecial) { /* Once we reach the 0x0a while ProcessCRLFSpecial_, reset the ProcessCRLFSpecial_ */ if (blobChar == (char)RtfChar.LF) { _processCrlfSpecial = false; } } else { /*---------------------------------------------------------------*/ /* skip new lines coming only from the RTF header 1/1/98 - #2390 */ /*---------------------------------------------------------------*/ /* Skip the LF (0x0a) if we are not in the ProcessCRLFSpecial_ */ if (blobChar == (char)RtfChar.LF || (blobChar == (char)RtfChar.CR && skipNewline && !_outputOnce)) { break; } } goto default; default: if (blobChar != (char)RtfChar.CR) { skipNewline = false; } if (_internalState == RIS.NORM) { if ((ec = ParseChar(blobChar, outputTxt)) != ErrorRtf.OK) { return(ec); } } else if (_internalState == RIS.UNICODE) { if ((ec = ParseChar((char)_lParam, outputTxt)) != ErrorRtf.OK) { return(ec); } _internalState = RIS.NORM; } else { /* parsing hex data */ if (_internalState != RIS.HEX) { return(ErrorRtf.ASSERTION); } b = b << 4; if (Char.IsDigit(blobChar)) { b += (int)blobChar - (int)'0'; } else { if (Char.IsLower(blobChar)) { if (blobChar < 'a' || blobChar > 'f') { return(ErrorRtf.INVALID_HEX); } b += 10 + (int)blobChar - (int)'a'; } else { if (blobChar < 'A' || blobChar > 'F') { return(ErrorRtf.INVALID_HEX); } b += 10 + (int)blobChar - (int)'A'; } } cNibble--; if (cNibble == 0) { if (UtilStrByteMode.isLocaleDefLangDBCS()) { charset = getCharset(_fontNum); if (!skipParseChar && is1stByte(b, charset)) // leading byte of a double-byte character { dbcsBytes[0] = (byte)b; dbcsBytes[1] = (byte)0; skipParseChar = true; } else { if (skipParseChar && is2ndByte(b, charset)) // trailing byte of a double-byte character { dbcsBytes[1] = (byte)b; } else // single-byte character { dbcsBytes[0] = (byte)b; dbcsBytes[1] = (byte)0; } // convert DBCS to Unicode codePage = getCodePage(charset); string workStr = Encoding.GetEncoding(codePage).GetString(dbcsBytes, 0, 2); char[] workChar = workStr.ToCharArray(); b = (long)workChar[0]; skipParseChar = false; } } if (!skipParseChar) { if ((ec = ParseChar((char)b, outputTxt)) != ErrorRtf.OK) { return(ec); } } cNibble = 2; b = 0; _internalState = RIS.NORM; } } /* end else (ris != risNorm) */ break; } /* switch */ } /* else (ris != risBin) */ } /* while */ if (_group < 0L) { return(ErrorRtf.STACK_UNDERFLOW); } if (_group > 0L) { return(ErrorRtf.UNMATCHED_BRACE); } /*-------------------------------------------------------------------*/ /* Eliminate suffix of carrige return + line feed */ /* (Check last characters - just in case format is not the expected) */ /*-------------------------------------------------------------------*/ currPos = outputTxt.Length; if (currPos >= 3 && (outputTxt[currPos - 3] == (char)RtfChar.CR && outputTxt[currPos - 2] == (char)RtfChar.LF && outputTxt[currPos - 1] == (char)RtfChar.CR || outputTxt[currPos - 3] == (char)RtfChar.LF && outputTxt[currPos - 2] == (char)RtfChar.CR && outputTxt[currPos - 1] == (char)RtfChar.CR)) { outputTxt.Remove(currPos - 3, 3); } return(ErrorRtf.OK); }
public IActionResult getService(string service_name) { //get 获取name参数方法二 // var name = Request.Query["name"].ToString(); try { return(ResponseAjax(200, 200, "getService successful", Config.Instance, RDS.GetService(service_name))); } catch (Exception e) { LogHelper.Error(e, Config.logName); return(ResponseAjax(500, 500, e.Message.ToString() + "Server exception! Please contact the administrator", Config.Instance)); } }