Ejemplo n.º 1
0
 Func <DataASTMutable.WarewolfAtom, DataASTMutable.WarewolfAtom> TryConvertFunc(BaseConvertTO item, IExecutionEnvironment env, int update)
 {
     return(a =>
     {
         IBaseConverter from = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.FromType, typeof(enDev2BaseConvertType)));
         IBaseConverter to = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.ToType, typeof(enDev2BaseConvertType)));
         IBaseConversionBroker broker = _fac.CreateBroker(@from, to);
         var value = a.ToString();
         if (a.IsNothing)
         {
             throw new Exception(string.Format("Scalar value {{{0}}} is NULL", item.FromExpression));
         }
         if (String.IsNullOrEmpty(value))
         {
             return DataASTMutable.WarewolfAtom.NewDataString("");
         }
         var upper = broker.Convert(value);
         var evalled = env.Eval(upper, update);
         if (evalled.IsWarewolfAtomResult)
         {
             var warewolfAtomResult = evalled as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult;
             if (warewolfAtomResult != null)
             {
                 return warewolfAtomResult.Item;
             }
             return DataASTMutable.WarewolfAtom.Nothing;
         }
         return DataASTMutable.WarewolfAtom.NewDataString(WarewolfDataEvaluationCommon.EvalResultToString(evalled));
     });
 }
Ejemplo n.º 2
0
        public void Broker_Can_Convert_Formats_Expected_Binary_to_Hex()
        {
            IBaseConverter        to     = Fac.CreateConverter(enDev2BaseConvertType.Hex);
            IBaseConverter        from   = Fac.CreateConverter(enDev2BaseConvertType.Binary);
            IBaseConversionBroker broker = Fac.CreateBroker(from, to);

            const string payload = "011101000110100001101001011100110010000001101001011100110010000001100001001000000110110001101001011011100110010100100000011011110110011000100000011101000110010101111000011101000010110000100000011010000110111101110111001000000110010001101111011001010111001100100000011101000110100001100001011101000010000001101101011000010110101101100101001000000111100101101111011101010010000001100110011001010110010101101100";

            string       result   = broker.Convert(payload);
            const string expected = "0x746869732069732061206c696e65206f6620746578742c20686f7720646f65732074686174206d616b6520796f75206665656c";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 3
0
        public void Broker_Can_Convert_Formats_Expected_Binary_to_Base64()
        {
            IBaseConverter        to     = Fac.CreateConverter(enDev2BaseConvertType.Base64);
            IBaseConverter        from   = Fac.CreateConverter(enDev2BaseConvertType.Binary);
            IBaseConversionBroker broker = Fac.CreateBroker(from, to);

            const string payload = "011101000110100001101001011100110010000001101001011100110010000001100001001000000110110001101001011011100110010100100000011011110110011000100000011101000110010101111000011101000010110000100000011010000110111101110111001000000110010001101111011001010111001100100000011101000110100001100001011101000010000001101101011000010110101101100101001000000111100101101111011101010010000001100110011001010110010101101100";

            string       result   = broker.Convert(payload);
            const string expected = "dGhpcyBpcyBhIGxpbmUgb2YgdGV4dCwgaG93IGRvZXMgdGhhdCBtYWtlIHlvdSBmZWVs";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 4
0
        public void Broker_Can_Convert_Formats_Expected_Binary_to_Text()
        {
            IBaseConverter        to     = Fac.CreateConverter(enDev2BaseConvertType.Text);
            IBaseConverter        from   = Fac.CreateConverter(enDev2BaseConvertType.Binary);
            IBaseConversionBroker broker = Fac.CreateBroker(from, to);

            const string payload = "011101000110100001101001011100110010000001101001011100110010000001100001001000000110110001101001011011100110010100100000011011110110011000100000011101000110010101111000011101000010110000100000011010000110111101110111001000000110010001101111011001010111001100100000011101000110100001100001011101000010000001101101011000010110101101100101001000000111100101101111011101010010000001100110011001010110010101101100";

            string       result   = broker.Convert(payload);
            const string expected = "this is a line of text, how does that make you feel";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 5
0
        public void Broker_Can_Convert_Formats_Expected_Binary_to_Binary()
        {
            IBaseConverter        to     = Fac.CreateConverter(enDev2BaseConvertType.Binary);
            IBaseConverter        from   = Fac.CreateConverter(enDev2BaseConvertType.Binary);
            IBaseConversionBroker broker = Fac.CreateBroker(from, to);

            const string payload = "011101000110100001101001011100110010000001101001011100110010000001100001001000000110110001101001011011100110010100100000011011110110011000100000011101000110010101111000011101000010110000100000011010000110111101110111001000000110010001101111011001010111001100100000011101000110100001100001011101000010000001101101011000010110101101100101001000000111100101101111011101010010000001100110011001010110010101101100";

            string       result   = broker.Convert(payload);
            const string expected = "011101000110100001101001011100110010000001101001011100110010000001100001001000000110110001101001011011100110010100100000011011110110011000100000011101000110010101111000011101000010110000100000011010000110111101110111001000000110010001101111011001010111001100100000011101000110100001100001011101000010000001101101011000010110101101100101001000000111100101101111011101010010000001100110011001010110010101101100";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 6
0
        public void Broker_Can_Convert_Formats_Expected_Base64_to_Hex()
        {
            IBaseConverter        to     = Fac.CreateConverter(enDev2BaseConvertType.Hex);
            IBaseConverter        from   = Fac.CreateConverter(enDev2BaseConvertType.Base64);
            IBaseConversionBroker broker = Fac.CreateBroker(from, to);

            const string payload = "dGhpcyBpcyBhIGxpbmUgb2YgdGV4dCwgaG93IGRvZXMgdGhhdCBtYWtlIHlvdSBmZWVs";

            string       result   = broker.Convert(payload);
            const string expected = "0x746869732069732061206c696e65206f6620746578742c20686f7720646f65732074686174206d616b6520796f75206665656c";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 7
0
        public void Broker_Can_Convert_Formats_Expected_Base64_to_Text()
        {
            IBaseConverter        to     = Fac.CreateConverter(enDev2BaseConvertType.Text);
            IBaseConverter        from   = Fac.CreateConverter(enDev2BaseConvertType.Base64);
            IBaseConversionBroker broker = Fac.CreateBroker(from, to);

            const string payload = "dGhpcyBpcyBhIGxpbmUgb2YgdGV4dCwgaG93IGRvZXMgdGhhdCBtYWtlIHlvdSBmZWVs";

            string       result   = broker.Convert(payload);
            const string expected = "this is a line of text, how does that make you feel";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 8
0
        public void Broker_Can_Convert_Formats_No_Leading0x_Expected_Hex_to_Text()
        {
            IBaseConverter        to     = Fac.CreateConverter(enDev2BaseConvertType.Text);
            IBaseConverter        from   = Fac.CreateConverter(enDev2BaseConvertType.Hex);
            IBaseConversionBroker broker = Fac.CreateBroker(from, to);

            const string payload = "746869732069732061206c696e65206f6620746578742c20686f7720646f65732074686174206d616b6520796f75206665656c";

            string       result   = broker.Convert(payload);
            const string expected = "this is a line of text, how does that make you feel";

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 9
0
        // ReSharper restore RedundantOverridenMember


        /// <summary>
        /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity
        /// </summary>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            _indexCounter = 0;
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors;
            Guid          executionId = DataListExecutionID.Get(context);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false);

            InitializeDebug(dataObject);

            try
            {
                CleanArgs();

                toUpsert.IsDebug = dataObject.IsDebugMode();

                foreach (var item in ConvertCollection)
                {
                    try
                    {
                        _indexCounter++;
                        // Travis.Frisinger - This needs to be in the ViewModel not here ;)
                        if (item.ToExpression == string.Empty)
                        {
                            item.ToExpression = item.FromExpression;
                        }
                        IsSingleValueRule.ApplyIsSingleValueRule(item.FromExpression, allErrors);
                        var fieldName = item.FromExpression;
                        fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName;
                        var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors);
                        if (!datalist.IsNullOrEmpty())
                        {
                            var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist.ToString())
                            {
                                LabelText = fieldName
                            };

                            var errorInfo = isValidExpr.Check();
                            if (errorInfo != null)
                            {
                                item.FromExpression = "";
                                errors.AddError(errorInfo.Message);
                            }
                            allErrors.MergeErrors(errors);
                        }

                        IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.FromExpression, false, out errors);
                        if (dataObject.IsDebugMode())
                        {
                            AddDebugInputItem(item.FromExpression, tmp, executionId, item.FromType, item.ToType);
                        }
                        allErrors.MergeErrors(errors);
                        if (tmp != null)
                        {
                            IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp);

                            IBaseConverter        from   = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.FromType, typeof(enDev2BaseConvertType)));
                            IBaseConverter        to     = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.ToType, typeof(enDev2BaseConvertType)));
                            IBaseConversionBroker broker = _fac.CreateBroker(from, to);

                            // process result information
                            while (itr.HasMoreRecords())
                            {
                                IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                                foreach (IBinaryDataListItem c in cols)
                                {
                                    // set up live flushing iterator details
                                    if (c.IsDeferredRead)
                                    {
                                        if (toUpsert != null)
                                        {
                                            toUpsert.HasLiveFlushing      = true;
                                            toUpsert.LiveFlushingLocation = executionId;
                                        }
                                    }

                                    int indexToUpsertTo = c.ItemCollectionIndex;

                                    string val        = string.IsNullOrEmpty(c.TheValue) ? "" : broker.Convert(c.TheValue);
                                    string expression = item.ToExpression;

                                    if (DataListUtil.IsValueRecordset(item.ToExpression) && DataListUtil.GetRecordsetIndexType(item.ToExpression) == enRecordsetIndexType.Star)
                                    {
                                        expression = item.ToExpression.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                                    }
                                    toUpsert.Add(expression, val);
                                    if (toUpsert != null && toUpsert.HasLiveFlushing)
                                    {
                                        toUpsert.FlushIterationFrame();
                                        toUpsert = null;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                    finally
                    {
                        if (allErrors.HasErrors())
                        {
                            toUpsert.Add(item.ToExpression, null);
                        }
                    }
                }

                if (toUpsert != null && toUpsert.HasLiveFlushing)
                {
                    try
                    {
                        toUpsert.FlushIterationFrame();
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                }
                else
                {
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                }

                if (!allErrors.HasErrors() && toUpsert != null)
                {
                    var outIndex = 1;
                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem);
                        _debugOutputs.Add(debugItem);
                        outIndex++;
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFBaseConvert", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfBaseConvertActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }