Exemplo n.º 1
0
        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            PropertyDescriptorCollection propertyDescriptorCol = context.DataContext.GetProperties();

            foreach (PropertyDescriptor pd in propertyDescriptorCol)
            {
                if (string.Equals(pd.Name, Singleton<Constants>.UniqueInstance.FileVariableName))
                {
                    try
                    {
                        NetworkCredential networkCredential = new NetworkCredential(Singleton<Constants>.UniqueInstance.UserName, Singleton<Constants>.UniqueInstance.PassWord, Singleton<Constants>.UniqueInstance.Domain);

                        string sharePath = string.Format(@"\\{0}\c$", Singleton<Constants>.UniqueInstance.MachineName);
                            //Singleton<Constants>.UniqueInstance.GacEssentialsPath.Substring(0, Singleton<Constants>.UniqueInstance.GacEssentialsPath.IndexOf(@"c$\Windows") + @"c$\Windows".Length);

                        using (NetworkConnection nc = new NetworkConnection(sharePath, networkCredential))
                        {
                            FileItem[] fileItems = (FileItem[])pd.GetValue(context.DataContext);
                            foreach (FileItem fileItem in fileItems)
                            {
                                ReplaceFileHelper.ReplaceFile(fileItem);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        string msg = string.Format("exception encounterred: {0} when executing replacefilesactivity", e);
                        Singleton<ReportMediator>.UniqueInstance.ReportStatus(msg, LogLevel.Warning);
                    }
                }
            }
            // Obtain the runtime value of the Text input argument
            string text = context.GetValue(this.Text);
        }
Exemplo n.º 2
0
        public static FileItem[] BuildFileItems()
        {
            string msg = "building the file item list...";
            Singleton<ReportMediator>.UniqueInstance.ReportStatus(msg);
            List<FileItem> fileItemsList = new List<FileItem>();
            // get source file list.
            List<string> sourceFullNames = GetFileListRecursively(Singleton<Constants>.UniqueInstance.SourceRootPath);
            sourceFullNames.Sort();
            // get destination file list.
            List<string> targetFiles = new List<string>();

            try
            {
                NetworkCredential networkCredential = new NetworkCredential(Singleton<Constants>.UniqueInstance.UserName, Singleton<Constants>.UniqueInstance.PassWord, Singleton<Constants>.UniqueInstance.Domain);

                string sharePath = string.Format(@"\\{0}\c$", Singleton<Constants>.UniqueInstance.MachineName);
                    //Constants.GacEssentialsPath.Substring(0, Constants.GacEssentialsPath.IndexOf(@"c$\Windows") + @"c$\Windows".Length);

                using (NetworkConnection nc = new NetworkConnection(sharePath, networkCredential))
                {
                    string [] targetDirectories = BuildTargetDirectories();
                    foreach (string targetDictory in targetDirectories)
                    {
                        targetFiles.AddRange(GetFileListRecursively(string.Format(targetDictory, Singleton<Constants>.UniqueInstance.MachineName)));
                    }
                    //targetFiles.AddRange(GetFileListRecursively(Constants.System32EssentialsPath));
                    //targetFiles.AddRange(GetFileListRecursively(Constants.GacEssentialsPath));
                }
            }
            catch (Exception e)
            {
                msg = string.Format("error building file items. {0}", e);
                Singleton<ReportMediator>.UniqueInstance.ReportStatus(msg, LogLevel.Warning);
            }

            targetFiles.Sort();

            // merge the two list into one array of FileItem
            foreach (string sourceFile in sourceFullNames)
            {
                if (sourceFile.EndsWith(".dll") || sourceFile.EndsWith(".exe"))
                {
                    string sourceFileName = ExtractFileName(sourceFile);

                    //Assembly sourceAssembly = Assembly.ReflectionOnlyLoadFrom(sourceFile);

                    ////Assembly.
                    foreach (string targetFile in targetFiles)
                    {
                        string destFileName = ExtractFileName(targetFile);
                        if (string.Equals(sourceFileName, destFileName, StringComparison.OrdinalIgnoreCase))
                        {
                            fileItemsList.Add(new FileItem(sourceFile, targetFile));
                        }
                        //Assembly targetAssembly = Assembly.ReflectionOnlyLoadFrom(sourceFile);
                        //if (string.Equals(sourceAssembly.FullName, targetAssembly.FullName))
                        //{
                        //    fileItemsList.Add(new FileItem(sourceFile, targetFile));
                        //}
                    }
                }
            }

            return fileItemsList.ToArray();
        }