private bool checkClientVersion(RemoteVersion version)
        {
            //Return 'true' if version is 2.3.1 p15 or greater. False if not.
            string[] verNums = version.Version.Split('.');

            return(false);
        }
        public void UserCanProvideCustomProjectVersionService()
        {
            // Arrange
            var projects = new Mock <IProjectService>();
            var client   = new Mock <IJiraRestClient>();
            var jira     = Jira.CreateRestClient(client.Object);

            var remoteProject = new RemoteProject()
            {
                id = "projId", key = "projKey", name = "my project"
            };

            projects.Setup(s => s.GetProjectsAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(Enumerable.Repeat(new Project(jira, remoteProject), 1)));
            jira.Services.Register <IProjectService>(() => projects.Object);

            var versionResource = new Mock <IProjectVersionService>();
            var remoteVersion   = new RemoteVersion()
            {
                id = "123", name = "my version"
            };
            var version = new ProjectVersion(jira, remoteVersion);

            versionResource.Setup(s => s.GetVersionsAsync("projKey", CancellationToken.None))
            .Returns(Task.FromResult(Enumerable.Repeat <ProjectVersion>(version, 1)));

            jira.Services.Register <IProjectVersionService>(() => versionResource.Object);

            // Act
            var versions = jira.Projects.GetProjectsAsync().Result.First().GetVersionsAsync().Result;

            // Assert
            Assert.Equal("my version", versions.First().Name);
        }
Example #3
0
        public void CheckUpdates()
        {
            if (!EnvironmentManager.Settings.CheckForUpdates)
            {
                return;
            }
            BackgroundWorker updateWorker = new BackgroundWorker();

            updateWorker.DoWork += async(s1, e2) => {
                RemoteVersion remote = RemoteVersion.Instance;
                if (remote != null)
                {
                    Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                    if (remote.Version.CompareTo(currentVersion) > 0)
                    {
                        string content = string.Format(LanguageManager.Model.UpdateAvailableText, remote.Version)
                                         + System.Environment.NewLine
                                         + System.Environment.NewLine
                                         + remote.ChangeLog
                                         + System.Environment.NewLine
                                         + System.Environment.NewLine
                                         + LanguageManager.Model.UpdateDownloadQuestion;
                        string caption = string.Format(LanguageManager.Model.UpdateAvailableCaption, remote.Version);
                        if (await App.Kernel.Get <IDialogManager>().ShowYesNoDialog(caption, content).Wait())
                        {
                            URLUtils.OpenSite(remote.DownloadUrl);
                        }
                    }
                }
            };
            updateWorker.RunWorkerAsync();
        }
Example #4
0
        public static RemoteVersion CreateVersion(string projectKey, string versionName)
        {
            if (!IsConfigured)
            {
                throw new InvalidOperationException("JIRA is not configured");
            }

            var remoteVersion = new RemoteVersion {
                name = versionName
            };

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Creating version: {0}\n{1}", projectKey, remoteVersion.ToJson());
            }

            remoteVersion = Service.addVersion(GetToken(), projectKey, remoteVersion);

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Response:\n{0}", remoteVersion.ToJson());
            }

            return(remoteVersion);
        }
Example #5
0
        /// <summary>Checks the given RemoteVersion wether it passes our minumum version required.</summary>
        /// <param name="version">The RemoteVersion from the Spira Instance</param>
        /// <returns>True is the SpiraServer meets minimum requirements.</returns>
        public static bool CheckVersionNum(RemoteVersion version)
        {
            //Return value.
            bool verOk = false;

            /* Try to convert over. First we try converting to a float (Pre-v4.1, ver.Version is two numbers, "0.0". This will
             * pass converting to a float. On v4.1 and later, ver.Version is all four, "0.0.0.0", which can be converted into
             * a Version object.
             */
            float   spiraVerNum = 0;
            Version spiraVer    = null;

            if (float.TryParse(version.Version, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out spiraVerNum))
            {
                int verPatch = ((version.Patch.HasValue) ? version.Patch.Value : 0);
                //Translate the minimunm version to a float as well.
                string strMinVer = Common.SPIRA_VERSION.Major + "." + Common.SPIRA_VERSION.Minor;
                float  verMin    = float.Parse(strMinVer, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture);
                if ((spiraVerNum >= verMin && verPatch >= Common.SPIRA_PATCH) || (spiraVerNum > verMin))
                {
                    verOk = true;
                }
            }
            else if (Version.TryParse(version.Version, out spiraVer))
            {
                if (spiraVer >= Common.SPIRA_VERSION)
                {
                    verOk = true;
                }
            }

            return(verOk);
        }
        /// <summary>
        /// Creates a new instance of a ProjectVersion.
        /// </summary>
        /// <param name="jira">The jira instance.</param>
        /// <param name="remoteVersion">The remote version.</param>
        public ProjectVersion(Jira jira, RemoteVersion remoteVersion)
            : base(remoteVersion)
        {
            if (jira == null)
            {
                throw new ArgumentNullException("jira");
            }

            _jira          = jira;
            _remoteVersion = remoteVersion;
        }
Example #7
0
            public void IfFieldsSet_ShouldPopulateFields()
            {
                var jira    = TestableJira.Create();
                var issue   = jira.CreateIssue("ProjectKey");
                var version = new RemoteVersion()
                {
                    id = "1"
                }.ToLocal(issue.Jira);
                var component = new RemoteComponent()
                {
                    id = "1"
                }.ToLocal();

                jira.IssueTypeService.Setup(s => s.GetIssueTypesAsync(CancellationToken.None))
                .Returns(Task.FromResult(Enumerable.Repeat(new IssueType("4", "issuetype"), 1)));
                jira.IssuePriorityService.Setup(s => s.GetPrioritiesAsync(CancellationToken.None))
                .Returns(Task.FromResult(Enumerable.Repeat(new IssuePriority("1", "priority"), 1)));

                issue.AffectsVersions.Add(version);
                issue.Assignee = "assignee";
                issue.Components.Add(component);
                // issue.CustomFields <-- requires extra setup, test below
                issue.Description = "description";
                issue.DueDate     = new DateTime(2011, 1, 1);
                issue.Environment = "environment";
                issue.FixVersions.Add(version);
                // issue.Key <-- should be non-settable
                issue.Priority = "1";
                // issue.Project <-- should be non-settable
                issue.Reporter = "reporter";
                issue.Summary  = "summary";
                issue.Type     = "4";

                var remoteIssue = issue.ToRemote();

                Assert.Single(remoteIssue.affectsVersions);
                Assert.Equal("assignee", remoteIssue.assignee);
                Assert.Single(remoteIssue.components);
                Assert.Null(remoteIssue.created);
                Assert.Equal("description", remoteIssue.description);
                Assert.Equal(new DateTime(2011, 1, 1), remoteIssue.duedate);
                Assert.Equal("environment", remoteIssue.environment);
                Assert.Null(remoteIssue.key);
                Assert.Equal("1", remoteIssue.priority.id);
                Assert.Equal("ProjectKey", remoteIssue.project);
                Assert.Equal("reporter", remoteIssue.reporter);
                Assert.Null(remoteIssue.resolution);
                Assert.Null(remoteIssue.status);
                Assert.Equal("summary", remoteIssue.summary);
                Assert.Equal("4", remoteIssue.type.id);
                Assert.Null(remoteIssue.updated);
            }
Example #8
0
            public async Task IfAddAffectsVersion_ReturnAllFieldsThatChanged()
            {
                var issue = new RemoteIssue()
                {
                    key = "foo"
                }.ToLocal(TestableJira.Create());
                var version = new RemoteVersion()
                {
                    id = "1", name = "1.0"
                };

                issue.AffectsVersions.Add(version.ToLocal(TestableJira.Create()));

                var fields = await GetUpdatedFieldsForIssueAsync(issue);

                Assert.Single(fields);
                Assert.Equal("versions", fields[0].id);
                Assert.Equal("1", fields[0].values[0]);
            }
            public void IfAddAffectsVersion_ReturnAllFieldsThatChanged()
            {
                var issue = new RemoteIssue()
                {
                    key = "foo"
                }.ToLocal();
                var version = new RemoteVersion()
                {
                    id = "1", name = "1.0"
                };

                issue.AffectsVersions.Add(version.ToLocal());

                var fields = GetUpdatedFieldsForIssue(issue);

                Assert.Equal(1, fields.Length);
                Assert.Equal("versions", fields[0].id);
                Assert.Equal("1", fields[0].values[0]);
            }
Example #10
0
            public void IfFieldsSet_ShouldPopulateFields()
            {
                var issue     = CreateIssue("ProjectKey");
                var version   = new RemoteVersion().ToLocal();
                var component = new RemoteComponent().ToLocal();

                issue.AffectsVersions.Add(version);
                issue.Assignee = "assignee";
                issue.Components.Add(component);
                // issue.CustomFields <-- requires extra setup, test below
                issue.Description = "description";
                issue.DueDate     = new DateTime(2011, 1, 1);
                issue.Environment = "environment";
                issue.FixVersions.Add(version);
                // issue.Key <-- should be non-settable
                issue.Priority = "1";
                // issue.Project <-- should be non-settable
                issue.Reporter = "reporter";
                issue.Summary  = "summary";
                issue.Type     = "4";
                issue.Votes    = 1;

                var remoteIssue = issue.ToRemote();

                Assert.Equal(1, remoteIssue.affectsVersions.Length);
                Assert.Equal("assignee", remoteIssue.assignee);
                Assert.Equal(1, remoteIssue.components.Length);
                Assert.Null(remoteIssue.created);
                Assert.Equal("description", remoteIssue.description);
                Assert.Equal(new DateTime(2011, 1, 1), remoteIssue.duedate);
                Assert.Equal("environment", remoteIssue.environment);
                Assert.Null(remoteIssue.key);
                Assert.Equal("1", remoteIssue.priority);
                Assert.Equal("ProjectKey", remoteIssue.project);
                Assert.Equal("reporter", remoteIssue.reporter);
                Assert.Null(remoteIssue.resolution);
                Assert.Null(remoteIssue.status);
                Assert.Equal("summary", remoteIssue.summary);
                Assert.Equal("4", remoteIssue.type);
                Assert.Null(remoteIssue.updated);
                Assert.Equal(1, remoteIssue.votes);
            }
Example #11
0
        private int GetWeight(bool matchImplementation)
        {
            int weight = 0;

            if (CalledAE.Contains("*") || CalledAE.Contains("?"))
            {
                weight++;
            }
            if (CallingAE.Contains("*") || CallingAE.Contains("?"))
            {
                weight++;
            }
            if (matchImplementation && RemoteImplUID.Contains("*") || RemoteImplUID.Contains("?"))
            {
                weight++;
            }
            if (matchImplementation && RemoteVersion.Contains("*") || RemoteVersion.Contains("?"))
            {
                weight++;
            }
            return(weight);
        }
 /// <remarks/>
 public void addVersionAsync(string in0, string in1, RemoteVersion in2) {
     this.addVersionAsync(in0, in1, in2, null);
 }
 public RemoteVersion addVersion(string in0, string in1, RemoteVersion in2) {
     object[] results = this.Invoke("addVersion", new object[] {
                 in0,
                 in1,
                 in2});
     return ((RemoteVersion)(results[0]));
 }
 /// <remarks/>
 public void releaseVersionAsync(string in0, string in1, RemoteVersion in2) {
     this.releaseVersionAsync(in0, in1, in2, null);
 }
 public void releaseVersion(string in0, string in1, RemoteVersion in2) {
     this.Invoke("releaseVersion", new object[] {
                 in0,
                 in1,
                 in2});
 }
        /// <summary>
        /// Save field changes to the server.
        /// </summary>
        /// <param name="token">Cancellation token for this operation.</param>
        public async Task SaveChangesAsync(CancellationToken token = default(CancellationToken))
        {
            var version = await _jira.Versions.UpdateVersionAsync(this, token).ConfigureAwait(false);

            _remoteVersion = version.RemoteVersion;
        }
Example #17
0
 /// <summary>
 /// Creates a new Version from RemoteVersion
 /// </summary>
 public static ProjectVersion ToLocal(this RemoteVersion remoteVersion)
 {
     return(new ProjectVersion(remoteVersion));
 }
 /// <remarks/>
 public System.IAsyncResult BeginaddVersion(string in0, string in1, RemoteVersion in2, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("addVersion", new object[] {
                 in0,
                 in1,
                 in2}, callback, asyncState);
 }
Example #19
0
 public RemoteVersion AddVersion(string in0, string in1, RemoteVersion in2)
 {
     return(_client.addVersion(in0, in1, in2));
 }
 /// <summary>
 /// Creates a new Version from RemoteVersion
 /// </summary>
 public static ProjectVersion ToLocal(this RemoteVersion remoteVersion, Jira jira)
 {
     return(new ProjectVersion(jira, remoteVersion));
 }
Example #21
0
 public void ReleaseVersion(string in0, string in1, RemoteVersion in2)
 {
     _client.releaseVersion(in0, in1, in2);
 }
 /// <remarks/>
 public void addVersionAsync(string in0, string in1, RemoteVersion in2, object userState) {
     if ((this.addVersionOperationCompleted == null)) {
         this.addVersionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnaddVersionOperationCompleted);
     }
     this.InvokeAsync("addVersion", new object[] {
                 in0,
                 in1,
                 in2}, this.addVersionOperationCompleted, userState);
 }
Example #23
0
 public ProjectVersion(RemoteVersion version)
 {
     this.Id       = version.id;
     this.Name     = version.name;
     this.Released = version.released;
 }
Example #24
0
 internal ProjectVersion(RemoteVersion remoteVersion)
     : base(remoteVersion)
 {
     _remoteVersion = remoteVersion;
 }
        /// <summary>The main processing function.</summary>
        /// <param name="ErrorMsg">Error message in case an error happens.</param>
        /// <returns>Boolean on status of import.</returns>
        private bool ProcessImport(StreamWriter streamWriter, out FinalStatusEnum Status)
        {
            Status = FinalStatusEnum.OK;
            this.ProgressUpdate(this, new ProgressArgs()
            {
                ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Processing, TaskNum = 2
            });
            streamWriter.WriteLine("Starting Import...");

            try
            {
                //Load the mapping data
                this._requirementDataMapping = new RequirementDataMapping();
                this._releaseDataMapping     = new ReleaseDataMapping();

                //See if we've been asked to clear the saved mapping data
                if (this._SpiraProject.RootReq == -1)
                {
                    this._requirementDataMapping.Clear();
                    this._releaseDataMapping.Clear();
                }
                else
                {
                    //Get the list of Releases in the Jama project
                    JamaProject jamaProject = this._jamaClient.GetProject(this._JamaProject.ProjectNum);
                    if (jamaProject != null)
                    {
                        //Store the project short name
                        this._projectShortName = jamaProject.ProjectKey;

                        List <JamaRelease> jamaReleases = this._jamaClient.GetReleases(jamaProject.Id);

                        //Import the releases into SpiraTeam
                        if (jamaReleases != null)
                        {
                            foreach (JamaRelease jamaRelease in jamaReleases)
                            {
                                if (ProcessThread.WantCancel)
                                {
                                    break;
                                }
                                FinalStatusEnum thisRun = this.ProcessRelease(streamWriter, jamaRelease);
                                if (Status != FinalStatusEnum.Error && thisRun == FinalStatusEnum.Error)
                                {
                                    Status = thisRun;
                                }
                                if (Status == FinalStatusEnum.OK && thisRun == FinalStatusEnum.Warning)
                                {
                                    Status = thisRun;
                                }
                            }
                        }
                    }

                    //Get the list of items in the Jama project in batches of 25
                    int             startItem = 1;
                    List <JamaItem> jamaItems = null;

                    //Store the list of jama project ids and item ids so that we can track deletes later
                    List <JamaProjectItemEntry> jamaEntries = new List <JamaProjectItemEntry>();

                    do
                    {
                        jamaItems = this._jamaClient.GetItemsForProject(this._JamaProject.ProjectNum, startItem, REQUEST_PAGE_SIZE);

                        //Import the items into SpiraTeam
                        if (jamaItems != null)
                        {
                            foreach (JamaItem jamaItem in jamaItems)
                            {
                                if (ProcessThread.WantCancel)
                                {
                                    break;
                                }
                                FinalStatusEnum thisRun = this.ProcessItem(streamWriter, jamaItem);
                                if (Status != FinalStatusEnum.Error && thisRun == FinalStatusEnum.Error)
                                {
                                    Status = thisRun;
                                }
                                if (Status == FinalStatusEnum.OK && thisRun == FinalStatusEnum.Warning)
                                {
                                    Status = thisRun;
                                }

                                //Also add to the list so that we can check for deletes afterwards
                                jamaEntries.Add(new JamaProjectItemEntry(jamaItem.ProjectId, jamaItem.Id));
                            }
                        }

                        startItem += REQUEST_PAGE_SIZE;
                    }while (jamaItems != null && jamaItems.Count > 0 && !ProcessThread.WantCancel);

                    //See if we want to delete items in Spira that are not in Jama
                    if (Properties.Settings.Default.DeleteItemInSpiraIfMissing)
                    {
                        //See if we have at least v3.1 of SpiraTest, since only that supports deletes
                        RemoteVersion remoteVersion = this._spiraClient.System_GetProductVersion();
                        if (remoteVersion != null)
                        {
                            string   versionNumber     = remoteVersion.Version;
                            string[] versionComponents = versionNumber.Split('.');
                            int      majorVersion      = 0;
                            if (!Int32.TryParse(versionComponents[0], out majorVersion))
                            {
                                majorVersion = 0;
                            }
                            int minorVersion = 0;
                            if (versionComponents.Length > 1)
                            {
                                if (!Int32.TryParse(versionComponents[1], out minorVersion))
                                {
                                    minorVersion = 0;
                                }
                            }

                            //We need at least v3.1
                            if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 1))
                            {
                                //Now see if we have any mapped requirements that are no longer in Jama
                                if (this._requirementDataMapping.Rows != null)
                                {
                                    for (int i = 0; i < this._requirementDataMapping.Rows.Count; i++)
                                    {
                                        RequirementMappingData.RequirementMappingRow mappingRow = this._requirementDataMapping.Rows[i];
                                        //See that entry exists in the list of items, if not, delete from Spira and mappings
                                        if (!jamaEntries.Any(je => je.ItemId == mappingRow.JamaItemId && je.ProjectId == mappingRow.JamaProjectId))
                                        {
                                            DeleteSpiraRequirement(streamWriter, mappingRow);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //Save the mapping data
                this._requirementDataMapping.Save();
                this._releaseDataMapping.Save();

                if (Status == FinalStatusEnum.Error)
                {
                    string ErrorMsg = "";
                    if (ProcessThread.WantCancel)
                    {
                        ErrorMsg = App.CANCELSTRING;
                    }
                    this.ProgressUpdate(this, new ProgressArgs()
                    {
                        ErrorText = ErrorMsg, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 2
                    });
                    return(false);
                }
                else
                {
                    this.ProgressUpdate(this, new ProgressArgs()
                    {
                        ErrorText = "", Progress = -1, Status = ItemProgress.ProcessStatusEnum.Success, TaskNum = 2
                    });
                    return(true);
                }
            }
            catch (Exception exception)
            {
                //Handle all exceptions
                streamWriter.WriteLine("Error: " + exception.Message);
                this.ProgressUpdate(this, new ProgressArgs()
                {
                    ErrorText = exception.Message, Progress = -1, Status = ItemProgress.ProcessStatusEnum.Error, TaskNum = 2
                });
                return(false);
            }
        }
Example #26
0
    //检查版本信息
    public void BeginInit(string remotoURL, Action <Exception> onInit, IEnumerable <string> groups, int taskcount = 1, bool checkRemote = true)
    {
        this.RemoteUrl = remotoURL;
        this.TaskCount = taskcount;
        verLocal       = new LocalVersion();


        Action <Exception> onInitRemote = (err) =>
        {
            if (err != null)
            {
                onInit(err);
                return;
            }
            Debug.Log("(ver)onInitRemote");
            //检查需更新的列表
            int addcount    = 0;
            int updatecount = 0;
            verLocal.ver = this.verRemote.ver;
            foreach (var g in groups)
            {
                if (verLocal.groups.ContainsKey(g) == false)
                {
                    if (verRemote.groups.ContainsKey(g) == false)
                    {
                        Debug.LogWarning("group:" + g + " 在服务器和本地均不存在");
                        continue;
                    }
                    else
                    {
                        verLocal.groups[g] = new LocalVersion.VerInfo(g, "", 0);
                    }
                }
                verLocal.groups[g].groupfilecount = this.verRemote.groups[g].filecount;
                verLocal.groups[g].grouphash      = this.verRemote.groups[g].hash;
                verLocal.groups[g].listverid      = this.verRemote.ver;
                //Debug.Log("check groups=====================>" + g);
                foreach (var f in verRemote.groups[g].files)
                {
                    //Debug.Log("check files=====>" + f.Key);

                    if (verLocal.groups[g].listfiles.ContainsKey(f.Key))
                    {
                        var fl = verLocal.groups[g].listfiles[f.Key];
                        if (fl.hash != f.Value.hash || fl.size != f.Value.length)
                        {
                            // fl.state |= LocalVersion.ResState.ResState_NeedUpdate;
                            fl.needupdate = true;
                            updatecount++;
                            Debug.Log("(ver)update:" + f.Key);
                        }
                    }
                    else
                    {
                        Debug.Log("(ver)add:" + f.Key);
                        verLocal.groups[g].listfiles[f.Key]            = new LocalVersion.ResInfo(g, f.Key, f.Value.hash, f.Value.length);
                        verLocal.groups[g].listfiles[f.Key].state      = LocalVersion.ResState.ResState_UseRemote;
                        verLocal.groups[g].listfiles[f.Key].needupdate = true;
                        addcount++;
                    }
                }
            }
            Debug.Log("(ver)addcount:" + addcount + ",updatecount:" + updatecount);
            verLocal.Save(groups);
            onInit(null);
        };
        Action onInitLocal = () =>
        {
            Debug.Log("(ver)onInitLocal");
            //此处仅完成本地资源检查,如果需要服务器同步,调用BeginCheckRemote
            if (!checkRemote)
            {
                onInit(null);
            }
            else
            {
                //taskState.Clear();
                verRemote = new RemoteVersion();
                verRemote.BeginInit(onInitRemote, groups);
            }
        };

        verLocal.BeginInit(onInitLocal, groups);

        //01先尝试从存储位置初始化Verinfo,没有则从Streaming assets 初始化本地Verinfo
        //02从服务器下载总的资料
        //03完成后回调
    }
Example #27
0
 public void ReleaseVersion(string in0, string in1, RemoteVersion in2)
 {
     throw new NotImplementedException();
 }
Example #28
0
    //检查版本信息
    public void BeginInit(string remotoURL, Action<Exception> onInit, IEnumerable<string> groups, int taskcount = 1, bool checkRemote = true)
    {
        this.remoteurl = remotoURL;
        this.taskCount = taskcount;
        verLocal = new LocalVersion();

        Action<Exception> onInitRemote = (err) =>
            {
                if (err != null)
                {
                    onInit(err);
                    return;
                }
                Debug.Log("(ver)onInitRemote");
                //检查需更新的列表
                int addcount = 0;
                int updatecount = 0;
                verLocal.ver = this.verRemote.ver;
                foreach (var g in groups)
                {
                    if (verLocal.groups.ContainsKey(g) == false)
                    {
                        if (verRemote.groups.ContainsKey(g) == false)
                        {
                            Debug.LogWarning("group:" + g + " 在服务器和本地均不存在");
                            continue;
                        }
                        else
                        {
                            verLocal.groups[g] = new LocalVersion.VerInfo(g, "", 0);
                        }
                    }
                    verLocal.groups[g].groupfilecount = this.verRemote.groups[g].filecount;
                    verLocal.groups[g].grouphash = this.verRemote.groups[g].hash;
                    verLocal.groups[g].listverid = this.verRemote.ver;
                    //Debug.Log("check groups=====================>" + g);
                    foreach (var f in verRemote.groups[g].files)
                    {
                        //Debug.Log("check files=====>" + f.Key);

                        if (verLocal.groups[g].listfiles.ContainsKey(f.Key))
                        {

                            var fl = verLocal.groups[g].listfiles[f.Key];
                            if (fl.hash != f.Value.hash || fl.size != f.Value.length)
                            {
                                // fl.state |= LocalVersion.ResState.ResState_NeedUpdate;
                                fl.needupdate = true;
                                updatecount++;
                                Debug.Log("(ver)update:" + f.Key);
                            }
                        }
                        else
                        {
                            Debug.Log("(ver)add:" + f.Key);
                            verLocal.groups[g].listfiles[f.Key] = new LocalVersion.ResInfo(g, f.Key, f.Value.hash, f.Value.length);
                            verLocal.groups[g].listfiles[f.Key].state = LocalVersion.ResState.ResState_UseRemote;
                            verLocal.groups[g].listfiles[f.Key].needupdate = true;
                            addcount++;
                        }
                    }
                }
                Debug.Log("(ver)addcount:" + addcount + ",updatecount:" + updatecount);
                verLocal.Save(groups);
                onInit(null);
            };
        Action onInitLocal = () =>
            {

                Debug.Log("(ver)onInitLocal");
                //此处仅完成本地资源检查,如果需要服务器同步,调用BeginCheckRemote
                if (!checkRemote)
                {
                    onInit(null);
                }
                else
                {
                    //taskState.Clear();
                    verRemote = new RemoteVersion();
                    verRemote.BeginInit(onInitRemote, groups);
                }
            };
        verLocal.BeginInit(onInitLocal, groups);

        //01先尝试从存储位置初始化Verinfo,没有则从Streaming assets 初始化本地Verinfo
        //02从服务器下载总的资料
        //03完成后回调
    }
Example #29
0
    public void BeginDownLoad(string path, Action callback)
    {
        Action CompareDiff = () =>
        {
            foreach (KeyValuePair <string, VerGroup> index in RemoteVersion.RemoteVerGroup)
            {
                if (LocalVersion.LocalVerGroup.ContainsKey(index.Key))//比较hash,size
                {
                    VerGroup local = LocalVersion.LocalVerGroup[index.Key];
                    //if (local.hash != index.Value.hash || local.filecount != index.Value.filecount)
                    //{
                    //    LocalVersion.LocalVerGroup[index.Key] = index.Value;
                    //}
                    foreach (KeyValuePair <string, RootGroup> KV in index.Value.rootlist)
                    {
                        if (local.rootlist.ContainsKey(KV.Key))
                        {
                            RootGroup group = local.rootlist[KV.Key];
                            if (group.hash != KV.Value.hash || group.filesize != KV.Value.filesize)
                            {
                                local.rootlist[KV.Key] = KV.Value;
                                local.rootlist[KV.Key].needdownload = true;
                            }
                        }
                        else
                        {
                            RootGroup g = new RootGroup(KV.Value.FileName, KV.Value.hash, KV.Value.filesize);
                            g.needdownload         = true;
                            local.rootlist[KV.Key] = g;
                        }
                    }
                }
                else
                {
                    VerGroup newgroup = new VerGroup(index.Value.RootName, index.Value.hash, index.Value.filecount);
                    index.Value.SetAllFilesNeedDownLoad();
                    newgroup.rootlist = index.Value.rootlist;
                    LocalVersion.LocalVerGroup[index.Key] = newgroup;
                }
            }
            //LocalVersion.SaveGroupToLocal("allver.ver.txt");
            //TODO::与本地解析比较,找出需要下载的
            if (callback != null)
            {
                callback();
            }
        };
        Action <WWW, int> AllVerCallBack = (www, udata) =>
        {
            if (www.error != null || www.text == null)
            {
                Log_Debug.LogError("www download error");
                return;
            }
            string   info    = www.text;
            string[] splited = info.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (splited.Length <= 1)//数据错误
            {
                ShowLoadingErrTips("服务器下载数据错误");
                return;
            }
            for (int i = 0; i < splited.Length; i++)
            {
                if (i == 0)
                {
                    string[] first = splited[0].Split(new string[] { ":" }, StringSplitOptions.None);
                    int.TryParse(first[1], out RemoteVersion.Version);
                }
                else
                {
                    string[] first = splited[i].Split(new string[] { "|" }, StringSplitOptions.None);
                    VerGroup ver   = new VerGroup(first[0], first[1], int.Parse(first[2]));
                    RemoteVersion.RemoteVerGroup[first[0]] = ver;
                }
            }
            Debug.Log(RootHashDiff());
            if (RemoteVersion.Version > LocalVersion.Version || RootHashDiff())//
            {
                LocalVersion.Version = RemoteVersion.Version;
                foreach (KeyValuePair <string, VerGroup> group in RemoteVersion.RemoteVerGroup)
                {
                    StringBuilder str = new StringBuilder();
                    str.Append(RemoteVersion.remoteurl).Append("/" + group.Key + ".ver.txt");
                    group.Value.CreateDownLoad(str.ToString(), CompareDiff);
                }
            }
            else
            {
                if (callback != null)
                {
                    callback();
                }
            }
        };
        Action MergeLocal = () =>
        {
            RemoteVersion.AddDownLoadTask(path, AllVerCallBack);
        };

        if (DataManager.Instance.IsFirstEnterGame)//首次进入游戏
        {
            LocalVersion.ClearLocalCache();
            RemoteVersion.AddDownLoadTask(path, AllVerCallBack);
        }
        else
        {
            LocalVersion.ReadLocalAllVer(path, MergeLocal);
        }
    }
Example #30
0
 public RemoteVersion AddVersion(string in0, string in1, RemoteVersion in2)
 {
     throw new NotImplementedException();
 }