Exemple #1
0
        /// <summary>
        /// Look for a user through its login
        /// </summary>
        /// <param name="login"></param>
        /// <param name="checkModule">true : user is retrieved by its login if a module is assigned to him</param>
        /// <returns>null if the user doesn't exist or if he can't get access (no modules)</returns>
        public UserRecord GetByLogin(string login, bool checkModule = true)
        {
            try
            {
                if (Database == null)
                {
                    return(null);
                }

                bool userExists = false;

                foreach (UserRecord currentUser in (from user in Database.User
                                                    where user.Login.Equals(login)
                                                    select user).ToList())
                {
                    InformationRecord information = Database._Information.Find("User", currentUser.Id);

                    if ((information != null && information.IsDeleted) || !currentUser.IsEnable())
                    {
                        continue;
                    }

                    userExists = true;

                    if (currentUser.CustomerId == 1 || !checkModule)
                    {
                        return(currentUser);
                    }

                    foreach (UserModuleRecord currentUserModule in (from userModule in Database.UserModule
                                                                    where userModule.UserId == currentUser.Id
                                                                    select userModule).ToList())
                    {
                        information = Database._Information.Find("UserModule", currentUserModule.Id);

                        if (information != null && information.IsDeleted)
                        {
                            continue;
                        }

                        ModuleRecord module = Database.Module.Find(currentUserModule.ModuleId);
                        if (module == null || !module.Enable)
                        {
                            continue;
                        }

                        return(currentUser);
                    }
                }

                if (userExists)
                {
                    Warn($"The user '{login}' exists but no module attached to him");
                }

                return(null);
            }
            catch (System.Exception ex)
            {
                Exception($"Unable to get the user '{login}'", ex);
            }

            return(null);
        }
Exemple #2
0
 public override void WriteInformation(InformationRecord record)
 {
     // Do nothing. The information stream is not visible by default
 }
Exemple #3
0
 public InformationMessage(InformationRecord informationRecord)
 {
     _informationRecord = informationRecord;
 }
 /// <summary>
 /// Writes the InformationRecord to informational buffers.
 /// </summary>
 /// <param name="record">WarningRecord</param>
 internal void WriteInformationInfoBuffers(InformationRecord record)
 {
     if (_informationalBuffers != null)
     {
         _informationalBuffers.AddInformation(record);
     }
 }
 public override void WriteInformation(InformationRecord record)
 {
     _hostOutput?.Invoke($"INFORMATION: {record.MessageData} (Tags: {String.Join(",", record.Tags)})");
 }
Exemple #6
0
 void ICommandRuntime2.WriteInformation(InformationRecord informationRecord)
 {
     Information.Add(informationRecord);
 }
 /// <summary>
 /// Invoked by <see cref="System.Management.Automation.Cmdlet.WriteInformation(InformationRecord)"/> to give the host a chance to intercept
 /// informational messages. These should not be displayed to the user by default, but may be useful to display in
 /// a separate area of the user interface.
 /// </summary>
 public virtual void WriteInformation(InformationRecord record) { }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="record">The Information message that is wrapped.</param>
 /// <param name="originInfo">The origin information.</param>
 public RemotingInformationRecord(InformationRecord record, OriginInfo originInfo)
     : base(record)
 {
     _originInfo = originInfo;
 }
Exemple #9
0
        public ActionResult Add(string name, string login, string email, string address, string comment)
        {
            Debug($"Get ~/Administration/Customer/Add(name={name}, login={login}, email={email}, address={address}, comment={comment})");

            // Only for administrator from the first customer (Syncytium)

            if (!(_userManager.GetById(int.Parse(HttpContext.User.Identity.Name)) is UserRecord user) || user.CustomerId != 1)
            {
                return(HttpNotFound());
            }

            // check the value by itself

            Errors errors = new Errors();

            // no name set

            if (string.IsNullOrWhiteSpace(name))
            {
                errors.AddField("Name", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_NAME}" });
            }
            name = name.Trim();

            // no login set

            if (string.IsNullOrWhiteSpace(login))
            {
                errors.AddField("Login", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_LOGIN}" });
            }
            login = login.Trim();

            // no email set

            if (string.IsNullOrWhiteSpace(email))
            {
                errors.AddField("Email", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_EMAIL}" });
            }
            email = email.Trim();

            // check if the name already exists

            if (_userManager.Database.Customer.Where(c => c.Name.Equals(name)).Any())
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_NAME}" });
            }

            // check if the login already exists

            bool loginExist = false;

            foreach (UserRecord record in _userManager.Database.User.Where(u => u.Login.Equals(login)).ToList())
            {
                // User deleted ?

                InformationRecord information = _userManager.Database._Information.FirstOrDefault(info => info.Id == record.Id && info.Table.Equals("User"));
                if (information == null || information.DeleteTick == null)
                {
                    loginExist = true;
                    break;
                }
            }

            if (loginExist)
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_LOGIN}" });
            }

            // load ressources before designing the screen fitted to the user's profile

            LanguageDictionary ressources = new LanguageDictionary(Server.MapPath(LanguageDictionary.DIRECTORY_IMAGE), ConfigurationManager.DefaultLanguage);

            ressources.Load(_userManager.Database, user.CustomerId);

            if (errors.HasError)
            {
                // update ModelState on depends on errors

                SetModelState(ModelState, ressources, errors);
                return(View(new CustomerViewModel(ressources, user)));
            }

            // Create a new customer

            Info($"Creating of a new customer ('{name}', '{login}', '{email}', '{address}', '{comment}') ...");

            CustomerRecord newCustomer = new CustomerRecord()
            {
                Name    = name,
                Login   = login,
                Email   = email,
                Address = address,
                Comment = comment
            };

            _userManager.Database.Customer.Add(newCustomer);
            _userManager.Database.SaveChanges();

            Info($"Customer created {newCustomer}");

            // Add the parameter "Language.Tick.<customerId>" into the parameter table

            _userManager.Database._Parameter.Add(new ParameterRecord()
            {
                Key = $"Language.Tick.{newCustomer.Id}", Value = "0"
            });

            // Duplicate multilanguage dictionary (from the customer 1 to the new one)

            Info($"Duplicating multilanguage labels ...");

            int nbLabels = 0;

            foreach (LanguageRecord languageRecord in _userManager.Database.Language.Where(l => l.CustomerId == 1).ToList())
            {
                LanguageRecord newLanguageRecord = LanguageRecord.Copy(languageRecord) as LanguageRecord;
                newLanguageRecord.CustomerId = newCustomer.Id;
                _userManager.Database.Language.Add(newLanguageRecord);
                nbLabels++;
            }

            Info($"{nbLabels} labels duplicated");

            // Create the administrator for this new customer

            UserRecord newUser = new UserRecord()
            {
                Login        = login,
                Registration = name,
                Name         = name,
                Email        = email,
                Language     = user.Language,
                CustomerId   = newCustomer.Id
            };

            _userManager.Database.User.Add(newUser);
            _userManager.Database.SaveChanges();
            Info($"Creating a new user {newUser} ...");

            ModuleRecord newModule = new ModuleRecord()
            {
                Name       = "Administration",
                Module     = ModuleRecord.EModule.Administration,
                Profile    = UserProfile.EUserProfile.Administrator,
                Enable     = true,
                CustomerId = newCustomer.Id
            };

            _userManager.Database.Module.Add(newModule);
            _userManager.Database.SaveChanges();
            Info($"Module({newModule.Id}) created");

            UserModuleRecord newUserModule = new UserModuleRecord()
            {
                UserId     = newUser.Id,
                ModuleId   = newModule.Id,
                Default    = true,
                CustomerId = newCustomer.Id
            };

            _userManager.Database.UserModule.Add(newUserModule);
            _userManager.Database.SaveChanges();
            Info($"UserModule({newUserModule.Id}) created");

            // send a mail for the new user

            Info($"Sending an email to create the password ...");

            using (UserController controller = new UserController(_userManager))
                controller.SendNewPassword(newUser.Login);

            Info($"Customer created ...");

            return(RedirectToAction("Index"));
        }
Exemple #10
0
        public ActionResult Update(int id, string name, string login, string email, string address, string comment)
        {
            Debug($"Get ~/Administration/Customer/Update(id={id}, name={name}, login={login}, email={email}, address={address}, comment={comment})");

            // Only for administrator from the first customer (Syncytium)

            if (!(_userManager.GetById(int.Parse(HttpContext.User.Identity.Name)) is UserRecord user) || user.CustomerId != 1)
            {
                return(HttpNotFound());
            }

            // The customer has to exist

            CustomerRecord customer = _userManager.Database.Customer.Find(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            // check the value by itself

            Errors errors = new Errors();

            // no name set

            if (string.IsNullOrWhiteSpace(name))
            {
                errors.AddField("Name", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_NAME}" });
            }
            name = name.Trim();

            // no login set

            if (string.IsNullOrWhiteSpace(login))
            {
                errors.AddField("Login", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_LOGIN}" });
            }
            login = login.Trim();

            // no email set

            if (string.IsNullOrWhiteSpace(email))
            {
                errors.AddField("Email", "ERR_FIELD_REQUIRED", new object[] { "{CUSTOMER_EMAIL}" });
            }
            email = email.Trim();

            // check if the name already exists

            if (_userManager.Database.Customer.Where(c => c.Name.Equals(name) && c.Id != customer.Id).Any())
            {
                errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_NAME}" });
            }

            if (!customer.Login.Equals(login))
            {
                // check if the new login already exists

                bool loginExist = false;
                foreach (UserRecord record in _userManager.Database.User.Where(u => u.Login.Equals(login) && u.CustomerId != customer.Id).ToList())
                {
                    // User deleted ?

                    InformationRecord information = _userManager.Database._Information.FirstOrDefault(info => info.Id == record.Id && info.Table.Equals("User"));
                    if (information == null || information.DeleteTick == null)
                    {
                        loginExist = true;
                        break;
                    }
                }

                if (loginExist)
                {
                    errors.AddField("Name", "ERR_FIELD_UNIQUE", new object[] { "{CUSTOMER_LOGIN}" });
                }
            }

            // load ressources before designing the screen fitted to the user's profile

            LanguageDictionary ressources = new LanguageDictionary(Server.MapPath(LanguageDictionary.DIRECTORY_IMAGE), ConfigurationManager.DefaultLanguage);

            ressources.Load(_userManager.Database, user.CustomerId);

            if (errors.HasError)
            {
                // update ModelState on depends on errors

                SetModelState(ModelState, ressources, errors);
                return(View(new CustomerViewModel(ressources, user, new CustomerRecord {
                    Name = name, Login = login, Email = email, Address = address, Comment = comment
                })));
            }

            // Update the customer

            Info($"Updating the customer ({customer}) within ('{name}', '{login}', '{email}', '{address}', '{comment}') ...");

            // look for the administrator exists

            UserRecord administrator = null;

            foreach (UserRecord record in _userManager.Database.User.Where(u => u.Login.Equals(customer.Login) && u.CustomerId == customer.Id).ToList())
            {
                // User deleted ?

                InformationRecord information = _userManager.Database._Information.FirstOrDefault(info => info.Id == record.Id && info.Table.Equals("User"));
                if (information == null || information.DeleteTick == null)
                {
                    administrator = record;
                    break;
                }
            }

            bool sendEmail = false;

            if (administrator == null)
            {
                Info($"The administrator '{customer.Login}' was removed!");

                administrator = new UserRecord()
                {
                    Login        = login,
                    Registration = name,
                    Name         = name,
                    Email        = email,
                    Language     = user.Language,
                    CustomerId   = customer.Id
                };
                Info($"Creating a new administrator {administrator} ...");

                _userManager.Database.User.Add(administrator);
                _userManager.Database.SaveChanges();

                sendEmail = true;
            }
            else if (!administrator.Login.Equals(login) || !administrator.Email.Equals(email))
            {
                Info($"The administrator '{administrator}' has to be updated!");

                if (!administrator.Login.Equals(login))
                {
                    administrator.Login = login;
                }

                if (administrator.Registration.Equals(customer.Name))
                {
                    administrator.Registration = name;
                }

                if (administrator.Name.Equals(customer.Name))
                {
                    administrator.Name = name;
                }

                if (!administrator.Email.Equals(email))
                {
                    administrator.Email = email;
                    sendEmail           = administrator.Password == null;
                }

                _userManager.Database.SaveChanges();

                Info($"The administrator '{administrator}' is updated!");
            }
            else
            {
                Debug($"The administrator {administrator} doesn't change");
            }

            // check if the administration module is defined and assigned to the user

            ModuleRecord moduleAdministration = null;

            foreach (ModuleRecord record in _userManager.Database.Module.Where(m => m.Module == ModuleRecord.EModule.Administration &&
                                                                               m.Profile == UserProfile.EUserProfile.Administrator &&
                                                                               m.CustomerId == customer.Id).ToList())
            {
                // Module deleted ?

                InformationRecord information = _userManager.Database._Information.Find("Module", record.Id);

                if (information != null && information.IsDeleted)
                {
                    continue;
                }

                moduleAdministration = record;
                if (!moduleAdministration.Enable)
                {
                    Info($"The module administrator '{moduleAdministration}' is enabled!");
                    moduleAdministration.Enable = true;
                    _userManager.Database.SaveChanges();
                }
            }

            if (moduleAdministration == null)
            {
                Debug($"Creation of the module administrator");
                moduleAdministration = new ModuleRecord()
                {
                    Name       = "Administration",
                    Module     = ModuleRecord.EModule.Administration,
                    Profile    = UserProfile.EUserProfile.Administrator,
                    Enable     = true,
                    CustomerId = customer.Id
                };
                _userManager.Database.Module.Add(moduleAdministration);
                _userManager.Database.SaveChanges();
                Info($"Module({moduleAdministration.Id}) created");
            }

            // check if the module administration is assigned to the administrator

            UserModuleRecord userModuleAdministration = null;

            foreach (UserModuleRecord record in _userManager.Database.UserModule.Where(a => a.ModuleId == moduleAdministration.Id &&
                                                                                       a.UserId == administrator.Id &&
                                                                                       a.CustomerId == customer.Id).ToList())
            {
                // Module deleted ?

                InformationRecord information = _userManager.Database._Information.Find("UserModule", record.Id);

                if (information != null && information.IsDeleted)
                {
                    continue;
                }

                userModuleAdministration = record;
            }

            if (userModuleAdministration == null)
            {
                Debug($"Creation of the association between the user and the module administration");
                userModuleAdministration = new UserModuleRecord()
                {
                    ModuleId   = moduleAdministration.Id,
                    UserId     = administrator.Id,
                    CustomerId = customer.Id
                };
                _userManager.Database.UserModule.Add(userModuleAdministration);
                _userManager.Database.SaveChanges();
                Info($"UserModule({userModuleAdministration.Id}) created");
            }

            // update the customer

            customer.Name    = name;
            customer.Login   = login;
            customer.Email   = email;
            customer.Address = address;
            customer.Comment = comment;

            _userManager.Database.SaveChanges();

            if (sendEmail)
            {
                // send a mail for the new user

                Info($"Sending an email to create the password ...");

                using (UserController controller = new UserController(_userManager))
                    controller.SendNewPassword(administrator.Login);
            }

            Info($"Customer updated ...");

            return(RedirectToAction("Index"));
        }
 public override void WriteInformation(InformationRecord record)
 {
     _Log.Write(Verbosity.Verbose, LogLevel.Information, "{0}", record.MessageData);
 }
 protected abstract void DoWriteInformation(InformationRecord informationRecord);
Exemple #13
0
        /// <summary>
        /// Retrieve the default module for the given user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public ModuleRecord GetDefaultModule(UserRecord user)
        {
            try
            {
                if (Database == null || user == null)
                {
                    return(null);
                }

                // Look for modules allowed for the current user

                UserModuleRecord userModuleFound = null;

                foreach (UserModuleRecord userModuleCurrent in (from userModule in Database.UserModule
                                                                where userModule.UserId == user.Id && userModule.Default
                                                                select userModule).ToList())
                {
                    InformationRecord information = Database._Information.Find("UserModule", userModuleCurrent.Id);

                    if (information == null || !information.IsDeleted)
                    {
                        userModuleFound = userModuleCurrent;
                        break;
                    }
                }

                if (userModuleFound == null)
                {
                    Warn($"No module by default for the user {user.Login} ... Set the first module defined for the user ...");

                    foreach (UserModuleRecord userModuleCurrent in (from userModule in Database.UserModule
                                                                    where userModule.UserId == user.Id
                                                                    select userModule).ToList())
                    {
                        InformationRecord information = Database._Information.Find("UserModule", userModuleCurrent.Id);

                        if (information == null || !information.IsDeleted)
                        {
                            userModuleFound = userModuleCurrent;
                            break;
                        }
                    }
                }

                if (userModuleFound == null)
                {
                    Warn($"No module found for the user {user.Login} ...");
                    return(null);
                }

                // Look for the module

                ModuleRecord module = Database.Module.Find(userModuleFound.ModuleId);

                if (module == null)
                {
                    Error($"Database inconsistency due to the missing of the module '{userModuleFound.ModuleId}' ...");
                    return(null);
                }

                if (!module.Enable)
                {
                    Warn($"The default module '{module.Name}' is disabled!");
                    return(null);
                }

                Info($"The default module is '{module.Name}'");
                return(module);
            }
            catch (System.Exception ex)
            {
                Exception($"Unable to retrieve the default module", ex);
                return(null);
            }
        }
Exemple #14
0
        private void Information_DataAdded(object sender, DataAddedEventArgs e)
        {
            InformationRecord informationRecord = PS.Streams.Information.Last();

            Logger.Log(informationRecord.MessageData.ToString(), LogLevels.Information);
        }
Exemple #15
0
 public PSOutput(InformationRecord information)
 {
     Stream      = PowerShellStreamType.Information;
     Information = information ?? throw new ArgumentNullException(nameof(information));
 }
Exemple #16
0
 public void OnInformation(InformationRecord information) => _onInformation?.Invoke(this, information);
Exemple #17
0
 protected override void DoWriteInformation(InformationRecord informationRecord)
 {
     Logger.WriteInformation(informationRecord);
 }
Exemple #18
0
        private static void InfoEventHandler(object sender, DataAddedEventArgs e)
        {
            InformationRecord newRecord = ((PSDataCollection <InformationRecord>)sender)[e.Index];

            Console.WriteLine("Info: {0}", newRecord);
        }
        /// <summary>
        /// Retrieve a list of tuple (DSRecord, Table) attached to a given record (table, id) for the given profile
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="table"></param>
        /// <param name="id"></param>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        /// <param name="profile"></param>
        /// <param name="area"></param>
        /// <param name="deepUpdate"></param>
        /// <param name="recordAlreadyRead"></param>
        /// <param name="informationAlreadyRead"></param>
        /// <returns></returns>
        public override void GetListRecordsConcernedByUpdate(DSCache cache,
                                                             string table,
                                                             int id,
                                                             int customerId,
                                                             int userId,
                                                             UserProfile.EUserProfile profile,
                                                             string area,
                                                             bool deepUpdate,
                                                             DSRecord recordAlreadyRead,
                                                             InformationRecord informationAlreadyRead)
        {
            if (id < 0 || profile == UserProfile.EUserProfile.None || cache.Is(table, id) != null)
                return;

            // Retrieve the current record

            DSRecord currentRecord = null;
            Tuple<DSRecord, InformationRecord> currentRecordFromCache = cache.GetRecord(this, table, id);

            if (currentRecordFromCache == null && recordAlreadyRead == null)
            {
                switch (table)
                {
                    case "Parameter":
                        currentRecord = Parameter.Find(id);
                        break;

                    default:
                        base.GetListRecordsConcernedByUpdate(cache, table, id, customerId, userId, profile, area, deepUpdate, recordAlreadyRead, informationAlreadyRead);
                        return;
                }

                if (currentRecord == null)
                {
                    cache.Set(table, id, null);
                    return;
                }

                currentRecordFromCache = cache.SetRecord(this, table, id, currentRecord, null);
            }
            else if (currentRecordFromCache == null && recordAlreadyRead != null)
            {
                currentRecordFromCache = cache.SetRecord(this, table, id, recordAlreadyRead, informationAlreadyRead);
            }

            if (currentRecordFromCache != null)
                currentRecord = currentRecordFromCache.Item1;

            // Check if the record is concerned by the current update

            if (currentRecord is DSRecordWithCustomerId currentCustomerRecord)
            {
                if (currentCustomerRecord.CustomerId != customerId)
                {
                    cache.Set(table, id, null);
                    return;
                }
            }

            if (currentRecord as Models.ParameterRecord != null)
            {
                cache.Set(table, id, currentRecord);
                return;
            }

            base.GetListRecordsConcernedByUpdate(cache, table, id, customerId, userId, profile, area, deepUpdate, recordAlreadyRead, informationAlreadyRead);
        }
Exemple #20
0
        } // WriteDebug

        /// <Content contentref="System.Management.Automation.Cmdlet.WriteInformation" />
        public void WriteInformation(InformationRecord record)
        {
            using (PSTransactionManager.GetEngineProtectionScope())
            {
                Diagnostics.Assert(
                    Context != null,
                    "The context should always be set");

                Context.WriteInformation(record);
            }
        } // WriteInformation
Exemple #21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="record">The Information message that is wrapped</param>
 /// <param name="originInfo">The origin information</param>
 public RemotingInformationRecord(InformationRecord record, OriginInfo originInfo)
     : base(record)
 {
     _originInfo = originInfo;
 }
Exemple #22
0
        /// <summary>
        /// Handle the object obtained from an ObjectStream's reader
        /// based on its type.
        /// </summary>
        /// <param name="cmdlet">Cmdlet to use for outputting the object.</param>
        /// <param name="instanceId"></param>
        /// <param name="overrideInquire">Suppresses prompt on messages with Inquire preference.
        /// Needed for Receive-Job</param>
        internal void WriteStreamObject(Cmdlet cmdlet, Guid instanceId, bool overrideInquire = false)
        {
            switch (ObjectType)
            {
            case PSStreamObjectType.Output:
            {
                if (instanceId != Guid.Empty)
                {
                    PSObject o = Value as PSObject;
                    if (o != null)
                    {
                        AddSourceJobNoteProperty(o, instanceId);
                    }
                }

                cmdlet.WriteObject(Value);
            }

            break;

            case PSStreamObjectType.Error:
            {
                ErrorRecord         errorRecord       = (ErrorRecord)this.Value;
                RemotingErrorRecord remoteErrorRecord = errorRecord as RemotingErrorRecord;

                if (remoteErrorRecord == null)
                {
                    // if we get a base ErrorRecord object, check if the computerName is
                    // populated in the RecommendedAction field
                    if (errorRecord.ErrorDetails != null && !string.IsNullOrEmpty(errorRecord.ErrorDetails.RecommendedAction))
                    {
                        string computerName;
                        Guid   jobInstanceId;
                        GetIdentifierInfo(errorRecord.ErrorDetails.RecommendedAction,
                                          out jobInstanceId, out computerName);

                        errorRecord = new RemotingErrorRecord(errorRecord,
                                                              new OriginInfo(computerName, Guid.Empty,
                                                                             jobInstanceId));
                    }
                }
                else
                {
                    errorRecord = remoteErrorRecord;
                }

                errorRecord.PreserveInvocationInfoOnce = true;
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteError(errorRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Warning:
            {
                string            warning           = (string)Value;
                WarningRecord     warningRecord     = new WarningRecord(warning);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteWarning(warningRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Verbose:
            {
                string            verbose           = (string)Value;
                VerboseRecord     verboseRecord     = new VerboseRecord(verbose);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteVerbose(verboseRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Progress:
            {
                ProgressRecord progressRecord = (ProgressRecord)Value;

                RemotingProgressRecord remotingProgressRecord = progressRecord as RemotingProgressRecord;
                if (remotingProgressRecord == null)
                {
                    Guid   jobInstanceId;
                    string computerName;
                    GetIdentifierInfo(progressRecord.CurrentOperation, out jobInstanceId,
                                      out computerName);
                    OriginInfo info = new OriginInfo(computerName, Guid.Empty, jobInstanceId);
                    progressRecord = new RemotingProgressRecord(progressRecord, info);
                }
                else
                {
                    progressRecord = remotingProgressRecord;
                }

                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteProgress(progressRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Debug:
            {
                string            debug             = (string)Value;
                DebugRecord       debugRecord       = new DebugRecord(debug);
                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteDebug(debugRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.Information:
            {
                InformationRecord         informationRecord       = (InformationRecord)this.Value;
                RemotingInformationRecord remoteInformationRecord = informationRecord as RemotingInformationRecord;

                if (remoteInformationRecord == null)
                {
                    // if we get a base InformationRecord object, check if the computerName is
                    // populated in the Source field
                    if (!string.IsNullOrEmpty(informationRecord.Source))
                    {
                        string computerName;
                        Guid   jobInstanceId;
                        GetIdentifierInfo(informationRecord.Source, out jobInstanceId, out computerName);
                        informationRecord = new RemotingInformationRecord(informationRecord,
                                                                          new OriginInfo(computerName, Guid.Empty,
                                                                                         jobInstanceId));
                    }
                }
                else
                {
                    informationRecord = remoteInformationRecord;
                }

                MshCommandRuntime mshCommandRuntime = cmdlet.CommandRuntime as MshCommandRuntime;
                if (mshCommandRuntime != null)
                {
                    mshCommandRuntime.WriteInformation(informationRecord, overrideInquire);
                }
            }

            break;

            case PSStreamObjectType.WarningRecord:
            case PSStreamObjectType.MethodExecutor:
            case PSStreamObjectType.BlockingError:
            case PSStreamObjectType.ShouldMethod:
            {
                WriteStreamObject(cmdlet, overrideInquire);
            }

            break;
            }
        }
Exemple #23
0
 protected virtual void DoWriteInformation(InformationRecord record)
 {
 }
        /// <summary>
        /// 
        /// </summary>
        internal void WriteInformationRecord(InformationRecord record)
        {
            WriteInformationInfoBuffers(record);

            if (_externalUI == null)
            {
                return;
            }

            _externalUI.WriteInformation(record);
        }
        /// <summary>
        /// Update the cache within the list of records updated by the transaction
        /// </summary>
        /// <param name="records"></param>
        /// <param name="customerId"></param>
        /// <param name="tick"></param>
        public void UpdateCache(List <Tuple <string, DSRecord, InformationRecord> > records, int customerId, int tick)
        {
            if (!_enable)
            {
                return;
            }

            Lock(customerId); // lock critical section

            // Check if the customer is currently loaded

            if (!_tick.ContainsKey(customerId))
            {
                Unlock(customerId); // unlock critical section
                return;
            }

            try
            {
                // Update the cache within the list of records from the transaction currently executed

                Dictionary <string, Dictionary <int, Tuple <DSRecord, InformationRecord> > > currentTable = _records[customerId];

                foreach (Tuple <string, DSRecord, InformationRecord> record in records)
                {
                    if (!currentTable.ContainsKey(record.Item1))
                    {
                        continue;
                    }

                    currentTable[record.Item1][record.Item2.Id] = Tuple.Create(DSRecord.Copy(record.Item2), InformationRecord.Copy(record.Item3));
                }

                _tick[customerId] = tick;

                if (IsDebug())
                {
                    Debug($"[{customerId}] Cache updated in tick {_tick[customerId]}");
                }
            }
            catch (System.Exception ex)
            {
                Exception($"[{customerId}] Unable to update the cache", ex);
            }

            Unlock(customerId); // unlock critical section
        }
Exemple #26
0
        public void WriteInformation(InformationRecord informationRecord)
        {
            CheckForCancellation();

            this.Information.Add(informationRecord);
        }
 public override void WriteInformation(InformationRecord record)
 {
     OnInfoReceived(new MessageEventArgs {
         Message = record.ToString()
     });
 }