示例#1
0
        /// <summary>
        /// 预加载模型
        /// </summary>
        /// <param name="prefab_path"></param>
        /// <param name="resourceNameType"></param>
        public bool PreloadModel(string prefab_path, FileNameType fileNameType = FileNameType.NONE)
        {
            if (string.IsNullOrEmpty(prefab_path))
            {
                Debug.LogError("Effect_name is null");
                return(false);
            }

            string effectprefab_path = FormatFileName(prefab_path, fileNameType);
            string realName          = GetNameWithRemovePath(effectprefab_path);

            if (EffectSpawnPool.GetPrefabPool(realName) == null)
            {
                PrefabPool prefabPool = GetModelPrefabPool(realName, effectprefab_path, fileNameType);

                if (prefabPool == null)
                {
                    return(false);
                }
#if UNITY_EDITOR
                if (!EffectSpawnPool._perPrefabPoolOptions.Contains(prefabPool))
                {
                    EffectSpawnPool._perPrefabPoolOptions.Add(prefabPool);
                }
#endif
                EffectSpawnPool.CreatePrefabPool(prefabPool);
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// 读表创建怪物
        /// </summary>
        /// <param name="monsterID"></param>
        /// <returns></returns>
        GameObject CreateMonsterGameObject(uint monsterID, FileNameType fileNameType = FileNameType.ASSET_BUNDLE_NAME)
        {
            /* 预留读表
             * wl_res.NPCBaseInfo refNPCBaseInfo;
             * if (!m_refNPCBaseInfoTable.GetData(MonsterID, out refNPCBaseInfo))
             * {
             *  Debuger.LogError("Can't find MonsterID:" + MonsterID + "in HeroBasicAttributesTable");
             *  return null;
             * }
             *
             * wl_res.ResConfig refResConfig;
             * if (!m_refResConfigTable.GetData(refNPCBaseInfo.ResID, out refResConfig))
             * {
             *  Debuger.LogError("Can't find MonsterID:" + MonsterID + "'s ResId:" + refNPCBaseInfo.ResID + "in ResConfigTable");
             *  return null;
             * }
             *
             * string modelFileStr = StringUtility.UTF8BytesToString(ref refResConfig.ModelFile);
             */
            string     modelFile = "";
            GameObject obj       = CreateGameObjectByPrefabPath(modelFile, fileNameType);

            if (obj == null)
            {
                return(null);
            }

            return(obj);
        }
示例#3
0
        public string ToString(FileNameType fileNameType = FileNameType.Relative, bool printStackTrace = false)
        {
            string fileName = fileNameType == FileNameType.None
                ? ""
                : fileNameType == FileNameType.Full
                ? CodeFile.FullName
                : fileNameType == FileNameType.Relative
                ? CodeFile.RelativeName
                : CodeFile.Name;

            string fileNameString = !string.IsNullOrEmpty(fileName)
                ? $@" in ""{fileName}"""
                : "";
            string patternString = CodeFile.IsPattern ? "Pattern " : "";

            string exceptionString = printStackTrace
                ? InnerException?.FormatExceptionMessage() ?? Message
                : Message;

            if (string.IsNullOrEmpty(exceptionString))
            {
                exceptionString = InnerException?.FormatExceptionMessage();
            }

            if (!string.IsNullOrEmpty(exceptionString))
            {
                exceptionString = $": {exceptionString}";
            }

            return($"{patternString}{ExceptionType}{fileNameString}{exceptionString}.");
        }
示例#4
0
        /// <summary>
        /// 读表创建英雄单位
        /// </summary>
        /// <param name="heroID"></param>
        /// <returns></returns>
        GameObject CreateHeroGameObject(uint heroID, FileNameType fileNameType = FileNameType.ASSET_BUNDLE_NAME)
        {
            /* 预留读表
             * wl_res.HeroBasicAttributes refHeroBasicAttributes;
             * if (!m_refHeroBasicAttributesTable.GetData(HeroID, out refHeroBasicAttributes))
             * {
             *  Debug.LogError("Can't find HeroID:" + HeroID + "in HeroBasicAttributesTable");
             *  return null;
             * }
             *
             * wl_res.ResConfig refResConfig;
             * if (!m_refResConfigTable.GetData(refHeroBasicAttributes.ResId, out refResConfig))
             * {
             *  Debug.LogError("Can't find HeroID:" + HeroID + "'s ResId:" + refHeroBasicAttributes.ResId + "in ResConfigTable");
             *  return null;
             * }
             *
             * string modelFile = StringUtility.UTF8BytesToString(ref refResConfig.ModelFile);
             */

            string     modelFile = "";
            GameObject obj       = CreateGameObjectByPrefabPath(modelFile, fileNameType);

            if (obj == null)
            {
                return(null);
            }

            return(obj);
        }
示例#5
0
        /// <summary>
        /// Get file name
        /// </summary>
        /// <param name="isDirectory">true for directory</param>
        /// <param name="fileNameType">file name type</param>
        /// <returns>The file name</returns>
        private string GetFileName(bool isDirectory, FileNameType fileNameType)
        {
            switch (fileNameType)
            {
            case FileNameType.NotExistedValidFileName:
                fileName = isDirectory ? "CreateClose_Directory_" + Guid.NewGuid() : "CreateClose_File_" + Guid.NewGuid() + ".txt";
                break;

            case FileNameType.ExistedValidFileName:
                break;

            case FileNameType.SymbolicLinkInMiddle:
                fileName = TestConfig.SymboliclinkInSubFolder + "\\CreateClose" + Guid.NewGuid();
                break;

            case FileNameType.SymbolicLinkAtLast:
                fileName = TestConfig.SymboliclinkInSubFolder;
                break;

            case FileNameType.InvalidSymbolicLink:
                fileName = TestConfig.Symboliclink + "\\CreateClose" + Guid.NewGuid();
                break;

            default:
                throw new ArgumentException("fileNameType");
            }

            return(fileName);
        }
示例#6
0
        public static string CreateFileName(int Seed, FileNameType types, string OriginalFileName, string Extension)
        {
            Random random = new Random();

            switch (types)
            {
            case FileNameType.Date:
                return(DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(Seed) + Extension);

            case FileNameType.FileNameAndDate:
                return(string.Concat(new object[] { OriginalFileName.Replace(Extension, "-"), DateTime.Now.ToString("yyyyMMddhhmmss"), random.Next(Seed), Extension }));

            case FileNameType.MD516:
                return(StringHelper.MD516(Guid.NewGuid().ToString()) + Extension);

            case FileNameType.MD532:
                return(StringHelper.MD532(Guid.NewGuid().ToString()) + Extension);

            case FileNameType.Guid:
                return(Guid.NewGuid().ToString() + Extension);

            case FileNameType.OriginalFileName:
                return(OriginalFileName);
            }
            return(Guid.NewGuid().ToString() + Extension);
        }
示例#7
0
        /// <summary>
        /// 获取角色模型池
        /// </summary>
        /// <param name="prefab_path"></param>
        /// <returns></returns>
        PrefabPool GetModelPrefabPool(string realName, string prefab_path, FileNameType fileNameType = FileNameType.RESOURCE_NAME)
        {
            PrefabPool prefabPool = null;

            Transform trans = null;

            switch (fileNameType)
            {
            case FileNameType.NONE:
                break;

            case FileNameType.RESOURCE_NAME:
            {
                trans = Resources.Load <Transform>(prefab_path);
                if (trans == null)
                {
                    return(null);
                }
            }
            break;

            case FileNameType.ASSET_BUNDLE_NAME:
                //go = ResManager.Instance.LoadMode(prefab_path);
                break;

            case FileNameType.ASSET_NAME:
                break;

            case FileNameType.APP_NAME:
                break;

            case FileNameType.FULL_NAME:
                break;

            default:
                break;
            }

            if (trans != null)
            {
                prefabPool = new PrefabPool(trans);

                if (prefabPool != null)
                {
                    prefabPool.preloadAmount  = 1;
                    prefabPool.limitInstances = false;
                    prefabPool.limitFIFO      = false;
                    prefabPool.limitAmount    = 5;
                    prefabPool.cullDespawned  = true;
                    prefabPool.cullAbove      = 5;
                    prefabPool.cullDelay      = 10;
                    prefabPool.cullMaxPerPass = 5;
                }
            }

            return(prefabPool);
        }
示例#8
0
        public static string GetPrettyErrorMessage(this Exception ex, FileNameType fileNameType = FileNameType.None)
        {
            if (ex is PMException pmException)
            {
                return(pmException.ToString(fileNameType));
            }

            return(ex.FormatExceptionMessage());
        }
示例#9
0
        private ObservableCollection <string> _filenames(FileNameType fType)
        {
            ObservableCollection <string> temp = new ObservableCollection <string>();

            foreach (FileInfo fi in this)
            {
                temp.Add((fType == FileNameType.FullName ? fi.FullName :
                          (fType == FileNameType.Path ? fi.DirectoryName :
                           (fType == FileNameType.Name ? fi.Name :
                            (fType == FileNameType.Extension ? fi.Extension : "")))));
            }
            return(temp);
        }
示例#10
0
        private ObservableCollection <string> _filenames(FileNameType fType, ThisFile tf)
        {
            ObservableCollection <string> temp = new ObservableCollection <string>();

            foreach (ConversionFileInfo fi in this)
            {
                temp.Add((fType == FileNameType.FullName ? (tf == ThisFile.Source ? fi.Source.FullName : fi.Target.FullName) :
                          (fType == FileNameType.Path ? (tf == ThisFile.Source ? fi.Source.DirectoryName : fi.Target.DirectoryName) :
                           (fType == FileNameType.Name ? (tf == ThisFile.Source ? fi.Source.Name : fi.Target.Name) :
                            (fType == FileNameType.Extension ? (tf == ThisFile.Source ? fi.Source.Extension : fi.Target.Extension) : "")))));
            }
            return(temp);
        }
示例#11
0
        /// <summary>
        /// 根据预测路径创建对象
        /// </summary>
        /// <param name="prefabPath"></param>
        /// <returns></returns>
        GameObject CreateGameObjectByPrefabPath(string prefab_path, FileNameType fileNameType = FileNameType.NONE)
        {
            string     realName = GetNameWithRemovePath(prefab_path);
            GameObject go       = null;

            if (PreloadModel(prefab_path, fileNameType))
            {
                Transform spawnGO = EffectSpawnPool.Spawn(realName);
                if (spawnGO != null)
                {
                    go = spawnGO.gameObject;
                }
            }
            return(go);
        }
示例#12
0
        public static string FormatFileName(string strFileName, FileNameType t)
        {
            if (t == FileNameType.NONE)
            {
                return(strFileName);
            }

            if (t == FileNameType.RESOURCE_NAME)
            {
                bool   bOk             = false;
                string strResourcePath = "Resources/";
                int    index           = strFileName.IndexOf(strResourcePath);
                if (index >= 0)
                {
                    strFileName = strFileName.Substring(strResourcePath.Length + index);
                    index       = strFileName.LastIndexOf('.');
                    if (index >= 0)
                    {
                        strFileName = strFileName.Substring(0, index);
                        bOk         = true;
                    }
                }

                if (!bOk)
                {
                    strResourcePath = "Resources\\";
                    index           = strFileName.IndexOf(strResourcePath);
                    if (index >= 0)
                    {
                        strFileName = strFileName.Substring(strResourcePath.Length + index);
                        index       = strFileName.LastIndexOf('.');
                        if (index >= 0)
                        {
                            strFileName = strFileName.Substring(0, index);
                            bOk         = true;
                        }
                    }
                }
            }

            strFileName = strFileName.Replace('\\', '/');

            return(strFileName);
        }
        public static bool Save(MapMeta meta, FileNameType fileNameType = FileNameType.ID)
        {
            try
            {
                switch (fileNameType)
                {
                case FileNameType.ID:
                    File.WriteAllText(GetPath(meta.Map.ID), JsonUtility.ToJson(meta, true));
                    break;

                case FileNameType.Name:
                    File.WriteAllText(GetPath(meta.Map.Name), JsonUtility.ToJson(meta, true));
                    break;
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.Message);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Check the status code of create response
        /// </summary>
        /// <param name="isNonAdmin">true for non admin credential</param>
        /// <param name="createOption">The create option set in create request</param>
        /// <param name="accessMask">The access mark set in create request</param>
        /// <param name="header">Header of create response</param>
        /// <param name="response">create response</param>
        /// <param name="fileNameType">file name type</param>
        private void CheckCreateResponse(bool isNonAdmin, CreateOptions_Values createOption, AccessMask accessMask, Packet_Header header, CREATE_Response response, FileNameType fileNameType)
        {
            switch (fileNameType)
            {
            case FileNameType.SymbolicLinkInMiddle:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                    header.Status,
                    "3.3.5.9: If any intermediate component of the path specified in the create request is a symbolic link, " +
                    "the server MUST return an error as specified in section 2.2.2.1. " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                break;
            }

            case FileNameType.SymbolicLinkAtLast:
            {
                if (!createOption.HasFlag(CreateOptions_Values.FILE_OPEN_REPARSE_POINT))
                {
                    BaseTestSite.Assert.AreEqual(
                        Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                        header.Status,
                        "3.3.5.9: If the final component of the path is a symbolic link, the server behavior depends on whether the flag FILE_OPEN_REPARSE_POINT was specified in the CreateOptions field of the request. " +
                        "If FILE_OPEN_REPARSE_POINT was specified, the server MUST open the underlying file or directory and return a handle to it. " +
                        "Otherwise, the server MUST return an error as specified in section 2.2.2.1. " +
                        "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                }
                break;
            }

            case FileNameType.InvalidSymbolicLink:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                    header.Status,
                    "3.3.5.9: If the underlying object store returns a failure indicating that the attempted open operation failed due to the presence of a symbolic link in the target path name, " +
                    "the server MUST fail the create operation with the error code STATUS_STOPPED_ON_SYMLINK. " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                break;
            }

            case FileNameType.NotExistedValidFileName:
            {
                if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) &&
                    !(accessMask.HasFlag(AccessMask.DELETE) || accessMask.HasFlag(AccessMask.GENERIC_ALL)))
                {
                    if (testConfig.Platform == Platform.NonWindows)
                    {
                        BaseTestSite.Assert.AreNotEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2008 ||
                             testConfig.Platform == Platform.WindowsServer2008R2)
                    {
                        //TD does not specify the behavior of windows 2008 and 2008R2, not check here
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2012)
                    {
                        //For platform windows 2012
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_INVALID_PARAMETER,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else
                    {
                        //For platform windows 2012R2 and above
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_ACCESS_DENIED,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                }
                else if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) && isNonAdmin)
                {
                    //NonAdminAccountCredential does not include DELETE or GENERIC_ALL in MaximalAccess
                    if (testConfig.Platform == Platform.NonWindows)
                    {
                        BaseTestSite.Assert.AreNotEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2008 ||
                             testConfig.Platform == Platform.WindowsServer2008R2)
                    {
                        //TD does not specify te behavior of windows 2008 and 2008R2, not check here
                    }
                    else
                    {
                        //For platform win2012 and 2012R2
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_ACCESS_DENIED,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                }
                else
                {
                    BaseTestSite.Assert.AreEqual(
                        Smb2Status.STATUS_SUCCESS,
                        header.Status,
                        "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
                }
                break;
            }

            case FileNameType.ExistedValidFileName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
            }
            break;

            case FileNameType.NotExistedValidFileNameWithDotDirectoryName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
            }
            break;

            case FileNameType.NotExistedValidFileNameWithDoubleDotDirectoryName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_INVALID_PARAMETER,
                    header.Status,
                    "3.3.5.9: Windows-based servers accept the path names containing Dot Directory Names specified in [MS-FSCC] section 2.1.5.1 and attempt to normalize the path name by removing the pathname components of \".\"  and \"..\"." +
                    "Windows-based servers fail the CREATE request with STATUS_INVALID_PARAMETER if the file name in the Buffer field of the request begins in the form \"subfolder\\..\\\", for example \"x\\..\\y.txt\". " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
            }
            break;

            default:
                throw new ArgumentException("fileNameType");
            }
        }
        /// <summary>
        /// Create or delete a file or directory with a given name.
        /// </summary>
        /// <param name="client">the functional client used to create</param>
        /// <param name="isDirectory">true for file and false for directory</param>
        /// <param name="isDeleteFlagSet">true for delete flag set</param>
        /// <param name="isNonAdmin">true for non admin account credential</param>
        /// <param name="fileNametype">the file name type: ValidFileName, SymbolicLinkInMiddle, SymbolicLinkAtLast, InvalidSymbolicLink</param>
        /// <param name="isValidAccessMask">true for valid access mask, which should contain DELETE or GENERIC_ALL</param>
        private void OperateFileOrDirectory(Smb2FunctionalClient client, bool isDirectory, bool isDeleteFlagSet, bool isNonAdmin, FileNameType fileNameType, bool isValidAccessMask)
        {
            CreateOptions_Values     createOption;
            CreateDisposition_Values createDisposition;

            if (isDirectory)
            {
                createOption = CreateOptions_Values.FILE_DIRECTORY_FILE;
            }
            else
            {
                createOption = CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
            }

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT.");
            client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            AccountCredential accountCredential = isNonAdmin ? TestConfig.NonAdminAccountCredential : TestConfig.AccountCredential;

            client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, accountCredential, false);
            uint treeId;

            client.TreeConnect(sharePath, out treeId);
            FILEID fileId;

            Smb2CreateContextResponse[] createContextResponse;

            AccessMask accessMask = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE;

            accessMask = isValidAccessMask ? accessMask : AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE;
            // The delete flag is set in the following situations: 1. Delete an existed file; 2. Test CreateOptions_Values.FILE_DELETE_ON_CLOSE combined with DesiredAccess
            createOption = isDeleteFlagSet ? (createOption | CreateOptions_Values.FILE_DELETE_ON_CLOSE) : createOption;
            // The createDisposition is set to FILE_OPEN if the file already existed; else, if it's the first time to create a file, this field should be set to FILE_CREATE
            createDisposition = (fileNameType == FileNameType.ExistedValidFileName) ? CreateDisposition_Values.FILE_OPEN : CreateDisposition_Values.FILE_CREATE;
            fileName          = GetFileName(isDirectory, fileNameType);
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with create option: {0} and create disposition: {1}", createOption, createDisposition);
            uint status = client.Create(
                treeId,
                fileName,
                createOption,
                out fileId,
                out createContextResponse,
                accessMask: accessMask,
                createDisposition: createDisposition,
                checker: (header, response) =>
            {
                CheckCreateResponse(isNonAdmin, createOption, accessMask, header, response, fileNameType);
            });

            AddTestFileName(sharePath, fileName);

            if (status == Smb2Status.STATUS_SUCCESS)
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF.");
                client.Close(treeId, fileId);
            }

            client.TreeDisconnect(treeId);
            client.LogOff();
        }
示例#16
0
 private string GetFileName(DateTime date, FileNameType type)
 {
     var strDate = date.ToString(CultureInfo.InvariantCulture)
         .Select(c => Path.GetInvalidFileNameChars().Contains(c) ? '_' : c)
         .Aggregate(new StringBuilder(), (sb, c) => sb.Append(c), sb => sb.ToString());
     switch (type)
     {
         case FileNameType.Default:
             return string.Format("{0}.xml", strDate);
         case FileNameType.ForSaving:
             return string.Format("{0}_saving.xml", strDate);
         default:
             throw new ArgumentException("Unsupported file name type", "type");
     }
 }
 /// <summary>
 /// Check the status code of create response
 /// </summary>
 /// <param name="isNonAdmin">true for non admin credential</param>
 /// <param name="createOption">The create option set in create request</param>
 /// <param name="accessMask">The access mark set in create request</param>
 /// <param name="header">Header of create response</param>
 /// <param name="response">create response</param>
 /// <param name="fileNameType">file name type</param>
 private void CheckCreateResponse(bool isNonAdmin, CreateOptions_Values createOption, AccessMask accessMask, Packet_Header header, CREATE_Response response, FileNameType fileNameType)
 {
     switch (fileNameType)
     {
         case FileNameType.SymbolicLinkInMiddle:
             {
                 BaseTestSite.Assert.AreEqual(
                     Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                     header.Status,
                     "3.3.5.9: If any intermediate component of the path specified in the create request is a symbolic link, " +
                     "the server MUST return an error as specified in section 2.2.2.1. " +
                     "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                 break;
             }
         case FileNameType.SymbolicLinkAtLast:
             {
                 if (!createOption.HasFlag(CreateOptions_Values.FILE_OPEN_REPARSE_POINT))
                 {
                     BaseTestSite.Assert.AreEqual(
                         Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                         header.Status,
                         "3.3.5.9: If the final component of the path is a symbolic link, the server behavior depends on whether the flag FILE_OPEN_REPARSE_POINT was specified in the CreateOptions field of the request. " +
                         "If FILE_OPEN_REPARSE_POINT was specified, the server MUST open the underlying file or directory and return a handle to it. " +
                         "Otherwise, the server MUST return an error as specified in section 2.2.2.1. " +
                         "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                 }
                 break;
             }
         case FileNameType.InvalidSymbolicLink:
             {
                 BaseTestSite.Assert.AreEqual(
                     Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                     header.Status,
                     "3.3.5.9: If the underlying object store returns a failure indicating that the attempted open operation failed due to the presence of a symbolic link in the target path name, " +
                     "the server MUST fail the create operation with the error code STATUS_STOPPED_ON_SYMLINK. " +
                     "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                 break;
             }
         case FileNameType.NotExistedValidFileName:
             {
                 if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE)
                     && !(accessMask.HasFlag(AccessMask.DELETE) || accessMask.HasFlag(AccessMask.GENERIC_ALL)))
                 {
                     if (testConfig.Platform == Platform.NonWindows)
                     {
                         BaseTestSite.Assert.AreNotEqual(
                             Smb2Status.STATUS_SUCCESS,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "DesiredAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                     else if (testConfig.Platform == Platform.WindowsServer2008
                         || testConfig.Platform == Platform.WindowsServer2008R2)
                     {
                         //TD does not specify the behavior of windows 2008 and 2008R2, not check here
                     }
                     else if(testConfig.Platform == Platform.WindowsServer2012)
                     {
                         //For platform windows 2012
                         BaseTestSite.Assert.AreEqual(
                             Smb2Status.STATUS_INVALID_PARAMETER,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "DesiredAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                     else
                     {
                         //For platform windows 2012R2 and above
                         BaseTestSite.Assert.AreEqual(
                             Smb2Status.STATUS_ACCESS_DENIED,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "DesiredAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                 }
                 else if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) && isNonAdmin)
                 {
                     //NonAdminAccountCredential does not include DELETE or GENERIC_ALL in MaximalAccess
                     if (testConfig.Platform == Platform.NonWindows)
                     {
                         BaseTestSite.Assert.AreNotEqual(
                             Smb2Status.STATUS_SUCCESS,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "Treeconnect.MaximalAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                     else if (testConfig.Platform == Platform.WindowsServer2008
                         || testConfig.Platform == Platform.WindowsServer2008R2)
                     {
                         //TD does not specify te behavior of windows 2008 and 2008R2, not check here
                     }
                     else
                     {
                         //For platform win2012 and 2012R2
                         BaseTestSite.Assert.AreEqual(
                             Smb2Status.STATUS_ACCESS_DENIED,
                             header.Status,
                             "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and any of the following conditions is TRUE, the server SHOULD<242> fail the request with STATUS_ACCESS_DENIED. " +
                             "Treeconnect.MaximalAccess does not include DELETE or GENERIC_ALL. " +
                             "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                     }
                 }
                 else
                 {
                     BaseTestSite.Assert.AreEqual(
                         Smb2Status.STATUS_SUCCESS,
                         header.Status,
                         "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
                 }
                 break;
             }
         case FileNameType.ExistedValidFileName:
             {
                 BaseTestSite.Assert.AreEqual(
                         Smb2Status.STATUS_SUCCESS,
                         header.Status,
                         "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
             }
             break;
         default:
             throw new ArgumentException("fileNameType");
     }
 }
        /// <summary>
        /// Get file name
        /// </summary>
        /// <param name="isDirectory">true for directory</param>
        /// <param name="fileNameType">file name type</param>
        /// <returns>The file name</returns>
        private string GetFileName(bool isDirectory, FileNameType fileNameType)
        {
            switch (fileNameType)
            {
                case FileNameType.NotExistedValidFileName:
                    fileName = isDirectory ? "CreateClose_Directory_" + Guid.NewGuid() : "CreateClose_File_" + Guid.NewGuid() + ".txt";
                    break;
                case FileNameType.ExistedValidFileName:
                    break;
                case FileNameType.SymbolicLinkInMiddle:
                    fileName = TestConfig.SymboliclinkInSubFolder + "\\CreateClose" + Guid.NewGuid();
                    break;
                case FileNameType.SymbolicLinkAtLast:
                    fileName = TestConfig.SymboliclinkInSubFolder;
                    break;
                case FileNameType.InvalidSymbolicLink:
                    fileName = TestConfig.Symboliclink + "\\CreateClose" + Guid.NewGuid();
                    break;
                default:
                    throw new ArgumentException("fileNameType");
            }

            return fileName;
        }
示例#19
0
 public static string CreateFileName(FileNameType types, string OriginalFileName, string Extension)
 {
     return(CreateFileName(0x3e8, types, OriginalFileName, Extension));
 }
        /// <summary>
        /// Create or delete a file or directory with a given name.
        /// </summary>
        /// <param name="client">the functional client used to create</param>
        /// <param name="isDirectory">true for file and false for directory</param>
        /// <param name="isDeleteFlagSet">true for delete flag set</param>
        /// <param name="isNonAdmin">true for non admin account credential</param>
        /// <param name="fileNametype">the file name type: ValidFileName, SymbolicLinkInMiddle, SymbolicLinkAtLast, InvalidSymbolicLink</param>
        /// <param name="isValidAccessMask">true for valid access mask, which should contain DELETE or GENERIC_ALL</param>
        private void OperateFileOrDirectory(Smb2FunctionalClient client, bool isDirectory, bool isDeleteFlagSet, bool isNonAdmin, FileNameType fileNameType, bool isValidAccessMask)
        {
            CreateOptions_Values createOption;
            CreateDisposition_Values createDisposition;
            if (isDirectory)
            {
                createOption = CreateOptions_Values.FILE_DIRECTORY_FILE;
            }
            else
            {
                createOption = CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
            }

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT.");
            client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            AccountCredential accountCredential = isNonAdmin ? TestConfig.NonAdminAccountCredential : TestConfig.AccountCredential;
            client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, accountCredential, false);
            uint treeId;
            client.TreeConnect(sharePath, out treeId);
            FILEID fileId;
            Smb2CreateContextResponse[] createContextResponse;

            AccessMask accessMask = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE;
            accessMask = isValidAccessMask ? accessMask : AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE;
            // The delete flag is set in the following situations: 1. Delete an existed file; 2. Test CreateOptions_Values.FILE_DELETE_ON_CLOSE combined with DesiredAccess
            createOption = isDeleteFlagSet ? (createOption | CreateOptions_Values.FILE_DELETE_ON_CLOSE) : createOption;
            // The createDisposition is set to FILE_OPEN if the file already existed; else, if it's the first time to create a file, this field should be set to FILE_CREATE
            createDisposition = (fileNameType == FileNameType.ExistedValidFileName) ? CreateDisposition_Values.FILE_OPEN : CreateDisposition_Values.FILE_CREATE;
            fileName = GetFileName(isDirectory, fileNameType);
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with create option: {0} and create disposition: {1}", createOption, createDisposition);
            uint status = client.Create(
                treeId,
                fileName,
                createOption,
                out fileId,
                out createContextResponse,
                accessMask: accessMask,
                createDisposition: createDisposition,
                checker: (header, response) =>
                {
                    CheckCreateResponse(isNonAdmin, createOption, accessMask, header, response, fileNameType);
                });

            if (status == Smb2Status.STATUS_SUCCESS)
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF.");
                client.Close(treeId, fileId);
            }

            client.TreeDisconnect(treeId);
            client.LogOff();
        }
 public DBAccessData(string tableName, string sql, string addressFieldName, string textFieldName, string sortFieldName, string textPrefix, bool useLocalTexts, FileNameType outputNameType)
 {
     this.tableName = tableName;
     this.sql = sql;
     this.addressFieldName = addressFieldName;
     this.textFieldName = textFieldName;
     this.sortFieldName = sortFieldName;
     this.textPrefix = textPrefix;
     this.useLocalTexts = useLocalTexts;
     this.outputNameType = outputNameType;
 }
        private void AsyncCreateRequest(Smb2FunctionalClient client, bool isDirectory, FileNameType fileNameType, CreateOptions_Values createOption,
                                        CreateDisposition_Values createDisposition, uint treeId, AccessMask accessMask, List <ulong> messageIdsList)
        {
            fileName = GetFileName(isDirectory, fileNameType);
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with create option: {0} and create disposition: {1}", createOption, createDisposition);

            Task <ulong> t1 = Task.Factory.StartNew(() => client.Create1(
                                                        treeId,
                                                        fileName,
                                                        createOption,
                                                        accessMask: accessMask,
                                                        createDisposition: createDisposition));

            //ulong msgId = client.Create1(
            //     treeId,
            //     fileName,
            //     createOption,
            //     accessMask: accessMask,
            //     createDisposition: createDisposition);

            //Task.Factory.StartNew(() => WaitForResponse(t1.Result, client));
            //t1.Wait();
            messageIdsList.Add(t1.Result);
        }
            public static DBAccessData FromFile(string accessDataFilepath)
            {
                if (!File.Exists(accessDataFilepath))
                {
                    throw new Exception($"{accessDataFilepath} file not found");
                }

                Dictionary<string, string> data = ReadFileData(accessDataFilepath);

                string tableName, sql, addressFieldName, textFieldName, sortFieldName, textPrefix, _useLocalTexts, _outputNameType;

                data.TryGetValue("SQL", out sql);
                data.TryGetValue("TABLE", out tableName);
                data.TryGetValue("ADDRESS_FIELD", out addressFieldName);
                data.TryGetValue("TEXT_FIELD", out textFieldName);
                data.TryGetValue("SORT_FIELD", out sortFieldName);
                data.TryGetValue("TEXT_PREFIX", out textPrefix);
                data.TryGetValue("USE_LOCAL_TEXTS", out _useLocalTexts);
                data.TryGetValue("OUTPUT_NAME_TYPE", out _outputNameType);

                if (sql == null || tableName == null || addressFieldName == null || textFieldName == null || sortFieldName  == null || textPrefix == null || _useLocalTexts == null || _outputNameType == null)
                {
                    throw new Exception(String.Join(Environment.NewLine,
                        "Missing parameters in the db_access.txt file.",
                        "    Needs the parameters SQL, TABLE, ADDRESS_FIELD, TEXT_FIELD, SORT_FIELD, TEXT_PREFIX, USE_LOCAL_TEXTS and OUTPUT_NAME_TYPE"));
                }

                if(textPrefix.StartsWith("'") && textPrefix.EndsWith("'") && textPrefix.Length >= 2)
                {
                    textPrefix = textPrefix.Substring(1, textPrefix.Length - 2);
                }

                bool useLocalTexts = false;
                try { useLocalTexts = (bool)Convert.ToBoolean(_useLocalTexts); }
                catch { Console.WriteLine($"'{_useLocalTexts}' is not convertable to true or false"); }

                FileNameType outputNameType = FileNameType.SourceNameAndPrefix;
                if (_outputNameType == "NUMBER_ONLY")
                    outputNameType = FileNameType.PrefixOnly;
                else if (_outputNameType == "NUMBER_AND_SOURCE_NAME")
                    outputNameType = FileNameType.SourceNameAndPrefix;
                else if (_outputNameType == "SOURCE_NAME")
                    outputNameType = FileNameType.SourceName;
                else
                    throw new Exception("OUTPUT_NAME_TYPE has to be in ['NUMBER_ONLY', 'NUMBER_AND_SOURCE_NAME', 'SOURCE_NAME']");

                return new DBAccessData(tableName, sql, addressFieldName, textFieldName, sortFieldName, textPrefix, useLocalTexts, outputNameType);
            }
        /// <summary>
        /// Create or delete a file or directory with a given name.
        /// </summary>
        /// <param name="client">the functional client used to create</param>
        /// <param name="isDirectory">true for file and false for directory</param>
        /// <param name="isDeleteFlagSet">true for delete flag set</param>
        /// <param name="isNonAdmin">true for non admin account credential</param>
        /// <param name="fileNametype">the file name type: ValidFileName, SymbolicLinkInMiddle, SymbolicLinkAtLast, InvalidSymbolicLink</param>
        /// <param name="isValidAccessMask">true for valid access mask, which should contain DELETE or GENERIC_ALL</param>
        private void OperateFileOrDirectory(Smb2FunctionalClient client, bool isDirectory, bool isDeleteFlagSet, bool isNonAdmin, FileNameType fileNameType, bool isValidAccessMask)
        {
            CreateOptions_Values     createOption;
            CreateDisposition_Values createDisposition;

            if (isDirectory)
            {
                createOption = CreateOptions_Values.FILE_DIRECTORY_FILE;
            }
            else
            {
                createOption = CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
            }

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT.");
            client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            AccountCredential accountCredential = isNonAdmin ? TestConfig.NonAdminAccountCredential : TestConfig.AccountCredential;

            client.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, accountCredential, false);
            uint treeId;

            client.TreeConnect(sharePath, out treeId);
            //FILEID fileId;
            //Smb2CreateContextResponse[] createContextResponse;

            AccessMask accessMask = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE;

            accessMask = isValidAccessMask ? accessMask : AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE;
            // The delete flag is set in the following situations: 1. Delete an existed file; 2. Test CreateOptions_Values.FILE_DELETE_ON_CLOSE combined with DesiredAccess
            createOption = isDeleteFlagSet ? (createOption | CreateOptions_Values.FILE_DELETE_ON_CLOSE) : createOption;
            // The createDisposition is set to FILE_OPEN if the file already existed; else, if it's the first time to create a file, this field should be set to FILE_CREATE
            createDisposition = (fileNameType == FileNameType.ExistedValidFileName) ? CreateDisposition_Values.FILE_OPEN : CreateDisposition_Values.FILE_CREATE;

            //fileName = GetFileName(isDirectory, fileNameType);
            //BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with create option: {0} and create disposition: {1}", createOption, createDisposition);
            //uint status = client.Create(
            //    treeId,
            //    fileName,
            //    createOption,
            //    out fileId,
            //    out createContextResponse,
            //    accessMask: accessMask,
            //    createDisposition: createDisposition,
            //    checker: (header, response) =>
            //    {
            //        CheckCreateResponse(isNonAdmin, createOption, accessMask, header, response, fileNameType);
            //    });
            client.StopThreads();
            List <ulong> messageIdsList = new List <ulong>();

            //Task t1 = Task.Factory.StartNew(() =>
            //{
            for (int i = 0; i <= 3; i++)
            {
                AsyncCreateRequest(client, isDirectory, fileNameType, createOption, createDisposition, treeId, accessMask, messageIdsList);
            }
            //});

            //t1.Wait();

            //messageIdsList.Add(t2.Result);
            //if (t1.IsCompleted)
            //{
            foreach (ulong messageId in messageIdsList)
            {
                Task <TCPResponse> taskResponse = Task.Factory.StartNew(() => client.CreateResponse1(messageId,
                                                                                                     checker: (header, response) =>
                {
                    CheckCreateResponse(isNonAdmin, createOption, accessMask, header, response, fileNameType);
                }));

                if (taskResponse.Result.status == Smb2Status.STATUS_SUCCESS)
                {
                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF.");
                    client.Close(treeId, taskResponse.Result.fileId);
                }
            }

            //if (status == Smb2Status.STATUS_SUCCESS)
            //{
            //    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF.");
            //client.Close(treeId, fileId);
            //}

            client.StartThreads();
            client.TreeDisconnect(treeId);
            client.LogOff();
            //}
        }