Exemplo n.º 1
0
        public void InitSessionWithNoDataBaseDirectoryIsNullStillInitialises()
        {
            DebugTO to = new DebugTO();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            to.RememberInputs = true;
            to.BaseSaveDirectory = null;
            to.DataList = "<DataList><scalar1/><rs><f1/><f2/></rs></DataList>";
            to.XmlData = "<DataList><scalar1>s1</scalar1><rs><f1/>f1Value<f2/>f2Value</rs></DataList>";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            broker.InitDebugSession(to);
            to = broker.PersistDebugSession(to);
            to.BaseSaveDirectory = null;
            PrivateObject p = new PrivateObject(broker);
            var field = p.GetField("_debugPersistSettings") as IDictionary<string, DebugTO>;
            Assert.IsNotNull(field);
            field.Add("bob", new DebugTO());
            to = broker.PersistDebugSession(to);

            Assert.AreEqual(string.Empty, to.Error);
            Assert.IsNotNull(to.BinaryDataList); // assert not null hence we created it ;)

            DeleteDir(rootFolder);
        }
        /// <summary>
        ///     Init the Debug Session
        /// </summary>
        /// <param name="to"></param>
        /// <returns></returns>
        public DebugTO InitDebugSession(DebugTO to)
        {
            DebugTO tmp;

            to.Error = string.Empty;

            // Bootstrap the operations
            if (to.BaseSaveDirectory != null)
            {
                BootstrapPersistence(to.BaseSaveDirectory);
                InitPersistSettings();
            }
            else if (to.BaseSaveDirectory == null && _debugPersistSettings.Count == 0)
            {
                BootstrapPersistence(_rootPath);
                InitPersistSettings();
            }

            if (to.BaseSaveDirectory == null)
            {
                // set the save location
                to.BaseSaveDirectory = _rootPath;
            }


            if (to.DataList != null)
            {
                to.DataListHash = to.DataList.GetHashCode(); // set incoming DL hash
            }
            else
            {
                to.DataListHash = -1; // default value
            }

            lock(SettingsLock)
            {
                if (_debugPersistSettings.TryGetValue(to.WorkflowID, out tmp))
                {
                    to.XmlData = tmp.RememberInputs
                        ? tmp.XmlData
                        : (to.XmlData ?? "<DataList></DataList>");
                    tmp.CleanUp();
                }
                else
                {
                    // if no XML data copy over the DataList
                    to.XmlData = to.XmlData != null && to.XmlData == string.Empty
                        ? (to.DataList ?? "<DataList></DataList>")
                        : (to.XmlData ?? "<DataList></DataList>");                    
                }
                to.BinaryDataList = new DataListModel();
                to.BinaryDataList.Create(to.XmlData, to.DataList);
            }

            if (tmp != null) tmp.CleanUp();
            return to;
        }
Exemplo n.º 3
0
 public void DebugTO_Copy_ValuesCorrect()
 {
     DebugTO to = new DebugTO();
     string rootFolder = Path.GetTempPath() + Guid.NewGuid();
     to.RememberInputs = true;
     to.BaseSaveDirectory = rootFolder;
     to.DataList = "<DataList><scalar1 ColumnIODirection=\"Input\"/><persistantscalar ColumnIODirection=\"Input\"/><rs><f1 ColumnIODirection=\"Input\"/><f2 ColumnIODirection=\"Input\"/></rs><recset><field1/><field2/></recset></DataList>";
     to.XmlData = "<DataList><scalar1>s1</scalar1><persistantscalar>SomeValue</persistantscalar><rs><f1>f1Value</f1><f2>f2Value</f2></rs><recset><field1>somedata</field1><field2>moredata</field2></recset><recset><field1></field1><field2></field2></recset></DataList>";
     to.ServiceName = "DummyService";
     to.WorkflowID = "DummyService";
     var save = to.CopyToSaveDebugTO();
     Assert.AreEqual(save.DataList,to.DataList);
     Assert.AreEqual(save.ServiceName,to.ServiceName);
     Assert.AreEqual(to.IsDebugMode,to.IsDebugMode);
     Assert.AreEqual(to.WorkflowID,to.WorkflowID);
 }
Exemplo n.º 4
0
        public void InitSessionWithNoDataBaseDirectoryIsNull()
        {
            DebugTO to = new DebugTO();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            to.RememberInputs = true;
            to.BaseSaveDirectory = null;
            to.DataList = "<DataList><scalar1/><rs><f1/><f2/></rs></DataList>";
            to.XmlData = "<DataList><scalar1>s1</scalar1><rs><f1/>f1Value<f2/>f2Value</rs></DataList>";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            broker.InitDebugSession(to);
            to = broker.PersistDebugSession(to);

            Assert.IsTrue(rootFolder.Contains(to.BaseSaveDirectory));
            DeleteDir(rootFolder);
        }
Exemplo n.º 5
0
        public void InitSessionWithNoData()
        {
            DebugTO to = new DebugTO();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            to.RememberInputs = true;
            to.BaseSaveDirectory = rootFolder;
            to.DataList = "<DataList><scalar1/><rs><f1/><f2/></rs></DataList>";
            to.XmlData = "<DataList><scalar1>s1</scalar1><rs><f1/>f1Value<f2/>f2Value</rs></DataList>";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            broker.InitDebugSession(to);
            to = broker.PersistDebugSession(to);

            // just ensure the operation worked successfully with no errors
            Assert.AreEqual(string.Empty, to.Error);
            Assert.IsNotNull(to.BinaryDataList); // assert not null hence we created it ;)

            DeleteDir(rootFolder);
        }
Exemplo n.º 6
0
        void PersistBinaryDataList(DebugTO to)
        {
            DebugTO tmp = null;

            try
            {
                if (_debugPersistSettings.TryGetValue(to.WorkflowID, out tmp))
                {
                    to.XmlData = tmp.RememberInputs ? tmp.XmlData : (to.XmlData ?? "<DataList></DataList>");
                    tmp.CleanUp();
                }
                else
                {
                    to.XmlData = to.RememberInputs ? to.XmlData : "<DataList></DataList>";
                }
                to.BinaryDataList = new DataListModel();
                to.BinaryDataList.Create(to.XmlData, to.DataList);
            }
            finally
            {
                tmp?.CleanUp();
            }
        }
        public WorkflowInputDataViewModel(IServiceDebugInfoModel input, Guid sessionId)
        {
            VerifyArgument.IsNotNull("input", input);
            CanDebug = true;
            CanViewInBrowser = true;

            DebugTo = new DebugTO
            {
                DataList = !string.IsNullOrEmpty(input.ResourceModel.DataList)
                               ? input.ResourceModel.DataList
                               : "<DataList></DataList>",
                ServiceName = input.ResourceModel.ResourceName,
                WorkflowID = input.ResourceModel.ResourceName,
                WorkflowXaml = string.Empty,
                //WorkflowXaml = input.ResourceModel.WorkflowXaml, - 05.12.2013 ;)
                XmlData = input.ServiceInputData,
                ResourceID = input.ResourceModel.ID,
                ServerID = input.ResourceModel.ServerID,
                RememberInputs = input.RememberInputs,
                SessionID = sessionId
            };

            if(input.DebugModeSetting == DebugMode.DebugInteractive)
            {
                DebugTo.IsDebugMode = true;
            }

            _resourceModel = input.ResourceModel;
            // ReSharper disable DoNotCallOverridableMethodsInConstructor
            DisplayName = "Debug input data";
            // ReSharper restore DoNotCallOverridableMethodsInConstructor
            _dataListConversionUtils = new DataListConversionUtils();
        }
        /// <summary>
        ///     Boot strap the Session
        /// </summary>
        private void InitPersistSettings()
        {
            lock (SettingsLock)
            {
                if (!_debugOptsEndPoint.PathExist(_debugPath))
                {
                    var args = new Dev2PutRawOperationTO(WriteType.Overwrite, "");
                    ActivityIOFactory.CreateOperationsBroker().PutRaw(_debugOptsEndPoint, args);
                }
                else
                {
                    // fetch from disk
                    var filesToCleanup = new List<string>();
                    using (Stream s = _debugOptsEndPoint.Get(_debugPath, filesToCleanup))
                    {
                        if (s.Length > 0)
                        {
                            var bf = new XmlSerializer(typeof (List<SaveDebugTO>));

                            try
                            {
                                var settings = (List<SaveDebugTO>) bf.Deserialize(s);
                                _debugPersistSettings.Values.ToList().ForEach(a=>a.CleanUp());
                                _debugPersistSettings.Clear();
                                // now push back into the Dictionary
                                foreach (SaveDebugTO dto in settings)
                                {
                                    if (dto.ServiceName.Length > 0)
                                    {
                                        var tmp = new DebugTO();
                                        tmp.CopyFromSaveDebugTO(dto);
                                        _debugPersistSettings[dto.WorkflowID] = tmp;
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                Dev2Logger.Log.Error(e);
                            }
                        }
                        else
                        {
                            Dev2Logger.Log.Error("No debug data stream [ " + _debugPath + " ] ");
                        }

                        s.Close();
                        s.Dispose();
                        filesToCleanup.ForEach(File.Delete);
                    }
                }
            }
        }
        /// <summary>
        ///     Save the debug session data
        /// </summary>
        /// <param name="to"></param>
        /// <returns></returns>
        public DebugTO PersistDebugSession(DebugTO to)
        {
            lock (SettingsLock)
            {
                if (to.DataList != null)
                    to.DataListHash = to.DataList.GetHashCode();
                        // set incoming hash //2013.01.22: Ashley Lewis - Added condition for Bug 7837
                to.Error = string.Empty;

                if (to.RememberInputs)
                {
                    // update the current TO
                    _debugPersistSettings[to.WorkflowID] = to;
                }
                else
                {
                    // no longer relavent, remove it
                    DebugTO tmp;

                    if (_debugPersistSettings.TryGetValue(to.WorkflowID, out tmp))
                    {
                         _debugPersistSettings[to.WorkflowID].CleanUp();
                        _debugPersistSettings.Remove(to.WorkflowID);
                    }
                }

                var settingList = new List<SaveDebugTO>();

                // build the list
                foreach (string key in _debugPersistSettings.Keys)
                {
                    DebugTO tmp;

                    if (key.Length > 0 && _debugPersistSettings.TryGetValue(key, out tmp))
                    {
                        SaveDebugTO that = tmp.CopyToSaveDebugTO();
                        settingList.Add(that);
                    }
                }

                // push to disk
                using (Stream s = File.Open(_debugPersistPath, FileMode.Truncate))
                {
                    var bf = new XmlSerializer(typeof (List<SaveDebugTO>));
                    bf.Serialize(s, settingList);
                }
            }

            return to;
        }
        /// <summary>
        ///     Init the Debug Session
        /// </summary>
        /// <param name="to"></param>
        /// <returns></returns>
        public DebugTO InitDebugSession(DebugTO to)
        {
            DebugTO tmp;

            to.Error = string.Empty;

            // Bootstrap the operations
            if (to.BaseSaveDirectory != null)
            {
                BootstrapPersistence(to.BaseSaveDirectory);
                InitPersistSettings();
            }
            else if (to.BaseSaveDirectory == null && _debugPersistSettings.Count == 0)
            {
                BootstrapPersistence(_rootPath);
                InitPersistSettings();
            }

            if (to.BaseSaveDirectory == null)
            {
                // set the save location
                to.BaseSaveDirectory = _rootPath;
            }


            if (to.DataList != null)
            {
                to.DataListHash = to.DataList.GetHashCode(); // set incoming DL hash
            }
            else
            {
                to.DataListHash = -1; // default value
            }

            IEnvironmentModelDataListCompiler svrCompiler = DataListFactory.CreateServerDataListCompiler();
            ErrorResultTO errors;

            if (_debugPersistSettings.TryGetValue(to.WorkflowID, out tmp))
            {
                string convertData = tmp.XmlData;
                Guid mergeGuid = svrCompiler.ConvertTo(null,
                    DataListFormat.CreateFormat(GlobalConstants._Studio_Debug_XML), Encoding.UTF8.GetBytes(convertData),
                    new StringBuilder(to.DataList), out errors);
                tmp.XmlData =
                    svrCompiler.ConvertFrom(null, mergeGuid, enTranslationDepth.Data,
                        DataListFormat.CreateFormat(GlobalConstants._Studio_Debug_XML), out errors)
                        .FetchAsString()
                        .ToString();
                to.XmlData = tmp.RememberInputs
                    ? (tmp.XmlData)
                    : (to.XmlData ?? "<DataList></DataList>");
                tmp.CleanUp();
                to.BinaryDataList = svrCompiler.FetchBinaryDataList(null, mergeGuid, out errors);
            }
            else
            {
                // if no XML data copy over the DataList
                to.XmlData = to.XmlData != null && to.XmlData == string.Empty
                    ? (to.DataList ?? "<DataList></DataList>")
                    : (to.XmlData ?? "<DataList></DataList>");

                Guid createGuid = svrCompiler.ConvertTo(null,
                    DataListFormat.CreateFormat(GlobalConstants._Studio_Debug_XML), Encoding.UTF8.GetBytes(to.XmlData),
                    new StringBuilder(to.DataList), out errors);

                to.BinaryDataList = to.BinaryDataList = svrCompiler.FetchBinaryDataList(null, createGuid, out errors);
            }

            if (tmp != null) tmp.CleanUp();
            return to;
        }
Exemplo n.º 11
0
        public void InitSessionWithSingleScalar()
        {
            DebugTO to = new DebugTO();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            to.RememberInputs = true;
            to.BaseSaveDirectory = rootFolder;
            to.DataList = "<DataList><scalar1/><rs><f1/><f2/></rs></DataList>";
            to.XmlData = "<DataList><scalar1>s1</scalar1></DataList>";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            broker.InitDebugSession(to);
            to = broker.PersistDebugSession(to);

            const string expected = "<DataList><scalar1>s1</scalar1></DataList>";

            // just ensure the operation worked successfully with no errors
            Assert.AreEqual(string.Empty, to.Error);
            Assert.AreEqual(expected, to.XmlData, "Got  [ " + to.XmlData + "] , but expected [ " + expected + " ]");

            DeleteDir(rootFolder);
        }
Exemplo n.º 12
0
        public void GetXmlForInputsExpectEmptyWithRandomDataList()
        {
            // bootstrap
            DebugTO to = new DebugTO();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            to.RememberInputs = false;
            to.BaseSaveDirectory = rootFolder;
            to.DataList = "<DataList><scalar1/><rs><f1/><f2/></rs></DataList>";
            to.XmlData = "";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            to = broker.InitDebugSession(to);
            to.XmlData = "<DataList><scalar1>s1</scalar1><rs><f1>f1Value</f1><f2>f2Value</f2></rs></DataList>";
            to = broker.PersistDebugSession(to);
            to.XmlData = "";
            to = broker.InitDebugSession(to);
            var outputxml =broker.GetXMLForInputs(to.BinaryDataList);
            Assert.AreEqual("<DataList></DataList>", outputxml);

            DeleteDir(rootFolder);
        }
Exemplo n.º 13
0
        public void PersistSessionWithSavedData_ChangedDataList_ExpectPreviousXmlData()
        {
            // bootstrap
            DebugTO to = new DebugTO();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            to.RememberInputs = true;
            to.BaseSaveDirectory = rootFolder;
            to.DataList = "<DataList><scalar1/><rs><f1/><f2/></rs></DataList>";
            to.XmlData = "<DataList><scalar1>s1</scalar1><rs><f1>f1Value</f1><f2>f2Value</f2></rs></DataList>";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            to = broker.InitDebugSession(to);
            to = broker.PersistDebugSession(to);

            Assert.AreEqual("<DataList><scalar1>s1</scalar1><rs><f1>f1Value</f1><f2>f2Value</f2></rs></DataList>", to.XmlData);

            DeleteDir(rootFolder);
        }
Exemplo n.º 14
0
        /// <summary>
        ///     Init the Debug Session
        /// </summary>
        /// <param name="to"></param>
        /// <returns></returns>
        public DebugTO InitDebugSession(DebugTO to)
        {
            DebugTO tmp;

            to.Error = string.Empty;

            // Bootstrap the operations
            if (to.BaseSaveDirectory != null)
            {
                BootstrapPersistence(to.BaseSaveDirectory);
                InitPersistSettings();
            }
            else if (to.BaseSaveDirectory == null && _debugPersistSettings.Count == 0)
            {
                BootstrapPersistence(_rootPath);
                InitPersistSettings();
            }

            if (to.BaseSaveDirectory == null)
            {
                // set the save location
                to.BaseSaveDirectory = _rootPath;
            }


            if (to.DataList != null)
            {
                to.DataListHash = to.DataList.GetHashCode(); // set incoming DL hash
            }
            else
            {
                to.DataListHash = -1; // default value
            }

            IEnvironmentModelDataListCompiler svrCompiler = DataListFactory.CreateServerDataListCompiler();
            ErrorResultTO errors;

            if (_debugPersistSettings.TryGetValue(to.WorkflowID, out tmp))
            {
                string convertData = tmp.XmlData;
                Guid   mergeGuid   = svrCompiler.ConvertTo(null,
                                                           DataListFormat.CreateFormat(GlobalConstants._Studio_Debug_XML), Encoding.UTF8.GetBytes(convertData),
                                                           new StringBuilder(to.DataList), out errors);
                tmp.XmlData =
                    svrCompiler.ConvertFrom(null, mergeGuid, enTranslationDepth.Data,
                                            DataListFormat.CreateFormat(GlobalConstants._Studio_Debug_XML), out errors)
                    .FetchAsString()
                    .ToString();
                to.XmlData = tmp.RememberInputs
                    ? (tmp.XmlData)
                    : (to.XmlData ?? "<DataList></DataList>");
                tmp.CleanUp();
                to.BinaryDataList = svrCompiler.FetchBinaryDataList(null, mergeGuid, out errors);
            }
            else
            {
                // if no XML data copy over the DataList
                to.XmlData = to.XmlData != null && to.XmlData == string.Empty
                    ? (to.DataList ?? "<DataList></DataList>")
                    : (to.XmlData ?? "<DataList></DataList>");

                Guid createGuid = svrCompiler.ConvertTo(null,
                                                        DataListFormat.CreateFormat(GlobalConstants._Studio_Debug_XML), Encoding.UTF8.GetBytes(to.XmlData),
                                                        new StringBuilder(to.DataList), out errors);

                to.BinaryDataList = to.BinaryDataList = svrCompiler.FetchBinaryDataList(null, createGuid, out errors);
            }

            if (tmp != null)
            {
                tmp.CleanUp();
            }
            return(to);
        }
Exemplo n.º 15
0
        public void PersistSessionWithSavedData_SubtlyChangedDataList_Expect_MergedXmlData()
        {
            // bootstrap
            DebugTO to = new DebugTO();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            to.RememberInputs = true;
            to.BaseSaveDirectory = rootFolder;
            to.DataList = "<DataList><rs><f1/><f2/></rs></DataList>";
            to.XmlData = "<DataList><rs><f1>f1Value</f1><f2>f2Value</f2></rs></DataList>";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            to = broker.InitDebugSession(to);
            to = broker.PersistDebugSession(to);

            // just ensure the operation worked successfully with no errors
            to.DataList = "<DataList><rs><f2 ColumnIODirection=\"Input\"/></rs></DataList>";
            to = broker.InitDebugSession(to);

            Assert.AreEqual("<DataList><rs><f2>f2Value</f2></rs></DataList>", to.XmlData);

            DeleteDir(rootFolder);
        }
Exemplo n.º 16
0
        public void PersistSessionWithAlotOfSavedData_RadicallyChangedDataList_Expect_MergedXmlData()
        {
            // bootstrap
            DebugTO to = new DebugTO();
            string rootFolder = Path.GetTempPath() + Guid.NewGuid();
            IDev2StudioSessionBroker broker = Dev2StudioSessionFactory.CreateBroker();
            to.RememberInputs = true;
            to.BaseSaveDirectory = rootFolder;
            to.DataList = "<DataList><scalar1 ColumnIODirection=\"Input\"/><persistantscalar ColumnIODirection=\"Input\"/><rs><f1 ColumnIODirection=\"Input\"/><f2 ColumnIODirection=\"Input\"/></rs><recset><field1/><field2/></recset></DataList>";
            to.XmlData = "<DataList><scalar1>s1</scalar1><persistantscalar>SomeValue</persistantscalar><rs><f1>f1Value</f1><f2>f2Value</f2></rs><recset><field1>somedata</field1><field2>moredata</field2></recset><recset><field1></field1><field2></field2></recset></DataList>";
            to.ServiceName = "DummyService";
            to.WorkflowID = "DummyService";
            to = broker.InitDebugSession(to);
            to = broker.PersistDebugSession(to);

            // just ensure the operation worked successfully with no errors
            to.DataList = "<DataList><persistantscalar ColumnIODirection=\"Input\"/><rs><field ColumnIODirection=\"Input\"/><f2 ColumnIODirection=\"Input\"/></rs><recset><newfield ColumnIODirection=\"Input\"/><field1 ColumnIODirection=\"Input\"/><changedfieldname ColumnIODirection=\"Input\"/></recset></DataList>";
            to = broker.InitDebugSession(to);

            Assert.AreEqual("<DataList><persistantscalar>SomeValue</persistantscalar><rs><field></field><f2>f2Value</f2></rs><recset><newfield></newfield><field1>somedata</field1><changedfieldname></changedfieldname></recset><recset><newfield></newfield><field1></field1><changedfieldname></changedfieldname></recset></DataList>", to.XmlData);

            DeleteDir(rootFolder);
        }