示例#1
0
        public static K GetContentByKey <T, K, C>(
            T key, bool?alive,
            Func <T, K> service,
            IDictionary <T, C> cache,
            UpdateCache <T, K, C> updateCacheFunction = null
            ) where C : CacheBase, new()
        {
            if (updateCacheFunction == null)
            {
                updateCacheFunction = DefaultUpdateCache;
            }
            K content;

            if (cache.ContainsKey(key))
            {
                content = cache[key].GetContent <K>();
            }
            else
            {
                content = service(key);
            }
            MethodResponse result;

            try
            {
                updateCacheFunction(key, content, alive, cache, out result);
            }
            catch
            {
            }
            return(content);
        }
示例#2
0
        public static IEnumerable <K> GetChildContentsByQuery <Key, K, C>(
            Func <IEnumerable <K> > getFromService,
            Func <IDictionary <Key, C>, IEnumerable <C> > getFromCache,
            Func <K, Key> getKey,
            IDictionary <Key, C> cacheInput,
            Func <K, bool> where = null,
            bool?alive           = null,
            int expireMin        = 30, bool newQuery = false,
            UpdateCache <Key, K, C> updateCacheFunction = null
            ) where C : CacheBase, new()
        {
            if (updateCacheFunction == null)
            {
                updateCacheFunction = DefaultUpdateCache;
            }
            var             cache = new Dictionary <Key, C>(cacheInput);
            IEnumerable <K> result;

            if (newQuery)
            {
                goto GetFromServer;
            }
            var resultFromCache = getFromCache(cache);

            if (where != null)
            {
                resultFromCache = resultFromCache.Where(b => where (b.GetContent <K>()));
            }
            if (resultFromCache.IsExpire(expireMin))
            {
                goto GetFromServer;
            }

            result = resultFromCache.Select(b => b.GetContent <K>());
            goto UpdateCache;

GetFromServer:
            result = getFromService().ToList();

UpdateCache:
            try
            {
                result.Select(r =>
                {
                    Key key = getKey(r);
                    MethodResponse response;
                    updateCacheFunction(key, r, alive, cacheInput, out response);
                    return(r);
                }).ToList();
                if (where != null)
                {
                    result = result.Where(where);
                }
                return(result);
            }
            catch
            {
                return(result);
            }
        }
示例#3
0
 private void LoadUpdateCache()
 {
     Debugger.Log(0, "Startup", "Loading Cache...");
     UpdateCache.Load();
     pbProgress.Increment();
     Debugger.Log(0, "Startup", "Cache Loaded.");
 }
 public override void Update(Entity entity)
 {
     if (UpdateAction != null)
     {
         UpdateAction(Service, entity);
     }
     else if (UpdateActions != null)
     {
         if (UpdateCache == null)
         {
             UpdateCache = Service;
             foreach (var update in UpdateActions)
             {
                 UpdateCache = new FakeIOrganizationService(UpdateCache)
                 {
                     UpdateAction = update
                 };
             }
         }
         UpdateCache.Update(entity);
     }
     else
     {
         if (ExecutionTracingEnabled)
         {
             Timer.Time(UpdateInternal, entity, "Update Entity {0}: {1}", entity.GetNameId());
         }
         else
         {
             Service.Update(entity);
         }
     }
 }
示例#5
0
        public void GenerateColumns()
        {
            var errorSuffix = "columns in table " + this.Name.Name;
            var columns     = new Dictionary <string, IColumn>();

            void AddColumns(IEnumerable <IColumn> newColumns)
            {
                try
                {
                    columns.AddRange(newColumns, c => c.Name, c => c, errorSuffix);
                }catch (RepeatedElementsException ex) when(StartParameters.IgnoredCodeErrors != null)
                {
                    StartParameters.IgnoredCodeErrors.Add(ex);
                }
            }

            AddColumns(Fields.Values.SelectMany(c => c.Field.Columns()));

            if (Mixins != null)
            {
                AddColumns(Mixins.Values.SelectMany(m => m.Fields.Values).SelectMany(f => f.Field.Columns()));
            }

            if (this.SystemVersioned != null)
            {
                AddColumns(this.SystemVersioned.Columns());
            }

            Columns = columns;
            inserterDisableIdentity = new ResetLazy <InsertCacheDisableIdentity>(() => InsertCacheDisableIdentity.InitializeInsertDisableIdentity(this));
            inserterIdentity        = new ResetLazy <InsertCacheIdentity>(() => InsertCacheIdentity.InitializeInsertIdentity(this));
            updater         = new ResetLazy <UpdateCache>(() => UpdateCache.InitializeUpdate(this));
            saveCollections = new ResetLazy <CollectionsCache?>(() => CollectionsCache.InitializeCollections(this));
        }
示例#6
0
        protected _Update(string filePath)
            : base(filePath)
        {
            _language = "Neutral";
            if (Path.GetFileNameWithoutExtension(Location).EndsWithIgnoreCase("-X64"))
            {
                _architecture = Architecture.X64;
            }

            var cacheItem = UpdateCache.Find(Path.GetFileName(Location), Size);

            if (cacheItem == null && !MD5.Equals("N/A"))
            {
                cacheItem = UpdateCache.Find(MD5);
            }

            if (cacheItem != null)
            {
                _packageName        = cacheItem.PackageName;
                _packageVersion     = cacheItem.PackageVersion;
                _updateType         = cacheItem.Type;
                _packageDescription = cacheItem.PackageDescription;
                _language           = cacheItem.Language;
                _appliesTo          = cacheItem.AppliesTo.ToString();
                _support            = cacheItem.Support;
                _createdDate        = cacheItem.CreatedDate;
                _offlineAllowed     = cacheItem.AllowedOffline;
            }

            _tooltip = _packageName + "\n" + _packageVersion + " [" + _updateType + "]\n" + Location;
        }
示例#7
0
        public void GenerateColumns()
        {
            var errorSuffix = "columns in table " + this.Name.Name;

            var columns = Fields.Values.SelectMany(c => c.Field.Columns()).ToDictionaryEx(c => c.Name, errorSuffix);

            if (Mixins != null)
            {
                columns.AddRange(Mixins.Values.SelectMany(m => m.Fields.Values).SelectMany(f => f.Field.Columns()).ToDictionaryEx(c => c.Name, errorSuffix), errorSuffix);
            }

            Columns = columns;

            inserterDisableIdentity = new ResetLazy <InsertCacheDisableIdentity>(() => InsertCacheDisableIdentity.InitializeInsertDisableIdentity(this));
            inserterIdentity        = new ResetLazy <InsertCacheIdentity>(() => InsertCacheIdentity.InitializeInsertIdentity(this));
            updater         = new ResetLazy <UpdateCache>(() => UpdateCache.InitializeUpdate(this));
            saveCollections = new ResetLazy <CollectionsCache>(() => CollectionsCache.InitializeCollections(this));
        }
示例#8
0
        protected _Integratable(string filePath)
        {
            _name        = Path.GetFileNameWithoutExtension(filePath);
            _location    = filePath;
            _size        = FileHandling.GetSize(filePath);
            _createdDate = FileHandling.GetCreationDate(filePath);
            _tooltip     = filePath;
            if (this is MsuUpdate || this is CabUpdate)
            {
                var cacheItem = UpdateCache.Find(Path.GetFileName(Location), Size);
                if (cacheItem != null)
                {
                    _md5 = cacheItem.MD5;
                }
            }

            if (Options.GetMD5 && _md5.EqualsIgnoreCase("N/A"))
            {
                _md5 = FileHandling.GetMD5(filePath);
            }
        }
示例#9
0
 public void Dispose()
 {
     Delegate[] invocationList;
     OnDispose(new EventArgs());
     if (UpdateCache != null)
     {
         invocationList = UpdateCache.GetInvocationList();
         foreach (Delegate delegate2 in invocationList)
         {
             UpdateCache = (EventHandler)Delegate.Remove(UpdateCache, delegate2); //(EventHandler)delegate2
         }
     }
     if (DisposeCache == null)
     {
         return;
     }
     invocationList = DisposeCache.GetInvocationList();
     foreach (Delegate delegate2 in invocationList)
     {
         DisposeCache = (EventHandler)Delegate.Remove(DisposeCache, delegate2);  //(EventHandler)delegate2
     }
 }
示例#10
0
        public static IEnumerable <K> GetContentByKeys <T, K, C>(
            IEnumerable <T> keys, bool?alive, Func <IEnumerable <T>, IEnumerable <K> > serviceFunction, Func <IEnumerable <T>, IDictionary <T, C>, IEnumerable <C> > cacheFunction,
            IDictionary <T, C> cacheInput, Func <K, T> getKey, int expireMin = 30, bool isNewQuery = false, UpdateCache <T, K, C> updateCacheFunction = null
            ) where C : CacheBase, new()
        {
            if (updateCacheFunction == null)
            {
                updateCacheFunction = DefaultUpdateCache;
            }
            IEnumerable <K> content;

            if (isNewQuery)
            {
                goto NewQuery;
            }
            var cache       = new Dictionary <T, C>(cacheInput);
            var cacheResult = cacheFunction(keys, cache);

            if (cacheResult.IsExpire(expireMin))
            {
                goto NewQuery;
            }
            content = cacheResult.Select(b => b.GetContent <K>());
            goto UpdateCache;
NewQuery:
            content = serviceFunction(keys).ToList();
UpdateCache:
            try
            {
                return(content.Select(r => { MethodResponse response; updateCacheFunction(getKey(r), r, alive, cacheInput, out response); return r; }).ToList());
            }
            catch
            {
                return(content);
            }
        }
示例#11
0
        private static void Main(string[] args)
        {
            Cleanup();

            try
            {
                Console.WindowHeight = 50;
            }
            catch
            {
            }

            if (args.Length == 0)
            {
                WriteText("No directory specified", ConsoleColor.Red);
                return;
            }

            var files    = new List <string>();
            var foundDir = new List <UpdateDirectory>();

            WriteText("Deleting [" + UpdateCache.CACHE_PATH_XML + "]...", ConsoleColor.Yellow);
            FileHandling.DeleteFile(UpdateCache.CACHE_PATH_XML);

            WriteText("Deleting [" + UpdateCache.CACHE_ERROR_XML + "]...", ConsoleColor.Yellow);
            FileHandling.DeleteFile(UpdateCache.CACHE_ERROR_XML);
            Console.WriteLine();

            foreach (var directory in args.AsParallel())
            {
                try
                {
                    if (!Directory.Exists(directory))
                    {
                        WriteText("Invalid directory [" + directory + "]", ConsoleColor.Red);
                        return;
                    }
                    WriteText("Searching [" + directory + "]...", ConsoleColor.Yellow);

                    var foundFiles = Directory.GetFileSystemEntries(directory, "*.*", SearchOption.AllDirectories)
                                     .Where(
                        f =>
                        Path.GetExtension(f)
                        .EndsWithIgnoreCase(".MSU", StringComparison.InvariantCultureIgnoreCase) ||
                        Path.GetExtension(f)
                        .EndsWithIgnoreCase(".CAB", StringComparison.InvariantCultureIgnoreCase))
                                     .ToArray();

                    lock (files)
                    {
                        var updDirectory = new UpdateDirectory
                        {
                            Path      = directory,
                            FileCount = foundFiles.Length
                        };

                        foundDir.Add(updDirectory);
                        files.AddRange(foundFiles);
                    }
                }
                catch (Exception Ex)
                {
                    Console.WriteLine(Ex.Message);
                    Console.ReadKey();
                }
            }


            Console.Title  = "Building Update Cache";
            Options.GetMD5 = true;
            WriteText("Found " + files.Count + " files.");

            WriteText("Loading Cache...");
            UpdateCache.Load();

            var i     = 1;
            var Cache = UpdateCache.Count;
            var total = files.Count;

            foreach (var update in files)
            {
                Console.Clear();
                var progress = ((float)i / total);
                WriteText("Building Cache " + i + " of " + total + " [" + progress.ToString("0.00%") + "]",
                          ConsoleColor.Cyan);
                Console.WriteLine();
                foreach (var updDirectory in foundDir)
                {
                    WriteText(" [" + updDirectory.Path + "] :: " + updDirectory.FileCount);
                }

                Console.WriteLine();
                WriteText("Cache: " + Cache);
                WriteText("Total: " + UpdateCache.Count + " | New: " +
                          (UpdateCache.Count - Cache - UpdateCache.UnknownCount));
                Console.WriteLine();

                WriteText("GDR: " + UpdateCache.GDRCount);
                WriteText("LDR: " + UpdateCache.LDRCount);
                WriteText("Unknown: " + UpdateCache.UnknownCount);
                Console.WriteLine();
                WriteText("----------------------------------------");
                Console.WriteLine();
                string cabFile;
                var    temp = Directories.Application + "\\Temp\\" + i;

                MsuUpdate msuItem = null;
                WriteText("Name: " + Path.GetFileName(update));
                WriteText("Size: " + FileHandling.GetSize(update, true));
                Console.WriteLine();
                if (update.EndsWithIgnoreCase("MSU", StringComparison.InvariantCultureIgnoreCase))
                {
                    WriteText("Checking MSU [" + update + "]");
                    if (UpdateCache.Find(Path.GetFileName(update), FileHandling.GetSize(update)) != null)
                    {
                        i++;
                        continue;
                    }

                    WriteText("Preparing MSU [" + update + "]");
                    msuItem = new MsuUpdate(update);

                    WriteText("Extracting CAB [" + update + "]");
                    Extraction.Expand(update, "*.cab", temp);

                    cabFile = Directory.GetFiles(temp, "*.cab", SearchOption.TopDirectoryOnly).FirstOrDefault();

                    if (cabFile == null)
                    {
                        msuItem.UpdateType = UpdateType.GDR;
                        UpdateCache.Add(msuItem);
                    }
                }
                else
                {
                    cabFile = update;
                }

                if (!string.IsNullOrWhiteSpace(cabFile))
                {
                    if (msuItem != null)
                    {
                        Console.WriteLine();
                    }

                    WriteText("Checking CAB [" + update + "]");
                    if (UpdateCache.Find(Path.GetFileName(cabFile), FileHandling.GetSize(cabFile)) == null)
                    {
                        WriteText("Preparing CAB [" + cabFile + "]");
                        var cabItem = new CabUpdate(cabFile);

                        WriteText("Extracting CAB Files [" + cabFile + "]");
                        Extraction.Expand(cabFile, "update-bf.mum", temp);

                        cabItem.UpdateType = UpdateType.GDR;

                        if (File.Exists(temp + "\\update-bf.mum"))
                        {
                            cabItem.UpdateType = UpdateType.LDR;
                        }
                        Console.WriteLine();
                        WriteText("Update is " + cabItem.UpdateType, ConsoleColor.Green);
                        UpdateCache.Add(cabItem);
                        if (msuItem != null)
                        {
                            msuItem.UpdateType = cabItem.UpdateType;
                            UpdateCache.Add(msuItem);
                        }
                    }
                }

                FileHandling.DeleteDirectory(temp);
                i++;
            }
            Cleanup();

            Console.WriteLine();
            WriteText("Build complete. Press any key to close.", ConsoleColor.Green);
            Console.ReadKey();
        }
示例#12
0
        /// <summary>
        ///     Either installs or integrate the update to the live OS or image.
        /// </summary>
        /// <param name="LDR">Install LDR or GDR.</param>
        /// <returns></returns>
        private Status DoWork(Task task, string mountPath, bool LDR)
        {
            if (_progressBar == null)
            {
                _progressBar = new ProgressBar();
            }

            _progressBar.Value = 0;

            Status = Status.Working;

            if (CheckIntegration(mountPath, LDR))
            {
                return(Status.Success);
            }

            if (task == Task.Install)
            {
                Processes.Run("wusa.exe", "\"" + Location + "\" /quiet /norestart");
            }
            else
            {
                Processes.Run(DISM.Default.Location,
                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + Location + "\"");
            }

            if (LDR && (_updateType == UpdateType.Unknown || _updateType == UpdateType.LDR))
            {
                if (CheckIntegration(mountPath))
                {
                    return(Status.Failed);
                }
                Extraction.Expand(Location, "*.cab", _tempLocation);

                var cabFile = Directory.GetFiles(_tempLocation, "*.cab", SearchOption.TopDirectoryOnly).First();
                Extraction.Expand(cabFile, _tempLocation);

                _updateType = UpdateType.GDR;
                if (File.Exists(_tempLocation + "\\update-bf.mum"))
                {
                    _updateType = UpdateType.LDR;

                    if (task == Task.Install)
                    {
                        Processes.Run("pkgmgr.exe",
                                      "/ip /m:\"" + _tempLocation + "\\update-bf.mum" + "\" /quiet /norestart");
                    }
                    else
                    {
                        var s = Processes.Run("DISM",
                                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + _tempLocation +
                                              "\\update-bf.mum" + "\"");
                        MessageBox.Show(s);
                    }
                }

                FileHandling.DeleteDirectory(_tempLocation);
            }

            UpdateCache.Add(this);

            if (_updateType != UpdateType.LDR)
            {
                LDR = false;
            }

            if (CheckIntegration(mountPath, LDR))
            {
                return(Status.Success);
            }
            return(Status.Failed);
        }
示例#13
0
 public Testing()
 {
     UpdateCache.Load();
     Options.GetMD5       = true;
     Directories.TempPath = _temp;
 }
示例#14
0
        /// <summary>
        ///     Either installs or integrate the update to the live OS or image.
        /// </summary>
        /// <param name="LDR">Install LDR or GDR.</param>
        /// <returns></returns>
        private Status DoWork(Task task, string mountPath, bool LDR)
        {
            if (_progressBar == null)
            {
                _progressBar = new ProgressBar();
            }

            _progressBar.Value = 0;

            Status = Status.Working;

            // if (CheckIntegration(mountPath, LDR)) { return Status.Success; }

            if (task == Task.Install)
            {
                using (var session = DismApi.OpenOnlineSession())
                {
                    DismApi.AddPackage(session, Location, true, false,
                                       delegate(DismProgress progress) { _progressBar.Value = progress.Current; });
                }
                // Processes.Run("pkgmgr.exe", "/ip /m:\"" + Location + "\" /quiet /norestart");
            }
            else
            {
                Processes.Run(DISM.Default.Location,
                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + Location + "\"");
            }

            if (LDR && (_updateType == UpdateType.Unknown || _updateType == UpdateType.LDR))
            {
                if (CheckIntegration(mountPath))
                {
                    return(Status.Failed);
                }
                Extraction.Expand(Location, _tempLocation);

                _updateType = UpdateType.GDR;
                if (File.Exists(_tempLocation + "\\update-bf.mum"))
                {
                    _updateType = UpdateType.LDR;

                    if (task == Task.Install)
                    {
                        Processes.Run("pkgmgr.exe",
                                      "/ip /m:\"" + _tempLocation + "\\update-bf.mum" + "\" /quiet /norestart");
                    }
                    else
                    {
                        var s = Processes.Run("DISM",
                                              "/Image:\"" + mountPath + "\" /Add-Package /Packagepath:\"" + _tempLocation +
                                              "\\update-bf.mum" + "\"");
                        MessageBox.Show(s);
                    }
                }

                FileHandling.DeleteDirectory(_tempLocation);
            }

            UpdateCache.Add(this);

            if (_updateType != UpdateType.LDR)
            {
                LDR = false;
            }

            if (CheckIntegration(mountPath, LDR))
            {
                return(Status.Success);
            }
            return(Status.Failed);
        }