예제 #1
0
 public static short SetIfNot(this DoType d, bool b)
 {
     if (d.Sts().Value == b)
     {
         return(0);
     }
     return(d.Set(b));
 }
예제 #2
0
        public static Sts Sts(this DoType d)
        {
            DO o = DOMgr.Instance.FindBy((int)d);

            if (o == null)
            {
                return(new Infrastructure.Sts());
            }
            return(o.Status);
        }
예제 #3
0
        public static short Set(this DoType d, bool b)
        {
            DO o = DOMgr.Instance.FindBy((int)d);

            if (o == null)
            {
                return(-1);
            }
            return(o.Set(b));
        }
예제 #4
0
        // 簡單工廠模式
        public void SetStrategy(DoType doType)
        {
            switch (doType)
            {
            case DoType.Add:
                this.strategy = new Add();
                break;

            case DoType.Minus:
                this.strategy = new Minus();
                break;

            case DoType.Divide:
                this.strategy = new Divide();
                break;

            case DoType.Multyply:
                this.strategy = new Multyply();
                break;
            }
        }
예제 #5
0
 public DoSomethingEventArgs(DoEventType eventType, DoType doType)
 {
     MyEventType = eventType;
     MyDoType    = doType;
 }
예제 #6
0
        private async Task <ServiceResult <TResult> > ResolveHttpResponseAsync <TResult>(DoType type, int retryCount, IFlurlRequest webApiObject, object bodyObject = null, int secondsTimeout = 30, string callerMemberName = null)
        {
            var                 _retMessage = "";
            ReturnMessage       _message;
            HttpResponseMessage _exec           = null;
            HttpStatusCode      _HttpStatusCode = HttpStatusCode.BadRequest;

            var _policyResult = await Policy
                                .Handle <FlurlHttpTimeoutException>().Or <FlurlHttpException>().Or <Exception>()
                                .RetryAsync(retryCount, (exception, retryNumber) =>
            {
                System.Diagnostics.Debug.WriteLine($"==================================================================");
                System.Diagnostics.Debug.WriteLine($"Method: {callerMemberName} -> Retry: number#{retryNumber} -> exception:{exception.Message}");
                System.Diagnostics.Debug.WriteLine($"==================================================================");
            })
                                .ExecuteAndCaptureAsync(new Func <Task <ServiceResult <TResult> > >(async() =>
            {
                var _token   = this.GetCancelationToken(secondsTimeout).Token;
                var _content = "";

#if DEBUG
                var _json = JsonConvert.SerializeObject(bodyObject);
#endif
                switch (type)
                {
                case DoType.Get:
                    _exec = await webApiObject.GetAsync(_token);
                    break;

                case DoType.Post:
                    _exec = await webApiObject.PostJsonAsync(bodyObject, _token);
                    break;

                case DoType.Put:
                    _exec = await webApiObject.PutJsonAsync(bodyObject, _token);
                    break;

                case DoType.Delete:
                    _exec = bodyObject == null ? await webApiObject.DeleteAsync(_token) : await webApiObject.SendJsonAsync(HttpMethod.Delete, bodyObject, _token);
                    break;
                }

                switch (_exec.StatusCode)
                {
                case HttpStatusCode.OK:
                    switch (type)
                    {
                    case DoType.Get:
                    case DoType.Post:
                    case DoType.Put:
                        // lê o retorno do serviço
                        var _stringContent = await _exec.Content.ReadAsStringAsync();

                        // checa se está nulo, se estiver manda uma string vazia
                        _stringContent = string.IsNullOrEmpty(_stringContent) ? "" : _stringContent;

                        // vê se o conteúdo é um json, se não for, formatamos para que seja
                        TResult _result = default(TResult);

                        if (this.IsValidJson(_stringContent))
                        {
                            _result = JsonConvert.DeserializeObject <TResult>(_stringContent);
                        }
                        else
                        {
                            _result = (TResult)Convert.ChangeType(_stringContent, typeof(TResult), CultureInfo.CurrentCulture);
                        }

                        // retornamos o resultado deserializando no formato informado
                        return(new ServiceResult <TResult>(_result, true, _exec.StatusCode));

                    case DoType.Delete:
                        object _RetBool = true;
                        return(new ServiceResult <TResult>((TResult)_RetBool, true, _exec.StatusCode));
                    }
                    break;

                case HttpStatusCode.Unauthorized:
                    _retMessage = $"Você não está autorizado a executar essa rotina: {callerMemberName}!\r\nPor favor contacte o suporte.";
                    break;

                case HttpStatusCode.InternalServerError:
                case HttpStatusCode.BadRequest:
                    _content = await _exec.Content.ReadAsStringAsync();
                    try
                    {
                        _message    = JsonConvert.DeserializeObject <ReturnMessage>(_content);
                        _retMessage = _message.Message;
                    }
                    catch (Exception)
                    {
                        _retMessage = _content;
                    }

                    break;

                case HttpStatusCode.NoContent:
                    return(new ServiceResult <TResult>(default(TResult), false, _exec.StatusCode));

                case HttpStatusCode.NotFound:
                    return(new ServiceResult <TResult>(default(TResult), false, _exec.StatusCode));

                default:
                    _content    = await _exec.Content.ReadAsStringAsync();
                    _message    = JsonConvert.DeserializeObject <ReturnMessage>(_content);
                    _retMessage = $"Ocorreu um erro ao executar operação na rotina {callerMemberName}!\r\nPor favor contacte o suporte:\r\n\r\n{_message.Message}";
                    break;
                }
                _HttpStatusCode = _exec.StatusCode;
                return(new ServiceResult <TResult>(default(TResult), false, _HttpStatusCode, _retMessage));
            }));

            if (_policyResult.Outcome == OutcomeType.Successful)
            {
                return(_policyResult.Result);
            }
            else
            {
                switch (_policyResult.FinalException)
                {
                case FlurlHttpTimeoutException fhtex:
                    _HttpStatusCode = HttpStatusCode.GatewayTimeout;
                    _retMessage     = $"O tempo para execução desta tarefa expirou!Rotina{callerMemberName}\r\nTente novamente em alguns segundos.";
                    break;

                case FlurlHttpException fhex:
                    string _retString = fhex.Message;
                    if (fhex.Call.HttpStatus.HasValue)
                    {
                        _HttpStatusCode = fhex.Call.HttpStatus.Value;
                        switch (fhex.Call.HttpStatus.Value)
                        {
                        case HttpStatusCode.InternalServerError:
                        case HttpStatusCode.BadRequest:
                            _retMessage = fhex.Call.Response.Content.ReadAsStringAsync().Result;
                            break;
                        }
                    }
                    else
                    {
                        //_retMessage = $"Ocorreu um erro ao executar a operação na rotina {callerMemberName}!\r\nPor favor contacte o suporte:\r\n\r\n{_retString}";
                        _retMessage = $"Não foi possível executar a sua solicitação. Verifique a sua conexão com a Internet e tente novamente.";
                    }
                    break;

                case Exception ex:
                    _retMessage = this.GetInnerExceptionMessages(ex);
                    break;

                default:
                    _retMessage = this.GetInnerExceptionMessages(_policyResult.FinalException);
                    break;
                }
                return(new ServiceResult <TResult>(default(TResult), false, _HttpStatusCode, _retMessage));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            FrmAttachmentDB downDB = new FrmAttachmentDB();

            if (DoType.Equals("view") || DoType.Equals("ViewPic"))
            {
                if (!string.IsNullOrEmpty(DelPKVal))
                {
                    downDB.MyPK = this.DelPKVal;
                    downDB.Retrieve();
                    string filePath = "";
                    if (DoType.Equals("view"))
                    {
                        if (DataType.IsImgExt(downDB.FileExts))
                        {
                            RenderPic(null);
                            return;
                        }
                    }

                    try
                    {
                        filePath = Server.MapPath("~/" + downDB.FileFullName);
                    }
                    catch (Exception ex)
                    {
                        filePath = downDB.FileFullName;
                    }

                    if (downDB.FileExts.ToUpper().Equals("CEB"))
                    {
                        //判断是绝对路径还是相对路径
                        string fileSave = Server.MapPath("~/DataUser/UploadFile/" + downDB.MyPK + "." + downDB.FileName);

                        if (!System.IO.File.Exists(fileSave))
                        {
                            byte[] fileBytes = File.ReadAllBytes(filePath);

                            File.WriteAllBytes(fileSave, fileBytes);
                        }
                        this.Response.Redirect("/DataUser/UploadFile/" + downDB.MyPK + "." +
                                               downDB.FileName, true);
                    }

                    if (File.Exists(filePath))
                    {
                        byte[] result;
                        try
                        {
                            result = File.ReadAllBytes(filePath);
                        }
                        catch
                        {
                            result = File.ReadAllBytes(downDB.FileFullName);
                        }

                        Response.Clear();
                        if (downDB.FileExts == "pdf")
                        {
                            Response.ContentType = "Application/pdf";
                        }

                        Response.BinaryWrite(result);
                        Response.End();
                    }
                    else
                    {
                        this.Alert("没有找到文件。");
                        this.WinClose();
                    }
                }
            }
            else
            {
                RenderPic(DoType);
            }
        }
예제 #8
0
파일: Do.cs 프로젝트: daramkun/ProjectVodka
 public Do(byte [] doDatas, int width, int height)
 {
     m_doType    = DoType.SizeChange;
     m_doDatas   = doDatas;
     m_sizeWidth = width; m_sizeHeight = height;
 }
예제 #9
0
파일: Do.cs 프로젝트: daramkun/ProjectVodka
 public Do(byte [] doDatas)
 {
     m_doType  = DoType.Drawing;
     m_doDatas = doDatas;
 }
예제 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Request["action"];

            string name = null;

            if (BP.Web.WebUser.No == "Guest")
            {
                name = BP.Web.GuestUser.Name;
            }
            else
            {
                name = BP.Web.WebUser.Name;
            }
            TB_User.Value = name;


            FrmAttachmentDB downDB = new FrmAttachmentDB();

            if (DoType.Equals("EditOffice"))
            {
                if (!string.IsNullOrEmpty(DelPKVal))
                {
                    downDB.MyPK = this.DelPKVal;
                    downDB.Retrieve();
                    TB_FilePath.Value = downDB.FileFullName;
                    TB_FileType.Value = downDB.FileExts;
                }
                if (!string.IsNullOrEmpty(this.FK_FrmAttachment))
                {
                    FrmAttachment attachment = new FrmAttachment();
                    int           result     = 0;
                    //表单编号与节点不为空
                    if (this.FK_MapData != null && this.FK_Node != null)
                    {
                        BP.En.QueryObject objInfo = new BP.En.QueryObject(attachment);
                        objInfo.AddWhere(FrmAttachmentAttr.FK_MapData, this.FK_MapData);
                        objInfo.addAnd();
                        objInfo.AddWhere(FrmAttachmentAttr.FK_Node, this.FK_Node);
                        objInfo.addAnd();
                        objInfo.AddWhere(FrmAttachmentAttr.NoOfObj, this.NoOfObj);
                        result = objInfo.DoQuery();
                        //result = attachment.Retrieve(FrmAttachmentAttr.FK_MapData, this.FK_MapData,
                        //                            FrmAttachmentAttr.FK_Node, this.FK_Node, FrmAttachmentAttr.NoOfObj, this.DelPKVal);
                    }
                    if (result == 0) /*如果没有定义,就获取默认的.*/
                    {
                        attachment.MyPK = this.FK_FrmAttachment;
                        attachment.Retrieve();
                    }

                    if (!attachment.IsWoEnableSave)
                    {
                        Btn_Save.Visible = false;
                    }
                    if (attachment.IsWoEnableReadonly)
                    {
                        TB_IsReadOnly.Value = "1";
                    }
                    else
                    {
                        TB_IsReadOnly.Value = "0";
                    }

                    if (!attachment.IsWoEnableRevise)
                    {
                        Btn_AttachDoc.Visible   = false;
                        Btn_UnAttachDoc.Visible = false;
                    }

                    if (!attachment.IsWoEnablePrint)
                    {
                        TB_IsPrint.Value = "0";
                    }
                    else
                    {
                        TB_IsPrint.Value = "1";
                    }

                    if (!attachment.IsWoEnableViewKeepMark)
                    {
                        sShowName.Visible = false;
                    }
                }
            }

            if (!string.IsNullOrEmpty(action))
            {
                if (action.Equals("SaveFile"))
                {
                    SaveFile();
                }
                else if (action.Equals("LoadFile"))
                {
                    LoadFile();
                }
                else if (action.Equals("LoadFlow"))
                {
                    GetFlow();
                }
            }
        }