Esempio n. 1
0
        /*
         * private static readonly XmlSerializer g_xmlSerializer = new XmlSerializer(typeof(WorkspaceToChekcoutCache));
         */

        public static WorkspaceToChekcoutCache Read(string cacheLocation, string workspaceName)
        {
            string filePath = Path.Combine(cacheLocation, workspaceName + ".p4cache");

            WorkspaceToChekcoutCache cacheFile = null;

            try
            {
                if (File.Exists(filePath))
                {
                    cacheFile = JsonHelper.BuildObjectForJson <WorkspaceToChekcoutCache>(JsonHelper.ParseFile(filePath));

                    /*
                     * using (Stream s = File.OpenRead(filePath))
                     * {
                     *  StreamReader reader = new StreamReader(s);
                     *
                     *  cacheFile = g_xmlSerializer.Deserialize(reader) as WorkspaceToChekcoutCache;
                     * }
                     */
                }
            }
            catch (Exception exc)
            {
                Logger.LogError("Failed to load p4cache info", exc);
            }

            if (cacheFile == null)
            {
                return(new WorkspaceToChekcoutCache()
                {
                    m_cachePath = filePath
                });
            }
            else
            {
                cacheFile.m_cachePath = filePath;
                return(cacheFile);
            }
        }
Esempio n. 2
0
        private static void ResetCache()
        {
            Logger.LogInfo("=======[Attempting to reset the PerforceCmdManager's check out/add later cache]=======");
            if (g_cache != null)
            {
                g_cache.Write();
                g_cache = null;
            }

            if (Connection.IsConnected && Connection.WorkspaceName != null)
            {
                g_cache = WorkspaceToChekcoutCache.Read(g_cacheRoot, Connection.WorkspaceName);
            }


            if (g_cache != null)
            {
                foreach (string file in g_cache.ToCheckoutPaths.ToArray())
                {
                    Logger.LogInfo($"Attempting to checkout file ({file}) which was asked to be checked out, but was unable to do so in the past.");
                    try
                    {
                        var editResult = kP4.BuildRunner().Run("edit \"{0}\"", file);
                        if (editResult.Success)
                        {
                            g_cache.ToCheckoutPaths.Remove(file);
                        }
                        else
                        {
                            Logger.LogError($"Failed to checkout file ({file}) again, checkout failure report:\n{editResult.GenerateFailureReport()}");
                        }
                    }
                    catch (Exception exc)
                    {
                        Logger.LogError($"Checkout of file ({file}) failed due to exception!", exc);
                    }
                }
                foreach (string file in g_cache.ToAddPaths.ToArray())
                {
                    Logger.LogInfo($"Attempting to add file ({file}) to source control which was asked to be added, but was unable to do so in the past.");
                    try
                    {
                        var addResult = kP4.BuildRunner().Run("add \"{0}\"", file);
                        if (addResult.Success)
                        {
                            g_cache.ToCheckoutPaths.Remove(file);
                        }
                        else
                        {
                            Logger.LogError($"Failed to add file ({file}) to source control again, checkout failure report:\n{addResult.GenerateFailureReport()}");
                        }
                    }
                    catch (Exception exc)
                    {
                        Logger.LogError($"Source control add of file ({file}) failed due to exception!", exc);
                    }
                }

                g_cache.Write();
            }
        }