Пример #1
0
        public override void Install(IDictionary savedState)
        {
            base.Install(savedState);

            // Create .dat file
            //
            // NOTE: during install we can't access the Web.config file, so the file name
            //  is just hard-coded here.  Given that you can't change the web.config file
            //  during install, this really shouldn't be a problem.  If someone changes the
            //  file location, then they'll have to deal with the problem of file permissions.
            //
            Console.WriteLine("Creating Venue Service data file.");
            string filepath = InstallPath + @"VenueService.dat";
            if( !File.Exists(filepath) )
            {
                using (FileStorage file = new FileStorage(filepath))
                {
                    // Add two sample venues
                    file.AddVenue(new Venue("*****@*****.**", "234.7.13.19", 5004,
                        "Sample Venue 1", null, null));
                    file.AddVenue(new Venue("*****@*****.**", "235.8.14.20", 5004,
                        "Sample Venue 2", null, null));
                }
            }
            else
            {
                Console.WriteLine("Data file exists.  Skipping creating file.");
            }

            // Store the location of the .dat file so the admin tool can find it
            using(RegistryKey key = Registry.LocalMachine.CreateSubKey(LocalMachineSubkey))
            {
                key.SetValue("DataFile", filepath);
            }

            try
            {
                FileSecurity fileSec = File.GetAccessControl(filepath);
                fileSec.AddAccessRule(new FileSystemAccessRule("IUSR_" + Environment.MachineName,
                    FileSystemRights.Modify, AccessControlType.Allow));
                File.SetAccessControl(filepath, fileSec);
            }
            catch(Exception)
            {
                MessageBox.Show(
                    "Setting the file security for the venueservice.dat file failed. \n" +
                    "This may be caused by the Internet Guest Account not being present \n" +
                    "or properly named. \n" +
                    "\nFor Venue Service to work properly, the data file must be \n" +
                    "modifiable by the Internet Guest Account. You must add \"modify\" \n" +
                    "permissions on the file for the Internet Guest Account.",
                    "File Security Changes Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        static VenueService()
        {
            // Start by getting the venue service storage (use the app.config as an override)
            string filePath = ConfigurationManager.AppSettings["FilePath"];
            if (filePath == null || filePath == String.Empty)
            {
                // Use the registry key
                using(RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                {
                    filePath = (string)key.GetValue("DataFile");
                }
            }

            storage = new FileStorage(filePath);
        }
Пример #3
0
        static void Main(string[] args)
        {
            string message;
            VenueService_Sample VenueService_Sample = null;

            try
            {
                // Start by getting the venue service storage (use the app.config as an override)
                string filePath = ConfigurationManager.AppSettings["FilePath"];
                if (filePath == null || filePath == String.Empty)
                {
                    // Use the registry key
                    using(RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                    {
                        filePath = (string)key.GetValue("DataFile");
                    }
                }
                FileStorage storage = new FileStorage(filePath);

                VenueService_Sample = new VenueService_Sample();

                message = "VenueService_Sample started successfully";
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);

                // Create a reference to the VenueService web service
                Console.WriteLine("Create a reference to the VenueService web service");
                MSR.LST.ConferenceXP.VenueService.VenueService.VenueService vs = new MSR.LST.ConferenceXP.VenueService.VenueService.VenueService();

                // Cleanup - remove venues and particpants in case the sample was cancelled before it finished
                // Will fail silently if not present
                try
                {
                    storage.DeleteVenue("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteVenue("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteParticipant("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteParticipant("*****@*****.**");
                }
                catch {}

                Console.WriteLine("Create venues called v1 and v2, and set venue security");
                // Create the first venue called v1, and update the attributes
                // Create the security so venue1@ms and anyone at hotmail can join
                Venue v1 = new Venue();
                v1.Name = "Test Venue 1";
                v1.Identifier = "*****@*****.**";
                v1.Icon = null;
                v1.IPAddress = "233.233.233.10";
                v1.Port = 1000;
                v1.AccessList = new SecurityPatterns(new String[] { @"[\w-]@hotmail.com" });
                storage.AddVenue(v1);

                // Create the second venue called v2, and update the attributes
                // Create the security so venue2@ms and anyone at msn can join
                Venue v2 = new Venue();
                v2.Name = "Test Venue 2";
                v2.Identifier = "*****@*****.**";
                v2.Icon = null;
                v2.IPAddress = "233.233.233.11";
                v2.Port = 1000;
                v2.AccessList = new SecurityPatterns(new String[] { @"[\w-]@msn.com" });
                storage.AddVenue(v2);

                Console.WriteLine("Test venue security");
                // Get the list of venues for jav@hotmail and verify which venues he can see
                VS.Venue[] vList = vs.GetVenues("*****@*****.**");
                bool v1Found = false;
                bool v2Found = false;
                foreach(VS.Venue v in vList)
                {
                    if (v.Identifier == v1.Identifier)
                    {
                        v1Found = true;
                    }
                    else if(v.Identifier == v2.Identifier)
                    {
                        v2Found = true;
                    }
                }

                // Validate that only allowed people can join v1
                // positive case
                if (!v1Found)
                {
                    message = "Permission Failed\n [email protected] should have access to V1";
                    throw new Exception(message);
                }

                // negative case
                if (v2Found)
                {
                    message = "Failed! Permission Failed\n [email protected] should not have access to V2";
                    throw new Exception(message);
                }

                Console.WriteLine("Update the name attribute of v1");
                // Update the name attribute of v1
                v1.Name = "Test Venue 1 Updated";
                storage.UpdateVenue(v1);

                // Verify the name change of v1 by retriving the name from the server
                // and compare against the local name.
                if (vs.GetVenue(v1.Identifier).Name != v1.Name)
                {
                    message = "Failed: UpdateVenue() - " + vs.GetVenue(v1.Identifier).Name.ToString() + "!=" + v1.Name.ToString();
                    throw new Exception(message);
                }

                Console.WriteLine("Delete v1 and v2");
                // Delete v1
                storage.DeleteVenue(v1.Identifier);

                // Verify v1 is deleted
                if (vs.GetVenue(v1.Identifier) != null)
                {
                    message = "Failed: v1 cannot be deleted.";
                    throw new Exception(message);
                }

                // Delete v2
                storage.DeleteVenue(v2.Identifier);

                // Verify v2 is deleted
                if (vs.GetVenue(v2.Identifier) != null)
                {
                    message = "Failed: v2 cannot be deleted.";
                    throw new Exception(message);

                }

                Console.WriteLine("Create participants called p1 and p2");
                //Create the first participant called p1, and update the atrributes
                VS.Participant p1 = new VS.Participant();
                p1.Name = "Test Participant 1";
                p1.Icon = null;
                p1.Identifier = "*****@*****.**";
                vs.AddParticipant(p1);

                //Create the second participant called p2, and update the attributes
                VS.Participant p2 = new VS.Participant();
                p2.Name = "Test Participant 2";
                p2.Icon = null;
                p2.Identifier="*****@*****.**";
                vs.AddParticipant(p2);

                // Verify the participants (p1 and p2) are created by checking the
                // total number of participants existed
                // Just check number is >= 2 so that we don't fail on sample venues.
                VS.Participant[] pList = vs.GetParticipants();
                if (pList.Length < 2)
                {
                    message = "Failed! GetParticipants() - Incorrect number of participants: " + pList.Length +
                        " (should be 2). It may be caused by a participant that is not able to be" +
                        " created or preexisting participant not being cleaned up.";
                    throw new Exception(message);

                }

                Console.WriteLine("Update the name attribute of p1");
                // Update the name attribute of p1
                p1.Name = "Test Participant 1 Updated";
                vs.UpdateParticipant(p1);

                // Verify the name change of p1 by retriving the name from the server
                // and compare against the local name.
                if (vs.GetParticipant(p1.Identifier).Name != p1.Name)
                {
                    message = "Failed: UpdateParticipant() - " +
                        vs.GetParticipant(p1.Identifier).Name.ToString() + "!=" + p1.Name.ToString();
                    throw new Exception(message);

                }

                Console.WriteLine("Delete p1 and p2");
                // Delete p1
                storage.DeleteParticipant(p1.Identifier);

                // Verify p1 is deleted
                if (vs.GetParticipant(p1.Identifier) != null)
                {
                    message = "Failed! DeleteParticipant() - p1 cannot be deleted";
                    throw new Exception(message);

                }

                // Delete p2
                storage.DeleteParticipant(p2.Identifier);

                // Verify p2 is deleted
                if (vs.GetParticipant(p2.Identifier) != null)
                {
                    message = "Failed! DelteParticipant() - p2 cannot be deleted";
                    throw new Exception(message);

                }

                message = "VenueService_Sample ended successfully";
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);

                Console.WriteLine("Press a key to continue");
                Console.Read();
                return;

            }
            catch(Exception ex)
            {
                message = ex.ToString();
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Error);

                message = "Test ended abnormally";
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);
                return;
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            #region Create the file store
            string filePath = ConfigurationManager.AppSettings["FilePath"];
            if (filePath == null || filePath == String.Empty)
            {
                // Use the registry key
                using(RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                {
                    filePath = (string)key.GetValue("DataFile");
                }
            }

            FileStorage filestore = new FileStorage(filePath);
            #endregion

            #region Delete existing participants & venues
            Venue[] oldVenues = filestore.GetVenues();
            Participant[] oldParts = filestore.GetParticipants();
            if (oldVenues.Length == 2 && (oldParts == null || oldParts.Length == 0))
            {
                // This is the default install.  Just delete them.
                foreach(Venue oldVenue in oldVenues)
                {
                    filestore.DeleteVenue(oldVenue.Identifier);
                }
            }
            #endregion

            #region Get the connection string
            string connString = ConfigurationManager.AppSettings["SqlConnectionString"];
            DatabaseStorage database = new DatabaseStorage(connString);
            #endregion

            try
            {
                #region Move the venues
                Console.WriteLine("Getting venues from database...");
                Venue[] venues = database.GetVenues();
                Console.WriteLine("Writing venues to filestore...");
                filestore.WriteCaching = true;
                foreach(Venue ven in venues)
                {
                    string[] acls = database.GetVenueSecurity(ven.Identifier);
                    ven.AccessList = new SecurityPatterns(acls);
                    filestore.AddVenue(ven);
                }
                filestore.WriteCaching = false;
                #endregion

                #region Move the participants
                Console.WriteLine("Getting participants from database...");
                Participant[] participants = database.GetParticipants();
                Console.WriteLine("Writing participants to filestore...");
                filestore.WriteCaching = true;
                foreach(Participant part in participants)
                {
                    filestore.AddParticipant(part);
                }
                filestore.WriteCaching = false;
                #endregion
            }
            catch (System.Data.SqlClient.SqlException)
            {
                Console.WriteLine();
                Console.WriteLine("The database could not be properly accessed.  Utility failed to execute.");
                Console.WriteLine("Press 'enter' to exit...");
                Console.ReadLine();
            }

            filestore.Dispose();
        }
Пример #5
0
        public override void Install(IDictionary savedState)
        {
            base.Install(savedState);

            // Create .dat file
            //
            // NOTE: during install we can't access the Web.config file, so the file name
            //  is just hard-coded here.  Given that you can't change the web.config file
            //  during install, this really shouldn't be a problem.  If someone changes the
            //  file location, then they'll have to deal with the problem of file permissions.
            //
            Console.WriteLine(Strings.CreatingVenueServiceDataFile);
            string filepath = InstallPath + @"VenueService.dat";
            if( !File.Exists(filepath) )
            {
                using (FileStorage file = new FileStorage(filepath))
                {
                    // Add two sample venues
                    file.AddVenue(new Venue("*****@*****.**", "234.7.13.19", 5004,
                        "Sample Venue 1", null, null), new PrivateVenueState());
                    file.AddVenue(new Venue("*****@*****.**", "235.8.14.20", 5004,
                        "Sample Venue 2", null, null),new PrivateVenueState());
                }
            }
            else
            {
                Console.WriteLine(Strings.DataFileExistsSkippingCreatingFile);
            }

            // Store the location of the .dat file so the admin tool can find it
            using(RegistryKey key = Registry.LocalMachine.CreateSubKey(LocalMachineSubkey))
            {
                key.SetValue("DataFile", filepath);
            }

            try
            {
                // In Venue Service 4.0 and prior, we used impersonation and the
                // IUSR_Machine account (having troubles when the machine name was
                // changed, but not the account name to match it).  In Vista, 
                // impersonation would cause an HTTP 500 error, and so we disabled
                // impersonation.  That in turn changed the user account that was
                // being used to read / write venueservice.dat.  We added security to the
                // folder (not just the file) so that in the event the file was deleted,
                // an empty one could be reconstructed.
                DirectorySecurity folderSec = Directory.GetAccessControl(InstallPath);

                if ((Environment.OSVersion.Version.Major == 5 && 
                     Environment.OSVersion.Version.Minor >= 2) ||
                     Environment.OSVersion.Version.Major >= 6) // Win2K3 or Vista and above (Longhorn Server, etc.)
                {
                    folderSec.AddAccessRule(new FileSystemAccessRule("NETWORK SERVICE",
                        FileSystemRights.Modify,
                        InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                        PropagationFlags.None, AccessControlType.Allow));
                }
                else if (Environment.OSVersion.Version.Major == 5 && 
                         Environment.OSVersion.Version.Minor == 1) // WinXP
                {
                    folderSec.AddAccessRule(new FileSystemAccessRule("ASPNET",
                        FileSystemRights.Modify,
                        InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                        PropagationFlags.None, AccessControlType.Allow));
                }
                else // Win2K and other down level OSes
                {
                    throw new ApplicationException(Strings.OSVersion);
                }

                Directory.SetAccessControl(InstallPath, folderSec);
            }
            catch(Exception)
            {
                RtlAwareMessageBox.Show(null, Strings.FileSecurityChangesFailedText, Strings.FileSecurityChangesFailedTitle, 
                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }
Пример #6
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            this.venuesLbl.Font = UIFont.StringFont;
            this.venues.Font = UIFont.StringFont;
            this.participants.Font = UIFont.StringFont;
            this.participantsLbl.Font = UIFont.StringFont;
            this.basicButtons.Font = UIFont.StringFont;

            this.venuesLbl.Text = Strings.ManageVenues;
            this.participantsLbl.Text = Strings.ManageParticipants;
            this.Text = Strings.ConferencexpVenueServiceManager;

            try
            {
                // Start by getting the venue service storage (use the app.config as an override)
                string filePath = ConfigurationManager.AppSettings["FilePath"];
                if (filePath == null || filePath == String.Empty)
                {
                    // Use the registry key
                    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                    {
                        filePath = (string)key.GetValue("DataFile");
                    }
                }

                storage = new FileStorage(filePath);

                this.venues.StorageFile = storage;
                this.participants.StorageFile = storage;
            }
            catch (Exception ex)
            {
                RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture,
                    Strings.StorageFailureText, ex.ToString()), Strings.StorageFailureTitle, MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                Close();
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            // Override the system UICulture
            string cultureOverride = null;
            if ((cultureOverride = ConfigurationManager.AppSettings["MSR.LST.ConferenceXP.VenueService.UICulture"]) != null) {
                try {
                    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(cultureOverride);
                    System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                }
                catch { }
            }

            string message;
            VenueService_Sample VenueService_Sample = null;

            try
            {
                // Start by getting the venue service storage (use the app.config as an override)
                string filePath = ConfigurationManager.AppSettings["FilePath"];
                if (filePath == null || filePath == String.Empty)
                {
                    // Use the registry key
                    using(RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                    {
                        filePath = (string)key.GetValue("DataFile");
                    }
                }
                FileStorage storage = new FileStorage(filePath);

                VenueService_Sample = new VenueService_Sample();

                message = Strings.VenueServiceSampleStartedSuccessfully;
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);

                // Create a reference to the VenueService web service
                Console.WriteLine(Strings.CreateAReferenceToTheVenueServiceWebService);
                MSR.LST.ConferenceXP.VenueService.VenueService.VenueService vs = new MSR.LST.ConferenceXP.VenueService.VenueService.VenueService();

                // Cleanup - remove venues and particpants in case the sample was cancelled before it finished
                // Will fail silently if not present
                try
                {
                    storage.DeleteVenue("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteVenue("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteParticipant("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteParticipant("*****@*****.**");
                }
                catch {}


                Console.WriteLine(Strings.CreateVenuesCalledV1AndV2);
                // Create the first venue called v1, and update the attributes
                // Create the security so venue1@ms and anyone at hotmail can join
                Venue v1 = new Venue();
                v1.Name = "Test Venue 1";
                v1.Identifier = "*****@*****.**";
                v1.Icon = null;
                v1.IPAddress = "233.233.233.10";
                v1.Port = 1000;
                v1.AccessList = new SecurityPatterns(new String[] { @"[\w-]@hotmail.com" });
                storage.AddVenue(v1, new PrivateVenueState());

                // Create the second venue called v2, and update the attributes
                // Create the security so venue2@ms and anyone at msn can join
                Venue v2 = new Venue();
                v2.Name = "Test Venue 2";
                v2.Identifier = "*****@*****.**";
                v2.Icon = null;
                v2.IPAddress = "233.233.233.11";
                v2.Port = 1000;
                v2.AccessList = new SecurityPatterns(new String[] { @"[\w-]@msn.com" });
                storage.AddVenue(v2, new PrivateVenueState());

                Console.WriteLine(Strings.TestVenueSecurity);
                // Get the list of venues for jav@hotmail and verify which venues he can see
                VS.Venue[] vList = vs.GetVenues("*****@*****.**");
                bool v1Found = false;
                bool v2Found = false;
                foreach(VS.Venue v in vList)
                {
                    if (v.Identifier == v1.Identifier)
                    {
                        v1Found = true;
                    }
                    else if(v.Identifier == v2.Identifier)
                    {
                        v2Found = true;
                    }
                }

                // Validate that only allowed people can join v1
                // positive case
                if (!v1Found)
                {
                    message = Strings.PermissionFailedSecurityError;
                    throw new Exception(message); 
                }

                // negative case
                if (v2Found)
                {
                    message = Strings.PermissionFailedNegativeCaseSecurityError;
                    throw new Exception(message); 
                }

                Console.WriteLine(Strings.UpdateTheNameAttributeOfV1);
                // Update the name attribute of v1 
                v1.Name = "Test Venue 1 Updated";
                storage.UpdateVenue(new VenueState(v1, new PrivateVenueState()));

                // Verify the name change of v1 by retriving the name from the server 
                // and compare against the local name.
                if (vs.GetVenue(v1.Identifier).Name != v1.Name)
                {
                    message = string.Format(CultureInfo.CurrentCulture, Strings.VenueNameChangeFailed, vs.GetVenue(v1.Identifier).Name.ToString(), v1.Name.ToString());
                    throw new Exception(message); 
                }

                Console.WriteLine(Strings.DeleteV1AndV2);
                // Delete v1
                storage.DeleteVenue(v1.Identifier);

                // Verify v1 is deleted
                if (vs.GetVenue(v1.Identifier) != null)
                {
                    message = Strings.FailedV1CannotBeDeleted;
                    throw new Exception(message); 
                }

                // Delete v2
                storage.DeleteVenue(v2.Identifier);

                // Verify v2 is deleted
                if (vs.GetVenue(v2.Identifier) != null)
                {
                    message = Strings.FailedV2CannotBeDeleted;
                    throw new Exception(message); 

                }

                Console.WriteLine(Strings.CreateParticipants);
                //Create the first participant called p1, and update the atrributes
                VS.Participant p1 = new VS.Participant();
                p1.Name = "Test Participant 1";
                p1.Icon = null;
                p1.Identifier = "*****@*****.**";
                vs.AddParticipant(p1);

                //Create the second participant called p2, and update the attributes
                VS.Participant p2 = new VS.Participant();
                p2.Name = "Test Participant 2";
                p2.Icon = null;
                p2.Identifier="*****@*****.**";
                vs.AddParticipant(p2);

                // Verify the participants (p1 and p2) are created by checking the
                // total number of participants existed
                // Just check number is >= 2 so that we don't fail on sample venues.
                VS.Participant[] pList = vs.GetParticipants();
                if (pList.Length < 2)
                {
                    message = string.Format(CultureInfo.CurrentCulture, Strings.IncorrectNumberOfParticipants, 
                        pList.Length);
                    throw new Exception(message); 

                }

                Console.WriteLine(Strings.UpdateTheNameAttributeOfP1);
                // Update the name attribute of p1
                p1.Name = "Test Participant 1 Updated";
                vs.UpdateParticipant(p1);

                // Verify the name change of p1 by retriving the name from the server 
                // and compare against the local name.
                if (vs.GetParticipant(p1.Identifier).Name != p1.Name)
                {
                    message = string.Format(CultureInfo.CurrentCulture, Strings.ParticipantNameChangeFailed, 
                        vs.GetParticipant(p1.Identifier).Name.ToString(), p1.Name.ToString());
                    throw new Exception(message); 

                }

                Console.WriteLine(Strings.DeleteP1AndP2);
                // Delete p1
                storage.DeleteParticipant(p1.Identifier);

                // Verify p1 is deleted
                if (vs.GetParticipant(p1.Identifier) != null)
                {
                    message = Strings.FailedDeleteParticipantP1;
                    throw new Exception(message); 

                }

                // Delete p2
                storage.DeleteParticipant(p2.Identifier);

                // Verify p2 is deleted
                if (vs.GetParticipant(p2.Identifier) != null)
                {
                    message = Strings.FailedDelteParticipantP2;
                    throw new Exception(message); 

                }

                message = Strings.VenueServiceSampleEndedSuccessfully;
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);

                Console.WriteLine(Strings.PressAKeyToContinue);
                Console.Read();
                return;

            }
            catch(Exception ex)
            {
                message = ex.ToString();
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Error);

                message = Strings.TestEndedAbnormally;
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);
                return;
            }
        }
Пример #8
0
        static void Main(string[] args)
        {
            // Override the system UICulture
            string cultureOverride = null;

            if ((cultureOverride = ConfigurationManager.AppSettings["MSR.LST.ConferenceXP.VenueService.UICulture"]) != null)
            {
                try {
                    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(cultureOverride);
                    System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                }
                catch { }
            }


            #region Create the file store
            string filePath = ConfigurationManager.AppSettings["FilePath"];
            if (filePath == null || filePath == String.Empty)
            {
                // Use the registry key
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                {
                    filePath = (string)key.GetValue("DataFile");
                }
            }

            FileStorage filestore = new FileStorage(filePath);
            #endregion

            #region Delete existing participants & venues
            Venue[]       oldVenues = filestore.GetVenues();
            Participant[] oldParts  = filestore.GetParticipants();
            if (oldVenues.Length == 2 && (oldParts == null || oldParts.Length == 0))
            {
                // This is the default install.  Just delete them.
                foreach (Venue oldVenue in oldVenues)
                {
                    filestore.DeleteVenue(oldVenue.Identifier);
                }
            }
            #endregion

            #region Get the connection string
            string          connString = ConfigurationManager.AppSettings["SqlConnectionString"];
            DatabaseStorage database   = new DatabaseStorage(connString);
            #endregion

            try
            {
                #region Move the venues
                Console.WriteLine(Strings.GettingVenuesFromDatabase);
                Venue[] venues = database.GetVenues();
                Console.WriteLine(Strings.WritingVenuesToFilestore);
                filestore.WriteCaching = true;
                foreach (Venue ven in venues)
                {
                    string[] acls = database.GetVenueSecurity(ven.Identifier);
                    ven.AccessList = new SecurityPatterns(acls);
                    filestore.AddVenue(ven, new PrivateVenueState());
                }
                filestore.WriteCaching = false;
                #endregion

                #region Move the participants
                Console.WriteLine(Strings.GettingParticipantsFromDatabase);
                Participant[] participants = database.GetParticipants();
                Console.WriteLine(Strings.WritingParticipantsToFilestore);
                filestore.WriteCaching = true;
                foreach (Participant part in participants)
                {
                    filestore.AddParticipant(part);
                }
                filestore.WriteCaching = false;
                #endregion
            }
            catch (System.Data.SqlClient.SqlException)
            {
                Console.WriteLine();
                Console.WriteLine(Strings.DatabaseCouldNotBeProperlyAccessed);
                Console.WriteLine(Strings.PressEnterToExit);
                Console.ReadLine();
            }

            filestore.Dispose();
        }
Пример #9
0
        static void Main(string[] args)
        {
            // Override the system UICulture
            string cultureOverride = null;
            if ((cultureOverride = ConfigurationManager.AppSettings["MSR.LST.ConferenceXP.VenueService.UICulture"]) != null) {
                try {
                    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(cultureOverride);
                    System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                }
                catch { }
            }


            #region Create the file store
            string filePath = ConfigurationManager.AppSettings["FilePath"];
            if (filePath == null || filePath == String.Empty)
            {
                // Use the registry key
                using(RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                {
                    filePath = (string)key.GetValue("DataFile");
                }
            }

            FileStorage filestore = new FileStorage(filePath);
            #endregion

            #region Delete existing participants & venues
            Venue[] oldVenues = filestore.GetVenues();
            Participant[] oldParts = filestore.GetParticipants();
            if (oldVenues.Length == 2 && (oldParts == null || oldParts.Length == 0))
            {
                // This is the default install.  Just delete them.
                foreach(Venue oldVenue in oldVenues)
                {
                    filestore.DeleteVenue(oldVenue.Identifier);
                }
            }
            #endregion

            #region Get the connection string
            string connString = ConfigurationManager.AppSettings["SqlConnectionString"];
            DatabaseStorage database = new DatabaseStorage(connString);
            #endregion

            try
            {
                #region Move the venues
                Console.WriteLine(Strings.GettingVenuesFromDatabase);
                Venue[] venues = database.GetVenues();
                Console.WriteLine(Strings.WritingVenuesToFilestore);
                filestore.WriteCaching = true;
                foreach(Venue ven in venues)
                {
                    string[] acls = database.GetVenueSecurity(ven.Identifier);
                    ven.AccessList = new SecurityPatterns(acls);
                    filestore.AddVenue(ven, new PrivateVenueState());
                }
                filestore.WriteCaching = false;
                #endregion

                #region Move the participants
                Console.WriteLine(Strings.GettingParticipantsFromDatabase);
                Participant[] participants = database.GetParticipants();
                Console.WriteLine(Strings.WritingParticipantsToFilestore);
                filestore.WriteCaching = true;
                foreach(Participant part in participants)
                {
                    filestore.AddParticipant(part);
                }
                filestore.WriteCaching = false;
                #endregion
            }
            catch (System.Data.SqlClient.SqlException)
            {
                Console.WriteLine();
                Console.WriteLine(Strings.DatabaseCouldNotBeProperlyAccessed);
                Console.WriteLine(Strings.PressEnterToExit);
                Console.ReadLine();
            }

            filestore.Dispose();
        }
Пример #10
0
        public override void Install(IDictionary savedState)
        {
            base.Install(savedState);

            // Create .dat file
            //
            // NOTE: during install we can't access the Web.config file, so the file name
            //  is just hard-coded here.  Given that you can't change the web.config file
            //  during install, this really shouldn't be a problem.  If someone changes the
            //  file location, then they'll have to deal with the problem of file permissions.
            //
            Console.WriteLine(Strings.CreatingVenueServiceDataFile);
            string filepath = InstallPath + @"VenueService.dat";

            if (!File.Exists(filepath))
            {
                using (FileStorage file = new FileStorage(filepath))
                {
                    // Add two sample venues
                    file.AddVenue(new Venue("*****@*****.**", "234.7.13.19", 5004,
                                            "Sample Venue 1", null, null), new PrivateVenueState());
                    file.AddVenue(new Venue("*****@*****.**", "235.8.14.20", 5004,
                                            "Sample Venue 2", null, null), new PrivateVenueState());
                }
            }
            else
            {
                Console.WriteLine(Strings.DataFileExistsSkippingCreatingFile);
            }

            // Store the location of the .dat file so the admin tool can find it
            using (RegistryKey key = Registry.LocalMachine.CreateSubKey(LocalMachineSubkey))
            {
                key.SetValue("DataFile", filepath);
            }

            try
            {
                // In Venue Service 4.0 and prior, we used impersonation and the
                // IUSR_Machine account (having troubles when the machine name was
                // changed, but not the account name to match it).  In Vista,
                // impersonation would cause an HTTP 500 error, and so we disabled
                // impersonation.  That in turn changed the user account that was
                // being used to read / write venueservice.dat.  We added security to the
                // folder (not just the file) so that in the event the file was deleted,
                // an empty one could be reconstructed.
                DirectorySecurity folderSec = Directory.GetAccessControl(InstallPath);

                if ((Environment.OSVersion.Version.Major == 5 &&
                     Environment.OSVersion.Version.Minor >= 2) ||
                    Environment.OSVersion.Version.Major >= 6)  // Win2K3 or Vista and above (Longhorn Server, etc.)
                {
                    folderSec.AddAccessRule(new FileSystemAccessRule("NETWORK SERVICE",
                                                                     FileSystemRights.Modify,
                                                                     InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                                     PropagationFlags.None, AccessControlType.Allow));
                }
                else if (Environment.OSVersion.Version.Major == 5 &&
                         Environment.OSVersion.Version.Minor == 1) // WinXP
                {
                    folderSec.AddAccessRule(new FileSystemAccessRule("ASPNET",
                                                                     FileSystemRights.Modify,
                                                                     InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                                     PropagationFlags.None, AccessControlType.Allow));
                }
                else // Win2K and other down level OSes
                {
                    throw new ApplicationException(Strings.OSVersion);
                }

                Directory.SetAccessControl(InstallPath, folderSec);
            }
            catch (Exception)
            {
                RtlAwareMessageBox.Show(null, Strings.FileSecurityChangesFailedText, Strings.FileSecurityChangesFailedTitle,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }
Пример #11
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            try
            {
                // Start by getting the venue service storage (use the app.config as an override)
                string filePath = ConfigurationManager.AppSettings["FilePath"];
                if (filePath == null || filePath == String.Empty)
                {
                    // Use the registry key
                    using(RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                    {
                        filePath = (string)key.GetValue("DataFile");
                    }
                }

                storage = new FileStorage(filePath);

                this.venues.StorageFile = storage;
                this.participants.StorageFile = storage;
            }
            catch(Exception ex)
            {
                MessageBox.Show(this,
                    "A failure occurred while accessing the storage file. " +
                    "The Admin Tool will now exit. \n" +
                    "Check the value of 'FilePath' in the application configuration file. \n" +
                    "\nException:\n" + ex.ToString(),
                    "Storage Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
        }
        static void Main(string[] args)
        {
            // Override the system UICulture
            string cultureOverride = null;

            if ((cultureOverride = ConfigurationManager.AppSettings["MSR.LST.ConferenceXP.VenueService.UICulture"]) != null)
            {
                try {
                    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(cultureOverride);
                    System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
                }
                catch { }
            }

            string message;
            VenueService_Sample VenueService_Sample = null;

            try
            {
                // Start by getting the venue service storage (use the app.config as an override)
                string filePath = ConfigurationManager.AppSettings["FilePath"];
                if (filePath == null || filePath == String.Empty)
                {
                    // Use the registry key
                    using (RegistryKey key = Registry.LocalMachine.OpenSubKey(StorageInstaller.LocalMachineSubkey))
                    {
                        filePath = (string)key.GetValue("DataFile");
                    }
                }
                FileStorage storage = new FileStorage(filePath);

                VenueService_Sample = new VenueService_Sample();

                message = Strings.VenueServiceSampleStartedSuccessfully;
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);

                // Create a reference to the VenueService web service
                Console.WriteLine(Strings.CreateAReferenceToTheVenueServiceWebService);
                MSR.LST.ConferenceXP.VenueService.VenueService.VenueService vs = new MSR.LST.ConferenceXP.VenueService.VenueService.VenueService();

                // Cleanup - remove venues and particpants in case the sample was cancelled before it finished
                // Will fail silently if not present
                try
                {
                    storage.DeleteVenue("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteVenue("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteParticipant("*****@*****.**");
                }
                catch {}
                try
                {
                    storage.DeleteParticipant("*****@*****.**");
                }
                catch {}


                Console.WriteLine(Strings.CreateVenuesCalledV1AndV2);
                // Create the first venue called v1, and update the attributes
                // Create the security so venue1@ms and anyone at hotmail can join
                Venue v1 = new Venue();
                v1.Name       = "Test Venue 1";
                v1.Identifier = "*****@*****.**";
                v1.Icon       = null;
                v1.IPAddress  = "233.233.233.10";
                v1.Port       = 1000;
                v1.AccessList = new SecurityPatterns(new String[] { @"[\w-]@hotmail.com" });
                storage.AddVenue(v1, new PrivateVenueState());

                // Create the second venue called v2, and update the attributes
                // Create the security so venue2@ms and anyone at msn can join
                Venue v2 = new Venue();
                v2.Name       = "Test Venue 2";
                v2.Identifier = "*****@*****.**";
                v2.Icon       = null;
                v2.IPAddress  = "233.233.233.11";
                v2.Port       = 1000;
                v2.AccessList = new SecurityPatterns(new String[] { @"[\w-]@msn.com" });
                storage.AddVenue(v2, new PrivateVenueState());

                Console.WriteLine(Strings.TestVenueSecurity);
                // Get the list of venues for jav@hotmail and verify which venues he can see
                VS.Venue[] vList   = vs.GetVenues("*****@*****.**");
                bool       v1Found = false;
                bool       v2Found = false;
                foreach (VS.Venue v in vList)
                {
                    if (v.Identifier == v1.Identifier)
                    {
                        v1Found = true;
                    }
                    else if (v.Identifier == v2.Identifier)
                    {
                        v2Found = true;
                    }
                }

                // Validate that only allowed people can join v1
                // positive case
                if (!v1Found)
                {
                    message = Strings.PermissionFailedSecurityError;
                    throw new Exception(message);
                }

                // negative case
                if (v2Found)
                {
                    message = Strings.PermissionFailedNegativeCaseSecurityError;
                    throw new Exception(message);
                }

                Console.WriteLine(Strings.UpdateTheNameAttributeOfV1);
                // Update the name attribute of v1
                v1.Name = "Test Venue 1 Updated";
                storage.UpdateVenue(new VenueState(v1, new PrivateVenueState()));

                // Verify the name change of v1 by retriving the name from the server
                // and compare against the local name.
                if (vs.GetVenue(v1.Identifier).Name != v1.Name)
                {
                    message = string.Format(CultureInfo.CurrentCulture, Strings.VenueNameChangeFailed, vs.GetVenue(v1.Identifier).Name.ToString(), v1.Name.ToString());
                    throw new Exception(message);
                }

                Console.WriteLine(Strings.DeleteV1AndV2);
                // Delete v1
                storage.DeleteVenue(v1.Identifier);

                // Verify v1 is deleted
                if (vs.GetVenue(v1.Identifier) != null)
                {
                    message = Strings.FailedV1CannotBeDeleted;
                    throw new Exception(message);
                }

                // Delete v2
                storage.DeleteVenue(v2.Identifier);

                // Verify v2 is deleted
                if (vs.GetVenue(v2.Identifier) != null)
                {
                    message = Strings.FailedV2CannotBeDeleted;
                    throw new Exception(message);
                }

                Console.WriteLine(Strings.CreateParticipants);
                //Create the first participant called p1, and update the atrributes
                VS.Participant p1 = new VS.Participant();
                p1.Name       = "Test Participant 1";
                p1.Icon       = null;
                p1.Identifier = "*****@*****.**";
                vs.AddParticipant(p1);

                //Create the second participant called p2, and update the attributes
                VS.Participant p2 = new VS.Participant();
                p2.Name       = "Test Participant 2";
                p2.Icon       = null;
                p2.Identifier = "*****@*****.**";
                vs.AddParticipant(p2);

                // Verify the participants (p1 and p2) are created by checking the
                // total number of participants existed
                // Just check number is >= 2 so that we don't fail on sample venues.
                VS.Participant[] pList = vs.GetParticipants();
                if (pList.Length < 2)
                {
                    message = string.Format(CultureInfo.CurrentCulture, Strings.IncorrectNumberOfParticipants,
                                            pList.Length);
                    throw new Exception(message);
                }

                Console.WriteLine(Strings.UpdateTheNameAttributeOfP1);
                // Update the name attribute of p1
                p1.Name = "Test Participant 1 Updated";
                vs.UpdateParticipant(p1);

                // Verify the name change of p1 by retriving the name from the server
                // and compare against the local name.
                if (vs.GetParticipant(p1.Identifier).Name != p1.Name)
                {
                    message = string.Format(CultureInfo.CurrentCulture, Strings.ParticipantNameChangeFailed,
                                            vs.GetParticipant(p1.Identifier).Name.ToString(), p1.Name.ToString());
                    throw new Exception(message);
                }

                Console.WriteLine(Strings.DeleteP1AndP2);
                // Delete p1
                storage.DeleteParticipant(p1.Identifier);

                // Verify p1 is deleted
                if (vs.GetParticipant(p1.Identifier) != null)
                {
                    message = Strings.FailedDeleteParticipantP1;
                    throw new Exception(message);
                }

                // Delete p2
                storage.DeleteParticipant(p2.Identifier);

                // Verify p2 is deleted
                if (vs.GetParticipant(p2.Identifier) != null)
                {
                    message = Strings.FailedDelteParticipantP2;
                    throw new Exception(message);
                }

                message = Strings.VenueServiceSampleEndedSuccessfully;
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);

                Console.WriteLine(Strings.PressAKeyToContinue);
                Console.Read();
                return;
            }
            catch (Exception ex)
            {
                message = ex.ToString();
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Error);

                message = Strings.TestEndedAbnormally;
                VenueService_Sample.WriteToLog(message, EventLogEntryType.Information);
                return;
            }
        }