public FormMapData SetRelationValues(FormMapData mapData)
        {
            int i=0;
            foreach ( FormMappingDataRelation relation in mapData.FormMappingRelations )
            {
                SetValue(mapData.FormTag[mapData.FormTag.Name][i],relation.CurrentValue);
                i++;
            }

            return mapData;
        }
        // TODO: Check for errors while updating
        private string UpdateFormMapping(string dirPath,string absPath, FormMapData data)
        {
            string newPath = absPath;
            if ( !File.Exists(newPath) )
            {
                newPath = GetFilePath(dirPath, newPath);
            }

            FileStream stm = null;
            if ( File.Exists(newPath) )
            {
                stm = File.Open(newPath,FileMode.Create);
            }
            else
            {
                // create any directory inside path
                string[] dirs = absPath.Split('/');
                string newDir = dirPath + "\\";
                for (int i=1;i<dirs.Length;i++)
                {
                    if (i==(dirs.Length-1))
                        break; // exit for loop

                    newDir += dirs[i] + "\\";
                    if ( !Directory.Exists(newDir) )
                    {
                        Directory.CreateDirectory(newDir);
                    }
                }
                stm = File.Open(newPath,FileMode.CreateNew);
            }

            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(stm,data);
            stm.Close();

            return newPath;
        }
        public void SaveFormMapping(Uri uri, FormMappingDataRelationList relations, Hashtable postDataValues, HtmlFormTag form)
        {
            // create new formMapData
            FormMapData formMapData = new FormMapData();
            formMapData.FormTag = form;
            formMapData.PostData = postDataValues;
            formMapData.FormMappingRelations = relations;

            // Save .gbmap file.
            this.AddFormMapping(uri, formMapData);
        }
        private void AddFormMapping(Uri siteUri, FormMapData data)
        {
            string folderName = siteUri.Authority + siteUri.Port;
            string uriAndPort = siteUri.Authority + ":" + siteUri.Port;
            string dir = formMapsFolder + @"\" + folderName;

            if ( !Directory.Exists(dir) )
            {
                Directory.CreateDirectory(dir);
            }

            // search index data for site root existence
            FormMappingDiskInfo diskInfo = (FormMappingDiskInfo)formMapIndex[uriAndPort];

            // add new to disk
            if ( diskInfo != null )
            {
                // get form mapping from site url
                diskInfo = (FormMappingDiskInfo)formMapIndex[uriAndPort + siteUri.AbsolutePath];

                // add file to disk
                string filePath = UpdateFormMapping(dir,siteUri.AbsolutePath,data);

                if ( diskInfo == null )
                {
                    diskInfo = new FormMappingDiskInfo(filePath);

                    // add reference to Index data
                    formMapIndex.Add(uriAndPort + siteUri.AbsolutePath, diskInfo);
                }
            }
            else
            {
                // add file to disk
                string filePath = UpdateFormMapping(dir,siteUri.AbsolutePath,data);

                diskInfo = new FormMappingDiskInfo(filePath);

                // add reference to Index data
                formMapIndex.Add(uriAndPort + siteUri.AbsolutePath, diskInfo);

                // add root reference to Index data
                formMapIndex.Add(uriAndPort,new FormMappingDiskInfo(""));
            }

            UpdateIndexData();
        }