/*Start--------------------Portal and Survey Skin Updates for Dynamic Variables by Optimus-----------------*/
        public static bool UpdateSkinDynamicVariable(string replacementValue, string skinFolderPath, string substitution,
            string propertyName, ReplacementDirectory.Replacement replacementDirectory)
        {
            List<String> files = new List<string>();
            FileSearch(skinFolderPath, files);

            foreach (string file in files)
            {
                if (!Exists(file)) continue;
                TextReader reader = new StreamReader(file);
                string contents = reader.ReadToEnd();
                reader.Close();
                if (contents.Contains(substitution))
                {
                    contents = contents.Replace(substitution, replacementValue);
                }
                TextWriter writer = new StreamWriter(file);
                writer.Write(contents);
                writer.Close();
            }
            return true;
        }
示例#2
0
 // Updating Portal and Survey Skin with Dynamic Variable Values by Optimus
 private static void ApplyDynamicVariables(PanelPreferences preferences, string groupName, GuiVariable guiVar, string skinFolderPath,
     string dataPath, ReplacementDirectory.Replacement replacementDirectory)
 {
     switch (guiVar.UiComponent)
     {
         // Modified by K.G for phase2 task 'Support upload/processing of non-image files (e.g. pdf)'.
         case "FileUpload()":
             SkinManagerHelper.UpdateDynamicFile(preferences.DynamicGuiVariables[guiVar.ComponentName],
                 skinFolderPath, dataPath, guiVar.PropertyName, replacementDirectory, guiVar.PathToUpload);
             break;
         case "ChoiceSelector()":
             var replaceValues = guiVar.PropertyName.Split(',');
             if (replaceValues.Length != 2) throw new Exception("Choice Selections must provide values for selected and unselected in PropertyName (e.g. 'block,none')");
             var replacementValue = preferences.DynamicGuiVariables[guiVar.ComponentName] == "true" ? replaceValues[0] : replaceValues[1];
             SkinManagerHelper.UpdateSkinDynamicVariable(replacementValue, skinFolderPath, guiVar.Substitution, guiVar.PropertyName, replacementDirectory);
             break;
         default:
             SkinManagerHelper.UpdateSkinDynamicVariable(preferences.DynamicGuiVariables[guiVar.ComponentName],
                 skinFolderPath, guiVar.Substitution, guiVar.PropertyName, replacementDirectory);
             break;
     }
 }
        /*        public static bool UpdateSkinVariableListChoiceText(string value, string skinFolderPath, string substitution,
                    string propertyName, bool isPortal)
                {
                    if (null == value)
                    {
                        return true;
                    }

                    string cssPath = isPortal ? Res.PortalCommonCSSPath : Res.SurveyLayoutCSSPath;

                    string combineCssPath = Path.Combine(skinFolderPath, cssPath);
                    Exists(combineCssPath);

                    TextReader reader = new StreamReader(combineCssPath);
                    string commonCss = reader.ReadToEnd();
                    reader.Close();

                    if (commonCss.Contains(substitution))
                    {
                        commonCss = commonCss.Replace(substitution, String.Format("{0} : {1};", propertyName, value));
                    }
                    TextWriter writer = new StreamWriter(combineCssPath);
                    writer.Write(commonCss);
                    writer.Close();

                    return true;
                }

                public static bool UpdateSkinChoice(string value, string skinFolderPath, string substitution,
                    string propertyName, bool isPortal)
                {
                    if (Convert.ToBoolean(value) || !isPortal)
                    {
                        return true; //By default its visible
                    }

                    string cssPath = Res.PortalMemberCSSPath;

                    string combineCssPath = Path.Combine(skinFolderPath, cssPath);
                    Exists(combineCssPath);

                    TextReader reader = new StreamReader(combineCssPath);
                    string commonCss = reader.ReadToEnd();
                    reader.Close();

                    if (commonCss.Contains(substitution))
                    {
                        commonCss = commonCss.Replace(substitution, String.Format("{0};", propertyName));
                    }
                    TextWriter writer = new StreamWriter(combineCssPath);
                    writer.Write(commonCss);
                    writer.Close();

                    return true;
                }
        */
        // Modified by K.G: To make image upload control to file upload control & Now Path is coming from substitution.xml.
        public static bool UpdateDynamicFile(string fileName, string skinFolderPath, string dataPath, string propertyName, ReplacementDirectory.Replacement replacementDirectory, string pathToUpload)
        {
            if (null == fileName)
            {
                return true;
            }

            if (fileName.Length == 0)
            {
                return true;
            }
            string fileExtention = Path.GetExtension(fileName);
             var newFilePath = string.Empty;
            // Modified by K.G(24-11-2011) to support multi path upload
            if (!string.IsNullOrEmpty(pathToUpload))
            {
                string[] pathsWithDirectoryName = pathToUpload.Split(':');
                foreach (var pathwithdeirwctoryname in pathsWithDirectoryName)
                {
                    int index = pathwithdeirwctoryname.IndexOf('\\');
                    string directoryZipName = pathwithdeirwctoryname.Substring(0, index);
                    if(directoryZipName.ToLower().Contains(ReplacementDirectory.GetReplacementDirectory(replacementDirectory)))
                    {
                        newFilePath=pathwithdeirwctoryname.Substring(index + 1);
                        break;
                    }

                }
            }

            StringBuilder filePath = new StringBuilder();
            filePath.Append(newFilePath);
            filePath.Append(propertyName);
            filePath.Append(fileExtention);

            string combinedFilePath = Path.Combine(skinFolderPath, filePath.ToString());

            if (File.Exists(combinedFilePath))
            {
                File.Delete(combinedFilePath);
            }

            string newFileSourcePath = Path.Combine(dataPath,
                                               String.Format("{0}{1}", Res.UploadsFolder, Path.GetFileName(fileName)));
            Exists(newFileSourcePath);

            File.Copy(newFileSourcePath, combinedFilePath);

            Exists(combinedFilePath);

            return true;
        }