Пример #1
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        internal int insertUploadText(Upload upload)
        {
            int returnCode = (int)CODE.ZERO;
            int result = (int)CODE.MINUS_ONE;

            //validate only text
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                upload.text == null ||
                upload.file != null
               ) { returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_FAILED_ONLYTEXT; result = (int)CODE.ZERO; }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                upload.text = upload.text;
                upload.file = null;

                CtrText _CtrText = new CtrText();
                IUploads _DbUploads = new DbUploads();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        returnCode = _CtrText.insertText(upload.text);
                        if (returnCode >= (int)CODE.TRANSLATO_DATABASE_SEED)//means text was inserted successfully
                        {
                            upload.text.textId = returnCode;
                            returnCode = _DbUploads.insertUploadText(upload);
                        }
                        else
                        {//means text failed to be inserted
                            trScope.Dispose();
                        }

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else { }
            return returnCode;
        }
 public ReturnedObject insertText(string publicKey, string privateKey, Text text)
 {
     ReturnedObject returnedObject = new ReturnedObject();
     if (Security.authorizeClient(publicKey, privateKey))
     {
         CtrText _CtrText = new CtrText();
         returnedObject.code = _CtrText.insertText(text);
     }
     else
     {
         returnedObject.code = (int)CODE.CLIENT_NOT_AUTHORIZED;
     }
     return returnedObject;
 }
Пример #3
0
        //LAYER_Class_NameOfTheMethod_TestedScenario_ExpectedBehaviour
        public void BLL_CtrText_InsertText_InsertText_TextIsInserted()
        {
            //arrange
            int textId = 1;
            string textData = "Test text to be inserted";
            
            Text text_m1 = new Text(
                textId,
                textData
                );
            CtrText _CtrText = new CtrText();

            //act
            int result = _CtrText.insertText(text_m1);

            //assert
            
            Assert.IsTrue(result >= (int)ENUM.CODE.TRANSLATO_DATABASE_SEED, "text not inserted");
        }
Пример #4
0
        //returns [int >= TRANSLATO_DATABASE_SEED] if successful
        //returns [int < TRANSLATO_DATABASE_SEED] if not
        internal int insertUploadText(Upload upload)
        {
            int returnCode = (int)CODE.ZERO;
            int result     = (int)CODE.MINUS_ONE;

            //validate only text
            if (
                result == (int)CODE.ZERO ||
                returnCode != (int)CODE.ZERO ||
                upload.text == null ||
                upload.file != null
                )
            {
                returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_FAILED_ONLYTEXT; result = (int)CODE.ZERO;
            }
            if (returnCode == (int)CODE.ZERO && result != (int)CODE.ZERO)//safe to proceed
            {
                upload.text = upload.text;
                upload.file = null;

                CtrText  _CtrText   = new CtrText();
                IUploads _DbUploads = new DbUploads();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        returnCode = _CtrText.insertText(upload.text);
                        if (returnCode >= (int)CODE.TRANSLATO_DATABASE_SEED)//means text was inserted successfully
                        {
                            upload.text.textId = returnCode;
                            returnCode         = _DbUploads.insertUploadText(upload);
                        }
                        else
                        {//means text failed to be inserted
                            trScope.Dispose();
                        }

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    returnCode = (int)CODE.CTRUPLOAD_INSERTUPLOADTEXT_EXCEPTION;
                    Log.Add(ex.ToString());
                }
            }
            else
            {
            }
            return(returnCode);
        }