Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExtensionEventArgs"/> class.
 /// </summary>
 /// <param name="extension">The extension.</param>
 /// <param name="action">The action.</param>
 /// <remarks>Documented by Dev02, 2009-07-03</remarks>
 public ExtensionEventArgs(IExtension extension, ExtensionAction action)
 {
     this.Extension = extension;
     this.Action = action;
 }
Пример #2
0
        public void IExtensionTestAddExtensionToLM()
        {
            TestInfrastructure.DebugLineStart(TestContext);
            if (TestInfrastructure.IsActive(TestContext) && TestInfrastructure.ConnectionType(TestContext) != "File")
            {
                using (IDictionary writeLM = TestInfrastructure.GetLMConnection(TestContext, TestInfrastructure.GetAdminUser))
                {
                    byte[] bufCheck = new byte[5];
                    byte[] bufOriginal = new byte[5] { (byte)'H', (byte)'e', (byte)'l', (byte)'l', (byte)'o' };

                    ExtensionAction extensionAction = new ExtensionAction() { Kind = ExtensionActionKind.Install, Execution = ExtensionActionExecution.Once };

                    IExtension extension = writeLM.Parent.CurrentUser.List().ExtensionFactory();
                    extension.Type = ExtensionType.Skin;
                    extension.Name = "TheurySkin";
                    extension.Version = new Version("1.0.0.0");
                    extension.StartFile = "TheurySkin.style";
                    extension.Data = new System.IO.MemoryStream(bufOriginal);
                    extension.Actions.Add(extensionAction);

                    writeLM.Extensions.Add(extension);

                    ////////////////////////////////////////////////////////////////

                    Assert.AreEqual<int>(1, writeLM.Extensions.Count, "The Extension is not correctly saved to the database/LM");
                    Assert.AreEqual<ExtensionType>(ExtensionType.Skin, writeLM.Extensions[0].Type, "The ExtensionType is wrong");
                    Assert.AreEqual<string>("TheurySkin", writeLM.Extensions[0].Name, "The ExtensionName is wrong");
                    Assert.AreEqual<Version>(new Version("1.0.0.0"), writeLM.Extensions[0].Version, "The ExtensionVersion is wrong");
                    Assert.AreEqual<string>("TheurySkin.style", writeLM.Extensions[0].StartFile, "The ExtensionStartFile is wrong");
                    Assert.AreEqual<ExtensionAction>(extensionAction, writeLM.Extensions[0].Actions[0], "The ExtensionAction is wrong");

                    writeLM.Extensions[0].Data.Read(bufCheck, 0, bufOriginal.Length);
                    for (int i = 0; i < bufCheck.Length; i++)
                        Assert.AreEqual<byte>(bufCheck[i], bufOriginal[i], "The ExtensionData is wrong");

                    ////////////////////////////////////////////////////////////////

                    writeLM.Extensions[0].Actions.RemoveAt(0);
                    Assert.AreEqual<int>(0, writeLM.Extensions[0].Actions.Count, "Number of ExtensionActions is wrong");
                }
            }
            TestInfrastructure.DebugLineEnd(TestContext);
        }
Пример #3
0
 /// <summary>
 /// Forces the extension.
 /// </summary>
 /// <param name="extension">The extension.</param>
 /// <param name="action">The action.</param>
 /// <remarks>Documented by Dev02, 2009-07-03</remarks>
 private void ForceExtension(IExtension extension, ExtensionAction action)
 {
     if (ExecuteExtension != null)
         ExecuteExtension(this, new ExtensionEventArgs(extension, action));
 }
Пример #4
0
 /// <summary>
 /// Installs the extension.
 /// </summary>
 /// <param name="extension">The extension.</param>
 /// <param name="action">The action.</param>
 /// <remarks>Documented by Dev02, 2009-07-03</remarks>
 private void InstallExtension(IExtension extension, ExtensionAction action)
 {
     string extractionPath;
     switch (extension.Type)
     {
         case ExtensionType.Skin:
             extractionPath = SkinPath;
             break;
         case ExtensionType.Unknown:
         default:
             return;
     }
     extension.ExtractData(extractionPath);
 }
Пример #5
0
 /// <summary>
 /// Informs the user.
 /// </summary>
 /// <param name="extension">The extension.</param>
 /// <param name="action">The action.</param>
 /// <remarks>Documented by Dev02, 2009-07-09</remarks>
 private void ExtensionInformUser(IExtension extension, ExtensionAction action)
 {
     if (InformUser != null)
         InformUser(this, new ExtensionEventArgs(extension, action));
 }
Пример #6
0
        /// <summary>
        /// Adds the action executed.
        /// </summary>
        /// <param name="extension">The extension.</param>
        /// <param name="action">The action.</param>
        /// <remarks>Documented by Dev02, 2009-07-03</remarks>
        private static void AddActionExecuted(IExtension extension, ExtensionAction action)
        {
            if (!executedActions.ContainsKey(extension.Id) || executedActions[extension.Id] == null)
                executedActions[extension.Id] = new List<ExtensionAction>();

            if (!executedActions[extension.Id].Contains(action))
            {
                executedActions[extension.Id].Add(action);
                extensionListsDirty = true;
            }
        }
Пример #7
0
        /// <summary>
        /// Determines whether action has already been executed.
        /// </summary>
        /// <param name="extension">The extension.</param>
        /// <param name="action">The action.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2009-07-03</remarks>
        private static bool ActionAlreadyExecuted(IExtension extension, ExtensionAction action)
        {
            if (!executedActions.ContainsKey(extension.Id) || executedActions[extension.Id] == null)
                return false;

            return executedActions[extension.Id].Contains(action);
        }
        /// <summary>
        /// Gets the extension actions.
        /// </summary>
        /// <param name="guid">The GUID.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2009-07-03</remarks>
        public IList<ExtensionAction> GetExtensionActions(Guid guid)
        {
            IList<ExtensionAction> extensionActions = new List<ExtensionAction>();
            using (SqlCeCommand cmd = MSSQLCEConn.CreateCommand(parent.CurrentUser))
            {
                cmd.CommandText = "SELECT action, execution FROM \"ExtensionActions\" WHERE guid=@guid";
                cmd.Parameters.Add("@guid", guid.ToString());

                SqlCeDataReader reader = MSSQLCEConn.ExecuteReader(cmd);
                while (reader.Read())
                {
                    object action = reader["action"];
                    object execution = reader["execution"];

                    ExtensionAction extensionAction = new ExtensionAction();
                    extensionAction.Kind = (ExtensionActionKind)Enum.Parse(typeof(ExtensionActionKind), action as string);
                    extensionAction.Execution = (ExtensionActionExecution)Enum.Parse(typeof(ExtensionActionExecution), execution as string);

                    extensionActions.Add(extensionAction);
                }
            }
            return extensionActions;
        }
 /// <summary>
 /// Gets the extension actions.
 /// </summary>
 /// <param name="guid">The GUID.</param>
 /// <returns></returns>
 public IList<ExtensionAction> GetExtensionActions(Guid guid)
 {
     List<ExtensionAction> actions = new List<ExtensionAction>();
     using (NpgsqlConnection con = PostgreSQLConn.CreateConnection(Parent.CurrentUser))
     {
         using (NpgsqlCommand cmd = con.CreateCommand())
         {
             cmd.CommandText = "SELECT action, execution FROM \"ExtensionActions\" WHERE guid=:guid";
             cmd.Parameters.Add("guid", guid.ToString());
             NpgsqlDataReader reader = PostgreSQLConn.ExecuteReader(cmd, Parent.CurrentUser);
             while (reader.Read())
             {
                 ExtensionAction action = new ExtensionAction();
                 action.Kind = (ExtensionActionKind)Enum.Parse(typeof(ExtensionActionKind), Convert.ToString(reader["action"]));
                 action.Execution = (ExtensionActionExecution)Enum.Parse(typeof(ExtensionActionExecution), Convert.ToString(reader["execution"]));
                 actions.Add(action);
             }
         }
     }
     return actions;
 }