PBI : 1172 Status : New Purpose : To provide a TO for RawPut operations
 public void Dev2PutRawOperation_Constructor_TakesContentsAndWriteTypeEnum()
 {
     //------------Setup for test--------------------------
     const WriteType WriteType = Dev2.PathOperations.WriteType.AppendBottom;
     const string Contents = "Some test";
     //------------Execute Test---------------------------
     var dev2PutRawOperation = new Dev2PutRawOperationTO(WriteType,Contents);
     //------------Assert Results-------------------------
     Assert.IsNotNull(dev2PutRawOperation);
 }
 public void Dev2PutRawOperationTO_Constructor_GivenParameter_ShouldSetProperties()
 {
     //------------Setup for test--------------------------
     const WriteType WriteType = Dev2.PathOperations.WriteType.AppendBottom;
     const string Contents = "Some test";
     //------------Execute Test---------------------------
     var dev2PutRawOperation = new Dev2PutRawOperationTO(WriteType, Contents);
     //------------Assert Results-------------------------
     Assert.AreEqual(WriteType,dev2PutRawOperation.WriteType);
     Assert.AreEqual(Contents,dev2PutRawOperation.FileContents);
 }
        /// <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);
                    }
                }
            }
        }
Example #4
0
        public string PutRaw(IActivityIOOperationsEndPoint dst, Dev2PutRawOperationTO args)
        {
            var result = ResultOk;

            // directory put?
            // wild char put?
            try
            {
                _fileLock.EnterWriteLock();
                if(dst.RequiresLocalTmpStorage())
                {
                    var tmp = CreateTmpFile();
                    switch(args.WriteType)
                    {
                        case WriteType.AppendBottom:
                            using(var s = dst.Get(dst.IOPath, _filesToDelete))
                            {
                                File.WriteAllBytes(tmp, s.ToByteArray());
                                File.AppendAllText(tmp, args.FileContents);
                            }
                            break;
                        case WriteType.AppendTop:
                            using(var s = dst.Get(dst.IOPath, _filesToDelete))
                            {
                                File.WriteAllText(tmp, args.FileContents);
                                AppendToTemp(s, tmp);
                            }
                            break;
                        default:
                            if(IsBase64(args.FileContents))
                            {
                                var data = Convert.FromBase64String(args.FileContents.Replace("Content-Type:BASE64", ""));
                                File.WriteAllBytes(tmp, data);
                            }
                            else
                            {
                                File.WriteAllText(tmp, args.FileContents);
                            }
                            break;
                    }
                    result = MoveTmpFileToDestination(dst, tmp, result);
                }
                else
                {
                    if(File.Exists(dst.IOPath.Path))
                    {

                        var tmp = CreateTmpFile();
                        switch(args.WriteType)
                        {
                            case WriteType.AppendBottom:
                                File.AppendAllText(dst.IOPath.Path, args.FileContents);
                                result = ResultOk;
                                break;
                            case WriteType.AppendTop:
                                using(var s = dst.Get(dst.IOPath, _filesToDelete))
                                {
                                    File.WriteAllText(tmp, args.FileContents);

                                    AppendToTemp(s, tmp);
                                    result = MoveTmpFileToDestination(dst, tmp, result);
                                    RemoveTmpFile(tmp);
                                }
                                break;
                            default:
                                if(IsBase64(args.FileContents))
                                {
                                    var data = Convert.FromBase64String(args.FileContents.Replace("Content-Type:BASE64", ""));
                                    File.WriteAllBytes(tmp, data);
                                }
                                else
                                {
                                    File.WriteAllText(tmp, args.FileContents);
                                }
                                result = MoveTmpFileToDestination(dst, tmp, result);
                                RemoveTmpFile(tmp);
                                break;
                        }
                    }
                    else
                    {
                        // we can write directly to the file
                        Dev2CRUDOperationTO newArgs = new Dev2CRUDOperationTO(true);

                        CreateEndPoint(dst, newArgs, true);

                        if(IsBase64(args.FileContents))
                        {
                            var data = Convert.FromBase64String(args.FileContents.Replace("Content-Type:BASE64", ""));
                            File.WriteAllBytes(dst.IOPath.Path, data);
                        }
                        else
                        {
                            File.WriteAllText(dst.IOPath.Path, args.FileContents);
                        }
                    }
                }
            }
            finally
            {
                _fileLock.ExitWriteLock();
                for(var index = _filesToDelete.Count-1; index > 0; index--)
                {
                    var name = _filesToDelete[index];
                    RemoveTmpFile(name);
                }
            }
            return result;
        }
 public string PutRaw(IActivityIOOperationsEndPoint dst, Dev2PutRawOperationTO args)
 {
     Destination = dst;
     Dev2PutRawOperationTo = args;
     return "Successful";
 }