Atomia.Provisioning.Modules.Folders.Commands.FileCommand.ExecuteAdd C# (CSharp) Метод

ExecuteAdd() защищенный Метод

protected ExecuteAdd ( Base moduleService ) : void
moduleService Base
Результат void
        protected override void ExecuteAdd(Base.Module.ModuleService moduleService)
        {
            switch (transContext)
            {
                case "BeginTransaction":
                    {
                        string rootFolder = this.resource["RootFolder"].ToString();
                        if (rootFolder == "")
                        {
                            rootFolder = "c:\\ProvisioningModuleTestFolder\\";
                        }

                        if (rootFolder.Substring(rootFolder.Length - 1, 1) != "\\")
                        {
                            rootFolder += "\\";
                        }

                        string fileName = moduleService.Properties.Find(p => p.Name == "Name").Value;

                        string parentFolder = moduleService.Properties.Find(p => p.Name == "ParentFolder").Value;

                        string fileFullPath = rootFolder + parentFolder + "\\" + fileName;

                        string fileContent = moduleService.Properties.Find(p => p.Name == "Content").Value;

                        if (File.Exists(fileFullPath))
                        {
                            throw ExceptionHelper.GetModuleException("ID422012", null, null);
                        }
                        else
                        {
                            File.WriteAllText(fileFullPath, fileContent);
                        }

                        bool bExist = moduleService.Properties.Exists(prop => prop.Name == "TestChangesPropagation");
                        if (bExist == false)
                        {
                            moduleService.Properties.Add(new ModuleServiceProperty("TestChangesPropagation", "NewValueForTesting"));
                        }
                        else
                        {
                            moduleService["TestChangesPropagation"] = "NewValueForTesting";
                        }

                    }
                    break;
                case "CommitTransaction":
                    {
                        //file is already added in BeginTransaction
                        //everything is OK and nothing to do
                    }
                    break;
                case "RollBackTransaction":
                    {
                        string rootFolder = this.resource["RootFolder"].ToString();
                        if (rootFolder == "")
                        {
                            rootFolder = "c:\\ProvisioningModuleTestFolder\\";
                        }

                        if (rootFolder.Substring(rootFolder.Length - 1, 1) != "\\")
                        {
                            rootFolder += "\\";
                        }

                        string fileName = moduleService.Properties.Find(p => p.Name == "Name").Value;

                        string parentFolder = moduleService.Properties.Find(p => p.Name == "ParentFolder").Value;

                        string fileFullPath = rootFolder + parentFolder + "\\" + fileName;

                        if (File.Exists(fileFullPath))
                        {
                            File.Delete(fileFullPath);
                        }
                        else
                        {
                            //nothing to do
                        }
                    }
                    break;
            }
        }